IntelligentRecognition/ah-jjsp-service/.svn/pristine/89/8970549108d484754f71d5431b4...

194 lines
8.1 KiB
Plaintext
Raw Normal View History

2024-05-24 16:09:40 +08:00
package com.sercurityControl.proteam.dutyTask.controller;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.securityControl.common.core.utils.StringUtils;
import com.securityControl.common.core.utils.aes.DateTimeHelper;
import com.securityControl.common.core.web.domain.AjaxResult;
import com.securityControl.common.log.annotation.Log;
import com.securityControl.common.log.enums.BusinessType;
import com.securityControl.common.log.enums.OperationType;
import com.sercurityControl.proteam.dutyTask.domain.*;
import com.sercurityControl.proteam.dutyTask.service.ResourceMonitorService;
import com.sercurityControl.proteam.dutyTask.service.ServerMonitorService;
import com.sercurityControl.proteam.util.ExcelStyleUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.*;
/**
* 资源监测
*/
@RestController
@RequestMapping("/pot/resourceMonitor/")
@Slf4j
public class ResourceMonitorController {
Logger logger = LoggerFactory.getLogger(ResourceMonitorController.class);
@Resource(name = "ResourceMonitorService")
private ResourceMonitorService service;
/**
* @return java.util.Map<java.lang.String, java.lang.Object>
* @author cw chen
* @description 设备状态监测
* @Param entity
* @date 2023-05-30 17:36
*/
@PostMapping(value = "getDeviceStatusMonitorList")
@Log(title = "设备状态监测", menu = "资源监测通知->设备状态监测", businessType = BusinessType.QUERY, details = "设备状态监测")
public Map<String, Object> getDeviceStatusMonitorList(ResourceMonitorEntity entity) {
PageHelper.startPage(Integer.parseInt(entity.getPage()), Integer.parseInt(entity.getLimit()));
Map<String, Object> map = new HashMap<String, Object>(16);
try {
PageInfo<ResourceMonitorEntity> pageInfo = service.getDeviceStatusMonitorList(entity);
map.put("code", 200);
map.put("msg", "获取数据成功");
map.put("count", pageInfo.getTotal());
map.put("curr", Integer.parseInt(entity.getPage()));
map.put("limit", Integer.parseInt(entity.getLimit()));
map.put("data", pageInfo.getList());
} catch (Exception e) {
map.put("code", 500);
map.put("msg", "获取数据失败");
map.put("count", 0);
map.put("curr", Integer.parseInt(entity.getPage()));
map.put("limit", Integer.parseInt(entity.getLimit()));
map.put("data", null);
logger.error("数据获取失败", e);
}
return map;
}
/**
* @return java.util.Map<java.lang.String, java.lang.Object>
* @author cw chen
* @description 服务器状态监测
* @Param entity
* @date 2023-05-31 15:19
*/
@PostMapping(value = "getServerMonitorList")
@Log(title = "服务器状态监测", menu = "资源监测通知->服务器状态监测", businessType = BusinessType.QUERY, details = "服务器状态监测")
public Map<String, Object> getServerMonitorList(ServerMonitorEntity entity) {
try {
List<String> list = new ServerMonitorService().initSystemInfo();
return AjaxResult.success("success", list);
} catch (Exception e) {
logger.error("服务器状态监测", e);
return AjaxResult.error("error");
}
}
/**
* @return com.securityControl.common.core.web.domain.AjaxResult
* @author cw chen
* @description 添加资源状态监测-设备状态监测
* @Param entity
* @date 2023-05-31 16:34
*/
@PostMapping(value = "addResourceData")
public AjaxResult addResourceData(ResourceMonitorEntity entity) {
try {
if (StringUtils.isBlank(entity.getCreateDate())) {
entity.setCreateDate(DateTimeHelper.getNowDate());
}
entity.setCreateTime(DateTimeHelper.getNowTime());
service.addResourceData(entity);
return AjaxResult.success("添加成功");
} catch (Exception e) {
logger.error("资源状态监测-设备状态监测", e);
return AjaxResult.error("服务异常,请稍后重试");
}
}
/**
* @return java.util.Map<java.lang.String, java.lang.Object>
* @author cw chen
* @description 告警记录列表
* @Param entity
* @date 2023-06-02 9:56
*/
@PostMapping(value = "getAlarmRecordList")
@Log(title = "告警记录", menu = "告警记录->告警记录列表", businessType = BusinessType.QUERY, details = "告警记录列表")
public Map<String, Object> getAlarmRecordList(ResourceMonitorEntity entity) {
if (StringUtils.isBlank(entity.getCreateDate())) {
entity.setCreateDate(DateTimeHelper.getNowDate());
}
PageHelper.startPage(Integer.parseInt(entity.getPage()), Integer.parseInt(entity.getLimit()));
Map<String, Object> map = new HashMap<String, Object>(16);
try {
PageInfo<ResourceMonitorEntity> pageInfo = service.getAlarmRecordList(entity);
map.put("code", 200);
map.put("msg", "获取数据成功");
map.put("count", pageInfo.getTotal());
map.put("curr", Integer.parseInt(entity.getPage()));
map.put("limit", Integer.parseInt(entity.getLimit()));
map.put("data", pageInfo.getList());
} catch (Exception e) {
map.put("code", 500);
map.put("msg", "获取数据失败");
map.put("count", 0);
map.put("curr", Integer.parseInt(entity.getPage()));
map.put("limit", Integer.parseInt(entity.getLimit()));
map.put("data", null);
logger.error("数据获取失败", e);
}
return map;
}
/**
* @return void
* @author cw chen
* @description 告警记录列表导出
* @Param request
* @Param response
* @Param entity
* @date 2023-06-05 16:14
*/
@GetMapping(value = "exportData")
@Log(title = "告警记录列表导出", menu = "告警记录->告警记录列表", businessType = BusinessType.EXPORT, details = "告警记录列表导出", grade = OperationType.EXPORT_BUSINESS)
public void exportData(HttpServletRequest request, HttpServletResponse response, ResourceMonitorEntity entity) {
if (StringUtils.isBlank(entity.getCreateDate())) {
entity.setCreateDate(DateTimeHelper.getNowDate());
}
List<ResourceMonitorEntity> list = new ArrayList<>();
try {
PageInfo<ResourceMonitorEntity> pageInfo = service.getAlarmRecordList(entity);
list = pageInfo.getList();
for (int i = 0; i < list.size(); i++) {
list.get(i).setId((i + 1) + "");
}
ExportParams exportParams = new ExportParams("告警记录", "告警记录", ExcelType.XSSF);
exportParams.setStyle(ExcelStyleUtil.class);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, ResourceMonitorEntity.class, list);
response.setHeader("content-disposition", "attachment;fileName=" + URLEncoder.encode("告警记录" + ".xlsx", "UTF-8"));
response.reset();
ServletOutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
outputStream.close();
workbook.close();
} catch (Exception e) {
logger.error("告警记录导出", e);
}
}
}