123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296 |
- 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.HashMap;
- 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<ManholeDTO> 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<ManholeDTO> newTotalList = manholeDao.getNewTotalBySectionList(sectionList);
- List<ManholeDTO> 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();
- vo.setTotal(manholeDao.getTotalBySectionList(dto.getSectionList()));
- List<ManholeDTO> listByDTO = manholeDao.getListByDTO(dto);
- List<ManholeDTO> 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("")){
- try {
- manholeDTO.setCreateTime(simpleDateFormat.format(simpleDateFormat.parse(manholeDTO.getCreateTime())));
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- }else {
- manholeDTO.setCreateTime("");
- }
- //获取设备安装时间
- 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());
- }
- list.add(manholeDTO);
- }
- });
- vo.setList(list);
- }
- return vo;
- }
- @Override
- public ManholeVO getHistoryListByDTO(ManholeDTO dto) {
- ManholeVO vo = new ManholeVO();
- List<ManholeDTO> historyList = manholeDao.getHistoryListByDTO(dto);
- List<ManholeDTO> 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;
- }
- @Override
- public void addManholeDataByDTO(ManholeDTO dto) {
- manholeDao.addManholeDataByDTO(dto);
- }
- @Override
- public void updateManholeDataByDTO(ManholeDTO dto) {
- manholeDao.updateManholeDataByDTO(dto);
- }
- @Override
- public Integer findByManholeDTO(ManholeDTO dto) {
- return manholeDao.findByManholeDTO(dto);
- }
- @Override
- public void deleteManholeDataById(Integer id) {
- this.deleteManholeLogDataById(id);
- manholeDao.deleteManholeDataById(id);
- }
- @Override
- public void deleteManholeLogDataById(Integer id) {
- manholeDao.deleteManholeLogDataById(id);
- }
- @Override
- public void changeManholeLocationById(ManholeDTO dto) {
- manholeDao.changeManholeLocationById(dto);
- }
- @Override
- public ManholeDTO getManholeDTOById(Integer id) {
- return manholeDao.getManholeDTOById(id);
- }
- @Override
- public ManholeDTO getTiltManholeByLampPoleId(Integer lampPoleId) {
- ManholeDTO dto = manholeDao.getTiltManholeByLampPoleId(lampPoleId);
- String alarmStr1,alarmStr2,alarmStr3,alarmStr4;
- if (dto.getOpenAlarm() == 1) {
- alarmStr1 = "打开告警,";
- } else {
- alarmStr1 = "打开恢复,";
- }
- if (dto.getOverAlarm() == 1) {
- alarmStr2 = "满溢告警,";
- } else {
- alarmStr2 = "满溢恢复,";
- }
- if (dto.getAirAlarm() == 1) {
- alarmStr3 = "气体警告,";
- } else {
- alarmStr3 = "气体恢复,";
- }
- if (dto.getDisManAlarm() == 1) {
- alarmStr4 = "拆除警告";
- } else {
- alarmStr4 = "拆除恢复";
- }
- String alarmInfo = alarmStr1 + alarmStr2 + alarmStr3 + alarmStr4;
- dto.setAlarmInfo(alarmInfo);
- return dto;
- }
- @Override
- public ManholeDTO getOneManhole(HashMap<String,Object> map){
- return manholeDao.getOneManhole(map);
- }
- }
|