lixing 4 роки тому
батько
коміт
cc3c739506

+ 12 - 0
pom.xml

@@ -78,6 +78,18 @@
             <version>1.0.0</version>
         </dependency>
 
+        <!--rabbitmq -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-starter-logging</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+
         <!-- websocket -->
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 83 - 0
src/main/java/com/persagy/dmp/starter/alarm/AutoConfiguration.java

@@ -1,7 +1,23 @@
 package com.persagy.dmp.starter.alarm;
 
+import com.alibaba.fastjson.PropertyNamingStrategy;
+import com.alibaba.fastjson.serializer.SerializeConfig;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.alibaba.fastjson.support.config.FastJsonConfig;
+import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
+import org.springframework.beans.factory.ObjectFactory;
+import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
+import org.springframework.cloud.openfeign.support.ResponseEntityDecoder;
+import org.springframework.cloud.openfeign.support.SpringDecoder;
+import org.springframework.cloud.openfeign.support.SpringEncoder;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.http.MediaType;
+import org.springframework.http.converter.HttpMessageConverter;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * @description: 配置类
@@ -13,4 +29,71 @@ import org.springframework.context.annotation.Configuration;
 @Configuration
 @ComponentScan(value = "com.persagy.dmp.starter.alarm")
 public class AutoConfiguration {
+    @Bean
+    public ResponseEntityDecoder feignDecoder() {
+        HttpMessageConverter fastJsonConverter = createFastJsonConverter();
+        ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(fastJsonConverter);
+        return new ResponseEntityDecoder(new SpringDecoder(objectFactory));
+    }
+
+    @Bean
+    public SpringEncoder feignEncoder(){
+        HttpMessageConverter fastJsonConverter = createFastJsonConverter();
+        ObjectFactory<HttpMessageConverters> objectFactory = () -> new HttpMessageConverters(fastJsonConverter);
+        return new SpringEncoder(objectFactory);
+    }
+
+    /**
+     * Description: 添加支持的类型
+     *
+     * @return List<MediaType>
+     * @author luoguangyi
+     * @since 2019年9月3日: 下午6:20:33 Update By luoguangyi 2019年9月3日: 下午6:20:33
+     */
+    private HttpMessageConverter createFastJsonConverter() {
+        //===========替换框架json为fastjson
+        FastJsonHttpMessageConverter fastConverter = new FastJsonHttpMessageConverter();
+        List<MediaType> supportedMediaTypes = new ArrayList<>();
+        supportedMediaTypes.add(MediaType.APPLICATION_JSON);
+        supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
+        supportedMediaTypes.add(MediaType.APPLICATION_ATOM_XML);
+        supportedMediaTypes.add(MediaType.APPLICATION_FORM_URLENCODED);
+        supportedMediaTypes.add(MediaType.APPLICATION_OCTET_STREAM);
+        supportedMediaTypes.add(MediaType.APPLICATION_PDF);
+        supportedMediaTypes.add(MediaType.APPLICATION_RSS_XML);
+        supportedMediaTypes.add(MediaType.APPLICATION_XHTML_XML);
+        supportedMediaTypes.add(MediaType.APPLICATION_XML);
+        supportedMediaTypes.add(MediaType.IMAGE_GIF);
+        supportedMediaTypes.add(MediaType.IMAGE_JPEG);
+        supportedMediaTypes.add(MediaType.IMAGE_PNG);
+        supportedMediaTypes.add(MediaType.TEXT_EVENT_STREAM);
+        supportedMediaTypes.add(MediaType.TEXT_HTML);
+        supportedMediaTypes.add(MediaType.TEXT_MARKDOWN);
+        supportedMediaTypes.add(MediaType.TEXT_PLAIN);
+        supportedMediaTypes.add(MediaType.TEXT_XML);
+        fastConverter.setSupportedMediaTypes(supportedMediaTypes);
+
+        //创建配置类
+        FastJsonConfig fastJsonConfig = new FastJsonConfig();
+        //---下划线转驼峰
+        SerializeConfig serializeConfig = new SerializeConfig();
+        serializeConfig.propertyNamingStrategy = PropertyNamingStrategy.CamelCase;
+        fastJsonConfig.setSerializeConfig(serializeConfig);
+        //---序列化格式
+        fastJsonConfig.setSerializerFeatures(
+                SerializerFeature.PrettyFormat,
+                SerializerFeature.WriteDateUseDateFormat,
+                // List字段如果为null,输出为[],而非null
+                SerializerFeature.WriteNullListAsEmpty,
+                // 是否显示为null的字段,加上会显示,取消就不会显示为空的字段
+                // SerializerFeature.WriteMapNullValue,
+                // 禁止循环引用
+                SerializerFeature.DisableCircularReferenceDetect
+                // SerializerFeature.WriteNullStringAsEmpty
+        );
+        fastJsonConfig.setDateFormat("yyyyMMddHHmmss");
+        fastConverter.setFastJsonConfig(fastJsonConfig);
+
+        return fastConverter;
+    }
 }

+ 0 - 1
src/main/java/com/persagy/dmp/starter/alarm/aspect/AlarmClientAspect.java

@@ -26,7 +26,6 @@ public class AlarmClientAspect {
 
     @Before("feignPointCut()")
     public void before() {
-        System.out.println("before");
     }
 
     @AfterReturning(returning = "res", pointcut = "feignPointCut()")

+ 55 - 0
src/main/java/com/persagy/dmp/starter/alarm/communication/mq/DmpMessage.java

@@ -0,0 +1,55 @@
+package com.persagy.dmp.starter.alarm.communication.mq;
+
+import com.alibaba.fastjson.JSONObject;
+import lombok.Data;
+
+/**
+ * @description:中台消息队列格式
+ * @author:LuoGuangyi
+ * @company:PersagyTechnologyCo.,Ltd
+ * @since:2020/10/28 002816:10
+ * @version:V1.0
+ **/
+@Data
+public class DmpMessage {
+    private String mid;
+    /**
+     *  type = alarmConfigsChange
+     *  报警消息变化
+     */
+    private String type;
+    private String groupCode;
+    private String projectId;
+    private String targetId;
+    private Integer int1;
+    private Integer int2;
+    private String str1;
+    private String str2;
+    private String sendTime;
+    private String expireTime;
+    private String appId;
+    private String userId;
+    /**
+     * 分别存放新增和修改的报警定义条目
+     * {
+     *     "createdConfigUniques": [
+     *         {
+     *             "itemCode": "报警条目编码",
+     *             "objId": "对象id"
+     *         }
+     *     ],
+     *     "deletedConfigUniques": [
+     *         {
+     *             "itemCode": "报警条目编码",
+     *             "objId": "对象id"
+     *         }
+     *     ]
+     * }
+     */
+    private JSONObject exts;
+
+    @Override
+    public String toString() {
+        return JSONObject.toJSONString(this);
+    }
+}

+ 84 - 0
src/main/java/com/persagy/dmp/starter/alarm/communication/mq/JmsConfig.java

@@ -0,0 +1,84 @@
+package com.persagy.dmp.starter.alarm.communication.mq;
+
+import com.persagy.dmp.starter.alarm.communication.netty.NettyAlarmMsgBaseHandler;
+import com.persagy.zkt.utils.StringUtil;
+import com.rabbitmq.client.Channel;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.core.*;
+import org.springframework.amqp.rabbit.annotation.RabbitHandler;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @description:报警定义消息通知
+ * @author:LuoGuangyi
+ * @company:PersagyTechnologyCo.,Ltd
+ * @since:2020/10/20 002016:30
+ * @version:V1.0
+ **/
+@Slf4j
+@Configuration
+public class JmsConfig {
+
+	/**
+	 * NettyAlarmMsgBaseHandler本身不进行ioc注入,这里注入的是他的子类。
+	 * 子类在实际项目中创建,starter中没有实例。
+	 */
+	@Autowired
+	private NettyAlarmMsgBaseHandler msgHandler;
+	/**
+	 * 报警定义变化类型
+	 */
+	private static final String ALARM_CONFIGS_CHANGE = "alarmConfigsChange";
+	/**
+	 * 报警交换器
+	 */
+	@Value("${dmp.alarm.exchange}")
+	private String exchange;
+	/**
+	 * 报警路由键
+	 */
+	@Value("${dmp.alarm.routingKey}")
+	private String alarmRoutingKey;
+	/**
+	 * 报警队列
+	 */
+	@Value("${dmp.alarm.queue}")
+	private String alarmQueue;
+
+
+	@Bean
+	public Queue queue() {
+		return new Queue(alarmQueue, true);
+	}
+
+	@Bean
+	public TopicExchange exchange() {
+		return new TopicExchange(exchange);
+	}
+
+	@Bean
+	public Binding alarmBinding() {
+		return BindingBuilder.bind(queue()).to(exchange()).with(alarmRoutingKey);
+	}
+
+	@RabbitHandler
+	@RabbitListener(queues = "${dmp.alarm.queue}")
+	public void planQueues(String msg, Channel channel, Message message) throws Exception {
+		log.info("============================== Receive:" + msg);
+		DmpMessage dmpMessage = StringUtil.tranferItemToDTO(msg, DmpMessage.class);
+		//报警定义变化
+		if(ALARM_CONFIGS_CHANGE.equals(dmpMessage.getType())){
+			log.info("================收到一条报警定义变化通知==============");
+			log.info(msg.toString());
+			try {
+				msgHandler.incrementSyncAlarmConfig(dmpMessage);
+			} catch (Exception e) {
+				log.error("error",e);
+			}
+		}
+	}
+}

+ 27 - 1
src/main/java/com/persagy/dmp/starter/alarm/communication/netty/NettyAlarmMsgBaseHandler.java

@@ -1,7 +1,9 @@
 package com.persagy.dmp.starter.alarm.communication.netty;
 
+import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.persagy.dmp.starter.alarm.communication.mq.DmpMessage;
 import com.persagy.dmp.starter.alarm.service.NettyAlarmService;
 import com.persagy.zkt.utils.StringUtil;
 import io.netty.channel.Channel;
@@ -29,12 +31,12 @@ import java.util.concurrent.ConcurrentHashMap;
 @Slf4j
 public class NettyAlarmMsgBaseHandler extends ChannelInboundHandlerAdapter {
 
+    private NettyAlarmService nettyAlarmService;
     /**
      * 装每个客户端的地址及对应的管道
      */
     public Map<String, Channel> socketChannelMap = new ConcurrentHashMap<>();
 
-    private NettyAlarmService nettyAlarmService;
 
     /**
      * 保留所有与服务器建立连接的channel对象
@@ -135,6 +137,30 @@ public class NettyAlarmMsgBaseHandler extends ChannelInboundHandlerAdapter {
     }
 
     /**
+     * @description: 增量同步报警定义
+     * @param: dmpMessage
+     * @return: void
+     * @exception:
+     * @author: lixing
+     * @company: Persagy Technology Co.,Ltd
+     * @since: 2020/12/1 11:45 上午
+     * @version: V1.0
+     */
+    public void incrementSyncAlarmConfig(DmpMessage dmpMessage) throws Exception {
+        Map<String, JSONArray> changedAlarmConfigs = nettyAlarmService.queryChangedAlarmConfigs(dmpMessage);
+        JSONArray createdConfigUniques = changedAlarmConfigs.get("createdConfigUniques");
+        JSONArray deletedConfigUniques = changedAlarmConfigs.get("deletedConfigUniques");
+        if (CollectionUtil.isNotEmpty(deletedConfigUniques)) {
+            // 通过netty发送给边缘端 10-云端推送删除的报警定义给边缘端(增量删除报警定义)
+            sendMessage(dmpMessage.getProjectId(), new NettyAlarmMessage(10, deletedConfigUniques).toString());
+        }
+        if (CollectionUtil.isNotEmpty(createdConfigUniques)) {
+            // 通过netty发送给边缘端 7-云端推送修改的报警定义给边缘端(增量新增修改报警定义)
+            sendMessage(dmpMessage.getProjectId(), new NettyAlarmMessage(7, createdConfigUniques).toString());
+        }
+    }
+
+    /**
      * @param channelHandlerContext
      * @param msg
      * @description: 接受客户端收到的数据

+ 0 - 37
src/main/java/com/persagy/dmp/starter/alarm/communication/netty/NettyAlarmMsgHandler.java

@@ -1,37 +0,0 @@
-package com.persagy.dmp.starter.alarm.communication.netty;
-
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import com.persagy.dmp.starter.alarm.service.NettyAlarmService;
-import com.persagy.zkt.utils.StringUtil;
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.channel.group.ChannelGroup;
-import io.netty.channel.group.DefaultChannelGroup;
-import io.netty.util.concurrent.GlobalEventExecutor;
-import lombok.extern.slf4j.Slf4j;
-
-import java.net.SocketAddress;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * @description: Netty报警息处理中心
- * @author: lixing
- * @company: Persagy Technology Co.,Ltd
- * @since: 2020/11/30 10:31 上午
- * @version: V1.0
- */
-@Slf4j
-public class NettyAlarmMsgHandler extends NettyAlarmMsgBaseHandler {
-    private NettyAlarmService nettyAlarmService;
-
-    public NettyAlarmMsgHandler(NettyAlarmService nettyAlarmService) {
-        super(nettyAlarmService);
-//        this.nettyAlarmService = nettyAlarmService;
-    }
-}

+ 2 - 2
src/main/java/com/persagy/dmp/starter/alarm/communication/netty/NettyAlarmServer.java

@@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit;
 @Slf4j
 public class NettyAlarmServer {
     @Autowired
-    private NettyAlarmService nettyAlarmService;
+    private NettyAlarmMsgBaseHandler nettyAlarmMsgBaseHandler;
 
     @Value("${group.alarm.port}")
     public int port;
@@ -79,7 +79,7 @@ public class NettyAlarmServer {
                             ch.pipeline().addLast(new StringDecoder());
                             ch.pipeline().addLast(new StringEncoder());
                             // 为监听客户端read/write事件的Channel添加用户自定义的ChannelHandler
-                            ch.pipeline().addLast(businessGroup, new NettyAlarmMsgHandler(nettyAlarmService));
+                            ch.pipeline().addLast(businessGroup, nettyAlarmMsgBaseHandler);
 
                             // 增加超时检查
                             ch.pipeline().addLast(new IdleStateHandler(10, 0, 0, TimeUnit.SECONDS));

+ 57 - 0
src/main/java/com/persagy/dmp/starter/alarm/feign/AlarmFeignConfig.java

@@ -0,0 +1,57 @@
+package com.persagy.dmp.starter.alarm.feign;
+
+import feign.Feign;
+import feign.Logger;
+import feign.Retryer;
+import feign.querymap.BeanQueryMapEncoder;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @description: Feign配置
+ * @author: xingmaojun
+ * @company: Persagy Technology Co.,Ltd
+ * @since: 2020/10/14 9:15
+ * @version: V1.0
+ **/
+
+@Configuration
+@EnableFeignClients(basePackages = "com.persagy.dmp.starter.alarm.feign.client")
+public class AlarmFeignConfig {
+
+    /**
+     * @description: feign日志配置
+     * @return: feign.Logger.Level
+     * @author: xingmaojun
+     * @company: Persagy Technology Co.,Ltd
+     * @since: 2020/10/21 17:01
+     * @version: V1.0
+     */
+    @Bean
+    Logger.Level alarmFeignLoggerLevel() {
+        //这里记录所有,根据实际情况选择合适的日志level
+        return Logger.Level.FULL;
+    }
+
+    @Bean
+    Logger alarmFeignLogger(){
+        return new AlarmFeignLogger();
+    }
+
+    /**
+     * @description: 替换解析queryMap的类,实现父类中变量的映射
+     * @return: feign.Feign.Builder
+     * @author: xingmaojun
+     * @company: Persagy Technology Co.,Ltd
+     * @since: 2020/10/21 17:01
+     * @version: V1.0
+     */
+    @Bean
+    public Feign.Builder alarmFeignBuilder() {
+        return Feign.builder()
+                .queryMapEncoder(new BeanQueryMapEncoder())
+                .retryer(Retryer.NEVER_RETRY);
+    }
+
+}

+ 136 - 12
src/main/java/com/persagy/dmp/starter/alarm/service/NettyAlarmService.java

@@ -1,13 +1,22 @@
 package com.persagy.dmp.starter.alarm.service;
 
+import cn.hutool.core.collection.CollectionUtil;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.persagy.dmp.starter.alarm.communication.mq.DmpMessage;
 import com.persagy.dmp.starter.alarm.feign.AlarmUrlParam;
 import com.persagy.dmp.starter.alarm.feign.DmpResult;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.CollectionUtils;
 
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
 /**
  * @description: 处理netty消息中调用数据中台的逻辑
  * @author: lixing
@@ -15,6 +24,7 @@ import org.springframework.util.CollectionUtils;
  * @since: 2020/11/30 2:38 下午
  * @version: V1.0
  **/
+@Slf4j
 public abstract class NettyAlarmService {
     @Autowired
     AlarmService alarmService;
@@ -93,12 +103,14 @@ public abstract class NettyAlarmService {
             criteria.remove("onlyCount");
         }
 
-        Integer page = criteria.getInteger("page");
-        Integer size = criteria.getInteger("size");
-        requestBody.put("page", page);
-        requestBody.put("size", size);
-        criteria.remove("page");
-        criteria.remove("size");
+        if (criteria.containsKey("page") && criteria.containsKey("size")) {
+            Integer page = criteria.getInteger("page");
+            Integer size = criteria.getInteger("size");
+            requestBody.put("page", page);
+            requestBody.put("size", size);
+            criteria.remove("page");
+            criteria.remove("size");
+        }
 
         requestBody.put("criteria", criteria);
         return requestBody;
@@ -118,26 +130,68 @@ public abstract class NettyAlarmService {
         DmpResult<JSONArray> queryResult = alarmService.queryAlarmConfig(getAlarmUrlParam(data), getRequestBody(data));
         JSONArray alarmConfigs = queryResult.getData();
         // 报警定义中的信息点转换为表号、功能号
+        initAlarmConfigInfoCodes(alarmConfigs);
+        return alarmConfigs;
+    }
+
+    /**
+     * @description: 报警定义中的信息点转换为表号、功能号
+     * @param: alarmConfigs
+     * @return: void
+     * @exception:
+     * @author: lixing
+     * @company: Persagy Technology Co.,Ltd
+     * @since: 2020/12/1 2:32 下午
+     * @version: V1.0
+     */
+    private void initAlarmConfigInfoCodes(JSONArray alarmConfigs) throws Exception {
+        if (alarmConfigs == null) {
+            return;
+        }
         for (Object alarmConfig : alarmConfigs) {
-            JSONObject config = (JSONObject)alarmConfig;
+            JSONObject config = (JSONObject) alarmConfig;
+            String classCode = config.getString("classCode");
             JSONObject condition = config.getJSONObject("condition");
             JSONArray infoCodeArray = condition.getJSONArray("infoCode");
 
             JSONArray infoCodes = new JSONArray();
             JSONObject infoCode = new JSONObject();
             for (Object infoCodeObj : infoCodeArray) {
-                String infoCodeStr = (String)infoCodeObj;
-                String[] tmp = infoCodeStr.split("_");
+                String infoCodeStr = (String) infoCodeObj;
                 infoCode.put("infoCode", infoCodeStr);
-                infoCode.put("meterId", tmp[0]);
-                infoCode.put("funcId", tmp[1]);
+                infoCode.put("meterId", getMeterId(infoCodeStr, classCode));
+                infoCode.put("funcId", getFuncId(infoCodeStr, classCode));
                 infoCodes.add(infoCode);
             }
             config.put("infoCodes", infoCodes);
         }
-        return alarmConfigs;
     }
 
+    /**
+     * @description: 获取表号
+     * @param: infoCode
+     * @param: classCode
+     * @return: java.lang.String
+     * @exception:
+     * @author: lixing
+     * @company: Persagy Technology Co.,Ltd
+     * @since: 2020/12/1 9:40 上午
+     * @version: V1.0
+     */
+    public abstract String getMeterId(String infoCode, String classCode) throws Exception;
+
+    /**
+     * @description: 获取功能号
+     * @param: infoCode
+     * @param: classCode
+     * @return: java.lang.String
+     * @exception:
+     * @author: lixing
+     * @company: Persagy Technology Co.,Ltd
+     * @since: 2020/12/1 9:40 上午
+     * @version: V1.0
+     */
+    public abstract String getFuncId(String infoCode, String classCode) throws Exception;
 
     /**
      * @description: 获取报警名称
@@ -200,4 +254,74 @@ public abstract class NettyAlarmService {
     public void updateAlarmRecord(JSONObject data) throws Exception {
         alarmService.updateAlarmRecord(getAlarmUrlParam(data), data);
     }
+
+    /**
+     * @description: 报警定义增量变化时,查询发生变化的报警定义
+     * @param: dmpMessage
+     * @return: java.util.Map<java.lang.String, com.alibaba.fastjson.JSONArray>
+     * @exception:
+     * @author: lixing
+     * @company: Persagy Technology Co.,Ltd
+     * @since: 2020/12/1 12:06 下午
+     * @version: V1.0
+     */
+    public Map<String, JSONArray> queryChangedAlarmConfigs(DmpMessage dmpMessage) throws Exception {
+        String projectId = dmpMessage.getProjectId();
+        JSONObject exts = dmpMessage.getExts();
+        //删除报警定义
+        JSONArray deletedConfigUniques = exts.getJSONArray("deletedConfigUniques");
+        //新增报警定义
+        JSONArray createdConfigUniques = exts.getJSONArray("createdConfigUniques");
+        //修改报警定义
+        JSONArray updatedConfigUniques = exts.getJSONArray("updatedConfigUniques");
+        createdConfigUniques = CollectionUtil.isEmpty(createdConfigUniques) ? new JSONArray() : createdConfigUniques;
+        deletedConfigUniques = CollectionUtil.isEmpty(deletedConfigUniques) ? new JSONArray() : deletedConfigUniques;
+        updatedConfigUniques = CollectionUtil.isEmpty(updatedConfigUniques) ? new JSONArray() : updatedConfigUniques;
+        createdConfigUniques.addAll(updatedConfigUniques);
+        List<String> defineList = createdConfigUniques.stream().map(
+                p -> JSONObject.parseObject(JSONObject.toJSONString(p))
+        ).map(this::getAlarmConfigDefineId).collect(Collectors.toList());
+        deletedConfigUniques = deletedConfigUniques.stream().map(
+                p -> JSONObject.parseObject(JSONObject.toJSONString(p))
+        ).filter(
+                t -> !defineList.contains(getAlarmConfigDefineId(t))
+        ).collect(Collectors.toCollection(JSONArray::new));
+
+        JSONArray alarmConfigArr = new JSONArray();
+        for (Object p : createdConfigUniques) {
+            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(p));
+            JSONObject data = new JSONObject();
+            data.put("projectId", projectId);
+            data.put("groupCode", dmpMessage.getGroupCode());
+            data.put("itemCode", jsonObject.getString("itemCode"));
+            data.put("objId", jsonObject.getString("objId"));
+            data.put("userId", "system");
+            DmpResult<JSONArray> alarmConfigQueryResult = alarmService.queryAlarmConfig(getAlarmUrlParam(data), getRequestBody(data));
+            JSONArray tmpAlarmConfigArr = alarmConfigQueryResult.getData();
+            if (CollectionUtil.isNotEmpty(tmpAlarmConfigArr)) {
+                // 报警定义中的信息点转换为表号、功能号
+                initAlarmConfigInfoCodes(tmpAlarmConfigArr);
+                alarmConfigArr.addAll(tmpAlarmConfigArr);
+            }
+            log.info("新增和更新的报警定义-------------------:{}", tmpAlarmConfigArr);
+        }
+        Map<String, JSONArray> resultMap = new HashMap<>();
+        resultMap.put("createdConfigUniques", alarmConfigArr);
+        resultMap.put("deletedConfigUniques", deletedConfigUniques);
+        return resultMap;
+    }
+
+    /**
+     * @description: 获取报警定义唯一标识
+     * @param: obj
+     * @return: java.lang.String
+     * @exception:
+     * @author: lixing
+     * @company: Persagy Technology Co.,Ltd
+     * @since: 2020/12/1 11:54 上午
+     * @version: V1.0
+     */
+    private String getAlarmConfigDefineId(JSONObject obj) {
+        return obj.getString("itemCode") + "" + obj.getString("objId");
+    }
 }