From 3cf5e9483f60c94d29df1a79bc0c1ca910ca46ef Mon Sep 17 00:00:00 2001
From: wl <173@qq.com>
Date: 星期二, 13 十二月 2022 14:58:24 +0800
Subject: [PATCH] fix: 执法事件对外接口

---
 ycl-platform/src/main/resources/mapper/caseHandler/BaseCaseMapper.xml                                    |   11 +++++
 ycl-platform/src/main/java/com/ycl/controller/cockpit/enforcementEvents/EnforcementEventsController.java |   53 ++++++++++++--------------
 ycl-platform/src/main/java/com/ycl/controller/trend/TrendAnalysisController.java                         |    4 +-
 ycl-platform/src/main/java/com/ycl/service/caseHandler/IViolationsService.java                           |    3 +
 ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/ViolationsServiceImpl.java                   |   15 ++++++-
 ycl-platform/src/main/java/com/ycl/mapper/caseHandler/ViolationsMapper.java                              |    1 
 ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java                     |    1 
 ycl-platform/src/main/java/com/ycl/mapper/caseHandler/BaseCaseMapper.java                                |    2 +
 ycl-platform/src/main/java/com/ycl/vo/TrendVo.java                                                       |    2 
 ycl-platform/src/main/java/com/ycl/service/caseHandler/IBaseCaseService.java                             |    2 
 10 files changed, 59 insertions(+), 35 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 012c29b..78cfda3 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
@@ -2,9 +2,15 @@
 
 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.service.trend.TrendAnalysisService;
 import com.ycl.util.CheckApiUtil;
+import com.ycl.vo.TrendVo;
 import com.ycl.vo.cockpit.CockpitVO;
 import com.ycl.vo.cockpit.enforcementEvents.EnforcementEventsVO;
 import com.ycl.vo.cockpit.enforcementEvents.VideoAndAreaVO;
@@ -23,6 +29,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @author Lyq
@@ -38,6 +45,10 @@
 
     @Autowired
     IBaseCaseService iBaseCaseService;
+    @Autowired
+    IViolationsService iViolationsService;
+    @Autowired
+    TrendAnalysisMapper trendAnalysisMapper;
 
     @ApiOperation(value = "鎵ф硶浜嬩欢缁熻")
     @GetMapping("/statistics")
@@ -60,24 +71,11 @@
     public CommonResult type(@Validated CockpitVO params) {
         checkApiUtil.cockpit(params);
         EnforcementEventsVO.TypeAndSourceVO typeAndSourceVO = new EnforcementEventsVO.TypeAndSourceVO();
-        Long allCount = iBaseCaseService.count();
-        Long violationCount = iBaseCaseService.count(new LambdaQueryWrapper<BaseCase>().eq(BaseCase::getCategory, "1"));
-        Long illegalBuildingCount = iBaseCaseService.count(new LambdaQueryWrapper<BaseCase>().eq(BaseCase::getCategory, "2"));
-
-        ArrayList<VideoAndAreaVO> typeAndSourceVO1s = new ArrayList<>();
-        VideoAndAreaVO violationVO1 = new VideoAndAreaVO();
-        violationVO1.setName("杩濊");
-        violationVO1.setCount(violationCount);
-        violationVO1.setRatio(new BigDecimal(violationCount * 1.0 / allCount).setScale(2, BigDecimal.ROUND_HALF_UP));
-        VideoAndAreaVO illegalBuildingVO1 = new VideoAndAreaVO();
-        illegalBuildingVO1.setName("杩濆缓");
-        illegalBuildingVO1.setCount(illegalBuildingCount);
-        illegalBuildingVO1.setRatio(new BigDecimal(illegalBuildingCount * 1.0 / allCount).setScale(2, BigDecimal.ROUND_HALF_UP));
-        typeAndSourceVO1s.add(violationVO1);
-        typeAndSourceVO1s.add(illegalBuildingVO1);
-        typeAndSourceVO.setRecords(typeAndSourceVO1s);
-        typeAndSourceVO.setAll(allCount);
-        System.out.println(illegalBuildingCount / allCount);
+        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(2,BigDecimal.ROUND_HALF_UP)));
+        typeAndSourceVO.setRecords(videoAndAreaVOS);
         return CommonResult.success(typeAndSourceVO);
     }
 
@@ -85,16 +83,15 @@
     @GetMapping("/video")
     public CommonResult video(@Validated CockpitVO params) {
         checkApiUtil.cockpit(params);
-        List<VideoAndAreaVO> videoVOS = new ArrayList<>();
-        VideoAndAreaVO videoVO = null;
-        for (int i = 0; i < 4; i++) {
-            videoVO = new VideoAndAreaVO();
-            videoVO.setName("鍥㈢粨灞�");
-            videoVO.setCount(10L);
-            videoVO.setRatio(new BigDecimal("0.65").setScale(2, RoundingMode.HALF_UP));
-            videoVOS.add(videoVO);
-        }
-        return CommonResult.success(videoVOS);
+        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(2, BigDecimal.ROUND_HALF_UP));
+            return videoAndAreaVO;
+        }).collect(Collectors.toList());
+        return CommonResult.success(collect);
     }
 
     @ApiOperation(value = "浜嬩欢鏉ユ簮")
diff --git a/ycl-platform/src/main/java/com/ycl/controller/trend/TrendAnalysisController.java b/ycl-platform/src/main/java/com/ycl/controller/trend/TrendAnalysisController.java
index dc6665e..b19efa9 100644
--- a/ycl-platform/src/main/java/com/ycl/controller/trend/TrendAnalysisController.java
+++ b/ycl-platform/src/main/java/com/ycl/controller/trend/TrendAnalysisController.java
@@ -28,8 +28,8 @@
 
     @ApiOperation("鐐逛綅鏁版嵁鏌ヨ")
     @GetMapping("/pointInfo")
-    public CommonResult<List<TrendVo>> queryPointInfo(@RequestParam String longitude,
-                                                      @RequestParam String latitude) {
+    public CommonResult<List<TrendVo>> queryPointInfo(@RequestParam(required = false) String longitude,
+                                                      @RequestParam(required = false) String latitude) {
         return CommonResult.success(trendAnalysisService.queryPointInfo(longitude,latitude));
     }
 
diff --git a/ycl-platform/src/main/java/com/ycl/mapper/caseHandler/BaseCaseMapper.java b/ycl-platform/src/main/java/com/ycl/mapper/caseHandler/BaseCaseMapper.java
index 540c790..237e22d 100644
--- a/ycl-platform/src/main/java/com/ycl/mapper/caseHandler/BaseCaseMapper.java
+++ b/ycl-platform/src/main/java/com/ycl/mapper/caseHandler/BaseCaseMapper.java
@@ -58,4 +58,6 @@
     List<VideoAndAreaVO> areaCount();
 
     List<DelayDO> selectDelayVOList();
+
+    List<VideoAndAreaVO> selectType();
 }
diff --git a/ycl-platform/src/main/java/com/ycl/mapper/caseHandler/ViolationsMapper.java b/ycl-platform/src/main/java/com/ycl/mapper/caseHandler/ViolationsMapper.java
index 7208a5e..7a32068 100644
--- a/ycl-platform/src/main/java/com/ycl/mapper/caseHandler/ViolationsMapper.java
+++ b/ycl-platform/src/main/java/com/ycl/mapper/caseHandler/ViolationsMapper.java
@@ -17,5 +17,4 @@
 public interface ViolationsMapper extends BaseMapper<Violations> {
 
     ViolationsVO selectCondMap(Map map);
-
 }
diff --git a/ycl-platform/src/main/java/com/ycl/service/caseHandler/IBaseCaseService.java b/ycl-platform/src/main/java/com/ycl/service/caseHandler/IBaseCaseService.java
index db25560..bef1bc3 100644
--- a/ycl-platform/src/main/java/com/ycl/service/caseHandler/IBaseCaseService.java
+++ b/ycl-platform/src/main/java/com/ycl/service/caseHandler/IBaseCaseService.java
@@ -86,4 +86,4 @@
     List<VideoAndAreaVO> areaCount();
 
     List<DelayVO> selectDelayList();
-}
+}
\ No newline at end of file
diff --git a/ycl-platform/src/main/java/com/ycl/service/caseHandler/IViolationsService.java b/ycl-platform/src/main/java/com/ycl/service/caseHandler/IViolationsService.java
index d453d4d..2889d34 100644
--- a/ycl-platform/src/main/java/com/ycl/service/caseHandler/IViolationsService.java
+++ b/ycl-platform/src/main/java/com/ycl/service/caseHandler/IViolationsService.java
@@ -3,6 +3,7 @@
 import com.ycl.entity.caseHandler.Violations;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ycl.entity.video.VideoAlarmReport;
+import com.ycl.vo.cockpit.enforcementEvents.VideoAndAreaVO;
 
 import java.util.List;
 
@@ -25,4 +26,6 @@
      * @date 2022-09-26 17:25
      */
     void saveFromVideo(List<VideoAlarmReport> videoAlarmReports);
+
+    List<VideoAndAreaVO> selectType();
 }
diff --git a/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java b/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java
index 6e80c0d..9acb354 100644
--- a/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java
+++ b/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/BaseCaseServiceImpl.java
@@ -508,4 +508,5 @@
         });
         return delayVOS;
     }
+
 }
\ No newline at end of file
diff --git a/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/ViolationsServiceImpl.java b/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/ViolationsServiceImpl.java
index b3e236a..f04029a 100644
--- a/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/ViolationsServiceImpl.java
+++ b/ycl-platform/src/main/java/com/ycl/service/caseHandler/impl/ViolationsServiceImpl.java
@@ -8,13 +8,16 @@
 import com.ycl.entity.caseHandler.Violations;
 import com.ycl.entity.video.VideoAlarmReport;
 import com.ycl.entity.video.VideoPoint;
+import com.ycl.mapper.caseHandler.BaseCaseMapper;
 import com.ycl.mapper.caseHandler.ViolationsMapper;
 import com.ycl.service.caseHandler.IBaseCaseService;
 import com.ycl.service.caseHandler.IViolationsService;
 import com.ycl.service.video.impl.IVideoPointService;
+import com.ycl.vo.cockpit.enforcementEvents.VideoAndAreaVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.time.LocalDateTime;
 import java.util.List;
 
@@ -31,6 +34,9 @@
 
     private IVideoPointService videoPointService;
     private IBaseCaseService baseCaseService;
+
+    @Resource
+    BaseCaseMapper baseCaseMapper;
 
     @Autowired
     public void setVideoPointService(IVideoPointService videoPointService) {
@@ -58,7 +64,7 @@
                 baseCase.setLongitude(videoPoint.getLongitude());
                 baseCase.setStreetId(videoPoint.getStreetId());
                 baseCase.setCommunityId(videoPoint.getCommunityId());
-
+                baseCase.setSite(videoPoint.getAddress());
             }
             baseCaseService.save(baseCase);
             violations.setId(baseCase.getId());
@@ -67,4 +73,9 @@
             baseMapper.insert(violations);
         }
     }
-}
+
+    @Override
+    public List<VideoAndAreaVO> selectType() {
+        return  baseCaseMapper.selectType();
+    }
+}
\ No newline at end of file
diff --git a/ycl-platform/src/main/java/com/ycl/vo/TrendVo.java b/ycl-platform/src/main/java/com/ycl/vo/TrendVo.java
index fa9ccd9..44fa666 100644
--- a/ycl-platform/src/main/java/com/ycl/vo/TrendVo.java
+++ b/ycl-platform/src/main/java/com/ycl/vo/TrendVo.java
@@ -18,7 +18,7 @@
     private String name;
 
     @ApiModelProperty(value = "鎶ヨ鏁伴噺")
-    private String count;
+    private Long count;
 
     @ApiModelProperty(value = "鎶ヨ鏃ユ湡")
     private String dateTime;
diff --git a/ycl-platform/src/main/resources/mapper/caseHandler/BaseCaseMapper.xml b/ycl-platform/src/main/resources/mapper/caseHandler/BaseCaseMapper.xml
index bbea396..ae8aff0 100644
--- a/ycl-platform/src/main/resources/mapper/caseHandler/BaseCaseMapper.xml
+++ b/ycl-platform/src/main/resources/mapper/caseHandler/BaseCaseMapper.xml
@@ -329,4 +329,15 @@
                  LEFT JOIN ums_violations t3 on t1.id = t3.id
         WHERE t2.workflow_config_step_id IN (1, 2)
     </select>
+
+    <select id="selectType" resultType="com.ycl.vo.cockpit.enforcementEvents.VideoAndAreaVO">
+        SELECT
+            IFNULL( t2.`name`, "鍏朵粬" ) as name,
+            COUNT( 1 )  as count
+        FROM
+            ums_violations t1
+                LEFT JOIN ums_data_dictionary t2 ON t1.category_id = t2.id
+        GROUP BY
+            t1.category_id
+    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0