Browse Source

修复报警重复转工单的校验问题

lixing 2 years ago
parent
commit
b89357bc3e

+ 33 - 24
src/main/java/com/persagy/apm/alarmservice/group/alarmrecord/controller/AlarmRecordController.java

@@ -2,9 +2,9 @@ package com.persagy.apm.alarmservice.group.alarmrecord.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.persagy.apm.alarmservice.group.alarmrecord.enums.EnumDownloadAlarmListType;
 import com.persagy.apm.alarmservice.group.alarmrecord.enums.EnumAlarmTreatMode;
 import com.persagy.apm.alarmservice.group.alarmrecord.enums.EnumAlarmTreatState;
+import com.persagy.apm.alarmservice.group.alarmrecord.enums.EnumDownloadAlarmListType;
 import com.persagy.apm.alarmservice.group.alarmrecord.model.ConvertAlarmRecordTool;
 import com.persagy.apm.alarmservice.group.alarmrecord.model.dto.*;
 import com.persagy.apm.alarmservice.group.alarmrecord.model.vo.AlarmRecordIdsItem;
@@ -22,7 +22,6 @@ import com.persagy.apm.common.response.PageList;
 import com.persagy.apm.common.utils.ResultHelper;
 import com.persagy.apm.energyalarmstarter.alarmdata.enums.EnumAlarmListType;
 import com.persagy.apm.energyalarmstarter.alarmdata.feign.DmpResult;
-import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmrecord.AddAlarmRecordDTO;
 import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmrecord.BatchUpdateAlarmRecordDTO;
 import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmrecord.QueryAlarmRecordDTO;
 import com.persagy.apm.energyalarmstarter.alarmdata.model.dto.alarmrecord.UpdateAlarmRecordDTO;
@@ -199,7 +198,7 @@ public class AlarmRecordController {
         String treatState = EnumAlarmTreatState.DONE.getType();
         List<String> recordIds = closeAlarmRecordDTO.getIds();
 
-        return updateAlarmRecordTreatState(treatMode, treatState,null,null, recordIds);
+        return updateAlarmRecordTreatState(treatMode, treatState, null, null, recordIds);
     }
 
     /**
@@ -212,7 +211,8 @@ public class AlarmRecordController {
      * @author lixing
      * @version V1.0 2021/9/20 7:25 下午
      */
-    private CommonResult<AlarmRecordIdsItem> updateAlarmRecordTreatState(String treatMode, String treatState,
+    private CommonResult<AlarmRecordIdsItem> updateAlarmRecordTreatState(
+            String treatMode, String treatState,
             String orderId, String orderState, List<String> recordIds) throws Exception {
         AlarmRecordIdsItem alarmRecordIdsItem = new AlarmRecordIdsItem();
 
@@ -226,10 +226,10 @@ public class AlarmRecordController {
             updateAlarmRecordDTO.setId(recordId);
             updateAlarmRecordDTO.setTreatMode(Integer.valueOf(treatMode));
             updateAlarmRecordDTO.setTreatState(Integer.valueOf(treatState));
-            if (!StringUtils.isEmpty(orderId)){
+            if (!StringUtils.isEmpty(orderId)) {
                 updateAlarmRecordDTO.setOrderId(orderId);
             }
-            if (!StringUtils.isEmpty(orderState)){
+            if (!StringUtils.isEmpty(orderState)) {
                 updateAlarmRecordDTO.setOrderState(orderState);
             }
             updateAlarmRecordDTOList.add(updateAlarmRecordDTO);
@@ -246,12 +246,21 @@ public class AlarmRecordController {
     @PostMapping("/convert_work_order")
     public CommonResult<AlarmRecordIdsItem> alarmRecordConvertWorkOrder(
             @Valid @RequestBody AlarmRecordConvertWorkOrderDTO alarmRecordConvertWorkOrderDTO) throws Exception {
+        // 判断报警是否已经转工单
+        List<String> recordIds = alarmRecordConvertWorkOrderDTO.getIds();
+        QueryAlarmRecordDTO queryAlarmRecordDTO = new QueryAlarmRecordDTO();
+        queryAlarmRecordDTO.setId(recordIds);
+        DmpResult<List<AlarmRecordItem>> queryResult = alarmRecordService.query(queryAlarmRecordDTO);
+        List<AlarmRecordItem> alarmRecordItems = queryResult.getData();
+        if (alarmRecordItems.stream().anyMatch(alarmRecordItem -> alarmRecordItem.getOrderId() != null)) {
+            throw new RuntimeException("报警已经转过工单");
+        }
+
         // 报警处理方式更新为转工单,报警状态更新为处理中
         String treatMode = EnumAlarmTreatMode.ORDER.getType();
         String treatState = EnumAlarmTreatState.HANDLING.getType();
-        List<String> recordIds = alarmRecordConvertWorkOrderDTO.getIds();
 
-        return updateAlarmRecordTreatState(treatMode, treatState,alarmRecordConvertWorkOrderDTO.getOrderId(),alarmRecordConvertWorkOrderDTO.getOrderState(), recordIds);
+        return updateAlarmRecordTreatState(treatMode, treatState, alarmRecordConvertWorkOrderDTO.getOrderId(), alarmRecordConvertWorkOrderDTO.getOrderState(), recordIds);
     }
 
 
@@ -264,7 +273,7 @@ public class AlarmRecordController {
         String treatState = EnumAlarmTreatState.DONE.getType();
         List<String> recordIds = ignoreAlarmRecordDTO.getIds();
 
-        return updateAlarmRecordTreatState(treatMode, treatState,null,null, recordIds);
+        return updateAlarmRecordTreatState(treatMode, treatState, null, null, recordIds);
     }
 
     @ApiOperation(value = "报警详情")
@@ -335,9 +344,9 @@ public class AlarmRecordController {
     /**
      * 下载报警记录列表
      *
-     * @param response            response对象
-     * @param enumDownloadAlarmListType   列表类型
-     * @param alarmRecordItemVOList 要下载的列表
+     * @param response                  response对象
+     * @param enumDownloadAlarmListType 列表类型
+     * @param alarmRecordItemVOList     要下载的列表
      * @author lixing
      * @version V1.0 2021/10/19 7:22 下午
      */
@@ -379,18 +388,18 @@ public class AlarmRecordController {
     @PostMapping("/test")
     public void test() {
         groupManagementService.getEquipList(null, "ACCCOT");
-//        AddAlarmRecordDTO addAlarmRecordDTO = new AddAlarmRecordDTO();
-//        addAlarmRecordDTO.setId("1234");
-//        addAlarmRecordDTO.setTriggerTime(new Date());
-//        addAlarmRecordDTO.setObjId("123");
-//        addAlarmRecordDTO.setName("test");
-//        addAlarmRecordDTO.setItemCode("123");
-//        addAlarmRecordDTO.setLevel("1");
-//        try {
-//            alarmRecordService.create(addAlarmRecordDTO);
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//        }
+        //        AddAlarmRecordDTO addAlarmRecordDTO = new AddAlarmRecordDTO();
+        //        addAlarmRecordDTO.setId("1234");
+        //        addAlarmRecordDTO.setTriggerTime(new Date());
+        //        addAlarmRecordDTO.setObjId("123");
+        //        addAlarmRecordDTO.setName("test");
+        //        addAlarmRecordDTO.setItemCode("123");
+        //        addAlarmRecordDTO.setLevel("1");
+        //        try {
+        //            alarmRecordService.create(addAlarmRecordDTO);
+        //        } catch (Exception e) {
+        //            e.printStackTrace();
+        //        }
     }
 }
 

+ 1 - 1
src/main/resources/bootstrap.yml

@@ -21,7 +21,7 @@ spring:
           data: classpath*:db/init/data.sql
           continue-on-error: true
           # MYSQL_SCHEMA建议使用默认值。如果有特殊需求,建议在环境变量中配置该值
-          url: jdbc:mysql://${persagy.mysql.ip}:${persagy.mysql.port}/${MYSQL_SCHEMA_ALARM_SERVICE:dmp_alarm}?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
+          url: jdbc:mysql://${persagy.mysql.ip}:${persagy.mysql.port}/${MYSQL_SCHEMA_ALARM_SERVICE:energy_alarm}?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
           username: ${MYSQL_USERNAME:${spring.datasource.username}}
           password: ${MYSQL_PASSWORD:${spring.datasource.password}}
           driver-class-name: com.mysql.cj.jdbc.Driver