package com.landtool.lanbase.modules.api.controller; import java.sql.Timestamp; import java.util.Date; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.landtool.lanbase.modules.res.entity.Res_ActionRecord; import com.landtool.lanbase.modules.res.service.ResActionRecordService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; /** * @author 刘小波 * @Description: 资源(浏览、调用、收藏)等操作查询写入接口 * @date 2018-01-30 */ @Controller @RequestMapping("/api/actionrecord/") @Api(value = "", tags = { "资源操作相关接口" }) public class ActionRecordController { @Autowired private ResActionRecordService resActionRecordService; /** * 资源调用日志记录,记录用户ESB服务调用情况 * @param record * @Description: 日志数据写入 {@link ResActionRecordService} * @Author: xiaoxuan.xie * @Date: 13:30 2018/3/28 * @return: Model * @see Res_ActionRecord */ @ResponseBody @PostMapping(path = "/adduseinfo") @ApiOperation(value = "资源调用日志记录", notes = "") public String adduseinfo( @ApiParam(name="resourceid",value="资源Id",required=true) @RequestParam(name="resourceid") Integer resourceid, @ApiParam(name="appid",value="应用Id") @RequestParam(name="appid", required = false) Integer appid, @ApiParam(name="userid",value="用户Id",required=true) @RequestParam(name="userid") Long userid, @ApiParam(name="ip",value="ip") @RequestParam(name="ip",required = false) String ip) { Res_ActionRecord record = new Res_ActionRecord(); record.setResourceid(resourceid); record.setUserid(userid); if(appid != null) record.setAppid(appid); if(ip != null) record.setIp(ip); Timestamp audittime = new Timestamp(new Date().getTime());// 获取当前时间 boolean success = false;// 操作状态 String msg = "";// 操作返回消息 record.setActiontime(audittime); record.setActiontype("调用"); int row = resActionRecordService.insertSelective(record); success = row >= 1; msg = success ? "日志写入成功!" : "日志写入失败"; return "{success:" + success + ", msg:'" + msg + "'}"; } }