|
@@ -3,6 +3,7 @@ package com.welampiot.service.impl;
|
|
|
import com.welampiot.common.BaseResult;
|
|
|
import com.welampiot.common.InterfaceResultEnum;
|
|
|
import com.welampiot.dao.LampPoleDao;
|
|
|
+import com.welampiot.dao.WifiDao;
|
|
|
import com.welampiot.dto.LampInfoDTO;
|
|
|
import com.welampiot.dto.LampPoleAlarmLogDTO;
|
|
|
import com.welampiot.dto.LampPoleDTO;
|
|
@@ -12,16 +13,13 @@ import com.welampiot.service.LampPoleService;
|
|
|
import com.welampiot.service.LampService;
|
|
|
import com.welampiot.service.WifiService;
|
|
|
import com.welampiot.utils.ToolUtils;
|
|
|
-import com.welampiot.vo.LampCountVO;
|
|
|
-import com.welampiot.vo.LampPoleCountVO;
|
|
|
-import com.welampiot.vo.LampPoleVO;
|
|
|
+import com.welampiot.vo.*;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class LampPoleServiceImpl implements LampPoleService {
|
|
@@ -113,13 +111,14 @@ public class LampPoleServiceImpl implements LampPoleService {
|
|
|
@Override
|
|
|
public BaseResult add(LampPoleVO lampPoleVO) {
|
|
|
LampPoleDTO lampPoleDTO = new LampPoleDTO();
|
|
|
+ lampPoleDTO.setCreateId(lampPoleVO.getCreateId());
|
|
|
if (lampPoleVO.getAreaId() == null || lampPoleVO.getAreaId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,lampPoleVO.getVersion());
|
|
|
if (lampPoleVO.getSectionId() == null || lampPoleVO.getSectionId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,lampPoleVO.getVersion());
|
|
|
|
|
|
if (lampPoleVO.getName() == null || lampPoleVO.getName().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_NAME_ERROR,lampPoleVO.getVersion());
|
|
|
if (lampPoleVO.getNumber() == null || lampPoleVO.getNumber().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_POLE_NUMBER_ERROR,lampPoleVO.getVersion());
|
|
|
|
|
|
- if (lampPoleVO.getNumber().matches("^[A-Za-z0-9_]+$")) return toolUtils.response(InterfaceResultEnum.LAMP_POLE_NUMBER_FORMAT_ERROR,lampPoleVO.getVersion());
|
|
|
+ if (!lampPoleVO.getNumber().matches("^[A-Za-z0-9_]+$")) return toolUtils.response(InterfaceResultEnum.LAMP_POLE_NUMBER_FORMAT_ERROR,lampPoleVO.getVersion());
|
|
|
LampPoleCountVO lampPoleVO1 = new LampPoleCountVO();
|
|
|
lampPoleVO1.setSectionId(lampPoleVO.getSectionId());
|
|
|
lampPoleVO1.setName(lampPoleVO.getName());
|
|
@@ -133,19 +132,27 @@ public class LampPoleServiceImpl implements LampPoleService {
|
|
|
lampPoleDTO.setNumber(lampPoleVO.getNumber());
|
|
|
lampPoleDTO.setAreaId(lampPoleVO.getAreaId());
|
|
|
lampPoleDTO.setSectionId(lampPoleVO.getSectionId());
|
|
|
- lampPoleDTO.setHeight(lampPoleVO.getHeight());
|
|
|
+ lampPoleDTO.setHeight(lampPoleVO.getHeight() == null ? 0 : lampPoleVO.getHeight());
|
|
|
+ lampPoleDTO.setLatitude(lampPoleVO.getLatitude());
|
|
|
+ lampPoleDTO.setLongitude(lampPoleVO.getLongitude());
|
|
|
lampPoleDTO.setInstallDate(lampPoleVO.getInstallDate());
|
|
|
lampPoleDTO.setExpirationDate(lampPoleVO.getExpirationDate());
|
|
|
+ Date endDate = new Date(System.currentTimeMillis());
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String createTime = simpleDateFormat.format(endDate).toString();
|
|
|
+ lampPoleDTO.setCreateTime(createTime);
|
|
|
lampPoleDao.add(lampPoleDTO);
|
|
|
+ List<Integer> devType = new ArrayList<>();
|
|
|
|
|
|
Integer id = lampPoleDTO.getId();
|
|
|
// 添加云盒
|
|
|
Map cloudBox = lampPoleVO.getCloudBox();
|
|
|
WifiDTO wifiDTO = new WifiDTO();
|
|
|
wifiDTO.setLampPoleId(id);
|
|
|
- if (cloudBox.containsKey("sn")) wifiDTO.setNum((String) cloudBox.get("sn"));
|
|
|
+ wifiDTO.setVersion2(lampPoleVO.getVersion());
|
|
|
+ if (cloudBox.containsKey("sn")) wifiDTO.setSn((String) cloudBox.get("sn"));
|
|
|
if (cloudBox.containsKey("ipAddr")) wifiDTO.setIpAddr((String) cloudBox.get("ipAddr"));
|
|
|
- if (cloudBox.containsKey("model")) wifiDTO.setModel((Integer) cloudBox.get("model"));
|
|
|
+ if (cloudBox.containsKey("model")) wifiDTO.setModel((String) cloudBox.get("model"));
|
|
|
if (cloudBox.containsKey("remark1")) wifiDTO.setRemark1((String) cloudBox.get("remark1"));
|
|
|
if (cloudBox.containsKey("remark2")) wifiDTO.setRemark2((String) cloudBox.get("remark2"));
|
|
|
if (cloudBox.containsKey("remark3")) wifiDTO.setRemark3((String) cloudBox.get("remark3"));
|
|
@@ -154,14 +161,10 @@ public class LampPoleServiceImpl implements LampPoleService {
|
|
|
if (cloudBox.containsKey("remark6")) wifiDTO.setRemark6((String) cloudBox.get("remark6"));
|
|
|
if (cloudBox.containsKey("installDate")) wifiDTO.setInstallDate((String) cloudBox.get("installDate"));
|
|
|
if (cloudBox.containsKey("expirationDate")) wifiDTO.setExpirationDate((String) cloudBox.get("expirationDate"));
|
|
|
-// if (wifiDTO.getSn() == null || wifiDTO.getSn().length() == 0) return toolUtils.response();
|
|
|
- WifiDTO wifiDTO1 = new WifiDTO();
|
|
|
- ArrayList<Integer> integers = new ArrayList<>();
|
|
|
- integers.add(lampPoleVO.getSectionId());
|
|
|
- wifiDTO1.setSectionList(integers);
|
|
|
- wifiDTO1.setSn(wifiDTO.getSn());
|
|
|
-// if (wifiService.getCountByDTO(wifiDTO1).intValue() > 0) return toolUtils.response();
|
|
|
- wifiService.add(wifiDTO);
|
|
|
+ BaseResult add1 = wifiService.add(wifiDTO);
|
|
|
+ if (!add1.getCode().equals("0000")) return add1;
|
|
|
+ devType.add(10);
|
|
|
+ devType.add(2);
|
|
|
|
|
|
// 添加灯控
|
|
|
List<Map> lightDevList = lampPoleVO.getLightDevList();
|
|
@@ -171,20 +174,154 @@ public class LampPoleServiceImpl implements LampPoleService {
|
|
|
if (m.containsKey("address")) lampInfoDTO.setSn(m.get("address").toString());
|
|
|
if (m.containsKey("number")) lampInfoDTO.setNumber(m.get("number").toString());
|
|
|
if (m.containsKey("name")) lampInfoDTO.setName(m.get("name").toString());
|
|
|
- if (m.containsKey("protocoltype")) lampInfoDTO.setProtocolType((Integer) m.get("protocoltype"));
|
|
|
- if (m.containsKey("controlType")) lampInfoDTO.setControlType((Integer) m.get("controlType"));
|
|
|
- if (m.containsKey("ratedpower")) lampInfoDTO.setRatedPower((Integer) m.get("ratedpower"));
|
|
|
+ if (m.containsKey("protocolType")) lampInfoDTO.setProtocolType(Integer.parseInt((String) m.get("protocolType")));
|
|
|
+ if (m.containsKey("controlType")) lampInfoDTO.setControlType(Integer.parseInt((String) m.get("controlType")));
|
|
|
+ if (m.containsKey("ratedPower")) {
|
|
|
+ if ( m.get("ratedPower") == null || m.get("ratedPower").toString().length() == 0){
|
|
|
+ lampInfoDTO.setRatedPower(0);
|
|
|
+ }else {
|
|
|
+ lampInfoDTO.setRatedPower(Integer.parseInt((String) m.get("ratedPower")));
|
|
|
+ }
|
|
|
+ }
|
|
|
if (m.containsKey("installDate")) lampInfoDTO.setInstallDate( m.get("installDate").toString());
|
|
|
if (m.containsKey("expirationDate")) lampInfoDTO.setExpirationDate( m.get("expirationDate").toString());
|
|
|
+ lampInfoDTO.setCreateTime(createTime);
|
|
|
+ lampInfoDTO.setVersion(lampPoleVO.getVersion());
|
|
|
+ lampInfoDTO.setAreaId(lampPoleVO.getAreaId());
|
|
|
+ lampInfoDTO.setSectionId(lampPoleVO.getSectionId());
|
|
|
+ lampInfoDTO.setLatitude(lampPoleVO.getLatitude());
|
|
|
+ lampInfoDTO.setLongitude(lampPoleVO.getLongitude());
|
|
|
+ lampInfoDTO.setLampPoleId(id);
|
|
|
BaseResult add = lampService.add(lampInfoDTO);
|
|
|
if (!add.getCode().equals("0000")) return add;
|
|
|
}
|
|
|
+ devType.add(0);
|
|
|
+ LampPoleDTO lampPoleDTO1 = new LampPoleDTO();
|
|
|
+ lampPoleDTO1.setId(lampPoleDTO.getId());
|
|
|
+ lampPoleDTO1.setDevType(StringUtils.join(devType,","));
|
|
|
+ lampPoleDTO1.setSn(wifiDTO.getSn());
|
|
|
+ lampPoleDao.update(lampPoleDTO1);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,lampPoleVO.getVersion());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseResult update(LampPoleVO lampPoleVO) {
|
|
|
+ LampPoleDTO lampPoleDTO = new LampPoleDTO();
|
|
|
+ lampPoleDTO.setId(lampPoleVO.getId());
|
|
|
+ if (lampPoleVO.getAreaId() == null || lampPoleVO.getAreaId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,lampPoleVO.getVersion());
|
|
|
+ if (lampPoleVO.getSectionId() == null || lampPoleVO.getSectionId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,lampPoleVO.getVersion());
|
|
|
+
|
|
|
+ if (lampPoleVO.getName() == null || lampPoleVO.getName().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_NAME_ERROR,lampPoleVO.getVersion());
|
|
|
+ if (lampPoleVO.getNumber() == null || lampPoleVO.getNumber().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_POLE_NUMBER_ERROR,lampPoleVO.getVersion());
|
|
|
+
|
|
|
+ if (!lampPoleVO.getNumber().matches("^[A-Za-z0-9_]+$")) return toolUtils.response(InterfaceResultEnum.LAMP_POLE_NUMBER_FORMAT_ERROR,lampPoleVO.getVersion());
|
|
|
+ LampPoleCountVO lampPoleVO1 = new LampPoleCountVO();
|
|
|
+ lampPoleVO1.setId(lampPoleDTO.getId());
|
|
|
+ lampPoleVO1.setSectionId(lampPoleVO.getSectionId());
|
|
|
+ lampPoleVO1.setName(lampPoleVO.getName());
|
|
|
+ if (lampPoleDao.getCountByVO(lampPoleVO1).intValue() > 0) return toolUtils.response(InterfaceResultEnum.LAMP_POLE_NAME_UNIQUE_ERROR,lampPoleVO.getVersion());
|
|
|
|
|
|
+ lampPoleVO1 = new LampPoleCountVO();
|
|
|
+ lampPoleVO1.setId(lampPoleDTO.getId());
|
|
|
+ lampPoleVO1.setSectionId(lampPoleVO.getSectionId());
|
|
|
+ lampPoleVO1.setNumber(lampPoleVO.getNumber());
|
|
|
+ if (lampPoleDao.getCountByVO(lampPoleVO1).intValue() > 0) return toolUtils.response(InterfaceResultEnum.LAMP_POLE_NUMBER_UNIQUE_ERROR,lampPoleVO.getVersion());
|
|
|
+ lampPoleDTO.setName(lampPoleVO.getName());
|
|
|
+ lampPoleDTO.setNumber(lampPoleVO.getNumber());
|
|
|
+ lampPoleDTO.setAreaId(lampPoleVO.getAreaId());
|
|
|
+ lampPoleDTO.setSectionId(lampPoleVO.getSectionId());
|
|
|
+ lampPoleDTO.setHeight(lampPoleVO.getHeight() == null ? 0 : lampPoleVO.getHeight());
|
|
|
+ lampPoleDTO.setLatitude(lampPoleVO.getLatitude());
|
|
|
+ lampPoleDTO.setLongitude(lampPoleVO.getLongitude());
|
|
|
+ lampPoleDTO.setInstallDate(lampPoleVO.getInstallDate());
|
|
|
+ lampPoleDTO.setExpirationDate(lampPoleVO.getExpirationDate());
|
|
|
+ lampPoleDao.update(lampPoleDTO);
|
|
|
+
|
|
|
+ Map cloudBox = lampPoleVO.getCloudBox();
|
|
|
+ WifiDTO wifiDTO = new WifiDTO();
|
|
|
+ wifiDTO.setLampPoleId(lampPoleDTO.getId());
|
|
|
+ wifiDTO.setVersion2(lampPoleVO.getVersion());
|
|
|
+ if (cloudBox.containsKey("sn")) wifiDTO.setSn((String) cloudBox.get("sn"));
|
|
|
+ if (cloudBox.containsKey("ipAddr")) wifiDTO.setIpAddr((String) cloudBox.get("ipAddr"));
|
|
|
+ if (cloudBox.containsKey("model")) wifiDTO.setModel((String) cloudBox.get("model"));
|
|
|
+ if (cloudBox.containsKey("remark1")) wifiDTO.setRemark1((String) cloudBox.get("remark1"));
|
|
|
+ if (cloudBox.containsKey("remark2")) wifiDTO.setRemark2((String) cloudBox.get("remark2"));
|
|
|
+ if (cloudBox.containsKey("remark3")) wifiDTO.setRemark3((String) cloudBox.get("remark3"));
|
|
|
+ if (cloudBox.containsKey("remark4")) wifiDTO.setRemark4((String) cloudBox.get("remark4"));
|
|
|
+ if (cloudBox.containsKey("remark5")) wifiDTO.setRemark5((String) cloudBox.get("remark5"));
|
|
|
+ if (cloudBox.containsKey("remark6")) wifiDTO.setRemark6((String) cloudBox.get("remark6"));
|
|
|
+ if (cloudBox.containsKey("installDate")) wifiDTO.setInstallDate((String) cloudBox.get("installDate"));
|
|
|
+ if (cloudBox.containsKey("expirationDate")) wifiDTO.setExpirationDate((String) cloudBox.get("expirationDate"));
|
|
|
+ BaseResult add1 = wifiService.update(wifiDTO);
|
|
|
+ if (!add1.getCode().equals("0000")) return add1;
|
|
|
+
|
|
|
+ // 添加灯控
|
|
|
+ Date endDate = new Date(System.currentTimeMillis());
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ String createTime = simpleDateFormat.format(endDate).toString();
|
|
|
+ List<Map> lightDevList = lampPoleVO.getLightDevList();
|
|
|
+ LampInfoDTO lampInfoDTO;
|
|
|
+ for (Map m :lightDevList) {
|
|
|
+ lampInfoDTO = new LampInfoDTO();
|
|
|
+ if (m.containsKey("address")) lampInfoDTO.setSn(m.get("address").toString());
|
|
|
+ if (m.containsKey("number")) lampInfoDTO.setNumber(m.get("number").toString());
|
|
|
+ if (m.containsKey("name")) lampInfoDTO.setName(m.get("name").toString());
|
|
|
+ if (m.containsKey("protocolType")) lampInfoDTO.setProtocolType(Integer.parseInt((String) m.get("protocolType")));
|
|
|
+ if (m.containsKey("controlType")) lampInfoDTO.setControlType(Integer.parseInt((String) m.get("controlType")));
|
|
|
+ if (m.containsKey("ratedPower")) {
|
|
|
+ if ( m.get("ratedPower") == null || m.get("ratedPower").toString().length() == 0){
|
|
|
+ lampInfoDTO.setRatedPower(0);
|
|
|
+ }else {
|
|
|
+ lampInfoDTO.setRatedPower(Integer.parseInt((String) m.get("ratedPower")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (m.containsKey("installDate")) lampInfoDTO.setInstallDate( m.get("installDate").toString());
|
|
|
+ if (m.containsKey("expirationDate")) lampInfoDTO.setExpirationDate( m.get("expirationDate").toString());
|
|
|
+ if (m.containsKey("id") && m.get("id") != null && m.get("id").toString().length() != 0) lampInfoDTO.setId(Integer.parseInt((String) m.get("id")));
|
|
|
+ lampInfoDTO.setVersion(lampPoleVO.getVersion());
|
|
|
+ lampInfoDTO.setAreaId(lampPoleVO.getAreaId());
|
|
|
+ lampInfoDTO.setSectionId(lampPoleVO.getSectionId());
|
|
|
+ lampInfoDTO.setLatitude(lampPoleVO.getLatitude());
|
|
|
+ lampInfoDTO.setLongitude(lampPoleVO.getLongitude());
|
|
|
+ lampInfoDTO.setLampPoleId(lampPoleVO.getId());
|
|
|
+ BaseResult add;
|
|
|
+ if (lampInfoDTO.getId() != null && lampInfoDTO.getId() != 0){
|
|
|
+ add = lampService.update(lampInfoDTO);
|
|
|
+ }else {
|
|
|
+ lampInfoDTO.setCreateTime(createTime);
|
|
|
+ add = lampService.add(lampInfoDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!add.getCode().equals("0000")) return add;
|
|
|
+ }
|
|
|
return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,lampPoleVO.getVersion());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Integer update(LampPoleDTO lampPoleDTO) {
|
|
|
- return lampPoleDao.update(lampPoleDTO);
|
|
|
+ public LampPoleDTO getDetailById(Integer id) {
|
|
|
+ return lampPoleDao.getDetailById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Integer deleteById(Integer id) {
|
|
|
+ if (id == null) return null;
|
|
|
+
|
|
|
+ // 删除灯控
|
|
|
+ LampListResponseVO lampListResponseVO = new LampListResponseVO();
|
|
|
+ lampListResponseVO.setLampPoleId(id);
|
|
|
+ List<LampInfoDTO> listByVO = lampService.getListByVO(lampListResponseVO);
|
|
|
+ for (LampInfoDTO l :listByVO) {
|
|
|
+ if (l.getId() != null) lampService.deleteById(l.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除云盒
|
|
|
+ WifiDTO wifiDTO = new WifiDTO();
|
|
|
+ wifiDTO.setLampPoleId(id);
|
|
|
+ List<WifiDTO> wifiList = wifiService.getWifiListByDTO(wifiDTO);
|
|
|
+ for (WifiDTO w :wifiList) {
|
|
|
+ if (w.getId() != null) wifiService.deleteById(w.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ return lampPoleDao.deleteById(id);
|
|
|
}
|
|
|
}
|