SolarDevServiceImpl.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package com.welampiot.service.impl;
  2. import com.welampiot.dao.SolarDevDao;
  3. import com.welampiot.dto.SolarDevDTO;
  4. import com.welampiot.service.SolarDevService;
  5. import com.welampiot.vo.SolarDevVO;
  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: SolarDevServiceImpl
  15. * Package: com.welampiot.service.impl
  16. * Description:
  17. *
  18. * @Author: zhj_Start
  19. * @Create: 2023/5/19 - 14:43
  20. * @Version: v1.0
  21. */
  22. @Service
  23. public class SolarDevServiceImpl implements SolarDevService {
  24. @Autowired
  25. private SolarDevDao solarDevDao;
  26. @Override
  27. public SolarDevVO getSolarListByDTO(SolarDevDTO dto) {
  28. SolarDevVO vo = new SolarDevVO();
  29. vo.setTotal(solarDevDao.getSolarDevTotalByDTO(dto));
  30. vo.setOnlineCount(solarDevDao.getSolarDevOnlineTotalByDTO(dto));
  31. vo.setLightCount(solarDevDao.getSolarDevLightTotalByDTO(dto));
  32. Double dayCom = solarDevDao.getSolarDevDayElectricTotalByDTO(dto).stream()
  33. .mapToDouble(solarDevDTO -> Double.parseDouble(solarDevDTO.getDayConsumption())).sum();
  34. vo.setDayCom(dayCom);
  35. Double totalCom = solarDevDao.getSolarDevSumElectricTotalByDTO(dto).stream()
  36. .mapToDouble(solarDevDTO -> Double.parseDouble(solarDevDTO.getTotalConsumption())).sum();
  37. vo.setTotalCom(totalCom);
  38. List<SolarDevDTO> solarListByDTO = solarDevDao.getSolarListByDTO(dto);
  39. List<SolarDevDTO> list = new ArrayList<>();
  40. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  41. solarListByDTO.forEach(solarDTO -> {
  42. if (solarDTO.getLampPoleName() == null) {
  43. solarDTO.setLampPoleName("");
  44. }
  45. if (solarDTO.getSection() == null) {
  46. solarDTO.setSection("");
  47. }
  48. if (solarDTO.getArea() == null) {
  49. solarDTO.setArea("");
  50. }
  51. if (solarDTO.getNetStatus() != null && solarDTO.getNetStatus() == 1) {
  52. solarDTO.setNetStatus(1);
  53. } else {
  54. solarDTO.setNetStatus(0);
  55. }
  56. if (solarDTO.getLogTime() != null && !solarDTO.getLogTime().equals("")){
  57. Date cmdTime;
  58. try {
  59. cmdTime = simpleDateFormat.parse(solarDTO.getLogTime());
  60. } catch (ParseException e) {
  61. throw new RuntimeException(e);
  62. }
  63. //判断时区,为null默认东八区
  64. long timezone = solarDTO.getTimezone() == null ? 8 : solarDTO.getTimezone();
  65. long l = cmdTime.getTime() + timezone * 3600 * 1000;
  66. cmdTime = new Date(l);
  67. solarDTO.setLogTime(simpleDateFormat.format(cmdTime));
  68. }else {
  69. solarDTO.setLogTime("");
  70. }
  71. if (solarDTO.getBatteryCurrent() == null || solarDTO.getBatteryCurrent().equals("0.0")) {
  72. solarDTO.setBatteryCurrent("0");
  73. }
  74. if (solarDTO.getBatteryVoltage() == null || solarDTO.getBatteryVoltage().equals("0.0")) {
  75. solarDTO.setBatteryVoltage("0");
  76. }
  77. if (solarDTO.getBatteryPower() == null || solarDTO.getBatteryPower().equals("0.0")) {
  78. solarDTO.setBatteryPower("0");
  79. }
  80. if (solarDTO.getSolarCurrent() == null || solarDTO.getSolarCurrent().equals("0.0")) {
  81. solarDTO.setSolarCurrent("0");
  82. }
  83. if (solarDTO.getSolarVoltage() == null || solarDTO.getSolarVoltage().equals("0.0")) {
  84. solarDTO.setSolarVoltage("0");
  85. }
  86. if (solarDTO.getSolarPower() == null || solarDTO.getSolarPower().equals("0.0")) {
  87. solarDTO.setSolarPower("0");
  88. }
  89. if (solarDTO.getLampCurrent() == null || solarDTO.getLampCurrent().equals("0.0")) {
  90. solarDTO.setLampCurrent("0");
  91. }
  92. if (solarDTO.getLampVoltage() == null || solarDTO.getLampVoltage().equals("0.0")) {
  93. solarDTO.setLampVoltage("0");
  94. }
  95. if (solarDTO.getLampPower() == null || solarDTO.getLampPower().equals("0.0")) {
  96. solarDTO.setLampPower("0");
  97. }
  98. list.add(solarDTO);
  99. });
  100. vo.setList(list);
  101. return vo;
  102. }
  103. @Override
  104. public void updateSolarDevData(SolarDevDTO dto) {
  105. solarDevDao.updateSolarDevData(dto);
  106. }
  107. }