LampPoleServiceImpl.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. package com.welampiot.service.impl;
  2. import com.welampiot.dto.*;
  3. import com.welampiot.service.*;
  4. import com.welampiot.utils.VideoUtil;
  5. import com.welampiot.common.BaseResult;
  6. import com.welampiot.common.InterfaceResultEnum;
  7. import com.welampiot.dao.LampPoleDao;
  8. import com.welampiot.dto.LampInfoDTO;
  9. import com.welampiot.dto.LampPoleAlarmLogDTO;
  10. import com.welampiot.dto.LampPoleDTO;
  11. import com.welampiot.dto.WifiDTO;
  12. import com.welampiot.service.LampPoleAlarmLogService;
  13. import com.welampiot.service.LampPoleService;
  14. import com.welampiot.service.LampService;
  15. import com.welampiot.service.WifiService;
  16. import com.welampiot.utils.ToolUtils;
  17. import com.welampiot.vo.*;
  18. import org.apache.commons.lang3.StringUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.stereotype.Service;
  21. import java.text.ParseException;
  22. import java.text.SimpleDateFormat;
  23. import java.util.*;
  24. @Service
  25. public class LampPoleServiceImpl implements LampPoleService {
  26. @Autowired
  27. private LampPoleDao lampPoleDao;
  28. @Override
  29. public Integer getCountByVO(LampPoleCountVO lampPoleCountVO) {return lampPoleDao.getCountByVO(lampPoleCountVO);}
  30. @Override
  31. public List<LampPoleDTO> getNavByVO(LampPoleVO lampPoleVO) {
  32. return lampPoleDao.getNavByVO(lampPoleVO);
  33. }
  34. @Override
  35. public List<LampPoleDTO> getListByVO(LampPoleVO lampPoleVO) {
  36. return lampPoleDao.getListByVO(lampPoleVO);
  37. }
  38. @Autowired
  39. private LampPoleAlarmLogService lampPoleAlarmLogService;
  40. @Autowired
  41. private ToolUtils toolUtils;
  42. @Autowired
  43. private LampService lampService;
  44. @Autowired
  45. private WifiService wifiService;
  46. @Autowired
  47. private VideoMonitorService videoMonitorService;
  48. @Autowired
  49. private VideoGbInfoService videoGbInfoService;
  50. @Override
  51. public List<LampPoleDTO> lampPoleList(LampPoleVO lampPoleVO) {
  52. List<LampPoleDTO> lampPoleDTOS = lampPoleDao.lampPoleList(lampPoleVO);
  53. ArrayList<LampPoleDTO> lampPoleDTOS1 = new ArrayList<>();
  54. ArrayList<Integer> lampPoleIds = new ArrayList<>();
  55. lampPoleIds.add(0);
  56. for (LampPoleDTO l :lampPoleDTOS){
  57. lampPoleIds.add(l.getId());
  58. }
  59. List<LampPoleAlarmLogDTO> listByLampPoleIdList = lampPoleAlarmLogService.getListByLampPoleIdList(lampPoleIds);
  60. HashMap<Integer, LampPoleAlarmLogDTO> integerLampPoleAlarmLogDTOHashMap = new HashMap<>();
  61. for (LampPoleAlarmLogDTO l :listByLampPoleIdList) {
  62. integerLampPoleAlarmLogDTOHashMap.put(l.getId(),l);
  63. }
  64. HashMap<Integer, String> integerStringHashMap = new HashMap<>();
  65. integerStringHashMap.put(1,"摄像头");
  66. integerStringHashMap.put(2,"WIFI");
  67. integerStringHashMap.put(3,"RFID");
  68. integerStringHashMap.put(4,"LED屏");
  69. integerStringHashMap.put(5,"一键报警");
  70. integerStringHashMap.put(6,"充电桩");
  71. integerStringHashMap.put(7,"气象站");
  72. integerStringHashMap.put(8,"微基站");
  73. integerStringHashMap.put(9,"音柱");
  74. integerStringHashMap.put(10,"云盒");
  75. for (LampPoleDTO l :lampPoleDTOS) {
  76. if (l.getIsInspec() == null) l.setIsInspec(0);
  77. if (l.getCity() != null){
  78. l.setLocation(l.getCity()+" "+l.getArea()+" "+l.getSection());
  79. }else {
  80. l.setLocation(l.getArea()+" "+l.getSection());
  81. }
  82. if (l.getPolicyName() == null) {
  83. if (lampPoleVO.getVersion() == 0){
  84. l.setPolicyName("暂无");
  85. } else if (lampPoleVO.getVersion() == 1) {
  86. l.setPolicyName("none");
  87. }
  88. }
  89. if (integerLampPoleAlarmLogDTOHashMap.containsKey(l.getId())){
  90. LampPoleAlarmLogDTO lampPoleAlarmLogDTO = integerLampPoleAlarmLogDTOHashMap.get(l.getId());
  91. if (integerStringHashMap.containsKey(lampPoleAlarmLogDTO.getDevType())){
  92. String s = integerStringHashMap.get(lampPoleAlarmLogDTO.getDevType());
  93. l.setFaultStatus(0);
  94. l.setAlarmInfo(s+"离线");
  95. }else {
  96. l.setFaultStatus(0);
  97. l.setAlarmInfo("");
  98. }
  99. }else {
  100. l.setFaultStatus(0);
  101. }
  102. lampPoleDTOS1.add(l);
  103. }
  104. return lampPoleDTOS1;
  105. }
  106. @Override
  107. public Integer lampPoleCount(LampPoleVO lampPoleVO) {
  108. return lampPoleDao.lampPoleCount(lampPoleVO);
  109. }
  110. @Override
  111. public BaseResult add(LampPoleVO lampPoleVO) {
  112. LampPoleDTO lampPoleDTO = new LampPoleDTO();
  113. lampPoleDTO.setCreateId(lampPoleVO.getCreateId());
  114. if (lampPoleVO.getAreaId() == null || lampPoleVO.getAreaId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,lampPoleVO.getVersion());
  115. if (lampPoleVO.getSectionId() == null || lampPoleVO.getSectionId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,lampPoleVO.getVersion());
  116. if (lampPoleVO.getName() == null || lampPoleVO.getName().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_NAME_ERROR,lampPoleVO.getVersion());
  117. if (lampPoleVO.getNumber() == null || lampPoleVO.getNumber().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_POLE_NUMBER_ERROR,lampPoleVO.getVersion());
  118. if (!lampPoleVO.getNumber().matches("^[A-Za-z0-9_]+$")) return toolUtils.response(InterfaceResultEnum.LAMP_POLE_NUMBER_FORMAT_ERROR,lampPoleVO.getVersion());
  119. LampPoleCountVO lampPoleVO1 = new LampPoleCountVO();
  120. lampPoleVO1.setSectionId(lampPoleVO.getSectionId());
  121. lampPoleVO1.setName(lampPoleVO.getName());
  122. if (lampPoleDao.getCountByVO(lampPoleVO1).intValue() > 0) return toolUtils.response(InterfaceResultEnum.LAMP_POLE_NAME_UNIQUE_ERROR,lampPoleVO.getVersion());
  123. lampPoleVO1 = new LampPoleCountVO();
  124. lampPoleVO1.setSectionId(lampPoleVO.getSectionId());
  125. lampPoleVO1.setNumber(lampPoleVO.getNumber());
  126. if (lampPoleDao.getCountByVO(lampPoleVO1).intValue() > 0) return toolUtils.response(InterfaceResultEnum.LAMP_POLE_NUMBER_UNIQUE_ERROR,lampPoleVO.getVersion());
  127. lampPoleDTO.setName(lampPoleVO.getName());
  128. lampPoleDTO.setNumber(lampPoleVO.getNumber());
  129. lampPoleDTO.setAreaId(lampPoleVO.getAreaId());
  130. lampPoleDTO.setSectionId(lampPoleVO.getSectionId());
  131. lampPoleDTO.setHeight(lampPoleVO.getHeight() == null ? 0 : lampPoleVO.getHeight());
  132. lampPoleDTO.setLatitude(lampPoleVO.getLatitude().toString());
  133. lampPoleDTO.setLongitude(lampPoleVO.getLongitude().toString());
  134. lampPoleDTO.setInstallDate(lampPoleVO.getInstallDate());
  135. lampPoleDTO.setExpirationDate(lampPoleVO.getExpirationDate());
  136. Date endDate = new Date(System.currentTimeMillis());
  137. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  138. String createTime = simpleDateFormat.format(endDate).toString();
  139. lampPoleDTO.setCreateTime(createTime);
  140. lampPoleDao.add(lampPoleDTO);
  141. List<Integer> devType = new ArrayList<>();
  142. Integer id = lampPoleDTO.getId();
  143. // 添加云盒
  144. Map cloudBox = lampPoleVO.getCloudBox();
  145. WifiDTO wifiDTO = new WifiDTO();
  146. wifiDTO.setLampPoleId(id);
  147. wifiDTO.setVersion2(lampPoleVO.getVersion());
  148. if (cloudBox.containsKey("sn")) wifiDTO.setSn((String) cloudBox.get("sn"));
  149. if (cloudBox.containsKey("ipAddr")) wifiDTO.setIpAddr((String) cloudBox.get("ipAddr"));
  150. if (cloudBox.containsKey("model")) wifiDTO.setModel((Integer) cloudBox.get("model"));
  151. if (cloudBox.containsKey("remark1")) wifiDTO.setRemark1((String) cloudBox.get("remark1"));
  152. if (cloudBox.containsKey("remark2")) wifiDTO.setRemark2((String) cloudBox.get("remark2"));
  153. if (cloudBox.containsKey("remark3")) wifiDTO.setRemark3((String) cloudBox.get("remark3"));
  154. if (cloudBox.containsKey("remark4")) wifiDTO.setRemark4((String) cloudBox.get("remark4"));
  155. if (cloudBox.containsKey("remark5")) wifiDTO.setRemark5((String) cloudBox.get("remark5"));
  156. if (cloudBox.containsKey("remark6")) wifiDTO.setRemark6((String) cloudBox.get("remark6"));
  157. if (cloudBox.containsKey("installDate")) wifiDTO.setInstallDate((String) cloudBox.get("installDate"));
  158. if (cloudBox.containsKey("expirationDate")) wifiDTO.setExpirationDate((String) cloudBox.get("expirationDate"));
  159. BaseResult add1 = wifiService.add(wifiDTO);
  160. if (!add1.getCode().equals("0000")) return add1;
  161. devType.add(10);
  162. devType.add(2);
  163. // 添加灯控
  164. List<Map> lightDevList = lampPoleVO.getLightDevList();
  165. LampInfoDTO lampInfoDTO;
  166. for (Map m :lightDevList) {
  167. lampInfoDTO = new LampInfoDTO();
  168. if (m.containsKey("address")) lampInfoDTO.setSn(m.get("address").toString());
  169. if (m.containsKey("number")) lampInfoDTO.setNumber(m.get("number").toString());
  170. if (m.containsKey("name")) lampInfoDTO.setName(m.get("name").toString());
  171. if (m.containsKey("protocolType")) lampInfoDTO.setProtocolType(Integer.parseInt((String) m.get("protocolType")));
  172. if (m.containsKey("controlType")) lampInfoDTO.setControlType(Integer.parseInt((String) m.get("controlType")));
  173. if (m.containsKey("ratedPower")) {
  174. if ( m.get("ratedPower") == null || m.get("ratedPower").toString().length() == 0){
  175. lampInfoDTO.setRatedPower(0);
  176. }else {
  177. lampInfoDTO.setRatedPower(Integer.parseInt((String) m.get("ratedPower")));
  178. }
  179. }
  180. if (m.containsKey("installDate")) lampInfoDTO.setInstallDate( m.get("installDate").toString());
  181. if (m.containsKey("expirationDate")) lampInfoDTO.setExpirationDate( m.get("expirationDate").toString());
  182. lampInfoDTO.setCreateTime(createTime);
  183. lampInfoDTO.setVersion(lampPoleVO.getVersion());
  184. lampInfoDTO.setAreaId(lampPoleVO.getAreaId());
  185. lampInfoDTO.setSectionId(lampPoleVO.getSectionId());
  186. lampInfoDTO.setLatitude(lampPoleVO.getLatitude());
  187. lampInfoDTO.setLongitude(lampPoleVO.getLongitude());
  188. lampInfoDTO.setLampPoleId(id);
  189. BaseResult add = lampService.add(lampInfoDTO);
  190. if (!add.getCode().equals("0000")) return add;
  191. }
  192. devType.add(0);
  193. // 添加摄像头
  194. // 设备类型(0 路灯,2 WIFI,3 RFID,4 LED屏,5 一键报警,6 充电桩,7 气象站,8 微基站,9 广播音柱,10 云盒,11 电缆,12 太阳能板凳,13 超级电源,14 水浸传感器,15 智能门锁,16 储能逆变,17 噪声监控,18 倾斜监测,19 液位传感器,20 灯带)多种类型用逗号隔开
  195. List<Map> videoList = lampPoleVO.getVideoList();
  196. if (videoList != null && !videoList.isEmpty()){
  197. for (Map m :videoList) {
  198. VideoMonitorDTO videoMonitorDTO = new VideoMonitorDTO();
  199. if (m.containsKey("id")) videoMonitorDTO.setId((Integer) m.get("id"));
  200. if (m.containsKey("name")) {
  201. videoMonitorDTO.setName((String) m.get("name"));
  202. }else {
  203. }
  204. if (m.containsKey("devId")) videoMonitorDTO.setDevId((String) m.get("devId"));
  205. if (m.containsKey("password")) videoMonitorDTO.setPassword((String) m.get("password"));
  206. if (m.containsKey("channel")) videoMonitorDTO.setChannel((String) m.get("channel"));
  207. if (m.containsKey("faceImage")) videoMonitorDTO.setFaceImage((String) m.get("faceImage"));
  208. if (m.containsKey("deviceType")) videoMonitorDTO.setDeviceType((Integer) m.get("deviceType"));
  209. if (m.containsKey("netType")) videoMonitorDTO.setNetType((Integer) m.get("netType"));
  210. if (m.containsKey("ipAddr")) videoMonitorDTO.setIpAddr((String) m.get("ipAddr"));
  211. if (m.containsKey("devPwd")) videoMonitorDTO.setDevPwd((String) m.get("devPwd"));
  212. if (m.containsKey("installDate")) videoMonitorDTO.setInstallDate((String) m.get("installDate"));
  213. if (m.containsKey("expirationDate")) videoMonitorDTO.setExpirationDate((String) m.get("expirationDate"));
  214. if (m.containsKey("type")) videoMonitorDTO.setType((Integer) m.get("type"));
  215. String gbAddressByDevId = VideoUtil.getGbAddressByDevId(videoMonitorDTO.getDevId(), videoGbInfoService);
  216. videoMonitorDTO.setGbAddress(gbAddressByDevId);
  217. if (m.containsKey("id")){
  218. videoMonitorService.updateVideoMonitorData(videoMonitorDTO);
  219. }else {
  220. videoMonitorService.addVideoMonitorData(videoMonitorDTO);
  221. }
  222. }
  223. devType.add(1);
  224. }
  225. // 添加气象站
  226. if (lampPoleVO.getWeatherDev() != null){
  227. Map weatherDev = lampPoleVO.getWeatherDev();
  228. EnvmonitorDTO envmonitorDTO = new EnvmonitorDTO();
  229. if (weatherDev.containsKey("model")) envmonitorDTO.setModel(String.valueOf(weatherDev.get("model")));
  230. if (weatherDev.containsKey("address")) envmonitorDTO.setAddress(String.valueOf(weatherDev.get("address")));
  231. if (weatherDev.containsKey("devType")) envmonitorDTO.setDevType((Integer) weatherDev.get("devType"));
  232. if (weatherDev.containsKey("pramType")) envmonitorDTO.setPramType((Integer) weatherDev.get("pramType"));
  233. if (weatherDev.containsKey("rate")) envmonitorDTO.setRate((Integer) weatherDev.get("rate"));
  234. if (weatherDev.containsKey("netType")) envmonitorDTO.setNetType((Integer) weatherDev.get("netType"));
  235. if (weatherDev.containsKey("serialPort")) envmonitorDTO.setSerialPort((Integer) weatherDev.get("serialPort"));
  236. if (weatherDev.containsKey("mp")) envmonitorDTO.setMp((Integer) weatherDev.get("mp"));
  237. if (weatherDev.containsKey("devList")){
  238. Object devList = weatherDev.get("devList");
  239. System.out.println(devList);
  240. }
  241. }
  242. LampPoleDTO lampPoleDTO1 = new LampPoleDTO();
  243. lampPoleDTO1.setId(lampPoleDTO.getId());
  244. lampPoleDTO1.setDevType(StringUtils.join(devType,","));
  245. lampPoleDTO1.setSn(wifiDTO.getSn());
  246. lampPoleDao.update(lampPoleDTO1);
  247. // return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,lampPoleVO.getVersion());
  248. return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,lampPoleVO.getVersion());
  249. }
  250. @Override
  251. public BaseResult update(LampPoleVO lampPoleVO) {
  252. LampPoleDTO lampPoleDTO = new LampPoleDTO();
  253. lampPoleDTO.setId(lampPoleVO.getId());
  254. if (lampPoleVO.getAreaId() == null || lampPoleVO.getAreaId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,lampPoleVO.getVersion());
  255. if (lampPoleVO.getSectionId() == null || lampPoleVO.getSectionId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,lampPoleVO.getVersion());
  256. if (lampPoleVO.getName() == null || lampPoleVO.getName().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_NAME_ERROR,lampPoleVO.getVersion());
  257. if (lampPoleVO.getNumber() == null || lampPoleVO.getNumber().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_POLE_NUMBER_ERROR,lampPoleVO.getVersion());
  258. if (!lampPoleVO.getNumber().matches("^[A-Za-z0-9_]+$")) return toolUtils.response(InterfaceResultEnum.LAMP_POLE_NUMBER_FORMAT_ERROR,lampPoleVO.getVersion());
  259. LampPoleCountVO lampPoleVO1 = new LampPoleCountVO();
  260. lampPoleVO1.setId(lampPoleDTO.getId());
  261. lampPoleVO1.setSectionId(lampPoleVO.getSectionId());
  262. lampPoleVO1.setName(lampPoleVO.getName());
  263. if (lampPoleDao.getCountByVO(lampPoleVO1).intValue() > 0) return toolUtils.response(InterfaceResultEnum.LAMP_POLE_NAME_UNIQUE_ERROR,lampPoleVO.getVersion());
  264. lampPoleVO1 = new LampPoleCountVO();
  265. lampPoleVO1.setId(lampPoleDTO.getId());
  266. lampPoleVO1.setSectionId(lampPoleVO.getSectionId());
  267. lampPoleVO1.setNumber(lampPoleVO.getNumber());
  268. if (lampPoleDao.getCountByVO(lampPoleVO1).intValue() > 0) return toolUtils.response(InterfaceResultEnum.LAMP_POLE_NUMBER_UNIQUE_ERROR,lampPoleVO.getVersion());
  269. lampPoleDTO.setName(lampPoleVO.getName());
  270. lampPoleDTO.setNumber(lampPoleVO.getNumber());
  271. lampPoleDTO.setAreaId(lampPoleVO.getAreaId());
  272. lampPoleDTO.setSectionId(lampPoleVO.getSectionId());
  273. lampPoleDTO.setHeight(lampPoleVO.getHeight() == null ? 0 : lampPoleVO.getHeight());
  274. lampPoleDTO.setLatitude(lampPoleVO.getLatitude().toString());
  275. lampPoleDTO.setLongitude(lampPoleVO.getLongitude().toString());
  276. lampPoleDTO.setInstallDate(lampPoleVO.getInstallDate());
  277. lampPoleDTO.setExpirationDate(lampPoleVO.getExpirationDate());
  278. lampPoleDao.update(lampPoleDTO);
  279. Map cloudBox = lampPoleVO.getCloudBox();
  280. WifiDTO wifiDTO = new WifiDTO();
  281. wifiDTO.setLampPoleId(lampPoleDTO.getId());
  282. wifiDTO.setVersion2(lampPoleVO.getVersion());
  283. if (cloudBox.containsKey("sn")) wifiDTO.setSn((String) cloudBox.get("sn"));
  284. if (cloudBox.containsKey("ipAddr")) wifiDTO.setIpAddr((String) cloudBox.get("ipAddr"));
  285. if (cloudBox.containsKey("model")) wifiDTO.setModel((Integer) cloudBox.get("model"));
  286. if (cloudBox.containsKey("remark1")) wifiDTO.setRemark1((String) cloudBox.get("remark1"));
  287. if (cloudBox.containsKey("remark2")) wifiDTO.setRemark2((String) cloudBox.get("remark2"));
  288. if (cloudBox.containsKey("remark3")) wifiDTO.setRemark3((String) cloudBox.get("remark3"));
  289. if (cloudBox.containsKey("remark4")) wifiDTO.setRemark4((String) cloudBox.get("remark4"));
  290. if (cloudBox.containsKey("remark5")) wifiDTO.setRemark5((String) cloudBox.get("remark5"));
  291. if (cloudBox.containsKey("remark6")) wifiDTO.setRemark6((String) cloudBox.get("remark6"));
  292. if (cloudBox.containsKey("installDate")) wifiDTO.setInstallDate((String) cloudBox.get("installDate"));
  293. if (cloudBox.containsKey("expirationDate")) wifiDTO.setExpirationDate((String) cloudBox.get("expirationDate"));
  294. BaseResult add1 = wifiService.update(wifiDTO);
  295. if (!add1.getCode().equals("0000")) return add1;
  296. // 添加灯控
  297. Date endDate = new Date(System.currentTimeMillis());
  298. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  299. String createTime = simpleDateFormat.format(endDate).toString();
  300. List<Map> lightDevList = lampPoleVO.getLightDevList();
  301. LampInfoDTO lampInfoDTO;
  302. for (Map m :lightDevList) {
  303. lampInfoDTO = new LampInfoDTO();
  304. if (m.containsKey("address")) lampInfoDTO.setSn(m.get("address").toString());
  305. if (m.containsKey("number")) lampInfoDTO.setNumber(m.get("number").toString());
  306. if (m.containsKey("name")) lampInfoDTO.setName(m.get("name").toString());
  307. if (m.containsKey("protocolType")) lampInfoDTO.setProtocolType(Integer.parseInt((String) m.get("protocolType")));
  308. if (m.containsKey("controlType")) lampInfoDTO.setControlType(Integer.parseInt((String) m.get("controlType")));
  309. if (m.containsKey("ratedPower")) {
  310. if ( m.get("ratedPower") == null || m.get("ratedPower").toString().length() == 0){
  311. lampInfoDTO.setRatedPower(0);
  312. }else {
  313. lampInfoDTO.setRatedPower(Integer.parseInt((String) m.get("ratedPower")));
  314. }
  315. }
  316. if (m.containsKey("installDate")) lampInfoDTO.setInstallDate( m.get("installDate").toString());
  317. if (m.containsKey("expirationDate")) lampInfoDTO.setExpirationDate( m.get("expirationDate").toString());
  318. if (m.containsKey("id") && m.get("id") != null && m.get("id").toString().length() != 0) lampInfoDTO.setId(Integer.parseInt((String) m.get("id")));
  319. lampInfoDTO.setVersion(lampPoleVO.getVersion());
  320. lampInfoDTO.setAreaId(lampPoleVO.getAreaId());
  321. lampInfoDTO.setSectionId(lampPoleVO.getSectionId());
  322. lampInfoDTO.setLatitude(lampPoleVO.getLatitude());
  323. lampInfoDTO.setLongitude(lampPoleVO.getLongitude());
  324. lampInfoDTO.setLampPoleId(lampPoleVO.getId());
  325. BaseResult add;
  326. if (lampInfoDTO.getId() != null && lampInfoDTO.getId() != 0){
  327. add = lampService.update(lampInfoDTO);
  328. }else {
  329. lampInfoDTO.setCreateTime(createTime);
  330. add = lampService.add(lampInfoDTO);
  331. }
  332. if (!add.getCode().equals("0000")) return add;
  333. }
  334. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,lampPoleVO.getVersion());
  335. }
  336. @Override
  337. public LampPoleDTO getDetailById(Integer id) {
  338. return lampPoleDao.getDetailById(id);
  339. }
  340. @Override
  341. public Integer deleteById(Integer id) {
  342. if (id == null) return null;
  343. // 删除灯控
  344. LampListResponseVO lampListResponseVO = new LampListResponseVO();
  345. lampListResponseVO.setLampPoleId(id);
  346. List<LampInfoDTO> listByVO = lampService.getListByVO(lampListResponseVO);
  347. for (LampInfoDTO l :listByVO) {
  348. if (l.getId() != null) lampService.deleteById(l.getId());
  349. }
  350. // 删除云盒
  351. WifiDTO wifiDTO = new WifiDTO();
  352. wifiDTO.setLampPoleId(id);
  353. List<WifiDTO> wifiList = wifiService.getWifiListByDTO(wifiDTO);
  354. for (WifiDTO w :wifiList) {
  355. if (w.getId() != null) wifiService.deleteById(w.getId());
  356. }
  357. return lampPoleDao.deleteById(id);
  358. }
  359. @Override
  360. public LampPoleVO getLampPoleListByDTO(LampPoleDTO dto) {
  361. LampPoleVO lampPoleVO = new LampPoleVO();
  362. List<LampPoleDTO> lampPoleList = lampPoleDao.getLampPoleListByDTO(dto);
  363. List<LampPoleDTO> list = new ArrayList<>();
  364. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  365. lampPoleList.forEach(lampDTO -> {
  366. //设备状态(0 = 设备正常, 1 = 供电异常,2 = 灯闪,4 =灯坏, 8 = LED驱动故障, 16 = 数据同步失败)
  367. if (lampDTO.getFaultStatus() != null && lampDTO.getFaultStatus() == 16) {
  368. lampDTO.setAlarmStatusStr("数据同步失败");
  369. } else if (lampDTO.getFaultStatus() != null && lampDTO.getFaultStatus() == 8) {
  370. lampDTO.setAlarmStatusStr("LED驱动故障");
  371. } else if (lampDTO.getFaultStatus() != null && lampDTO.getFaultStatus() == 4) {
  372. lampDTO.setAlarmStatusStr("灯坏");
  373. } else if (lampDTO.getFaultStatus() != null && lampDTO.getFaultStatus() == 2) {
  374. lampDTO.setAlarmStatusStr("灯闪");
  375. } else if (lampDTO.getFaultStatus() != null && lampDTO.getFaultStatus() == 1) {
  376. lampDTO.setAlarmStatusStr("供电异常");
  377. } else {
  378. lampDTO.setAlarmStatusStr("设备正常");
  379. }
  380. if (lampDTO.getArea() == null) {
  381. lampDTO.setArea("");
  382. }
  383. if (lampDTO.getSection() == null) {
  384. lampDTO.setSection("");
  385. }
  386. if (lampDTO.getUpdateTime() != null && !lampDTO.getUpdateTime().equals("")) {
  387. Date cmdTime;
  388. try {
  389. cmdTime = simpleDateFormat.parse(lampDTO.getUpdateTime());
  390. } catch (ParseException e) {
  391. throw new RuntimeException(e);
  392. }
  393. //判断时区,为null默认东八区
  394. long timezone = lampDTO.getTimezone() == null ? 8 : lampDTO.getTimezone();
  395. long l = cmdTime.getTime() + timezone * 3600 * 1000;
  396. cmdTime = new Date(l);
  397. lampDTO.setUpdateTime(simpleDateFormat.format(cmdTime));
  398. } else {
  399. lampDTO.setUpdateTime("");
  400. }
  401. if (lampDTO.getVideoId() == null) {
  402. lampDTO.setVideoId(0);
  403. }
  404. list.add(lampDTO);
  405. });
  406. lampPoleVO.setList(list);
  407. return lampPoleVO;
  408. }
  409. @Override
  410. public LampPoleInfoVO getLampPoleCount(LampPoleDTO lampPoleDTO, LampInfoDTO lampInfoDTO) {
  411. LampPoleInfoVO countVO = new LampPoleInfoVO();
  412. countVO.setInstallCount(lampPoleDao.getLampPoleInstallTotalByDTO(lampPoleDTO));
  413. countVO.setOnlineCount(lampService.getLampOnlineTotalByDTO(lampInfoDTO));
  414. countVO.setFaultCount(lampService.getLampFaultTotalByDTO(lampInfoDTO));
  415. countVO.setLightingCount(lampService.getLampLightTotalByDTO(lampInfoDTO));
  416. countVO.setChargeCount(lampPoleDao.getChargeCount(lampPoleDTO));
  417. countVO.setVideoCount(lampPoleDao.getVideoCount(lampPoleDTO));
  418. countVO.setScreenCount(lampPoleDao.getScreenCount(lampPoleDTO));
  419. countVO.setWifiCount(lampPoleDao.getWifiCount(lampPoleDTO));
  420. countVO.setWeatherCount(lampPoleDao.getWeatherCount(lampPoleDTO));
  421. countVO.setEmCount(lampPoleDao.getEmergencyCount(lampPoleDTO));
  422. countVO.setRfidCount(lampPoleDao.getRfidCount(lampPoleDTO));
  423. countVO.setRadioCount(lampPoleDao.getBroadcastCount(lampPoleDTO));
  424. return countVO;
  425. }
  426. @Override
  427. public Integer getSectionIdByLampPoleId(Integer id) {
  428. return lampPoleDao.getSectionIdByLampPoleId(id);
  429. }
  430. @Override
  431. public void changeLampPoleLocationById(LampPoleDTO dto) {
  432. lampPoleDao.changeLampPoleLocationById(dto);
  433. }
  434. @Override
  435. public LampPoleDTO getLampPoleDTOById(Integer id) {
  436. return lampPoleDao.getLampPoleDTOById(id);
  437. }
  438. @Override
  439. public Integer getLampPoleAlarmTotal(LampPoleVO vo) {
  440. return lampPoleDao.getLampPoleAlarmTotal(vo);
  441. }
  442. @Override
  443. public Integer getLampPoleAlarmStatusTotal(LampPoleVO vo) {
  444. return lampPoleDao.getLampPoleAlarmStatusTotal(vo);
  445. }
  446. @Override
  447. public Integer getLampPoleOfDevAlarmTotal(LampPoleVO vo) {
  448. return lampPoleDao.getLampPoleOfDevAlarmTotal(vo);
  449. }
  450. @Override
  451. public List<LampPoleDTO> getAlarmLampPoleList(LampPoleVO vo) {
  452. return lampPoleDao.getAlarmLampPoleList(vo);
  453. }
  454. @Override
  455. public Integer getLampPoleLightCount(LampPoleVO vo) {
  456. return lampPoleDao.getLampPoleLightCount(vo);
  457. }
  458. @Override
  459. public List<LampPoleDTO> getLampPoleLightList(LampPoleVO vo) {
  460. return lampPoleDao.getLampPoleLightList(vo);
  461. }
  462. @Override
  463. public Integer getNewCreateLampPoleCount(LampPoleVO vo) {
  464. return lampPoleDao.getNewCreateLampPoleCount(vo);
  465. }
  466. @Override
  467. public Integer getLampPoleInstallTotal(LampPoleVO vo) {
  468. return lampPoleDao.getLampPoleInstallTotal(vo);
  469. }
  470. @Override
  471. public List<LampPoleDTO> getLampPoleInstallList(LampPoleVO vo) {
  472. return lampPoleDao.getLampPoleInstallList(vo);
  473. }
  474. @Override
  475. public void updateLampPoleDevType(LampPoleDTO dto) {
  476. lampPoleDao.updateLampPoleDevType(dto);
  477. }
  478. @Override
  479. public List<LampPoleDTO> getSectionLampPoleList(LampPoleVO vo) {
  480. return lampPoleDao.getSectionLampPoleList(vo);
  481. }
  482. @Override
  483. public List<LampPoleDTO> getLampPoleByLampIds(List<String> lampIds) {
  484. return lampPoleDao.getLampPoleByLampIds(lampIds);
  485. }
  486. @Override
  487. public void updateLampPoleIcon(LampPoleDTO dto) {
  488. lampPoleDao.updateLampPoleIcon(dto);
  489. }
  490. @Override
  491. public List<LampPoleDTO> getNewLampPoleList2(LampPoleVO vo) {
  492. return lampPoleDao.getNewLampPoleList2(vo);
  493. }
  494. @Override
  495. public List<LampPoleDTO> getNewLampPoleList3(LampPoleVO vo) {
  496. return lampPoleDao.getNewLampPoleList3(vo);
  497. }
  498. @Override
  499. public LampPoleDTO getLampPoleDetails(LampPoleVO vo) {
  500. return lampPoleDao.getLampPoleDetails(vo);
  501. }
  502. @Override
  503. public LampInfoLogNewDTO getComBySectionList(LampPoleVO lampPoleVO) {
  504. return lampPoleDao.getComBySectionList(lampPoleVO);
  505. }
  506. @Override
  507. public List<LampPoleDTO> getLampPoleDevList(LampPoleVO vo) {
  508. return lampPoleDao.getLampPoleDevList(vo);
  509. }
  510. @Override
  511. public List<LampPoleDTO> getLampPoleAlarmInfoList(LampPoleVO vo) {
  512. return lampPoleDao.getLampPoleAlarmInfoList(vo);
  513. }
  514. @Override
  515. public LampPoleInfoVO getLampPoleDevCount(LampPoleDTO dto) {
  516. LampPoleInfoVO lampPoleInfoVO = new LampPoleInfoVO();
  517. lampPoleInfoVO.setWifiCount(lampPoleDao.getWifiCount(dto));
  518. lampPoleInfoVO.setBroadcastCount(lampPoleDao.getBroadcastCount(dto));
  519. lampPoleInfoVO.setLampCount(lampPoleDao.getLampInfoCount(dto));
  520. lampPoleInfoVO.setLoopCount(lampPoleDao.getLoopCount(dto));
  521. lampPoleInfoVO.setVideoCount(lampPoleDao.getVideoCount(dto));
  522. lampPoleInfoVO.setChargeCount(lampPoleDao.getChargeCount(dto));
  523. lampPoleInfoVO.setLedCount(lampPoleDao.getScreenCount(dto));
  524. lampPoleInfoVO.setWellCoverCount(lampPoleDao.getManholeCount(dto));
  525. lampPoleInfoVO.setWeatherCount(lampPoleDao.getWeatherCount(dto));
  526. lampPoleInfoVO.setTrashCount(lampPoleDao.getTrashCount(dto));
  527. lampPoleInfoVO.setOneKeyCount(lampPoleDao.getEmergencyCount(dto));
  528. lampPoleInfoVO.setLineCount(0);
  529. return lampPoleInfoVO;
  530. }
  531. @Override
  532. public List<LampPoleDTO> getLampPoleAlarmListByLampPoleId(Integer lampPoleId) {
  533. return lampPoleDao.getLampPoleAlarmListByLampPoleId(lampPoleId);
  534. }
  535. @Override
  536. public LampPoleDTO getNewLampPoleDetailsById(Integer id) {
  537. return lampPoleDao.getNewLampPoleDetailsById(id);
  538. }
  539. @Override
  540. public List<LampPoleDTO> getLampListByLampPoleId(Integer lampPoleId) {
  541. return lampPoleDao.getLampListByLampPoleId(lampPoleId);
  542. }
  543. @Override
  544. public LampPoleInfoVO getLampPoleBigScreenCount(LampPoleDTO lampPoleDTO, LampInfoDTO lampInfoDTO) {
  545. LampPoleInfoVO countVO = new LampPoleInfoVO();
  546. Integer total = lampPoleDao.getLampPoleInstallTotalByDTO(lampPoleDTO);
  547. countVO.setInstallCount(total);
  548. countVO.setLampPoleCount(total);
  549. countVO.setOnlineCount(lampService.getLampOnlineTotalByDTO(lampInfoDTO));
  550. countVO.setFaultCount(lampService.getLampFaultTotalByDTO(lampInfoDTO));
  551. countVO.setLightCount(lampService.getLampLightTotalByDTO(lampInfoDTO));
  552. countVO.setScreenCount(lampPoleDao.getScreenCount(lampPoleDTO));
  553. return countVO;
  554. }
  555. @Override
  556. public List<LampPoleDTO> getMapDataByVO(MapDataVO vo) {
  557. return lampPoleDao.getMapDataByVO(vo);
  558. }
  559. @Override
  560. public Integer getAlarmCountByVO(LampPoleCountVO lampPoleCountVO) {
  561. return lampPoleDao.getAlarmCountByVO(lampPoleCountVO);
  562. }
  563. @Override
  564. public void updateById(LampPoleDTO lampPoleDTO){
  565. lampPoleDao.updateById( lampPoleDTO);
  566. }
  567. @Override
  568. public List<LampPoleDTO>getPoleAlarmLogList(List<Integer> lampPoleIds){
  569. return lampPoleDao.getPoleAlarmLogList(lampPoleIds);
  570. }
  571. @Override
  572. public LampPoleDTO getLocalDataById(Integer id){
  573. return lampPoleDao.getLocalDataById(id);
  574. }
  575. @Override
  576. public List<LampPoleDTO> getRangeLampPole(HashMap<String,Double> hashMap){
  577. return lampPoleDao.getRangeLampPole(hashMap);
  578. }
  579. @Override
  580. public LampPoleDTO getSimpleOne(LampPoleDTO dto){
  581. return lampPoleDao.getSimpleOne(dto);
  582. }
  583. }