SuperPowerDevInfoServiceImpl.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. package com.welampiot.service.impl;
  2. import com.welampiot.dao.SuperPowerDevInfoDao;
  3. import com.welampiot.dto.SuperPowerDevInfoDTO;
  4. import com.welampiot.service.SuperPowerDevInfoService;
  5. import com.welampiot.vo.SuperPowerDevInfoVO;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import java.text.ParseException;
  9. import java.text.SimpleDateFormat;
  10. import java.util.ArrayList;
  11. import java.util.Date;
  12. import java.util.List;
  13. /**
  14. * ClassName: SuperPowerDevInfoServiceImpl
  15. * Package: com.welampiot.service.impl
  16. * Description:
  17. *
  18. * @Author: zhj_Start
  19. * @Create: 2023/4/23 - 11:21
  20. * @Version: v1.0
  21. */
  22. @Service
  23. public class SuperPowerDevInfoServiceImpl implements SuperPowerDevInfoService {
  24. @Autowired
  25. private SuperPowerDevInfoDao superPowerDevInfoDao;
  26. @Override
  27. public SuperPowerDevInfoVO getListBySuperPowerDevInfoDTO(SuperPowerDevInfoDTO dto, Integer version) {
  28. SuperPowerDevInfoVO vo = new SuperPowerDevInfoVO();
  29. vo.setTotal(superPowerDevInfoDao.getTotalBySuperPowerDevInfoDTO(dto));
  30. List<SuperPowerDevInfoDTO> listByDTO = superPowerDevInfoDao.getListBySuperPowerDevInfoDTO(dto);
  31. List<SuperPowerDevInfoDTO> list = new ArrayList<>();
  32. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  33. listByDTO.forEach(infoDTO ->{
  34. //灯杆名
  35. if (infoDTO.getLampPoleName() == null){
  36. infoDTO.setLampPoleName("");
  37. }
  38. //区域名
  39. if (version == 0){
  40. if (infoDTO.getChArea() != null){
  41. infoDTO.setArea(infoDTO.getChArea());
  42. }else {
  43. infoDTO.setArea("");
  44. }
  45. }else if (version == 1){
  46. if (infoDTO.getEnArea() != null){
  47. infoDTO.setArea(infoDTO.getEnArea());
  48. }else {
  49. infoDTO.setArea("");
  50. }
  51. }else {
  52. if (infoDTO.getRuArea() != null){
  53. infoDTO.setArea(infoDTO.getRuArea());
  54. }else {
  55. infoDTO.setArea("");
  56. }
  57. }
  58. //路段名
  59. if (infoDTO.getSection() == null){
  60. infoDTO.setSection("");
  61. }
  62. //网络状态(0:离线,1:在线)
  63. if (infoDTO.getStatus() != null && infoDTO.getStatus() == 1){
  64. infoDTO.setStatus(1);
  65. }else {
  66. infoDTO.setStatus(0);
  67. }
  68. //220V1路输出开关状态(0:关,1:开)
  69. if (infoDTO.getRemark1Status() != null && infoDTO.getRemark1Status() == 1){
  70. infoDTO.setRemark1Status(1);
  71. }else {
  72. infoDTO.setRemark1Status(0);
  73. }
  74. //220V2路输出开关状态(0:关,1:开)
  75. if (infoDTO.getRemark2Status() != null && infoDTO.getRemark2Status() == 1){
  76. infoDTO.setRemark2Status(1);
  77. }else {
  78. infoDTO.setRemark2Status(0);
  79. }
  80. //220V3路输出开关状态(0:关,1:开)
  81. if (infoDTO.getRemark3Status() != null && infoDTO.getRemark3Status() == 1){
  82. infoDTO.setRemark3Status(1);
  83. }else {
  84. infoDTO.setRemark3Status(0);
  85. }
  86. //DC48V输出开关状态(0:关,1:开)
  87. if (infoDTO.getRemark4Status() != null && infoDTO.getRemark4Status() == 1){
  88. infoDTO.setRemark4Status(1);
  89. }else {
  90. infoDTO.setRemark4Status(0);
  91. }
  92. //DC24V1路输出开关状态(0:关,1:开)
  93. if (infoDTO.getRemark5Status() != null && infoDTO.getRemark5Status() == 1){
  94. infoDTO.setRemark5Status(1);
  95. }else {
  96. infoDTO.setRemark5Status(0);
  97. }
  98. //DC24V2路输出开关状态(0:关,1:开)
  99. if (infoDTO.getRemark6Status() != null && infoDTO.getRemark6Status() == 1){
  100. infoDTO.setRemark6Status(1);
  101. }else {
  102. infoDTO.setRemark6Status(0);
  103. }
  104. //DC12V输出开关状态(0:关,1:开)
  105. if (infoDTO.getRemark7Status() != null && infoDTO.getRemark7Status() == 1){
  106. infoDTO.setRemark7Status(1);
  107. }else {
  108. infoDTO.setRemark7Status(0);
  109. }
  110. if (infoDTO.getRemark1RunningStatus() != null){
  111. switch (infoDTO.getRemark1RunningStatus()){
  112. case 4 :
  113. infoDTO.setRemark1RunningStatus(4);
  114. break;
  115. case 3 :
  116. infoDTO.setRemark1RunningStatus(3);
  117. break;
  118. case 2 :
  119. infoDTO.setRemark1RunningStatus(2);
  120. break;
  121. case 1 :
  122. infoDTO.setRemark1RunningStatus(1);
  123. break;
  124. default:
  125. infoDTO.setRemark1RunningStatus(0);
  126. break;
  127. }
  128. }else {
  129. infoDTO.setRemark1RunningStatus(0);
  130. }
  131. if (infoDTO.getRemark2RunningStatus() != null){
  132. switch (infoDTO.getRemark2RunningStatus()){
  133. case 4 :
  134. infoDTO.setRemark2RunningStatus(4);
  135. break;
  136. case 3 :
  137. infoDTO.setRemark2RunningStatus(3);
  138. break;
  139. case 2 :
  140. infoDTO.setRemark2RunningStatus(2);
  141. break;
  142. case 1 :
  143. infoDTO.setRemark2RunningStatus(1);
  144. break;
  145. default:
  146. infoDTO.setRemark2RunningStatus(0);
  147. break;
  148. }
  149. }else {
  150. infoDTO.setRemark2RunningStatus(0);
  151. }
  152. if (infoDTO.getRemark3RunningStatus() != null){
  153. switch (infoDTO.getRemark3RunningStatus()){
  154. case 4 :
  155. infoDTO.setRemark3RunningStatus(4);
  156. break;
  157. case 3 :
  158. infoDTO.setRemark3RunningStatus(3);
  159. break;
  160. case 2 :
  161. infoDTO.setRemark3RunningStatus(2);
  162. break;
  163. case 1 :
  164. infoDTO.setRemark3RunningStatus(1);
  165. break;
  166. default:
  167. infoDTO.setRemark3RunningStatus(0);
  168. break;
  169. }
  170. }else {
  171. infoDTO.setRemark3RunningStatus(0);
  172. }
  173. if (infoDTO.getRemark4RunningStatus() != null){
  174. switch (infoDTO.getRemark4RunningStatus()){
  175. case 5 :
  176. infoDTO.setRemark4RunningStatus(5);
  177. break;
  178. case 4 :
  179. infoDTO.setRemark4RunningStatus(4);
  180. break;
  181. case 3 :
  182. infoDTO.setRemark4RunningStatus(3);
  183. break;
  184. case 2 :
  185. infoDTO.setRemark4RunningStatus(2);
  186. break;
  187. case 1 :
  188. infoDTO.setRemark4RunningStatus(1);
  189. break;
  190. default:
  191. infoDTO.setRemark4RunningStatus(0);
  192. break;
  193. }
  194. }else {
  195. infoDTO.setRemark4RunningStatus(0);
  196. }
  197. if (infoDTO.getRemark5RunningStatus() != null){
  198. switch (infoDTO.getRemark5RunningStatus()){
  199. case 5 :
  200. infoDTO.setRemark5RunningStatus(5);
  201. break;
  202. case 4 :
  203. infoDTO.setRemark5RunningStatus(4);
  204. break;
  205. case 3 :
  206. infoDTO.setRemark5RunningStatus(3);
  207. break;
  208. case 2 :
  209. infoDTO.setRemark5RunningStatus(2);
  210. break;
  211. case 1 :
  212. infoDTO.setRemark5RunningStatus(1);
  213. break;
  214. default:
  215. infoDTO.setRemark5RunningStatus(0);
  216. break;
  217. }
  218. }else {
  219. infoDTO.setRemark5RunningStatus(0);
  220. }
  221. if (infoDTO.getRemark6RunningStatus() != null){
  222. switch (infoDTO.getRemark6RunningStatus()){
  223. case 5 :
  224. infoDTO.setRemark6RunningStatus(5);
  225. break;
  226. case 4 :
  227. infoDTO.setRemark6RunningStatus(4);
  228. break;
  229. case 3 :
  230. infoDTO.setRemark6RunningStatus(3);
  231. break;
  232. case 2 :
  233. infoDTO.setRemark6RunningStatus(2);
  234. break;
  235. case 1 :
  236. infoDTO.setRemark6RunningStatus(1);
  237. break;
  238. default:
  239. infoDTO.setRemark6RunningStatus(0);
  240. break;
  241. }
  242. }else {
  243. infoDTO.setRemark6RunningStatus(0);
  244. }
  245. if (infoDTO.getRemark7RunningStatus() != null){
  246. switch (infoDTO.getRemark7RunningStatus()){
  247. case 5 :
  248. infoDTO.setRemark7RunningStatus(5);
  249. break;
  250. case 4 :
  251. infoDTO.setRemark7RunningStatus(4);
  252. break;
  253. case 3 :
  254. infoDTO.setRemark7RunningStatus(3);
  255. break;
  256. case 2 :
  257. infoDTO.setRemark7RunningStatus(2);
  258. break;
  259. case 1 :
  260. infoDTO.setRemark7RunningStatus(1);
  261. break;
  262. default:
  263. infoDTO.setRemark7RunningStatus(0);
  264. break;
  265. }
  266. }else {
  267. infoDTO.setRemark7RunningStatus(0);
  268. }
  269. if (infoDTO.getFaultInfo1() == null){
  270. infoDTO.setFaultInfo1("");
  271. }
  272. if (infoDTO.getFaultInfo2() == null){
  273. infoDTO.setFaultInfo2("");
  274. }
  275. //创建时间
  276. if (infoDTO.getCreateTime() != null && !infoDTO.getCreateTime().equals("")){
  277. try {
  278. infoDTO.setCreateTime(simpleDateFormat.format(simpleDateFormat.parse(infoDTO.getCreateTime())));
  279. } catch (ParseException e) {
  280. throw new RuntimeException(e);
  281. }
  282. }else {
  283. infoDTO.setCreateTime("");
  284. }
  285. //安装时间
  286. if (infoDTO.getInstallDate() != null && !infoDTO.getInstallDate().equals("")){
  287. try {
  288. infoDTO.setInstallDate(simpleDateFormat.format(simpleDateFormat.parse(infoDTO.getInstallDate())));
  289. } catch (ParseException e) {
  290. throw new RuntimeException(e);
  291. }
  292. }else {
  293. infoDTO.setInstallDate("");
  294. }
  295. //过期时间
  296. if (infoDTO.getExpirationDate() != null && !infoDTO.getExpirationDate().equals("")){
  297. try {
  298. infoDTO.setExpirationDate(simpleDateFormat.format(simpleDateFormat.parse(infoDTO.getExpirationDate())));
  299. } catch (ParseException e) {
  300. throw new RuntimeException(e);
  301. }
  302. }else {
  303. infoDTO.setExpirationDate("");
  304. }
  305. //更新时间
  306. if (infoDTO.getUpdateTime() != null && !infoDTO.getUpdateTime().equals("")){
  307. Date cmdTime;
  308. try {
  309. cmdTime = simpleDateFormat.parse(infoDTO.getUpdateTime());
  310. } catch (ParseException e) {
  311. throw new RuntimeException(e);
  312. }
  313. //判断时区,为null默认东八区
  314. long timezone = infoDTO.getTimezone() == null ? 8 : infoDTO.getTimezone();
  315. long l = cmdTime.getTime() + timezone * 3600 * 1000;
  316. cmdTime = new Date(l);
  317. infoDTO.setUpdateTime(simpleDateFormat.format(cmdTime));
  318. }else {
  319. infoDTO.setUpdateTime("");
  320. }
  321. list.add(infoDTO);
  322. });
  323. vo.setList(list);
  324. return vo;
  325. }
  326. @Override
  327. public SuperPowerDevInfoVO getPowerInfo(SuperPowerDevInfoDTO dto) {
  328. SuperPowerDevInfoVO vo = new SuperPowerDevInfoVO();
  329. //设备总数
  330. vo.setDevTotal(superPowerDevInfoDao.getTotalBySuperPowerDevInfoDTO(dto));
  331. //在线数
  332. vo.setOnlineCount(superPowerDevInfoDao.getOnlineTotalBySuperPowerDevInfoDTO(dto));
  333. //设备故障数
  334. vo.setFaultCount(superPowerDevInfoDao.getFaultTotalBySuperPowerDevInfoDTO(dto));
  335. //当天用电量
  336. List<SuperPowerDevInfoDTO> dayElectricByDTO = superPowerDevInfoDao.getDayElectricBySuperPowerDevInfoDTO(dto);
  337. Double dayElectric = dayElectricByDTO.stream().mapToDouble(infoDTO -> Float.parseFloat(infoDTO.getDayElectric())).sum();
  338. vo.setDayElectric(Float.parseFloat(String.format("%.2f",dayElectric)));
  339. //总用电量
  340. List<SuperPowerDevInfoDTO> totalElectricByDTO = superPowerDevInfoDao.getTotalElectricBySuperPowerDevInfoDTO(dto);
  341. Double totalElectric = totalElectricByDTO.stream().mapToDouble(infoDTO -> Float.parseFloat(infoDTO.getTotalElectric())).sum();
  342. vo.setTotalElectric(Float.parseFloat(String.format("%.2f",totalElectric)));
  343. return vo;
  344. }
  345. @Override
  346. public SuperPowerDevInfoVO getPowerOutInfoByDTO(SuperPowerDevInfoDTO dto) {
  347. SuperPowerDevInfoVO vo = new SuperPowerDevInfoVO();
  348. SuperPowerDevInfoDTO powerOutInfoDTO = superPowerDevInfoDao.getPowerOutInfoByDTO(dto);
  349. if (powerOutInfoDTO == null) return null;
  350. if (powerOutInfoDTO.getRemark1() != null){
  351. vo.setRemark1(powerOutInfoDTO.getRemark1());
  352. }else {
  353. vo.setRemark1("");
  354. }
  355. if (powerOutInfoDTO.getRemark2() != null){
  356. vo.setRemark2(powerOutInfoDTO.getRemark2());
  357. }else {
  358. vo.setRemark2("");
  359. }
  360. if (powerOutInfoDTO.getRemark3() != null){
  361. vo.setRemark3(powerOutInfoDTO.getRemark3());
  362. }else {
  363. vo.setRemark3("");
  364. }
  365. if (powerOutInfoDTO.getRemark4() != null){
  366. vo.setRemark4(powerOutInfoDTO.getRemark4());
  367. }else {
  368. vo.setRemark4("");
  369. }
  370. if (powerOutInfoDTO.getRemark5() != null){
  371. vo.setRemark5(powerOutInfoDTO.getRemark5());
  372. }else {
  373. vo.setRemark5("");
  374. }
  375. if (powerOutInfoDTO.getRemark6() != null){
  376. vo.setRemark6(powerOutInfoDTO.getRemark6());
  377. }else {
  378. vo.setRemark6("");
  379. }
  380. if (powerOutInfoDTO.getRemark7() != null){
  381. vo.setRemark7(powerOutInfoDTO.getRemark7());
  382. }else {
  383. vo.setRemark7("");
  384. }
  385. //220V1路输出开关状态(0:关,1:开)
  386. if (powerOutInfoDTO.getRemark1Status() != null && powerOutInfoDTO.getRemark1Status() == 1){
  387. vo.setRemark1Status(1);
  388. }else {
  389. vo.setRemark1Status(0);
  390. }
  391. //220V2路输出开关状态(0:关,1:开)
  392. if (powerOutInfoDTO.getRemark2Status() != null && powerOutInfoDTO.getRemark2Status() == 1){
  393. vo.setRemark2Status(1);
  394. }else {
  395. vo.setRemark2Status(0);
  396. }
  397. //220V3路输出开关状态(0:关,1:开)
  398. if (powerOutInfoDTO.getRemark3Status() != null && powerOutInfoDTO.getRemark3Status() == 1){
  399. vo.setRemark3Status(1);
  400. }else {
  401. vo.setRemark3Status(0);
  402. }
  403. //DC48V输出开关状态(0:关,1:开)
  404. if (powerOutInfoDTO.getRemark4Status() != null && powerOutInfoDTO.getRemark4Status() == 1){
  405. vo.setRemark4Status(1);
  406. }else {
  407. vo.setRemark4Status(0);
  408. }
  409. //DC24V1路输出开关状态(0:关,1:开)
  410. if (powerOutInfoDTO.getRemark5Status() != null && powerOutInfoDTO.getRemark5Status() == 1){
  411. vo.setRemark5Status(1);
  412. }else {
  413. vo.setRemark5Status(0);
  414. }
  415. //DC24V2路输出开关状态(0:关,1:开)
  416. if (powerOutInfoDTO.getRemark6Status() != null && powerOutInfoDTO.getRemark6Status() == 1){
  417. vo.setRemark6Status(1);
  418. }else {
  419. vo.setRemark6Status(0);
  420. }
  421. //DC12V输出开关状态(0:关,1:开)
  422. if (powerOutInfoDTO.getRemark7Status() != null && powerOutInfoDTO.getRemark7Status() == 1){
  423. vo.setRemark7Status(1);
  424. }else {
  425. vo.setRemark7Status(0);
  426. }
  427. if (powerOutInfoDTO.getType1() != null && powerOutInfoDTO.getType1() == 1){
  428. vo.setType1(1);
  429. }else {
  430. vo.setType1(0);
  431. }
  432. if (powerOutInfoDTO.getType2() != null && powerOutInfoDTO.getType2() == 1){
  433. vo.setType2(1);
  434. }else {
  435. vo.setType2(0);
  436. }
  437. if (powerOutInfoDTO.getType3() != null && powerOutInfoDTO.getType3() == 1){
  438. vo.setType3(1);
  439. }else {
  440. vo.setType3(0);
  441. }
  442. if (powerOutInfoDTO.getType4() != null && powerOutInfoDTO.getType4() == 1){
  443. vo.setType4(1);
  444. }else {
  445. vo.setType4(0);
  446. }
  447. if (powerOutInfoDTO.getType5() != null && powerOutInfoDTO.getType5() == 1){
  448. vo.setType5(1);
  449. }else {
  450. vo.setType5(0);
  451. }
  452. if (powerOutInfoDTO.getType6() != null && powerOutInfoDTO.getType6() == 1){
  453. vo.setType6(1);
  454. }else {
  455. vo.setType6(0);
  456. }
  457. if (powerOutInfoDTO.getType7() != null && powerOutInfoDTO.getType7() == 1){
  458. vo.setType7(1);
  459. }else {
  460. vo.setType7(0);
  461. }
  462. if (powerOutInfoDTO.getCloseTime1() != null){
  463. vo.setCloseTime1(powerOutInfoDTO.getCloseTime1());
  464. }else {
  465. vo.setCloseTime1("");
  466. }
  467. if (powerOutInfoDTO.getCloseTime2() != null){
  468. vo.setCloseTime2(powerOutInfoDTO.getCloseTime2());
  469. }else {
  470. vo.setCloseTime2("");
  471. }
  472. if (powerOutInfoDTO.getCloseTime3() != null){
  473. vo.setCloseTime3(powerOutInfoDTO.getCloseTime3());
  474. }else {
  475. vo.setCloseTime3("");
  476. }
  477. if (powerOutInfoDTO.getCloseTime4() != null){
  478. vo.setCloseTime4(powerOutInfoDTO.getCloseTime4());
  479. }else {
  480. vo.setCloseTime4("");
  481. }
  482. if (powerOutInfoDTO.getCloseTime5() != null){
  483. vo.setCloseTime5(powerOutInfoDTO.getCloseTime5());
  484. }else {
  485. vo.setCloseTime5("");
  486. }
  487. if (powerOutInfoDTO.getCloseTime6() != null){
  488. vo.setCloseTime6(powerOutInfoDTO.getCloseTime6());
  489. }else {
  490. vo.setCloseTime6("");
  491. }
  492. if (powerOutInfoDTO.getCloseTime7() != null){
  493. vo.setCloseTime7(powerOutInfoDTO.getCloseTime7());
  494. }else {
  495. vo.setCloseTime7("");
  496. }
  497. if (powerOutInfoDTO.getOpenTime1() != null){
  498. vo.setOpenTime1(powerOutInfoDTO.getOpenTime1());
  499. }else {
  500. vo.setOpenTime1("");
  501. }
  502. if (powerOutInfoDTO.getOpenTime2() != null){
  503. vo.setOpenTime2(powerOutInfoDTO.getOpenTime2());
  504. }else {
  505. vo.setOpenTime2("");
  506. }
  507. if (powerOutInfoDTO.getOpenTime3() != null){
  508. vo.setOpenTime3(powerOutInfoDTO.getOpenTime3());
  509. }else {
  510. vo.setOpenTime3("");
  511. }
  512. if (powerOutInfoDTO.getOpenTime4() != null){
  513. vo.setOpenTime4(powerOutInfoDTO.getOpenTime4());
  514. }else {
  515. vo.setOpenTime4("");
  516. }
  517. if (powerOutInfoDTO.getOpenTime5() != null){
  518. vo.setOpenTime5(powerOutInfoDTO.getOpenTime5());
  519. }else {
  520. vo.setOpenTime5("");
  521. }
  522. if (powerOutInfoDTO.getOpenTime6() != null){
  523. vo.setOpenTime6(powerOutInfoDTO.getOpenTime6());
  524. }else {
  525. vo.setOpenTime6("");
  526. }
  527. if (powerOutInfoDTO.getOpenTime7() != null){
  528. vo.setOpenTime7(powerOutInfoDTO.getOpenTime7());
  529. }else {
  530. vo.setOpenTime7("");
  531. }
  532. return vo;
  533. }
  534. }