ManholeServiceImpl.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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.HashMap;
  16. import java.util.List;
  17. /**
  18. * ClassName: ManholeServiceImpl
  19. * Package: com.welampiot.service.impl
  20. * Description:
  21. *
  22. * @Author: zhj_Start
  23. * @Create: 2023/4/10 - 10:55
  24. * @Version: v1.0
  25. */
  26. @Service
  27. public class ManholeServiceImpl implements ManholeService {
  28. @Autowired
  29. private ManholeDao manholeDao;
  30. @Override
  31. public ManholeVO getDevTotalBySectionList(List<ManholeDTO> sectionList) {
  32. ManholeVO vo = new ManholeVO();
  33. vo.setTotal(manholeDao.getTotalBySectionList(sectionList));
  34. vo.setOnlineCount(manholeDao.getOnlineTotalBySectionList(sectionList));
  35. vo.setAlarmCount(manholeDao.getAlarmTotalBySectionList(sectionList));
  36. vo.setNormalCount(manholeDao.getNormalTotalBySectionList(sectionList));
  37. List<ManholeDTO> newTotalList = manholeDao.getNewTotalBySectionList(sectionList);
  38. List<ManholeDTO> totalList = new ArrayList<>();
  39. DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  40. LocalDateTime startTime = LocalDate.now().atTime(0, 0, 0);
  41. LocalDateTime endTime = LocalDate.now().atTime(23, 59, 59);
  42. newTotalList.forEach(manholeDTO -> {
  43. if (manholeDTO.getCreateTime() != null && !manholeDTO.getCreateTime().equals("")){
  44. LocalDateTime localDateTime = LocalDateTime.parse(manholeDTO.getCreateTime(), dtf);
  45. if (localDateTime.isAfter(startTime) && localDateTime.isBefore(endTime)){
  46. totalList.add(manholeDTO);
  47. }
  48. }
  49. });
  50. int size = totalList.size();
  51. vo.setNewCount(size);
  52. return vo;
  53. }
  54. @Override
  55. public ManholeVO getListByDTO(ManholeDTO dto, Integer version) {
  56. ManholeVO vo = new ManholeVO();
  57. vo.setTotal(manholeDao.getTotalBySectionList(dto.getSectionList()));
  58. List<ManholeDTO> listByDTO = manholeDao.getListByDTO(dto);
  59. List<ManholeDTO> list = new ArrayList<>();
  60. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  61. if (listByDTO != null && !listByDTO.isEmpty()){
  62. listByDTO.forEach(manholeDTO ->{
  63. if (manholeDTO.getId() != null) {
  64. if (manholeDTO.getOnline() != null && manholeDTO.getOnline() == 1){
  65. manholeDTO.setOnline(1);
  66. }else {
  67. manholeDTO.setOnline(0);
  68. }
  69. if (manholeDTO.getAlarmStatus() != null && manholeDTO.getAlarmStatus() == 1){
  70. manholeDTO.setAlarmStatus(1);
  71. }else {
  72. manholeDTO.setAirAlarm(0);
  73. }
  74. if (manholeDTO.getAlarmInfo() == null && manholeDTO.getAlarmStatus() == 0){
  75. manholeDTO.setAlarmInfo("");
  76. }
  77. //获取设备更新时间
  78. if (manholeDTO.getUpdateTime() != null && !manholeDTO.getUpdateTime().equals("")){
  79. Date cmdTime;
  80. try {
  81. cmdTime = simpleDateFormat.parse(manholeDTO.getUpdateTime());
  82. } catch (ParseException e) {
  83. throw new RuntimeException(e);
  84. }
  85. //判断时区,为null默认东八区
  86. long timezone = manholeDTO.getTimezone() == null ? 8 : manholeDTO.getTimezone();
  87. long l = cmdTime.getTime() + timezone * 3600 * 1000;
  88. cmdTime = new Date(l);
  89. manholeDTO.setUpdateTime(simpleDateFormat.format(cmdTime));
  90. }else {
  91. manholeDTO.setUpdateTime("");
  92. }
  93. //获取设备创建时间
  94. if (manholeDTO.getCreateTime() != null && !manholeDTO.getCreateTime().equals("")){
  95. try {
  96. manholeDTO.setCreateTime(simpleDateFormat.format(simpleDateFormat.parse(manholeDTO.getCreateTime())));
  97. } catch (ParseException e) {
  98. throw new RuntimeException(e);
  99. }
  100. }else {
  101. manholeDTO.setCreateTime("");
  102. }
  103. //获取设备安装时间
  104. if (manholeDTO.getInstallDate() != null && !manholeDTO.getInstallDate().equals("")){
  105. try {
  106. manholeDTO.setInstallDate(simpleDateFormat.format(simpleDateFormat.parse(manholeDTO.getInstallDate())));
  107. } catch (ParseException e) {
  108. throw new RuntimeException(e);
  109. }
  110. }else {
  111. manholeDTO.setInstallDate("");
  112. }
  113. //获取设备过期时间
  114. if (manholeDTO.getExpirationDate() != null && !manholeDTO.getExpirationDate().equals("")){
  115. try {
  116. manholeDTO.setExpirationDate(simpleDateFormat.format(simpleDateFormat.parse(manholeDTO.getExpirationDate())));
  117. } catch (ParseException e) {
  118. throw new RuntimeException(e);
  119. }
  120. }else {
  121. manholeDTO.setExpirationDate("");
  122. }
  123. //获取设备位置信息
  124. if (version == 0){
  125. if (manholeDTO.getChCity() != null && !manholeDTO.getChCity().equals("")){
  126. manholeDTO.setCity(manholeDTO.getChCity());
  127. }else {
  128. manholeDTO.setCity("");
  129. }
  130. if (manholeDTO.getChArea() != null && !manholeDTO.getChArea().equals("")){
  131. manholeDTO.setArea(manholeDTO.getChArea());
  132. }else {
  133. manholeDTO.setArea("");
  134. }
  135. if (manholeDTO.getSection() == null){
  136. manholeDTO.setSection("");
  137. }
  138. manholeDTO.setLocation(manholeDTO.getCity() + " " + manholeDTO.getArea() + " " + manholeDTO.getSection());
  139. }else if (version == 1){
  140. if (manholeDTO.getEnCity() != null && !manholeDTO.getEnCity().equals("")){
  141. manholeDTO.setCity(manholeDTO.getEnCity());
  142. }else {
  143. manholeDTO.setCity("");
  144. }
  145. if (manholeDTO.getEnArea() != null && !manholeDTO.getEnArea().equals("")){
  146. manholeDTO.setArea(manholeDTO.getEnArea());
  147. }else {
  148. manholeDTO.setArea("");
  149. }
  150. if (manholeDTO.getSection() == null){
  151. manholeDTO.setSection("");
  152. }
  153. manholeDTO.setLocation(manholeDTO.getCity() + " " + manholeDTO.getArea() + " " + manholeDTO.getSection());
  154. }else {
  155. if (manholeDTO.getRuCity() != null && !manholeDTO.getRuCity().equals("")){
  156. manholeDTO.setCity(manholeDTO.getRuCity());
  157. }else {
  158. manholeDTO.setCity("");
  159. }
  160. if (manholeDTO.getRuArea() != null && !manholeDTO.getRuArea().equals("")){
  161. manholeDTO.setArea(manholeDTO.getRuArea());
  162. }else {
  163. manholeDTO.setArea("");
  164. }
  165. if (manholeDTO.getSection() == null){
  166. manholeDTO.setSection("");
  167. }
  168. manholeDTO.setLocation(manholeDTO.getCity() + " " + manholeDTO.getArea() + " " + manholeDTO.getSection());
  169. }
  170. list.add(manholeDTO);
  171. }
  172. });
  173. vo.setList(list);
  174. }
  175. return vo;
  176. }
  177. @Override
  178. public ManholeVO getHistoryListByDTO(ManholeDTO dto) {
  179. ManholeVO vo = new ManholeVO();
  180. List<ManholeDTO> historyList = manholeDao.getHistoryListByDTO(dto);
  181. List<ManholeDTO> list = new ArrayList<>();
  182. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  183. historyList.forEach(manholeDTO ->{
  184. if (manholeDTO.getAlarmStatus() != null && manholeDTO.getAlarmStatus() == 1){
  185. manholeDTO.setAlarmStatus(1);
  186. }else {
  187. manholeDTO.setAlarmStatus(0);
  188. }
  189. if (manholeDTO.getAlarmInfo() == null && manholeDTO.getAlarmStatus() == 0){
  190. manholeDTO.setAlarmInfo("");
  191. }
  192. //获取设备更新时间
  193. if (manholeDTO.getUpdateTime() != null && !manholeDTO.getUpdateTime().equals("")){
  194. Date cmdTime;
  195. try {
  196. cmdTime = simpleDateFormat.parse(manholeDTO.getUpdateTime());
  197. } catch (ParseException e) {
  198. throw new RuntimeException(e);
  199. }
  200. //判断时区,为null默认东八区
  201. long timezone = manholeDTO.getTimezone() == null ? 8 : manholeDTO.getTimezone();
  202. long l = cmdTime.getTime() + timezone * 3600 * 1000;
  203. cmdTime = new Date(l);
  204. manholeDTO.setUpdateTime(simpleDateFormat.format(cmdTime));
  205. }else {
  206. manholeDTO.setUpdateTime("");
  207. }
  208. if (manholeDTO.getStatus() != null && manholeDTO.getStatus() == 1){
  209. manholeDTO.setStatus(1);
  210. }else {
  211. manholeDTO.setStatus(0);
  212. }
  213. manholeDTO.setTotal(manholeDao.getTotalBySectionList(dto.getSectionList()));
  214. list.add(manholeDTO);
  215. });
  216. vo.setList(list);
  217. return vo;
  218. }
  219. @Override
  220. public void addManholeDataByDTO(ManholeDTO dto) {
  221. manholeDao.addManholeDataByDTO(dto);
  222. }
  223. @Override
  224. public void updateManholeDataByDTO(ManholeDTO dto) {
  225. manholeDao.updateManholeDataByDTO(dto);
  226. }
  227. @Override
  228. public Integer findByManholeDTO(ManholeDTO dto) {
  229. return manholeDao.findByManholeDTO(dto);
  230. }
  231. @Override
  232. public void deleteManholeDataById(Integer id) {
  233. this.deleteManholeLogDataById(id);
  234. manholeDao.deleteManholeDataById(id);
  235. }
  236. @Override
  237. public void deleteManholeLogDataById(Integer id) {
  238. manholeDao.deleteManholeLogDataById(id);
  239. }
  240. @Override
  241. public void changeManholeLocationById(ManholeDTO dto) {
  242. manholeDao.changeManholeLocationById(dto);
  243. }
  244. @Override
  245. public ManholeDTO getManholeDTOById(Integer id) {
  246. return manholeDao.getManholeDTOById(id);
  247. }
  248. @Override
  249. public ManholeDTO getTiltManholeByLampPoleId(Integer lampPoleId) {
  250. ManholeDTO dto = manholeDao.getTiltManholeByLampPoleId(lampPoleId);
  251. String alarmStr1,alarmStr2,alarmStr3,alarmStr4;
  252. if (dto.getOpenAlarm() == 1) {
  253. alarmStr1 = "打开告警,";
  254. } else {
  255. alarmStr1 = "打开恢复,";
  256. }
  257. if (dto.getOverAlarm() == 1) {
  258. alarmStr2 = "满溢告警,";
  259. } else {
  260. alarmStr2 = "满溢恢复,";
  261. }
  262. if (dto.getAirAlarm() == 1) {
  263. alarmStr3 = "气体警告,";
  264. } else {
  265. alarmStr3 = "气体恢复,";
  266. }
  267. if (dto.getDisManAlarm() == 1) {
  268. alarmStr4 = "拆除警告";
  269. } else {
  270. alarmStr4 = "拆除恢复";
  271. }
  272. String alarmInfo = alarmStr1 + alarmStr2 + alarmStr3 + alarmStr4;
  273. dto.setAlarmInfo(alarmInfo);
  274. return dto;
  275. }
  276. @Override
  277. public ManholeDTO getOneManhole(HashMap<String,Object> map){
  278. return manholeDao.getOneManhole(map);
  279. }
  280. }