From 3c5e8c0005211e64fd3be564615fb1bf9c4978dc Mon Sep 17 00:00:00 2001 From: kami <605128600@qq.com> Date: Sat, 16 Nov 2024 21:44:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=84=E8=AD=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supervision/config/InterceptorConfig.java | 1 + .../controller/datav/RiskDataController.java | 95 ++++++++++ .../work/AlarmNotificationController.java | 2 + .../mapper/NegativeBlameMapper.java | 4 +- .../mapper/NegativeScoreDepartMapper.java | 11 +- .../mapper/NegativeScorePoliceMapper.java | 28 ++- .../supervision/pojo/vo/RiskStatisticsVo.java | 24 +++ .../service/ProblemSourceService.java | 76 +++++--- .../service/RiskStatisticsService.java | 167 ++++++++++++++++++ 9 files changed, 380 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/biutag/supervision/controller/datav/RiskDataController.java create mode 100644 src/main/java/com/biutag/supervision/pojo/vo/RiskStatisticsVo.java create mode 100644 src/main/java/com/biutag/supervision/service/RiskStatisticsService.java diff --git a/src/main/java/com/biutag/supervision/config/InterceptorConfig.java b/src/main/java/com/biutag/supervision/config/InterceptorConfig.java index 08673e5..67d3995 100644 --- a/src/main/java/com/biutag/supervision/config/InterceptorConfig.java +++ b/src/main/java/com/biutag/supervision/config/InterceptorConfig.java @@ -34,6 +34,7 @@ public class InterceptorConfig implements WebMvcConfigurer { .excludePathPatterns("/login") .excludePathPatterns("/auth/self") .excludePathPatterns("/file/stream/**", "/templates/**") + .excludePathPatterns("/datav/risk/**") .excludePathPatterns("/score/**") .excludePathPatterns(List.of("/doc.html", "/webjars/**", "/favicon.ico", "/v3/api-docs/**")); diff --git a/src/main/java/com/biutag/supervision/controller/datav/RiskDataController.java b/src/main/java/com/biutag/supervision/controller/datav/RiskDataController.java new file mode 100644 index 0000000..1db629a --- /dev/null +++ b/src/main/java/com/biutag/supervision/controller/datav/RiskDataController.java @@ -0,0 +1,95 @@ +package com.biutag.supervision.controller.datav; + +import com.biutag.supervision.pojo.Result; +import com.biutag.supervision.pojo.vo.ProblemSourceStatisticsVo; +import com.biutag.supervision.pojo.vo.RiskStatisticsVo; +import com.biutag.supervision.service.ProblemSourceService; +import com.biutag.supervision.service.RiskStatisticsService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @author kami on 2024-11-16 19:16:04 + * @version 0.0.1 + * @since 1.8 + */ +@Slf4j +@RestController +@RequestMapping("/datav/risk") +@AllArgsConstructor +public class RiskDataController { + + private final ProblemSourceService sourceService; + + private final RiskStatisticsService statisticsService; + + @GetMapping("/total/statistics") + public Result totalStatistics() { + return Result.success(sourceService.totalStatistics()); + } + + @GetMapping("/area/risk/statistics") + public Result> areaRiskStatistics() { + return Result.success(statisticsService.riskStatisticsBigOrg()); + } + + @GetMapping("/risk/org/statistics") + public Result> riskOrgStatistics() { + return Result.success(statisticsService.riskStatisticsOrg("派出所")); + } + + @GetMapping("/risk/org/car/statistics") + public Result> riskOrgCarStatistics() { + return Result.success(statisticsService.riskStatisticsOrg("交警大队")); + } + + @GetMapping("/risk/police/a/statistics") + public Result> riskPoliceAStatistics() { + return Result.success(statisticsService.personStatistics()); + } + + @GetMapping("/risk/police/b/statistics") + public Result> riskPoliceBStatistics() { + return Result.success(statisticsService.personStatistics2()); + } + + @GetMapping("/risk/leader/statistics") + public Result> riskLeaderStatistics() { + return Result.success(statisticsService.leaderStatistics()); + } + // **********问题数************* + @GetMapping("/area/negative/statistics") + public Result> areaNegativeStatistics() { + return Result.success(sourceService.statisticsGroupRank3()); + } + + @GetMapping("/org/negative/statistics") + public Result> orgNegativeStatistics() { + return Result.success(sourceService.statisticsGroupRank2()); + } + + @GetMapping("/org/car/negative/statistics") + public Result> orgCarNegativeStatistics() { + return Result.success(sourceService.statisticsGroupRank()); + } + + @GetMapping("/police/a/negative/statistics") + public Result> policeANegativeStatistics() { + return Result.success(sourceService.personA()); + } + + @GetMapping("/police/b/negative/statistics") + public Result> policeBNegativeStatistics() { + return Result.success(sourceService.personB()); + } + + @GetMapping("/police/leader/negative/statistics") + public Result> policeLeaderNegativeStatistics() { + return Result.success(sourceService.personB()); + } +} diff --git a/src/main/java/com/biutag/supervision/controller/work/AlarmNotificationController.java b/src/main/java/com/biutag/supervision/controller/work/AlarmNotificationController.java index 71a2f3b..90a73e8 100644 --- a/src/main/java/com/biutag/supervision/controller/work/AlarmNotificationController.java +++ b/src/main/java/com/biutag/supervision/controller/work/AlarmNotificationController.java @@ -5,6 +5,8 @@ import com.biutag.supervision.pojo.Result; import com.biutag.supervision.pojo.entity.AlarmNotification; import com.biutag.supervision.pojo.param.AlarmParam; import com.biutag.supervision.service.AlarmNotificationService; +import com.biutag.supervision.service.ProblemSourceService; +import com.biutag.supervision.util.CompletableUtils.CompletableFutureUtil; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.PostMapping; diff --git a/src/main/java/com/biutag/supervision/mapper/NegativeBlameMapper.java b/src/main/java/com/biutag/supervision/mapper/NegativeBlameMapper.java index f654551..2555457 100644 --- a/src/main/java/com/biutag/supervision/mapper/NegativeBlameMapper.java +++ b/src/main/java/com/biutag/supervision/mapper/NegativeBlameMapper.java @@ -28,12 +28,12 @@ public interface NegativeBlameMapper extends BaseMapper { @Select(" SELECT blameIdCode, blameName, count(1) as number FROM `negative_blame` " + - " where blameIdCode is not null and LENGTH(blameIdCode) > 0 and ivPersonTypeCode = 1 " + + " where blameIdCode is not null and LENGTH(blameIdCode) > 0 and ivPersonTypeCode = '1' " + " GROUP BY blameIdCode order by number desc limit 10") List statisticsBlame(); @Select(" SELECT blameIdCode, blameName, count(1) as number FROM `negative_blame` " + - " where blameIdCode is not null and LENGTH(blameIdCode) > 0 and ivPersonTypeCode != 1 " + + " where blameIdCode is not null and LENGTH(blameIdCode) > 0 and ivPersonTypeCode != '1' " + " GROUP BY blameIdCode order by number desc limit 10") List statisticsBlame2(); diff --git a/src/main/java/com/biutag/supervision/mapper/NegativeScoreDepartMapper.java b/src/main/java/com/biutag/supervision/mapper/NegativeScoreDepartMapper.java index 6016442..0254552 100644 --- a/src/main/java/com/biutag/supervision/mapper/NegativeScoreDepartMapper.java +++ b/src/main/java/com/biutag/supervision/mapper/NegativeScoreDepartMapper.java @@ -2,7 +2,16 @@ package com.biutag.supervision.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.biutag.supervision.pojo.entity.NegativeScoreDepart; +import com.biutag.supervision.pojo.vo.RiskStatisticsVo; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; public interface NegativeScoreDepartMapper extends BaseMapper { -} \ No newline at end of file + @Select(" select depart_id as departId, sum(score) as score from negative_score_depart " + + " where discovery_time >= '2024-01-01 00:00:00' and depart_group_id = #{groupId} " + + " group by depart_id") + List statistics(@Param("groupId") String groupId); +} diff --git a/src/main/java/com/biutag/supervision/mapper/NegativeScorePoliceMapper.java b/src/main/java/com/biutag/supervision/mapper/NegativeScorePoliceMapper.java index 3d89117..9ddd2d7 100644 --- a/src/main/java/com/biutag/supervision/mapper/NegativeScorePoliceMapper.java +++ b/src/main/java/com/biutag/supervision/mapper/NegativeScorePoliceMapper.java @@ -2,7 +2,33 @@ package com.biutag.supervision.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.biutag.supervision.pojo.entity.NegativeScorePolice; +import com.biutag.supervision.pojo.vo.RiskStatisticsVo; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; public interface NegativeScorePoliceMapper extends BaseMapper { -} \ No newline at end of file + @Select(" select id_code as idCode, sum(score) as score from negative_score_police " + + " where id_code in ( " + + " select blameIdCode from negative_blame where ivPersonTypeCode = '1' " + + ") and discovery_time >= '2024-01-01 00:00:00' " + + " group by id_code order by score desc limit 10 ") + List statisticsPolice(); + + @Select(" select id_code as idCode, sum(score) as score from negative_score_police " + + " where id_code in ( " + + " select blameIdCode from negative_blame where ivPersonTypeCode != '1' " + + ") and discovery_time >= '2024-01-01 00:00:00' " + + " group by id_code order by score desc limit 10 ") + List statisticsPolice2(); + + @Select(" select id_code as idCode, sum(score) as score from negative_score_police " + + " where id_code in ( " + + " select leadIdCode from negative_blame where ivPersonTypeCode != '1' " + + ") and discovery_time >= '2024-01-01 00:00:00' " + + " group by id_code order by score desc limit 10 ") + List statisticsLeader(); + +} diff --git a/src/main/java/com/biutag/supervision/pojo/vo/RiskStatisticsVo.java b/src/main/java/com/biutag/supervision/pojo/vo/RiskStatisticsVo.java new file mode 100644 index 0000000..4e4cb59 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/vo/RiskStatisticsVo.java @@ -0,0 +1,24 @@ +package com.biutag.supervision.pojo.vo; + +import lombok.Data; + +/** + * @author kami on 2024-11-16 18:22:46 + * @version 0.0.1 + * @since 1.8 + */ +@Data +public class RiskStatisticsVo { + + String name; + + String idCode; + + String departId; + + Double score; + + Integer value; + + String label; +} diff --git a/src/main/java/com/biutag/supervision/service/ProblemSourceService.java b/src/main/java/com/biutag/supervision/service/ProblemSourceService.java index 9ed34b3..3607b1a 100644 --- a/src/main/java/com/biutag/supervision/service/ProblemSourceService.java +++ b/src/main/java/com/biutag/supervision/service/ProblemSourceService.java @@ -6,6 +6,7 @@ import com.biutag.supervision.pojo.entity.*; import com.biutag.supervision.pojo.vo.BlamePerson; import com.biutag.supervision.pojo.vo.ProblemSourceStatisticsVo; import com.biutag.supervision.pojo.vo.ProblemSourceVo; +import com.biutag.supervision.pojo.vo.RiskStatisticsVo; import com.biutag.supervision.util.CompletableUtils.CompletableFutureUtil; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -50,7 +51,9 @@ public class ProblemSourceService { CompletableFutureUtil.runSyncObject(() -> build.caseTotal(businessDepartMapper.problemSum(List.of(4, 5, 6), "2024-01-01 00:00:00"))), CompletableFutureUtil.runSyncObject(() -> build.negativeTotal(negativeMapper.selectCount(new LambdaQueryWrapper().in(Negative::getCheckStatus, List.of(1, 2))).intValue())) ).join(); - List list = blameMapper.selectList(new LambdaQueryWrapper().select(NegativeBlame::getBlameIdCode)); + List list = blameMapper.selectList(new LambdaQueryWrapper() + .select(NegativeBlame::getBlameIdCode) + .isNotNull(NegativeBlame::getBlameIdCode)); Long count = list.stream().map(NegativeBlame::getBlameIdCode).distinct().count(); build.peopleCount(count.intValue()); ProblemSourceStatisticsVo vo = build.build(); @@ -98,8 +101,9 @@ public class ProblemSourceService { private final StatisticsDepartMapper departMapper; - public void statisticsGroupRank() { - StatisticsGroup group = statisticsGroupMapper.selectOne(new LambdaQueryWrapper() + public List statisticsGroupRank() { + StatisticsGroup group = statisticsGroupMapper + .selectOne(new LambdaQueryWrapper() .eq(StatisticsGroup::getName, "交警大队").last("limit 1")); List list = departMapper.selectList(new LambdaQueryWrapper() @@ -119,15 +123,24 @@ public class ProblemSourceService { count++; mapLevel3.put(negative.getInvolveDepartId(), count); } + List vo = new ArrayList<>(); for (Map.Entry entry : mapLevel3.entrySet()) { - log.info("机构:{} | {}", departMap.get(entry.getKey()).getName(), entry.getValue()); + RiskStatisticsVo v = new RiskStatisticsVo(); + v.setLabel(departMap.get(entry.getKey()).getName().replaceFirst("湖南省长沙市公安局", "").replaceFirst("湖南省长沙市", "").replaceFirst("湖南省", "")); + v.setValue(entry.getValue()); + vo.add(v); + } + vo.sort(Comparator.comparing(RiskStatisticsVo::getValue, Comparator.reverseOrder())); + if(vo.size() > 10) { + return vo.subList(0,10); } + return vo; } /** * 派出所 */ - public void statisticsGroupRank2() { + public List statisticsGroupRank2() { StatisticsGroup group = statisticsGroupMapper.selectOne(new LambdaQueryWrapper() .eq(StatisticsGroup::getName, "派出所").last("limit 1")); @@ -148,13 +161,22 @@ public class ProblemSourceService { count++; mapLevel3.put(negative.getInvolveDepartId(), count); } + List vo = new ArrayList<>(); for (Map.Entry entry : mapLevel3.entrySet()) { - log.info("机构:{} | {}", departMap.get(entry.getKey()).getName(), entry.getValue()); + RiskStatisticsVo v = new RiskStatisticsVo(); + v.setLabel(departMap.get(entry.getKey()).getName().replaceFirst("湖南省长沙市公安局", "").replaceFirst("湖南省长沙市", "").replaceFirst("湖南省", "")); + v.setValue(entry.getValue()); + vo.add(v); + } + vo.sort(Comparator.comparing(RiskStatisticsVo::getValue, Comparator.reverseOrder())); + if(vo.size() > 10) { + return vo.subList(0,10); } + return vo; } // 分县 - public void statisticsGroupRank3() { + public List statisticsGroupRank3() { StatisticsGroup group = statisticsGroupMapper.selectOne(new LambdaQueryWrapper() .eq(StatisticsGroup::getName, "派出所").last("limit 1")); @@ -184,32 +206,38 @@ public class ProblemSourceService { count++; mapLevel3.put(negative.getInvolveDepartId(), count); } + List vo = new ArrayList<>(); for (Map.Entry entry : mapLevel3.entrySet()) { - log.info("机构:{} | {}", areaMap.get(entry.getKey()).getName(), entry.getValue()); + RiskStatisticsVo v = new RiskStatisticsVo(); + v.setLabel(areaMap.get(entry.getKey()).getName().replaceFirst("湖南省长沙市公安局", "").replaceFirst("湖南省长沙市", "").replaceFirst("湖南省", "")); + v.setValue(entry.getValue()); + vo.add(v); } + vo.sort(Comparator.comparing(RiskStatisticsVo::getValue, Comparator.reverseOrder())); + return vo; } + public List personA() { + return trans(blameMapper.statisticsBlame()); + } - /** - * 民警、辅警 - */ - public void personStatistics() { - List list = blameMapper.statisticsBlame(); - - List list2 = blameMapper.statisticsBlame2(); - - List list3 = blameMapper.statisticsBlame3(); + public List personB() { + return trans(blameMapper.statisticsBlame2()); + } + public List leader() { + return trans(blameMapper.statisticsBlame3()); + } + List trans(List list) { + List vo = new ArrayList<>(); for (BlamePerson blamePerson : list) { - log.info("民警:{} | {}", blamePerson.getBlameName(), blamePerson.getNumber()); - } - for (BlamePerson blamePerson : list2) { - log.info("辅警:{} | {}", blamePerson.getBlameName(), blamePerson.getNumber()); - } - for (BlamePerson blamePerson : list3) { - log.info("领导:{} | {}", blamePerson.getBlameName(), blamePerson.getNumber()); + RiskStatisticsVo v = new RiskStatisticsVo(); + v.setLabel(blamePerson.getBlameName()); + v.setValue(blamePerson.getNumber()); + vo.add(v); } + return vo; } } diff --git a/src/main/java/com/biutag/supervision/service/RiskStatisticsService.java b/src/main/java/com/biutag/supervision/service/RiskStatisticsService.java new file mode 100644 index 0000000..3975ad1 --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/RiskStatisticsService.java @@ -0,0 +1,167 @@ +package com.biutag.supervision.service; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.biutag.supervision.mapper.*; +import com.biutag.supervision.pojo.entity.NegativeBlame; +import com.biutag.supervision.pojo.entity.StatisticsGroup; +import com.biutag.supervision.pojo.entity.SupDepart; +import com.biutag.supervision.pojo.vo.RiskStatisticsVo; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * @author kami on 2024-11-16 18:22:13 + * @version 0.0.1 + * @since 1.8 + */ +@Slf4j +@Service +@AllArgsConstructor +public class RiskStatisticsService { + + private final StatisticsGroupMapper statisticsGroupMapper; + + private final NegativeScoreDepartMapper negativeScoreDepartMapper; + + private final SupDepartMapper supDepartMapper; + + + /** + * 分机构统计风险分 + * + * @param name 机构类型名称 + * @return 列表 + */ + public List riskStatisticsOrg(String name) { + List departs = supDepartMapper.selectList(new LambdaQueryWrapper() + .select(SupDepart::getId, SupDepart::getPid, SupDepart::getName, SupDepart::getLevel)); + Map departMap = departs.stream().collect(Collectors.toMap(SupDepart::getId, Function.identity(), (oldValue, newValue) -> newValue)); + + StatisticsGroup group = statisticsGroupMapper.selectOne(new LambdaQueryWrapper() + .eq(StatisticsGroup::getName, name).last("limit 1")); + List vo = negativeScoreDepartMapper.statistics(group.getGroupId()); + vo.sort(Comparator.comparing(RiskStatisticsVo::getScore, Comparator.reverseOrder())); + if (vo.size() > 10) { + vo = vo.subList(0, 10); + } + // 补名字 + for (RiskStatisticsVo r : vo) { + SupDepart depart = departMap.get(r.getDepartId()); + r.setName(depart.getName().replaceFirst("湖南省长沙市公安局", "").replaceFirst("湖南省长沙市", "").replaceFirst("湖南省", "")); + } + return vo; + } + + /** + * 分县统计风险分 + * + * @return 列表 + */ + public List riskStatisticsBigOrg() { + StatisticsGroup group = statisticsGroupMapper.selectOne(new LambdaQueryWrapper() + .eq(StatisticsGroup::getName, "派出所").last("limit 1")); + List vo = negativeScoreDepartMapper.statistics(group.getGroupId()); + + List departs = supDepartMapper.selectList(new LambdaQueryWrapper() + .select(SupDepart::getId, SupDepart::getPid, SupDepart::getName, SupDepart::getLevel)); + Map areaMap = departs.stream().collect(Collectors.toMap(SupDepart::getId, Function.identity(), (oldValue, newValue) -> newValue)); + + Map map = new HashMap<>(); + for (RiskStatisticsVo depart : vo) { + SupDepart department = areaMap.get(depart.getDepartId()); + if(department == null) { + log.info("统计未找到该id的机构:{}", depart.getDepartId()); + continue; + } + SupDepart area = areaMap.get(department.getPid()); + Double score = Optional.ofNullable(map.get(area.getId())).orElse(0.0); + score += depart.getScore(); + map.put(area.getId(), score); + } + List result = new ArrayList<>(); + for (Map.Entry entry : map.entrySet()) { + RiskStatisticsVo tmp = new RiskStatisticsVo(); + tmp.setDepartId(entry.getKey()); + tmp.setScore(entry.getValue()); + SupDepart depart = areaMap.get(entry.getKey()); + tmp.setName(depart.getName().replaceFirst("湖南省长沙市公安局", "").replaceFirst("湖南省长沙市", "").replaceFirst("湖南省", "")); + result.add(tmp); + } + return result; + } + + private final NegativeBlameMapper blameMapper; + + private final NegativeScorePoliceMapper policeMapper; + + /** + * 民警 + * + * @return + */ + public List personStatistics() { + List blames = blameMapper.selectList(new LambdaQueryWrapper() + .select(NegativeBlame::getBlameName, NegativeBlame::getBlameIdCode) + .isNotNull(NegativeBlame::getBlameIdCode) + .eq(NegativeBlame::getIvPersonTypeCode, "1")); + Map blameMap = blames.stream().collect(Collectors.toMap(NegativeBlame::getBlameIdCode, Function.identity(), (oldValue, newValue) -> newValue)); + List list = policeMapper.statisticsPolice(); + for (RiskStatisticsVo riskStatisticsVo : list) { + NegativeBlame map = blameMap.get(riskStatisticsVo.getIdCode()); + if (map == null) { + continue; + } + riskStatisticsVo.setName(map.getBlameName()); + } + return list; + } + + /** + * 辅警/协警 + * + * @return + */ + public List personStatistics2() { + List blames = blameMapper.selectList(new LambdaQueryWrapper() + .select(NegativeBlame::getBlameName, NegativeBlame::getBlameIdCode) + .isNotNull(NegativeBlame::getBlameIdCode) + .ne(NegativeBlame::getIvPersonTypeCode, "1")); + Map blameMap = blames.stream().collect(Collectors.toMap(NegativeBlame::getBlameIdCode, Function.identity(), (oldValue, newValue) -> newValue)); + List list = policeMapper.statisticsPolice2(); + for (RiskStatisticsVo riskStatisticsVo : list) { + NegativeBlame map = blameMap.get(riskStatisticsVo.getIdCode()); + if (map == null) { + continue; + } + riskStatisticsVo.setName(map.getBlameName()); + } + return list; + } + + /** + * 领导 + * + * @return + */ + public List leaderStatistics() { + List blames = blameMapper.selectList(new LambdaQueryWrapper() + .select(NegativeBlame::getLeadIdCode, NegativeBlame::getLeadName) + .isNotNull(NegativeBlame::getLeadIdCode) + .ne(NegativeBlame::getIvPersonTypeCode, "1")); + Map blameMap = blames.stream().collect(Collectors.toMap(NegativeBlame::getLeadIdCode, Function.identity(), (oldValue, newValue) -> newValue)); + List list = policeMapper.statisticsLeader(); + for (RiskStatisticsVo riskStatisticsVo : list) { + NegativeBlame map = blameMap.get(riskStatisticsVo.getIdCode()); + if (map == null) { + continue; + } + riskStatisticsVo.setName(map.getLeadName()); + } + return list; + } +}