BigScreenController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. package com.welampiot.controller;
  2. import com.welampiot.common.BaseResult;
  3. import com.welampiot.common.InterfaceResultEnum;
  4. import com.welampiot.dto.*;
  5. import com.welampiot.service.*;
  6. import com.welampiot.utils.ToolUtils;
  7. import com.welampiot.utils.WeatherUtil;
  8. import com.welampiot.vo.LampInfoCacheByDayVO;
  9. import com.welampiot.vo.LampInfoVO;
  10. import com.welampiot.vo.LampPoleDataVO;
  11. import com.welampiot.vo.LampPoleInfoVO;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.web.bind.annotation.CrossOrigin;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import javax.servlet.http.HttpServletRequest;
  18. import java.text.DecimalFormat;
  19. import java.text.ParseException;
  20. import java.text.SimpleDateFormat;
  21. import java.util.ArrayList;
  22. import java.util.Date;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. /**
  26. * ClassName: BigScreenController
  27. * Package: com.welampiot.controller
  28. * Description:
  29. *
  30. * @Author: zhj_Start
  31. * @Create: 2023/8/29 - 17:38
  32. * @Version: v1.0
  33. */
  34. @RestController
  35. @CrossOrigin
  36. @RequestMapping("/bigScreen")
  37. public class BigScreenController {
  38. @Autowired
  39. private ToolUtils toolUtils;
  40. @Autowired
  41. private LampInfoCacheByDayService lampInfoCacheByDayService;
  42. @Autowired
  43. private LampService lampService;
  44. @Autowired
  45. private LampPoleService lampPoleService;
  46. @Autowired
  47. private EnvmonitorService envmonitorService;
  48. @Autowired
  49. private ScreenService screenService;
  50. @Autowired
  51. private VideoMonitorService videoMonitorService;
  52. @Autowired
  53. private VideoCarService videoCarService;
  54. @Autowired
  55. private VideoFaceService videoFaceService;
  56. @Autowired
  57. private TrailInfoService trailInfoService;
  58. @Autowired
  59. private ChargeService chargeService;
  60. @Autowired
  61. private WifiService wifiService;
  62. @Autowired
  63. private WifiInfoLogService wifiInfoLogService;
  64. /**
  65. * 用电量统计
  66. * @param request sectionList
  67. * @return 用电量统计
  68. */
  69. @RequestMapping(value = "/statistics", method = RequestMethod.POST)
  70. public BaseResult<?> statistics(HttpServletRequest request) throws ParseException {
  71. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  72. long startTime = System.currentTimeMillis() - 24L * 3600 * 1000 * 30;
  73. long endTime = System.currentTimeMillis() - 24 * 3600 * 1000;
  74. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  75. String startDate = simpleDateFormat.format(startTime);
  76. String endDate = simpleDateFormat.format(endTime);
  77. LampInfoCacheByDayDTO dayDTO = new LampInfoCacheByDayDTO();
  78. dayDTO.setStartDate(startDate);
  79. dayDTO.setEndDate(endDate);
  80. dayDTO.setSectionList(toolUtils.getSectionList(request));
  81. List<LampInfoCacheByDayDTO> list = lampInfoCacheByDayService.getSectionOfMonthConSum(dayDTO);
  82. DecimalFormat decimalFormat = new DecimalFormat("0.00");
  83. HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
  84. long timeT = startTime;
  85. int i = 0;
  86. List<Object> dateList = new ArrayList<>();
  87. List<Object> valueList = new ArrayList<>();
  88. while (timeT <= endTime) {
  89. objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i);
  90. dateList.add(simpleDateFormat.format(new Date(timeT)));
  91. valueList.add(0);
  92. timeT += 3600 * 1000 * 24;
  93. i ++;
  94. }
  95. for (LampInfoCacheByDayDTO dto : list) {
  96. Date date = new Date(simpleDateFormat.parse(dto.getUpdateTime()).getTime());
  97. String s = simpleDateFormat.format(date);
  98. Integer integer = null;
  99. if (objectObjectHashMap.containsKey(s)) {
  100. integer = objectObjectHashMap.get(s);
  101. }
  102. if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) {
  103. String formatConSum = decimalFormat.format(dto.getConSum());
  104. valueList.set(integer, Float.parseFloat(formatConSum));
  105. }
  106. }
  107. LampInfoCacheByDayVO lampInfoCacheByDayVO = new LampInfoCacheByDayVO();
  108. lampInfoCacheByDayVO.setDate(dateList);
  109. lampInfoCacheByDayVO.setValue(valueList);
  110. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoCacheByDayVO);
  111. }
  112. /**
  113. * 故障数量TOP5地区
  114. * @param request sectionList
  115. * @return 故障数量TOP5地区
  116. */
  117. @RequestMapping(value = "/alarmTOP", method = RequestMethod.POST)
  118. public BaseResult<?> alarmTOP(HttpServletRequest request) {
  119. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  120. LampInfoDTO lampInfoDTO = new LampInfoDTO();
  121. lampInfoDTO.setVersion(version);
  122. lampInfoDTO.setSectionList(toolUtils.getSectionList(request));
  123. List<LampInfoDTO> list = lampService.getAlarmAreaCountTop(lampInfoDTO);
  124. LampInfoVO lampInfoVO = new LampInfoVO();
  125. lampInfoVO.setList(list);
  126. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO);
  127. }
  128. /**
  129. * 用电量TOP5路段
  130. * @param request sectionList
  131. * @return 用电量TOP5路段
  132. */
  133. @RequestMapping(value = "/consumptionTOP", method = RequestMethod.POST)
  134. public BaseResult<?> consumptionTOP(HttpServletRequest request) {
  135. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  136. LampInfoDTO lampInfoDTO = new LampInfoDTO();
  137. lampInfoDTO.setSectionList(toolUtils.getSectionList(request));
  138. List<LampInfoDTO> list = lampService.getLampEleUseSectionTop(lampInfoDTO);
  139. DecimalFormat decimalFormat = new DecimalFormat("0.00");
  140. for (LampInfoDTO dto : list) {
  141. if (dto.getConsumption() != null && !dto.getConsumption().equals("0.0")) {
  142. float consumption = Float.parseFloat(dto.getConsumption());
  143. String format = decimalFormat.format(consumption);
  144. dto.setConsumption(format);
  145. } else if (dto.getConsumption() == null || dto.getConsumption().equals("0.0")) {
  146. dto.setConsumption("0");
  147. }
  148. }
  149. LampInfoVO lampInfoVO = new LampInfoVO();
  150. lampInfoVO.setList(list);
  151. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO);
  152. }
  153. /**
  154. * 故障信息列表
  155. * @param request sectionList
  156. * @return 故障信息列表
  157. */
  158. @RequestMapping(value = "/alarmList", method = RequestMethod.POST)
  159. public BaseResult<?> alarmList(HttpServletRequest request) {
  160. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  161. Integer page = (Integer) toolUtils.getRequestContent(request,"page",1);
  162. Integer count = (Integer) toolUtils.getRequestContent(request,"count",1);
  163. if (page == 0) page = 1;
  164. if (count == 0) count = 16;
  165. LampInfoDTO lampInfoDTO = new LampInfoDTO();
  166. lampInfoDTO.setPage(count * (page - 1));
  167. lampInfoDTO.setCount(count);
  168. lampInfoDTO.setVersion(version);
  169. lampInfoDTO.setSectionList(toolUtils.getSectionList(request));
  170. List<LampInfoDTO> list = lampService.getLampInfoAlarmList(lampInfoDTO);
  171. LampInfoVO lampInfoVO = new LampInfoVO();
  172. lampInfoVO.setList(list);
  173. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO);
  174. }
  175. /**
  176. * 故障数量折线图
  177. * @param request sectionList
  178. * @return 故障数量折线图
  179. */
  180. @RequestMapping(value = "/alarmChart", method = RequestMethod.POST)
  181. public BaseResult<?> alarmChart(HttpServletRequest request) throws ParseException {
  182. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  183. long startTime = System.currentTimeMillis() - 29L * 3600 * 1000 * 24;
  184. long endTime = System.currentTimeMillis();
  185. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
  186. String startDate = simpleDateFormat.format(startTime);
  187. String endDate = simpleDateFormat.format(endTime);
  188. LampInfoDTO lampInfoDTO = new LampInfoDTO();
  189. lampInfoDTO.setStartDate(startDate);
  190. lampInfoDTO.setEndDate(endDate);
  191. lampInfoDTO.setSectionList(toolUtils.getSectionList(request));
  192. List<LampInfoDTO> list = lampService.getLampAlarmTotal(lampInfoDTO);
  193. HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
  194. long timeT = startTime;
  195. int i = 0;
  196. List<Object> dateList = new ArrayList<>();
  197. List<Object> valueList = new ArrayList<>();
  198. while (timeT <= endTime) {
  199. objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i);
  200. dateList.add(simpleDateFormat.format(new Date(timeT)));
  201. valueList.add(0);
  202. timeT += 3600 * 1000 * 24;
  203. i ++;
  204. }
  205. for (LampInfoDTO dto : list) {
  206. Date date = new Date(simpleDateFormat.parse(dto.getUpdateTime()).getTime());
  207. String s = simpleDateFormat.format(date);
  208. Integer integer = null;
  209. if (objectObjectHashMap.containsKey(s)) {
  210. integer = objectObjectHashMap.get(s);
  211. }
  212. if (dto.getLampCount() != null && dto.getLampCount() != 0 && integer != null) {
  213. valueList.set(integer, dto.getLampCount());
  214. }
  215. }
  216. LampInfoVO lampInfoVO = new LampInfoVO();
  217. lampInfoVO.setDate(dateList);
  218. lampInfoVO.setValue(valueList);
  219. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO);
  220. }
  221. /**
  222. * 灯杆大屏统计数据
  223. * @param request sectionList
  224. * @return 灯杆数量统计
  225. */
  226. @RequestMapping(value = "/lampPoleTotalData", method = RequestMethod.POST)
  227. public BaseResult<?> lampPoleTotalData(HttpServletRequest request) {
  228. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  229. LampPoleDTO lampPoleDTO = new LampPoleDTO();
  230. lampPoleDTO.setSectionList(toolUtils.getSectionList(request));
  231. LampInfoDTO lampInfoDTO = new LampInfoDTO();
  232. lampInfoDTO.setSectionList(toolUtils.getSectionList(request));
  233. LampPoleInfoVO lampPoleData = lampPoleService.getLampPoleBigScreenCount(lampPoleDTO, lampInfoDTO);
  234. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampPoleData);
  235. }
  236. /**
  237. * 灯杆大屏灯杆数据
  238. * @param request 灯杆id
  239. * @return 灯杆数据
  240. */
  241. @RequestMapping(value = "/lampPoleData", method = RequestMethod.POST)
  242. public BaseResult<?> lampPoleData(HttpServletRequest request) throws Exception {
  243. Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
  244. Integer lampPoleId = (Integer) toolUtils.getRequestContent(request,"lampPoleId",1);
  245. if (lampPoleId == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
  246. // 照明数据
  247. LampInfoDTO lampInfoDTO = lampService.getLampOfLampPoleById(lampPoleId, 0);
  248. LampPoleDataVO lampPoleDataVO = new LampPoleDataVO();
  249. lampPoleDataVO.setLampData(lampInfoDTO);
  250. // 气象数据
  251. EnvmonitorDTO envmonitor = envmonitorService.getEnvmonitorByLampPoleId(lampPoleId);
  252. Double longitude = null,latitude = null;
  253. if (envmonitor != null) {
  254. longitude = envmonitor.getLongitude();
  255. latitude = envmonitor.getLatitude();
  256. }
  257. if (longitude != null && latitude != null) {
  258. List<WeatherDTO> weatherList = WeatherUtil.getNearWeatherInfo(longitude.toString(), latitude.toString());
  259. envmonitor.setWeatherList(weatherList);
  260. }
  261. lampPoleDataVO.setWeatherData(envmonitor);
  262. // 屏幕数据
  263. ScreenDTO screen = screenService.getScreenByLampPoleId(lampPoleId);
  264. if (screen != null) screen.setName(screen.getPlay());
  265. lampPoleDataVO.setScreenData(screen);
  266. // 监控数据
  267. VideoMonitorDTO video = videoMonitorService.getVideoMonitorByLampPoleId(lampPoleId);
  268. video.setVideoPath("");
  269. video.setVideoPathHd("");
  270. VideoCarDTO videoCar = videoCarService.getVideoCarByVideoId(video.getId());
  271. if (videoCar != null) video.setCarImage(videoCar.getImage());
  272. List<VideoCarDTO> carList = videoCarService.getVideoCarListByVideoId(video.getId());
  273. video.setCarList(carList); // 车牌识别列表
  274. List<VideoFaceDTO> videoFace = videoFaceService.getVideoFaceListByVideoId(lampPoleId);
  275. video.setFaceList(videoFace); // 人脸识别列表
  276. List<TrailInfoDTO> trailList = trailInfoService.getTrailInfoListByVideoId(video.getId());
  277. video.setTrailList(trailList); // 轨迹列表
  278. List<TrailInfoDTO> smailList = trailInfoService.getSmailListByVideoId(video.getId());
  279. video.setSmailList(smailList); // 相似度列表
  280. lampPoleDataVO.setVideoData(video);
  281. // 充电桩数据
  282. ChargeDTO chargeDTO = chargeService.getChargeInfoByLampPoleId(lampPoleId);
  283. lampPoleDataVO.setChargeData(chargeDTO);
  284. // wifi数据
  285. WifiDTO wifi = wifiService.getWifiByLampPoleId(lampPoleId);
  286. if (wifi.getFlow() != null) {
  287. Float flow = wifi.getFlow();
  288. if (flow < 1024) {
  289. wifi.setType(0);
  290. } else if (1024 <= flow && flow < 1024 * 1024) {
  291. wifi.setType(1);
  292. flow = flow / 1024;
  293. wifi.setFlow(flow);
  294. } else if (1024 * 1024 <= flow) {
  295. wifi.setType(2);
  296. flow = flow / (1024 * 1024);
  297. wifi.setFlow(flow);
  298. }
  299. }
  300. // 流量列表
  301. List<Object> dateList = new ArrayList<>();
  302. List<Object> flowList = new ArrayList<>();
  303. long l = System.currentTimeMillis();
  304. long startTime = l - 24 * 3600 * 1000 * 6;
  305. HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
  306. long timeT = startTime;
  307. int i = 0;
  308. DecimalFormat decimalFormat = new DecimalFormat("0.00");
  309. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
  310. SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  311. while (timeT <= l) {
  312. objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)), i);
  313. dateList.add(simpleDateFormat.format(new Date(timeT)));
  314. flowList.add(0);
  315. timeT += 3600 * 1000;
  316. i++;
  317. }
  318. int dayNumber = 1;
  319. WifiInfoLogDTO wifiInfoLogDTO = new WifiInfoLogDTO();
  320. wifiInfoLogDTO.setDayNum(7);
  321. wifiInfoLogDTO.setDayNumber(dayNumber);
  322. wifiInfoLogDTO.setLampPoleId(lampPoleId);
  323. List<WifiInfoLogDTO> wifiInfoLogList = wifiInfoLogService.getWifiStatisticsListByDTO(wifiInfoLogDTO);
  324. for (WifiInfoLogDTO dto1 : wifiInfoLogList) {
  325. Date date = new Date(simpleDateFormat2.parse(dto1.getUpdateTime()).getTime());
  326. String s = simpleDateFormat.format(date);
  327. long time = simpleDateFormat.parse(s).getTime();
  328. String formatStart = simpleDateFormat.format(startTime);
  329. startTime = simpleDateFormat.parse(formatStart).getTime();
  330. long timespan = (time - startTime) / (3600 * 1000 * dayNumber);
  331. long newTime = startTime + timespan * (3600 * 1000 * dayNumber);
  332. date = new Date(newTime);
  333. s = simpleDateFormat.format(date);
  334. Integer integer = null;
  335. if (objectObjectHashMap.containsKey(s)) {
  336. integer = objectObjectHashMap.get(s);
  337. }
  338. if (dto1.getMinFlow() != null && !dto1.getMinFlow().equals("0") && integer != null &&
  339. dto1.getMaxFlow() != null && !dto1.getMaxFlow().equals("0")) {
  340. Float flow = Float.parseFloat(dto1.getMaxFlow()) - Float.parseFloat(dto1.getMinFlow());
  341. flowList.set(integer,Float.parseFloat(decimalFormat.format(flow)));
  342. }
  343. }
  344. wifi.setDateList(dateList);
  345. wifi.setFlowList(flowList);
  346. lampPoleDataVO.setWifiData(wifi);
  347. return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampPoleDataVO);
  348. }
  349. }