123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541 |
- package com.welampiot.service.impl;
- import com.welampiot.dao.SuperPowerDevInfoDao;
- import com.welampiot.dto.SuperPowerDevInfoDTO;
- import com.welampiot.service.SuperPowerDevInfoService;
- import com.welampiot.vo.SuperPowerDevInfoVO;
- 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: SuperPowerDevInfoServiceImpl
- * Package: com.welampiot.service.impl
- * Description:
- *
- * @Author: zhj_Start
- * @Create: 2023/4/23 - 11:21
- * @Version: v1.0
- */
- @Service
- public class SuperPowerDevInfoServiceImpl implements SuperPowerDevInfoService {
- @Autowired
- private SuperPowerDevInfoDao superPowerDevInfoDao;
- @Override
- public SuperPowerDevInfoVO getListBySuperPowerDevInfoDTO(SuperPowerDevInfoDTO dto, Integer version) {
- SuperPowerDevInfoVO vo = new SuperPowerDevInfoVO();
- vo.setTotal(superPowerDevInfoDao.getTotalBySuperPowerDevInfoDTO(dto));
- List<SuperPowerDevInfoDTO> listByDTO = superPowerDevInfoDao.getListBySuperPowerDevInfoDTO(dto);
- List<SuperPowerDevInfoDTO> list = new ArrayList<>();
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- listByDTO.forEach(infoDTO ->{
- //灯杆名
- if (infoDTO.getLampPoleName() == null){
- infoDTO.setLampPoleName("");
- }
- //区域名
- if (version == 0){
- if (infoDTO.getChArea() != null){
- infoDTO.setArea(infoDTO.getChArea());
- }else {
- infoDTO.setArea("");
- }
- }else if (version == 1){
- if (infoDTO.getEnArea() != null){
- infoDTO.setArea(infoDTO.getEnArea());
- }else {
- infoDTO.setArea("");
- }
- }else {
- if (infoDTO.getRuArea() != null){
- infoDTO.setArea(infoDTO.getRuArea());
- }else {
- infoDTO.setArea("");
- }
- }
- //路段名
- if (infoDTO.getSection() == null){
- infoDTO.setSection("");
- }
- //网络状态(0:离线,1:在线)
- if (infoDTO.getStatus() != null && infoDTO.getStatus() == 1){
- infoDTO.setStatus(1);
- }else {
- infoDTO.setStatus(0);
- }
- //220V1路输出开关状态(0:关,1:开)
- if (infoDTO.getRemark1Status() != null && infoDTO.getRemark1Status() == 1){
- infoDTO.setRemark1Status(1);
- }else {
- infoDTO.setRemark1Status(0);
- }
- //220V2路输出开关状态(0:关,1:开)
- if (infoDTO.getRemark2Status() != null && infoDTO.getRemark2Status() == 1){
- infoDTO.setRemark2Status(1);
- }else {
- infoDTO.setRemark2Status(0);
- }
- //220V3路输出开关状态(0:关,1:开)
- if (infoDTO.getRemark3Status() != null && infoDTO.getRemark3Status() == 1){
- infoDTO.setRemark3Status(1);
- }else {
- infoDTO.setRemark3Status(0);
- }
- //DC48V输出开关状态(0:关,1:开)
- if (infoDTO.getRemark4Status() != null && infoDTO.getRemark4Status() == 1){
- infoDTO.setRemark4Status(1);
- }else {
- infoDTO.setRemark4Status(0);
- }
- //DC24V1路输出开关状态(0:关,1:开)
- if (infoDTO.getRemark5Status() != null && infoDTO.getRemark5Status() == 1){
- infoDTO.setRemark5Status(1);
- }else {
- infoDTO.setRemark5Status(0);
- }
- //DC24V2路输出开关状态(0:关,1:开)
- if (infoDTO.getRemark6Status() != null && infoDTO.getRemark6Status() == 1){
- infoDTO.setRemark6Status(1);
- }else {
- infoDTO.setRemark6Status(0);
- }
- //DC12V输出开关状态(0:关,1:开)
- if (infoDTO.getRemark7Status() != null && infoDTO.getRemark7Status() == 1){
- infoDTO.setRemark7Status(1);
- }else {
- infoDTO.setRemark7Status(0);
- }
- if (infoDTO.getRemark1RunningStatus() != null){
- switch (infoDTO.getRemark1RunningStatus()){
- case 4 :
- infoDTO.setRemark1RunningStatus(4);
- break;
- case 3 :
- infoDTO.setRemark1RunningStatus(3);
- break;
- case 2 :
- infoDTO.setRemark1RunningStatus(2);
- break;
- case 1 :
- infoDTO.setRemark1RunningStatus(1);
- break;
- default:
- infoDTO.setRemark1RunningStatus(0);
- break;
- }
- }else {
- infoDTO.setRemark1RunningStatus(0);
- }
- if (infoDTO.getRemark2RunningStatus() != null){
- switch (infoDTO.getRemark2RunningStatus()){
- case 4 :
- infoDTO.setRemark2RunningStatus(4);
- break;
- case 3 :
- infoDTO.setRemark2RunningStatus(3);
- break;
- case 2 :
- infoDTO.setRemark2RunningStatus(2);
- break;
- case 1 :
- infoDTO.setRemark2RunningStatus(1);
- break;
- default:
- infoDTO.setRemark2RunningStatus(0);
- break;
- }
- }else {
- infoDTO.setRemark2RunningStatus(0);
- }
- if (infoDTO.getRemark3RunningStatus() != null){
- switch (infoDTO.getRemark3RunningStatus()){
- case 4 :
- infoDTO.setRemark3RunningStatus(4);
- break;
- case 3 :
- infoDTO.setRemark3RunningStatus(3);
- break;
- case 2 :
- infoDTO.setRemark3RunningStatus(2);
- break;
- case 1 :
- infoDTO.setRemark3RunningStatus(1);
- break;
- default:
- infoDTO.setRemark3RunningStatus(0);
- break;
- }
- }else {
- infoDTO.setRemark3RunningStatus(0);
- }
- if (infoDTO.getRemark4RunningStatus() != null){
- switch (infoDTO.getRemark4RunningStatus()){
- case 5 :
- infoDTO.setRemark4RunningStatus(5);
- break;
- case 4 :
- infoDTO.setRemark4RunningStatus(4);
- break;
- case 3 :
- infoDTO.setRemark4RunningStatus(3);
- break;
- case 2 :
- infoDTO.setRemark4RunningStatus(2);
- break;
- case 1 :
- infoDTO.setRemark4RunningStatus(1);
- break;
- default:
- infoDTO.setRemark4RunningStatus(0);
- break;
- }
- }else {
- infoDTO.setRemark4RunningStatus(0);
- }
- if (infoDTO.getRemark5RunningStatus() != null){
- switch (infoDTO.getRemark5RunningStatus()){
- case 5 :
- infoDTO.setRemark5RunningStatus(5);
- break;
- case 4 :
- infoDTO.setRemark5RunningStatus(4);
- break;
- case 3 :
- infoDTO.setRemark5RunningStatus(3);
- break;
- case 2 :
- infoDTO.setRemark5RunningStatus(2);
- break;
- case 1 :
- infoDTO.setRemark5RunningStatus(1);
- break;
- default:
- infoDTO.setRemark5RunningStatus(0);
- break;
- }
- }else {
- infoDTO.setRemark5RunningStatus(0);
- }
- if (infoDTO.getRemark6RunningStatus() != null){
- switch (infoDTO.getRemark6RunningStatus()){
- case 5 :
- infoDTO.setRemark6RunningStatus(5);
- break;
- case 4 :
- infoDTO.setRemark6RunningStatus(4);
- break;
- case 3 :
- infoDTO.setRemark6RunningStatus(3);
- break;
- case 2 :
- infoDTO.setRemark6RunningStatus(2);
- break;
- case 1 :
- infoDTO.setRemark6RunningStatus(1);
- break;
- default:
- infoDTO.setRemark6RunningStatus(0);
- break;
- }
- }else {
- infoDTO.setRemark6RunningStatus(0);
- }
- if (infoDTO.getRemark7RunningStatus() != null){
- switch (infoDTO.getRemark7RunningStatus()){
- case 5 :
- infoDTO.setRemark7RunningStatus(5);
- break;
- case 4 :
- infoDTO.setRemark7RunningStatus(4);
- break;
- case 3 :
- infoDTO.setRemark7RunningStatus(3);
- break;
- case 2 :
- infoDTO.setRemark7RunningStatus(2);
- break;
- case 1 :
- infoDTO.setRemark7RunningStatus(1);
- break;
- default:
- infoDTO.setRemark7RunningStatus(0);
- break;
- }
- }else {
- infoDTO.setRemark7RunningStatus(0);
- }
- if (infoDTO.getFaultInfo1() == null){
- infoDTO.setFaultInfo1("");
- }
- if (infoDTO.getFaultInfo2() == null){
- infoDTO.setFaultInfo2("");
- }
- //创建时间
- if (infoDTO.getCreateTime() != null && !infoDTO.getCreateTime().equals("")){
- try {
- infoDTO.setCreateTime(simpleDateFormat.format(simpleDateFormat.parse(infoDTO.getCreateTime())));
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- }else {
- infoDTO.setCreateTime("");
- }
- //安装时间
- if (infoDTO.getInstallDate() != null && !infoDTO.getInstallDate().equals("")){
- try {
- infoDTO.setInstallDate(simpleDateFormat.format(simpleDateFormat.parse(infoDTO.getInstallDate())));
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- }else {
- infoDTO.setInstallDate("");
- }
- //过期时间
- if (infoDTO.getExpirationDate() != null && !infoDTO.getExpirationDate().equals("")){
- try {
- infoDTO.setExpirationDate(simpleDateFormat.format(simpleDateFormat.parse(infoDTO.getExpirationDate())));
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- }else {
- infoDTO.setExpirationDate("");
- }
- //更新时间
- if (infoDTO.getUpdateTime() != null && !infoDTO.getUpdateTime().equals("")){
- Date cmdTime;
- try {
- cmdTime = simpleDateFormat.parse(infoDTO.getUpdateTime());
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- //判断时区,为null默认东八区
- long timezone = infoDTO.getTimezone() == null ? 8 : infoDTO.getTimezone();
- long l = cmdTime.getTime() + timezone * 3600 * 1000;
- cmdTime = new Date(l);
- infoDTO.setUpdateTime(simpleDateFormat.format(cmdTime));
- }else {
- infoDTO.setUpdateTime("");
- }
- list.add(infoDTO);
- });
- vo.setList(list);
- return vo;
- }
- @Override
- public SuperPowerDevInfoVO getPowerInfo(SuperPowerDevInfoDTO dto) {
- SuperPowerDevInfoVO vo = new SuperPowerDevInfoVO();
- //设备总数
- vo.setDevTotal(superPowerDevInfoDao.getTotalBySuperPowerDevInfoDTO(dto));
- //在线数
- vo.setOnlineCount(superPowerDevInfoDao.getOnlineTotalBySuperPowerDevInfoDTO(dto));
- //设备故障数
- vo.setFaultCount(superPowerDevInfoDao.getFaultTotalBySuperPowerDevInfoDTO(dto));
- //当天用电量
- List<SuperPowerDevInfoDTO> dayElectricByDTO = superPowerDevInfoDao.getDayElectricBySuperPowerDevInfoDTO(dto);
- Double dayElectric = dayElectricByDTO.stream().mapToDouble(infoDTO -> Float.parseFloat(infoDTO.getDayElectric())).sum();
- vo.setDayElectric(Float.parseFloat(String.format("%.2f",dayElectric)));
- //总用电量
- List<SuperPowerDevInfoDTO> totalElectricByDTO = superPowerDevInfoDao.getTotalElectricBySuperPowerDevInfoDTO(dto);
- Double totalElectric = totalElectricByDTO.stream().mapToDouble(infoDTO -> Float.parseFloat(infoDTO.getTotalElectric())).sum();
- vo.setTotalElectric(Float.parseFloat(String.format("%.2f",totalElectric)));
- return vo;
- }
- @Override
- public SuperPowerDevInfoVO getPowerOutInfoByDTO(SuperPowerDevInfoDTO dto) {
- SuperPowerDevInfoVO vo = new SuperPowerDevInfoVO();
- SuperPowerDevInfoDTO powerOutInfoDTO = superPowerDevInfoDao.getPowerOutInfoByDTO(dto);
- if (powerOutInfoDTO == null) return null;
- if (powerOutInfoDTO.getRemark1() != null){
- vo.setRemark1(powerOutInfoDTO.getRemark1());
- }else {
- vo.setRemark1("");
- }
- if (powerOutInfoDTO.getRemark2() != null){
- vo.setRemark2(powerOutInfoDTO.getRemark2());
- }else {
- vo.setRemark2("");
- }
- if (powerOutInfoDTO.getRemark3() != null){
- vo.setRemark3(powerOutInfoDTO.getRemark3());
- }else {
- vo.setRemark3("");
- }
- if (powerOutInfoDTO.getRemark4() != null){
- vo.setRemark4(powerOutInfoDTO.getRemark4());
- }else {
- vo.setRemark4("");
- }
- if (powerOutInfoDTO.getRemark5() != null){
- vo.setRemark5(powerOutInfoDTO.getRemark5());
- }else {
- vo.setRemark5("");
- }
- if (powerOutInfoDTO.getRemark6() != null){
- vo.setRemark6(powerOutInfoDTO.getRemark6());
- }else {
- vo.setRemark6("");
- }
- if (powerOutInfoDTO.getRemark7() != null){
- vo.setRemark7(powerOutInfoDTO.getRemark7());
- }else {
- vo.setRemark7("");
- }
- //220V1路输出开关状态(0:关,1:开)
- if (powerOutInfoDTO.getRemark1Status() != null && powerOutInfoDTO.getRemark1Status() == 1){
- vo.setRemark1Status(1);
- }else {
- vo.setRemark1Status(0);
- }
- //220V2路输出开关状态(0:关,1:开)
- if (powerOutInfoDTO.getRemark2Status() != null && powerOutInfoDTO.getRemark2Status() == 1){
- vo.setRemark2Status(1);
- }else {
- vo.setRemark2Status(0);
- }
- //220V3路输出开关状态(0:关,1:开)
- if (powerOutInfoDTO.getRemark3Status() != null && powerOutInfoDTO.getRemark3Status() == 1){
- vo.setRemark3Status(1);
- }else {
- vo.setRemark3Status(0);
- }
- //DC48V输出开关状态(0:关,1:开)
- if (powerOutInfoDTO.getRemark4Status() != null && powerOutInfoDTO.getRemark4Status() == 1){
- vo.setRemark4Status(1);
- }else {
- vo.setRemark4Status(0);
- }
- //DC24V1路输出开关状态(0:关,1:开)
- if (powerOutInfoDTO.getRemark5Status() != null && powerOutInfoDTO.getRemark5Status() == 1){
- vo.setRemark5Status(1);
- }else {
- vo.setRemark5Status(0);
- }
- //DC24V2路输出开关状态(0:关,1:开)
- if (powerOutInfoDTO.getRemark6Status() != null && powerOutInfoDTO.getRemark6Status() == 1){
- vo.setRemark6Status(1);
- }else {
- vo.setRemark6Status(0);
- }
- //DC12V输出开关状态(0:关,1:开)
- if (powerOutInfoDTO.getRemark7Status() != null && powerOutInfoDTO.getRemark7Status() == 1){
- vo.setRemark7Status(1);
- }else {
- vo.setRemark7Status(0);
- }
- if (powerOutInfoDTO.getType1() != null && powerOutInfoDTO.getType1() == 1){
- vo.setType1(1);
- }else {
- vo.setType1(0);
- }
- if (powerOutInfoDTO.getType2() != null && powerOutInfoDTO.getType2() == 1){
- vo.setType2(1);
- }else {
- vo.setType2(0);
- }
- if (powerOutInfoDTO.getType3() != null && powerOutInfoDTO.getType3() == 1){
- vo.setType3(1);
- }else {
- vo.setType3(0);
- }
- if (powerOutInfoDTO.getType4() != null && powerOutInfoDTO.getType4() == 1){
- vo.setType4(1);
- }else {
- vo.setType4(0);
- }
- if (powerOutInfoDTO.getType5() != null && powerOutInfoDTO.getType5() == 1){
- vo.setType5(1);
- }else {
- vo.setType5(0);
- }
- if (powerOutInfoDTO.getType6() != null && powerOutInfoDTO.getType6() == 1){
- vo.setType6(1);
- }else {
- vo.setType6(0);
- }
- if (powerOutInfoDTO.getType7() != null && powerOutInfoDTO.getType7() == 1){
- vo.setType7(1);
- }else {
- vo.setType7(0);
- }
- if (powerOutInfoDTO.getCloseTime1() != null){
- vo.setCloseTime1(powerOutInfoDTO.getCloseTime1());
- }else {
- vo.setCloseTime1("");
- }
- if (powerOutInfoDTO.getCloseTime2() != null){
- vo.setCloseTime2(powerOutInfoDTO.getCloseTime2());
- }else {
- vo.setCloseTime2("");
- }
- if (powerOutInfoDTO.getCloseTime3() != null){
- vo.setCloseTime3(powerOutInfoDTO.getCloseTime3());
- }else {
- vo.setCloseTime3("");
- }
- if (powerOutInfoDTO.getCloseTime4() != null){
- vo.setCloseTime4(powerOutInfoDTO.getCloseTime4());
- }else {
- vo.setCloseTime4("");
- }
- if (powerOutInfoDTO.getCloseTime5() != null){
- vo.setCloseTime5(powerOutInfoDTO.getCloseTime5());
- }else {
- vo.setCloseTime5("");
- }
- if (powerOutInfoDTO.getCloseTime6() != null){
- vo.setCloseTime6(powerOutInfoDTO.getCloseTime6());
- }else {
- vo.setCloseTime6("");
- }
- if (powerOutInfoDTO.getCloseTime7() != null){
- vo.setCloseTime7(powerOutInfoDTO.getCloseTime7());
- }else {
- vo.setCloseTime7("");
- }
- if (powerOutInfoDTO.getOpenTime1() != null){
- vo.setOpenTime1(powerOutInfoDTO.getOpenTime1());
- }else {
- vo.setOpenTime1("");
- }
- if (powerOutInfoDTO.getOpenTime2() != null){
- vo.setOpenTime2(powerOutInfoDTO.getOpenTime2());
- }else {
- vo.setOpenTime2("");
- }
- if (powerOutInfoDTO.getOpenTime3() != null){
- vo.setOpenTime3(powerOutInfoDTO.getOpenTime3());
- }else {
- vo.setOpenTime3("");
- }
- if (powerOutInfoDTO.getOpenTime4() != null){
- vo.setOpenTime4(powerOutInfoDTO.getOpenTime4());
- }else {
- vo.setOpenTime4("");
- }
- if (powerOutInfoDTO.getOpenTime5() != null){
- vo.setOpenTime5(powerOutInfoDTO.getOpenTime5());
- }else {
- vo.setOpenTime5("");
- }
- if (powerOutInfoDTO.getOpenTime6() != null){
- vo.setOpenTime6(powerOutInfoDTO.getOpenTime6());
- }else {
- vo.setOpenTime6("");
- }
- if (powerOutInfoDTO.getOpenTime7() != null){
- vo.setOpenTime7(powerOutInfoDTO.getOpenTime7());
- }else {
- vo.setOpenTime7("");
- }
- return vo;
- }
- }
|