diff --git a/sql/1114.sql b/sql/1114.sql new file mode 100644 index 0000000..2feba64 --- /dev/null +++ b/sql/1114.sql @@ -0,0 +1,13 @@ +CREATE TABLE `risk_score_rule` ( + `id` int NOT NULL AUTO_INCREMENT, + `pid` int DEFAULT NULL, + `risk_name` varchar(255) COMMENT '风险因素', + `score` varchar(255) COMMENT '分值', + `rule_desc` text COLLATE utf8mb4_general_ci COMMENT '规则描述', + `weight` int DEFAULT NULL COMMENT '权重', + `status` tinyint DEFAULT NULL COMMENT '状态', + `update_time` datetime DEFAULT NULL COMMENT '更新时间', + `create_time` datetime DEFAULT NULL COMMENT '创建时间', + `sort_id` int DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=1 COMMENT='个人极端赋分规则'; diff --git a/src/main/java/com/biutag/supervision/constants/AppConstants.java b/src/main/java/com/biutag/supervision/constants/AppConstants.java index 8fdbdb4..6d67389 100644 --- a/src/main/java/com/biutag/supervision/constants/AppConstants.java +++ b/src/main/java/com/biutag/supervision/constants/AppConstants.java @@ -2,7 +2,7 @@ package com.biutag.supervision.constants; public class AppConstants { - public static final int MENU_ROOT_ID = 0; + public static final Integer TREE_ROOT_ID = 0; // 单位 public static final String DICT_CONTENT_ROOT_PARENT_CODE = "-1"; diff --git a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ModelController.java b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ModelController.java index 49a15ce..9911300 100644 --- a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ModelController.java +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ModelController.java @@ -3,12 +3,12 @@ package com.biutag.supervision.controller.sensitivePerception; import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.biutag.supervision.mapper.ModelClassMapper; import com.biutag.supervision.pojo.Result; import com.biutag.supervision.pojo.entity.Model; -import com.biutag.supervision.pojo.entity.ModelClass; +import com.biutag.supervision.pojo.model.ModelClassModel; import com.biutag.supervision.pojo.param.ModelQueryParam; import com.biutag.supervision.pojo.vo.ModelTree; -import com.biutag.supervision.service.ModelClassService; import com.biutag.supervision.service.ModelService; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.*; @@ -24,7 +24,7 @@ public class ModelController { private final ModelService modelService; - private final ModelClassService modelClassService; + private final ModelClassMapper modelClassMapper; @GetMapping public Result> list(ModelQueryParam queryParam) { @@ -39,13 +39,14 @@ public class ModelController { @GetMapping("tree") public Result> tree() { - List modelClasses = modelClassService.list(); + List modelClasses = modelClassMapper.selectListAll(); List models = modelService.list(); List list = new ArrayList<>(); list.addAll(modelClasses.stream().map(item -> { ModelTree node = new ModelTree(); node.setValue(item.getId()); node.setLabel(item.getName()); + node.setSize(item.getSize()); node.setType("modelClass"); List children = models.stream().filter(model -> item.getId().equals(model.getClassId())).map(ModelTree::of).toList(); node.setChildren(children); @@ -57,7 +58,6 @@ public class ModelController { @PostMapping public Result add(@RequestBody Model model) { - return Result.success(modelService.saveModel(model)); } diff --git a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfileDepartController.java b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfileDepartController.java index ff6fe53..9f561b3 100644 --- a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfileDepartController.java +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfileDepartController.java @@ -63,6 +63,8 @@ public class ProfileDepartController { return Result.success(page); } + private final NegativeScoreDepartService negativeScoreDepartService; + @GetMapping("{departId}") public Result profile(@PathVariable String departId, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date beginTime, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) { if (Objects.isNull(beginTime)) { @@ -80,10 +82,11 @@ public class ProfileDepartController { profileDepart.getDepartInfo().setMainRole(polices.stream().filter(item -> "正职".equals(item.getPosition())).findFirst().map(SupPolice::getName).orElse(null)); profileDepart.getDepartInfo().setDeputyRole(polices.stream().filter(item -> "副职".equals(item.getPosition())).map(SupPolice::getName).toList()); - List list = negativeService.list(new LambdaQueryWrapper().eq(Negative::getInvolveDepartId, departId) - .between(Negative::getDiscoveryTime, beginTime, endTime) - .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))); - List negativeIds = list.stream().map(Negative::getId).toList(); + List list = negativeScoreDepartService.list(new LambdaQueryWrapper() + .eq(NegativeScoreDepart::getDepartId, departId) + .between(NegativeScoreDepart::getDiscoveryTime, beginTime, endTime)); + + List negativeIds = list.stream().map(NegativeScoreDepart::getNegativeId).toList(); int negativePoliceSize = negativeIds.isEmpty() ? 0 : profileDepartMapper.countByNegativeIdsAndPersonTypes(negativeIds, List.of(PersonTypeEnum.police.getValue())); profileDepart.getDepartInfo().setNegativePoliceSize(negativePoliceSize); int negativeAuxSize = negativeIds.isEmpty() ? 0 : profileDepartMapper.countByNegativeIdsAndPersonTypes(negativeIds, List.of(PersonTypeEnum.aux.getValue(), PersonTypeEnum.xj.getValue())); @@ -96,42 +99,32 @@ public class ProfileDepartController { .eq(BusinessDepart::getBusinessType, BusinessTypeEnum.JCJ_110.getValue()) .eq(BusinessDepart::getDepartId, departId)) .stream().mapToInt(BusinessDepart::getNumber).sum(); - int jcj110Size = negativeService.list(new LambdaQueryWrapper() - .between(Negative::getDiscoveryTime, beginTime, endTime) - .eq(Negative::getBusinessTypeCode, BusinessTypeEnum.JCJ_110.getValue()) - .eq(Negative::getInvolveDepartId, departId) - .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))).size(); + int jcj122BusinessSize = businessDepartService.list(new LambdaQueryWrapper() .between(BusinessDepart::getDate, beginTime, endTime) .eq(BusinessDepart::getBusinessType, BusinessTypeEnum.JCJ_122.getValue()) .eq(BusinessDepart::getDepartId, departId)) .stream().mapToInt(BusinessDepart::getNumber).sum(); - int jcj122Size = negativeService.list(new LambdaQueryWrapper() - .between(Negative::getDiscoveryTime, beginTime, endTime) - .eq(Negative::getBusinessTypeCode, BusinessTypeEnum.JCJ_122.getValue()) - .eq(Negative::getInvolveDepartId, departId) - .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))).size(); - int zfbaBusinessSize = businessDepartService.list(new LambdaQueryWrapper() .between(BusinessDepart::getDate, beginTime, endTime) .eq(BusinessDepart::getBusinessType, BusinessTypeEnum.ZFBA.getValue()) .eq(BusinessDepart::getDepartId, departId)) .stream().mapToInt(BusinessDepart::getNumber).sum(); - int zfbaSize = negativeService.list(new LambdaQueryWrapper() - .between(Negative::getDiscoveryTime, beginTime, endTime) - .eq(Negative::getBusinessTypeCode, BusinessTypeEnum.ZFBA.getValue()) - .eq(Negative::getInvolveDepartId, departId) - .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))).size(); - profileDepart.getNegativeInfo().setJcj110Size(jcj110Size).setJcj110BusinessSize(jcj110BusinessSize) - .setJcj122Size(jcj122Size) + + profileDepart.getNegativeInfo() + .setJcj110Size(list.stream().filter(item -> BusinessTypeEnum.JCJ_110.getValue().equals(item.getBusinessTypeCode())).count()) + .setJcj110BusinessSize(jcj110BusinessSize) + .setJcj122Size(list.stream().filter(item -> BusinessTypeEnum.JCJ_122.getValue().equals(item.getBusinessTypeCode())).count()) .setJcj122BusinessSize(jcj122BusinessSize) - .setZfbaBusinessSize(zfbaBusinessSize).setZfbaSize(zfbaSize); + .setZfbaBusinessSize(zfbaBusinessSize) + .setZfbaSize(list.stream().filter(item -> BusinessTypeEnum.ZFBA.getValue().equals(item.getBusinessTypeCode())).count()); + List negatives = negativeService.listByIds(negativeIds); // 问题来源占比 - Map> problemSourcesGroup = list.stream().collect(Collectors.groupingBy(Negative::getProblemSourcesCode)); + Map> problemSourcesGroup = negatives.stream().collect(Collectors.groupingBy(Negative::getProblemSourcesCode)); List problemSourcesList = problemSourcesGroup.keySet().stream().map(key -> new PieItem(Optional.ofNullable(ProblemSourcesEnum.get(key)).map(ProblemSourcesEnum::getLabel).orElse(key), problemSourcesGroup.get(key).size())).toList(); profileDepart.setProblemSourcesList(problemSourcesList); // 业务类型占比 - Map> businessTypeGroup = list.stream().collect(Collectors.groupingBy(Negative::getBusinessTypeCode)); + Map> businessTypeGroup = negatives.stream().collect(Collectors.groupingBy(Negative::getBusinessTypeCode)); List businessTypeList = businessTypeGroup.keySet().stream().map(key -> new PieItem(Optional.ofNullable(BusinessTypeEnum.get(key)).map(BusinessTypeEnum::getLabel).orElse(key), businessTypeGroup.get(key).size())).toList(); profileDepart.setBusinessTypeList(businessTypeList); 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 abfd15d..b31bdda 100644 --- a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java @@ -1,6 +1,7 @@ package com.biutag.supervision.controller.sensitivePerception; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.NumberUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -13,9 +14,7 @@ import com.biutag.supervision.pojo.domain.ProfileDepart; import com.biutag.supervision.pojo.domain.ProfilePolice; import com.biutag.supervision.pojo.dto.common.BarItem; import com.biutag.supervision.pojo.dto.common.PieItem; -import com.biutag.supervision.pojo.entity.BusinessPolice; -import com.biutag.supervision.pojo.entity.Negative; -import com.biutag.supervision.pojo.entity.NegativeBlame; +import com.biutag.supervision.pojo.entity.*; import com.biutag.supervision.pojo.model.PoliceNegativeModel; import com.biutag.supervision.pojo.param.DepartPoliceQueryParam; import com.biutag.supervision.service.*; @@ -66,6 +65,9 @@ public class ProfilePoliceController { return Result.success(page); } + private final NegativeScorePoliceService negativeScorePoliceService; + private final NegativeProblemRelationService negativeProblemRelationService; + @GetMapping("{idCode}") public Result profile(@PathVariable String idCode, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date beginTime, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endTime) { if (Objects.isNull(beginTime)) { @@ -77,6 +79,8 @@ public class ProfilePoliceController { ProfilePolice profilePolice = new ProfilePolice(); profilePolice.setPoliceInfo(policeService.getByIdCode(idCode)); + List negatives = negativeScorePoliceService.list(new LambdaQueryWrapper().between(NegativeScorePolice::getDiscoveryTime, beginTime, endTime).eq(NegativeScorePolice::getIdCode, idCode)); + int jcj110BusinessSize = businessPoliceService.list(new LambdaQueryWrapper() .between(BusinessPolice::getDate, beginTime, endTime) .eq(BusinessPolice::getBusinessType, BusinessTypeEnum.JCJ_110.getValue()) @@ -84,12 +88,6 @@ public class ProfilePoliceController { .eq(BusinessPolice::getPoliceName, profilePolice.getPoliceInfo().getName())) .stream().mapToInt(BusinessPolice::getNumber).sum(); - Set negativeIds = negativeBlameService.list(new LambdaQueryWrapper().eq(NegativeBlame::getBlameIdCode, idCode)).stream().map(NegativeBlame::getNegativeId).collect(Collectors.toSet()); - int jcj110Size = negativeIds.isEmpty() ? 0 : negativeService.list(new LambdaQueryWrapper() - .between(Negative::getDiscoveryTime, beginTime, endTime) - .eq(Negative::getBusinessTypeCode, BusinessTypeEnum.JCJ_110.getValue()) - .in(Negative::getId, negativeIds) - .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))).size(); int jcj122BusinessSize = businessPoliceService.list(new LambdaQueryWrapper() .between(BusinessPolice::getDate, beginTime, endTime) .eq(BusinessPolice::getBusinessType, BusinessTypeEnum.JCJ_122.getValue()) @@ -97,11 +95,6 @@ public class ProfilePoliceController { .eq(BusinessPolice::getPoliceName, profilePolice.getPoliceInfo().getName())) .stream().mapToInt(BusinessPolice::getNumber).sum(); - int jcj122Size = negativeIds.isEmpty() ? 0 : negativeService.list(new LambdaQueryWrapper() - .between(Negative::getDiscoveryTime, beginTime, endTime) - .eq(Negative::getBusinessTypeCode, BusinessTypeEnum.JCJ_122.getValue()) - .in(Negative::getId, negativeIds) - .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))).size(); int zfbaBusinessSize = businessPoliceService.list(new LambdaQueryWrapper() .between(BusinessPolice::getDate, beginTime, endTime) @@ -109,46 +102,51 @@ public class ProfilePoliceController { .eq(BusinessPolice::getEmpNo, profilePolice.getPoliceInfo().getEmpNo()) .eq(BusinessPolice::getPoliceName, profilePolice.getPoliceInfo().getName())) .stream().mapToInt(BusinessPolice::getNumber).sum(); - int zfbaSize = negativeIds.isEmpty() ? 0 : negativeService.list(new LambdaQueryWrapper() - .between(Negative::getDiscoveryTime, beginTime, endTime) - .eq(Negative::getBusinessTypeCode, BusinessTypeEnum.ZFBA.getValue()) - .in(Negative::getId, negativeIds) - .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))).size(); - profilePolice.getNegativeInfo().setJcj110BusinessSize(jcj110BusinessSize).setJcj110Size(jcj110Size) - .setJcj122BusinessSize(jcj122BusinessSize).setJcj122Size(jcj122Size) - .setZfbaBusinessSize(zfbaBusinessSize).setZfbaSize(zfbaSize); - List list = negativeIds.isEmpty() ? new ArrayList<>() : negativeService.list(new LambdaQueryWrapper() - .between(Negative::getDiscoveryTime, beginTime, endTime) - .in(Negative::getId, negativeIds) - .in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))); + profilePolice.getNegativeInfo() + .setScore(NumberUtil.round(negatives.stream().mapToDouble(NegativeScorePolice::getScore).sum(), 2).doubleValue()) + .setJcj110BusinessSize(jcj110BusinessSize) + .setSize(negatives.size()) + .setJcj110Size(negatives.stream().filter(item -> BusinessTypeEnum.JCJ_110.getValue().equals(item.getBusinessTypeCode())).count()) + .setJcj122BusinessSize(jcj122BusinessSize) + .setJcj122Size(negatives.stream().filter(item -> BusinessTypeEnum.JCJ_122.getValue().equals(item.getBusinessTypeCode())).count()) + .setZfbaBusinessSize(zfbaBusinessSize) + .setZfbaSize(negatives.stream().filter(item -> BusinessTypeEnum.ZFBA.getValue().equals(item.getBusinessTypeCode())).count()); + + Set negativeIds = negatives.stream().map(NegativeScorePolice::getNegativeId).collect(Collectors.toSet()); + List list = negatives.isEmpty() ? new ArrayList<>() : negativeService.list(new LambdaQueryWrapper() + .in(Negative::getId, negativeIds)); // 问题来源占比 Map> problemSourcesGroup = list.stream().collect(Collectors.groupingBy(Negative::getProblemSourcesCode)); - List problemSourcesList = problemSourcesGroup.keySet().stream().map(key -> new PieItem(Optional.ofNullable(ProblemSourcesEnum.get(key)).map(ProblemSourcesEnum::getLabel).orElse(key), + List problemSourcesList = problemSourcesGroup.keySet().stream() + .map(key -> new PieItem(Optional.ofNullable(ProblemSourcesEnum.get(key)).map(ProblemSourcesEnum::getLabel).orElse(key), problemSourcesGroup.get(key).size())).toList(); profilePolice.setProblemSourcesList(problemSourcesList); - // 业务类型占比 - Map> businessTypeGroup = list.stream().collect(Collectors.groupingBy(Negative::getBusinessTypeCode)); - List businessTypeList = businessTypeGroup.keySet().stream().map(key -> new PieItem(Optional.ofNullable(BusinessTypeEnum.get(key)).map(BusinessTypeEnum::getLabel).orElse(key) - , businessTypeGroup.get(key).size())).toList(); - profilePolice.setBusinessTypeList(businessTypeList); - // 风险问题构成 雷达图 - List problemTypeBarList = profilePoliceMapper.selectProblemType(idCode, beginTime, endTime); - int max = problemTypeBarList.stream().mapToInt(BarItem::getValue).max().getAsInt(); - List problemTypeRadarIndicator = problemTypeBarList.stream().map(item -> { - ProfileDepart.RadarIndicatorItem radarIndicatorItem = new ProfileDepart.RadarIndicatorItem(); - radarIndicatorItem.setMax(max); - radarIndicatorItem.setName(item.getLabel()); - return radarIndicatorItem; - }).toList(); - List problemTypeRadarData = problemTypeBarList.stream().map(BarItem::getValue).toList(); - profilePolice.setProblemTypeRadarIndicator(problemTypeRadarIndicator); - profilePolice.setProblemTypeRadarData(problemTypeRadarData); + // 问题类型占比 + if (!negativeIds.isEmpty()) { + List blameIds = negativeBlameService.list(new LambdaQueryWrapper() + .in(NegativeBlame::getNegativeId, negativeIds) + .eq(NegativeBlame::getBlameIdCode, idCode)) + .stream().map(NegativeBlame::getBlameId).toList(); + if (!blameIds.isEmpty()) { + List problemRelations = negativeProblemRelationService.list(new LambdaQueryWrapper() + .in(NegativeProblemRelation::getBlameId, blameIds) + .in(NegativeProblemRelation::getNegativeId, negativeIds)); + Map> groups = problemRelations.stream().collect(Collectors.groupingBy(NegativeProblemRelation::getThreeLevelContent)); + List problemTypeList = groups.keySet().stream().map(key -> new PieItem(key, groups.get(key).size())).toList(); + profilePolice.setProblemTypeList(problemTypeList); + } + } List result = negativeScoreService.calculatePoliceScore(beginTime, endTime, idCode); profilePolice.setScore((BigDecimal) result.get(0)); profilePolice.setExpression(result.get(1).toString()); profilePolice.setRemarks(result.get(2).toString()); + // 雷达图 + profilePolice.setBusinessTypeRadarIndicator(Arrays.stream(BusinessTypeEnum.values()) + .map(item -> new ProfileDepart.RadarIndicatorItem().setName(item.getLabel()).setMax(100)).toList()); + profilePolice.setBusinessTypeScoreRadarData((List) result.get(3)); + profilePolice.setBusinessTypeWeightRadarData((List) result.get(4)); return Result.success(profilePolice); } diff --git a/src/main/java/com/biutag/supervision/controller/sensitivePerception/RiskClueController.java b/src/main/java/com/biutag/supervision/controller/sensitivePerception/RiskClueController.java new file mode 100644 index 0000000..f80d0ec --- /dev/null +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/RiskClueController.java @@ -0,0 +1,55 @@ +package com.biutag.supervision.controller.sensitivePerception; + +import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.biutag.supervision.pojo.Result; +import com.biutag.supervision.pojo.entity.Model; +import com.biutag.supervision.pojo.entity.RiskModelTaskClue; +import com.biutag.supervision.pojo.param.RiskModelTaskClueQueryParam; +import com.biutag.supervision.service.ModelService; +import com.biutag.supervision.service.RiskModelTaskClueService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * @author wxc + * @date 2024/11/14 + */ +@RequiredArgsConstructor +@RequestMapping("risk/clues") +@RestController +public class RiskClueController { + + private final RiskModelTaskClueService riskModelTaskClueService; + + private final ModelService modelService; + + @GetMapping + public Result> page(RiskModelTaskClueQueryParam param) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + if (Objects.nonNull(param.getRiskScoreRuleId()) && !param.getRiskScoreRuleId().isEmpty()) { + List models = modelService.list(new LambdaQueryWrapper().in(Model::getRiskScoreRuleId, param.getRiskScoreRuleId())); + if (models.isEmpty()) { + return Result.success(new Page().setRecords(new ArrayList<>()).setTotal(0)); + } + queryWrapper.in(RiskModelTaskClue::getModelId, models.stream().map(Model::getId).collect(Collectors.toSet())); + } + if (Objects.nonNull(param.getEventTime()) && param.getEventTime().size() == 2) { + queryWrapper.between(RiskModelTaskClue::getEventTime, param.getEventTime().get(0), param.getEventTime().get(1)); + } + queryWrapper.like(StrUtil.isNotBlank(param.getName()), RiskModelTaskClue::getName, param.getName()) + .like(StrUtil.isNotBlank(param.getIdCode()), RiskModelTaskClue::getIdCode, param.getIdCode()) + .like(StrUtil.isNotBlank(param.getThingDesc()), RiskModelTaskClue::getThingDesc, param.getThingDesc()); + queryWrapper.orderByDesc(RiskModelTaskClue::getCreateTime); + return Result.success(riskModelTaskClueService.page(Page.of(param.getCurrent(), param.getSize()), queryWrapper)); + } + +} diff --git a/src/main/java/com/biutag/supervision/controller/sensitivePerception/RiskPersonalController.java b/src/main/java/com/biutag/supervision/controller/sensitivePerception/RiskPersonalController.java index da443a9..6731a36 100644 --- a/src/main/java/com/biutag/supervision/controller/sensitivePerception/RiskPersonalController.java +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/RiskPersonalController.java @@ -10,6 +10,7 @@ import com.biutag.supervision.service.RiskPersonalService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -36,4 +37,10 @@ public class RiskPersonalController { return Result.success(riskPersonalService.page(Page.of(param.getCurrent(), param.getSize()), queryWrapper)); } + @GetMapping("{id}") + public Result> list(@PathVariable Integer id) { + + return Result.success(); + } + } \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/controller/sensitivePerception/RiskScoreRuleController.java b/src/main/java/com/biutag/supervision/controller/sensitivePerception/RiskScoreRuleController.java new file mode 100644 index 0000000..be705f2 --- /dev/null +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/RiskScoreRuleController.java @@ -0,0 +1,58 @@ +package com.biutag.supervision.controller.sensitivePerception; + +import com.biutag.supervision.pojo.Result; +import com.biutag.supervision.pojo.entity.RiskScoreRule; +import com.biutag.supervision.pojo.vo.RiskScoreRuleTree; +import com.biutag.supervision.service.RiskScoreRuleService; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * @author wxc + * @date 2024/11/14 + */ +@RequiredArgsConstructor +@RequestMapping("risk/scoreRule") +@RestController +public class RiskScoreRuleController { + + private final RiskScoreRuleService riskScoreRuleService; + + @GetMapping("tree") + public Result> list() { + return Result.success(riskScoreRuleService.buildTree()); + } + + @PostMapping + public Result add(@RequestBody RiskScoreRule scoreRule) { + scoreRule.setCreateTime(LocalDateTime.now()); + scoreRule.setUpdateTime(LocalDateTime.now()); + if (scoreRule.getPid() == 0) { + scoreRule.setLevel(1); + } else { + scoreRule.setLevel(2); + } + return Result.success(riskScoreRuleService.save(scoreRule)); + } + + @PutMapping + public Result update(@RequestBody RiskScoreRule scoreRule) { + scoreRule.setUpdateTime(LocalDateTime.now()); + if (scoreRule.getPid() == 0) { + scoreRule.setLevel(1); + } else { + scoreRule.setLevel(2); + } + return Result.success(riskScoreRuleService.updateById(scoreRule)); + } + + @DeleteMapping("{id}") + public Result update(@PathVariable Integer id) { + + return Result.success(riskScoreRuleService.removeById(id)); + } + +} diff --git a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ScoreController.java b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ScoreController.java index be5fde3..1496d05 100644 --- a/src/main/java/com/biutag/supervision/controller/sensitivePerception/ScoreController.java +++ b/src/main/java/com/biutag/supervision/controller/sensitivePerception/ScoreController.java @@ -3,11 +3,9 @@ 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.pojo.entity.*; import com.biutag.supervision.service.NegativeScoreService; +import com.biutag.supervision.service.RiskPersonalService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.RequestMapping; @@ -75,4 +73,13 @@ public class ScoreController { return Result.success("success"); } + private final RiskPersonalService riskPersonalService; + + @RequestMapping("personal") + public Result updatePersonalScore() { + List riskPersonals = riskPersonalService.list(); + + return Result.success("success"); + } + } diff --git a/src/main/java/com/biutag/supervision/mapper/ModelClassMapper.java b/src/main/java/com/biutag/supervision/mapper/ModelClassMapper.java index 8db59f1..c5ce565 100644 --- a/src/main/java/com/biutag/supervision/mapper/ModelClassMapper.java +++ b/src/main/java/com/biutag/supervision/mapper/ModelClassMapper.java @@ -2,7 +2,14 @@ package com.biutag.supervision.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.biutag.supervision.pojo.entity.ModelClass; +import com.biutag.supervision.pojo.model.ModelClassModel; +import org.apache.ibatis.annotations.Select; + +import java.util.List; public interface ModelClassMapper extends BaseMapper { + @Select("select mc.id, mc.name, mc.sort, count(m.id) size from model_class mc left join model m on mc.id = m.class_id GROUP BY mc.id, mc.name, mc.sort order by sort") + List selectListAll(); + } \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/mapper/RiskModelTaskClueMapper.java b/src/main/java/com/biutag/supervision/mapper/RiskModelTaskClueMapper.java new file mode 100644 index 0000000..7d91b05 --- /dev/null +++ b/src/main/java/com/biutag/supervision/mapper/RiskModelTaskClueMapper.java @@ -0,0 +1,8 @@ +package com.biutag.supervision.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.biutag.supervision.pojo.entity.RiskModelTaskClue; + +public interface RiskModelTaskClueMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/mapper/RiskScoreRuleMapper.java b/src/main/java/com/biutag/supervision/mapper/RiskScoreRuleMapper.java new file mode 100644 index 0000000..3ddb5c3 --- /dev/null +++ b/src/main/java/com/biutag/supervision/mapper/RiskScoreRuleMapper.java @@ -0,0 +1,8 @@ +package com.biutag.supervision.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.biutag.supervision.pojo.entity.RiskScoreRule; + +public interface RiskScoreRuleMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/domain/NegativeInfo.java b/src/main/java/com/biutag/supervision/pojo/domain/NegativeInfo.java index 05eb1f1..0fa3ebd 100644 --- a/src/main/java/com/biutag/supervision/pojo/domain/NegativeInfo.java +++ b/src/main/java/com/biutag/supervision/pojo/domain/NegativeInfo.java @@ -15,12 +15,15 @@ public class NegativeInfo { private long size; // 110接处警 + + private Double score; + private Integer jcj110BusinessSize; - private Integer jcj110Size; + private Long jcj110Size; // 122接处警 private Integer jcj122BusinessSize; - private Integer jcj122Size; + private Long jcj122Size; // 执法办案 private Integer zfbaBusinessSize; - private Integer zfbaSize; + private Long zfbaSize; } 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 09c0dca..ebad75f 100644 --- a/src/main/java/com/biutag/supervision/pojo/domain/ProfilePolice.java +++ b/src/main/java/com/biutag/supervision/pojo/domain/ProfilePolice.java @@ -26,9 +26,10 @@ public class ProfilePolice { private SupPolice policeInfo = new SupPolice(); private NegativeInfo negativeInfo = new NegativeInfo(); private List problemSourcesList = new ArrayList<>(); - private List businessTypeList = new ArrayList<>(); + private List problemTypeList = new ArrayList<>(); // 雷达图 - private List problemTypeRadarIndicator = new ArrayList<>(); - private List problemTypeRadarData = new ArrayList<>(); + private List businessTypeRadarIndicator = new ArrayList<>(); + private List businessTypeScoreRadarData = new ArrayList<>(); + private List businessTypeWeightRadarData = new ArrayList<>(); } diff --git a/src/main/java/com/biutag/supervision/pojo/domain/RiskPersonalDetail.java b/src/main/java/com/biutag/supervision/pojo/domain/RiskPersonalDetail.java new file mode 100644 index 0000000..c6c5b96 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/domain/RiskPersonalDetail.java @@ -0,0 +1,17 @@ +package com.biutag.supervision.pojo.domain; + +import com.biutag.supervision.pojo.entity.RiskPersonal; +import lombok.Getter; +import lombok.Setter; + +/** + * @author wxc + * @date 2024/11/14 + */ +@Setter +@Getter +public class RiskPersonalDetail { + + private RiskPersonal riskPersonal; + +} diff --git a/src/main/java/com/biutag/supervision/pojo/entity/Model.java b/src/main/java/com/biutag/supervision/pojo/entity/Model.java index aa66988..ceae6c5 100644 --- a/src/main/java/com/biutag/supervision/pojo/entity/Model.java +++ b/src/main/java/com/biutag/supervision/pojo/entity/Model.java @@ -91,4 +91,6 @@ public class Model { @TableField("model_sql") private String modelSql; + + private Integer riskScoreRuleId; } \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/entity/RiskModelTaskClue.java b/src/main/java/com/biutag/supervision/pojo/entity/RiskModelTaskClue.java new file mode 100644 index 0000000..3dbdd7c --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/entity/RiskModelTaskClue.java @@ -0,0 +1,85 @@ +package com.biutag.supervision.pojo.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; + +@Setter +@Getter +public class RiskModelTaskClue { + + // 主键 + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + // 模型id + @TableField("model_id") + private Integer modelId; + + // 姓名 + @TableField("name") + private String name; + + // 证件号码 + @TableField("id_code") + private String idCode; + + // 预警内容 + @TableField("thing_desc") + private String thingDesc; + + // 状态 默认 0-未分发 1-已分发 2-已处理 + @TableField("distribution_state") + private Boolean distributionState; + + // 任务ID + @TableField("task_id") + private Integer taskId; + + // 问题id + @TableField("negative_id") + private String negativeId; + + // 原始id + @TableField("source_id") + private String sourceId; + + // 案件id,“,”分割 + @TableField("case_ids") + private String caseIds; + + // 风险原因 + @TableField("risk_reason") + private String riskReason; + + // 数据详情 JSON + @TableField("data") + private String data; + + // 分数 + @TableField("score") + private Integer score; + + // 发生时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @TableField("event_time") + private LocalDateTime eventTime; + + // 创建时间 + @TableField("create_time") + private LocalDateTime createTime; + + // 修改时间 + @TableField("update_time") + private LocalDateTime updateTime; + + // 逻辑删除键0-未删1已删 + @TableField("del") + private Boolean del; + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/entity/RiskScoreRule.java b/src/main/java/com/biutag/supervision/pojo/entity/RiskScoreRule.java new file mode 100644 index 0000000..51730ce --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/entity/RiskScoreRule.java @@ -0,0 +1,58 @@ +package com.biutag.supervision.pojo.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; + +@Setter +@Getter +public class RiskScoreRule { + + // + @TableId(type = IdType.AUTO) + private Integer id; + + // + @TableField("pid") + private Integer pid; + + // 风险因素 + @TableField("risk_name") + private String riskName; + + // 分值 + @TableField("score") + private String score; + + // 规则描述 + @TableField("rule_desc") + private String ruleDesc; + + // 权重 + @TableField("weight") + private Integer weight; + + // 状态 + @TableField("status") + private Boolean status; + + // 更新时间 + @TableField("update_time") + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm") + private LocalDateTime updateTime; + + // 创建时间 + @TableField("create_time") + private LocalDateTime createTime; + + private Integer sortId; + + private Integer level; + +} \ No newline at end of file diff --git a/src/main/java/com/biutag/supervision/pojo/model/ModelClassModel.java b/src/main/java/com/biutag/supervision/pojo/model/ModelClassModel.java new file mode 100644 index 0000000..fbfd6ac --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/model/ModelClassModel.java @@ -0,0 +1,22 @@ +package com.biutag.supervision.pojo.model; + +import lombok.Getter; +import lombok.Setter; + +/** + * @author wxc + * @date 2024/11/13 + */ +@Setter +@Getter +public class ModelClassModel { + + private Integer id; + + private String name; + + private Integer sort; + + private Integer size; + +} diff --git a/src/main/java/com/biutag/supervision/pojo/param/RiskModelTaskClueQueryParam.java b/src/main/java/com/biutag/supervision/pojo/param/RiskModelTaskClueQueryParam.java new file mode 100644 index 0000000..4c16034 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/param/RiskModelTaskClueQueryParam.java @@ -0,0 +1,29 @@ +package com.biutag.supervision.pojo.param; + +import lombok.Getter; +import lombok.Setter; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * @author wxc + * @date 2024/11/14 + */ +@Setter +@Getter +public class RiskModelTaskClueQueryParam extends BasePage { + + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private List eventTime = new ArrayList<>(); + + private String name; + + private String idCode; + + private String thingDesc; + + private List riskScoreRuleId = new ArrayList<>(); +} diff --git a/src/main/java/com/biutag/supervision/pojo/vo/MenuTree.java b/src/main/java/com/biutag/supervision/pojo/vo/MenuTree.java index 0350ebd..9df8593 100644 --- a/src/main/java/com/biutag/supervision/pojo/vo/MenuTree.java +++ b/src/main/java/com/biutag/supervision/pojo/vo/MenuTree.java @@ -46,13 +46,13 @@ public class MenuTree { // 是否打开新页面 默认为false private Boolean openNewPage; - @JsonFormat(pattern = "YYYY-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") private LocalDateTime updateTime; private List children; public static List buildTree(List list) { - return buildTree(list, AppConstants.MENU_ROOT_ID); + return buildTree(list, AppConstants.TREE_ROOT_ID); } public static List buildTree(List list, Integer pid) { diff --git a/src/main/java/com/biutag/supervision/pojo/vo/ModelTree.java b/src/main/java/com/biutag/supervision/pojo/vo/ModelTree.java index 05db427..688d766 100644 --- a/src/main/java/com/biutag/supervision/pojo/vo/ModelTree.java +++ b/src/main/java/com/biutag/supervision/pojo/vo/ModelTree.java @@ -21,6 +21,8 @@ public class ModelTree { private String type; + private Integer size; + private List children = new ArrayList<>(); public static ModelTree of(Model model) { diff --git a/src/main/java/com/biutag/supervision/pojo/vo/RiskScoreRuleTree.java b/src/main/java/com/biutag/supervision/pojo/vo/RiskScoreRuleTree.java new file mode 100644 index 0000000..aa7f539 --- /dev/null +++ b/src/main/java/com/biutag/supervision/pojo/vo/RiskScoreRuleTree.java @@ -0,0 +1,45 @@ +package com.biutag.supervision.pojo.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +/** + * @author wxc + * @date 2024/11/14 + */ +@Setter +@Getter +public class RiskScoreRuleTree { + + private Integer id; + + private Integer pid; + + // 风险因素 + private String riskName; + + // 分值 + private String score; + + // 规则描述 + private String ruleDesc; + + // 权重 + private Integer weight; + + // 状态 + private Boolean status; + + // 更新时间 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm") + private LocalDateTime updateTime; + + private Integer sortId; + + private List children = new ArrayList<>(); +} diff --git a/src/main/java/com/biutag/supervision/service/BusinessDepartService.java b/src/main/java/com/biutag/supervision/service/BusinessDepartService.java index 9e8a50c..46f44a7 100644 --- a/src/main/java/com/biutag/supervision/service/BusinessDepartService.java +++ b/src/main/java/com/biutag/supervision/service/BusinessDepartService.java @@ -278,7 +278,9 @@ public class BusinessDepartService extends ServiceImpl list(Date beginTime, Date endTime, String businessType) { - return list(new LambdaQueryWrapper().between(BusinessDepart::getDate, beginTime, endTime).eq(BusinessDepart::getBusinessType, businessType)); + public List list(Date beginTime, Date endTime, String departId, String businessType) { + return list(new LambdaQueryWrapper().between(BusinessDepart::getDate, beginTime, endTime) + .eq(BusinessDepart::getDepartId, departId) + .eq(BusinessDepart::getBusinessType, businessType)); } } diff --git a/src/main/java/com/biutag/supervision/service/ModelClassService.java b/src/main/java/com/biutag/supervision/service/ModelClassService.java index 37a42bc..6e78464 100644 --- a/src/main/java/com/biutag/supervision/service/ModelClassService.java +++ b/src/main/java/com/biutag/supervision/service/ModelClassService.java @@ -8,4 +8,5 @@ import org.springframework.stereotype.Service; @Service public class ModelClassService extends ServiceImpl { + } diff --git a/src/main/java/com/biutag/supervision/service/ModelClueService.java b/src/main/java/com/biutag/supervision/service/ModelClueService.java index 9c8c1aa..ef5979f 100644 --- a/src/main/java/com/biutag/supervision/service/ModelClueService.java +++ b/src/main/java/com/biutag/supervision/service/ModelClueService.java @@ -24,10 +24,7 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.sql.Timestamp; import java.text.SimpleDateFormat; -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; +import java.time.*; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; import java.util.*; @@ -202,23 +199,18 @@ public class ModelClueService extends ServiceImpl { if (!Objects.isNull(model) && model.getModelSql() != null) { modelClues.addAll(getModelClueBySql(model.getModelSql(), modelId)); } - System.out.println("测试10"); if (!modelClues.isEmpty()) { List result = new ArrayList<>(); for (ModelClue modelClue : modelClues) { modelClue.setModelId(modelId); modelClue.setCreateTime(LocalDateTime.now()); - System.out.println("测试12"); if (modelClue.getInvolveDepartName() != null && !modelClue.getInvolveDepartName().isEmpty()) { - System.out.println("测试13"); result.add(modelClue); } } - System.out.println("测试14"); modelClueMapper.insert(result); modelClueRecordMapper.insert(new ModelClueRecord().setModelId(modelId).setSize(result.size()).setCreateTime(LocalDateTime.now()).setState("success")); } else { - System.out.println("测试15"); modelClueRecordMapper.insert(new ModelClueRecord().setModelId(modelId).setSize(0).setCreateTime(LocalDateTime.now()).setState("fail").setErrMsg("数据为空")); } } @@ -252,7 +244,7 @@ public class ModelClueService extends ServiceImpl { List uniqueKeys = modelClues.stream().map(ModelClue::getUniqueKey).filter(k -> k != null && !k.isEmpty()).toList(); List oldUniqueKeys = new ArrayList<>(); // 无需更新状态的模型 - if (modelId != 19 && modelId != 27 && modelId != 28 && modelId != 30) { + if (modelId != 19 && modelId != 26 && modelId != 27 && modelId != 28 && modelId != 30 && modelId != 100) { oldUniqueKeys = this.listObjs(new LambdaQueryWrapper().select(ModelClue::getUniqueKey).ne(ModelClue::getDistributionState, "2").eq(ModelClue::getModelId, modelId), String::valueOf); List changeStatusIds = oldUniqueKeys.stream().filter(item -> !uniqueKeys.contains(item)).toList(); if (!changeStatusIds.isEmpty()) { @@ -273,34 +265,27 @@ public class ModelClueService extends ServiceImpl { return new ArrayList<>(); } List needsInsertModelClues = modelClues.stream().filter(item -> needsInsertIds.contains(item.getUniqueKey())).toList(); - System.out.println("needsInsertModelClues:" + needsInsertModelClues.size()); String newSql = generateNewSql(sql, needsInsertIds, modelId); System.out.println("开始查询新sql" + newSql); List> allData = modelClueDataMapper.selectByUniqueKeys(newSql); + if (modelId == 26) { + filterDataForModel26(allData); + } System.out.println("查询新sql完成,结果数量:" + allData.size()); String originalFieldName = getKeyFieldName(sql); - System.out.println("originalFieldName:" + originalFieldName); for (ModelClue modelClue : needsInsertModelClues) { for (Map data : allData) { String keyColumn = (String) data.get(originalFieldName); - System.out.println("测试1:" + keyColumn + "测试" + modelClue.getUniqueKey()); if (Objects.equals(keyColumn, modelClue.getUniqueKey())) { - System.out.println("测试2"); modelClue.setData(JSONObject.toJSONString(data)); modelClue.setDistributionState("0"); - System.out.println("测试3"); SupExternalDepart supExternalDepart = supExternalDepartMapper.selectOne(new LambdaQueryWrapper().eq(SupExternalDepart::getExternalId, modelClue.getInvolveDepartId()).last("LIMIT 1")); - System.out.println("测试4"+modelClue.getInvolveDepartId()); if (supExternalDepart != null && supExternalDepart.getInternalShortName() != null && !supExternalDepart.getInternalShortName().isEmpty()) { - System.out.println("测试5"); modelClue.setInvolveDepartName(supExternalDepart.getInternalShortName()); modelClue.setInvolveDepartId(supExternalDepart.getInternalId()); } - System.out.println("测试6"); setPerson(modelId, modelClue, data); - System.out.println("测试7"); generateThingDesc(modelId, modelClue, data); - System.out.println("测试8"); break; } } @@ -308,6 +293,54 @@ public class ModelClueService extends ServiceImpl { return needsInsertModelClues; } + private static void filterDataForModel26(List> allData) { + List> filteredData = allData.stream().filter(map -> map.get("ajbh") != null).toList(); + Map>> groupedData = filteredData.stream().collect(Collectors.groupingBy(map -> (String) map.get("ajbh"))); + allData.clear(); + for (Map.Entry>> entry : groupedData.entrySet()) { + String ajbh = entry.getKey(); + List> records = entry.getValue(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); + String earliestJRSJ = null; + LocalDateTime earliestDateTime = LocalDateTime.MIN; + for (Map record : records) { + String jrsj = (String) record.get("jrsj"); + LocalDateTime dateTime = LocalDateTime.parse(jrsj, formatter); + if (earliestJRSJ == null || !dateTime.isAfter(earliestDateTime)) { + earliestJRSJ = jrsj; + earliestDateTime = dateTime; + } + } + String latestLKSJ = null; + LocalDateTime latestDateTime = LocalDateTime.MIN; + for (Map record : records) { + String lksj = (String) record.get("lksj"); + LocalDateTime dateTime = LocalDateTime.parse(lksj, formatter); + if (latestLKSJ == null || dateTime.isAfter(latestDateTime)) { + latestLKSJ = lksj; + latestDateTime = dateTime; + } + } + if (earliestJRSJ != null && latestLKSJ != null) { + Duration duration = Duration.between(earliestDateTime, latestDateTime); + if (duration.toHours() >= 3) { + continue; + } + Map newRecord = new HashMap<>(); + newRecord.put("ajbh", ajbh); + newRecord.put("jrsj", earliestJRSJ); + newRecord.put("lksj", latestLKSJ); + for (String key : records.get(0).keySet()) { + if (!key.equals("jrsj") && !key.equals("lksj")) { + newRecord.put(key, records.get(0).get(key)); + } + } + allData.add(newRecord); + } + } + System.out.println("模型26筛选后的alldata数量:" + allData.size()); + } + private void setPerson(Integer modelId, ModelClue modelClue, Map data) { // 执法区域人员表 if (modelId == 3) { @@ -486,23 +519,22 @@ public class ModelClueService extends ServiceImpl { + ",未录入反馈人员身份证信息。"); } else if (modelId == 26) { // 26号模型:执法办案场所进出时间过短 if (data.get("lksj") != null && !data.get("lksj").equals("")) { - modelClue.setThingDesc("发现执法场所人员“" + data.get("xm") - + "”(身份证号" + data.get("zjhm") - + "),于" + getDateMinuteString(data.get("jrsj")) - + "进入" + modelClue.getInvolveDepartName() - + "执法办案区,于" + getDateMinuteString(data.get("lksj")) - + "离开,停留时长" + calculateMinutesBetween(data.get("djsj"), data.get("lksj")) - + ",存在间隔时间过短的异常。"); + modelClue.setThingDesc("发现" + modelClue.getInvolveDepartName() + "办理的被处以刑事打处的嫌疑人员“" + + data.get("xm") + "”(身份证号:" + data.get("zjhm") + + "),其于" + getDateMinuteString(data.get("jrsj")) + + "登记进入" + modelClue.getInvolveDepartName() + + "执法办案区,但仅停留" + calculateMinutesBetween(data.get("jrsj"), data.get("lksj")) + + "后便予以离开,少于3小时,与正常开展流程办理刑事案件所需时长相违背,存在疑似不如实登记执法办案场所的异常问题。"); } } else if (modelId == 27) { // 27号模型:盗窃车内财物警情结警性质变动的异常数据 modelClue.setThingDesc("发现" + modelClue.getInvolveDepartName() + "受理的接警单" + modelClue.getUniqueKey() + ",报警日期为" + getDateMinuteString(data.get("bjsj")) + ",接警性质为“" + data.get("ysjqxzmc") + "”,结警性质为“" + data.get("jqxzmc") + ",存在盗窃车内财物警情结警性质变动的异常情况。"); - } else if (modelId == 28) { // 28号模型:盗窃车内财物超过5000元的数据 + } else if (modelId == 28) { // 28号模型:盗窃车内财物超过2000元的数据 modelClue.setThingDesc("发现" + modelClue.getInvolveDepartName() + "受理的接警单" + modelClue.getUniqueKey() + ",报警日期为" + getDateMinuteString(data.get("bjsj")) - + ",接警性质为“" + data.get("ysjqxzmc") + "”,金额超过5000元。报警内容为:“" + data.get("bjnr") + + ",接警性质为“" + data.get("ysjqxzmc") + "”,金额超过2000元。报警内容为:“" + data.get("bjnr") + "”。"); } else if (modelId == 29) { // 29号模型:案件降格处理的异常数据 modelClue.setThingDesc("发现" + modelClue.getInvolveDepartName() + "受理的接警单" @@ -518,6 +550,14 @@ public class ModelClueService extends ServiceImpl { "发现" + modelClue.getInvolveDepartName() + "受理的“" + data.get("AJMC") + "”(【" + data.get("AJBZmc") + "】编号:" + getAjbh(data) + "),未扣押任何财物,存在疑似涉案财物未按要求录入的问题。"); + } else if (modelId == 100) { // 100号模型:散油实时预警 + modelClue.setInvolvePoliceName((String) data.get("gmrxm")); + modelClue.setThingDesc( + "发现" + data.get("gmrxm") + "(身份证号:" + data.get("zjhm") + ")于" + + getDateMinuteString(data.get("gmsj")) + "在" + + data.get("fjmc") + modelClue.getInvolveDepartName() + "管辖的" + data.get("dwmc") + + "购买了" + data.get("gmsl") + "升" + data.get("gmyt") + + ",产生了" + data.get("yjlx") + ",请予以重点关注。"); } } @@ -894,9 +934,13 @@ public class ModelClueService extends ServiceImpl { } newModelClue.setData(JSONObject.toJSONString(map)); newModelClue.setDistributionState("0"); + Long count = (Long) map.get("num"); + BigDecimal result = BigDecimal.valueOf(count).divide(BigDecimal.valueOf(250), 3, RoundingMode.HALF_UP); newModelClue.setThingDesc( - "灵敏感知系统发现" + newModelClue.getInvolveDepartName() + "民警" + xzdzrr - + "的管控人数为" + map.get("num") + "人。"); + "发现" + newModelClue.getInvolveDepartName() + "民警" + xzdzrr + + ",其在重点人员管控系统中的管控人数为" + count + + "人,即使每个重点人员只见一次,其工作日(采取每年250天)必须每日完成管控" + + result +"个。"); modelClues.add(newModelClue); } } @@ -950,9 +994,7 @@ public class ModelClueService extends ServiceImpl { List uniqueKeys = modelClues1.stream().map(ModelClue::getUniqueKey).filter(k -> k != null && !k.isEmpty()).toList(); if (!uniqueKeys.isEmpty()) { String newSql = "SELECT a.* FROM dwd_asj_zhtx_jjd a LEFT JOIN dwd_asj_sjjhygx_jjcjxxb b ON b.BARLXDH = a.bjdh WHERE a.jjdbh IN " + "(" + uniqueKeys.stream().map(k -> "'" + k + "'").collect(Collectors.joining(",")) + ");"; - System.out.println("测试2开始查询数据库 newSql"); List> allData = modelClueDataMapper.selectByUniqueKeys(newSql); - System.out.println("测试2查询数据库newSql记录条数:" + allData.size()); for (ModelClue modelClue : modelClues1) { for (Map data : allData) { String keyColumn = (String) data.get("jjdbh"); @@ -1070,7 +1112,18 @@ public class ModelClueService extends ServiceImpl { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日HH时mm分"); return formatter.format(localDateTime); } catch (Exception exx) { - log.info("日期转换异常{}", time, ex); + try { + time = String.valueOf(param); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date parse = sdf.parse(time); + Instant instant = parse.toInstant(); + ZoneId zoneId = ZoneId.systemDefault(); + LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日HH时mm分"); + return formatter.format(localDateTime); + } catch (Exception exxx) { + log.info("日期转换异常{}", time, ex); + } } } } diff --git a/src/main/java/com/biutag/supervision/service/ModelService.java b/src/main/java/com/biutag/supervision/service/ModelService.java index 884d0e0..4e470fd 100644 --- a/src/main/java/com/biutag/supervision/service/ModelService.java +++ b/src/main/java/com/biutag/supervision/service/ModelService.java @@ -1,5 +1,6 @@ package com.biutag.supervision.service; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.biutag.supervision.common.UserContextHolder; @@ -24,7 +25,7 @@ public class ModelService extends ServiceImpl { } public boolean saveModel(Model model) { - if (DistributionMethodEnum.NEGATIVE_DISTRIBUTE.getValue().equals(model.getDistributionMethod())) { + if (StrUtil.isNotBlank(model.getDistributionCycle()) && DistributionMethodEnum.NEGATIVE_DISTRIBUTE.getValue().equals(model.getDistributionMethod())) { String expression = DistributionCycleEnum.day.name().equals(model.getDistributionCycle()) ? ExpressionBuilder.build(model.getDistributionCycleTime()) : ExpressionBuilder.build(model.getDistributionCycleTime(), model.getDistributionCycleDayOfWeek()); model.setDistributionCycleExpression(expression); @@ -39,7 +40,7 @@ public class ModelService extends ServiceImpl { } public boolean updateModel(Model model) { - if (DistributionMethodEnum.NEGATIVE_DISTRIBUTE.getValue().equals(model.getDistributionMethod())) { + if (StrUtil.isNotBlank(model.getDistributionCycle()) && DistributionMethodEnum.NEGATIVE_DISTRIBUTE.getValue().equals(model.getDistributionMethod())) { String expression = DistributionCycleEnum.day.name().equals(model.getDistributionCycle()) ? ExpressionBuilder.build(model.getDistributionCycleTime()) : ExpressionBuilder.build(model.getDistributionCycleTime(), model.getDistributionCycleDayOfWeek()); model.setDistributionCycleExpression(expression); diff --git a/src/main/java/com/biutag/supervision/service/NegativeScoreService.java b/src/main/java/com/biutag/supervision/service/NegativeScoreService.java index a1899cc..af8d0a3 100644 --- a/src/main/java/com/biutag/supervision/service/NegativeScoreService.java +++ b/src/main/java/com/biutag/supervision/service/NegativeScoreService.java @@ -11,7 +11,6 @@ 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; import java.math.BigDecimal; @@ -116,90 +115,77 @@ public class NegativeScoreService { System.out.println("calculateScore-------------------------------------------------End"); } - - private final BusinessPoliceService businessPoliceService; - private final BusinessDepartService businessDepartService; private final SupPoliceService policeService; // 业务权重 = 单个业务风险指数 / 总业务风险指数之和 - public double calculateBusinessWeight(Double totalScore, Double score) { + public double calculateBusinessWeight(Double score, Double totalScore) { if (totalScore == 0) { return 0.0; } - + log.info("业务权重 = {} / {}", score, totalScore); return NumberUtil.div(score, totalScore); } - // 平均问题数 = 单个业务问题数 / 业务涉及人数 - public double calculateAvgNumber(int size, int policeSize) { - if (policeSize == 0) { + // 平均问题发生率 = 单个业务问题加权数 / 单位总业务量 + public double calculateAvgNumber(double businessWeightScore, int totalBusinessSize) { + if (totalBusinessSize == 0) { + log.info("平均问题发生率 = 0"); return 0; } - return NumberUtil.div(size, policeSize); + log.info("平均问题发生率 = {} / {}", businessWeightScore, totalBusinessSize); + return NumberUtil.div(businessWeightScore, totalBusinessSize); } + // 业务标准差 = 根号(sum((个人问题数 - 平均问题数)²) / 业务涉及人数) - public double calculateSd(double[] diffNumber, int policeSize) { + public double calculateSd1(double[] diffNumber, int policeSize) { if (policeSize == 0) { + log.info("业务标准差 = 0"); return 0; } + log.info("业务标准差 = 根号({}) / {}", Arrays.stream(diffNumber).mapToObj(val -> String.format("(%s)²", val)).collect(Collectors.joining(" + ")), policeSize); return Math.sqrt(Arrays.stream(diffNumber).map(val -> Math.pow(val, 2)).sum() / policeSize); } - // 业务差异值1 = (个人问题发生率 - 平均问题发生率) / 业务标准差 - // 平均问题发生率 = 总问题数 / 总业务量 - // 个人问题发生率 = 个人问题数 / 个人业务量 - public double calculateDiff1(List businessScorePolice, SupPolice police, Date beginTime, Date endTime, String businessTypeCode, double sd) { - if (sd == 0) { + // 业务标准差 = 根号(sum((个人问题数 - 平均问题数)²) / 业务涉及人数) + public double calculateSd2(double[] diffNumber, int policeSize) { + if (policeSize == 0) { + log.info("业务标准差 = 0"); return 0; } - List businessDeparts = businessDepartService.list(beginTime, endTime, businessTypeCode); - // 总业务量 - int totalBusinessSize = businessDeparts.stream().mapToInt(BusinessDepart::getNumber).sum(); - // 平均问题发生率 - double avgRate = totalBusinessSize == 0? 0: NumberUtil.div(businessScorePolice.size(), totalBusinessSize); - // 个人问题数 - long personSize = businessScorePolice.stream().filter(item -> police.getOrgId().equals(item.getIdCode())).count(); - // 单位业务量 - long departBusinessSize = businessDeparts.stream().filter(item -> police.getOrgId().equals(item.getDepartId())).count(); - // 个人问题发生率 - double personRate = departBusinessSize == 0? 0: NumberUtil.div(personSize, departBusinessSize); - return NumberUtil.div(personRate - avgRate, sd); + log.info("业务标准差 = 根号({}) / {}", Arrays.stream(diffNumber).mapToObj(val -> String.format("(%s)²", val)).collect(Collectors.joining(" + ")), policeSize); + return Math.sqrt(Arrays.stream(diffNumber).map(val -> Math.pow(val, 2)).sum() / policeSize); } - public double calculateDiff1ByDepart(List businessScoreDeparts, String departId, Date beginTime, Date endTime, String businessTypeCode, double sd) { + // 业务差异值1 = (个人问题发生率 - 平均问题发生率) / 业务标准差 + // 平均问题发生率 = 总问题数 / 总业务量 + // 个人问题发生率 = 个人问题数 / 个人业务量 + public double calculateDiff1(double personalRate, double avgNumber, double sd) { if (sd == 0) { + log.info("业务差异值(发生率) = 0"); return 0; } - List businessDeparts = businessDepartService.list(beginTime, endTime, businessTypeCode); - // 总业务量 - int totalBusinessSize = businessDeparts.stream().mapToInt(BusinessDepart::getNumber).sum(); - // 平均问题发生率 - double avgRate = totalBusinessSize == 0? 0: NumberUtil.div(businessScoreDeparts.size(), totalBusinessSize); - // 个人问题数 - long personSize = businessScoreDeparts.stream().filter(item -> departId.equals(item.getDepartId())).count(); - // 个人业务量 - long personBusinessSize = businessDeparts.stream().filter(item -> departId.equals(item.getDepartId())).count(); - // 个人问题发生率 - double personRate = personBusinessSize == 0? 0: NumberUtil.div(personSize, personBusinessSize); - return NumberUtil.div(personRate - avgRate, sd); + log.info("业务差异值(发生率) = ({} - {}) / {}", personalRate, avgNumber, sd); + return NumberUtil.div(personalRate - avgNumber, sd); } - // 业务差异值2 = (问题数 - 平均问题数) / 业务标准差 - public double calculateDiff2(long personalSize, double avgNumber, double sd) { + // 业务差异值2 = (加权问题数 - 平均问题数) / 业务标准差 + public double calculateDiff2(double personalScore, double avgNumber, double sd) { if (sd == 0) { return 0; } - return NumberUtil.div(personalSize - avgNumber, sd); + log.info("业务差异值(数量) = ({} - {}) / {}", personalScore, avgNumber, sd); + return NumberUtil.div(personalScore - avgNumber, sd); } - public double calculateBusinessScore(double diff, long personalSize) { + public double calculateBusinessScore(double diff, double personalSize) { if (personalSize == 0) { return 0; } - return 50 + (diff * 15); + log.info("单个业务风险指数 = 50 + ({} * 5)", diff); + return 50 + (diff * 5); } private final SupDepartService departService; @@ -227,49 +213,85 @@ public class NegativeScoreService { Double totalScore = scorePolices.stream().mapToDouble(NegativeScorePolice::getScore).sum(); List expressionArr = new ArrayList<>(); StringBuilder remarks = new StringBuilder(); + List scores = new ArrayList<>(); + List weights = new ArrayList<>(); double policeScore = Arrays.stream(BusinessTypeEnum.values()).mapToDouble(businessTypeEnum -> { + log.info("业务 【{}】 开始-------------------------------------------------------------------", businessTypeEnum.getLabel()); List businessScorePolice = scorePolices.stream().filter(item -> item.getBusinessTypeCode().equals(businessTypeEnum.getValue())).toList(); + // 业务加权问题总数 + double businessWeightScore = businessScorePolice.stream().mapToDouble(NegativeScorePolice::getScore).sum(); + log.info("业务加权问题数 = {}", businessWeightScore); // 业务涉及人数 int policeSize = businessScorePolice.stream().map(NegativeScorePolice::getIdCode).collect(Collectors.toSet()).size(); - remarks.append(String.format("业务设计人数 %s", policeSize)); - // 业务问题数 - int businessSize = businessScorePolice.size(); - //--------------------------------------------------------- - // 平均问题数 - double avgNumber = calculateAvgNumber(businessSize, policeSize); - // 差值集合 = 个人问题数 - 平均问题数 - Map> group = businessScorePolice.stream().collect(Collectors.groupingBy(NegativeScorePolice::getIdCode)); - double[] diffNumbers = group.values().stream().mapToDouble(val -> val.size() - avgNumber).toArray(); - // 业务标准差 - double sd = calculateSd(diffNumbers, policeSize); - log.info("业务标准差为:{}", sd); + log.info("业务涉及人数 = {}", policeSize); + // 业务加权问题数(风险指数) + double personalScore = businessScorePolice.stream().filter(item -> idCode.equals(item.getIdCode())).mapToDouble(NegativeScorePolice::getScore).sum(); + log.info("个人业务加权问题数 = {}", personalScore); // 业务差异值 double diff; - long personalSize = businessScorePolice.stream().filter(item -> idCode.equals(item.getIdCode())).count(); - if (businessTypeEnum.getBusinessVolume()) { - diff = calculateDiff1(businessScorePolice, police, beginTime, endTime, businessTypeEnum.getValue(), sd); + if (false) { + String departId = depart.getId(); + // 如果是4级单位 则找他上级单位 + if (depart.getLevel() == 4) { + departId = departService.getById(depart.getPid()).getId(); + } + List businessDeparts = businessDepartService.list(beginTime, endTime, departId, businessTypeEnum.getValue()); + // 单位总业务量 + int totalBusinessSize = businessDeparts.stream().mapToInt(BusinessDepart::getNumber).sum(); + log.info("单位总业务量 = {}", totalBusinessSize); + // 平均加权问题发生率 + double avgNumber = calculateAvgNumber(businessWeightScore, totalBusinessSize); + log.info("平均加权问题发生率 = {}", avgNumber); + Map> group = businessScorePolice.stream().collect(Collectors.groupingBy(NegativeScorePolice::getIdCode)); + double[] diffNumbers = group.values().stream().mapToDouble(val -> { + if (totalBusinessSize == 0) { + return -avgNumber; + } + return (val.stream().mapToDouble(NegativeScorePolice::getScore).sum() / totalBusinessSize) - avgNumber; + }).toArray(); + // 业务标准差 + double sd = calculateSd1(diffNumbers, policeSize); + double rate = personalScore / totalBusinessSize; + log.info("个人问题发生率 = {} / {}", personalScore, totalBusinessSize); + log.info("个人问题发生率 = {}", rate); + diff = calculateDiff1(personalScore / totalBusinessSize, avgNumber, sd); } else { - diff = calculateDiff2(personalSize, avgNumber, sd); + remarks.append(String.format("业务涉及人数 %s", policeSize)); + // 业务平均加权问题数 + double avgNumber = calculateAvgNumber(businessWeightScore, policeSize); + // 差值集合 = 个人问题数 - 平均问题数 + Map> group = businessScorePolice.stream().collect(Collectors.groupingBy(NegativeScorePolice::getIdCode)); + double[] diffNumbers = group.values().stream().mapToDouble(val -> val.stream().mapToDouble(NegativeScorePolice::getScore).sum() - avgNumber).toArray(); + // 业务标准差 + double sd = calculateSd2(diffNumbers, policeSize); + log.info("业务标准差为 = {}", sd); + + diff = calculateDiff2(personalScore, avgNumber, sd); } - log.info("业务差异值为:{}", diff); + log.info("业务差异值为 = {}", diff); // 业务风险指数 - double businessScore = calculateBusinessScore(diff, personalSize); - log.info("业务风险指数:{}", businessScore); + double businessScore = calculateBusinessScore(diff, personalScore); + // 业务权重 Double score = businessScorePolice.stream().mapToDouble(NegativeScorePolice::getScore).sum(); - double businessWeight = calculateBusinessWeight(totalScore, score); + double businessWeight = calculateBusinessWeight(score, totalScore); expressionArr.add(String.format("(%s * %s)", businessScore, businessWeight)); remarks.append(String.format("%s:", businessTypeEnum.getLabel())).append("\n"); remarks.append(String.format("业务涉及人数 %s", policeSize)).append("\n"); - remarks.append(String.format("业务问题数 %s", businessSize)).append("\n"); - remarks.append(String.format("平均问题数 %s", avgNumber)).append("\n"); - remarks.append(String.format("业务标准差 %s", sd)).append("\n"); + remarks.append(String.format("业务问题数 %s", businessWeightScore)).append("\n"); remarks.append(String.format("业务差异值 %s", diff)).append("\n"); + log.info("业务风险指数 = {}", businessScore); + log.info("业务权重 = {}", businessWeight); + log.info("单个业务风险指数 = {} * {}", businessScore, businessWeight); + + log.info("单个业务结束-------------------------------------------------------------------", businessTypeEnum.getLabel()); + scores.add(NumberUtil.round(businessScore, 2).doubleValue()); + weights.add(NumberUtil.round(businessWeight * 100, 2).doubleValue()); return NumberUtil.mul(businessScore, businessWeight); }).sum(); BigDecimal score = NumberUtil.roundHalfEven(policeScore, 2); String expression = String.join(" + ", expressionArr); - return List.of(score, expression, remarks); + return List.of(score, expression, remarks, scores, weights); } /** @@ -288,35 +310,46 @@ public class NegativeScoreService { StringBuilder remarks = new StringBuilder(); double policeScore = Arrays.stream(BusinessTypeEnum.values()).mapToDouble(businessTypeEnum -> { List businessScoreDeparts = scoreDeparts.stream().filter(item -> item.getBusinessTypeCode().equals(businessTypeEnum.getValue())).toList(); + // 业务加权问题数 + double businessWeightScore = businessScoreDeparts.stream().mapToDouble(NegativeScoreDepart::getScore).sum(); // 业务涉及人数 int departSize = businessScoreDeparts.stream().map(NegativeScoreDepart::getDepartId).collect(Collectors.toSet()).size(); - // 当前部门问题数 - long personalSize = businessScoreDeparts.stream().filter(item -> departId.equals(item.getDepartId())).count(); - // 平均问题数 - double avgNumber = calculateAvgNumber(businessScoreDeparts.size(), departSize); - // 差值集合 = 个人问题数 - 平均问题数 - Map> group = businessScoreDeparts.stream().collect(Collectors.groupingBy(NegativeScoreDepart::getDepartId)); - double[] diffNumbers = group.values().stream().mapToDouble(val -> val.size() - avgNumber).toArray(); - // 业务标准差 - double sd = calculateSd(diffNumbers, departSize); + // 业务加权问题数(风险指数) + double personalScore = businessScoreDeparts.stream().filter(item -> departId.equals(item.getDepartId())).mapToDouble(NegativeScoreDepart::getScore).sum(); // 业务差异值 double diff; - if (businessTypeEnum.getBusinessVolume()) { - diff = calculateDiff1ByDepart(businessScoreDeparts, departId, beginTime, endTime, businessTypeEnum.getValue(), sd); + if (false) { + List businessDeparts = businessDepartService.list(beginTime, endTime, departId, businessTypeEnum.getValue()); + // 总业务量 + int totalBusinessSize = businessDeparts.stream().mapToInt(BusinessDepart::getNumber).sum(); + // 平均加权问题发生率 + double avgNumber = calculateAvgNumber(businessWeightScore, totalBusinessSize); + Map> group = businessScoreDeparts.stream().collect(Collectors.groupingBy(NegativeScoreDepart::getDepartId)); + double[] diffNumbers = group.values().stream().mapToDouble(val -> val.stream().mapToDouble(NegativeScoreDepart::getScore).sum() - avgNumber).toArray(); + // 业务标准差 + double sd = calculateSd1(diffNumbers, departSize); + log.info(""); + diff = calculateDiff1(personalScore, avgNumber, sd); } else { + // 当前部门问题数 + long personalSize = businessScoreDeparts.stream().filter(item -> departId.equals(item.getDepartId())).count(); + // 平均问题数 + double avgNumber = calculateAvgNumber(businessScoreDeparts.size(), departSize); + // 差值集合 = 个人问题数 - 平均问题数 + Map> group = businessScoreDeparts.stream().collect(Collectors.groupingBy(NegativeScoreDepart::getDepartId)); + double[] diffNumbers = group.values().stream().mapToDouble(val -> val.size() - avgNumber).toArray(); + // 业务标准差 + double sd = calculateSd2(diffNumbers, departSize); diff = calculateDiff2(personalSize, avgNumber, sd); } // 业务风险指数 - double businessScore = calculateBusinessScore(diff, personalSize); + double businessScore = calculateBusinessScore(diff, personalScore); // 业务权重 Double score = businessScoreDeparts.stream().mapToDouble(NegativeScoreDepart::getScore).sum(); - double businessWeight = calculateBusinessWeight(totalScore, score); + double businessWeight = calculateBusinessWeight(score, totalScore); expressionArr.add(String.format("(%s * %s)", businessScore, businessWeight)); remarks.append(String.format("%s:", businessTypeEnum.getLabel())).append("\n"); remarks.append(String.format("业务涉及人数 %s", departSize)).append("\n"); - remarks.append(String.format("当前部门问题数 %s", personalSize)).append("\n"); - remarks.append(String.format("平均问题数 %s", avgNumber)).append("\n"); - remarks.append(String.format("业务标准差 %s", sd)).append("\n"); remarks.append(String.format("业务差异值 %s", diff)).append("\n"); return NumberUtil.mul(businessScore, businessWeight); }).sum(); diff --git a/src/main/java/com/biutag/supervision/service/RiskModelTaskClueService.java b/src/main/java/com/biutag/supervision/service/RiskModelTaskClueService.java new file mode 100644 index 0000000..6922335 --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/RiskModelTaskClueService.java @@ -0,0 +1,11 @@ +package com.biutag.supervision.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.biutag.supervision.pojo.entity.RiskModelTaskClue; +import com.biutag.supervision.mapper.RiskModelTaskClueMapper; +import org.springframework.stereotype.Service; + +@Service +public class RiskModelTaskClueService extends ServiceImpl { + +} diff --git a/src/main/java/com/biutag/supervision/service/RiskScoreRuleService.java b/src/main/java/com/biutag/supervision/service/RiskScoreRuleService.java new file mode 100644 index 0000000..a8fb130 --- /dev/null +++ b/src/main/java/com/biutag/supervision/service/RiskScoreRuleService.java @@ -0,0 +1,50 @@ +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.constants.AppConstants; +import com.biutag.supervision.mapper.RiskScoreRuleMapper; +import com.biutag.supervision.pojo.entity.RiskScoreRule; +import com.biutag.supervision.pojo.vo.RiskScoreRuleTree; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Service +public class RiskScoreRuleService extends ServiceImpl { + + public List buildTree() { + List scoreRules = list(new LambdaQueryWrapper().orderByAsc(RiskScoreRule::getSortId)); + Map> childMap = new HashMap<>(); + List tree = new ArrayList<>(); + for (RiskScoreRule rule: scoreRules) { + RiskScoreRuleTree node = new RiskScoreRuleTree(); + BeanUtils.copyProperties(rule, node); + List children = childMap.computeIfAbsent(node.getPid(), k -> new ArrayList<>()); + children.add(node); + Integer pid = node.getPid(); + if (AppConstants.TREE_ROOT_ID.equals(pid)) { + tree.add(node); + } + } + for (RiskScoreRuleTree node : tree) { + buildTreeRecursive(node, childMap); + } + return tree; + } + + private static RiskScoreRuleTree buildTreeRecursive(RiskScoreRuleTree node, Map> childMap) { + List children = childMap.get(node.getId()); + if (children != null) { + node.getChildren().addAll(children.stream() + .map(childNode -> buildTreeRecursive(childNode, childMap)) + .toList()); + } + return node; + } + +} diff --git a/src/main/java/com/biutag/supervision/support/ModelClueDistributionAware.java b/src/main/java/com/biutag/supervision/support/ModelClueDistributionAware.java index 854487c..719eb16 100644 --- a/src/main/java/com/biutag/supervision/support/ModelClueDistributionAware.java +++ b/src/main/java/com/biutag/supervision/support/ModelClueDistributionAware.java @@ -51,7 +51,7 @@ public class ModelClueDistributionAware { log.info("新增模型【{}】分发任务", model.getModelName()); String expression = model.getDistributionCycleExpression(); if (StrUtil.isBlank(expression)) { - throw new RuntimeException("分发周期配置[expression]为空"); + return; } if (taskMap.containsKey(model.getId())) { remove(model.getId()); diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 506acbc..7c967c0 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -19,9 +19,9 @@ spring: port: 6379 password: 123456 -mybatis-plus: - configuration: - log-impl: org.apache.ibatis.logging.stdout.StdOutImpl +#mybatis-plus: +# configuration: +# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl fdfs: tracker-list: #TrackerList参数,支持多个 diff --git a/src/main/resources/mapper/ProfilePoliceMapper.xml b/src/main/resources/mapper/ProfilePoliceMapper.xml index a13a5cd..12b9e6a 100644 --- a/src/main/resources/mapper/ProfilePoliceMapper.xml +++ b/src/main/resources/mapper/ProfilePoliceMapper.xml @@ -28,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND d.statistics_group_id = #{departGroupId} - AND pc.score > 0 + AND p.name like concat('%', #{name}, '%') diff --git a/src/main/resources/static/templates/【工作机制】个人极端暴力风险数字督察灵敏感知体系风险赋分及预警处置机制.doc b/src/main/resources/static/templates/【工作机制】个人极端暴力风险数字督察灵敏感知体系风险赋分及预警处置机制.doc new file mode 100644 index 0000000..851ede3 Binary files /dev/null and b/src/main/resources/static/templates/【工作机制】个人极端暴力风险数字督察灵敏感知体系风险赋分及预警处置机制.doc differ diff --git a/src/test/java/com/biutag/supervision/tools/ExcelTest.java b/src/test/java/com/biutag/supervision/tools/ExcelTest.java new file mode 100644 index 0000000..dc24199 --- /dev/null +++ b/src/test/java/com/biutag/supervision/tools/ExcelTest.java @@ -0,0 +1,41 @@ +package com.biutag.supervision.tools; + +import cn.hutool.core.util.StrUtil; +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.ExcelReader; +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.read.listener.ReadListener; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.biutag.supervision.pojo.dto.DataCaseVerifImportDto; +import com.biutag.supervision.pojo.entity.SupDepart; +import jakarta.validation.ConstraintViolation; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * @author wxc + * @date 2024/11/13 + */ +public class ExcelTest { + + public void test() throws FileNotFoundException { + File file = new File(""); + + ExcelReader excelReader = EasyExcel.read(new FileInputStream(file), HdtExcelDto.class, new ReadListener() { + @Override + public void invoke(DataCaseVerifImportDto data, AnalysisContext analysisContext) { + + + } + + @Override + public void doAfterAllAnalysed(AnalysisContext analysisContext) { + + } + }).build(); + } +} diff --git a/src/test/java/com/biutag/supervision/tools/GenCodeTests.java b/src/test/java/com/biutag/supervision/tools/GenCodeTests.java index f57ee08..b9769ae 100644 --- a/src/test/java/com/biutag/supervision/tools/GenCodeTests.java +++ b/src/test/java/com/biutag/supervision/tools/GenCodeTests.java @@ -25,7 +25,7 @@ public class GenCodeTests { @Test public void genEntity() throws TemplateException, IOException { - String tableName = "depart_score"; + String tableName = "risk_model_task_clue"; String tableSchema = "negative"; boolean genMapper = true; boolean genService = true; diff --git a/src/test/java/com/biutag/supervision/tools/HdtExcelDto.java b/src/test/java/com/biutag/supervision/tools/HdtExcelDto.java new file mode 100644 index 0000000..bf6a5f7 --- /dev/null +++ b/src/test/java/com/biutag/supervision/tools/HdtExcelDto.java @@ -0,0 +1,26 @@ +package com.biutag.supervision.tools; + +import com.alibaba.excel.annotation.ExcelProperty; +import lombok.Getter; +import lombok.Setter; + +import java.time.LocalDateTime; + +/** + * @author wxc + * @date 2024/11/13 + */ +@Setter +@Getter +public class HdtExcelDto { + + @ExcelProperty("姓名") + private String departId; + + @ExcelProperty("部门") + private String departName; + + @ExcelProperty("姓名") + private LocalDateTime discoveryTime; + +}