kaiyu
2021-04-09 54d7eb96e071c62fa96f95b56ff8be66f7c3718e
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
package com.moral.api.util;
 
import com.moral.api.entity.ManageAccount;
import com.moral.api.entity.ManageLog;
import com.moral.api.mapper.ManageLogMapper;
import com.moral.api.pojo.dto.login.AccountInfoDTO;
import com.moral.util.TokenUtils;
import com.moral.util.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import javax.servlet.http.HttpServletRequest;
 
/**
 * @ClassName LogUtils
 * @Description TODO
 * @Author 陈凯裕
 * @Date 2021/4/2 8:45
 * @Version TODO
 **/
@Component
public class LogUtils {
 
    @Autowired
    public ManageLogMapper manageLogMapper;
 
    /**
    * @Description: 通用插入日志
            * @Param: [request, content]
            * @return: void
            * @Author: 陈凯裕
            * @Date: 2021/4/8
            */
    @Transactional
    public void saveOperationForManage(HttpServletRequest request, String content) {
        String token = request.getHeader("token");
        AccountInfoDTO accountInfoDTO = (AccountInfoDTO) TokenUtils.getUserInfoByToken(token);
        ManageAccount account = accountInfoDTO.getAccount();
        Integer id = account.getId();
        String userName = account.getUserName();
        String ip = WebUtils.getIpAddr(request);
 
        ManageLog log = new ManageLog();
        log.setUserName(userName);
        log.setAccountId(id);
        log.setIp(ip);
        log.setContent(content);
        manageLogMapper.insert(log);
    }
 
    /**
    * @Description: 插入登陆操作日志
            * @Param: [request, content, id, userName]
            * @return: void
            * @Author: 陈凯裕
            * @Date: 2021/4/8
            */
    @Transactional
    public void saveLoginForManage(HttpServletRequest request,String content,Integer id,String userName){
        ManageLog log = new ManageLog();
        String ip = WebUtils.getIpAddr(request);
 
        log.setAccountId(id);
        log.setUserName(userName);
        log.setIp(ip);
        log.setContent(content);
        manageLogMapper.insert(log);
    }
}