From 31c82154b7163ec55808ce7050b669c2e1b05170 Mon Sep 17 00:00:00 2001 From: wxc <191104855@qq.com> Date: Mon, 11 Nov 2024 17:15:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20BUG=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constants/enums/BusinessTypeEnum.java | 39 ++++--- .../ProfilePoliceController.java | 8 +- .../controller/work/NegativeController.java | 50 ++++---- .../pojo/domain/ProfilePolice.java | 3 + .../pojo/entity/NegativeScorePolice.java | 3 + .../service/BusinessPoliceService.java | 2 + .../supervision/service/ModelClueService.java | 2 + .../service/NegativeScorePoliceService.java | 9 +- .../service/ProfilePoliceService.java | 109 ++++++++++++++++++ 9 files changed, 181 insertions(+), 44 deletions(-) create mode 100644 src/main/java/com/biutag/supervision/service/ProfilePoliceService.java diff --git a/src/main/java/com/biutag/supervision/constants/enums/BusinessTypeEnum.java b/src/main/java/com/biutag/supervision/constants/enums/BusinessTypeEnum.java index 22749f3..f531bba 100644 --- a/src/main/java/com/biutag/supervision/constants/enums/BusinessTypeEnum.java +++ b/src/main/java/com/biutag/supervision/constants/enums/BusinessTypeEnum.java @@ -7,20 +7,19 @@ import lombok.Getter; @Getter public enum BusinessTypeEnum { - JCJ_110("110接处警", "1", "110"), - JCJ_122("122接处警", "2", "122"), - RJCKFW("人境窗口服务", "3", "RJ"), - CJGFF("车驾管服务", "4", "CJG"), - JJCF("交警执法", "5", "JJ"), - ZFBA("执法办案", "6", "CF"), - ZXGZ("专项工作", "7", "ZX"), - ABWW("安保维稳", "8", "AB"), - JAFK("治安防控", "9", "ZA"), - XZGL("行政管理", "10", "XZ"), - FFJC("服务基层", "12", "FF"), - DWGL("队伍管理", "13", "DW"), - QT("其他", "14", "QT"), - ; + JCJ_110("110接处警", "1", "110", true), + JCJ_122("122接处警", "2", "122", true), + RJCKFW("人境窗口服务", "3", "RJ", false), + CJGFF("车驾管服务", "4", "CJG", false), + JJCF("交警执法", "5", "JJ", false), + ZFBA("执法办案", "6", "CF", false), + ZXGZ("专项工作", "7", "ZX", false), + ABWW("安保维稳", "8", "AB", false), + JAFK("治安防控", "9", "ZA", false), + XZGL("行政管理", "10", "XZ", false), + FFJC("服务基层", "12", "FF", false), + DWGL("队伍管理", "13", "DW", false), + QT("其他", "14", "QT", false); private String label; @@ -28,6 +27,8 @@ public enum BusinessTypeEnum { private String key; + private Boolean businessVolume; + public static BusinessTypeEnum get(String value) { for (BusinessTypeEnum businessTypeEnum : values()) { if (businessTypeEnum.value.equals(value)) { @@ -36,4 +37,14 @@ public enum BusinessTypeEnum { } return null; } + + public static boolean isBusinessVolume(String value) { + for (BusinessTypeEnum businessTypeEnum : values()) { + if (businessTypeEnum.value.equals(value)) { + return businessTypeEnum.businessVolume; + } + } + return false; + } + } diff --git a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java index 481e3f2..6df2f7c 100644 --- a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java @@ -18,10 +18,7 @@ import com.biutag.supervision.pojo.entity.Negative; import com.biutag.supervision.pojo.entity.NegativeBlame; import com.biutag.supervision.pojo.model.PoliceNegativeModel; import com.biutag.supervision.pojo.param.DepartPoliceQueryParam; -import com.biutag.supervision.service.BusinessPoliceService; -import com.biutag.supervision.service.NegativeBlameService; -import com.biutag.supervision.service.NegativeService; -import com.biutag.supervision.service.SupPoliceService; +import com.biutag.supervision.service.*; import lombok.RequiredArgsConstructor; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.web.bind.annotation.GetMapping; @@ -44,6 +41,7 @@ import java.util.stream.Collectors; @RestController public class ProfilePoliceController { + private final ProfilePoliceService profilePoliceService; private final ProfilePoliceMapper profilePoliceMapper; private final SupPoliceService policeService; @@ -142,6 +140,8 @@ public class ProfilePoliceController { List problemTypeRadarData = problemTypeBarList.stream().map(BarItem::getValue).toList(); profilePolice.setProblemTypeRadarIndicator(problemTypeRadarIndicator); profilePolice.setProblemTypeRadarData(problemTypeRadarData); + // + profilePolice.setScore(profilePoliceService.getPoliceScore(beginTime, endTime, idCode)); return Result.success(profilePolice); } diff --git a/src/main/java/com/biutag/supervision/controller/work/NegativeController.java b/src/main/java/com/biutag/supervision/controller/work/NegativeController.java index 4ae2de4..dc096d2 100644 --- a/src/main/java/com/biutag/supervision/controller/work/NegativeController.java +++ b/src/main/java/com/biutag/supervision/controller/work/NegativeController.java @@ -121,32 +121,32 @@ public class NegativeController { DepartNegativeRate rate = departNegativeRateService.get(negative.getInvolveDepartId(), month); - List blames = blameService.list(id).stream().map(blame -> { - List problems = negativeProblemRelationService.list(id, blame.getBlameId()); - List codes = problems.stream().map(NegativeProblemRelation::getThreeLevelCode).toList(); - if (codes.isEmpty()) { - throw new RuntimeException("数据异常"); - } - SupDictProblemType problemType = supDictContentMapper.selectOneByMaxScore(codes); - - NegativeConfirmationCompletionVo.Blame b = new NegativeConfirmationCompletionVo.Blame(); - b.setProblems(problems); - b.setBlameId(blame.getBlameId()); - b.setBlameName(blame.getBlameName()); - b.setBlameEmpNo(blame.getBlameEmpNo()); - b.setBlameIdCode(blame.getBlameIdCode()); - b.setBaseScore(problemType.getScore()); - - int frequency = blameService.countByTrue(blame.getBlameIdCode(), problemType.getParentCode(), beginTime, endTime); - b.setFrequency(frequency); - b.setFrequencyScore(ScoreRule.getFrequencyScore(frequency)); - if (Objects.nonNull(rate)) { - b.setIncidenceRate(rate.getIncidenceRate()); - } - return b; - }).toList(); +// List blames = blameService.list(id).stream().map(blame -> { +// List problems = negativeProblemRelationService.list(id, blame.getBlameId()); +// List codes = problems.stream().map(NegativeProblemRelation::getThreeLevelCode).toList(); +// if (codes.isEmpty()) { +// throw new RuntimeException("数据异常"); +// } +// SupDictProblemType problemType = supDictContentMapper.selectOneByMaxScore(codes); +// +// NegativeConfirmationCompletionVo.Blame b = new NegativeConfirmationCompletionVo.Blame(); +// b.setProblems(problems); +// b.setBlameId(blame.getBlameId()); +// b.setBlameName(blame.getBlameName()); +// b.setBlameEmpNo(blame.getBlameEmpNo()); +// b.setBlameIdCode(blame.getBlameIdCode()); +// b.setBaseScore(problemType.getScore()); +// +// int frequency = blameService.countByTrue(blame.getBlameIdCode(), problemType.getParentCode(), beginTime, endTime); +// b.setFrequency(frequency); +// b.setFrequencyScore(ScoreRule.getFrequencyScore(frequency)); +// if (Objects.nonNull(rate)) { +// b.setIncidenceRate(rate.getIncidenceRate()); +// } +// return b; +// }).toList(); NegativeConfirmationCompletionVo completionVo = new NegativeConfirmationCompletionVo(); - completionVo.setBlames(blames); +// completionVo.setBlames(blames); return Result.success(completionVo); } diff --git a/src/main/java/com/biutag/supervision/pojo/domain/ProfilePolice.java b/src/main/java/com/biutag/supervision/pojo/domain/ProfilePolice.java index a69eb60..adf718d 100644 --- a/src/main/java/com/biutag/supervision/pojo/domain/ProfilePolice.java +++ b/src/main/java/com/biutag/supervision/pojo/domain/ProfilePolice.java @@ -5,6 +5,7 @@ import com.biutag.supervision.pojo.entity.SupPolice; import lombok.Getter; import lombok.Setter; +import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -16,6 +17,8 @@ import java.util.List; @Getter public class ProfilePolice { + private BigDecimal score; + private SupPolice policeInfo = new SupPolice(); private NegativeInfo negativeInfo = new NegativeInfo(); private List problemSourcesList = new ArrayList<>(); diff --git a/src/main/java/com/biutag/supervision/pojo/entity/NegativeScorePolice.java b/src/main/java/com/biutag/supervision/pojo/entity/NegativeScorePolice.java index 623bdad..0990ca8 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/NegativeScorePolice.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/NegativeScorePolice.java @@ -31,4 +31,7 @@ public class NegativeScorePolice { // 计算公式 private String expression; + // 业务类型 + private String businessTypeCode; + } \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/service/BusinessPoliceService.java b/src/main/java/com/biutag/supervision/service/BusinessPoliceService.java index a59c7fb..843ba3e 100644 --- a/src/main/java/com/biutag/supervision/service/BusinessPoliceService.java +++ b/src/main/java/com/biutag/supervision/service/BusinessPoliceService.java @@ -427,4 +427,6 @@ public class BusinessPoliceService extends ServiceImpl { negative.setProblemSources(ProblemSourcesEnum.LMGZ.getLabel()); negative.setProblemSourcesCode(ProblemSourcesEnum.LMGZ.getValue()); // TODO 业务类别 涉及问题 + negative.setBusinessTypeCode(BusinessTypeEnum.QT.getValue()); + negative.setBusinessTypeName(BusinessTypeEnum.QT.getLabel()); // 涉及单位 negative.setInvolveDepartId(item.getInvolveDepartId()); negative.setInvolveDepartName(item.getInvolveDepartName()); diff --git a/src/main/java/com/biutag/supervision/service/NegativeScorePoliceService.java b/src/main/java/com/biutag/supervision/service/NegativeScorePoliceService.java index bd214cb..9eaa46e 100644 --- a/src/main/java/com/biutag/supervision/service/NegativeScorePoliceService.java +++ b/src/main/java/com/biutag/supervision/service/NegativeScorePoliceService.java @@ -2,10 +2,11 @@ package com.biutag.supervision.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.biutag.supervision.pojo.entity.NegativeScorePolice; import com.biutag.supervision.mapper.NegativeScorePoliceMapper; +import com.biutag.supervision.pojo.entity.NegativeScorePolice; import org.springframework.stereotype.Service; +import java.util.Date; import java.util.List; @Service @@ -15,4 +16,10 @@ public class NegativeScorePoliceService extends ServiceImpl().eq(NegativeScorePolice::getNegativeId, negativeId)); } + + public List list(Date beginTime, Date endTime) { + return list(new LambdaQueryWrapper() + .between(NegativeScorePolice::getDiscoveryTime, beginTime, endTime)); + } + } diff --git a/src/main/java/com/biutag/supervision/service/ProfilePoliceService.java b/src/main/java/com/biutag/supervision/service/ProfilePoliceService.java new file mode 100644 index 0000000..36b41b3 --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/ProfilePoliceService.java @@ -0,0 +1,109 @@ +package com.biutag.supervision.service; + +import cn.hutool.core.util.NumberUtil; +import com.biutag.supervision.constants.enums.BusinessTypeEnum; +import com.biutag.supervision.pojo.entity.NegativeScorePolice; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * + * @author wxc + * @date 2024/11/11 + */ +// 平均问题数 = 总问题数 / 业务涉及人数 +// 业务标准差 = sum((个人问题数 - 平均问题数)²) / 业务涉及人数 +// 业务差异值1 = (问题发生率 - 平均问题发生率) / 业务标准差 +// 业务差异值2 = (问题数 - 平均问题数) / 业务标准差 +// 业务风险指数 = 50 + (业务差异值 * 15) +// 业务权重 = 单个业务风险指数 / 总业务风险指数之和 +// 个人风险指数 = sum(业务风险指数 * 业务权重) +@RequiredArgsConstructor +@Service +public class ProfilePoliceService { + + private final NegativeScorePoliceService negativeScorePoliceService; + + // 业务权重 = 单个业务风险指数 / 总业务风险指数之和 + public double getBusinessWeight(Double totalScore, List businessScorePolice) { + if (totalScore == 0) { + return 0.0; + } + Double score = businessScorePolice.stream().mapToDouble(NegativeScorePolice::getScore).sum(); + return NumberUtil.div(score, totalScore); + } + + // 平均问题数 = 单个业务问题数 / 业务涉及人数 + public double getAvgNumber(int size, int policeSize) { + if (policeSize == 0) { + return 0; + } + return NumberUtil.div(size, policeSize); + } + + // 业务标准差 = 根号(sum((个人问题数 - 平均问题数)²) / 业务涉及人数) + public double getSd(List businessScorePolice, double avgNumber, int policeSize) { + if (policeSize == 0) { + return 0; + } + Map> group = businessScorePolice.stream().collect(Collectors.groupingBy(NegativeScorePolice::getIdCode)); + return Math.sqrt(group.values().stream().mapToDouble(val -> Math.pow(val.size() - avgNumber, 2)).sum() / policeSize); + } + + // 业务差异值2 = (问题数 - 平均问题数) / 业务标准差 + public double getDiff(List businessScorePolice, String idCode, double avgNumber, double sd) { + if (sd == 0) { + return 0; + } + long size = businessScorePolice.stream().filter(item -> idCode.equals(item.getIdCode())).count(); + return NumberUtil.div(size - avgNumber, sd); + } + + public double getBusinessScore(double diff) { + return 50 + (diff * 15); + } + + + // 平均问题数 = 单个业务问题数 / 业务涉及人数 + // 业务标准差 = sum((个人问题数 - 平均问题数)²) / 业务涉及人数 + // 业务差异值1 = (问题发生率 - 平均问题发生率) / 业务标准差 + // 业务差异值2 = (问题数 - 平均问题数) / 业务标准差 + // 业务风险指数 = 50 + (业务差异值 * 15) + // 业务权重 = 单个业务风险指数 / 总业务风险指数之和 + // 个人风险指数 = sum(业务风险指数 * 业务权重) + public BigDecimal getPoliceScore(Date beginTime, Date endTime, String idCode) { + List scorePolices = negativeScorePoliceService.list(beginTime, endTime); + Double totalScore = scorePolices.stream().mapToDouble(NegativeScorePolice::getScore).sum(); + double policeScore = Arrays.stream(BusinessTypeEnum.values()).mapToDouble(businessTypeEnum -> { + List businessScorePolice = scorePolices.stream().filter(item -> item.getBusinessTypeCode().equals(businessTypeEnum.getValue())).toList(); + // 业务涉及人数 + int policeSize = businessScorePolice.stream().map(NegativeScorePolice::getIdCode).collect(Collectors.toSet()).size(); + // 平均问题数 + double avgNumber = getAvgNumber(businessScorePolice.size(), policeSize); + // 业务标准差 + double sd = getSd(businessScorePolice, avgNumber, policeSize); + // 业务差异值 + double diff = 0; + if (businessTypeEnum.getBusinessVolume()) { + + } else { + diff = getDiff(businessScorePolice, idCode, avgNumber, sd); + } + // 业务风险指数 + double businessScore = getBusinessScore(diff); + // 业务权重 + double businessWeight = getBusinessWeight(totalScore, businessScorePolice); + return NumberUtil.mul(businessScore, businessWeight); + }).sum(); + return NumberUtil.roundHalfEven(policeScore, 2); + } + +}