SmartLockDevInfoServiceImpl.java 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.welampiot.service.impl;
  2. import com.welampiot.dao.SmartLockDevInfoDao;
  3. import com.welampiot.dto.SmartLockDevInfoDTO;
  4. import com.welampiot.service.SmartLockDevInfoService;
  5. import com.welampiot.vo.SmartLockDevInfoVO;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Service;
  8. import java.text.ParseException;
  9. import java.text.SimpleDateFormat;
  10. import java.util.ArrayList;
  11. import java.util.Date;
  12. import java.util.List;
  13. /**
  14. * ClassName: SmartLockDevInfoServiceImpl
  15. * Package: com.welampiot.service.impl
  16. * Description:
  17. *
  18. * @Author: zhj_Start
  19. * @Create: 2023/4/28 - 12:42
  20. * @Version: v1.0
  21. */
  22. @Service
  23. public class SmartLockDevInfoServiceImpl implements SmartLockDevInfoService {
  24. @Autowired
  25. private SmartLockDevInfoDao smartLockDevInfoDao;
  26. @Override
  27. public SmartLockDevInfoVO getListBySmartLockDevInfoDTO(SmartLockDevInfoDTO dto) {
  28. SmartLockDevInfoVO vo = new SmartLockDevInfoVO();
  29. vo.setTotal(smartLockDevInfoDao.getSmartLockTotalByDTO(dto));
  30. List<SmartLockDevInfoDTO> listDTO = smartLockDevInfoDao.getListBySmartLockDevInfoDTO(dto);
  31. List<SmartLockDevInfoDTO> list = new ArrayList<>();
  32. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  33. listDTO.forEach(devInfoDTO ->{
  34. if (devInfoDTO.getLampPoleName() == null){
  35. devInfoDTO.setLampPoleName("");
  36. }
  37. if (devInfoDTO.getArea() == null){
  38. devInfoDTO.setArea("");
  39. }
  40. if (devInfoDTO.getSection() == null){
  41. devInfoDTO.setSection("");
  42. }
  43. if (devInfoDTO.getModel() != null && devInfoDTO.getModel() == 2){
  44. devInfoDTO.setModel(2);
  45. }else if (devInfoDTO.getModel() != null && devInfoDTO.getModel() == 1){
  46. devInfoDTO.setModel(1);
  47. }else {
  48. devInfoDTO.setModel(0);
  49. }
  50. if (devInfoDTO.getOnline() != null && devInfoDTO.getOnline() == 1){
  51. devInfoDTO.setOnline(1);
  52. }else {
  53. devInfoDTO.setOnline(0);
  54. }
  55. if (devInfoDTO.getStatus() != null && devInfoDTO.getStatus() == 1){
  56. devInfoDTO.setStatus(1);
  57. }else {
  58. devInfoDTO.setStatus(0);
  59. }
  60. if (devInfoDTO.getCloudBoxModel() != null && devInfoDTO.getCloudBoxModel() == 3){
  61. devInfoDTO.setCloudBoxModel(3);
  62. }else if (devInfoDTO.getCloudBoxModel() != null && devInfoDTO.getCloudBoxModel() == 2){
  63. devInfoDTO.setCloudBoxModel(2);
  64. }else if (devInfoDTO.getCloudBoxModel() != null && devInfoDTO.getCloudBoxModel() == 1){
  65. devInfoDTO.setCloudBoxModel(1);
  66. }else {
  67. devInfoDTO.setCloudBoxModel(0);
  68. }
  69. if (devInfoDTO.getCreateTime() != null && !devInfoDTO.getCreateTime().equals("")){
  70. try {
  71. devInfoDTO.setCreateTime(simpleDateFormat.format(simpleDateFormat.parse(devInfoDTO.getCreateTime())));
  72. } catch (ParseException e) {
  73. throw new RuntimeException(e);
  74. }
  75. }else {
  76. devInfoDTO.setCreateTime("");
  77. }
  78. if (devInfoDTO.getInstallDate() != null && !devInfoDTO.getInstallDate().equals("")){
  79. try {
  80. devInfoDTO.setInstallDate(simpleDateFormat.format(simpleDateFormat.parse(devInfoDTO.getInstallDate())));
  81. } catch (ParseException e) {
  82. throw new RuntimeException(e);
  83. }
  84. }else {
  85. devInfoDTO.setInstallDate("");
  86. }
  87. if (devInfoDTO.getExpirationDate() != null && !devInfoDTO.getExpirationDate().equals("")){
  88. try {
  89. devInfoDTO.setExpirationDate(simpleDateFormat.format(simpleDateFormat.parse(devInfoDTO.getExpirationDate())));
  90. } catch (ParseException e) {
  91. throw new RuntimeException(e);
  92. }
  93. }else {
  94. devInfoDTO.setExpirationDate("");
  95. }
  96. if (devInfoDTO.getUpdateTime() != null && !devInfoDTO.getUpdateTime().equals("")){
  97. Date cmdTime;
  98. try {
  99. cmdTime = simpleDateFormat.parse(devInfoDTO.getUpdateTime());
  100. } catch (ParseException e) {
  101. throw new RuntimeException(e);
  102. }
  103. //判断时区,为null默认东八区
  104. long timezone = devInfoDTO.getTimezone() == null ? 8 : devInfoDTO.getTimezone();
  105. long l = cmdTime.getTime() + timezone * 3600 * 1000;
  106. cmdTime = new Date(l);
  107. devInfoDTO.setUpdateTime(simpleDateFormat.format(cmdTime));
  108. }else {
  109. devInfoDTO.setUpdateTime("");
  110. }
  111. list.add(devInfoDTO);
  112. });
  113. vo.setList(list);
  114. return vo;
  115. }
  116. }