|
@@ -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);
|
|
|
+ }
|
|
|
}
|