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
66
67
68
69
70
71
72
73
74
package com.landtool.lanbase.modules.log.service.impl;
 
import java.io.IOException;
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.landtool.lanbase.common.utils.HttpContextUtils;
import com.landtool.lanbase.common.utils.HttpOperateUtils;
import com.landtool.lanbase.common.utils.IPUtils;
import com.landtool.lanbase.config.LoginConfigProperties;
import com.landtool.lanbase.config.SysTemPropertyConfig;
import com.landtool.lanbase.modules.log.entity.LogAction;
import com.landtool.lanbase.modules.log.service.LogActionService;
import com.landtool.lanbase.modules.org.entity.OrgUser;
 
@Service("actionService")
public class LogActionServiceImpl implements LogActionService {
 
    @Autowired
    private SysTemPropertyConfig  tokenConfig;
 
    @Autowired
    private LoginConfigProperties loginConfig;
 
    @Override
    public void save(LogAction action){
        String url = tokenConfig.getApiServer()+"/api/log/action/addAction";
        try{
            HttpOperateUtils.httpPost(url,action);
        }catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    @Override
    public void saveLogAction(String action) {
        String url = tokenConfig.getApiServer()+"/api/log/action/addAction";
        LogAction logAction = new LogAction();
        String[] list = action.split(",");
        logAction.setLargemodel(list[0]); //大模块
        logAction.setSmallmodel(list[1]);//小模块
        logAction.setRemark(list[2]);    //备注
        logAction.setActiontype(list[3]);//操作类型
 
        if(list.length == 5) {
            logAction.setUserid(Long.parseLong(list[4]));
        }
        else if(list.length == 4) {
            Long userid = ((OrgUser) SecurityUtils.getSubject().getPrincipal()).getUserid();
            logAction.setUserid(userid);
        }
        if(list.length == 6){
            logAction.setResourceid(Integer.valueOf(list[4]));
            logAction.setTitle(list[5]);
        }
        //获取request
        HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
        String ipurl = request.getServletPath();
        logAction.setRequesturl(ipurl);
        //设置IP地址
        logAction.setRequestip(IPUtils.getIpAddr(request));
 
        logAction.setAppid(loginConfig.getAppId());
        try{
            HttpOperateUtils.httpPost(url,logAction);
        }catch (IOException e) {
            e.printStackTrace();
        }
    }
}