ManholeServiceImpl.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. package com.welampiot.service.impl;
  2. import com.welampiot.dao.ManholeDao;
  3. import com.welampiot.dto.ManholeDTO;
  4. import com.welampiot.service.ManholeService;
  5. import com.welampiot.vo.ManholeVO;
  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.time.LocalDate;
  11. import java.time.LocalDateTime;
  12. import java.time.format.DateTimeFormatter;
  13. import java.util.ArrayList;
  14. import java.util.Date;
  15. import java.util.List;
  16. /**
  17. * ClassName: ManholeServiceImpl
  18. * Package: com.welampiot.service.impl
  19. * Description:
  20. *
  21. * @Author: zhj_Start
  22. * @Create: 2023/4/10 - 10:55
  23. * @Version: v1.0
  24. */
  25. @Service
  26. public class ManholeServiceImpl implements ManholeService {
  27. @Autowired
  28. private ManholeDao manholeDao;
  29. @Override
  30. public ManholeVO getDevTotalBySectionList(List<ManholeDTO> sectionList) {
  31. ManholeVO vo = new ManholeVO();
  32. vo.setTotal(manholeDao.getTotalBySectionList(sectionList));
  33. vo.setOnlineCount(manholeDao.getOnlineTotalBySectionList(sectionList));
  34. vo.setAlarmCount(manholeDao.getAlarmTotalBySectionList(sectionList));
  35. vo.setNormalCount(manholeDao.getNormalTotalBySectionList(sectionList));
  36. List<ManholeDTO> newTotalList = manholeDao.getNewTotalBySectionList(sectionList);
  37. List<ManholeDTO> totalList = new ArrayList<>();
  38. DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  39. LocalDateTime startTime = LocalDate.now().atTime(0, 0, 0);
  40. LocalDateTime endTime = LocalDate.now().atTime(23, 59, 59);
  41. newTotalList.forEach(manholeDTO -> {
  42. if (manholeDTO.getCreateTime() != null && !manholeDTO.getCreateTime().equals("")){
  43. LocalDateTime localDateTime = LocalDateTime.parse(manholeDTO.getCreateTime(), dtf);
  44. if (localDateTime.isAfter(startTime) && localDateTime.isBefore(endTime)){
  45. totalList.add(manholeDTO);
  46. }
  47. }
  48. });
  49. int size = totalList.size();
  50. vo.setNewCount(size);
  51. return vo;
  52. }
  53. @Override
  54. public ManholeVO getListByDTO(ManholeDTO dto, Integer version) {
  55. ManholeVO vo = new ManholeVO();
  56. List<ManholeDTO> listByDTO = manholeDao.getListByDTO(dto);
  57. List<ManholeDTO> list = new ArrayList<>();
  58. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  59. if (listByDTO != null && !listByDTO.isEmpty()){
  60. listByDTO.forEach(manholeDTO ->{
  61. if (manholeDTO.getId() != null) {
  62. if (manholeDTO.getOnline() != null && manholeDTO.getOnline() == 1){
  63. manholeDTO.setOnline(1);
  64. }else {
  65. manholeDTO.setOnline(0);
  66. }
  67. if (manholeDTO.getAlarmStatus() != null && manholeDTO.getAlarmStatus() == 1){
  68. manholeDTO.setAlarmStatus(1);
  69. }else {
  70. manholeDTO.setAirAlarm(0);
  71. }
  72. if (manholeDTO.getAlarmInfo() == null && manholeDTO.getAlarmStatus() == 0){
  73. manholeDTO.setAlarmInfo("");
  74. }
  75. //获取设备更新时间
  76. if (manholeDTO.getUpdateTime() != null && !manholeDTO.getUpdateTime().equals("")){
  77. Date cmdTime;
  78. try {
  79. cmdTime = simpleDateFormat.parse(manholeDTO.getUpdateTime());
  80. } catch (ParseException e) {
  81. throw new RuntimeException(e);
  82. }
  83. //判断时区,为null默认东八区
  84. long timezone = manholeDTO.getTimezone() == null ? 8 : manholeDTO.getTimezone();
  85. long l = cmdTime.getTime() + timezone * 3600 * 1000;
  86. cmdTime = new Date(l);
  87. manholeDTO.setUpdateTime(simpleDateFormat.format(cmdTime));
  88. }else {
  89. manholeDTO.setUpdateTime("");
  90. }
  91. //获取设备创建时间
  92. if (manholeDTO.getCreateTime() == null && !manholeDTO.getCreateTime().equals("")){
  93. manholeDTO.setCreateTime("");
  94. }else {
  95. try {
  96. manholeDTO.setCreateTime(simpleDateFormat.format(simpleDateFormat.parse(manholeDTO.getCreateTime())));
  97. } catch (ParseException e) {
  98. throw new RuntimeException(e);
  99. }
  100. }
  101. //获取设备安装时间
  102. if (manholeDTO.getInstallDate() != null && !manholeDTO.getInstallDate().equals("")){
  103. try {
  104. manholeDTO.setInstallDate(simpleDateFormat.format(simpleDateFormat.parse(manholeDTO.getInstallDate())));
  105. } catch (ParseException e) {
  106. throw new RuntimeException(e);
  107. }
  108. }else {
  109. manholeDTO.setInstallDate("");
  110. }
  111. //获取设备过期时间
  112. if (manholeDTO.getExpirationDate() != null && !manholeDTO.getExpirationDate().equals("")){
  113. try {
  114. manholeDTO.setExpirationDate(simpleDateFormat.format(simpleDateFormat.parse(manholeDTO.getExpirationDate())));
  115. } catch (ParseException e) {
  116. throw new RuntimeException(e);
  117. }
  118. }else {
  119. manholeDTO.setExpirationDate("");
  120. }
  121. //获取设备位置信息
  122. if (version == 0){
  123. if (manholeDTO.getChCity() != null && !manholeDTO.getChCity().equals("")){
  124. manholeDTO.setCity(manholeDTO.getChCity());
  125. }else {
  126. manholeDTO.setCity("");
  127. }
  128. if (manholeDTO.getChArea() != null && !manholeDTO.getChArea().equals("")){
  129. manholeDTO.setArea(manholeDTO.getChArea());
  130. }else {
  131. manholeDTO.setArea("");
  132. }
  133. if (manholeDTO.getSection() == null){
  134. manholeDTO.setSection("");
  135. }
  136. manholeDTO.setLocation(manholeDTO.getCity() + " " + manholeDTO.getArea() + " " + manholeDTO.getSection());
  137. }else if (version == 1){
  138. if (manholeDTO.getEnCity() != null && !manholeDTO.getEnCity().equals("")){
  139. manholeDTO.setCity(manholeDTO.getEnCity());
  140. }else {
  141. manholeDTO.setCity("");
  142. }
  143. if (manholeDTO.getEnArea() != null && !manholeDTO.getEnArea().equals("")){
  144. manholeDTO.setArea(manholeDTO.getEnArea());
  145. }else {
  146. manholeDTO.setArea("");
  147. }
  148. if (manholeDTO.getSection() == null){
  149. manholeDTO.setSection("");
  150. }
  151. manholeDTO.setLocation(manholeDTO.getCity() + " " + manholeDTO.getArea() + " " + manholeDTO.getSection());
  152. }else {
  153. if (manholeDTO.getRuCity() != null && !manholeDTO.getRuCity().equals("")){
  154. manholeDTO.setCity(manholeDTO.getRuCity());
  155. }else {
  156. manholeDTO.setCity("");
  157. }
  158. if (manholeDTO.getRuArea() != null && !manholeDTO.getRuArea().equals("")){
  159. manholeDTO.setArea(manholeDTO.getRuArea());
  160. }else {
  161. manholeDTO.setArea("");
  162. }
  163. if (manholeDTO.getSection() == null){
  164. manholeDTO.setSection("");
  165. }
  166. manholeDTO.setLocation(manholeDTO.getCity() + " " + manholeDTO.getArea() + " " + manholeDTO.getSection());
  167. }
  168. manholeDTO.setTotal(manholeDao.getTotalBySectionList(dto.getSectionList()));
  169. list.add(manholeDTO);
  170. }
  171. });
  172. vo.setList(list);
  173. return vo;
  174. }else {
  175. return null;
  176. }
  177. }
  178. @Override
  179. public ManholeVO getHistoryListByDTO(ManholeDTO dto) {
  180. ManholeVO vo = new ManholeVO();
  181. List<ManholeDTO> historyList = manholeDao.getHistoryListByDTO(dto);
  182. List<ManholeDTO> list = new ArrayList<>();
  183. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  184. historyList.forEach(manholeDTO ->{
  185. if (manholeDTO.getAlarmStatus() != null && manholeDTO.getAlarmStatus() == 1){
  186. manholeDTO.setAlarmStatus(1);
  187. }else {
  188. manholeDTO.setAlarmStatus(0);
  189. }
  190. if (manholeDTO.getAlarmInfo() == null && manholeDTO.getAlarmStatus() == 0){
  191. manholeDTO.setAlarmInfo("");
  192. }
  193. //获取设备更新时间
  194. if (manholeDTO.getUpdateTime() != null && !manholeDTO.getUpdateTime().equals("")){
  195. Date cmdTime;
  196. try {
  197. cmdTime = simpleDateFormat.parse(manholeDTO.getUpdateTime());
  198. } catch (ParseException e) {
  199. throw new RuntimeException(e);
  200. }
  201. //判断时区,为null默认东八区
  202. long timezone = manholeDTO.getTimezone() == null ? 8 : manholeDTO.getTimezone();
  203. long l = cmdTime.getTime() + timezone * 3600 * 1000;
  204. cmdTime = new Date(l);
  205. manholeDTO.setUpdateTime(simpleDateFormat.format(cmdTime));
  206. }else {
  207. manholeDTO.setUpdateTime("");
  208. }
  209. if (manholeDTO.getStatus() != null && manholeDTO.getStatus() == 1){
  210. manholeDTO.setStatus(1);
  211. }else {
  212. manholeDTO.setStatus(0);
  213. }
  214. manholeDTO.setTotal(manholeDao.getTotalBySectionList(dto.getSectionList()));
  215. list.add(manholeDTO);
  216. });
  217. vo.setList(list);
  218. return vo;
  219. }
  220. }