kongdeqiang
2023-02-17 ac94b1d939373a684344764e5b00dac44feabd81
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.wgcloud.service;
 
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wgcloud.entity.FileSafe;
import com.wgcloud.mapper.FileSafeMapper;
import com.wgcloud.util.DateUtil;
import com.wgcloud.util.HostUtil;
import com.wgcloud.util.UUIDUtil;
import com.wgcloud.util.staticvar.StaticKeys;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
 
/**
 * @version v3.3
 * @ClassName:FileSafeService.java
 * @author: http://www.wgstart.com
 * @date: 2021年9月21日
 * @Description: FileSafeService.java
 * @Copyright: 2019-2021 wgcloud. All rights reserved.
 */
@Service
public class FileSafeService {
 
    public PageInfo selectByParams(Map<String, Object> params, int currPage, int pageSize) throws Exception {
        PageHelper.startPage(currPage, pageSize);
        List<FileSafe> list = fileSafeMapper.selectByParams(params);
        PageInfo<FileSafe> pageInfo = new PageInfo<FileSafe>(list);
        return pageInfo;
    }
 
    public void save(FileSafe FileSafe) throws Exception {
        FileSafe.setId(UUIDUtil.getUUID());
        FileSafe.setCreateTime(DateUtil.getNowTime());
        if (!StringUtils.isEmpty(FileSafe.getFileSign())) {
            FileSafe.setFileSign(FileSafe.getFileSign().trim());
        }
        fileSafeMapper.save(FileSafe);
    }
 
    public int deleteByHostName(Map<String, Object> map) throws Exception {
        return fileSafeMapper.deleteByHostName(map);
    }
 
    @Transactional
    public void saveRecord(List<FileSafe> recordList) throws Exception {
        if (recordList.size() < 1) {
            return;
        }
        for (FileSafe as : recordList) {
            as.setId(UUIDUtil.getUUID());
        }
        fileSafeMapper.insertList(recordList);
    }
 
    public void downByHostName(List<String> recordList) throws Exception {
        if (recordList.size() < 1) {
            return;
        }
        fileSafeMapper.downByHostName(recordList);
    }
 
    public int countByParams(Map<String, Object> params) throws Exception {
        return fileSafeMapper.countByParams(params);
    }
 
    @Transactional
    public int deleteById(String[] id) throws Exception {
        return fileSafeMapper.deleteById(id);
    }
 
    @Transactional
    public void updateRecord(List<FileSafe> recordList) throws Exception {
        if (recordList.size() < 1) {
            return;
        }
        fileSafeMapper.updateList(recordList);
    }
 
    public void updateById(FileSafe FileSafe)
            throws Exception {
        fileSafeMapper.updateById(FileSafe);
    }
 
    public FileSafe selectById(String id) throws Exception {
        return fileSafeMapper.selectById(id);
    }
 
    public List<FileSafe> selectAllByParams(Map<String, Object> params) throws Exception {
        return fileSafeMapper.selectAllByParams(params);
    }
 
    /**
     * 保存操作日志
     *
     * @param request 获取当前登录用户
     * @param action  操作标识
     */
    public void saveLog(HttpServletRequest request, String action, FileSafe fileSafe) {
        if(null == fileSafe){
            return;
        }
        logInfoService.save(HostUtil.getAccountByRequest(request).getAccount() + action + "文件防篡改监测信息:" + fileSafe.getHostname() + "," + fileSafe.getFileName(),
                "文件名称:" + fileSafe.getFileName() + ",文件路径:" + fileSafe.getFilePath(), StaticKeys.LOG_XTCZ);
    }
 
 
    @Autowired
    private FileSafeMapper fileSafeMapper;
    @Autowired
    private LogInfoService logInfoService;
 
 
}