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;
|
|
|
}
|