From 7ef4892f9f24f941aca37e6b3991b808a0aca619 Mon Sep 17 00:00:00 2001 From: zhanghua <314079846@qq.com> Date: 星期五, 08 九月 2023 11:16:35 +0800 Subject: [PATCH] 优化 --- ycl-platform/src/main/java/com/ycl/controller/cockpit/enforcementEvents/EnforcementEventsController.java | 165 +++++++++++++++++++++++++------------------------------ 1 files changed, 75 insertions(+), 90 deletions(-) diff --git a/ycl-platform/src/main/java/com/ycl/controller/cockpit/enforcementEvents/EnforcementEventsController.java b/ycl-platform/src/main/java/com/ycl/controller/cockpit/enforcementEvents/EnforcementEventsController.java index 1c19a87..a8800de 100644 --- a/ycl-platform/src/main/java/com/ycl/controller/cockpit/enforcementEvents/EnforcementEventsController.java +++ b/ycl-platform/src/main/java/com/ycl/controller/cockpit/enforcementEvents/EnforcementEventsController.java @@ -1,11 +1,22 @@ package com.ycl.controller.cockpit.enforcementEvents; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; import com.ycl.api.CommonResult; +import com.ycl.dto.trend.TrendAnalysisParam; +import com.ycl.entity.caseHandler.BaseCase; +import com.ycl.entity.caseHandler.Violations; +import com.ycl.mapper.trend.TrendAnalysisMapper; +import com.ycl.service.caseHandler.IBaseCaseService; +import com.ycl.service.caseHandler.IViolationsService; import com.ycl.util.CheckApiUtil; import com.ycl.vo.cockpit.CockpitVO; import com.ycl.vo.cockpit.enforcementEvents.EnforcementEventsVO; +import com.ycl.vo.cockpit.enforcementEvents.EventVO; +import com.ycl.vo.cockpit.enforcementEvents.VideoAndAreaVO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -13,11 +24,10 @@ import javax.annotation.Resource; import java.math.BigDecimal; -import java.math.RoundingMode; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * @author Lyq @@ -31,123 +41,98 @@ @Resource private CheckApiUtil checkApiUtil; + @Autowired + IBaseCaseService iBaseCaseService; + @Autowired + IViolationsService iViolationsService; + @Resource + TrendAnalysisMapper trendAnalysisMapper; + @ApiOperation(value = "鎵ф硶浜嬩欢缁熻") @GetMapping("/statistics") - public CommonResult<Map<String, Object>> statistics(@Validated CockpitVO.Params2VO params) { - checkApiUtil.cockpit(params.getAppId(), params.getAppKey(), params.getSign(), params.getBeginTime(), params.getEndTime()); - Map<String, Object> map = new HashMap<>(); - EnforcementEventsVO.StatisticsEventVO eventVO = new EnforcementEventsVO.StatisticsEventVO(); - eventVO.setCount(10); - eventVO.setRatio(new BigDecimal("0.69").setScale(2, RoundingMode.HALF_UP)); - map.put("reported", eventVO); - map.put("disposition", eventVO); - map.put("dispositionInTime", eventVO); - map.put("register", eventVO); - return CommonResult.success(map); + public CommonResult<Map<String, Object>> statistics(@Validated CockpitVO params) { + checkApiUtil.cockpit(params); + return CommonResult.success(iBaseCaseService.statistics()); } @ApiOperation(value = "浜嬩欢绫诲瀷") @GetMapping("/type") - public CommonResult<EnforcementEventsVO.TypeAndSourceVO> type(@Validated CockpitVO.Params2VO params) { - checkApiUtil.cockpit(params.getAppId(), params.getAppKey(), params.getSign(), params.getBeginTime(), params.getEndTime()); - List<EnforcementEventsVO.TypeAndSourceVO1> typeVO1s = new ArrayList<>(); - EnforcementEventsVO.TypeAndSourceVO typeVO = new EnforcementEventsVO.TypeAndSourceVO(); - EnforcementEventsVO.TypeAndSourceVO1 typeVO1 = null; - for (int i = 0; i < 4; i++) { - typeVO1 = new EnforcementEventsVO.TypeAndSourceVO1(); - typeVO1.setName("鍥㈢粨灞�"); - typeVO1.setCount(20); - typeVO1.setRatio(new BigDecimal("0.69").setScale(2, RoundingMode.HALF_UP)); - typeVO1s.add(typeVO1); - } - typeVO.setAll(100); - typeVO.setRecords(typeVO1s); - return CommonResult.success(typeVO); + public CommonResult type(@Validated CockpitVO params) { + checkApiUtil.cockpit(params); + EnforcementEventsVO.TypeAndSourceVO typeAndSourceVO = new EnforcementEventsVO.TypeAndSourceVO(); + Long count = iViolationsService.count(); + typeAndSourceVO.setAll(iViolationsService.count()); + List<VideoAndAreaVO> videoAndAreaVOS = iViolationsService.selectType(); + videoAndAreaVOS.stream().forEach(item -> item.setRatio(new BigDecimal(item.getCount() * 1.0 / count).setScale(4, BigDecimal.ROUND_HALF_UP))); + typeAndSourceVO.setRecords(videoAndAreaVOS); + return CommonResult.success(typeAndSourceVO); } @ApiOperation(value = "瑙嗛鎶撴媿鍛婂彂鐐逛綅") @GetMapping("/video") - public CommonResult<List<EnforcementEventsVO.VideoAndAreaVO>> video(@Validated CockpitVO.Params2VO params) { - checkApiUtil.cockpit(params.getAppId(), params.getAppKey(), params.getSign(), params.getBeginTime(), params.getEndTime()); - List<EnforcementEventsVO.VideoAndAreaVO> videoVOS = new ArrayList<>(); - EnforcementEventsVO.VideoAndAreaVO videoVO = null; - for (int i = 0; i < 4; i++) { - videoVO = new EnforcementEventsVO.VideoAndAreaVO(); - videoVO.setName("鍥㈢粨灞�"); - videoVO.setCount(10); - videoVOS.add(videoVO); - } - return CommonResult.success(videoVOS); + public CommonResult video(@Validated CockpitVO params) { + checkApiUtil.cockpit(params); + Long count = iViolationsService.count(new LambdaQueryWrapper<Violations>().isNotNull(Violations::getVideoPointId)); + List<VideoAndAreaVO> collect = trendAnalysisMapper.selectTrendInfo(new TrendAnalysisParam()).stream().map(item -> { + VideoAndAreaVO videoAndAreaVO = new VideoAndAreaVO(); + videoAndAreaVO.setName(item.getName()); + videoAndAreaVO.setCount(item.getCount()); + videoAndAreaVO.setRatio(new BigDecimal(item.getCount() * 1.0 / count).setScale(4, BigDecimal.ROUND_HALF_UP)); + return videoAndAreaVO; + }).collect(Collectors.toList()); + return CommonResult.success(collect); } @ApiOperation(value = "浜嬩欢鏉ユ簮") @GetMapping("/source") - public CommonResult<EnforcementEventsVO.TypeAndSourceVO> source(@Validated CockpitVO.Params2VO params) { - checkApiUtil.cockpit(params.getAppId(), params.getAppKey(), params.getSign(), params.getBeginTime(), params.getEndTime()); - List<EnforcementEventsVO.TypeAndSourceVO1> typeVO1s = new ArrayList<>(); + public CommonResult<EnforcementEventsVO.TypeAndSourceVO> source(@Validated CockpitVO params) { + checkApiUtil.cockpit(params); + Long allCount = iBaseCaseService.count(); + Long alCount = iBaseCaseService.count(new LambdaQueryWrapper<BaseCase>().eq(BaseCase::getEventSource, "1")); + Long handCount = iBaseCaseService.count(new LambdaQueryWrapper<BaseCase>().eq(BaseCase::getEventSource, "2")); + List<VideoAndAreaVO> typeVO1s = new ArrayList<>(); EnforcementEventsVO.TypeAndSourceVO typeVO = new EnforcementEventsVO.TypeAndSourceVO(); - EnforcementEventsVO.TypeAndSourceVO1 typeVO1 = null; - for (int i = 0; i < 4; i++) { - typeVO1 = new EnforcementEventsVO.TypeAndSourceVO1(); - typeVO1.setName("鍥㈢粨灞�"); - typeVO1.setCount(20); - typeVO1.setRatio(new BigDecimal("0.69").setScale(2, RoundingMode.HALF_UP)); - typeVO1s.add(typeVO1); - } - typeVO.setAll(100); + VideoAndAreaVO al = new VideoAndAreaVO(); + al.setName("瑙嗛宸℃煡"); + al.setRatio(new BigDecimal(alCount * 1.0 / allCount).setScale(4, BigDecimal.ROUND_HALF_UP)); + al.setCount(alCount); + typeVO1s.add(al); + VideoAndAreaVO hand = new VideoAndAreaVO(); + hand.setName("缃戞牸宸℃煡"); + hand.setRatio(new BigDecimal(handCount * 1.0 / allCount).setScale(4, BigDecimal.ROUND_HALF_UP)); + hand.setCount(handCount); + typeVO1s.add(hand); + typeVO.setAll(allCount); typeVO.setRecords(typeVO1s); return CommonResult.success(typeVO); } @ApiOperation(value = "浜嬩欢鍖哄煙缁熻") @GetMapping("/area") - public CommonResult<List<EnforcementEventsVO.VideoAndAreaVO>> area(@Validated CockpitVO.Params2VO params) { - checkApiUtil.cockpit(params.getAppId(), params.getAppKey(), params.getSign(), params.getBeginTime(), params.getEndTime()); - List<EnforcementEventsVO.VideoAndAreaVO> videoVOS = new ArrayList<>(); - EnforcementEventsVO.VideoAndAreaVO videoVO = null; - for (int i = 0; i < 4; i++) { - videoVO = new EnforcementEventsVO.VideoAndAreaVO(); - videoVO.setName("鍥㈢粨灞�"); - videoVO.setCount(10); - videoVOS.add(videoVO); - } - return CommonResult.success(videoVOS); + public CommonResult area(@Validated CockpitVO params) { + checkApiUtil.cockpit(params); + return CommonResult.success(iBaseCaseService.areaCount()); } @ApiOperation(value = "寤惰浜嬩欢") @GetMapping("/delay") - public CommonResult<List<EnforcementEventsVO.DelayVO>> delay(@Validated CockpitVO.Params2VO params) { - checkApiUtil.cockpit(params.getAppId(), params.getAppKey(), params.getSign(), params.getBeginTime(), params.getEndTime()); - List<EnforcementEventsVO.DelayVO> delayVOS = new ArrayList<>(); - EnforcementEventsVO.DelayVO delayVO = null; - for (int i = 0; i < 4; i++) { - delayVO = new EnforcementEventsVO.DelayVO(); - delayVO.setCode("201245555555"); - delayVO.setDescription("鍥㈢粨灞�"); - delayVO.setDuration(30); - delayVOS.add(delayVO); - } - return CommonResult.success(delayVOS); + public CommonResult delay(@Validated CockpitVO params) { + checkApiUtil.cockpit(params); + return CommonResult.success(iBaseCaseService.selectDelayList()); } @ApiOperation(value = "浜嬩欢淇℃伅") @GetMapping("/info") - public CommonResult<EnforcementEventsVO.InfoVO> info(@Validated CockpitVO.Params2VO params) { - checkApiUtil.cockpit(params.getAppId(), params.getAppKey(), params.getSign(), params.getBeginTime(), params.getEndTime()); + public CommonResult<EnforcementEventsVO.InfoVO> info(@Validated CockpitVO params) { + checkApiUtil.cockpit(params); EnforcementEventsVO.InfoVO infoVO = new EnforcementEventsVO.InfoVO(); - EnforcementEventsVO.EventVO eventVO = new EnforcementEventsVO.EventVO(); - infoVO.setToday(5); - infoVO.setWeek(10); - infoVO.setDispatch(20); - infoVO.setIdentification(20); - eventVO.setDescription("浜嬩欢鎻忚堪"); - eventVO.setAddress("浜嬪彂鍦板潃"); - eventVO.setAlarmTime("2022-10-15 16:12:13"); - eventVO.setPoint("1鍙风偣浣�"); - eventVO.setPicture("http://12.2.23.4/xx.png"); - eventVO.setSource("AI璇嗗埆"); - infoVO.setEvent(eventVO); + infoVO.setToday(iBaseCaseService.dayCount()); + infoVO.setWeek(iBaseCaseService.weekCount()); + infoVO.setDispatch(iBaseCaseService.dispatchCount()); + infoVO.setIdentification(iBaseCaseService.alCount()); + IPage<EventVO> page = iBaseCaseService.selectEventList(params.getBeginTime(), params.getEndTime(),params.getPageIndex(),params.getPageSize()); + infoVO.setEvent(page.getRecords()); + infoVO.setTotal(page.getTotal()); return CommonResult.success(infoVO); } - -} +} \ No newline at end of file -- Gitblit v1.8.0