AirSwitchInfoServiceImpl.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package com.welampiot.service.impl;
  2. import com.welampiot.dao.AirSwitchInfoDao;
  3. import com.welampiot.dto.AirSwitchInfoDTO;
  4. import com.welampiot.service.AirSwitchInfoService;
  5. import com.welampiot.vo.AirSwitchDetailVO;
  6. import com.welampiot.vo.AirSwitchInfoReturnVO;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import java.text.ParseException;
  10. import java.text.SimpleDateFormat;
  11. import java.util.ArrayList;
  12. import java.util.Date;
  13. import java.util.List;
  14. /**
  15. * ClassName: AirSwitchInfoServiceImpl
  16. * Package: com.welampiot.service.impl
  17. * Description:
  18. *
  19. * @Author: zhj_Start
  20. * @Create: 2023/3/28 - 21:27
  21. * @Version: v1.0
  22. */
  23. @Service
  24. public class AirSwitchInfoServiceImpl implements AirSwitchInfoService {
  25. @Autowired
  26. private AirSwitchInfoDao airSwitchInfoDao;
  27. @Override
  28. public AirSwitchInfoReturnVO getAirSwitchInfo(Integer boxId, Integer online) {
  29. AirSwitchInfoReturnVO airSwitchInfoReturnVO = new AirSwitchInfoReturnVO();
  30. airSwitchInfoReturnVO.setTotalDev(airSwitchInfoDao.getCountByBoxId(boxId));
  31. airSwitchInfoReturnVO.setOneDev(airSwitchInfoDao.getCountByBoxIdAndType(boxId,0));
  32. airSwitchInfoReturnVO.setThreeDev(airSwitchInfoDao.getCountByBoxIdAndType(boxId,1));
  33. airSwitchInfoReturnVO.setAlarmCount(airSwitchInfoDao.getCountByBoxIdAndAlarmStatus(boxId));
  34. airSwitchInfoReturnVO.setPolicyId(airSwitchInfoDao.getPolicyIdByBoxId(boxId));
  35. if (airSwitchInfoReturnVO.getPolicyId() != null && airSwitchInfoReturnVO.getPolicyId() != 0){
  36. airSwitchInfoReturnVO.setPolicyName(airSwitchInfoDao.getPolicyNameByPolicyId(airSwitchInfoReturnVO.getPolicyId()));
  37. }else {
  38. airSwitchInfoReturnVO.setPolicyName("");
  39. }
  40. List<AirSwitchInfoDTO> airSwitchList = airSwitchInfoDao.getAirSwitchInfoByBoxId(boxId, online);
  41. List<AirSwitchInfoDTO> airSwitchInfoDTOS = new ArrayList<>();
  42. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  43. airSwitchList.forEach(airSwitchInfoDTO -> {
  44. if (airSwitchInfoDTO.getPolicyId() == null || airSwitchInfoDTO.getPolicyId() == 0){
  45. airSwitchInfoDTO.setPolicyName("");
  46. }
  47. if (airSwitchInfoDTO.getLogTime() != null){
  48. Date cmdTime;
  49. try {
  50. cmdTime = simpleDateFormat.parse(airSwitchInfoDTO.getLogTime());
  51. } catch (ParseException e) {
  52. throw new RuntimeException(e);
  53. }
  54. //判断时区,为null默认东八区
  55. long timezone = airSwitchInfoDTO.getTimezone() == null ? 8 : airSwitchInfoDTO.getTimezone();
  56. long l = cmdTime.getTime() + timezone * 3600 * 1000;
  57. cmdTime = new Date(l);
  58. airSwitchInfoDTO.setLogTime(simpleDateFormat.format(cmdTime));
  59. }else {
  60. airSwitchInfoDTO.setLogTime("");
  61. }
  62. if (airSwitchInfoDTO.getStatus() != null && airSwitchInfoDTO.getStatus() == 1){
  63. airSwitchInfoDTO.setStatus(1);
  64. }else {
  65. airSwitchInfoDTO.setStatus(0);
  66. }
  67. if (airSwitchInfoDTO.getType() != null && airSwitchInfoDTO.getType() == 1) {
  68. airSwitchInfoDTO.setType(1);
  69. }else {
  70. airSwitchInfoDTO.setType(0);
  71. }
  72. airSwitchInfoDTOS.add(airSwitchInfoDTO);
  73. });
  74. airSwitchInfoReturnVO.setList(airSwitchInfoDTOS);
  75. return airSwitchInfoReturnVO;
  76. }
  77. @Override
  78. public AirSwitchDetailVO getAirSwitchDetail(Integer id) {
  79. AirSwitchDetailVO airSwitchDetailVO = new AirSwitchDetailVO();
  80. AirSwitchInfoDTO airSwitchInfoDTO = airSwitchInfoDao.getAirSwitchDetailById(id);
  81. airSwitchDetailVO.setName(airSwitchInfoDTO.getName());
  82. airSwitchDetailVO.setAddress(airSwitchInfoDTO.getAddress());
  83. airSwitchDetailVO.setBoxId(airSwitchInfoDTO.getBoxId().toString());
  84. if (airSwitchInfoDTO.getType() != null && airSwitchInfoDTO.getType() == 1){
  85. airSwitchInfoDTO.setType(1);
  86. airSwitchDetailVO.setType(airSwitchInfoDTO.getType().toString());
  87. }else {
  88. airSwitchInfoDTO.setType(0);
  89. airSwitchDetailVO.setType(airSwitchInfoDTO.getType().toString());
  90. }
  91. return airSwitchDetailVO;
  92. }
  93. }