Kaynağa Gözat

时间戳转时间存储以及if换成switch

nahida 1 yıl önce
ebeveyn
işleme
593215b1da

+ 0 - 8
pole-service/src/main/java/com/zksy/pole/domain/po/DgGatewayRegistration.java

@@ -24,11 +24,6 @@ public class DgGatewayRegistration implements Serializable {
      */
     private Long cmd;
 
-    /**
-     * 时间
-     */
-    private Date dateTime;
-
     /**
      * 经度
      */
@@ -88,7 +83,6 @@ public class DgGatewayRegistration implements Serializable {
         DgGatewayRegistration other = (DgGatewayRegistration) that;
         return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
             && (this.getCmd() == null ? other.getCmd() == null : this.getCmd().equals(other.getCmd()))
-            && (this.getDateTime() == null ? other.getDateTime() == null : this.getDateTime().equals(other.getDateTime()))
             && (this.getLongitude() == null ? other.getLongitude() == null : this.getLongitude().equals(other.getLongitude()))
             && (this.getLatitude() == null ? other.getLatitude() == null : this.getLatitude().equals(other.getLatitude()))
             && (this.getDeviceType() == null ? other.getDeviceType() == null : this.getDeviceType().equals(other.getDeviceType()))
@@ -105,7 +99,6 @@ public class DgGatewayRegistration implements Serializable {
         int result = 1;
         result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
         result = prime * result + ((getCmd() == null) ? 0 : getCmd().hashCode());
-        result = prime * result + ((getDateTime() == null) ? 0 : getDateTime().hashCode());
         result = prime * result + ((getLongitude() == null) ? 0 : getLongitude().hashCode());
         result = prime * result + ((getLatitude() == null) ? 0 : getLatitude().hashCode());
         result = prime * result + ((getDeviceType() == null) ? 0 : getDeviceType().hashCode());
@@ -125,7 +118,6 @@ public class DgGatewayRegistration implements Serializable {
         sb.append("Hash = ").append(hashCode());
         sb.append(", id=").append(id);
         sb.append(", cmd=").append(cmd);
-        sb.append(", dateTime=").append(dateTime);
         sb.append(", longitude=").append(longitude);
         sb.append(", latitude=").append(latitude);
         sb.append(", deviceType=").append(deviceType);

+ 52 - 36
pole-service/src/main/java/com/zksy/pole/factory/HandleCmdFactory.java

@@ -1,5 +1,6 @@
 package com.zksy.pole.factory;
 
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.json.JSON;
 import cn.hutool.json.JSONArray;
 import cn.hutool.json.JSONObject;
@@ -13,46 +14,61 @@ import org.springframework.stereotype.Component;
 
 @Component
 public class HandleCmdFactory {
+    @Autowired
+    private HandleDgEquipmentAlarmCmd handleDgEquipmentAlarmCmd;
+    @Autowired
+    private HandleDgEquipmentStatusCmd handleDgEquipmentStatusCmd;
     @Autowired
     private HandleDgGatewayRegistrationCmd handleDgGatewayRegistrationCmd;
+    @Autowired
+    private HandleDgGatewayStrategyCmd handleDgGatewayStrategyCmd;
+    @Autowired
+    private HandleDgLampControlledHeartbeatCmd handleDgLampControlledHeartbeatCmd;
+    @Autowired
+    private HandleDgRelayControlCmd handleDgRelayControlCmd;
+    @Autowired
+    private HandleDgRelayTimingStrategyCmd handleDgRelayTimingStrategyCmd;
+    @Autowired
+    private HandleDgReportEnvironmentalDataCmd handleDgReportEnvironmentalDataCmd;
+    @Autowired
+    private HandleDgTimelyControlCmd handleDgTimelyControlCmd;
     public String HandleCmd(String data) {
         JSONObject jsonObject = JSONUtil.parseObj(data);
-        if(jsonObject.getInt("cmd") == 6031){
-            var c = new HandleDgEquipmentAlarmCmd();
-            String s = c.HandleCmdMethod(jsonObject.toBean(DgEquipmentAlarm.class));
-            return s;
-        }else if(jsonObject.getInt("cmd") == 6012){
-            var c = new HandleDgEquipmentStatusCmd();
-            String s = c.HandleCmdMethod(jsonObject.toBean(DgEquipmentStatus.class));
-            return s;
-        }else if(jsonObject.getInt("cmd") == 1111){
-            var s = handleDgGatewayRegistrationCmd.HandleCmdMethod(jsonObject.toBean(DgGatewayRegistration.class));
-            return s;
-        }else if(jsonObject.getInt("cmd") == 6022){
-            var c = new HandleDgGatewayStrategyCmd();
-            String s = c.HandleCmdMethod(jsonObject.toBean(DgGatewayStrategy.class));
-            return s;
-        }else if(jsonObject.getInt("cmd") == 6010){
-            var c = new HandleDgLampControlledHeartbeatCmd();
-            String s = c.HandleCmdMethod(jsonObject.toBean(DgLampControlledHeartbeat.class));
-            return s;
-        }else if(jsonObject.getInt("cmd") == 6014){
-            var c = new HandleDgRelayControlCmd();
-            String s = c.HandleCmdMethod(jsonObject.toBean(DgRelayControl.class));
-            return s;
-        }else if(jsonObject.getInt("cmd") == 6015){
-            var c = new HandleDgRelayTimingStrategyCmd();
-            String s = c.HandleCmdMethod(jsonObject.toBean(DgRelayTimingStrategy.class));
-            return s;
-        }else if(jsonObject.getInt("cmd") == 2000){
-            var c = new HandleDgReportEnvironmentalDataCmd();
-            String s = c.HandleCmdMethod(jsonObject.toBean(DgReportEnvironmentalData.class));
-            return s;
-        }else if(jsonObject.getInt("cmd") == 6011){
-            var c = new HandleDgTimelyControlCmd();
-            String s = c.HandleCmdMethod(jsonObject.toBean(DgTimelyControl.class));
-            return s;
+        int cmd = jsonObject.getInt("cmd");
+        if(jsonObject.getInt("timestamp") != null){
+            jsonObject.set("date_time", DateUtil.parseDate(jsonObject.getStr("timestamp")));
+        }
+        String s;
+        switch (cmd) {
+            case 6031:
+                s = handleDgEquipmentAlarmCmd.HandleCmdMethod(jsonObject.toBean(DgEquipmentAlarm.class));
+                return s;
+            case 6012:
+                s = handleDgEquipmentStatusCmd.HandleCmdMethod(jsonObject.toBean(DgEquipmentStatus.class));
+                return s;
+            case 1111:
+                s = handleDgGatewayRegistrationCmd.HandleCmdMethod(jsonObject.toBean(DgGatewayRegistration.class));
+                return s;
+            case 6022:
+                s = handleDgGatewayStrategyCmd.HandleCmdMethod(jsonObject.toBean(DgGatewayStrategy.class));
+                return s;
+            case 6010:
+                s = handleDgLampControlledHeartbeatCmd.HandleCmdMethod(jsonObject.toBean(DgLampControlledHeartbeat.class));
+                return s;
+            case 6014:
+                s = handleDgRelayControlCmd.HandleCmdMethod(jsonObject.toBean(DgRelayControl.class));
+                return s;
+            case 6015:
+                s = handleDgRelayTimingStrategyCmd.HandleCmdMethod(jsonObject.toBean(DgRelayTimingStrategy.class));
+                return s;
+            case 2000:
+                s = handleDgReportEnvironmentalDataCmd.HandleCmdMethod(jsonObject.toBean(DgReportEnvironmentalData.class));
+                return s;
+            case 6011:
+                s = handleDgTimelyControlCmd.HandleCmdMethod(jsonObject.toBean(DgTimelyControl.class));
+                return s;
+            default:
+                throw new CommonException("cmd有误或者没有对应的cmd处理", 500);
         }
-        throw new CommonException("cmd有误或者没有对应的cmd处理", 500);
     }
 }

+ 1 - 2
pole-service/src/main/resources/mapper/DgGatewayRegistrationMapper.xml

@@ -7,7 +7,6 @@
     <resultMap id="BaseResultMap" type="com.zksy.pole.domain.po.DgGatewayRegistration">
             <id property="id" column="id" jdbcType="VARCHAR"/>
             <result property="cmd" column="cmd" jdbcType="BIGINT"/>
-            <result property="dateTime" column="date_time" jdbcType="TIMESTAMP"/>
             <result property="longitude" column="longitude" jdbcType="DOUBLE"/>
             <result property="latitude" column="latitude" jdbcType="DOUBLE"/>
             <result property="deviceType" column="device_type" jdbcType="VARCHAR"/>
@@ -19,7 +18,7 @@
     </resultMap>
 
     <sql id="Base_Column_List">
-        id,cmd,date_time,
+        id,cmd,
         longitude,latitude,device_type,
         mac,create_by,create_time,
         update_by,update_time