From f3e9db45cbe3e1e22f060105b563c70b37a3460f Mon Sep 17 00:00:00 2001 From: wxc <191104855@qq.com> Date: Wed, 13 Nov 2024 11:23:47 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E8=B5=8B=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constants/enums/FlowNodeEnum.java | 4 +- .../ProfilePoliceController.java | 1 - .../sensitivePerception/ScoreController.java | 77 +++++++++++++++++++ .../flow/action/ApplyExtensionAction.java | 12 +-- .../supervision/mapper/DepartScoreMapper.java | 16 ++++ .../mapper/NegativeBlameMapper.java | 6 +- .../supervision/mapper/PoliceScoreMapper.java | 15 ++++ .../supervision/pojo/entity/DepartScore.java | 32 ++++++++ .../supervision/pojo/entity/PoliceScore.java | 32 ++++++++ .../service/DepartScoreService.java | 11 +++ .../service/NegativeScoreService.java | 9 ++- .../service/PoliceScoreService.java | 17 ++++ .../resources/mapper/ProfileDepartMapper.xml | 10 ++- .../resources/mapper/ProfilePoliceMapper.xml | 10 ++- .../supervision/tools/GenCodeTests.java | 2 +- 15 files changed, 235 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/biutag/supervision/controller/sensitivePerception/ScoreController.java create mode 100644 src/main/java/com/biutag/supervision/mapper/DepartScoreMapper.java create mode 100644 src/main/java/com/biutag/supervision/mapper/PoliceScoreMapper.java create mode 100644 src/main/java/com/biutag/supervision/pojo/entity/DepartScore.java create mode 100644 src/main/java/com/biutag/supervision/pojo/entity/PoliceScore.java create mode 100644 src/main/java/com/biutag/supervision/service/DepartScoreService.java create mode 100644 src/main/java/com/biutag/supervision/service/PoliceScoreService.java diff --git a/src/main/java/com/biutag/supervision/constants/enums/FlowNodeEnum.java b/src/main/java/com/biutag/supervision/constants/enums/FlowNodeEnum.java index b8b61c9..8bbe13c 100644 --- a/src/main/java/com/biutag/supervision/constants/enums/FlowNodeEnum.java +++ b/src/main/java/com/biutag/supervision/constants/enums/FlowNodeEnum.java @@ -16,8 +16,8 @@ public enum FlowNodeEnum { VERIFY("verify"), SECOND_APPROVE("second_approve"), FIRST_APPROVE("first_approve"), - SECOND_EXTENSION_APPROVE("first_approve"), - FIRST_EXTENSION_APPROVE("first_approve"), + SECOND_EXTENSION_APPROVE("second_extension_approve"), + FIRST_EXTENSION_APPROVE("first_extension_approve"), COMPLETED("completed"); private String key; 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 1d9a0b8..4e4d6cc 100644 --- a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java @@ -44,7 +44,6 @@ import java.util.stream.Collectors; @RestController public class ProfilePoliceController { - private final ScoreService profilePoliceService; private final ProfilePoliceMapper profilePoliceMapper; private final SupPoliceService policeService; diff --git a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ScoreController.java b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ScoreController.java new file mode 100644 index 0000000..0bd5ef2 --- /dev/null +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ScoreController.java @@ -0,0 +1,77 @@ +package com.biutag.supervision.controller.sensitivePerception; + +import com.biutag.supervision.mapper.DepartScoreMapper; +import com.biutag.supervision.mapper.PoliceScoreMapper; +import com.biutag.supervision.pojo.Result; +import com.biutag.supervision.pojo.entity.DepartScore; +import com.biutag.supervision.pojo.entity.PoliceScore; +import com.biutag.supervision.pojo.entity.SupDepart; +import com.biutag.supervision.pojo.entity.SupPolice; +import com.biutag.supervision.service.NegativeScoreService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Date; +import java.util.List; + +/** + * @author wxc + * @date 2024/11/13 + */ +@Slf4j +@RequestMapping("score") +@RequiredArgsConstructor +@RestController +public class ScoreController { + + private final PoliceScoreMapper policeScoreMapper; + + private final DepartScoreMapper departScoreMapper; + + private final NegativeScoreService negativeScoreService; + + @RequestMapping("police") + public Result updatePoliceScore() { + List supPolices = policeScoreMapper.listPolice(); + Date endTime = new Date(); + LocalDateTime localDateTime = LocalDateTime.of(2024, 1, 1, 0, 0, 0); + Date beginTime = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); + supPolices.forEach(item -> { + List result = negativeScoreService.calculatePoliceScore(beginTime, endTime, item.getIdCode()); + PoliceScore score = new PoliceScore(); + score.setIdCode(item.getIdCode()); + score.setScore((Double) result.get(0)); + score.setExpression((String) result.get(1)); + score.setBeginTime(beginTime); + score.setEndTime(endTime); + score.setCreateTime(new Date()); + policeScoreMapper.insert(score); + }); + return Result.success("success"); + } + + @RequestMapping("depart") + public Result updateDepartScore() { + List supDeparts = departScoreMapper.listDepart(); + Date endTime = new Date(); + LocalDateTime localDateTime = LocalDateTime.of(2024, 1, 1, 0, 0, 0); + Date beginTime = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant()); + supDeparts.forEach(item -> { + List result = negativeScoreService.calculateDepartScore(beginTime, endTime, item.getId()); + DepartScore score = new DepartScore(); + score.setDepartId(item.getId()); + score.setScore((Double) result.get(0)); + score.setExpression((String) result.get(1)); + score.setBeginTime(beginTime); + score.setEndTime(endTime); + score.setCreateTime(new Date()); + departScoreMapper.insert(score); + }); + return Result.success("success"); + } + +} diff --git a/src/main/java/com/biutag/supervision/flow/action/ApplyExtensionAction.java b/src/main/java/com/biutag/supervision/flow/action/ApplyExtensionAction.java index 8c391b7..0df69bd 100644 --- a/src/main/java/com/biutag/supervision/flow/action/ApplyExtensionAction.java +++ b/src/main/java/com/biutag/supervision/flow/action/ApplyExtensionAction.java @@ -5,14 +5,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.biutag.supervision.common.UserContextHolder; import com.biutag.supervision.constants.AppConstants; +import com.biutag.supervision.constants.enums.FlowActionEnum; +import com.biutag.supervision.constants.enums.FlowNodeEnum; import com.biutag.supervision.constants.enums.RoleCodeEnum; import com.biutag.supervision.constants.enums.WorkStatusEnum; import com.biutag.supervision.pojo.dto.ActionDto; import com.biutag.supervision.pojo.dto.flow.ExtensionApplyData; -import com.biutag.supervision.pojo.entity.Negative; -import com.biutag.supervision.pojo.entity.NegativeExtensionApply; -import com.biutag.supervision.pojo.entity.NegativeWork; -import com.biutag.supervision.pojo.entity.SupDepart; +import com.biutag.supervision.pojo.entity.*; import com.biutag.supervision.pojo.model.UserAuth; import com.biutag.supervision.service.NegativeExtensionApplyService; import com.biutag.supervision.service.NegativeService; @@ -76,16 +75,19 @@ public class ApplyExtensionAction implements Action { String roleCode; String departId; String departName; + String flowKey; // 是否是二级机构办理 if (negative.getIsSecondHandle()) { roleCode = RoleCodeEnum.FIRST_ADMIN.getCode(); departId = AppConstants.ROOT_DEPART_ID; departName = AppConstants.ROOT_DEPART_NAME; + flowKey = FlowNodeEnum.FIRST_EXTENSION_APPROVE.getKey(); } else { roleCode = RoleCodeEnum.SECOND_ADMIN.getCode(); SupDepart parentDepart = departService.getParentDepart(currentWork.getDepartId()); departId = parentDepart.getId(); departName = parentDepart.getShortName(); + flowKey = actionDto.getNextFlowKey(); } workService.remove(new LambdaQueryWrapper() .eq(NegativeWork::getNegativeId, actionDto.getNegativeId()) @@ -98,7 +100,7 @@ public class ApplyExtensionAction implements Action { .setDepartId(departId) .setDepartName(departName) .setProblemSourcesCode(negative.getProblemSourcesCode()) - .setFlowKey(actionDto.getNextFlowKey()) + .setFlowKey(flowKey) .setCreateTime(LocalDateTime.now()) .setUpdateTime(LocalDateTime.now()) .setStatus(WorkStatusEnum.todo.name()); diff --git a/src/main/java/com/biutag/supervision/mapper/DepartScoreMapper.java b/src/main/java/com/biutag/supervision/mapper/DepartScoreMapper.java new file mode 100644 index 0000000..856f3ce --- /dev/null +++ b/src/main/java/com/biutag/supervision/mapper/DepartScoreMapper.java @@ -0,0 +1,16 @@ +package com.biutag.supervision.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.biutag.supervision.pojo.entity.DepartScore; +import com.biutag.supervision.pojo.entity.SupDepart; +import com.biutag.supervision.pojo.entity.SupPolice; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +public interface DepartScoreMapper extends BaseMapper { + + @Select("select d.id from sup_depart d left join negative_score_depart sd on d.id = sd.depart_id where sd.depart_id is not null GROUP BY d.id") + List listDepart(); + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/mapper/NegativeBlameMapper.java b/src/main/java/com/biutag/supervision/mapper/NegativeBlameMapper.java index 37715d9..83c1f06 100644 --- a/src/main/java/com/biutag/supervision/mapper/NegativeBlameMapper.java +++ b/src/main/java/com/biutag/supervision/mapper/NegativeBlameMapper.java @@ -19,9 +19,9 @@ public interface NegativeBlameMapper extends BaseMapper { @Select("select count(DISTINCT n.id) from negative n left join negative_blame nb on n.id = nb.negativeId left join negative_problem_relation pr on pr.negativeId = n.id and pr.blameId = nb.blameId where n.checkStatus in ('1', '2') and n.discoveryTime BETWEEN #{beginTime} and #{endTime} and nb.blameIdCode = #{idCode} and pr.twoLevelCode = #{twoLevelCode}") int selectCountByTrue(String idCode, String twoLevelCode, LocalDateTime beginTime, LocalDateTime endTime); - @Select("select DISTINCT nb.* from negative_blame nb left join negative n on nb.negativeId = n.id left join negative_score_police sp on " + - "sp.negative_id = nb.negativeId and sp.id_code = nb.blameIdCode left join negative_problem_relation pr on pr.negativeId = nb.negativeId and pr.blameId = nb.blameId " + - "where n.checkStatus in ('1', '2') and n.processing_status = 'completed' and sp.negative_id is null and pr.threeLevelCode is not null") + @Select("select DISTINCT nb.* from negative_blame nb left join negative n on nb.negativeId = n.id " + + "left join negative_problem_relation pr on pr.negativeId = nb.negativeId and pr.blameId = nb.blameId " + + "where n.checkStatus in ('1', '2') and n.processing_status = 'completed' and pr.threeLevelCode is not null") List selectVerifyTrue(); } \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/mapper/PoliceScoreMapper.java b/src/main/java/com/biutag/supervision/mapper/PoliceScoreMapper.java new file mode 100644 index 0000000..bd5c57e --- /dev/null +++ b/src/main/java/com/biutag/supervision/mapper/PoliceScoreMapper.java @@ -0,0 +1,15 @@ +package com.biutag.supervision.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.biutag.supervision.pojo.entity.PoliceScore; +import com.biutag.supervision.pojo.entity.SupPolice; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +public interface PoliceScoreMapper extends BaseMapper { + + @Select("select p.id_code from sup_police p left join negative_score_police sp on p.id_code = sp.id_code where sp.id_code is not null GROUP BY p.id_code") + List listPolice(); + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/entity/DepartScore.java b/src/main/java/com/biutag/supervision/pojo/entity/DepartScore.java new file mode 100644 index 0000000..ea4e503 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/entity/DepartScore.java @@ -0,0 +1,32 @@ +package com.biutag.supervision.pojo.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Getter; +import lombok.Setter; + +import java.util.Date; + +@Setter +@Getter +public class DepartScore { + + // + @TableId(value = "depart_id") + private String departId; + + // + @TableField("score") + private Double score; + + // + @TableField("expression") + private String expression; + + private Date createTime; + + private Date beginTime; + + private Date endTime; + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/entity/PoliceScore.java b/src/main/java/com/biutag/supervision/pojo/entity/PoliceScore.java new file mode 100644 index 0000000..f425bd1 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/entity/PoliceScore.java @@ -0,0 +1,32 @@ +package com.biutag.supervision.pojo.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import lombok.Getter; +import lombok.Setter; + +import java.util.Date; + +@Setter +@Getter +public class PoliceScore { + + // + @TableId(value = "id_code") + private String idCode; + + // + @TableField("score") + private Double score; + + // + @TableField("expression") + private String expression; + + private Date createTime; + + private Date beginTime; + + private Date endTime; + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/service/DepartScoreService.java b/src/main/java/com/biutag/supervision/service/DepartScoreService.java new file mode 100644 index 0000000..879c38e --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/DepartScoreService.java @@ -0,0 +1,11 @@ +package com.biutag.supervision.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.biutag.supervision.pojo.entity.DepartScore; +import com.biutag.supervision.mapper.DepartScoreMapper; +import org.springframework.stereotype.Service; + +@Service +public class DepartScoreService extends ServiceImpl { + +} diff --git a/src/main/java/com/biutag/supervision/service/NegativeScoreService.java b/src/main/java/com/biutag/supervision/service/NegativeScoreService.java index 9178e01..3da774c 100644 --- a/src/main/java/com/biutag/supervision/service/NegativeScoreService.java +++ b/src/main/java/com/biutag/supervision/service/NegativeScoreService.java @@ -10,6 +10,7 @@ import com.biutag.supervision.mapper.SupDictContentMapper; import com.biutag.supervision.pojo.entity.*; import com.biutag.supervision.util.ScoreRule; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; @@ -23,6 +24,7 @@ import java.util.stream.Collectors; * @author wxc * @date 2024/11/12 */ +@Slf4j @RequiredArgsConstructor @Service public class NegativeScoreService { @@ -50,6 +52,7 @@ public class NegativeScoreService { flag.set(true); System.out.println("calculateScore-------------------------------------------------"); List negativeBlames = blameMapper.selectVerifyTrue(); + log.info("总共问题条数:{}", negativeBlames.size()); if (negativeBlames.isEmpty()) { flag.set(false); return; @@ -61,9 +64,10 @@ public class NegativeScoreService { Set negativeIds = negativeBlames.stream().map(NegativeBlame::getNegativeId).collect(Collectors.toSet()); List problemsAll = problemRelationService.list(negativeIds); List negatives = negativeService.listByIds(negativeIds); + List departs = departService.listByIds(negatives.stream().map(Negative::getInvolveDepartId).collect(Collectors.toSet())); negativeBlames.forEach(blame -> { Negative negative = negatives.stream().filter(item -> item.getId().equals(blame.getNegativeId())).findFirst().get(); - SupDepart depart = departService.getById(negative.getInvolveDepartId()); + SupDepart depart = departs.stream().filter(item -> item.getId().equals(negative.getInvolveDepartId())).findFirst().get(); NegativeScorePolice negativeScorePolice = new NegativeScorePolice() .setNegativeId(blame.getNegativeId()) .setIdCode(blame.getBlameIdCode()) @@ -236,6 +240,7 @@ public class NegativeScoreService { double[] diffNumbers = group.values().stream().mapToDouble(val -> val.size() - avgNumber).toArray(); // 业务标准差 double sd = calculateSd(diffNumbers, policeSize); + log.info("业务标准差为:{}", sd); // 业务差异值 double diff; long personalSize = businessScorePolice.stream().filter(item -> idCode.equals(item.getIdCode())).count(); @@ -244,8 +249,10 @@ public class NegativeScoreService { } else { diff = calculateDiff2(personalSize, avgNumber, sd); } + log.info("业务差异值为:{}", diff); // 业务风险指数 double businessScore = calculateBusinessScore(diff, personalSize); + log.info("业务风险指数:{}", businessScore); // 业务权重 Double score = businessScorePolice.stream().mapToDouble(NegativeScorePolice::getScore).sum(); double businessWeight = calculateBusinessWeight(totalScore, score); diff --git a/src/main/java/com/biutag/supervision/service/PoliceScoreService.java b/src/main/java/com/biutag/supervision/service/PoliceScoreService.java new file mode 100644 index 0000000..5c218dd --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/PoliceScoreService.java @@ -0,0 +1,17 @@ +package com.biutag.supervision.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.biutag.supervision.pojo.entity.PoliceScore; +import com.biutag.supervision.mapper.PoliceScoreMapper; +import com.biutag.supervision.pojo.entity.SupPolice; +import org.apache.ibatis.annotations.Select; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class PoliceScoreService extends ServiceImpl { + + + +} diff --git a/src/main/resources/mapper/ProfileDepartMapper.xml b/src/main/resources/mapper/ProfileDepartMapper.xml index 367add0..d73ef2f 100644 --- a/src/main/resources/mapper/ProfileDepartMapper.xml +++ b/src/main/resources/mapper/ProfileDepartMapper.xml @@ -8,7 +8,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" SELECT d.*, count( DISTINCT nb.blameIdCode ) verify_police_size, - count( n.id ) verify_size + count( n.id ) verify_size, + dc.score FROM ( SELECT @@ -16,6 +17,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" d1.short_name parent_depart_name, d.short_name depart_name, p.police_size, + p.aux_size FROM sup_depart d @@ -23,13 +25,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" LEFT JOIN sup_depart_police_size p ON p.depart_id = d.id WHERE d.LEVEL = 3 + and d.statistics_group_id = #{departGroupId} ) d LEFT JOIN negative n ON n.involveDepartId = d.depart_id AND n.checkStatus IN ( '1', '2' ) AND n.discoveryTime BETWEEN #{beginTime} AND #{endTime} LEFT JOIN negative_blame nb ON n.id = nb.negativeId + left join depart_score dc on d.depart_id = dc.depart_id WHERE - d.statistics_group_id = #{departGroupId} + 1 = 1 AND d.short_name like concat('%', #{departName}, '%') @@ -41,7 +45,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" d.parent_depart_name, d.depart_name ORDER BY - verify_size DESC + score DESC