package com.welampiot.controller; import com.welampiot.common.BaseResult; import com.welampiot.common.InterfaceResultEnum; import com.welampiot.dto.*; import com.welampiot.service.*; import com.welampiot.utils.ToolUtils; import com.welampiot.utils.WeatherUtil; import com.welampiot.vo.LampInfoCacheByDayVO; import com.welampiot.vo.LampInfoVO; import com.welampiot.vo.LampPoleDataVO; import com.welampiot.vo.LampPoleInfoVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; /** * ClassName: BigScreenController * Package: com.welampiot.controller * Description: * * @Author: zhj_Start * @Create: 2023/8/29 - 17:38 * @Version: v1.0 */ @RestController @CrossOrigin @RequestMapping("/bigScreen") public class BigScreenController { @Autowired private ToolUtils toolUtils; @Autowired private LampInfoCacheByDayService lampInfoCacheByDayService; @Autowired private LampService lampService; @Autowired private LampPoleService lampPoleService; @Autowired private EnvmonitorService envmonitorService; @Autowired private ScreenService screenService; @Autowired private VideoMonitorService videoMonitorService; @Autowired private VideoCarService videoCarService; @Autowired private VideoFaceService videoFaceService; @Autowired private TrailInfoService trailInfoService; @Autowired private ChargeService chargeService; @Autowired private WifiService wifiService; @Autowired private WifiInfoLogService wifiInfoLogService; /** * 用电量统计 * @param request sectionList * @return 用电量统计 */ @RequestMapping(value = "/statistics", method = RequestMethod.POST) public BaseResult statistics(HttpServletRequest request) throws ParseException { Integer version = (Integer) toolUtils.getRequestContent(request,"version",1); long startTime = System.currentTimeMillis() - 24L * 3600 * 1000 * 30; long endTime = System.currentTimeMillis() - 24 * 3600 * 1000; SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); String startDate = simpleDateFormat.format(startTime); String endDate = simpleDateFormat.format(endTime); LampInfoCacheByDayDTO dayDTO = new LampInfoCacheByDayDTO(); dayDTO.setStartDate(startDate); dayDTO.setEndDate(endDate); dayDTO.setSectionList(toolUtils.getSectionList(request)); List list = lampInfoCacheByDayService.getSectionOfMonthConSum(dayDTO); DecimalFormat decimalFormat = new DecimalFormat("0.00"); HashMap objectObjectHashMap = new HashMap<>(); long timeT = startTime; int i = 0; List dateList = new ArrayList<>(); List valueList = new ArrayList<>(); while (timeT <= endTime) { objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i); dateList.add(simpleDateFormat.format(new Date(timeT))); valueList.add(0); timeT += 3600 * 1000 * 24; i ++; } for (LampInfoCacheByDayDTO dto : list) { Date date = new Date(simpleDateFormat.parse(dto.getUpdateTime()).getTime()); String s = simpleDateFormat.format(date); Integer integer = null; if (objectObjectHashMap.containsKey(s)) { integer = objectObjectHashMap.get(s); } if (dto.getConSum() != null && !dto.getConSum().equals("0") && integer != null) { String formatConSum = decimalFormat.format(dto.getConSum()); valueList.set(integer, Float.parseFloat(formatConSum)); } } LampInfoCacheByDayVO lampInfoCacheByDayVO = new LampInfoCacheByDayVO(); lampInfoCacheByDayVO.setDate(dateList); lampInfoCacheByDayVO.setValue(valueList); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoCacheByDayVO); } /** * 故障数量TOP5地区 * @param request sectionList * @return 故障数量TOP5地区 */ @RequestMapping(value = "/alarmTOP", method = RequestMethod.POST) public BaseResult alarmTOP(HttpServletRequest request) { Integer version = (Integer) toolUtils.getRequestContent(request,"version",1); LampInfoDTO lampInfoDTO = new LampInfoDTO(); lampInfoDTO.setVersion(version); lampInfoDTO.setSectionList(toolUtils.getSectionList(request)); List list = lampService.getAlarmAreaCountTop(lampInfoDTO); LampInfoVO lampInfoVO = new LampInfoVO(); lampInfoVO.setList(list); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO); } /** * 用电量TOP5路段 * @param request sectionList * @return 用电量TOP5路段 */ @RequestMapping(value = "/consumptionTOP", method = RequestMethod.POST) public BaseResult consumptionTOP(HttpServletRequest request) { Integer version = (Integer) toolUtils.getRequestContent(request,"version",1); LampInfoDTO lampInfoDTO = new LampInfoDTO(); lampInfoDTO.setSectionList(toolUtils.getSectionList(request)); List list = lampService.getLampEleUseSectionTop(lampInfoDTO); DecimalFormat decimalFormat = new DecimalFormat("0.00"); for (LampInfoDTO dto : list) { if (dto.getConsumption() != null && !dto.getConsumption().equals("0.0")) { float consumption = Float.parseFloat(dto.getConsumption()); String format = decimalFormat.format(consumption); dto.setConsumption(format); } else if (dto.getConsumption() == null || dto.getConsumption().equals("0.0")) { dto.setConsumption("0"); } } LampInfoVO lampInfoVO = new LampInfoVO(); lampInfoVO.setList(list); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO); } /** * 故障信息列表 * @param request sectionList * @return 故障信息列表 */ @RequestMapping(value = "/alarmList", method = RequestMethod.POST) public BaseResult alarmList(HttpServletRequest request) { Integer version = (Integer) toolUtils.getRequestContent(request,"version",1); Integer page = (Integer) toolUtils.getRequestContent(request,"page",1); Integer count = (Integer) toolUtils.getRequestContent(request,"count",1); if (page == 0) page = 1; if (count == 0) count = 16; LampInfoDTO lampInfoDTO = new LampInfoDTO(); lampInfoDTO.setPage(count * (page - 1)); lampInfoDTO.setCount(count); lampInfoDTO.setVersion(version); lampInfoDTO.setSectionList(toolUtils.getSectionList(request)); List list = lampService.getLampInfoAlarmList(lampInfoDTO); LampInfoVO lampInfoVO = new LampInfoVO(); lampInfoVO.setList(list); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO); } /** * 故障数量折线图 * @param request sectionList * @return 故障数量折线图 */ @RequestMapping(value = "/alarmChart", method = RequestMethod.POST) public BaseResult alarmChart(HttpServletRequest request) throws ParseException { Integer version = (Integer) toolUtils.getRequestContent(request,"version",1); long startTime = System.currentTimeMillis() - 29L * 3600 * 1000 * 24; long endTime = System.currentTimeMillis(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); String startDate = simpleDateFormat.format(startTime); String endDate = simpleDateFormat.format(endTime); LampInfoDTO lampInfoDTO = new LampInfoDTO(); lampInfoDTO.setStartDate(startDate); lampInfoDTO.setEndDate(endDate); lampInfoDTO.setSectionList(toolUtils.getSectionList(request)); List list = lampService.getLampAlarmTotal(lampInfoDTO); HashMap objectObjectHashMap = new HashMap<>(); long timeT = startTime; int i = 0; List dateList = new ArrayList<>(); List valueList = new ArrayList<>(); while (timeT <= endTime) { objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)),i); dateList.add(simpleDateFormat.format(new Date(timeT))); valueList.add(0); timeT += 3600 * 1000 * 24; i ++; } for (LampInfoDTO dto : list) { Date date = new Date(simpleDateFormat.parse(dto.getUpdateTime()).getTime()); String s = simpleDateFormat.format(date); Integer integer = null; if (objectObjectHashMap.containsKey(s)) { integer = objectObjectHashMap.get(s); } if (dto.getLampCount() != null && dto.getLampCount() != 0 && integer != null) { valueList.set(integer, dto.getLampCount()); } } LampInfoVO lampInfoVO = new LampInfoVO(); lampInfoVO.setDate(dateList); lampInfoVO.setValue(valueList); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO); } /** * 灯杆大屏统计数据 * @param request sectionList * @return 灯杆数量统计 */ @RequestMapping(value = "/lampPoleTotalData", method = RequestMethod.POST) public BaseResult lampPoleTotalData(HttpServletRequest request) { Integer version = (Integer) toolUtils.getRequestContent(request,"version",1); LampPoleDTO lampPoleDTO = new LampPoleDTO(); lampPoleDTO.setSectionList(toolUtils.getSectionList(request)); LampInfoDTO lampInfoDTO = new LampInfoDTO(); lampInfoDTO.setSectionList(toolUtils.getSectionList(request)); LampPoleInfoVO lampPoleData = lampPoleService.getLampPoleBigScreenCount(lampPoleDTO, lampInfoDTO); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampPoleData); } /** * 灯杆大屏灯杆数据 * @param request 灯杆id * @return 灯杆数据 */ @RequestMapping(value = "/lampPoleData", method = RequestMethod.POST) public BaseResult lampPoleData(HttpServletRequest request) throws Exception { Integer version = (Integer) toolUtils.getRequestContent(request,"version",1); Integer lampPoleId = (Integer) toolUtils.getRequestContent(request,"lampPoleId",1); if (lampPoleId == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version); // 照明数据 LampInfoDTO lampInfoDTO = lampService.getLampOfLampPoleById(lampPoleId, 0); LampPoleDataVO lampPoleDataVO = new LampPoleDataVO(); lampPoleDataVO.setLampData(lampInfoDTO); // 气象数据 EnvmonitorDTO envmonitor = envmonitorService.getEnvmonitorByLampPoleId(lampPoleId); Double longitude = null,latitude = null; if (envmonitor != null) { longitude = envmonitor.getLongitude(); latitude = envmonitor.getLatitude(); } if (longitude != null && latitude != null) { List weatherList = WeatherUtil.getNearWeatherInfo(longitude.toString(), latitude.toString()); envmonitor.setWeatherList(weatherList); } lampPoleDataVO.setWeatherData(envmonitor); // 屏幕数据 ScreenDTO screen = screenService.getScreenByLampPoleId(lampPoleId); if (screen != null) screen.setName(screen.getPlay()); lampPoleDataVO.setScreenData(screen); // 监控数据 VideoMonitorDTO video = videoMonitorService.getVideoMonitorByLampPoleId(lampPoleId); video.setVideoPath(""); video.setVideoPathHd(""); VideoCarDTO videoCar = videoCarService.getVideoCarByVideoId(video.getId()); if (videoCar != null) video.setCarImage(videoCar.getImage()); List carList = videoCarService.getVideoCarListByVideoId(video.getId()); video.setCarList(carList); // 车牌识别列表 List videoFace = videoFaceService.getVideoFaceListByVideoId(lampPoleId); video.setFaceList(videoFace); // 人脸识别列表 List trailList = trailInfoService.getTrailInfoListByVideoId(video.getId()); video.setTrailList(trailList); // 轨迹列表 List smailList = trailInfoService.getSmailListByVideoId(video.getId()); video.setSmailList(smailList); // 相似度列表 lampPoleDataVO.setVideoData(video); // 充电桩数据 ChargeDTO chargeDTO = chargeService.getChargeInfoByLampPoleId(lampPoleId); lampPoleDataVO.setChargeData(chargeDTO); // wifi数据 WifiDTO wifi = wifiService.getWifiByLampPoleId(lampPoleId); if (wifi.getFlow() != null) { Float flow = wifi.getFlow(); if (flow < 1024) { wifi.setType(0); } else if (1024 <= flow && flow < 1024 * 1024) { wifi.setType(1); flow = flow / 1024; wifi.setFlow(flow); } else if (1024 * 1024 <= flow) { wifi.setType(2); flow = flow / (1024 * 1024); wifi.setFlow(flow); } } // 流量列表 List dateList = new ArrayList<>(); List flowList = new ArrayList<>(); long l = System.currentTimeMillis(); long startTime = l - 24 * 3600 * 1000 * 6; HashMap objectObjectHashMap = new HashMap<>(); long timeT = startTime; int i = 0; DecimalFormat decimalFormat = new DecimalFormat("0.00"); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00"); SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); while (timeT <= l) { objectObjectHashMap.put(simpleDateFormat.format(new Date(timeT)), i); dateList.add(simpleDateFormat.format(new Date(timeT))); flowList.add(0); timeT += 3600 * 1000; i++; } int dayNumber = 1; WifiInfoLogDTO wifiInfoLogDTO = new WifiInfoLogDTO(); wifiInfoLogDTO.setDayNum(7); wifiInfoLogDTO.setDayNumber(dayNumber); wifiInfoLogDTO.setLampPoleId(lampPoleId); List wifiInfoLogList = wifiInfoLogService.getWifiStatisticsListByDTO(wifiInfoLogDTO); for (WifiInfoLogDTO dto1 : wifiInfoLogList) { Date date = new Date(simpleDateFormat2.parse(dto1.getUpdateTime()).getTime()); String s = simpleDateFormat.format(date); long time = simpleDateFormat.parse(s).getTime(); String formatStart = simpleDateFormat.format(startTime); startTime = simpleDateFormat.parse(formatStart).getTime(); long timespan = (time - startTime) / (3600 * 1000 * dayNumber); long newTime = startTime + timespan * (3600 * 1000 * dayNumber); date = new Date(newTime); s = simpleDateFormat.format(date); Integer integer = null; if (objectObjectHashMap.containsKey(s)) { integer = objectObjectHashMap.get(s); } if (dto1.getMinFlow() != null && !dto1.getMinFlow().equals("0") && integer != null && dto1.getMaxFlow() != null && !dto1.getMaxFlow().equals("0")) { Float flow = Float.parseFloat(dto1.getMaxFlow()) - Float.parseFloat(dto1.getMinFlow()); flowList.set(integer,Float.parseFloat(decimalFormat.format(flow))); } } wifi.setDateList(dateList); wifi.setFlowList(flowList); lampPoleDataVO.setWifiData(wifi); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampPoleDataVO); } }