2
13693261870
2022-09-16 653761a31dfeb50dd3d007e892d69c90bf0cdafc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 + "'}";
    }
}