|
|
@@ -1,16 +1,28 @@
|
|
|
package com.ufo.project.alarm.controller;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
-import com.github.pagehelper.PageHelper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
@@ -19,13 +31,19 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
import com.ufo.base.framework.aspectj.lang.annotation.Log;
|
|
|
import com.ufo.base.framework.aspectj.lang.enums.BusinessType;
|
|
|
import com.ufo.project.alarm.domain.AlarmEventRecord;
|
|
|
-import com.ufo.project.alarm.domain.vo.AlarmEventRecordExportStat;
|
|
|
+import com.ufo.project.alarm.domain.AlarmEventTemplate;
|
|
|
+import com.ufo.project.alarm.domain.enums.AlarmEventRecordStatus;
|
|
|
import com.ufo.project.alarm.service.IAlarmEventRecordService;
|
|
|
+import com.ufo.project.alarm.service.IAlarmEventTemplateService;
|
|
|
+import com.ufo.project.alarm.vo.request.AlarmRecordQueryRequest;
|
|
|
+import com.ufo.project.alarm.vo.response.AlarmRecordVo;
|
|
|
import com.ufo.base.framework.web.controller.BaseController;
|
|
|
import com.ufo.base.framework.web.domain.AjaxResult;
|
|
|
-import com.ufo.base.common.utils.DictUtils;
|
|
|
import com.ufo.base.common.utils.poi.ExcelUtil;
|
|
|
+import com.ufo.base.framework.web.page.PageDomain;
|
|
|
import com.ufo.base.framework.web.page.TableDataInfo;
|
|
|
+import com.ufo.module.system.domain.SysDictData;
|
|
|
+import com.ufo.module.system.service.ISysDictTypeService;
|
|
|
|
|
|
/**
|
|
|
* 报警信息统计Controller
|
|
|
@@ -39,6 +57,13 @@ public class AlarmEventRecordController extends BaseController
|
|
|
{
|
|
|
@Autowired
|
|
|
private IAlarmEventRecordService alarmEventRecordService;
|
|
|
+ @Autowired
|
|
|
+ private IAlarmEventTemplateService alarmEventTemplateService;
|
|
|
+ @Autowired
|
|
|
+ private ISysDictTypeService dictTypeService;
|
|
|
+ private final static String DICT_ALARM_CATEGORY = "alarm_category";
|
|
|
+ private final static String DICT_ALARM_LEVEL = "alarm_level";
|
|
|
+ private final static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");;
|
|
|
|
|
|
/**
|
|
|
* 查询事件列表
|
|
|
@@ -48,12 +73,20 @@ public class AlarmEventRecordController extends BaseController
|
|
|
*/
|
|
|
@PreAuthorize("@ss.hasPermi('alarm:eventRecord:list')")
|
|
|
@PostMapping("/list")
|
|
|
- public TableDataInfo list(@RequestBody JSONObject params)
|
|
|
+ public TableDataInfo list(@RequestBody AlarmRecordQueryRequest request)
|
|
|
{
|
|
|
- AlarmEventRecord query = buildQuery(params);
|
|
|
- PageHelper.startPage(params.getIntValue("pageNum", 1), params.getIntValue("pageSize", 10));
|
|
|
- List<AlarmEventRecord> list = alarmEventRecordService.selectAlarmEventRecordList(query);
|
|
|
- return getDataTable(list);
|
|
|
+ LambdaQueryWrapper<AlarmEventRecord> query = buildQuery(request);
|
|
|
+ PageDomain pageDomain = getRequestCommonParams();
|
|
|
+ IPage<AlarmEventRecord> page = alarmEventRecordService.page(new Page<AlarmEventRecord>(pageDomain.getPageNum(), pageDomain.getPageSize()), query);
|
|
|
+
|
|
|
+ Map<String, String> categoryMap = this.getCategoryMap();
|
|
|
+ Map<Integer, String> levelMap = this.getLevelMap();
|
|
|
+ List<Long> templateIds = page.getRecords().stream().map(AlarmEventRecord::getAlarmTemplateId).distinct().collect(Collectors.toList());
|
|
|
+ List<AlarmEventTemplate> templateList = CollectionUtils.isEmpty(templateIds) ? new ArrayList<AlarmEventTemplate>(0) : alarmEventTemplateService.listByIds(templateIds);
|
|
|
+ Map<Long, AlarmEventTemplate> templateMap = templateList.stream().collect(Collectors.toMap(AlarmEventTemplate::getId, Function.identity()));
|
|
|
+
|
|
|
+ List<AlarmRecordVo> list = page.getRecords().stream().map(r -> this.convert2Vo(r, levelMap, categoryMap, templateMap)).collect(Collectors.toList());
|
|
|
+ return getDataTable(page, list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -67,17 +100,13 @@ public class AlarmEventRecordController extends BaseController
|
|
|
public AjaxResult process(@RequestBody JSONObject params)
|
|
|
{
|
|
|
JSONArray idsArr = params.getJSONArray("ids");
|
|
|
- List<String> ids = idsArr == null ? null : idsArr.toJavaList(String.class);
|
|
|
+ List<Long> ids = idsArr == null ? null : idsArr.toJavaList(Long.class);
|
|
|
if (ids == null || ids.isEmpty())
|
|
|
{
|
|
|
return error("请选择要处理的告警数据");
|
|
|
}
|
|
|
- int rows = alarmEventRecordService.processAlarmEventRecord(ids);
|
|
|
- if (rows == 0)
|
|
|
- {
|
|
|
- return success("所选告警均已处理, 未执行处理");
|
|
|
- }
|
|
|
- return success("已处理 " + rows + " 条告警");
|
|
|
+ alarmEventRecordService.processAlarmEventRecord(ids);
|
|
|
+ return success("已处理 " + ids.size() + " 条告警");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -88,22 +117,21 @@ public class AlarmEventRecordController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('alarm:eventRecord:export')")
|
|
|
@Log(title = "事件查询", businessType = BusinessType.EXPORT)
|
|
|
@PostMapping("/export")
|
|
|
- public void export(HttpServletResponse response, @RequestBody JSONObject params)
|
|
|
+ public void export(HttpServletResponse response, @RequestBody AlarmRecordQueryRequest request)
|
|
|
{
|
|
|
- AlarmEventRecord query = buildQuery(params);
|
|
|
- List<AlarmEventRecord> list = alarmEventRecordService.selectAlarmEventRecordList(query);
|
|
|
- List<AlarmEventRecordExportStat> exportList = new ArrayList<>();
|
|
|
- for (AlarmEventRecord record : list)
|
|
|
- {
|
|
|
- exportList.add(new AlarmEventRecordExportStat(
|
|
|
- dictLabel("alarm_level", record.getAlarmLevel() == null ? null : String.valueOf(record.getAlarmLevel())),
|
|
|
- dictLabel("alarm_category", record.getAlarmCategory()),
|
|
|
- record.getAlarmData(),
|
|
|
- processFlagLabel(record.getProcessFlag()),
|
|
|
- record.getAlarmCreateTime()));
|
|
|
- }
|
|
|
- ExcelUtil<AlarmEventRecordExportStat> util = new ExcelUtil<AlarmEventRecordExportStat>(AlarmEventRecordExportStat.class);
|
|
|
- util.exportExcel(response, exportList, "事件查询数据");
|
|
|
+ LambdaQueryWrapper<AlarmEventRecord> query = buildQuery(request);
|
|
|
+ List<AlarmEventRecord> list = alarmEventRecordService.list(query);
|
|
|
+
|
|
|
+ Map<String, String> categoryMap = this.getCategoryMap();
|
|
|
+ Map<Integer, String> levelMap = this.getLevelMap();
|
|
|
+ List<Long> templateIds = list.stream().map(AlarmEventRecord::getAlarmTemplateId).distinct().collect(Collectors.toList());
|
|
|
+ List<AlarmEventTemplate> templateList = CollectionUtils.isEmpty(templateIds) ? new ArrayList<AlarmEventTemplate>(0) : alarmEventTemplateService.listByIds(templateIds);
|
|
|
+ Map<Long, AlarmEventTemplate> templateMap = templateList.stream().collect(Collectors.toMap(AlarmEventTemplate::getId, Function.identity()));
|
|
|
+
|
|
|
+ List<AlarmRecordVo> voList = list.stream().map(r -> this.convert2Vo(r, levelMap, categoryMap, templateMap)).collect(Collectors.toList());
|
|
|
+
|
|
|
+ ExcelUtil<AlarmRecordVo> util = new ExcelUtil<AlarmRecordVo>(AlarmRecordVo.class);
|
|
|
+ util.exportExcel(response, voList, "事件查询数据");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -113,29 +141,8 @@ public class AlarmEventRecordController extends BaseController
|
|
|
@GetMapping(value = "/{id}")
|
|
|
public AjaxResult getInfo(@PathVariable("id") String id)
|
|
|
{
|
|
|
- return success(alarmEventRecordService.selectAlarmEventRecordById(id));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 新增报警信息统计
|
|
|
- */
|
|
|
- @PreAuthorize("@ss.hasPermi('alarm:eventRecord:add')")
|
|
|
- @Log(title = "报警信息统计", businessType = BusinessType.INSERT)
|
|
|
- @PostMapping
|
|
|
- public AjaxResult add(@RequestBody AlarmEventRecord alarmEventRecord)
|
|
|
- {
|
|
|
- return toAjax(alarmEventRecordService.insertAlarmEventRecord(alarmEventRecord));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 修改报警信息统计
|
|
|
- */
|
|
|
- @PreAuthorize("@ss.hasPermi('alarm:eventRecord:edit')")
|
|
|
- @Log(title = "报警信息统计", businessType = BusinessType.UPDATE)
|
|
|
- @PutMapping
|
|
|
- public AjaxResult edit(@RequestBody AlarmEventRecord alarmEventRecord)
|
|
|
- {
|
|
|
- return toAjax(alarmEventRecordService.updateAlarmEventRecord(alarmEventRecord));
|
|
|
+ AlarmEventRecord record = alarmEventRecordService.getById(id);
|
|
|
+ return success(this.convert2Vo(record));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -144,53 +151,87 @@ public class AlarmEventRecordController extends BaseController
|
|
|
@PreAuthorize("@ss.hasPermi('alarm:eventRecord:remove')")
|
|
|
@Log(title = "报警信息统计", businessType = BusinessType.DELETE)
|
|
|
@DeleteMapping("/{ids}")
|
|
|
- public AjaxResult remove(@PathVariable String[] ids)
|
|
|
+ public AjaxResult remove(@PathVariable Long[] ids)
|
|
|
{
|
|
|
- return toAjax(alarmEventRecordService.deleteAlarmEventRecordByIds(ids));
|
|
|
+ alarmEventRecordService.deleteAlarmEventRecordByIds(ids);
|
|
|
+ return toAjax(ids.length);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 构建查询条件
|
|
|
*/
|
|
|
- private AlarmEventRecord buildQuery(JSONObject params)
|
|
|
+ private LambdaQueryWrapper<AlarmEventRecord> buildQuery(AlarmRecordQueryRequest request)
|
|
|
{
|
|
|
- AlarmEventRecord query = new AlarmEventRecord();
|
|
|
- query.setAlarmCategory(params.getString("alarmCategory"));
|
|
|
- query.setAlarmLevel(params.getLong("alarmLevel"));
|
|
|
- query.setProcessStatus(params.getBoolean("processStatus"));
|
|
|
- query.setAlarmDate(params.getString("alarmDate"));
|
|
|
+
|
|
|
+ LambdaQueryWrapper<AlarmEventRecord> query = Wrappers.<AlarmEventRecord>lambdaQuery()
|
|
|
+ .orderByDesc(AlarmEventRecord::getAlarmTime)
|
|
|
+ .orderByDesc(AlarmEventRecord::getId);
|
|
|
+ if(null != request.getAlarmCategory()){
|
|
|
+ List<AlarmEventTemplate> templates = alarmEventTemplateService.list(Wrappers.<AlarmEventTemplate>lambdaQuery().eq(AlarmEventTemplate::getCategory, request.getAlarmCategory()));
|
|
|
+ if(CollectionUtils.isEmpty(templates)){
|
|
|
+ query.eq(AlarmEventRecord::getId, -1l);
|
|
|
+ }else{
|
|
|
+ query.in(AlarmEventRecord::getAlarmTemplateId, templates.stream().map(AlarmEventTemplate::getId).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(null != request.getAlarmLevel()){
|
|
|
+ query.eq(AlarmEventRecord::getAlarmLevel, request.getAlarmLevel());
|
|
|
+ }
|
|
|
+ if(null != request.getProcessStatus()){
|
|
|
+ if(request.getProcessStatus()){
|
|
|
+ query.eq(AlarmEventRecord::getStatus, AlarmEventRecordStatus.CONFIRMED);
|
|
|
+ } else {
|
|
|
+ query.ne(AlarmEventRecord::getStatus, AlarmEventRecordStatus.CONFIRMED);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(null != request.getAlarmDate()){
|
|
|
+ LocalDateTime startOfDay = request.getAlarmDate().atStartOfDay();
|
|
|
+ LocalDateTime endOfDay = request.getAlarmDate().atTime(23, 59, 59);
|
|
|
+ query.ge(AlarmEventRecord::getAlarmTime, startOfDay).le(AlarmEventRecord::getAlarmTime, endOfDay);
|
|
|
+ }
|
|
|
return query;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 字典值转标签(无匹配时返回空串)
|
|
|
- */
|
|
|
- private String dictLabel(String dictType, String dictValue)
|
|
|
+ private AlarmRecordVo convert2Vo(AlarmEventRecord record, Map<Integer, String> levelMap, Map<String, String> categoryMap, Map<Long, AlarmEventTemplate> templateMap)
|
|
|
{
|
|
|
- if (dictValue == null || dictValue.isEmpty())
|
|
|
- {
|
|
|
- return "";
|
|
|
+ AlarmRecordVo vo = new AlarmRecordVo().setId(record.getId())
|
|
|
+ .setAlarmLevel(levelMap.get(record.getAlarmLevel()))
|
|
|
+ .setAlarmCategory(categoryMap.get(templateMap.get(record.getAlarmTemplateId()).getCategory()))
|
|
|
+ .setProcessFlag(record.getStatus().getDesc())
|
|
|
+ .setAlarmDate(record.getAlarmTime().format(formatter));
|
|
|
+ JSONObject jo = JSON.parseObject(record.getAlarmContent());
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ int i = 0;
|
|
|
+ for (String key : jo.keySet()) {
|
|
|
+ if(i > 0){
|
|
|
+ builder.append(";");
|
|
|
+ }
|
|
|
+ builder.append(jo.getString(key));
|
|
|
+ i++;
|
|
|
}
|
|
|
- String label = DictUtils.getDictLabel(dictType, dictValue);
|
|
|
- return label == null ? "" : label;
|
|
|
+ vo.setAlarmData(builder.toString());
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ private AlarmRecordVo convert2Vo(AlarmEventRecord record){
|
|
|
+ Map<String, String> categoryMap = this.getCategoryMap();
|
|
|
+ Map<Integer, String> levelMap = this.getLevelMap();
|
|
|
+ AlarmEventTemplate template = alarmEventTemplateService.getById(record.getAlarmTemplateId());
|
|
|
+ AlarmRecordVo vo = new AlarmRecordVo().setId(record.getId())
|
|
|
+ .setAlarmLevel(levelMap.get(record.getAlarmLevel()))
|
|
|
+ .setAlarmCategory(categoryMap.get(template.getCategory()))
|
|
|
+ .setProcessFlag(record.getStatus().getDesc())
|
|
|
+ .setAlarmDate(record.getAlarmTime().format(formatter));
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 处理状态转文案: 0未处理/1处理中/2已处理/3误报
|
|
|
- */
|
|
|
- private String processFlagLabel(Long processFlag)
|
|
|
+ private Map<Integer, String> getLevelMap()
|
|
|
{
|
|
|
- if (processFlag == null)
|
|
|
- {
|
|
|
- return "";
|
|
|
- }
|
|
|
- switch (processFlag.intValue())
|
|
|
- {
|
|
|
- case 0: return "未处理";
|
|
|
- case 1: return "处理中";
|
|
|
- case 2: return "已处理";
|
|
|
- case 3: return "误报";
|
|
|
- default: return String.valueOf(processFlag);
|
|
|
- }
|
|
|
+ List<SysDictData> dictDataList = dictTypeService.selectDictDataByType(DICT_ALARM_LEVEL);
|
|
|
+ return dictDataList.stream().collect(Collectors.toMap(r -> Integer.parseInt(r.getDictValue()), r -> r.getDictLabel()));
|
|
|
+ }
|
|
|
+ private Map<String, String> getCategoryMap()
|
|
|
+ {
|
|
|
+ List<SysDictData> dictDataList = dictTypeService.selectDictDataByType(DICT_ALARM_CATEGORY);
|
|
|
+ return dictDataList.stream().collect(Collectors.toMap(r -> r.getDictValue(), r -> r.getDictLabel()));
|
|
|
}
|
|
|
}
|