123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- 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<LampInfoCacheByDayDTO> list = lampInfoCacheByDayService.getSectionOfMonthConSum(dayDTO);
- DecimalFormat decimalFormat = new DecimalFormat("0.00");
- HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
- long timeT = startTime;
- int i = 0;
- List<Object> dateList = new ArrayList<>();
- List<Object> 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<LampInfoDTO> 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<LampInfoDTO> 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<LampInfoDTO> 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<LampInfoDTO> list = lampService.getLampAlarmTotal(lampInfoDTO);
- HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
- long timeT = startTime;
- int i = 0;
- List<Object> dateList = new ArrayList<>();
- List<Object> 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<WeatherDTO> 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<VideoCarDTO> carList = videoCarService.getVideoCarListByVideoId(video.getId());
- video.setCarList(carList); // 车牌识别列表
- List<VideoFaceDTO> videoFace = videoFaceService.getVideoFaceListByVideoId(lampPoleId);
- video.setFaceList(videoFace); // 人脸识别列表
- List<TrailInfoDTO> trailList = trailInfoService.getTrailInfoListByVideoId(video.getId());
- video.setTrailList(trailList); // 轨迹列表
- List<TrailInfoDTO> 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<Object> dateList = new ArrayList<>();
- List<Object> flowList = new ArrayList<>();
- long l = System.currentTimeMillis();
- long startTime = l - 24 * 3600 * 1000 * 6;
- HashMap<String, Integer> 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<WifiInfoLogDTO> 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);
- }
- }
|