Browse Source

fit: 个人风险指数赋分

main
wxc 1 year ago
parent
commit
2a9959729d
  1. 10
      src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java
  2. 29
      src/main/java/com/biutag/supervision/job/ScoreJob.java
  3. 2
      src/main/java/com/biutag/supervision/pojo/domain/ProfilePolice.java
  4. 5
      src/main/java/com/biutag/supervision/service/BusinessPoliceService.java
  5. 51
      src/main/java/com/biutag/supervision/service/ProfilePoliceService.java

10
src/main/java/com/biutag/supervision/controller/sensitivePerception/ProfilePoliceController.java

@ -26,6 +26,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
@ -140,8 +141,10 @@ public class ProfilePoliceController {
List<Integer> problemTypeRadarData = problemTypeBarList.stream().map(BarItem::getValue).toList();
profilePolice.setProblemTypeRadarIndicator(problemTypeRadarIndicator);
profilePolice.setProblemTypeRadarData(problemTypeRadarData);
//
profilePolice.setScore(profilePoliceService.getPoliceScore(beginTime, endTime, idCode));
List<Object> result = profilePoliceService.getPoliceScore(beginTime, endTime, idCode);
profilePolice.setScore((BigDecimal) result.get(0));
profilePolice.setExpression(result.get(1).toString());
return Result.success(profilePolice);
}
@ -160,7 +163,8 @@ public class ProfilePoliceController {
Page<Negative> pageData = negativeService.page(page, new LambdaQueryWrapper<Negative>()
.between(Negative::getDiscoveryTime, beginTime, endTime)
.in(Negative::getId, negativeIds)
.in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue())));
.in(Negative::getCheckStatus, List.of(InspectCaseEnum.TRUE.getValue(), InspectCaseEnum.PARTIALLY_TRUE.getValue()))
.orderByDesc(Negative::getUpdTime));
return Result.success(pageData);
}

29
src/main/java/com/biutag/supervision/job/ScoreJob.java

@ -1,6 +1,7 @@
package com.biutag.supervision.job;
import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.biutag.supervision.constants.enums.NegativeLevelEnum;
import com.biutag.supervision.mapper.NegativeBlameMapper;
import com.biutag.supervision.mapper.SupDictContentMapper;
@ -37,42 +38,44 @@ public class ScoreJob {
private final SupDictContentMapper supDictContentMapper;
// @Scheduled(fixedRate = 6000000)
@Scheduled(fixedRate = 600000)
public void updateScore() {
System.out.println("updateScore-------------------------------------------------");
List<NegativeBlame> negativeBlames = blameMapper.selectVerifyTrue();
String formula = "%s + (1 * %s) + (1 * %s)";
List<NegativeScorePolice> scorePolices = negativeBlames.stream().map(blame -> {
String formula = "%s + (%s * %s) + (%s * %s)";
negativeBlames.forEach(blame -> {
Negative negative = negativeService.getById(blame.getNegativeId());
NegativeScorePolice negativeScorePolice = new NegativeScorePolice()
.setNegativeId(blame.getNegativeId())
.setIdCode(blame.getBlameIdCode())
.setDiscoveryTime(negative.getDiscoveryTime())
.setIdCode(blame.getBlameIdCode());
.setIdCode(blame.getBlameIdCode())
.setBusinessTypeCode(negative.getBusinessTypeCode())
.setCreateTime(LocalDateTime.now());
List<NegativeProblemRelation> problems = problemRelationService.list(blame.getNegativeId(), blame.getBlameId());
List<String> codes = problems.stream().map(NegativeProblemRelation::getThreeLevelCode).toList();
if (codes.isEmpty()) {
throw new RuntimeException("数据异常");
return;
}
SupDictProblemType problemType = supDictContentMapper.selectOneByMaxScore(codes);
LocalDateTime endTime = negative.getDiscoveryTime();
LocalDateTime beginTime = endTime.minusYears(1);
int frequency = blameService.countByTrue(blame.getBlameIdCode(), problemType.getParentCode(), beginTime, endTime);
String expression = String.format(formula,
problemType.getScore(),
problemType.getScore(),
NegativeLevelEnum.GENERAL_IMPACT.getScore(),
problemType.getScore(),
ScoreRule.getFrequencyScore(frequency));
negativeScorePolice.setExpression(expression);
double calculate = NumberUtil.calculate(expression);
double score = NumberUtil.roundHalfEven(calculate, 2).doubleValue();
negativeScorePolice.setScore(score);
negativeScorePolice.setCreateTime(LocalDateTime.now());
return negativeScorePolice;
}).toList();
if (!scorePolices.isEmpty()) {
negativeScorePoliceService.saveBatch(scorePolices);
}
negativeScorePolice.setScore(score)
.setExpression(expression);
negativeScorePoliceService.remove(new LambdaQueryWrapper<NegativeScorePolice>().eq(NegativeScorePolice::getNegativeId, negative.getId()).eq(NegativeScorePolice::getIdCode, blame.getBlameIdCode()));
negativeScorePoliceService.save(negativeScorePolice);
});
}

2
src/main/java/com/biutag/supervision/pojo/domain/ProfilePolice.java

@ -19,6 +19,8 @@ public class ProfilePolice {
private BigDecimal score;
private String expression;
private SupPolice policeInfo = new SupPolice();
private NegativeInfo negativeInfo = new NegativeInfo();
private List<PieItem> problemSourcesList = new ArrayList<>();

5
src/main/java/com/biutag/supervision/service/BusinessPoliceService.java

@ -2,6 +2,7 @@ package com.biutag.supervision.service;
import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -428,5 +429,9 @@ public class BusinessPoliceService extends ServiceImpl<BusinessPoliceMapper, Bus
}
}
public List<BusinessPolice> list(Date beginTime, Date endTime, String businessType) {
return list(new LambdaQueryWrapper<BusinessPolice>().between(BusinessPolice::getDate, beginTime, endTime).eq(BusinessPolice::getBusinessType, businessType));
}
}

51
src/main/java/com/biutag/supervision/service/ProfilePoliceService.java

@ -2,16 +2,14 @@ package com.biutag.supervision.service;
import cn.hutool.core.util.NumberUtil;
import com.biutag.supervision.constants.enums.BusinessTypeEnum;
import com.biutag.supervision.pojo.entity.BusinessPolice;
import com.biutag.supervision.pojo.entity.NegativeScorePolice;
import com.biutag.supervision.pojo.entity.SupPolice;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -32,6 +30,10 @@ public class ProfilePoliceService {
private final NegativeScorePoliceService negativeScorePoliceService;
private final BusinessPoliceService businessPoliceService;
private final SupPoliceService policeService;
// 业务权重 = 单个业务风险指数 / 总业务风险指数之和
public double getBusinessWeight(Double totalScore, List<NegativeScorePolice> businessScorePolice) {
if (totalScore == 0) {
@ -58,8 +60,29 @@ public class ProfilePoliceService {
return Math.sqrt(group.values().stream().mapToDouble(val -> Math.pow(val.size() - avgNumber, 2)).sum() / policeSize);
}
// 业务差异值1 = (个人问题发生率 - 平均问题发生率) / 业务标准差
// 平均问题发生率 = 总问题数 / 总业务量
// 个人问题发生率 = 个人问题数 / 个人业务量
public double getDiff1(List<NegativeScorePolice> businessScorePolice, SupPolice police, Date beginTime, Date endTime, String businessTypeCode, double sd) {
if (sd == 0) {
return 0;
}
List<BusinessPolice> businessPolices = businessPoliceService.list(beginTime, endTime, businessTypeCode);
// 总业务量
int totalBusinessSize = businessPolices.stream().mapToInt(BusinessPolice::getNumber).sum();
// 平均问题发生率
double avgRate = totalBusinessSize == 0? 0: NumberUtil.div(businessScorePolice.size(), totalBusinessSize);
// 个人问题数
long personSize = businessScorePolice.stream().filter(item -> police.getIdCode().equals(item.getIdCode())).count();
// 个人业务量
long personBusinessSize = businessPolices.stream().filter(item -> police.getName().equals(item.getPoliceName()) && police.getEmpNo().equals(item.getEmpNo())).count();
// 个人问题发生率
double personRate = personBusinessSize == 0? 0: NumberUtil.div(personSize, personBusinessSize);
return NumberUtil.div(personRate - avgRate, sd);
}
// 业务差异值2 = (问题数 - 平均问题数) / 业务标准差
public double getDiff(List<NegativeScorePolice> businessScorePolice, String idCode, double avgNumber, double sd) {
public double getDiff2(List<NegativeScorePolice> businessScorePolice, String idCode, double avgNumber, double sd) {
if (sd == 0) {
return 0;
}
@ -67,6 +90,7 @@ public class ProfilePoliceService {
return NumberUtil.div(size - avgNumber, sd);
}
public double getBusinessScore(double diff) {
return 50 + (diff * 15);
}
@ -79,9 +103,11 @@ public class ProfilePoliceService {
// 业务风险指数 = 50 + (业务差异值 * 15)
// 业务权重 = 单个业务风险指数 / 总业务风险指数之和
// 个人风险指数 = sum(业务风险指数 * 业务权重)
public BigDecimal getPoliceScore(Date beginTime, Date endTime, String idCode) {
public List<Object> getPoliceScore(Date beginTime, Date endTime, String idCode) {
List<NegativeScorePolice> scorePolices = negativeScorePoliceService.list(beginTime, endTime);
Double totalScore = scorePolices.stream().mapToDouble(NegativeScorePolice::getScore).sum();
SupPolice police = policeService.getByIdCode(idCode);
List<String> expressionArr = new ArrayList<>();
double policeScore = Arrays.stream(BusinessTypeEnum.values()).mapToDouble(businessTypeEnum -> {
List<NegativeScorePolice> businessScorePolice = scorePolices.stream().filter(item -> item.getBusinessTypeCode().equals(businessTypeEnum.getValue())).toList();
// 业务涉及人数
@ -91,19 +117,22 @@ public class ProfilePoliceService {
// 业务标准差
double sd = getSd(businessScorePolice, avgNumber, policeSize);
// 业务差异值
double diff = 0;
double diff;
if (businessTypeEnum.getBusinessVolume()) {
diff = getDiff1(businessScorePolice, police, beginTime, endTime, businessTypeEnum.getValue(), sd);
} else {
diff = getDiff(businessScorePolice, idCode, avgNumber, sd);
diff = getDiff2(businessScorePolice, idCode, avgNumber, sd);
}
// 业务风险指数
double businessScore = getBusinessScore(diff);
// 业务权重
double businessWeight = getBusinessWeight(totalScore, businessScorePolice);
expressionArr.add(String.format("(%s * %s)", businessScore, businessWeight));
return NumberUtil.mul(businessScore, businessWeight);
}).sum();
return NumberUtil.roundHalfEven(policeScore, 2);
BigDecimal score = NumberUtil.roundHalfEven(policeScore, 2);
String expression = String.join(" + ", expressionArr);
return List.of(score, expression);
}
}

Loading…
Cancel
Save