package com.ycl.controller.cockpit.enforcementEvents; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.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; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @author Lyq * @version 1.0 * @date 2022/10/26 */ @Api(tags = "驾驶舱数据-执法事件") @RestController @RequestMapping("/api/event") public class EnforcementEventsController { @Resource private CheckApiUtil checkApiUtil; @Autowired IBaseCaseService iBaseCaseService; @Autowired IViolationsService iViolationsService; @Resource TrendAnalysisMapper trendAnalysisMapper; @ApiOperation(value = "执法事件统计") @GetMapping("/statistics") public CommonResult> statistics(@Validated CockpitVO params) { checkApiUtil.cockpit(params); return CommonResult.success(iBaseCaseService.statistics()); } @ApiOperation(value = "事件类型") @GetMapping("/type") public CommonResult type(@Validated CockpitVO params) { checkApiUtil.cockpit(params); EnforcementEventsVO.TypeAndSourceVO typeAndSourceVO = new EnforcementEventsVO.TypeAndSourceVO(); Long count = iViolationsService.count(); typeAndSourceVO.setAll(iViolationsService.count()); List videoAndAreaVOS = iViolationsService.selectType(); videoAndAreaVOS.stream().forEach(item -> item.setRatio(new BigDecimal(item.getCount() * 1.0 / count).setScale(2, BigDecimal.ROUND_HALF_UP))); typeAndSourceVO.setRecords(videoAndAreaVOS); return CommonResult.success(typeAndSourceVO); } @ApiOperation(value = "视频抓拍告发点位") @GetMapping("/video") public CommonResult video(@Validated CockpitVO params) { checkApiUtil.cockpit(params); Long count = iViolationsService.count(new LambdaQueryWrapper().isNotNull(Violations::getVideoPointId)); List 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(2, BigDecimal.ROUND_HALF_UP)); return videoAndAreaVO; }).collect(Collectors.toList()); return CommonResult.success(collect); } @ApiOperation(value = "事件来源") @GetMapping("/source") public CommonResult source(@Validated CockpitVO params) { checkApiUtil.cockpit(params); Long allCount = iBaseCaseService.count(); Long alCount = iBaseCaseService.count(new LambdaQueryWrapper().eq(BaseCase::getEventSource, "1")); Long handCount = iBaseCaseService.count(new LambdaQueryWrapper().eq(BaseCase::getEventSource, "2")); List typeVO1s = new ArrayList<>(); EnforcementEventsVO.TypeAndSourceVO typeVO = new EnforcementEventsVO.TypeAndSourceVO(); VideoAndAreaVO al = new VideoAndAreaVO(); al.setName("视频巡查"); al.setRatio(new BigDecimal(alCount * 1.0 / allCount).setScale(2, 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(2, 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 area(@Validated CockpitVO params) { checkApiUtil.cockpit(params); return CommonResult.success(iBaseCaseService.areaCount()); } @ApiOperation(value = "延误事件") @GetMapping("/delay") public CommonResult delay(@Validated CockpitVO params) { checkApiUtil.cockpit(params); return CommonResult.success(iBaseCaseService.selectDelayList()); } @ApiOperation(value = "事件信息") @GetMapping("/info") public CommonResult info(@Validated CockpitVO params) { checkApiUtil.cockpit(params); EnforcementEventsVO.InfoVO infoVO = new EnforcementEventsVO.InfoVO(); infoVO.setToday(iBaseCaseService.dayCount()); infoVO.setWeek(iBaseCaseService.weekCount()); infoVO.setDispatch(iBaseCaseService.dispatchCount()); infoVO.setIdentification(iBaseCaseService.alCount()); infoVO.setEvent(iBaseCaseService.selectEventList(params.getBeginTime(), params.getEndTime())); return CommonResult.success(infoVO); } }