forked from wangjiadong/comp
parent
9fd85881c7
commit
ad6d1df069
4 changed files with 198 additions and 4 deletions
@ -1,23 +1,182 @@ |
|||||||
package org.jeecg.modules.demo.annualScore.service.impl; |
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.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.entity.PersonalCompScore; |
||||||
import org.jeecg.modules.demo.annualScore.mapper.PersonalCompScoreMapper; |
import org.jeecg.modules.demo.annualScore.mapper.PersonalCompScoreMapper; |
||||||
import org.jeecg.modules.demo.annualScore.service.IPersonalCompScoreService; |
import org.jeecg.modules.demo.annualScore.service.IPersonalCompScoreService; |
||||||
|
import org.jeecg.modules.demo.annualcomp.entity.AnnualComp; |
||||||
|
import org.jeecg.modules.demo.annualcomp.service.IAnnualCompService; |
||||||
|
import org.jeecg.modules.demo.annualcompaward.entity.AnnualCompAward; |
||||||
|
import org.jeecg.modules.demo.annualcompaward.service.IAnnualCompAwardService; |
||||||
|
import org.jeecg.modules.demo.annualcompetitionprojectregistration.entity.TeamManagement; |
||||||
|
import org.jeecg.modules.demo.annualcompetitionprojectregistration.service.ITeamManagementService; |
||||||
|
import org.jeecg.modules.demo.comp.entity.Comp; |
||||||
|
import org.jeecg.modules.demo.comp.service.ICompService; |
||||||
|
import org.jeecg.modules.system.entity.SysDepart; |
||||||
|
import org.jeecg.modules.system.entity.SysUser; |
||||||
|
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.stereotype.Service; |
||||||
|
import org.springframework.util.ObjectUtils; |
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
import java.math.BigDecimal; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.LinkedList; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Optional; |
||||||
|
import java.util.concurrent.atomic.AtomicReference; |
||||||
|
|
||||||
/** |
/** |
||||||
* @Description: 个人比赛积分 |
* @Description: 个人比赛积分 |
||||||
* @Author: jeecg-boot |
* @Author: jeecg-boot |
||||||
* @Date: 2023-10-30 |
* @Date: 2023-10-30 |
||||||
* @Version: V1.0 |
* @Version: V1.0 |
||||||
*/ |
*/ |
||||||
@Service |
@Service |
||||||
public class PersonalCompScoreServiceImpl extends ServiceImpl<PersonalCompScoreMapper, PersonalCompScore> implements IPersonalCompScoreService { |
public class PersonalCompScoreServiceImpl extends ServiceImpl<PersonalCompScoreMapper, PersonalCompScore> implements IPersonalCompScoreService { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private IAnnualCompService iAnnualCompService; |
||||||
|
@Autowired |
||||||
|
private IAnnualCompPointService iAnnualCompPointService; |
||||||
|
@Autowired |
||||||
|
private ICompService iCompService; |
||||||
|
@Autowired |
||||||
|
private IAnnualCompAwardService iAnnualCompAwardService; |
||||||
|
@Autowired |
||||||
|
private ITeamManagementService iTeamManagementService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ISysDepartService iSysDepartService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ISysUserService iSysUserService; |
||||||
|
|
||||||
@Override |
@Override |
||||||
public void collectScore(PersonalCompScore personalCompScore) { |
public void collectScore(PersonalCompScore personalCompScore) { |
||||||
|
|
||||||
|
//年度比赛id
|
||||||
|
String annualCompId = personalCompScore.getAnnualCompId(); |
||||||
|
|
||||||
|
AnnualComp annualComp = iAnnualCompService.getById(annualCompId); |
||||||
|
if (ObjectUtils.isEmpty(annualComp)) return; |
||||||
|
|
||||||
|
Comp comp = iCompService.getById(annualComp.getCompid()); |
||||||
|
if (ObjectUtils.isEmpty(comp)) return; |
||||||
|
//项目分值
|
||||||
|
Integer compweight = comp.getCompweight(); |
||||||
|
double compweight_val = compweight.doubleValue(); |
||||||
|
|
||||||
|
//年度比赛项目,只有isPj为1时才能触发个人比赛积分汇总
|
||||||
|
AnnualCompPoint annualCompPoint = iAnnualCompPointService.getOne(new LambdaQueryWrapper<AnnualCompPoint>() |
||||||
|
.eq(AnnualCompPoint::getAnnualCompId, annualCompId) |
||||||
|
.eq(AnnualCompPoint::getIsPj, new Integer(1)) |
||||||
|
); |
||||||
|
|
||||||
|
List<PersonalCompScore> saveList = new LinkedList<>(); |
||||||
|
if (!ObjectUtils.isEmpty(annualCompPoint)) { |
||||||
|
//TODO
|
||||||
|
//1、根据年度比赛项目id,查询获取管理(award_persion)列表,即参赛人员及获取奖项顺序号
|
||||||
|
|
||||||
|
//2、遍历获奖理理(award_persion)列表,根据奖项id查询比赛奖项设置表(annual_comp_award)
|
||||||
|
//2.1、比赛奖项设置 根据awardsort奖项顺序,获取对应的奖项权重值
|
||||||
|
//奖项顺序与交期权重值映射关系: wardsort(1:first_weight,2:second_weight,3:third_weight,4:fourth_weight,5:fifth_weight
|
||||||
|
|
||||||
|
|
||||||
|
AnnualCompAward annualCompAward = iAnnualCompAwardService.getById("获奖理理表id"); |
||||||
|
if (ObjectUtils.isEmpty(annualCompAward)) return; |
||||||
|
Integer wardsort = 0; |
||||||
|
String weightVal; |
||||||
|
switch (wardsort) { |
||||||
|
case 1: |
||||||
|
weightVal = annualCompAward.getFifthWeight(); |
||||||
|
break; |
||||||
|
case 2: |
||||||
|
weightVal = annualCompAward.getSecondWeight(); |
||||||
|
break; |
||||||
|
case 3: |
||||||
|
weightVal = annualCompAward.getThirdWeight(); |
||||||
|
break; |
||||||
|
case 4: |
||||||
|
weightVal = annualCompAward.getFourthWeight(); |
||||||
|
break; |
||||||
|
case 5: |
||||||
|
weightVal = annualCompAward.getFifthWeight(); |
||||||
|
break; |
||||||
|
default: |
||||||
|
weightVal = "1"; |
||||||
|
} |
||||||
|
String entryForm = annualCompPoint.getEntryForm(); |
||||||
|
List<TeamManagement> managementList = iTeamManagementService.list(new LambdaQueryWrapper<TeamManagement>() |
||||||
|
.eq(TeamManagement::getEnrollCode, "获奖管理表enroll_code") |
||||||
|
); |
||||||
|
//参与形式 个人、团队,键值对 N-个人 Y-团队
|
||||||
|
//3、计算积分
|
||||||
|
double baseScore = mul(compweight_val, new Double(weightVal)); |
||||||
|
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))); |
||||||
|
} else { |
||||||
|
score.set(mul(baseScore, new Double(0.2))); |
||||||
|
} |
||||||
|
|
||||||
|
PersonalCompScore bean = new PersonalCompScore(); |
||||||
|
bean.setAnnualCompId(annualCompId); |
||||||
|
bean.setAnnualCompP(annualCompPoint.getId()); |
||||||
|
bean.setAnnualId(annualComp.getAnnualid()); |
||||||
|
SysUser sysUser = iSysUserService.getById(e.getUserId()); |
||||||
|
bean.setWorkOn(sysUser.getWorkNo()); |
||||||
|
bean.setName(sysUser.getRealname()); |
||||||
|
SysDepart sysDepart = iSysDepartService.getById(sysUser.getOrgCode()); |
||||||
|
bean.setDepet(sysDepart.getId()); |
||||||
|
bean.setScore(score.get()); |
||||||
|
saveList.add(bean); |
||||||
|
}); |
||||||
|
} else { //个人赛
|
||||||
|
score.set(baseScore); |
||||||
|
TeamManagement teamManagement = managementList.get(0); |
||||||
|
PersonalCompScore bean = new PersonalCompScore(); |
||||||
|
bean.setAnnualCompId(annualCompId); |
||||||
|
bean.setAnnualCompP(annualCompPoint.getId()); |
||||||
|
bean.setAnnualId(annualComp.getAnnualid()); |
||||||
|
SysUser sysUser = iSysUserService.getById(teamManagement.getUserId()); |
||||||
|
bean.setWorkOn(sysUser.getWorkNo()); |
||||||
|
bean.setName(sysUser.getRealname()); |
||||||
|
SysDepart sysDepart = iSysDepartService.getById(sysUser.getOrgCode()); |
||||||
|
bean.setDepet(sysDepart.getId()); |
||||||
|
bean.setScore(score.get()); |
||||||
|
saveList.add(bean); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
this.saveBatch(saveList); |
||||||
|
iAnnualCompPointService.lambdaUpdate() |
||||||
|
.eq(AnnualCompPoint::getId,personalCompScore.getId()) |
||||||
|
.eq(AnnualCompPoint::getIsPj,1) |
||||||
|
.set(AnnualCompPoint::getAnnualCompState,10) |
||||||
|
.update(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 精确的乘法运算 |
||||||
|
* |
||||||
|
* @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(); |
||||||
} |
} |
||||||
} |
} |
||||||
|
Loading…
Reference in new issue