Преглед на файлове

北向设备同步代码修改

jingyuanchao преди 1 година
родител
ревизия
1a00f64bdd

+ 8 - 0
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/constant/DictConstants.java

@@ -283,4 +283,12 @@ public class DictConstants {
      * 安全检查-检查类型
      */
     public static final String CHECK_TYPE = "check_type";
+    /**
+     * 动环传感器告警状态
+     */
+    public static final String SENSOR_ALARM_STATUS = "sensor_alarm_status";
+    /**
+     * 动环传感器设备类型
+     */
+    public static final String SENSOR_DEVICE_TYPE = "sensor_device_type";
 }

+ 6 - 6
soc-common/soc-common-core/src/main/java/com/xunmei/common/core/domain/iot/domain/IotSensor.java

@@ -2,9 +2,13 @@ package com.xunmei.common.core.domain.iot.domain;
 
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.baomidou.mybatisplus.annotation.TableId;
+
 import java.time.LocalDateTime;
+
 import com.baomidou.mybatisplus.annotation.TableField;
+
 import java.io.Serializable;
+
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -12,7 +16,7 @@ import lombok.EqualsAndHashCode;
 
 /**
  * <p>
- * 
+ *
  * </p>
  *
  * @author oygj
@@ -21,7 +25,7 @@ import lombok.EqualsAndHashCode;
 @Data
 @EqualsAndHashCode(callSuper = false)
 @TableName("iot_sensor")
-@ApiModel(value="IotSensor对象", description="")
+@ApiModel(value = "IotSensor对象", description = "")
 public class IotSensor implements Serializable {
 
     private static final long serialVersionUID = 1L;
@@ -53,10 +57,6 @@ public class IotSensor implements Serializable {
     @TableField("device_code")
     private String deviceCode;
 
-    @ApiModelProperty(value = "传感器类型编码")
-    @TableField("category_id")
-    private Long categoryId;
-
     @ApiModelProperty(value = "设备类型编码")
     @TableField("device_type")
     private String deviceType;

+ 11 - 1
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/dto/sensor/SensorPageDto.java

@@ -1,6 +1,7 @@
 package com.xunmei.iot.dto.sensor;
 
 import com.xunmei.common.core.web.domain.PageRequest;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.util.Date;
@@ -11,16 +12,25 @@ import java.util.Date;
  */
 @Data
 public class SensorPageDto extends PageRequest {
-
+    @ApiModelProperty(value = "传感器设备名称")
     private String deviceName;
 
+    @ApiModelProperty(value = "传感器设备code")
     private String deviceCode;
 
+    @ApiModelProperty(value = "传感器设备类型")
+    private String deviceType;
+
+    @ApiModelProperty(value = "上报时间")
     private Date[] dateRange;
 
     private Date startTime;
 
     private Date endTime;
 
+    @ApiModelProperty(value = "告警状态,0:正常,1:告警")
+    private Integer state;
+
+
 
 }

+ 5 - 20
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotCommonSensorServiceImpl.java

@@ -5,10 +5,13 @@ import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.xunmei.common.core.constant.DictConstants;
 import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.domain.iot.domain.IotSensor;
 import com.xunmei.common.core.domain.mediator.domain.MediatorCategory;
 import com.xunmei.common.core.web.page.TableDataInfo;
+import com.xunmei.common.redis.utils.RedisUtils;
+import com.xunmei.common.security.utils.DictUtils;
 import com.xunmei.iot.dto.sensor.SensorPageDto;
 import com.xunmei.iot.mapper.IotCommonSensorMapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -51,11 +54,11 @@ public class IotCommonSensorServiceImpl extends ServiceImpl<IotCommonSensorMappe
         dealPageParam(request);
 
         Page<SensorPageVo> page = sensorMapper.selectPageData(request.getPageRequest(), request);
-        final List<MediatorCategory> categoryList = categoryMapper.selectList(new LambdaQueryWrapper<>());
         for (SensorPageVo record : page.getRecords()) {
             final String info = record.getInfo();
             record.setInfo(dealInfoData(info));
-            dealCategoryName(record, categoryList);
+            record.setDeviceType(DictUtils.getDictLabel(DictConstants.SENSOR_DEVICE_TYPE,Integer.parseInt(record.getDeviceType())));
+            record.setStateText(DictUtils.getDictLabel(DictConstants.SENSOR_ALARM_STATUS,record.getState()));
         }
         return TableDataInfo.build(page);
     }
@@ -106,22 +109,4 @@ public class IotCommonSensorServiceImpl extends ServiceImpl<IotCommonSensorMappe
         return String.join(";", dataList);
     }
 
-    private void dealCategoryName(SensorPageVo record, List<MediatorCategory> categoryList) {
-        if (ObjectUtil.isEmpty(record.getCategoryId())) {
-            return;
-        }
-        final Optional<MediatorCategory> optional = categoryList.stream().filter(c -> ObjectUtil.equal(c.getId(), record.getCategoryId())).findFirst();
-        if (!optional.isPresent()) {
-            return;
-        }
-        final MediatorCategory category = optional.get();
-        record.setCategoryType(category.getName());
-        final Optional<MediatorCategory> parentCategoryOptional = categoryList.stream().filter(c -> ObjectUtil.equal(c.getId(), category.getParentId())).findFirst();
-        if (!parentCategoryOptional.isPresent()) {
-            return;
-        }
-        final MediatorCategory parentCategory = parentCategoryOptional.get();
-        record.setAssetsType(parentCategory.getName());
-
-    }
 }

+ 6 - 4
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/sensor/SensorPageVo.java

@@ -28,11 +28,8 @@ public class SensorPageVo {
     @ApiModelProperty("设备名称")
     private String deviceName;
 
-    @ApiModelProperty("资产类别")
-    private String assetsType;
-
     @ApiModelProperty("设备类型")
-    private String categoryType;
+    private String deviceType;
 
     @ApiModelProperty("设备code")
     private String deviceCode;
@@ -44,4 +41,9 @@ public class SensorPageVo {
     @ApiModelProperty("上报时间")
     private LocalDateTime updateTime;
 
+    @ApiModelProperty(value = "告警状态,0:正常,1:告警")
+    private Integer state;
+
+    @ApiModelProperty(value = "告警状态")
+    private String stateText;
 }

+ 17 - 11
soc-modules/soc-modules-iot/src/main/resources/mapper/IotSensorMapper.xml

@@ -1,9 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.xunmei.iot.mapper.IotCommonSensorMapper">
-
     <select id="selectPageData" resultType="com.xunmei.iot.vo.sensor.SensorPageVo">
-        select s.id, org_id, org_name, device_name, category_id, infos as info,device_code, update_time
+        select s.id, org_id, org_name, device_name, device_type, infos as info,device_code, update_time,state
         from iot_sensor s
         where s.deleted=0
         <if test="request.orgId!= null">
@@ -15,6 +14,12 @@
         <if test="request.deviceName != null and request.deviceName!= ''">
             and s.device_name like CONCAT('%',#{request.deviceName},'%')
         </if>
+        <if test="request.state!= null">
+            and s.state = #{request.state}
+        </if>
+        <if test="request.deviceType!= null">
+            and s.device_type = #{request.deviceType}
+        </if>
         <if test="request.startTime!= null">
             and s.state_update_time >=#{request.startTime}
         </if>
@@ -24,7 +29,8 @@
     </select>
 
     <select id="selectSensorLogDataPage" resultType="com.xunmei.iot.vo.sensor.SensorPageVo">
-        select s.id, org_id, org_name, device_name, category_id, infos as info,device_code, update_time from iot_sensor_log s
+        select s.id, org_id, org_name, device_name, category_id, infos as info,device_code, update_time from
+        iot_sensor_log s
         <where>
             <if test="request.orgId!= null">
                 and s.org_id=#{request.orgId}
@@ -47,16 +53,16 @@
         </where>
         order by s.state_update_time desc
     </select>
-    <select id="selectByIds"  resultType="com.xunmei.common.core.domain.iot.domain.IotSensor">
+    <select id="selectByIds" resultType="com.xunmei.common.core.domain.iot.domain.IotSensor">
         SELECT
-            org_id,
-            CONCAT(b.affiliated_area,'-',b.affiliated_bank,'-',b.short_name) as org_name,
-            device_name,
-            category_id,
-            infos AS info,
-            device_code
+        org_id,
+        CONCAT(b.affiliated_area,'-',b.affiliated_bank,'-',b.short_name) as org_name,
+        device_name,
+        category_id,
+        infos AS info,
+        device_code
         FROM
-            iot_sensor a
+        iot_sensor a
         LEFT JOIN sys_org b ON a.org_id = b.id
         where device_code in
         <foreach collection="deviceIds" index="index" item="item" open="(" separator="," close=")">

+ 7 - 29
soc-modules/soc-modules-mediator/src/main/java/com/xunmei/mediator/api/service/impl/IotSensorServiceImpl.java

@@ -6,12 +6,14 @@ import com.alibaba.fastjson2.JSONArray;
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xunmei.common.core.constant.DictConstants;
 import com.xunmei.common.core.constant.SecurityConstants;
 import com.xunmei.common.core.domain.iot.domain.IotSensor;
 import com.xunmei.common.core.domain.iot.domain.IotSensorLog;
 import com.xunmei.common.core.enums.CategoryDataEnum;
 import com.xunmei.common.core.utils.DateUtils;
 import com.xunmei.common.core.utils.IDHelper;
+import com.xunmei.common.security.utils.DictUtils;
 import com.xunmei.mediator.api.mapper.IotSensorMapper;
 import com.xunmei.mediator.api.service.*;
 import com.xunmei.mediator.util.CheckDataUtil;
@@ -223,7 +225,7 @@ public class IotSensorServiceImpl extends ServiceImpl<IotSensorMapper, IotSensor
                         , sensorDto, "数据来源中,同机构中设备编号重复。"));
                 continue;
             }
-            Long deviceType = convertDeviceType(sensorDto.getDeviceType());
+            String deviceType = convertDeviceType(sensorDto.getDeviceType());
             if (ObjectUtil.isNull(deviceType)) {
                 errors.add(new NorthError(msgId, path
                         , sensorDto, "无法识别的设备类型"));
@@ -244,7 +246,6 @@ public class IotSensorServiceImpl extends ServiceImpl<IotSensorMapper, IotSensor
             }
             domain.setUpdateTime(LocalDateTime.now());
             domain.setDeviceName(sensorDto.getDeviceName().replace("机房/基站环境", "物联环境"));
-            domain.setCategoryId(deviceType);
             domain.setHostCode(sensorDto.getHostCode());
             domain.setDeviceCode(sensorDto.getDeviceCode());
             domain.setOrgId(org.getId());
@@ -269,33 +270,10 @@ public class IotSensorServiceImpl extends ServiceImpl<IotSensorMapper, IotSensor
                 .collect(Collectors.groupingBy(c -> String.valueOf(c.getOrgId())));
     }
 
-    private Long convertDeviceType(String deviceCode) {
-        Long type = null;
-        switch (deviceCode) {
-            case "4183"://温湿度
-                type = CategoryDataEnum.HUMITURE_SENSOR.getId(); //todo
-                break;
-            case "4181"://红外
-                type = CategoryDataEnum.INFRARED_SENSOR.getId();
-                break;
-            case "4182": //烟感
-                type = CategoryDataEnum.SMOKE_SENSOR.getId();
-                break;
-            case "4184": //水浸
-                type = CategoryDataEnum.WATER_SENSOR.getId();
-                break;
-            case "4160"://智能电表
-                type = CategoryDataEnum.AMMETER_SENSOR.getId();
-                break;
-            case "4188"://门窗磁
-                type = CategoryDataEnum.DOOR_WINDOW_SENSOR.getId();
-                break;
-            case "41885"://燃气报警器
-                type = CategoryDataEnum.GAS_ALARM.getId();
-            default:
-                break;
+    private String convertDeviceType(String deviceType) {
+        if (ObjectUtil.isNotNull(deviceType)){
+            return null;
         }
-
-        return type;
+        return DictUtils.getDictLabel(DictConstants.SENSOR_DEVICE_TYPE, Integer.parseInt(deviceType));
     }
 }