package com.welampiot.service.impl; import com.welampiot.dao.SolarDevDao; import com.welampiot.dto.SolarDevDTO; import com.welampiot.service.SolarDevService; import com.welampiot.vo.SolarDevVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * ClassName: SolarDevServiceImpl * Package: com.welampiot.service.impl * Description: * * @Author: zhj_Start * @Create: 2023/5/19 - 14:43 * @Version: v1.0 */ @Service public class SolarDevServiceImpl implements SolarDevService { @Autowired private SolarDevDao solarDevDao; @Override public SolarDevVO getSolarListByDTO(SolarDevDTO dto) { SolarDevVO vo = new SolarDevVO(); vo.setTotal(solarDevDao.getSolarDevTotalByDTO(dto)); vo.setOnlineCount(solarDevDao.getSolarDevOnlineTotalByDTO(dto)); vo.setLightCount(solarDevDao.getSolarDevLightTotalByDTO(dto)); Double dayCom = solarDevDao.getSolarDevDayElectricTotalByDTO(dto).stream() .mapToDouble(solarDevDTO -> Double.parseDouble(solarDevDTO.getDayConsumption())).sum(); vo.setDayCom(dayCom); Double totalCom = solarDevDao.getSolarDevSumElectricTotalByDTO(dto).stream() .mapToDouble(solarDevDTO -> Double.parseDouble(solarDevDTO.getTotalConsumption())).sum(); vo.setTotalCom(totalCom); List solarListByDTO = solarDevDao.getSolarListByDTO(dto); List list = new ArrayList<>(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); solarListByDTO.forEach(solarDTO -> { if (solarDTO.getLampPoleName() == null) { solarDTO.setLampPoleName(""); } if (solarDTO.getSection() == null) { solarDTO.setSection(""); } if (solarDTO.getArea() == null) { solarDTO.setArea(""); } if (solarDTO.getNetStatus() != null && solarDTO.getNetStatus() == 1) { solarDTO.setNetStatus(1); } else { solarDTO.setNetStatus(0); } if (solarDTO.getLogTime() != null && !solarDTO.getLogTime().equals("")){ Date cmdTime; try { cmdTime = simpleDateFormat.parse(solarDTO.getLogTime()); } catch (ParseException e) { throw new RuntimeException(e); } //判断时区,为null默认东八区 long timezone = solarDTO.getTimezone() == null ? 8 : solarDTO.getTimezone(); long l = cmdTime.getTime() + timezone * 3600 * 1000; cmdTime = new Date(l); solarDTO.setLogTime(simpleDateFormat.format(cmdTime)); }else { solarDTO.setLogTime(""); } if (solarDTO.getBatteryCurrent() == null || solarDTO.getBatteryCurrent().equals("0.0")) { solarDTO.setBatteryCurrent("0"); } if (solarDTO.getBatteryVoltage() == null || solarDTO.getBatteryVoltage().equals("0.0")) { solarDTO.setBatteryVoltage("0"); } if (solarDTO.getBatteryPower() == null || solarDTO.getBatteryPower().equals("0.0")) { solarDTO.setBatteryPower("0"); } if (solarDTO.getSolarCurrent() == null || solarDTO.getSolarCurrent().equals("0.0")) { solarDTO.setSolarCurrent("0"); } if (solarDTO.getSolarVoltage() == null || solarDTO.getSolarVoltage().equals("0.0")) { solarDTO.setSolarVoltage("0"); } if (solarDTO.getSolarPower() == null || solarDTO.getSolarPower().equals("0.0")) { solarDTO.setSolarPower("0"); } if (solarDTO.getLampCurrent() == null || solarDTO.getLampCurrent().equals("0.0")) { solarDTO.setLampCurrent("0"); } if (solarDTO.getLampVoltage() == null || solarDTO.getLampVoltage().equals("0.0")) { solarDTO.setLampVoltage("0"); } if (solarDTO.getLampPower() == null || solarDTO.getLampPower().equals("0.0")) { solarDTO.setLampPower("0"); } list.add(solarDTO); }); vo.setList(list); return vo; } @Override public void updateSolarDevData(SolarDevDTO dto) { solarDevDao.updateSolarDevData(dto); } }