LampServiceImpl.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. package com.welampiot.service.impl;
  2. import com.welampiot.common.BaseResult;
  3. import com.welampiot.common.InterfaceResultEnum;
  4. import com.welampiot.dto.*;
  5. import com.welampiot.dao.LampDao;
  6. import com.welampiot.dto.LampInfoCacheByDayDTO;
  7. import com.welampiot.dto.LampInfoDTO;
  8. import com.welampiot.dto.LampInfoLogDTO;
  9. import com.welampiot.dto.NetworkDTO;
  10. import com.welampiot.service.LampInfoCacheByDayService;
  11. import com.welampiot.service.LampInfoLogService;
  12. import com.welampiot.service.LampService;
  13. import com.welampiot.service.NetworkService;
  14. import com.welampiot.utils.ToolUtils;
  15. import com.welampiot.vo.*;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Service;
  18. import java.text.DecimalFormat;
  19. import java.text.ParseException;
  20. import java.text.SimpleDateFormat;
  21. import java.util.*;
  22. @Service
  23. public class LampServiceImpl implements LampService {
  24. @Autowired
  25. private LampDao lampDao;
  26. @Autowired
  27. private ToolUtils toolUtils;
  28. @Autowired
  29. private LampInfoLogService lampInfoLogService;
  30. @Autowired
  31. private NetworkService networkService;
  32. @Autowired
  33. private LampInfoCacheByDayService lampInfoCacheByDayService;
  34. @Override
  35. public Integer getCountByVO(LampCountVO lampCountVO) {return lampDao.getCountByVO(lampCountVO);}
  36. @Override
  37. public Float getDayConsumptionByVO(LampCountVO lampCountVO) {
  38. Float dayConsumptionByVO = lampDao.getDayConsumptionByVO(lampCountVO);
  39. dayConsumptionByVO = dayConsumptionByVO == null ? 0 : dayConsumptionByVO;
  40. return dayConsumptionByVO;
  41. }
  42. @Override
  43. public Float getConsumptionByVO(LampCountVO lampCountVO) {
  44. Float consumptionByVO = lampDao.getConsumptionByVO(lampCountVO);
  45. consumptionByVO = consumptionByVO == null ? 0 : consumptionByVO;
  46. return consumptionByVO;
  47. }
  48. @Override
  49. public List<LampLogVO> getConsumptionListByVO(LampCountVO lampCountVO) {return lampDao.getConsumptionListByVO(lampCountVO);}
  50. @Override
  51. public List<LampInfoDTO> getListByVO(LampListResponseVO lampListResponseVO) {
  52. List<LampInfoDTO> listByVO = lampDao.getListByVO(lampListResponseVO);
  53. List<LampInfoDTO> list = new ArrayList<>();
  54. for (LampInfoDTO lamp :listByVO) {
  55. if (lamp.getCurrent() != null) {
  56. if (Math.abs(Float.parseFloat(lamp.getCurrent())) >= 0.01){
  57. lamp.setCurrent(String.valueOf((Math.round((Float.parseFloat(lamp.getCurrent()))*100)/100f)));
  58. }else {
  59. lamp.setCurrent("0");
  60. }
  61. }else {
  62. lamp.setCurrent("");
  63. }
  64. if (lamp.getVoltage() != null) {
  65. if (Math.abs(Float.parseFloat(lamp.getCurrent())) >= 0.01){
  66. lamp.setVoltage(String.valueOf((Math.round((Float.parseFloat(lamp.getVoltage()))*100)/100f)));
  67. }else {
  68. lamp.setCurrent("0");
  69. }
  70. }else {
  71. lamp.setVoltage("");
  72. }
  73. if (lamp.getPower() != null) {
  74. if (Math.abs(Float.parseFloat(lamp.getCurrent())) >= 0.01){
  75. lamp.setPower(String.valueOf((Math.round((Float.parseFloat(lamp.getPower()))*100)/100f)));
  76. }else {
  77. lamp.setCurrent("0");
  78. }
  79. }else {
  80. lamp.setPower("");
  81. }
  82. if (lamp.getLedLuxValue() == null){
  83. lamp.setLedLuxValue(0);
  84. }
  85. if (Integer.parseInt(lamp.getNetworkStatus()) == 0){
  86. lamp.setLighteness(0);
  87. }
  88. if (lamp.getPolicyName() == null || lamp.getPolicyType() != 1){
  89. lamp.setPolicyName("暂无");
  90. }
  91. lamp.setControlTypeStr(toolUtils.getLampControlNameById(lamp.getControlType()));
  92. if (lamp.getControlType() == 5){
  93. if (lamp.getMode() == 0){
  94. lamp.setNumber(lamp.getNumber()+"-1");
  95. }else {
  96. lamp.setNumber(lamp.getNumber()+"-2");
  97. }
  98. }
  99. list.add(lamp);
  100. }
  101. return list;
  102. }
  103. @Override
  104. public LampInfoDTO getDetailsById(Integer id,Integer version) {
  105. LampInfoDTO detailsById = lampDao.getDetailsById(id,version);
  106. return detailsById;
  107. }
  108. @Override
  109. public Integer findByVO(LampInfoDTO lampInfoDTO) {
  110. return lampDao.findByVO(lampInfoDTO);
  111. }
  112. @Override
  113. public Integer checkData(LampInfoDTO lampInfoDTO) {
  114. Integer integer = lampDao.checkData(lampInfoDTO);
  115. if (integer == null) integer = 0;
  116. return integer;
  117. }
  118. @Override
  119. public BaseResult add(LampInfoDTO lampInfoDTO) {
  120. if (lampInfoDTO.getNumber() == null || lampInfoDTO.getNumber().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_NUMBER_ERROR,lampInfoDTO.getVersion());
  121. if (!lampInfoDTO.getNumber().matches("^[A-Za-z0-9_]+$")) return toolUtils.response(InterfaceResultEnum.LAMP_NUMBER_FORMAT_ERROR,lampInfoDTO.getVersion());
  122. if (lampInfoDTO.getName() == null || lampInfoDTO.getName().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_NAME_ERROR,lampInfoDTO.getVersion());
  123. if (lampInfoDTO.getSn() == null || lampInfoDTO.getSn().length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_LAMP_ADDRESS_ERROR,lampInfoDTO.getVersion());
  124. if (lampInfoDTO.getAreaId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_AREA_ERROR,lampInfoDTO.getVersion());
  125. if (lampInfoDTO.getSectionId() == 0) return toolUtils.response(InterfaceResultEnum.LACK_SECTION_ERROR,lampInfoDTO.getVersion());
  126. LampInfoDTO lampInfoDTO1 = new LampInfoDTO();
  127. lampInfoDTO1.setSn(lampInfoDTO.getSn());
  128. if (lampDao.findByVO(lampInfoDTO1) > 0) return toolUtils.response(InterfaceResultEnum.LAMP_ADDRESS_UNIQUE_ERROR,lampInfoDTO.getVersion());
  129. lampInfoDTO1 = new LampInfoDTO();
  130. lampInfoDTO1.setNumber(lampInfoDTO.getNumber());
  131. lampInfoDTO1.setSectionId(lampInfoDTO.getSectionId());
  132. if (lampDao.findByVO(lampInfoDTO1) > 0) return toolUtils.response(InterfaceResultEnum.LAMP_NUMBER_UNIQUE_ERROR,lampInfoDTO.getVersion());
  133. lampInfoDTO1 = new LampInfoDTO();
  134. lampInfoDTO1.setName(lampInfoDTO.getName());
  135. lampInfoDTO1.setSectionId(lampInfoDTO.getSectionId());
  136. if (lampDao.findByVO(lampInfoDTO) > 0) return toolUtils.response(InterfaceResultEnum.LAMP_NAME_UNIQUE_ERROR,lampInfoDTO.getVersion());
  137. NetworkDTO networkDTO = new NetworkDTO();
  138. networkDTO.setNetworkName(lampInfoDTO.getSn());
  139. networkDTO.setDeviceSn(lampInfoDTO.getSn());
  140. networkDTO.setAreaId(lampInfoDTO.getAreaId());
  141. networkDTO.setSectionId(lampInfoDTO.getSectionId());
  142. networkDTO.setNetType(1);
  143. networkDTO.setGatewayType("direct");
  144. if (lampInfoDTO.getProtocolType() == 10) networkDTO.setDeviceType(4);
  145. networkDTO.setProtocolType(lampInfoDTO.getProtocolType());
  146. networkService.add(networkDTO);
  147. lampInfoDTO.setNetworkId(networkDTO.getId());
  148. Date endDate = new Date(System.currentTimeMillis());
  149. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  150. String createTime = simpleDateFormat.format(endDate).toString();
  151. lampInfoDTO.setCreateTime(createTime);
  152. if (lampInfoDTO.getControlType() == 5 || lampInfoDTO.getControlType() == 6 || lampInfoDTO.getControlType() == 7){
  153. lampInfoDTO.setMode(1);
  154. }
  155. lampDao.add(lampInfoDTO);
  156. if (lampInfoDTO.getControlType() == 5){ // 4G 双灯
  157. lampInfoDTO.setMode(0);
  158. lampDao.add(lampInfoDTO);
  159. }
  160. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,lampInfoDTO.getVersion());
  161. }
  162. @Override
  163. public BaseResult update(LampInfoDTO lampInfoDTO) {
  164. LampInfoDTO oldLamp = lampDao.getDetailsById(lampInfoDTO.getId(),lampInfoDTO.getVersion());
  165. lampInfoDTO.setNetworkId(oldLamp.getNetworkId());
  166. LampInfoDTO lampInfoDTO1 = new LampInfoDTO();
  167. // lampInfoDTO1.
  168. lampInfoDTO1.setSn(lampInfoDTO.getSn());
  169. lampInfoDTO1.setId(lampInfoDTO.getId());
  170. lampInfoDTO1.setNetworkId(lampInfoDTO.getNetworkId());
  171. if (this.checkData(lampInfoDTO1) > 0) return toolUtils.response(InterfaceResultEnum.LAMP_ADDRESS_UNIQUE_ERROR,lampInfoDTO.getVersion());
  172. lampInfoDTO1 = new LampInfoDTO();
  173. lampInfoDTO1.setNetworkId(lampInfoDTO.getNetworkId());
  174. lampInfoDTO1.setNumber(lampInfoDTO.getNumber());
  175. lampInfoDTO1.setSectionId(lampInfoDTO.getSectionId());
  176. if (this.checkData(lampInfoDTO1) > 0) return toolUtils.response(InterfaceResultEnum.LAMP_NUMBER_UNIQUE_ERROR,lampInfoDTO.getVersion());
  177. lampInfoDTO1 = new LampInfoDTO();
  178. lampInfoDTO1.setNetworkId(lampInfoDTO.getNetworkId());
  179. lampInfoDTO1.setName(lampInfoDTO.getName());
  180. lampInfoDTO1.setSectionId(lampInfoDTO.getSectionId());
  181. if (this.checkData(lampInfoDTO) > 0) return toolUtils.response(InterfaceResultEnum.LAMP_NAME_UNIQUE_ERROR,lampInfoDTO.getVersion());
  182. if (oldLamp.getProtocolType() != lampInfoDTO.getProtocolType()){
  183. NetworkDTO networkDTO = new NetworkDTO();
  184. networkDTO.setId(oldLamp.getNetworkId());
  185. networkDTO.setNetworkName(lampInfoDTO.getSn());
  186. networkDTO.setDeviceSn(lampInfoDTO.getSn());
  187. networkDTO.setAreaId(lampInfoDTO.getAreaId());
  188. networkDTO.setSectionId(lampInfoDTO.getSectionId());
  189. networkDTO.setDeviceType(0);
  190. if (lampInfoDTO.getProtocolType() == 10) networkDTO.setDeviceType(4);
  191. networkDTO.setProtocolType(lampInfoDTO.getProtocolType());
  192. networkService.update(networkDTO);
  193. }
  194. if (lampInfoDTO.getControlType() == 5 || lampInfoDTO.getControlType() == 6 || lampInfoDTO.getControlType() == 7){
  195. lampInfoDTO.setMode(oldLamp.getMode());
  196. }
  197. lampDao.update(lampInfoDTO);
  198. System.out.println(lampInfoDTO.getMode());
  199. if (lampInfoDTO.getControlType() == 5){ // 4G 双灯
  200. lampInfoDTO1 = new LampInfoDTO();
  201. lampInfoDTO1.setSn(lampInfoDTO.getSn());
  202. lampInfoDTO1.setId(lampInfoDTO.getId());
  203. Integer lampId = this.checkData(lampInfoDTO1);
  204. if (oldLamp.getMode() == null || oldLamp.getMode() == 0){
  205. lampInfoDTO.setMode(1);
  206. }else {
  207. lampInfoDTO.setMode(0);
  208. }
  209. System.out.println(lampInfoDTO.getMode());
  210. if (lampId > 0){
  211. lampInfoDTO.setId(lampId);
  212. lampDao.update(lampInfoDTO);
  213. }else {
  214. Date endDate = new Date(System.currentTimeMillis());
  215. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  216. String createTime = simpleDateFormat.format(endDate).toString();
  217. lampInfoDTO.setCreateTime(createTime);
  218. lampDao.add(lampInfoDTO);
  219. }
  220. }else {
  221. if (oldLamp.getControlType() == 5){
  222. lampInfoDTO1 = new LampInfoDTO();
  223. lampInfoDTO1.setSn(lampInfoDTO.getSn());
  224. lampInfoDTO1.setId(lampInfoDTO.getId());
  225. Integer lampId = this.checkData(lampInfoDTO1);
  226. System.out.println(lampId);
  227. if (lampId > 0){
  228. lampDao.deleteById(lampId);
  229. }
  230. }
  231. }
  232. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,lampInfoDTO.getVersion());
  233. }
  234. @Override
  235. public Integer deleteById(Integer id) {
  236. LampInfoDTO detailsById = this.getDetailsById(id, 0);
  237. lampInfoLogService.deleteByLampId(id);
  238. Integer integer = lampDao.deleteById(id);
  239. if (detailsById.getControlType() == 5){ // 4G 双灯
  240. LampInfoDTO detailsByAddress = this.getDetailsByAddress(detailsById.getSn(), 0);
  241. lampInfoLogService.deleteByLampId(detailsByAddress.getId());
  242. lampDao.deleteById(detailsByAddress.getId());
  243. }
  244. return integer;
  245. }
  246. @Override
  247. public LampInfoDTO getDetailsByAddress(String address, Integer version) {
  248. return lampDao.getDetailsByAddress(address,version);
  249. }
  250. @Override
  251. public List<LampInfoDTO> groupSelectLamp(LampListResponseVO lampListResponseVO) {
  252. List<LampInfoDTO> lampInfoDTOS = lampDao.groupSelectLamp(lampListResponseVO);
  253. return lampInfoDTOS;
  254. }
  255. @Override
  256. public List<LampInfoDTO> getNavByVO(LampListResponseVO lampListResponseVO) {
  257. List<LampInfoDTO> navByVO = lampDao.getNavByVO(lampListResponseVO);
  258. List<LampInfoDTO> list = new ArrayList<>();
  259. for (LampInfoDTO l :navByVO) {
  260. if ((l.getProtocolType() == 10 && l.getControlType() == 5) || (l.getProtocolType() == 3 && l.getControlType() == 9) || (l.getProtocolType() == 11 && l.getControlType() == 8) || l.getControlType() == 25 || l.getControlType() == 27){
  261. if (l.getMode() == 0){
  262. l.setNumber(l.getNumber()+"-1");
  263. }else {
  264. l.setNumber(l.getNumber()+"-2");
  265. }
  266. }
  267. list.add(l);
  268. }
  269. return list;
  270. }
  271. @Override
  272. public List<LampInfoDTO> getLampPoleDetailListByLampPoleId(Integer lampPoleId) {
  273. return lampDao.getLampPoleDetailListByLampPoleId(lampPoleId);
  274. }
  275. @Override
  276. public List<LampInfoDTO> getLampInfoListByDTO(LampInfoDTO dto) {
  277. return lampDao.getLampInfoListByDTO(dto);
  278. }
  279. @Override
  280. public List<LampInfoDTO> getLampLocationByGroupId(Integer id) {
  281. return lampDao.getLampLocationByGroupId(id);
  282. }
  283. @Override
  284. public List<LampInfoDTO> getLampLocationByLoopId(Integer id) {
  285. return lampDao.getLampLocationByLoopId(id);
  286. }
  287. @Override
  288. public Integer getLampInstallTotalByDTO(LampInfoDTO dto) {
  289. return lampDao.getLampInstallTotalByDTO(dto);
  290. }
  291. @Override
  292. public Integer getLampLightTotalByDTO(LampInfoDTO dto) {
  293. return lampDao.getLampLightTotalByDTO(dto);
  294. }
  295. @Override
  296. public Integer getLampOnlineTotalByDTO(LampInfoDTO dto) {
  297. return lampDao.getLampOnlineTotalByDTO(dto);
  298. }
  299. @Override
  300. public Integer getLampFaultTotalByDTO(LampInfoDTO dto) {
  301. return lampDao.getLampFaultTotalByDTO(dto);
  302. }
  303. @Override
  304. public void changeLampLocationById(LampInfoDTO dto) {
  305. lampDao.changeLampLocationById(dto);
  306. }
  307. @Override
  308. public Integer getSectionOfLampCountBySectionId(Integer id) {
  309. return lampDao.getSectionOfLampCountBySectionId(id);
  310. }
  311. @Override
  312. public String getNameOrNumber(Integer type, Integer value, Integer version) {
  313. return lampDao.getNameOrNumber(type, value, version);
  314. }
  315. @Override
  316. public LampInfoDTO getLampInfoDTOById(Integer id) {
  317. return lampDao.getLampInfoDTOById(id);
  318. }
  319. @Override
  320. public List<LampInfoDTO> getLampList(LampVO vo) {
  321. return lampDao.getLampList(vo);
  322. }
  323. @Override
  324. public Integer getLampTotal(LampVO vo) {
  325. return lampDao.getLampTotal(vo);
  326. }
  327. @Override
  328. public List<LampInfoDTO> getLampDataByLampIds(List<String> lampIds) {
  329. return lampDao.getLampDataByLampIds(lampIds);
  330. }
  331. @Override
  332. public List<LampInfoDTO> getLampListByLampPoleId(Integer lampPoleId) {
  333. return lampDao.getLampListByLampPoleId(lampPoleId);
  334. }
  335. @Override
  336. public Integer getLampPoleIdByLampId(Integer id) {
  337. return lampDao.getLampPoleIdByLampId(id);
  338. }
  339. @Override
  340. public Integer getLampCountByLampPoleId(Integer lampPoleId) {
  341. return lampDao.getLampCountByLampPoleId(lampPoleId);
  342. }
  343. @Override
  344. public void updateLampInfoForLoopId(LampInfoDTO dto) {
  345. lampDao.updateLampInfoForLoopId(dto);
  346. }
  347. @Override
  348. public List<LampInfoDTO> getLampInfoListForGroup(LampVO vo) {
  349. return lampDao.getLampInfoListForGroup(vo);
  350. }
  351. @Override
  352. public LampInfoVO getLampConsumptionData(LampInfoDataVO vo) throws ParseException {
  353. String dateType = vo.getDateType();
  354. Integer type = vo.getType();
  355. Integer value = vo.getValue();
  356. String date = vo.getDate();
  357. long l = System.currentTimeMillis();
  358. Date date1 = new Date(l);
  359. Calendar calendar = Calendar.getInstance();
  360. calendar.setTime(date1);
  361. int year = calendar.get(Calendar.YEAR); // 获取年份
  362. int month = calendar.get(Calendar.MONTH) + 1; // 获取月份
  363. long startTime = 0L;
  364. long endTime = 0L;
  365. String startDate = "";
  366. DecimalFormat decimalFormat = new DecimalFormat("0.00");
  367. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  368. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
  369. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
  370. SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd 23:59:59");
  371. SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  372. String endDate = simpleDateFormat.format(l);
  373. if (dateType != null && !dateType.isEmpty()) {
  374. switch (dateType) {
  375. case "day":
  376. startDate = format.format(l);
  377. endDate = format1.format(l);
  378. startTime = format2.parse(startDate).getTime();
  379. endTime = format2.parse(endDate).getTime();
  380. break;
  381. case "month":
  382. if (month < 10) {
  383. startDate = year + "-0" + month + "-01";
  384. } else {
  385. startDate = year + "-" + month + "-01";
  386. }
  387. startTime = simpleDateFormat.parse(startDate).getTime();
  388. endTime = simpleDateFormat.parse(endDate).getTime();
  389. break;
  390. case "year":
  391. month = 1;
  392. startDate = year + "-0" + month + "-01";
  393. endDate = simpleDateFormat.format(l);
  394. startTime = simpleDateFormat.parse(startDate).getTime();
  395. endTime = simpleDateFormat.parse(endDate).getTime();
  396. break;
  397. }
  398. } else if (date != null && !date.isEmpty()) {
  399. List<String> split = Arrays.asList(date.split("/"));
  400. startDate = split.get(0);
  401. endDate = split.get(1);
  402. startTime = simpleDateFormat.parse(startDate + " 00:00:00").getTime();
  403. endTime = simpleDateFormat.parse(endDate + " 23:59:59").getTime();
  404. if (endTime < startTime) {
  405. LampInfoVO lampInfoVO = new LampInfoVO();
  406. lampInfoVO.setName("错误1");
  407. return lampInfoVO;
  408. }
  409. if (endTime - startTime > 29L * 24 * 3600 * 1000) {
  410. LampInfoVO lampInfoVO = new LampInfoVO();
  411. lampInfoVO.setName("错误2");
  412. return lampInfoVO;
  413. }
  414. }
  415. HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
  416. long timeT = startTime;
  417. int i = 0;
  418. List<Object> dateList = new ArrayList<>();
  419. List<Object> valueList1 = new ArrayList<>();
  420. List<Object> valueList2 = new ArrayList<>();
  421. List<Object> valueList3 = new ArrayList<>();
  422. List<LampInfoCacheByDayDTO> conSumList = new ArrayList<>();
  423. List<LampInfoLogDTO> dayEleList = new ArrayList<>();
  424. LampInfoCacheByDayDTO dayDTO = new LampInfoCacheByDayDTO();
  425. dayDTO.setType(type);
  426. dayDTO.setValue(value);
  427. dayDTO.setStartDate(startDate);
  428. dayDTO.setEndDate(endDate);
  429. if (dateType != null && !dateType.isEmpty()) {
  430. switch (dateType) {
  431. case "day": // 当天
  432. dayEleList = lampInfoLogService.getDayEleUsedList(type, value);
  433. break;
  434. case "month": // 当月
  435. conSumList = lampInfoCacheByDayService.getMonthConSum(dayDTO);
  436. break;
  437. case "year":
  438. conSumList = lampInfoCacheByDayService.getYearConSum(dayDTO);
  439. break;
  440. }
  441. if (dateType.equals("month")) { // 当月
  442. while (timeT <= endTime) {
  443. objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i);
  444. dateList.add(simpleDateFormat.format(new Date(timeT)));
  445. valueList1.add(0);
  446. valueList2.add(0);
  447. valueList3.add(0);
  448. timeT += 3600 * 1000 * 24;
  449. i ++;
  450. }
  451. for (LampInfoCacheByDayDTO dto : conSumList) {
  452. Date date2 = new Date(simpleDateFormat.parse(dto.getUpdateTime()).getTime());
  453. String s = simpleDateFormat.format(date2);
  454. Integer integer = null;
  455. if (objectObjectHashMap.containsKey(s)) {
  456. integer = objectObjectHashMap.get(s);
  457. }
  458. // 当月累计用电量
  459. if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) {
  460. String formatConSum = decimalFormat.format(dto.getConSum());
  461. valueList1.set(integer, Float.parseFloat(formatConSum));
  462. }
  463. // 当月累计亮灯时间
  464. if (dto.getLightTime() != null && dto.getLightTime() != 0 && integer != null) {
  465. valueList2.set(integer,dto.getLightTime());
  466. }
  467. // 当月累计省电量
  468. if (dto.getPowerSave() != null && !dto.getPowerSave().equals("0") && integer != null) {
  469. String formatSave = decimalFormat.format(dto.getPowerSave());
  470. valueList3.set(integer,Float.parseFloat(formatSave));
  471. }
  472. }
  473. } else if (dateType.equals("day")) { // 当天
  474. format = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
  475. while (timeT < endTime) {
  476. objectObjectHashMap.put(format.format(new Date(timeT)),i);
  477. dateList.add(format.format(new Date(timeT)));
  478. valueList1.add(0);
  479. valueList2.add(0);
  480. valueList3.add(0);
  481. timeT += 3600 * 1000;
  482. i ++;
  483. }
  484. for (LampInfoLogDTO dto : dayEleList) {
  485. Date date2 = new Date(format.parse(dto.getUpdateTime()).getTime());
  486. String s = format.format(date2);
  487. Integer integer = null;
  488. if (objectObjectHashMap.containsKey(s)) {
  489. integer = objectObjectHashMap.get(s);
  490. }
  491. // 当天累计用电量
  492. if (dto.getSumMinEle() != null && !dto.getSumMinEle().equals("0") && integer != null &&
  493. dto.getSumMaxEle() != null && !dto.getSumMaxEle().equals("0")) {
  494. Float sumEle = Float.parseFloat(dto.getSumMaxEle()) - Float.parseFloat(dto.getSumMinEle());
  495. String formatEle = decimalFormat.format(sumEle);
  496. valueList1.set(integer, Float.parseFloat(formatEle));
  497. }
  498. // 当天累计亮灯时间
  499. if (dto.getSumMinLightTime() != null && !dto.getSumMinLightTime().equals("0") && integer != null &&
  500. dto.getSumMaxLightTime() != null && !dto.getSumMaxLightTime().equals("0")) {
  501. Float sumTime = Float.parseFloat(dto.getSumMaxLightTime()) - Float.parseFloat(dto.getSumMinLightTime());
  502. String formatTime = decimalFormat.format(sumTime);
  503. valueList1.set(integer, Float.parseFloat(formatTime));
  504. }
  505. // 当天累计省电量
  506. if (dto.getSumMinSave() != null && !dto.getSumMinSave().equals("0") && integer != null &&
  507. dto.getSumMaxSave() != null && !dto.getSumMaxSave().equals("0")) {
  508. Float sumSave = Float.parseFloat(dto.getSumMaxSave()) - Float.parseFloat(dto.getSumMinSave());
  509. String formatSave = decimalFormat.format(sumSave);
  510. valueList1.set(integer, Float.parseFloat(formatSave));
  511. }
  512. }
  513. } else { // 当年
  514. String dateStr;
  515. while (timeT <= endTime) {
  516. objectObjectHashMap.put(dateFormat.format(new Date(timeT)),i);
  517. dateList.add(dateFormat.format(new Date(timeT)));
  518. valueList1.add(0);
  519. valueList2.add(0);
  520. valueList3.add(0);
  521. month ++;
  522. if (month == 13) {
  523. month = 1;
  524. year ++;
  525. }
  526. if (month < 10) {
  527. dateStr = year + "-0" + month;
  528. } else {
  529. dateStr = year + "-" + month;
  530. }
  531. timeT = dateFormat.parse(dateStr).getTime();
  532. i ++;
  533. }
  534. for (LampInfoCacheByDayDTO dto : conSumList) {
  535. Date date2 = new Date(dateFormat.parse(dto.getUpdateTime()).getTime());
  536. String s = dateFormat.format(date2);
  537. Integer integer = null;
  538. if (objectObjectHashMap.containsKey(s)) {
  539. integer = objectObjectHashMap.get(s);
  540. }
  541. // 当年累计用电量
  542. if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) {
  543. String formatConSum = decimalFormat.format(dto.getConSum());
  544. valueList1.set(integer, Float.parseFloat(formatConSum));
  545. }
  546. // 当年累计亮灯时间
  547. if (dto.getLightTime() != null && dto.getLightTime() != 0 && integer != null) {
  548. valueList2.set(integer,dto.getLightTime());
  549. }
  550. // 当年累计省电量
  551. if (dto.getPowerSave() != null && !dto.getPowerSave().equals("0") && integer != null) {
  552. String formatSave = decimalFormat.format(dto.getPowerSave());
  553. valueList3.set(integer,Float.parseFloat(formatSave));
  554. }
  555. }
  556. }
  557. } else if (date != null && !date.isEmpty()) {
  558. while (timeT <= endTime) {
  559. objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i);
  560. dateList.add(simpleDateFormat.format(new Date(timeT)));
  561. valueList1.add(0);
  562. valueList2.add(0);
  563. valueList3.add(0);
  564. timeT += 3600 * 1000 * 24;
  565. i ++;
  566. }
  567. conSumList = lampInfoCacheByDayService.getMonthConSum(dayDTO);
  568. for (LampInfoCacheByDayDTO dto : conSumList) {
  569. Date date2 = new Date(simpleDateFormat.parse(dto.getUpdateTime()).getTime());
  570. String s = simpleDateFormat.format(date2);
  571. Integer integer = null;
  572. if (objectObjectHashMap.containsKey(s)) {
  573. integer = objectObjectHashMap.get(s);
  574. }
  575. // 具体日期累计用电量
  576. if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) {
  577. String formatConSum = decimalFormat.format(dto.getConSum());
  578. valueList1.set(integer, Float.parseFloat(formatConSum));
  579. }
  580. // 具体日期累计亮灯时间
  581. if (dto.getLightTime() != null && dto.getLightTime() != 0 && integer != null) {
  582. valueList2.set(integer,dto.getLightTime());
  583. }
  584. // 具体日期累计省电量
  585. if (dto.getPowerSave() != null && !dto.getPowerSave().equals("0") && integer != null) {
  586. String formatSave = decimalFormat.format(dto.getPowerSave());
  587. valueList3.set(integer,Float.parseFloat(formatSave));
  588. }
  589. }
  590. }
  591. LampInfoVO lampInfoVO = new LampInfoVO();
  592. lampInfoVO.setDate(dateList);
  593. lampInfoVO.setConsumption(valueList1);
  594. lampInfoVO.setLightTime(valueList2);
  595. lampInfoVO.setSavePower(valueList3);
  596. return lampInfoVO;
  597. }
  598. @Override
  599. public List<LampInfoDTO> getAlarmAreaCountTop(LampInfoDTO dto) {
  600. return lampDao.getAlarmAreaCountTop(dto);
  601. }
  602. @Override
  603. public List<LampInfoDTO> getLampEleUseSectionTop(LampInfoDTO dto) {
  604. return lampDao.getLampEleUseSectionTop(dto);
  605. }
  606. @Override
  607. public List<LampInfoDTO> getLampInfoAlarmList(LampInfoDTO dto) {
  608. return lampDao.getLampInfoAlarmList(dto);
  609. }
  610. @Override
  611. public List<LampInfoDTO> getLampAlarmTotal(LampInfoDTO dto) {
  612. return lampDao.getLampAlarmTotal(dto);
  613. }
  614. @Override
  615. public int getAlarmCountByVO(LampVO lampVO) {
  616. return lampDao.getAlarmCountByVO(lampVO);
  617. }
  618. @Override
  619. public int getOnlineCountByVO(LampVO lampVO) {
  620. return lampDao.getOnlineCountByVO(lampVO);
  621. }
  622. @Override
  623. public List<LampInfoDTO> getLampSectionAlarmCountTop(LampVO vo) {
  624. return lampDao.getLampSectionAlarmCountTop(vo);
  625. }
  626. @Override
  627. public LampInfoDTO getLampOfLampPoleById(Integer lampPoleId, Integer lampId) {
  628. LampInfoDTO lampInfoDTO = lampDao.getLampOfLampPoleById(lampPoleId, lampId);
  629. String workTimeTotal = lampInfoDTO.getWorkTimeTotal();
  630. int workTime = Integer.parseInt(workTimeTotal);
  631. int hour = workTime / 60;
  632. int min = workTime % 60;
  633. String hourStr,minStr;
  634. if (hour < 10) {
  635. hourStr = "0" + hour;
  636. } else {
  637. hourStr = hour + "";
  638. }
  639. if (min < 10) {
  640. minStr = "0" + min;
  641. } else {
  642. minStr = min + "";
  643. }
  644. workTimeTotal = hourStr + ":" + minStr;
  645. lampInfoDTO.setWorkTimeTotal(workTimeTotal);
  646. return lampInfoDTO;
  647. }
  648. @Override
  649. public LampInfoLogNewDTO getComBySectionList(LampVO vo) {
  650. return lampDao.getComBySectionList(vo);
  651. }
  652. @Override
  653. public Integer updateLight(LampInfoDTO lampInfoDTO) {
  654. return lampDao.updateLight(lampInfoDTO);
  655. }
  656. @Override
  657. public List<LampInfoDTO> getListByIdList(List idList) {
  658. return lampDao.getListByIdList(idList);
  659. }
  660. @Override
  661. public Integer getLampPoleCountByVO(LampCountVO lampCountVO) {
  662. return lampDao.getLampPoleCountByVO(lampCountVO);
  663. }
  664. @Override
  665. public List<LampInfoDTO> areaInfoLampList(LampListResponseVO lampListResponseVO) {
  666. return lampDao.areaInfoLampList(lampListResponseVO);
  667. }
  668. }