Kaynağa Gözat

添加编辑删除配电柜、空开

crazycat 2 yıl önce
ebeveyn
işleme
485e854c96

+ 5 - 0
pom.xml

@@ -110,6 +110,11 @@
             <artifactId>spring-social-web</artifactId>
             <version>1.1.6.RELEASE</version>
         </dependency>
+        <dependency>
+            <groupId>commons-httpclient</groupId>
+            <artifactId>commons-httpclient</artifactId>
+            <version>3.1</version>
+        </dependency>
     </dependencies>
 
     <repositories>  <!-- 配置阿里云镜像仓库 -->

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

@@ -38,6 +38,10 @@ public enum InterfaceResultEnum {
     LACK_MANHOLE_ADDRESS_ERROR("0231","请填写井盖设备地址","",""),
     MANHOLE_ADDRESS_UNIQUE_ERROR("0232","井盖设备地址重复","",""),
     LACK_MANHOLE_MODEL_ERROR("0233","请选择井盖设备型号","",""),
+    LACK_ELECTRIC_BOX_NAME_ERROR("0234","请填写配电柜名称","",""),
+    ELECTRIC_BOX_NAME_UNIQUE_ERROR("0235","配电柜名称重复!","",""),
+    LACK_ELECTRIC_MODULE_ERROR("0236","请添加通信模块","",""),
+    LACK_ELECTRIC_MODULE_ADDRESS_ERROR("0237","通信模块地址不能为空!","",""),
     ;
     private String code;
     private String msgCn;

+ 65 - 0
src/main/java/com/welampiot/common/LampControlTypeEnum.java

@@ -0,0 +1,65 @@
+package com.welampiot.common;
+
+public enum LampControlTypeEnum {
+
+    WE_MA_10(0, "WE-MA-10"),
+    WE_MA_20(1, "WE-MA-20"),
+    WE_CON_10(2, "WE-CON-10"),
+    WE_CON_20(3, "WE-CON-20"),
+    WE_CON_P10(4, "WE-CON-P10"),
+    WE_CON_4G20(5, "WE-CON-4G20"),
+    WE_CON_4G11(6, "WE-CON-4G11"),
+    WE_CON_4G10(7, "WE-CON-4G10"),
+    WE_CON_P20(8, "WE-CON-P20"),
+    WE_CON_N20(9, "WE-CON-N20"),
+    WE_CON_N10(10, "WE-CON-N10"),
+    PGH_125_051A(11, "PGH-125-051A"),
+    LHS_120_HP18G0(12, "LHS-120-HP18G0"),
+    SZ10_R1A_M(13, "SZ10-R1A-M"),
+    PGH_060_046(14, "PGH-060-046"),
+    WE_MA_4G10(15, "WE-MA-4G10"),
+    WE_CON_ZB10(16, "WE-CON-ZB10"),
+    WE_CON_R20(17, "WE-CON-R20"),
+    WE_CON_R10(18, "WE-CON-R10"),
+    WE_MA_N30(19, "WE-MA-N30"),
+    WE_ZH_4GS(20, "WE-ZH-4GS"),
+    WE_CON_4GH10(21, "WE-CON-4GH10"),
+    WE_CON_4GH20(22, "WE-CON-4GH20"),
+    WE_CON_4G15(23, "WE-CON-4G15"),
+    WE_CON_B10(24, "WE-CON-B10"),
+    WE_CON_B20(24, "WE-CON-B20"),
+    WE_CON_PW10(26, "WE-CON-PW10"),
+    WE_CON_PW20(27, "WE-CON-PW20"),
+    WE_MA_B10(28, "WE-MA-B10"),
+    ;
+    private final Integer id;
+    private final String name;
+
+    LampControlTypeEnum(Integer id, String name) {
+        this.id = id;
+        this.name = name;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * 转为数据
+     * @return 枚举对象数组
+     */
+//    public static List<Map<String, String>> toList() {
+//        List<Map<String, String>> list = new ArrayList<>();
+//        for (LampControlTypeEnum item : LampControlTypeEnum.values()) {
+//            Map<String, String> map = new HashMap<>();
+//            map.put("code", item.getCode());
+//            map.put("name", item.getName());
+//            list.add(map);
+//        }
+//        return list;
+//    }
+}

+ 0 - 20
src/main/java/com/welampiot/configuration/LampConfig.java

@@ -1,20 +0,0 @@
-package com.welampiot.configuration;
-
-import com.welampiot.common.YamlPropertySourceFactory;
-import lombok.Data;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.PropertySource;
-import org.springframework.stereotype.Component;
-
-import java.util.List;
-import java.util.Map;
-
-@Component
-@PropertySource(factory = YamlPropertySourceFactory.class,value = "classpath:config/lamp.yml", encoding = "utf-8")
-@ConfigurationProperties(prefix = "lamp")
-@Data
-public class LampConfig {
-    public Map<Integer, String> controlType;
-}

+ 64 - 1
src/main/java/com/welampiot/controller/ElectricBoxController.java

@@ -11,6 +11,8 @@ import com.welampiot.vo.AirSwitchDetailVO;
 import com.welampiot.vo.AirSwitchInfoReturnVO;
 import com.welampiot.vo.ElectricBoxReturnVO;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.web.bind.annotation.CrossOrigin;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -98,9 +100,70 @@ public class ElectricBoxController {
         return BaseResult.success(airSwitchDetail);
     }
 
+    /**
+     * 添加编辑配电柜
+     * @param electricBoxDTO
+     * @return
+     */
     @PostMapping("/saveDev")
+    @Transactional
     public BaseResult saveDev(ElectricBoxDTO electricBoxDTO){
+        System.out.println(electricBoxDTO.getModuleList());
         Integer version = electricBoxDTO.getVersion() == null ? 0 : electricBoxDTO.getVersion();
-        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
+        BaseResult res;
+        if (electricBoxDTO.getId() != null && electricBoxDTO.getId() > 0){
+            res = electricBoxService.add(electricBoxDTO);
+        }else {
+            res = electricBoxService.update(electricBoxDTO);
+        }
+        if (!res.getCode().equals("0000")){
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+        }
+        return res;
+    }
+    /**
+     * 添加编辑空开
+     * @param electricBoxDTO
+     * @return
+     */
+    @PostMapping("/saveAirSwitch")
+    @Transactional
+    public BaseResult saveAirSwitch(AirSwitchInfoDTO airSwitchInfoDTO){
+        Integer version = airSwitchInfoDTO.getVersion() == null ? 0 : airSwitchInfoDTO.getVersion();
+        BaseResult res;
+        if (airSwitchInfoDTO.getId() != null && airSwitchInfoDTO.getId() > 0){
+            res = airSwitchInfoService.add(airSwitchInfoDTO);
+        }else {
+            res = airSwitchInfoService.update(airSwitchInfoDTO);
+        }
+        if (!res.getCode().equals("0000")){
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+        }
+        return res;
+    }
+    /**
+     * 删除空开
+     * @param electricBoxDTO
+     * @return
+     */
+    @PostMapping("/delAirSwitch")
+    @Transactional
+    public BaseResult delAirSwitch(AirSwitchInfoDTO airSwitchInfoDTO){
+        if (airSwitchInfoDTO.getId() == null || airSwitchInfoDTO.getId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,airSwitchInfoDTO.getVersion());
+        airSwitchInfoService.delete(airSwitchInfoDTO);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,airSwitchInfoDTO.getVersion());
+    }
+
+    /**
+     * 删除配电柜
+     * @param electricBoxDTO
+     * @return
+     */
+    @PostMapping("/delDev")
+    @Transactional
+    public BaseResult delDev(ElectricBoxDTO electricBoxDTO){
+        if (electricBoxDTO.getId() == null || electricBoxDTO.getId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,electricBoxDTO.getVersion());
+        electricBoxService.delete(electricBoxDTO);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,electricBoxDTO.getVersion());
     }
 }

+ 5 - 0
src/main/java/com/welampiot/dao/AirSwitchInfoDao.java

@@ -1,6 +1,7 @@
 package com.welampiot.dao;
 
 import com.welampiot.dto.AirSwitchInfoDTO;
+import com.welampiot.dto.ElectricBoxDTO;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -28,4 +29,8 @@ public interface AirSwitchInfoDao {
     String getPolicyNameByPolicyId(@Param("policyId") Integer policyId);
 
     AirSwitchInfoDTO getAirSwitchDetailById(@Param("id") Integer id);
+    Integer add(AirSwitchInfoDTO dto);
+    Integer update(AirSwitchInfoDTO dto);
+    Integer delete(AirSwitchInfoDTO dto);
+    Integer deleteByBoxId(@Param("boxId") Integer boxId);
 }

+ 6 - 0
src/main/java/com/welampiot/dao/ElectricBoxDao.java

@@ -1,6 +1,7 @@
 package com.welampiot.dao;
 
 import com.welampiot.dto.ElectricBoxDTO;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -21,4 +22,9 @@ public interface ElectricBoxDao {
     Integer getOnlineTotalByStatus(ElectricBoxDTO dto);
 
     Integer getOfflineTotalByStatus(ElectricBoxDTO dto);
+    Integer add(ElectricBoxDTO dto);
+    Integer update(ElectricBoxDTO dto);
+    Integer checkData(ElectricBoxDTO dto);
+    Integer delete(ElectricBoxDTO dto);
+    ElectricBoxDTO getDetailsById(@Param("id") Integer id);
 }

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

@@ -9,4 +9,6 @@ public interface ElectricModuleDao {
     Integer add(ElectricModuleDTO electricModuleDTO);
     Integer update(ElectricModuleDTO electricModuleDTO);
     List<ElectricModuleDTO> getListByBoxId(@Param("boxId")Integer boxId);
+    Integer deleteByBoxId(@Param("boxId") Integer boxId);
+    ElectricModuleDTO getDetailsById(@Param("id") Integer id);
 }

+ 5 - 0
src/main/java/com/welampiot/dto/AirSwitchInfoDTO.java

@@ -121,4 +121,9 @@ public class AirSwitchInfoDTO implements Serializable {
     private Integer timezone;
 
     private static final long serialVersionUID = 1L;
+    private Integer moduleId;
+    private Integer pNum;
+    private String plcMacAddress;
+    private String lampId;
+    private Integer version;
 }

+ 7 - 0
src/main/java/com/welampiot/service/AirSwitchInfoService.java

@@ -1,7 +1,10 @@
 package com.welampiot.service;
 
+import com.welampiot.common.BaseResult;
+import com.welampiot.dto.AirSwitchInfoDTO;
 import com.welampiot.vo.AirSwitchDetailVO;
 import com.welampiot.vo.AirSwitchInfoReturnVO;
+import org.apache.ibatis.annotations.Param;
 
 
 /**
@@ -17,4 +20,8 @@ public interface AirSwitchInfoService {
     AirSwitchInfoReturnVO getAirSwitchInfo(Integer boxId, Integer online);
 
     AirSwitchDetailVO getAirSwitchDetail(Integer id);
+    BaseResult add(AirSwitchInfoDTO dto);
+    BaseResult update(AirSwitchInfoDTO dto);
+    Integer delete(AirSwitchInfoDTO dto);
+    Integer deleteByBoxId(@Param("boxId") Integer boxId);
 }

+ 8 - 0
src/main/java/com/welampiot/service/ElectricBoxService.java

@@ -1,7 +1,10 @@
 package com.welampiot.service;
 
+import com.welampiot.common.BaseResult;
+import com.welampiot.dto.AirSwitchInfoDTO;
 import com.welampiot.dto.ElectricBoxDTO;
 import com.welampiot.vo.ElectricBoxReturnVO;
+import org.apache.ibatis.annotations.Param;
 
 
 /**
@@ -21,4 +24,9 @@ public interface ElectricBoxService {
     Integer getOnlineTotalByStatus(ElectricBoxDTO dto);
 
     Integer getOfflineTotalByStatus(ElectricBoxDTO dto);
+    BaseResult add(ElectricBoxDTO dto);
+    BaseResult update(ElectricBoxDTO dto);
+    Integer checkData(ElectricBoxDTO dto);
+    Integer delete(ElectricBoxDTO dto);
+    ElectricBoxDTO getDetailsById(@Param("id") Integer id);
 }

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

@@ -9,4 +9,6 @@ public interface ElectricModuleService {
     Integer add(ElectricModuleDTO electricModuleDTO);
     Integer update(ElectricModuleDTO electricModuleDTO);
     List<ElectricModuleDTO> getListByBoxId(@Param("boxId")Integer boxId);
+    Integer deleteByBoxId(@Param("boxId") Integer boxId);
+    ElectricModuleDTO getDetailsById(@Param("id") Integer id);
 }

+ 40 - 0
src/main/java/com/welampiot/service/impl/AirSwitchInfoServiceImpl.java

@@ -1,8 +1,14 @@
 package com.welampiot.service.impl;
 
+import com.welampiot.common.BaseResult;
+import com.welampiot.common.InterfaceResultEnum;
 import com.welampiot.dao.AirSwitchInfoDao;
 import com.welampiot.dto.AirSwitchInfoDTO;
+import com.welampiot.dto.ElectricModuleDTO;
 import com.welampiot.service.AirSwitchInfoService;
+import com.welampiot.service.ElectricBoxService;
+import com.welampiot.service.ElectricModuleService;
+import com.welampiot.utils.ToolUtils;
 import com.welampiot.vo.AirSwitchDetailVO;
 import com.welampiot.vo.AirSwitchInfoReturnVO;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -28,6 +34,12 @@ public class AirSwitchInfoServiceImpl implements AirSwitchInfoService {
 
     @Autowired
     private AirSwitchInfoDao airSwitchInfoDao;
+    @Autowired
+    private ToolUtils toolUtils;
+    @Autowired
+    private ElectricModuleService electricModuleService;
+    @Autowired
+    private ElectricBoxService electricBoxService;
 
     @Override
     public AirSwitchInfoReturnVO getAirSwitchInfo(Integer boxId, Integer online) {
@@ -97,4 +109,32 @@ public class AirSwitchInfoServiceImpl implements AirSwitchInfoService {
             }
         return airSwitchDetailVO;
     }
+
+    @Override
+    public BaseResult add(AirSwitchInfoDTO dto) {
+        ElectricModuleDTO detailsById = electricModuleService.getDetailsById(dto.getModuleId());
+        dto.setBoxId(detailsById.getBoxId());
+        dto.setBoxAddress(detailsById.getAddress());
+        airSwitchInfoDao.add(dto);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,dto.getVersion());
+    }
+
+    @Override
+    public BaseResult update(AirSwitchInfoDTO dto) {
+        ElectricModuleDTO detailsById = electricModuleService.getDetailsById(dto.getModuleId());
+        dto.setBoxId(detailsById.getBoxId());
+        dto.setBoxAddress(detailsById.getAddress());
+        airSwitchInfoDao.update(dto);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,dto.getVersion());
+    }
+
+    @Override
+    public Integer delete(AirSwitchInfoDTO dto) {
+        return airSwitchInfoDao.delete(dto);
+    }
+
+    @Override
+    public Integer deleteByBoxId(Integer boxId) {
+        return airSwitchInfoDao.deleteByBoxId(boxId);
+    }
 }

+ 91 - 1
src/main/java/com/welampiot/service/impl/ElectricBoxServiceImpl.java

@@ -1,10 +1,14 @@
 package com.welampiot.service.impl;
 
+import com.welampiot.common.BaseResult;
+import com.welampiot.common.InterfaceResultEnum;
 import com.welampiot.dao.ElectricBoxDao;
 import com.welampiot.dto.ElectricBoxDTO;
 import com.welampiot.dto.ElectricModuleDTO;
+import com.welampiot.service.AirSwitchInfoService;
 import com.welampiot.service.ElectricBoxService;
 import com.welampiot.service.ElectricModuleService;
+import com.welampiot.utils.ToolUtils;
 import com.welampiot.vo.ElectricBoxReturnVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -32,7 +36,10 @@ public class ElectricBoxServiceImpl implements ElectricBoxService {
     private ElectricBoxDao electricBoxDao;
     @Autowired
     protected ElectricModuleService electricModuleService;
-
+    @Autowired
+    private ToolUtils toolUtils;
+    @Autowired
+    private AirSwitchInfoService airSwitchInfoService;
     @Override
     public ElectricBoxReturnVO getElectricBoxListBySectionId(ElectricBoxDTO dto) {
         ElectricBoxReturnVO electricBoxReturnVO = new ElectricBoxReturnVO();
@@ -101,4 +108,87 @@ public class ElectricBoxServiceImpl implements ElectricBoxService {
     public Integer getOfflineTotalByStatus(ElectricBoxDTO dto) {
         return electricBoxDao.getOfflineTotalByStatus(dto);
     }
+
+    @Override
+    public BaseResult add(ElectricBoxDTO dto) {
+        if (dto.getAreaId() == 0 || dto.getAreaId() == null) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,dto.getVersion());
+        if (dto.getSectionId() == 0 || dto.getSectionId() == null) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,dto.getVersion());
+        if (dto.getName() == null || dto.getName().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_ELECTRIC_BOX_NAME_ERROR,dto.getVersion());
+        ElectricBoxDTO electricBoxDTO = new ElectricBoxDTO();
+        electricBoxDTO.setSectionId(dto.getSectionId());
+        electricBoxDTO.setName(dto.getName());
+        if (electricBoxDao.checkData(electricBoxDTO).intValue() > 0) return toolUtils.response(InterfaceResultEnum.ELECTRIC_BOX_NAME_UNIQUE_ERROR,dto.getVersion());
+        if (dto.getModuleList() == null || dto.getModuleList().isEmpty()) return toolUtils.response(InterfaceResultEnum.LACK_ELECTRIC_MODULE_ERROR,dto.getVersion());
+        electricBoxDao.add(dto);
+        List<Map> moduleList = dto.getModuleList();
+        for (Map map:moduleList) {
+            ElectricModuleDTO electricModuleDTO = new ElectricModuleDTO();
+            if (map.containsKey("id")) electricModuleDTO.setId(Integer.parseInt((String) map.get("id")));
+            electricModuleDTO.setBoxId(dto.getId());
+            if (map.containsKey("address") && map.get("address").toString().length() > 0) {
+                electricModuleDTO.setAddress((String) map.get("address"));
+            }else {
+                return toolUtils.response(InterfaceResultEnum.LACK_ELECTRIC_MODULE_ADDRESS_ERROR,dto.getVersion());
+            }
+            electricModuleDTO.setType(Integer.parseInt((String) map.get("type")));
+            if (electricModuleDTO.getId() != null && electricModuleDTO.getId() > 0){
+                electricModuleService.add(electricModuleDTO);
+            }else {
+                electricModuleService.update(electricModuleDTO);
+            }
+
+        }
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,dto.getVersion());
+    }
+
+    @Override
+    public BaseResult update(ElectricBoxDTO dto) {
+        if (dto.getAreaId() == 0 || dto.getAreaId() == null) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,dto.getVersion());
+        if (dto.getSectionId() == 0 || dto.getSectionId() == null) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,dto.getVersion());
+        if (dto.getName() == null || dto.getName().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_ELECTRIC_BOX_NAME_ERROR,dto.getVersion());
+        ElectricBoxDTO electricBoxDTO = new ElectricBoxDTO();
+        electricBoxDTO.setSectionId(dto.getSectionId());
+        electricBoxDTO.setName(dto.getName());
+        electricBoxDTO.setId(dto.getId());
+        if (electricBoxDao.checkData(electricBoxDTO).intValue() > 0) return toolUtils.response(InterfaceResultEnum.ELECTRIC_BOX_NAME_UNIQUE_ERROR,dto.getVersion());
+        if (dto.getModuleList() == null || dto.getModuleList().isEmpty()) return toolUtils.response(InterfaceResultEnum.LACK_ELECTRIC_MODULE_ERROR,dto.getVersion());
+        electricBoxDao.add(dto);
+        List<Map> moduleList = dto.getModuleList();
+        for (Map map:moduleList) {
+            ElectricModuleDTO electricModuleDTO = new ElectricModuleDTO();
+            if (map.containsKey("id")) electricModuleDTO.setId(Integer.parseInt((String) map.get("id")));
+            electricModuleDTO.setBoxId(dto.getId());
+            if (map.containsKey("address") && map.get("address").toString().length() > 0) {
+                electricModuleDTO.setAddress((String) map.get("address"));
+            }else {
+                return toolUtils.response(InterfaceResultEnum.LACK_ELECTRIC_MODULE_ADDRESS_ERROR,dto.getVersion());
+            }
+            electricModuleDTO.setType(Integer.parseInt((String) map.get("type")));
+            if (electricModuleDTO.getId() != null && electricModuleDTO.getId() > 0){
+                electricModuleService.add(electricModuleDTO);
+            }else {
+                electricModuleService.update(electricModuleDTO);
+            }
+
+        }
+        electricBoxDao.update(dto);
+        return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,dto.getVersion());
+    }
+
+    @Override
+    public Integer checkData(ElectricBoxDTO dto) {
+        return electricBoxDao.checkData(dto);
+    }
+
+    @Override
+    public Integer delete(ElectricBoxDTO dto) {
+        airSwitchInfoService.deleteByBoxId(dto.getId());
+        electricModuleService.deleteByBoxId(dto.getId());
+        return electricBoxDao.delete(dto);
+    }
+
+    @Override
+    public ElectricBoxDTO getDetailsById(Integer id) {
+        return electricBoxDao.getDetailsById(id);
+    }
 }

+ 10 - 0
src/main/java/com/welampiot/service/impl/ElectricModuleServiceImpl.java

@@ -26,4 +26,14 @@ public class ElectricModuleServiceImpl implements ElectricModuleService {
     public List<ElectricModuleDTO> getListByBoxId(Integer boxId) {
         return electricModuleDao.getListByBoxId(boxId);
     }
+
+    @Override
+    public Integer deleteByBoxId(Integer boxId) {
+        return electricModuleDao.deleteByBoxId(boxId);
+    }
+
+    @Override
+    public ElectricModuleDTO getDetailsById(Integer id) {
+        return electricModuleDao.getDetailsById(id);
+    }
 }

+ 1 - 8
src/main/java/com/welampiot/service/impl/LampServiceImpl.java

@@ -2,7 +2,6 @@ package com.welampiot.service.impl;
 
 import com.welampiot.common.BaseResult;
 import com.welampiot.common.InterfaceResultEnum;
-import com.welampiot.configuration.LampConfig;
 import com.welampiot.dao.LampDao;
 import com.welampiot.dto.LampInfoDTO;
 import com.welampiot.dto.NetworkDTO;
@@ -27,8 +26,6 @@ public class LampServiceImpl implements LampService {
     @Autowired
     private LampDao lampDao;
     @Autowired
-    private LampConfig lampConfig;
-    @Autowired
     private ToolUtils toolUtils;
     @Autowired
     private LampInfoLogService lampInfoLogService;
@@ -95,11 +92,7 @@ public class LampServiceImpl implements LampService {
             if (lamp.getPolicyName() == null || lamp.getPolicyType() != 1){
                 lamp.setPolicyName("暂无");
             }
-            if (lampConfig.getControlType().containsKey(lamp.getControlType())){
-                lamp.setControlTypeStr(lampConfig.getControlType().get(lamp.getControlType()));
-            }else {
-                lamp.setControlTypeStr("");
-            }
+            lamp.setControlTypeStr(toolUtils.getLampControlNameById(lamp.getControlType()));
             if (lamp.getControlType() == 5){
                 if (lamp.getMode() == 0){
                     lamp.setNumber(lamp.getNumber()+"-1");

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

@@ -1,7 +1,9 @@
 package com.welampiot.utils;
 
+import com.alibaba.fastjson.JSON;
 import com.welampiot.common.BaseResult;
 import com.welampiot.common.InterfaceResultEnum;
+import com.welampiot.common.LampControlTypeEnum;
 import com.welampiot.configuration.MqttConfig;
 import com.welampiot.dto.GlobalLocationDTO;
 import com.welampiot.dto.SectionDTO;
@@ -10,6 +12,9 @@ import com.welampiot.handle.MqttHandler;
 import com.welampiot.service.GlobalLocationService;
 import com.welampiot.service.SectionService;
 import com.welampiot.service.UserService;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.params.HttpMethodParams;
 import org.eclipse.paho.client.mqttv3.MqttClient;
 import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
 import org.eclipse.paho.client.mqttv3.MqttMessage;
@@ -18,6 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
 import java.util.*;
 
 @Component
@@ -385,4 +391,95 @@ public class ToolUtils {
         }
         return request.getParameter(key);
     }
+
+    /**
+     * 发送post请求
+     * @param url 请求地址
+     * @param paraMap 请求参数
+     * @return
+     */
+    public String httpPost(String url,Map paraMap){
+        HttpClient httpClient = new HttpClient();
+        httpClient.getHttpConnectionManager().getParams().setSoTimeout(30000);
+        PostMethod postMethod = new PostMethod(url);
+
+        postMethod.addRequestHeader("accept", "*/*");
+        //设置Content-Type
+        postMethod.addRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+        //添加请求参数
+        Set set = paraMap.keySet();
+        for (Object s : set) {
+            postMethod.addParameter((String) s, (String) paraMap.get(s));
+        }
+        String result = "";
+        try {
+            int code = httpClient.executeMethod(postMethod);
+            if (code == 200){
+                result = postMethod.getResponseBodyAsString();
+            }
+        } catch (IOException e) {
+//            e.printStackTrace();
+        }
+        return result;
+    }
+
+    /**
+     * 发送post请求
+     * @param url 请求地址
+     * @param paraMap 请求参数
+     * @param timeout 超时时间
+     * @return
+     */
+    public String httpPost(String url,Map paraMap,int timeout){
+        HttpClient httpClient = new HttpClient();
+        httpClient.getHttpConnectionManager().getParams().setSoTimeout(timeout);
+        PostMethod postMethod = new PostMethod(url);
+
+        postMethod.addRequestHeader("accept", "*/*");
+        //设置Content-Type
+        postMethod.addRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+        //添加请求参数
+        Set set = paraMap.keySet();
+        for (Object s : set) {
+            postMethod.addParameter((String) s, (String) paraMap.get(s));
+        }
+        String result = "";
+        try {
+            int code = httpClient.executeMethod(postMethod);
+            if (code == 200){
+                result = postMethod.getResponseBodyAsString();
+            }
+        } catch (IOException e) {
+//            e.printStackTrace();
+        }
+        return result;
+    }
+
+    /**
+     * 通过id获取控制器型号名称
+     * @param id
+     * @return
+     */
+    public String getLampControlNameById(Integer id){
+        for (LampControlTypeEnum value : LampControlTypeEnum.values()) {
+            if (value.getId().intValue() == id.intValue()){
+                return value.getName();
+            }
+        }
+        return "";
+    }
+
+    /**
+     * 通过控制器型号名称获取型号id
+     * @param id
+     * @return
+     */
+    public Integer getLampControlIdByName(String name){
+        for (LampControlTypeEnum value : LampControlTypeEnum.values()) {
+            if (value.getName().equals(name)){
+                return value.getId();
+            }
+        }
+        return 0;
+    }
 }

+ 0 - 30
src/main/resources/config/lamp.yml

@@ -1,30 +0,0 @@
-lamp:
-  controlType: {0: 'WE-MA-10',
-                1: 'WE-MA-20',
-                2: 'WE-CON-10',
-                3: 'WE-CON-20',
-                4: 'WE-CON-P10',
-                5: 'WE-CON-4G20',
-                6: 'WE-CON-4G11',
-                7: 'WE-CON-4G10',
-                8: 'WE-CON-P20',
-                9: 'WE-CON-N20',
-                10: 'WE-CON-N10',
-                11: 'PGH-125-051A',
-                12: 'LHS-120-HP18G0',
-                13: 'SZ10-R1A-M',
-                14: 'PGH-060-046',
-                15: 'WE-MA-4G10',
-                16: 'WE-CON-ZB10',
-                17: 'WE-CON-R20',
-                18: 'WE-CON-R10',
-                19: 'WE-MA-N30',
-                20: 'WE-ZH-4GS',
-                21: 'WE-CON-4GH10',
-                22: 'WE-CON-4GH20',
-                23: 'WE-CON-4G15',
-                24: 'WE-CON-B10',
-                25: 'WE-CON-B20',
-                26: 'WE-CON-PW10',
-                27: 'WE-CON-PW20'
-  }

+ 39 - 0
src/main/resources/mapper/AirSwitchInfoMapper.xml

@@ -47,5 +47,44 @@
     <select id="getAirSwitchDetailById" resultType="AirSwitchInfoDTO" parameterType="Integer">
         select a.name,a.box_id boxId,a.address,a.type from air_switch_info a where a.id = #{id}
     </select>
+    <insert id="add" parameterType="com.welampiot.dto.AirSwitchInfoDTO" useGeneratedKeys="true" keyProperty="id"
+    >
+        insert into air_switch_info(name,address,type,p_num,createtime,module_id
+        <if test="boxId != null">,box_id</if>
+        <if test="lampPoleId != null">,lamp_pole_id</if>
+        <if test="boxAddress != null">,box_address</if>
+        <if test="serialPort != null">,serial_port</if>
+        )
+        values
+        (#{name},#{address},#{type},#{pNum},#{createTime},#{moduleId}
+        <if test="boxId != null">,#{boxId}</if>
+        <if test="lampPoleId != null">,#{lampPoleId}</if>
+        <if test="boxAddress != null">,#{boxAddress}</if>
+        <if test="serialPort != null">,#{serialPort}</if>
+        )
+    </insert>
+    <update id="update" parameterType="com.welampiot.dto.AirSwitchInfoDTO"
+    >
+        update air_switch_info
+        set
+        name=#{name},
+        address=#{address},
+        type=#{type},
+        p_num=#{pum},
+        createtime=#{createTime},
+        module_id=#{moduleId}
+        <if test="boxId != null">,box_id=#{boxId},</if>
+        <if test="lampPoleId != null">,lamp_pole_id=#{lampPoleId}</if>
+        <if test="boxAddress != null">,box_address=#{boxAddress}</if>
+        <if test="serialPort != null">,serial_port=#{serialPort}</if>
 
+        where id = #{id}
+    </update>
+
+    <delete id="delete" parameterType="com.welampiot.dto.AirSwitchInfoDTO">
+        delete from air_switch_info where id=#{id}
+    </delete>
+    <delete id="deleteByBoxId" parameterType="int">
+        delete from air_switch_info where box_id=#{boxId}
+    </delete>
 </mapper>

+ 30 - 0
src/main/resources/mapper/ElectricBoxMapper.xml

@@ -102,4 +102,34 @@
 
         where id = #{id}
     </update>
+
+    <select id="checkData" resultType="Integer" parameterType="ElectricBoxDTO">
+        select count(e.id)
+        from electric_box e
+        where 1=1
+        <if test="sectionList != null and !sectionList.isEmpty()">
+            and e.sectionid in
+            <foreach item="dto" collection="sectionList" open="(" separator="," close=")">
+                #{dto}
+            </foreach>
+        </if>
+        <if test="sectionId != null">
+            and e.sectionid = #{sectionId}
+        </if>
+        <if test="name != null">
+            and e.name = #{name}
+        </if>
+        <if test="id != null">
+            and e.id != #{id}
+        </if>
+    </select>
+    <delete id="delete" parameterType="com.welampiot.dto.AirSwitchInfoDTO">
+        delete from electric_box where id=#{id}
+    </delete>
+
+    <select id="getDetailsById" resultType="com.welampiot.dto.ElectricBoxDTO" parameterType="int">
+        select id,areaid as areaId,sectionid as sectionId,name,address,longitude,latitude,image,install_date installDate,expiration_date expirationDate,devType
+        from electric_box
+        where id = #{id}
+    </select>
 </mapper>

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

@@ -22,4 +22,10 @@
     <select id="getListByBoxId" resultType="com.welampiot.dto.ElectricModuleDTO" parameterType="int">
         select address,id,box_id as boxId,type from electric_module where box_id = #{boxId}
     </select>
+    <select id="getDetailsById" resultType="com.welampiot.dto.ElectricModuleDTO" parameterType="int">
+        select address,id,box_id as boxId,type from electric_module where id = #{id}
+    </select>
+    <delete id="deleteByBoxId" parameterType="int">
+        delete from electric_module where box_id=#{boxId}
+    </delete>
 </mapper>