Pārlūkot izejas kodu

水浸设置报警延时时间、储能逆变注册设备

crazycat 2 gadi atpakaļ
vecāks
revīzija
8e365d5dfb

+ 62 - 0
src/main/java/com/welampiot/controller/ContravariantController.java

@@ -3,7 +3,9 @@ package com.welampiot.controller;
 import com.welampiot.common.BaseResult;
 import com.welampiot.common.InterfaceResultEnum;
 import com.welampiot.dto.ContravariantDevInfoDTO;
+import com.welampiot.dto.WifiDTO;
 import com.welampiot.service.ContravariantDevInfoService;
+import com.welampiot.service.WifiService;
 import com.welampiot.utils.ToolUtils;
 import com.welampiot.vo.ContravariantDevInfoVO;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -34,6 +36,8 @@ public class ContravariantController {
 
     @Autowired
     private ContravariantDevInfoService contravariantDevInfoService;
+    @Autowired
+    private WifiService wifiService;
 
     /**
      * 储能逆变设备列表
@@ -105,4 +109,62 @@ public class ContravariantController {
         }
         return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,contravariantDevInfoVO1);
     }
+
+    /**
+     * 注册设备
+     * @param request
+     * @return 注册设备
+     */
+    @RequestMapping(value = "/devRegister", method = RequestMethod.POST)
+    public BaseResult<?> devRegister(HttpServletRequest request){
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        Integer id = (Integer) toolUtils.getRequestContent(request,"id",1);
+        if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        ContravariantDevInfoDTO oneById = contravariantDevInfoService.getOneById(id);
+        WifiDTO wifiDTO = new WifiDTO();
+        wifiDTO.setLampPoleId(oneById.getLampPoleId());
+        WifiDTO detailByDTO = wifiService.getDetailByDTO(wifiDTO);
+        String address = "01";
+        String cmd = "01030100000f";
+        cmd += toolUtils.getCRC(cmd.getBytes());
+        String cmdT = cmd;
+        String rate = "00000000"+Integer.toHexString(9600);
+        rate = rate.substring(rate.length()-8);
+        String top = "";
+        String chuanKou = "";
+        if (detailByDTO.getModel() == 0){
+            top = "WEGW";
+        } else if (detailByDTO.getModel() == 1) {
+            top = "WEGW2";
+            cmd = rate + cmd;
+        }else {
+            top = "WEGW3";
+            cmd = rate + cmd;
+            chuanKou = "00"+oneById.getSerialPort();
+            chuanKou = chuanKou.substring(chuanKou.length() - 2);
+        }
+        String len = "00"+Integer.toHexString(cmd.length()/2);
+        len = len.substring(len.length()-2);
+        String sendTopic = "/"+top+"/WriteIn"+detailByDTO.getNum();
+        String backTopic = "/"+top+"/WriteOut"+detailByDTO.getNum();
+        String sendData = "02"+"{\"D2\":\""+chuanKou+address+len+cmd+"\"}";
+        String s = toolUtils.sendMqttCmd(sendTopic, sendData, backTopic, 5);
+        if (s != null && s.length() != 0){
+            if (detailByDTO.getModel() != 0){
+                sendTopic = "/"+top+"/TransIn"+detailByDTO.getNum();
+                backTopic = "/"+top+"/TransOut"+detailByDTO.getNum();
+                sendData = "00D2"+chuanKou+cmdT;
+                s = toolUtils.sendMqttCmd(sendTopic, toolUtils.hexString2Bytes(sendData), backTopic, 5);
+                if (s != null && s.length() != 0){
+                    sendTopic = "/"+top+"/DataReport"+detailByDTO.getNum();
+                    backTopic = "/"+top+"/DataReport"+detailByDTO.getNum();
+                    String s1 = "02000000000000" + chuanKou + s.substring(4);
+//                    toolUtils.sendMqttCmd(sendTopic, toolUtils.hexString2Bytes(s1), backTopic, 0);
+                }
+            }
+            return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
+        }else {
+            return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
+        }
+    }
 }

+ 58 - 0
src/main/java/com/welampiot/controller/WaterImmersionController.java

@@ -2,12 +2,14 @@ package com.welampiot.controller;
 
 import com.welampiot.common.BaseResult;
 import com.welampiot.common.InterfaceResultEnum;
+import com.welampiot.dao.WaterImmersionDevInfoDao;
 import com.welampiot.dto.AirSwitchInfoDTO;
 import com.welampiot.dto.WaterImmersionDevInfoDTO;
 import com.welampiot.dto.WaterImmersionDevInfoLogDTO;
 import com.welampiot.service.AirSwitchInfoService;
 import com.welampiot.service.WaterImmersionDevInfoService;
 import com.welampiot.utils.ToolUtils;
+import com.welampiot.utils.WebUtils;
 import com.welampiot.vo.AirSwitchInfoReturnVO;
 import com.welampiot.vo.WaterImmersionDevInfoLogVO;
 import com.welampiot.vo.WaterImmersionDevInfoVO;
@@ -231,4 +233,60 @@ public class WaterImmersionController {
         airSwitchInfoReturnVO1.setTotal(total);
         return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,airSwitchInfoReturnVO1);
     }
+
+    /**
+     * 设置报警延时时间
+     * @param request
+     * @return
+     */
+    @RequestMapping(value = "/setAlarmTime", method = RequestMethod.POST)
+    public BaseResult<?> setAlarmTime(HttpServletRequest request) {
+        Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
+        Integer id = (Integer) toolUtils.getRequestContent(request,"id",1);
+        Integer delayTime = (Integer) toolUtils.getRequestContent(request,"delayTime",1);
+
+        WaterImmersionDevInfoDTO waterDTOById = waterImmersionDevInfoService.getWaterDTOById(id);
+        if (waterDTOById.getFactory() == 1 || waterDTOById.getFactory() == 2) return toolUtils.response(InterfaceResultEnum.DEVICE_NO_SUPPORT,version);
+        if (waterDTOById.getModel() == 1 && waterDTOById.getFactory() == 0){
+            String timeHex = Integer.toHexString(delayTime);
+            timeHex = "0000"+timeHex;
+            timeHex = timeHex.substring(timeHex.length()-4);
+            String address = Integer.toHexString(Integer.parseInt(waterDTOById.getAddress()));
+            address = "00"+address;
+            address = address.substring(address.length()-2);
+            String cmd = address + "060033" + timeHex;
+            cmd += toolUtils.getCRC(cmd.getBytes());
+            cmd = "0202"+cmd;
+            String sendTopic = "/WEGW2/TransIn/"+waterDTOById.getNum();
+            String backTopic = "/WEGW2/TransOut/"+waterDTOById.getNum();
+            String s = toolUtils.sendMqttCmd(sendTopic, toolUtils.hexString2Bytes(cmd), backTopic);
+            if (s == null || s.length() == 0) return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
+            WaterImmersionDevInfoDTO waterImmersionDevInfoDTO = new WaterImmersionDevInfoDTO();
+            waterImmersionDevInfoDTO.setId(id);
+            waterImmersionDevInfoDTO.setDelayTime(delayTime);
+            waterImmersionDevInfoService.updateDelayTimeByDto(waterImmersionDevInfoDTO);
+        } else if (waterDTOById.getModel() == 3 && waterDTOById.getFactory() == 0) {
+            String port = "00"+waterDTOById.getSerialPort();
+            port = port.substring(port.length()-2);
+            String timeHex = Integer.toHexString(delayTime);
+            timeHex = "0000"+timeHex;
+            timeHex = timeHex.substring(timeHex.length()-4);
+            String address = Integer.toHexString(Integer.parseInt(waterDTOById.getAddress()));
+            address = "00"+address;
+            address = address.substring(address.length()-2);
+            String cmd = address + "060033" + timeHex;
+            cmd += toolUtils.getCRC(cmd.getBytes());
+            cmd = "0202"+port+cmd;
+            String sendTopic = "/WEGW3/TransIn/"+waterDTOById.getNum();
+            String backTopic = "/WEGW3/TransOut/"+waterDTOById.getNum();
+            String s = toolUtils.sendMqttCmd(sendTopic, toolUtils.hexString2Bytes(cmd), backTopic);
+            if (s == null || s.length() == 0) return toolUtils.response(InterfaceResultEnum.SEND_CMD_TIME_OUT,version);
+            WaterImmersionDevInfoDTO waterImmersionDevInfoDTO = new WaterImmersionDevInfoDTO();
+            waterImmersionDevInfoDTO.setId(id);
+            waterImmersionDevInfoDTO.setDelayTime(delayTime);
+            waterImmersionDevInfoService.updateDelayTimeByDto(waterImmersionDevInfoDTO);
+        }
+
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
+    }
 }

+ 2 - 0
src/main/java/com/welampiot/dao/ContravariantDevInfoDao.java

@@ -2,6 +2,7 @@ package com.welampiot.dao;
 
 import com.welampiot.dto.ContravariantDevInfoDTO;
 import com.welampiot.vo.ContravariantDevInfoVO;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -22,4 +23,5 @@ public interface ContravariantDevInfoDao {
     Integer getContravariantDevTotal(ContravariantDevInfoVO vo);
 
     Integer getContravariantDevOnlineTotal(ContravariantDevInfoVO vo);
+    ContravariantDevInfoDTO getOneById(@Param("id")Integer id);
 }

+ 1 - 0
src/main/java/com/welampiot/dao/WaterImmersionDevInfoDao.java

@@ -45,4 +45,5 @@ public interface WaterImmersionDevInfoDao {
     Integer getWaterImmersionAlarmCount(WaterImmersionDevInfoDTO dto);
 
     Integer getWaterImmersionNewCount(WaterImmersionDevInfoDTO dto);
+    void updateDelayTimeByDto(WaterImmersionDevInfoDTO dto);
 }

+ 2 - 1
src/main/java/com/welampiot/dto/WaterImmersionDevInfoDTO.java

@@ -47,7 +47,7 @@ public class WaterImmersionDevInfoDTO implements Serializable {
     private Integer probe2;
 
     /** 报警延时时间(单位:s)**/
-    private String delayTime;
+    private int delayTime;
 
     /** 巡检命令(0 未下发,1 已下发)**/
     private Integer patrolCmd;
@@ -114,6 +114,7 @@ public class WaterImmersionDevInfoDTO implements Serializable {
     private String keyword;
 
     private Integer online;
+    private String num; // 云盒地址
 
     private static final long serialVersionUID = 1L;
 }

+ 2 - 0
src/main/java/com/welampiot/service/ContravariantDevInfoService.java

@@ -2,6 +2,7 @@ package com.welampiot.service;
 
 import com.welampiot.dto.ContravariantDevInfoDTO;
 import com.welampiot.vo.ContravariantDevInfoVO;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -22,4 +23,5 @@ public interface ContravariantDevInfoService {
     Integer getContravariantDevTotal(ContravariantDevInfoVO vo);
 
     Integer getContravariantDevOnlineTotal(ContravariantDevInfoVO vo);
+    ContravariantDevInfoDTO getOneById(@Param("id")Integer id);
 }

+ 1 - 0
src/main/java/com/welampiot/service/WaterImmersionDevInfoService.java

@@ -38,4 +38,5 @@ public interface WaterImmersionDevInfoService {
     Integer getWaterImmersionAlarmCount(WaterImmersionDevInfoDTO dto);
 
     Integer getWaterImmersionNewCount(WaterImmersionDevInfoDTO dto);
+    void updateDelayTimeByDto(WaterImmersionDevInfoDTO dto);
 }

+ 5 - 0
src/main/java/com/welampiot/service/impl/ContravariantDevInfoServiceImpl.java

@@ -42,4 +42,9 @@ public class ContravariantDevInfoServiceImpl implements ContravariantDevInfoServ
     public Integer getContravariantDevOnlineTotal(ContravariantDevInfoVO vo) {
         return contravariantDevInfoDao.getContravariantDevOnlineTotal(vo);
     }
+
+    @Override
+    public ContravariantDevInfoDTO getOneById(Integer id) {
+        return contravariantDevInfoDao.getOneById(id);
+    }
 }

+ 5 - 0
src/main/java/com/welampiot/service/impl/WaterImmersionDevInfoServiceImpl.java

@@ -305,4 +305,9 @@ public class WaterImmersionDevInfoServiceImpl implements WaterImmersionDevInfoSe
     public Integer getWaterImmersionNewCount(WaterImmersionDevInfoDTO dto) {
         return waterImmersionDevInfoDao.getWaterImmersionNewCount(dto);
     }
+
+    @Override
+    public void updateDelayTimeByDto(WaterImmersionDevInfoDTO dto) {
+        waterImmersionDevInfoDao.updateDelayTimeByDto(dto);
+    }
 }

+ 7 - 0
src/main/resources/mapper/ContravariantDevInfoMapper.xml

@@ -103,5 +103,12 @@
             </foreach>
         </if>
     </select>
+
+    <select id="getOneById" resultType="com.welampiot.dto.ContravariantDevInfoDTO" parameterType="int">
+        select
+        c.id,c.lamp_pole_id as lampPoleId,c.serial_port as serialPort
+        from contravariant_dev_info c
+        where c.id = #{id}
+    </select>
  
 </mapper>

+ 9 - 1
src/main/resources/mapper/WaterImmersionDevInfoMapper.xml

@@ -102,6 +102,13 @@
             ,box_sub_address = #{boxSubAddress}
         where id = #{id}
     </update>
+    <update id="updateDelayTimeByDto" parameterType="com.welampiot.dto.WaterImmersionDevInfoDTO">
+        update water_immersion_dev_info
+        set
+        delaytime = #{delayTime}
+        where id = #{id}
+    </update>
+
 
     <select id="findByWaterImmersionDTO" resultType="Integer">
         select count(*)
@@ -142,8 +149,9 @@
     </delete>
 
     <select id="getWaterDTOById" resultType="WaterImmersionDevInfoDTO">
-        select w.id,w.number
+        select w.id,w.number,w.serial_port as serialPort,w.address,w.factory,c.num,c.model
         from water_immersion_dev_info w
+        left join wifi c on c.lamp_pole_id = w.lamp_pole_id
         where w.id = #{id}
     </select>