package com.welampiot.service.impl; import com.welampiot.dao.ManholeDao; import com.welampiot.dto.ManholeDTO; import com.welampiot.service.ManholeService; import com.welampiot.vo.ManholeVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * ClassName: ManholeServiceImpl * Package: com.welampiot.service.impl * Description: * * @Author: zhj_Start * @Create: 2023/4/10 - 10:55 * @Version: v1.0 */ @Service public class ManholeServiceImpl implements ManholeService { @Autowired private ManholeDao manholeDao; @Override public ManholeVO getDevTotalBySectionList(List sectionList) { ManholeVO vo = new ManholeVO(); vo.setTotal(manholeDao.getTotalBySectionList(sectionList)); vo.setOnlineCount(manholeDao.getOnlineTotalBySectionList(sectionList)); vo.setAlarmCount(manholeDao.getAlarmTotalBySectionList(sectionList)); vo.setNormalCount(manholeDao.getNormalTotalBySectionList(sectionList)); List newTotalList = manholeDao.getNewTotalBySectionList(sectionList); List totalList = new ArrayList<>(); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); LocalDateTime startTime = LocalDate.now().atTime(0, 0, 0); LocalDateTime endTime = LocalDate.now().atTime(23, 59, 59); newTotalList.forEach(manholeDTO -> { if (manholeDTO.getCreateTime() != null && !manholeDTO.getCreateTime().equals("")){ LocalDateTime localDateTime = LocalDateTime.parse(manholeDTO.getCreateTime(), dtf); if (localDateTime.isAfter(startTime) && localDateTime.isBefore(endTime)){ totalList.add(manholeDTO); } } }); int size = totalList.size(); vo.setNewCount(size); return vo; } @Override public ManholeVO getListByDTO(ManholeDTO dto, Integer version) { ManholeVO vo = new ManholeVO(); List listByDTO = manholeDao.getListByDTO(dto); List list = new ArrayList<>(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (listByDTO != null && !listByDTO.isEmpty()){ listByDTO.forEach(manholeDTO ->{ if (manholeDTO.getId() != null) { if (manholeDTO.getOnline() != null && manholeDTO.getOnline() == 1){ manholeDTO.setOnline(1); }else { manholeDTO.setOnline(0); } if (manholeDTO.getAlarmStatus() != null && manholeDTO.getAlarmStatus() == 1){ manholeDTO.setAlarmStatus(1); }else { manholeDTO.setAirAlarm(0); } if (manholeDTO.getAlarmInfo() == null && manholeDTO.getAlarmStatus() == 0){ manholeDTO.setAlarmInfo(""); } //获取设备更新时间 if (manholeDTO.getUpdateTime() != null && !manholeDTO.getUpdateTime().equals("")){ Date cmdTime; try { cmdTime = simpleDateFormat.parse(manholeDTO.getUpdateTime()); } catch (ParseException e) { throw new RuntimeException(e); } //判断时区,为null默认东八区 long timezone = manholeDTO.getTimezone() == null ? 8 : manholeDTO.getTimezone(); long l = cmdTime.getTime() + timezone * 3600 * 1000; cmdTime = new Date(l); manholeDTO.setUpdateTime(simpleDateFormat.format(cmdTime)); }else { manholeDTO.setUpdateTime(""); } //获取设备创建时间 if (manholeDTO.getCreateTime() == null && !manholeDTO.getCreateTime().equals("")){ manholeDTO.setCreateTime(""); }else { try { manholeDTO.setCreateTime(simpleDateFormat.format(simpleDateFormat.parse(manholeDTO.getCreateTime()))); } catch (ParseException e) { throw new RuntimeException(e); } } //获取设备安装时间 if (manholeDTO.getInstallDate() != null && !manholeDTO.getInstallDate().equals("")){ try { manholeDTO.setInstallDate(simpleDateFormat.format(simpleDateFormat.parse(manholeDTO.getInstallDate()))); } catch (ParseException e) { throw new RuntimeException(e); } }else { manholeDTO.setInstallDate(""); } //获取设备过期时间 if (manholeDTO.getExpirationDate() != null && !manholeDTO.getExpirationDate().equals("")){ try { manholeDTO.setExpirationDate(simpleDateFormat.format(simpleDateFormat.parse(manholeDTO.getExpirationDate()))); } catch (ParseException e) { throw new RuntimeException(e); } }else { manholeDTO.setExpirationDate(""); } //获取设备位置信息 if (version == 0){ if (manholeDTO.getChCity() != null && !manholeDTO.getChCity().equals("")){ manholeDTO.setCity(manholeDTO.getChCity()); }else { manholeDTO.setCity(""); } if (manholeDTO.getChArea() != null && !manholeDTO.getChArea().equals("")){ manholeDTO.setArea(manholeDTO.getChArea()); }else { manholeDTO.setArea(""); } if (manholeDTO.getSection() == null){ manholeDTO.setSection(""); } manholeDTO.setLocation(manholeDTO.getCity() + " " + manholeDTO.getArea() + " " + manholeDTO.getSection()); }else if (version == 1){ if (manholeDTO.getEnCity() != null && !manholeDTO.getEnCity().equals("")){ manholeDTO.setCity(manholeDTO.getEnCity()); }else { manholeDTO.setCity(""); } if (manholeDTO.getEnArea() != null && !manholeDTO.getEnArea().equals("")){ manholeDTO.setArea(manholeDTO.getEnArea()); }else { manholeDTO.setArea(""); } if (manholeDTO.getSection() == null){ manholeDTO.setSection(""); } manholeDTO.setLocation(manholeDTO.getCity() + " " + manholeDTO.getArea() + " " + manholeDTO.getSection()); }else { if (manholeDTO.getRuCity() != null && !manholeDTO.getRuCity().equals("")){ manholeDTO.setCity(manholeDTO.getRuCity()); }else { manholeDTO.setCity(""); } if (manholeDTO.getRuArea() != null && !manholeDTO.getRuArea().equals("")){ manholeDTO.setArea(manholeDTO.getRuArea()); }else { manholeDTO.setArea(""); } if (manholeDTO.getSection() == null){ manholeDTO.setSection(""); } manholeDTO.setLocation(manholeDTO.getCity() + " " + manholeDTO.getArea() + " " + manholeDTO.getSection()); } manholeDTO.setTotal(manholeDao.getTotalBySectionList(dto.getSectionList())); list.add(manholeDTO); } }); vo.setList(list); return vo; }else { return null; } } @Override public ManholeVO getHistoryListByDTO(ManholeDTO dto) { ManholeVO vo = new ManholeVO(); List historyList = manholeDao.getHistoryListByDTO(dto); List list = new ArrayList<>(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); historyList.forEach(manholeDTO ->{ if (manholeDTO.getAlarmStatus() != null && manholeDTO.getAlarmStatus() == 1){ manholeDTO.setAlarmStatus(1); }else { manholeDTO.setAlarmStatus(0); } if (manholeDTO.getAlarmInfo() == null && manholeDTO.getAlarmStatus() == 0){ manholeDTO.setAlarmInfo(""); } //获取设备更新时间 if (manholeDTO.getUpdateTime() != null && !manholeDTO.getUpdateTime().equals("")){ Date cmdTime; try { cmdTime = simpleDateFormat.parse(manholeDTO.getUpdateTime()); } catch (ParseException e) { throw new RuntimeException(e); } //判断时区,为null默认东八区 long timezone = manholeDTO.getTimezone() == null ? 8 : manholeDTO.getTimezone(); long l = cmdTime.getTime() + timezone * 3600 * 1000; cmdTime = new Date(l); manholeDTO.setUpdateTime(simpleDateFormat.format(cmdTime)); }else { manholeDTO.setUpdateTime(""); } if (manholeDTO.getStatus() != null && manholeDTO.getStatus() == 1){ manholeDTO.setStatus(1); }else { manholeDTO.setStatus(0); } manholeDTO.setTotal(manholeDao.getTotalBySectionList(dto.getSectionList())); list.add(manholeDTO); }); vo.setList(list); return vo; } }