付延余
2022-12-16 f0f8ee8c4a945adbc742d9bab69382b28ad311fb
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.wgcloud.service;
 
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wgcloud.entity.CustomInfo;
import com.wgcloud.entity.HostGroup;
import com.wgcloud.mapper.CustomInfoMapper;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @version v3.3
 * @ClassName:CustomInfoService.java
 * @author: http://www.wgstart.com
 * @date: 2022年9月16日
 * @Description: CustomInfoService.java
 * @Copyright: 2019-2022 wgcloud. All rights reserved.
 */
@Service
public class CustomInfoService {
 
    private static final Logger logger = LoggerFactory.getLogger(CustomInfoService.class);
 
    public PageInfo selectByParams(Map<String, Object> params, int currPage, int pageSize) throws Exception {
        PageHelper.startPage(currPage, pageSize);
        List<CustomInfo> list = customInfoMapper.selectByParams(params);
        PageInfo<CustomInfo> pageInfo = new PageInfo<CustomInfo>(list);
        return pageInfo;
    }
 
    public void save(CustomInfo customInfo, HttpServletRequest request) throws Exception {
        customInfo.setId(UUIDUtil.getUUID());
        Date nowDate = DateUtil.getNowTime();
        customInfo.setCreateTime(nowDate);
        customInfo.setState(StaticKeys.ON_STATE);
        if (!StringUtils.isEmpty(customInfo.getCustomShell())) {
            customInfo.setCustomShell(customInfo.getCustomShell().trim());
        }
        customInfoMapper.save(customInfo);
    }
 
 
    public int deleteByHostName(Map<String, Object> map) throws Exception {
        return customInfoMapper.deleteByHostName(map);
    }
 
    @Transactional
    public void saveRecord(List<CustomInfo> recordList) throws Exception {
        if (recordList.size() < 1) {
            return;
        }
        for (CustomInfo as : recordList) {
            as.setId(UUIDUtil.getUUID());
        }
        customInfoMapper.insertList(recordList);
    }
 
    public int countByParams(Map<String, Object> params) throws Exception {
        return customInfoMapper.countByParams(params);
    }
 
    @Transactional
    public int deleteById(String[] id) throws Exception {
        return customInfoMapper.deleteById(id);
    }
 
    @Transactional
    public void updateRecord(List<CustomInfo> recordList) throws Exception {
        if (recordList.size() < 1) {
            return;
        }
        customInfoMapper.updateList(recordList);
    }
 
    public void downByHostName(List<String> recordList) throws Exception {
        if (recordList.size() < 1) {
            return;
        }
        customInfoMapper.downByHostName(recordList);
    }
 
    public void updateById(CustomInfo CustomInfo)
            throws Exception {
        customInfoMapper.updateById(CustomInfo);
    }
 
    public CustomInfo selectById(String id) throws Exception {
        return customInfoMapper.selectById(id);
    }
 
    public List<CustomInfo> selectAllByParams(Map<String, Object> params) throws Exception {
        return customInfoMapper.selectAllByParams(params);
    }
 
    /**
     * 设置资源分组 begin
     *
     * @param recordList
     */
    public List<HostGroup> setGroupInList(List<CustomInfo> recordList) throws Exception {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("groupType", StaticKeys.HOST_GROUP_1);
        List<HostGroup> hostGroupList = hostGroupService.selectAllByParams(params);
        //查询所有主机分组列表,封装为map
        Map<String, String> hostGroupMap = new HashMap<>();
        for (HostGroup hostGroup : hostGroupList) {
            hostGroupMap.put(hostGroup.getId(), hostGroup.getGroupName());
        }
        for (CustomInfo CustomInfo : recordList) {
            if (!StringUtils.isEmpty(CustomInfo.getGroupId())) {
                CustomInfo.setGroupId(hostGroupMap.get(CustomInfo.getGroupId()));
            }
        }
        return hostGroupList;
    }
 
    /**
     * 保存操作日志
     *
     * @param request 获取当前登录用户
     * @param action  操作标识
     */
    public void saveLog(HttpServletRequest request, String action, CustomInfo customInfo) {
        if (null == customInfo) {
            return;
        }
        logInfoService.save(HostUtil.getAccountByRequest(request).getAccount() + action + "自定义监控项信息:" + customInfo.getHostname() + "," + customInfo.getCustomName(),
                "自定义监控项信息:" + customInfo.getCustomName(), StaticKeys.LOG_XTCZ);
    }
 
    @Autowired
    private CustomInfoMapper customInfoMapper;
    @Resource
    private HostGroupService hostGroupService;
    @Autowired
    private LogInfoService logInfoService;
 
 
}