1、个人总积分功能开发

main
zhc077 1 year ago
parent c989748ec5
commit 6802161647
  1. 76
      jeecg-boot-master/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ComputeUtils.java
  2. 4
      jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualScore/service/IPersonalCompTotalScoreService.java
  3. 57
      jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualScore/service/impl/PersonalCompScoreServiceImpl.java
  4. 36
      jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualScore/service/impl/PersonalCompTotalScoreServiceImpl.java

@ -0,0 +1,76 @@
package org.jeecg.common.util;
import java.math.BigDecimal;
public class ComputeUtils {
//默认除法运算精度
private static final int DEF_DIV_SCALE = 10;
//构造器私有化,让这个类不能实例化
private ComputeUtils() {
}
/**
*提供精确的加法运算
* @param v1
* @param v2
* @return
*/
public static double add(double v1, double v2) {
BigDecimal b1 = BigDecimal.valueOf(v1);
BigDecimal b2 = BigDecimal.valueOf(v2);
return b1.add(b2).doubleValue();
}
/**
*精确的减法运算
* @param v1
* @param v2
* @return
*/
public static double sub(double v1, double v2) {
BigDecimal b1 = BigDecimal.valueOf(v1);
BigDecimal b2 = BigDecimal.valueOf(v2);
return b1.subtract(b2).doubleValue();
}
/**
* 精确的乘法运算
* @param v1
* @param v2
* @return
*/
public static double mul(double v1, double v2) {
BigDecimal b1 = BigDecimal.valueOf(v1);
BigDecimal b2 = BigDecimal.valueOf(v2);
return b1.multiply(b2).doubleValue();
}
/**
//提供(相对)精确的除法运算,当发生除不尽的情况时
//精确到小数点后10位的数字四舍五入
* @param v1 分子
* @param v2 分母
* @return
*/
public static double div(double v1, double v2) {
BigDecimal b1 = BigDecimal.valueOf(v1);
BigDecimal b2 = BigDecimal.valueOf(v2);
return b1.divide(b2, DEF_DIV_SCALE, BigDecimal.ROUND_HALF_UP).doubleValue();
}
public static double div2(double v1, double v2) {
BigDecimal b1 = BigDecimal.valueOf(v1);
BigDecimal b2 = BigDecimal.valueOf(v2);
return b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
}
public static void main(String[] args) {
// System.out.println("args = " + div(39,64));
System.out.println("args2 = " + div2(39,64));
System.out.println("args = " + mul(div2(39,64),new Double(2)));
}
}

@ -1,8 +1,11 @@
package org.jeecg.modules.demo.annualScore.service;
import org.jeecg.modules.demo.annualScore.entity.PersonalCompScore;
import org.jeecg.modules.demo.annualScore.entity.PersonalCompTotalScore;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @Description: 个人总积分
* @Author: jeecg-boot
@ -11,4 +14,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface IPersonalCompTotalScoreService extends IService<PersonalCompTotalScore> {
void saveOrUpdateTotalScore(List<PersonalCompScore> saveList);
}

@ -3,11 +3,13 @@ package org.jeecg.modules.demo.annualScore.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.util.ComputeUtils;
import org.jeecg.modules.demo.annualCompPoint.entity.AnnualCompPoint;
import org.jeecg.modules.demo.annualCompPoint.service.IAnnualCompPointService;
import org.jeecg.modules.demo.annualScore.entity.PersonalCompScore;
import org.jeecg.modules.demo.annualScore.mapper.PersonalCompScoreMapper;
import org.jeecg.modules.demo.annualScore.service.IPersonalCompScoreService;
import org.jeecg.modules.demo.annualScore.service.IPersonalCompTotalScoreService;
import org.jeecg.modules.demo.annualcomp.entity.AnnualComp;
import org.jeecg.modules.demo.annualcomp.service.IAnnualCompService;
import org.jeecg.modules.demo.annualcompaward.entity.AnnualCompAward;
@ -22,9 +24,9 @@ import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
@ -57,12 +59,16 @@ public class PersonalCompScoreServiceImpl extends ServiceImpl<PersonalCompScoreM
@Autowired
private ISysUserService iSysUserService;
@Autowired
private IPersonalCompTotalScoreService iPersonalCompTotalScoreService;
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
@Transactional(rollbackFor = Exception.class)
public void collectScore(PersonalCompScore personalCompScore) {
//年度比赛id
@ -123,16 +129,16 @@ public class PersonalCompScoreServiceImpl extends ServiceImpl<PersonalCompScoreM
);
//参与形式 个人、团队,键值对 N-个人 Y-团队
//3、计算积分
double baseScore = mul(compweight_val, div(new Double(weightVal), ONE_HUNDRED));
double baseScore = ComputeUtils.mul(compweight_val, ComputeUtils.div2(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, ZERO_POINT_FIVE));
score.set(ComputeUtils.mul(baseScore, ZERO_POINT_FIVE));
} else {
score.set(mul(baseScore, ZERO_POINT_TWO));
score.set(ComputeUtils.mul(baseScore, ZERO_POINT_TWO));
}
PersonalCompScore bean = new PersonalCompScore();
@ -166,6 +172,11 @@ public class PersonalCompScoreServiceImpl extends ServiceImpl<PersonalCompScoreM
}
this.saveBatch(saveList);
//个人比赛积分汇总完成,汇总个人总积分
this.iPersonalCompTotalScoreService.saveOrUpdateTotalScore(saveList);
//更新状态为积分已汇总
iAnnualCompPointService.lambdaUpdate()
.eq(AnnualCompPoint::getId, personalCompScore.getId())
.eq(AnnualCompPoint::getIsPj, 1)
@ -180,23 +191,23 @@ public class PersonalCompScoreServiceImpl extends ServiceImpl<PersonalCompScoreM
* @param v2
* @return
*/
public static double mul(double v1, double v2) {
BigDecimal b1 = BigDecimal.valueOf(v1);
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();
}
// public static double mul(double v1, double v2) {
// BigDecimal b1 = BigDecimal.valueOf(v1);
// 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();
// }
}

@ -1,19 +1,51 @@
package org.jeecg.modules.demo.annualScore.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.common.util.ComputeUtils;
import org.jeecg.modules.demo.annualScore.entity.PersonalCompScore;
import org.jeecg.modules.demo.annualScore.entity.PersonalCompTotalScore;
import org.jeecg.modules.demo.annualScore.mapper.PersonalCompTotalScoreMapper;
import org.jeecg.modules.demo.annualScore.service.IPersonalCompTotalScoreService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
/**
* @Description: 个人总积分
* @Author: jeecg-boot
* @Date: 2023-11-01
* @Date: 2023-11-01
* @Version: V1.0
*/
@Service
public class PersonalCompTotalScoreServiceImpl extends ServiceImpl<PersonalCompTotalScoreMapper, PersonalCompTotalScore> implements IPersonalCompTotalScoreService {
@Override
@Transactional(rollbackFor = Exception.class)
public void saveOrUpdateTotalScore(List<PersonalCompScore> list) {
List<PersonalCompTotalScore> updateList = new LinkedList<>();
Optional.ofNullable(list).orElse(new LinkedList<>()).forEach(e -> {
PersonalCompTotalScore p = this.getOne(new LambdaQueryWrapper<PersonalCompTotalScore>()
.eq(PersonalCompTotalScore::getWorkOn, e.getWorkOn())
.apply("limit 1"));
//为空则为首次累计,新增操作
if ((ObjectUtils.isEmpty(p))) {
PersonalCompTotalScore p2 = new PersonalCompTotalScore();
BeanUtils.copyProperties(e, p2);
updateList.add(p2);
} else { //更新操作
p.setScore(ComputeUtils.add(p.getScore(), e.getScore()));
p.setUpdateTime(new Date());
updateList.add(p);
}
});
this.saveOrUpdateBatch(updateList);
}
}

Loading…
Cancel
Save