1、个人年度积分功能优化

main
zhc077 1 year ago
parent ad6d1df069
commit 590e6a1528
  1. 26
      jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualScore/service/impl/PersonalCompScoreServiceImpl.java

@ -57,6 +57,11 @@ public class PersonalCompScoreServiceImpl extends ServiceImpl<PersonalCompScoreM
@Autowired
private ISysUserService iSysUserService;
private static final Integer ONE_HUNDRED = 100;
private static final Double ZERO_POINT_FIVE = 0.5;
private static final Double ZERO_POINT_TWO = 0.2;
@Override
public void collectScore(PersonalCompScore personalCompScore) {
@ -91,6 +96,7 @@ public class PersonalCompScoreServiceImpl extends ServiceImpl<PersonalCompScoreM
AnnualCompAward annualCompAward = iAnnualCompAwardService.getById("获奖理理表id");
if (ObjectUtils.isEmpty(annualCompAward)) return;
Integer wardsort = 0;
//权重 百分比
String weightVal;
switch (wardsort) {
case 1:
@ -117,16 +123,16 @@ public class PersonalCompScoreServiceImpl extends ServiceImpl<PersonalCompScoreM
);
//参与形式 个人、团队,键值对 N-个人 Y-团队
//3、计算积分
double baseScore = mul(compweight_val, new Double(weightVal));
double baseScore = mul(compweight_val, div(new Double(weightVal), ONE_HUNDRED));
AtomicReference<Double> score = new AtomicReference<>((double) 0);
if (StringUtils.equals("Y", entryForm)) { //团队赛
Optional.ofNullable(managementList).orElse(new ArrayList<>()).forEach(e -> {
// 参与形式是团队时,队长积分*0.5,职员积分*0.2
//captain 是否队长,自关联表如果是队长则是为0.如果不是存储队长学号
if (StringUtils.equals("0", e.getCaptain())) {
score.set(mul(baseScore, new Double(0.5)));
score.set(mul(baseScore, ZERO_POINT_FIVE));
} else {
score.set(mul(baseScore, new Double(0.2)));
score.set(mul(baseScore, ZERO_POINT_TWO));
}
PersonalCompScore bean = new PersonalCompScore();
@ -179,4 +185,18 @@ public class PersonalCompScoreServiceImpl extends ServiceImpl<PersonalCompScoreM
BigDecimal b2 = BigDecimal.valueOf(v2);
return b1.multiply(b2).doubleValue();
}
/**
* @description: 提供相对精确的除法运算当发生除不尽的情况时
* 精确到小数点后10位的数字四舍五入
* @param: [v1, v2]
* @return: double
* @author: z.h.c
* @date: 23/11/1 08:41
*/
public static double div(double v1, double v2) {
BigDecimal b1 = BigDecimal.valueOf(v1);
BigDecimal b2 = BigDecimal.valueOf(v2);
return b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
}
}

Loading…
Cancel
Save