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
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.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;
 
    @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.setAccountId(id);
        log.setIp(ip);
        log.setContent(content);
        log.setUserName(userName);
        manageLogMapper.insert(log);
    }
}