瀏覽代碼

添加编辑集中控制器,开关闭合回路

zhj 1 年之前
父節點
當前提交
a2f4dac667

+ 4 - 0
src/main/java/com/welampiot/common/InterfaceResultEnum.java

@@ -269,10 +269,14 @@ public enum InterfaceResultEnum {
     DEVICE_DISCONNECT("1102","请先断开其他设备","Please disconnect other devices first","Отключите сначала другое устройство"),
     DEVICE_TURN_ON("1103","请先开启输出状态","Please turn on the output state first","состояние на выходе"),
 
+    //投影灯 1200-1299
     LACK_PROJECTION_LIGHT_ADDRESS("1200", "投影灯地址不能为空", "The projection lamp address cannot be empty" , "Адрес прожектора не может быть пустым"),
     LACK_PROJECTION_LIGHT_NAME("1201", "投影灯的设备名称不能为空", "The device name of the projection lamp cannot be empty" , "Название устройства для проекции не может быть пустым"),
     LACK_PROJECTION_LIGHT_SERIAL_PORT("1202", "请填写投影灯连接的云盒的串口号", "Enter the serial port number of the cloud box to which the projection light is connected", "Пожалуйста, заполните последовательный номер коробки с облаками, соединенной прожекторами"),
     IMAGE_NUMBER_ERROR("1203", "当前设备仅支持切换四张图案片", "The current device supports only four pattern switches", "Нынешнее оборудование поддерживает только четыре схемы переключения"),
+
+    // 集控器 1300-1399
+    LACK_CT_TYPE_ERROR("1300", "请选择ctr量程范围" , "Please select a ctr range" , "Пожалуйста, выберите диапазон КТР" ),
     ;
     private String code;
     private String msgCn;

+ 1 - 2
src/main/java/com/welampiot/controller/LoopController.java

@@ -13,7 +13,6 @@ import com.welampiot.service.SectionService;
 import com.welampiot.utils.ExcelUtil;
 import com.welampiot.utils.ToolUtils;
 import com.welampiot.vo.LampVO;
-import com.welampiot.vo.LoopDetailVO;
 import com.welampiot.vo.LoopVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -196,7 +195,7 @@ public class LoopController {
         Integer version = request.getParameter("version") == null ? 0 : Integer.parseInt(request.getParameter("version"));
         int id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
         if (id == 0) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL, version);
-        LoopDetailVO loopDetail = loopService.getLoopDetail(id, version,toolUtils.getSectionList(request));
+        LoopDTO loopDetail = loopService.getLoopDetail(id);
         if (loopDetail == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
         return BaseResult.success(loopDetail);
     }

+ 44 - 4
src/main/java/com/welampiot/controller/NetworkController.java

@@ -2,9 +2,11 @@ package com.welampiot.controller;
 
 import com.welampiot.common.BaseResult;
 import com.welampiot.common.InterfaceResultEnum;
+import com.welampiot.dto.LoopDTO;
 import com.welampiot.dto.NetInfoDTO;
 import com.welampiot.dto.NetworkDTO;
 import com.welampiot.dto.UserDTO;
+import com.welampiot.service.LoopService;
 import com.welampiot.service.NetInfoService;
 import com.welampiot.service.NetworkService;
 import com.welampiot.service.UserService;
@@ -44,6 +46,8 @@ public class NetworkController {
     private NetInfoService netInfoService;
     @Autowired
     private UserService userService;
+    @Autowired
+    private LoopService loopService;
 
     /**
      * 网关详情
@@ -426,14 +430,41 @@ public class NetworkController {
             dto.setDeviceSn(deviceSn);
             if (networkService.checkNetworkData(dto) > 0)
                 return toolUtils.response(InterfaceResultEnum.DEV_SN_UNIQUE_ERROR,version);
-            long l = System.currentTimeMillis();
-            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-            String format = simpleDateFormat.format(l);
-            networkDTO.setCreateTime(format);
+
+            // 添加集中控制器(8路或者12路)
+            if (vo.getProtocolType() == 14 || vo.getProtocolType() == 15) {
+                // ct类型(0 20A,1 50A,2 100A,3 200A)
+                if (vo.getCtType() == null) {
+                    return toolUtils.response(InterfaceResultEnum.LACK_CT_TYPE_ERROR, version);
+                }
+            }
+
+            networkDTO.setCreateTime(ToolUtils.getNowTime());
             networkDTO.setUserId(userDTO.getId());
             networkService.addNetworkData(networkDTO);
             Integer id = networkDTO.getId();
             networkVO.setId(id);
+
+            if (vo.getProtocolType() == 14 || vo.getProtocolType() == 15) {
+                // ct类型(0 20A,1 50A,2 100A,3 200A)
+                int count = 8;
+                if (vo.getProtocolType() == 15) count = 12;
+                String loopName = "DO";
+                LoopDTO loopDTO = new LoopDTO();
+                loopDTO.setNetworkId(id);
+                loopDTO.setSectionId(sectionId);
+                loopDTO.setAreaId(areaId);
+                loopDTO.setControlType(5);
+                loopDTO.setCreateTime(ToolUtils.getNowTime());
+                for (int i = 1; i <= count; i++) {
+                    loopDTO.setName(loopName + i);
+                    if (i >= 10) loopDTO.setNumber("0000" + i);
+                    else loopDTO.setNumber("00000" + i);
+                    loopDTO.setDeviceId(loopDTO.getNumber());
+                    loopDTO.setSn(loopDTO.getNumber());
+                    loopService.addLoopData(loopDTO);
+                }
+           }
         } else { // 编辑
             dto.setId(vo.getId());
             if (networkService.checkNetworkData(dto) > 0)
@@ -443,6 +474,15 @@ public class NetworkController {
             dto.setDeviceSn(deviceSn);
             if (networkService.checkNetworkData(dto) > 0)
                 return toolUtils.response(InterfaceResultEnum.DEV_SN_UNIQUE_ERROR,version);
+
+            // 添加集中控制器(8路或者12路)
+            if (vo.getProtocolType() == 14 || vo.getProtocolType() == 15) {
+                // ct类型(0 20A,1 50A,2 100A,3 200A)
+                if (vo.getCtType() == null) {
+                    return toolUtils.response(InterfaceResultEnum.LACK_CT_TYPE_ERROR, version);
+                }
+            }
+
             networkService.updateNetworkData(networkDTO);
             networkVO.setId(vo.getId());
         }

+ 26 - 1
src/main/java/com/welampiot/controller/NewLampPoleController.java

@@ -35,7 +35,7 @@ import java.util.*;
 @RestController
 @CrossOrigin
 @RequestMapping("/newLampPole")
-public class NewLampPoleController {
+public class NewLampPoleController extends BaseController {
 
     @Autowired
     private WifiService wifiService;
@@ -1801,4 +1801,29 @@ public class NewLampPoleController {
         emergencyVO.setList(emergencyDevList);
         return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,emergencyVO);
     }
+
+    /**
+     * 回路开闸/合闸
+     * @return 操作成功
+     */
+    @RequestMapping(value = "/loopStatus", method = RequestMethod.POST)
+    private BaseResult<?> loopStatus(LoopVO loopVO) {
+        Integer version = loopVO.getVersion();
+        Integer loopId = loopVO.getLoopId();
+        Integer type = loopVO.getType();
+        if (loopId == null || type == null) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
+        if (type == 1) { // 手动
+            LoopDTO loopDetail = loopService.getLoopDetail(loopId);
+            if (loopDetail == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
+            if (loopDetail.getControlType() == 14 || loopDetail.getControlType() == 15) {
+                // 集控器M100
+                if (loopVO.getStatus() != null)  {
+                    boolean isSuccess = toolUtils.openCloseLoop(loopDetail.getDeviceSn(), loopDetail.getDeviceId(), loopVO.getStatus());
+                    if (!isSuccess) return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL, version);
+                }
+            }
+        }
+
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
+    }
 }

+ 1 - 1
src/main/java/com/welampiot/dao/LoopDao.java

@@ -19,7 +19,7 @@ public interface LoopDao {
 
     Integer getTotalBySectionList(LoopDTO dto);
 
-    LoopDTO getLoopDetailById(@Param("id") Integer id, @Param("sectionList") List<LoopDTO> sectionList);
+    LoopDTO getLoopDetailById(@Param("id") Integer id);
 
     List<LoopDTO> getLoopDropDownListBySectionList(@Param("sectionList") List<LoopDTO> sectionList);
 

+ 10 - 1
src/main/java/com/welampiot/dto/LoopDTO.java

@@ -26,11 +26,20 @@ public class LoopDTO implements Serializable {
     private String number;
 
     /** 设备id **/
-    private Integer deviceId;
+    private String deviceId;
+
+    private String deviceSn;
 
     /** 控制器类型(0 GPRS,1 NB,2 Lora, 3 PLC,4 zigbee) **/
     private Integer controlType;
 
+    /** 协议类型(0 = lorawan, 1 = lora mesh, 2 = rf mesh, 3 = nbiot,
+     * 4 = gprs_direct, 5 = zigbee,6=LoraWAN,7=onenet, 8=emqtt,
+     * 9=LC-6B11-J,10=WE-CON-4G20(双路控制),11=PLC(有单灯,也有双灯控制器),
+     * 12=铂胜lora,13=2.4G,14=WE-CC-GL8,15=WE-CC-GL12
+     */
+    private Integer protocolType;
+
     /** 区、县id **/
     private Integer areaId;
 

+ 2 - 0
src/main/java/com/welampiot/dto/NetworkDTO.java

@@ -39,4 +39,6 @@ public class NetworkDTO {
     private String simId;
     private String uId;
     private String deviceId;
+    /** ct类型(0 20A,1 50A,2 100A,3 200A)(添加集中器网关使用)*/
+    private Integer ctType;
 }

+ 1 - 2
src/main/java/com/welampiot/service/LoopService.java

@@ -1,7 +1,6 @@
 package com.welampiot.service;
 
 import com.welampiot.dto.LoopDTO;
-import com.welampiot.vo.LoopDetailVO;
 import com.welampiot.vo.LoopVO;
 
 import java.util.List;
@@ -18,7 +17,7 @@ import java.util.List;
 public interface LoopService {
     LoopVO getLoopList(LoopDTO dto);
 
-    LoopDetailVO getLoopDetail(Integer id, Integer version, List<LoopDTO> sectionList);
+    LoopDTO getLoopDetail(Integer id);
 
     LoopVO getLoopDropDownList(List<LoopDTO> sectionList);
 

+ 2 - 52
src/main/java/com/welampiot/service/impl/LoopServiceImpl.java

@@ -3,7 +3,6 @@ package com.welampiot.service.impl;
 import com.welampiot.dao.LoopDao;
 import com.welampiot.dto.LoopDTO;
 import com.welampiot.service.LoopService;
-import com.welampiot.vo.LoopDetailVO;
 import com.welampiot.vo.LoopVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -72,57 +71,8 @@ public class LoopServiceImpl implements LoopService {
     }
 
     @Override
-    public LoopDetailVO getLoopDetail(Integer id,Integer version,List<LoopDTO> sectionList) {
-        LoopDetailVO vo = new LoopDetailVO();
-        LoopDTO dto = loopDao.getLoopDetailById(id,sectionList);
-        if (dto == null) return null;
-            vo.setName(dto.getName());
-            vo.setAreaId(dto.getAreaId().toString());
-            if (dto.getAreaId() != null && dto.getAreaId() != 0){
-                if (version == 0){
-                    dto.setArea(dto.getChineseName());
-                    vo.setArea(dto.getArea());
-                }else if (version == 1){
-                    dto.setArea(dto.getEnglishName());
-                    vo.setArea(dto.getArea());
-                }else {
-                    dto.setArea(dto.getRuName());
-                    vo.setArea(dto.getArea());
-                }
-            }else {
-                vo.setArea("");
-            }
-            vo.setSectionId(dto.getSectionId().toString());
-            if (dto.getSectionId() != null && dto.getSectionId() != 0){
-                vo.setSection(dto.getSection());
-            }else {
-                vo.setSection("");
-            }
-            vo.setNumber(dto.getNumber());
-            vo.setLampCount(dto.getLampCount().toString());
-            vo.setSn(dto.getSn());
-            if (dto.getDevType() != null && dto.getDevType() == 1){
-                dto.setDevType(1);
-                vo.setDevType(dto.getDevType().toString());
-            }else {
-                dto.setDevType(0);
-                vo.setDevType(dto.getDevType().toString());
-            }
-            if (dto.getStatus() != null && dto.getStatus() == 1){
-                dto.setStatus(1);
-                vo.setStatus(dto.getStatus().toString());
-            }else {
-                dto.setStatus(0);
-                vo.setStatus(dto.getStatus().toString());
-            }
-            vo.setRateId(dto.getRateId().toString());
-            if (dto.getRateId() != null && dto.getRateId() != 0){
-                vo.setRateStr(dto.getRateStr());
-            }else {
-                vo.setRateStr("");
-            }
-            vo.setLampPoleId(dto.getLampPoleId().toString());
-        return vo;
+    public LoopDTO getLoopDetail(Integer id) {
+        return loopDao.getLoopDetailById(id);
     }
 
     @Override

+ 46 - 0
src/main/java/com/welampiot/utils/ToolUtils.java

@@ -2160,4 +2160,50 @@ System.out.println(res);
         }
         return seqBuilder.toString();
     }
+
+    /**
+     * 集控器回路分合闸(M100)
+     * @param sn 集控器SN
+     * @param deviceId 第几路回路
+     * @param status 状态(0 闭合,1 断开)
+     */
+    public boolean openCloseLoop(String sn, String deviceId, Integer status) {
+        String sendTopic = "/gateway/commandIn/" + sn;
+        String backTopic = "gateway/commandOut/" + sn;
+
+        if (status == 0) { // 这里0是闭合
+            status = 1; // 发MQTT消息里面1就是开
+        } else {           // 这里1是断开
+            status = 0; // 发MQTT消息里面0就是关
+        }
+
+        String cmd = "{\"rw_prot\":{\"Ver\":\"1.0.1\",\"dir\":\"down\",\"id\":\"" + ToolUtils.getSeq() + "\",\"w_data\":["
+                + "{\"name\":\"DO" + Integer.parseInt(deviceId) + "\",\"value\":\"" + status + "\"}]}}";
+        String s = sendMqttCmd(sendTopic, cmd, backTopic);
+        return checkBackResult(s,1);
+    }
+
+    /**
+     * 检查指令返回结果
+     * @param backResult 指令返回结果
+     * @param type (0 读,1 写)
+     * @return true 成功,false 失败
+     */
+    private boolean checkBackResult(String backResult, int type) {
+        if (backResult.isEmpty()) return false;
+        JSONObject jsonObject = JSONObject.parseObject(backResult);
+        if (!jsonObject.containsKey("rw_prot")) return false;
+        JSONObject rwJson = (JSONObject) jsonObject.get("rw_prot");
+        String str;
+        if (type == 0) {
+            str = "r_data";
+        } else {
+            str = "w_data";
+        }
+        if (!rwJson.containsKey(str)) return false;
+        JSONObject dataJson = (JSONObject) rwJson.get(str);
+        if (!dataJson.containsKey("err")) return false;
+        int err = (int) dataJson.get("err");
+        return err != 1;
+    }
 }

+ 14 - 0
src/main/java/com/welampiot/vo/LoopVO.java

@@ -39,5 +39,19 @@ public class LoopVO implements Serializable {
 
     private List<Object> msg;
 
+    private Integer loopId;
+    /** 闸状态(0 合闸,1 分闸)(手动) */
+    private Integer lockStatus;
+    /** 锁状态(0 解锁,1 锁死)(手动) */
+    private Integer status;
+    private String username;
+
+    /** 协议类型(0 = lorawan, 1 = lora mesh, 2 = rf mesh, 3 = nbiot,
+     * 4 = gprs_direct, 5 = zigbee,6=LoraWAN,7=onenet, 8=emqtt,
+     * 9=LC-6B11-J,10=WE-CON-4G20(双路控制),11=PLC(有单灯,也有双灯控制器),
+     * 12=铂胜lora,13=2.4G,14=WE-CC-GL8,15=WE-CC-GL12
+     */
+    private Integer protocolType;
+
     private static final long serialVersionUID = 1L;
 }

+ 2 - 0
src/main/java/com/welampiot/vo/NetworkVO.java

@@ -25,6 +25,8 @@ public class NetworkVO {
     private String networkName;
     private String deviceSn;
     private Integer protocolType; // 协议类型
+    /** 交直流变送器(0 20A,1 50A,2 100A,3 200A) */
+    private Integer ctType;
     private String protocolTypeStr;
     private String model;
     private String area;

+ 25 - 11
src/main/resources/mapper/LoopMapper.xml

@@ -67,20 +67,16 @@
     </select>
 
     <select id="getLoopDetailById" resultType="LoopDTO">
-        select l.name,l.areaid as areaId,l.sectionid as sectionId,l.number,
+        select l.id,l.name,l.areaid as areaId,l.sectionid as sectionId,l.number,
                l.lampcount as lampCount,l.sn,l.dev_type as devType,l.status,
-               l.rateid as rateId,l.lamp_pole_id lampPoleId,s.name as section,
-               g.chinese_name chineseName,g.ru_name ruName,g.english_name englishName,r.name rateStr
+               l.rateid as rateId,l.lamp_pole_id lampPoleId,s.name as section,l.deviceid as deviceId,
+               g.chinese_name chineseName,g.ru_name ruName,g.english_name englishName,r.name rateStr,
+               n.protocoltype as protocolType,n.devicesn as deviceSn
         from `loop` l left join section s on l.sectionid = s.id
             left join global_location g on l.areaid = g.id
             left join rate r on l.rateid = r.id
+            left join network n on n.id = l.network_id
         where l.id = #{id}
-            <if test="sectionList != null and !sectionList.isEmpty()">
-                and l.sectionid in
-                    <foreach item="item" collection="sectionList" open="(" separator="," close=")">
-                        #{item}
-                    </foreach>
-            </if>
     </select>
 
     <select id="getLoopDropDownListBySectionList" resultType="LoopDTO">
@@ -100,9 +96,27 @@
     </insert>
 
     <insert id="addLoopData" parameterType="com.welampiot.dto.LoopDTO" useGeneratedKeys="true" keyProperty="id">
-        insert into `loop`(areaid,sectionid,`name`,`number`,control_type,createtime)
+        insert into `loop`(areaid,sectionid,`name`,`number`,control_type,createtime
+        <if test="deviceId != null">
+            ,deviceid
+        </if>
+        <if test="sn != null">
+            ,sn
+        </if>
+        <if test="networkId != null">
+            ,network_id
+        </if>)
         values
-            (#{areaId},#{sectionId},#{name},#{number},#{controlType},#{createTime})
+            (#{areaId},#{sectionId},#{name},#{number},#{controlType},#{createTime}
+        <if test="deviceId != null">
+            ,#{deviceId}
+        </if>
+        <if test="sn != null">
+            ,#{sn}
+        </if>
+        <if test="networkId != null">
+            ,#{networkId}
+        </if>)
     </insert>
 
     <update id="updateLoopDataByDTO" parameterType="com.welampiot.dto.LoopDTO">

+ 6 - 0
src/main/resources/mapper/NetworkMapper.xml

@@ -247,6 +247,9 @@
                             <if test="operator != null and operator != ''">
                                 operator,
                             </if>
+                            <if test="ctType != null and ctType != ''">
+                                ct_type,
+                            </if>
                             createtime,
                             userId)
         values (#{networkName},#{deviceSn},#{protocolType},#{areaId},#{sectionId},
@@ -271,6 +274,9 @@
                 <if test="operator != null and operator != ''">
                     #{operator},
                 </if>
+                <if test="ctType != null and ctType != ''">
+                    #{ctType},
+                </if>
                 #{createTime},#{userId})
     </insert>