Jelajahi Sumber

新增重新计算接口

‘xugp 1 tahun lalu
induk
melakukan
0da96152bf

+ 8 - 7
ims-service/ims-eval/src/main/java/com/ims/eval/controller/TestController.java

@@ -5,30 +5,31 @@ import com.ims.eval.schedule.ScoreCalculationSchedule;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
 /**
- * @authormmzs
+ * @authorxugp
  * @date :Created in 2023/3/15 9:46
- * @description
+ * @description计算控制器
  * @modified By:
  * @version: $
  */
 
 @RestController
-@RequestMapping("//test")
-public class TestController {
+@RequestMapping("//calculator")
+public class CalculatorController {
 
 	@Autowired
 	private ScoreCalculationSchedule scoreCalculationSchedule;
 
 	@GetMapping("/cron")
-	public R test(){
-		boolean b = scoreCalculationSchedule.doTask();
+	public R test(@RequestParam("id") String id){
+		boolean b = scoreCalculationSchedule.doTask(id);
 		if (b){
 			return R.ok().data(b);
 		}else {
-			return R.error().data("保存失败!");
+			return R.error().data("计算失败!");
 		}
 	}
 }

+ 52 - 41
ims-service/ims-eval/src/main/java/com/ims/eval/schedule/ScoreCalculationSchedule.java

@@ -51,60 +51,68 @@ public class ScoreCalculationSchedule {
 	private CalculateIndicatorItemInfoMapper calculateIndicatorItemInfoMapper;
 
 	/*@Scheduled(cron = "* 10 11 ? * 3")*/
-	public boolean doTask(){
+	public boolean doTask(String id){
 
 		boolean save = true;
 		try {
 
+			//判断本次考评的计算记录是否存在  如果存在,删除计算记录
+			QueryWrapper<EvaluationScoreCount> qw1 = new QueryWrapper<>();
+			if (StringUtils.isNotEmpty(id)) {
+				qw1.lambda().eq(EvaluationScoreCount::getOrganizationEvaluationId, id);
+			}
+			List<EvaluationScoreCount> evaluationScoreCountList = iEvaluatioinScoreCountService.list(qw1);
+			if (evaluationScoreCountList.size() >0){
+				List<String> idList = evaluationScoreCountList.stream().map(EvaluationScoreCount::getId).collect(Collectors.toList());
+				iEvaluatioinScoreCountService.removeByIds(idList);
+			}
+
 			//加载单位/部门考评记录
 			//todo 后续添加查询条件
-			QueryWrapper<OrganizationEvaluation> or = new QueryWrapper<>();
-			List<OrganizationEvaluation> organizationEvaluations = organizationEvaluationMapper.selectList(or);
-			if (organizationEvaluations.size() <= 0){
+			OrganizationEvaluation organizationEvaluation = organizationEvaluationMapper.selectById(id);
+			if (organizationEvaluation == null){
 				throw new Exception("考评记录为空!!!");
 			}
-			for (OrganizationEvaluation organizationEvaluation : organizationEvaluations){
-				//加载该考评记录下的考评指标明细数据
-				List<String> list = Arrays.asList(organizationEvaluation.getOrganizationEvaluationRuleId().split(","));
+			//加载该考评记录下的考评指标明细数据
+			List<String> list = Arrays.asList(organizationEvaluation.getOrganizationEvaluationRuleId().split(","));
 
-				QueryWrapper<OrganizationEvaluationInfo> qw = new QueryWrapper<>();
-				if (StringUtils.isNotEmpty(organizationEvaluation.getOrganizationEvaluationRuleId())) {
-					qw.lambda().in(OrganizationEvaluationInfo::getOrganizationEvaluationRuleId,list);
-				}
-				List<OrganizationEvaluationInfo> organizationEvaluationInfos= organizationEvaluationInfoMapper.selectList(qw);
-				if (organizationEvaluationInfos.size() > 0){
-					//对考评规则id进行分组
-					Map<String, List<OrganizationEvaluationInfo>> collect = organizationEvaluationInfos.stream().collect(Collectors.groupingBy(OrganizationEvaluationInfo::getOrganizationEvaluationRuleId));
-					for (Map.Entry<String, List<OrganizationEvaluationInfo>> entry : collect.entrySet()){
-						//对指标id进行分组
-						if (entry.getValue().size() > 0){
-							Map<String, List<OrganizationEvaluationInfo>> collectIn = entry.getValue().stream().collect(Collectors.groupingBy(OrganizationEvaluationInfo::getIndicatorId));
-							for (Map.Entry<String, List<OrganizationEvaluationInfo>> listEntry : collectIn.entrySet()){
-								Indicator indicator = indicatorMapper.selectById(listEntry.getKey());
-								QueryWrapper<EvaluationScoringRule> e = new QueryWrapper<>();
-								if (StringUtils.isNotEmpty(indicator.getIndicatorCode())) {
-									e.lambda().eq(EvaluationScoringRule::getIndicatorId,indicator.getIndicatorCode());
-								}
-								EvaluationScoringRule evaluationScoringRule = evaluationScoringRuleMapper.selectOne(e);
-								if (evaluationScoringRule != null){
-									String calculation = replace(listEntry.getValue(), evaluationScoringRule);
-									log.info(indicator.getIndicatorCode()+"得分为" + calculation);
-									//将得分存入考评得分统计表
-									EvaluationScoreCount evaluationScoreCount = EvaluationScoreCount.builder()
-										.indicatorId(listEntry.getKey())
-										.organizationEvaluationRuleId(entry.getKey())
-										.organizationEvaluationId(organizationEvaluation.getId())
-										.score(Double.parseDouble(calculation))
-										.build();
-									save = iEvaluatioinScoreCountService.save(evaluationScoreCount);
-								}
+			QueryWrapper<OrganizationEvaluationInfo> qw = new QueryWrapper<>();
+			if (StringUtils.isNotEmpty(organizationEvaluation.getOrganizationEvaluationRuleId())) {
+				qw.lambda().in(OrganizationEvaluationInfo::getOrganizationEvaluationRuleId,list);
+			}
+			List<OrganizationEvaluationInfo> organizationEvaluationInfos= organizationEvaluationInfoMapper.selectList(qw);
+			if (organizationEvaluationInfos.size() > 0){
+				//对考评规则id进行分组
+				Map<String, List<OrganizationEvaluationInfo>> collect = organizationEvaluationInfos.stream().collect(Collectors.groupingBy(OrganizationEvaluationInfo::getOrganizationEvaluationRuleId));
+				for (Map.Entry<String, List<OrganizationEvaluationInfo>> entry : collect.entrySet()){
+					//对指标id进行分组
+					if (entry.getValue().size() > 0){
+						Map<String, List<OrganizationEvaluationInfo>> collectIn = entry.getValue().stream().collect(Collectors.groupingBy(OrganizationEvaluationInfo::getIndicatorId));
+						for (Map.Entry<String, List<OrganizationEvaluationInfo>> listEntry : collectIn.entrySet()){
+							Indicator indicator = indicatorMapper.selectById(listEntry.getKey());
+							QueryWrapper<EvaluationScoringRule> e = new QueryWrapper<>();
+							if (StringUtils.isNotEmpty(indicator.getIndicatorCode())) {
+								e.lambda().eq(EvaluationScoringRule::getIndicatorId,indicator.getIndicatorCode());
+							}
+							EvaluationScoringRule evaluationScoringRule = evaluationScoringRuleMapper.selectOne(e);
+							if (evaluationScoringRule != null){
+								String calculation = replace(listEntry.getValue(), evaluationScoringRule);
+								log.info(indicator.getIndicatorCode()+"得分为" + calculation);
+								//将得分存入考评得分统计表
+								EvaluationScoreCount evaluationScoreCount = EvaluationScoreCount.builder()
+									.indicatorId(listEntry.getKey())
+									.organizationEvaluationRuleId(entry.getKey())
+									.organizationEvaluationId(organizationEvaluation.getId())
+									.score(Double.parseDouble(calculation))
+									.build();
+								save = iEvaluatioinScoreCountService.save(evaluationScoreCount);
 							}
 						}
 					}
-
-				}else {
-					throw new Exception("考评指标明细数据为空!!");
 				}
+
+			}else {
+				throw new Exception("考评指标明细数据为空!!");
 			}
 
 		}catch (Exception e){
@@ -180,6 +188,9 @@ public class ScoreCalculationSchedule {
 					String range = intervalScoringTable.getRange();
 					if (rangeHandle(range)){
 						score =  MathCalculatorUtil.handle(intervalScoringTable.getRegularExpression().trim());
+						if (!StringUtils.isNotEmpty(score)){
+							score = "0";
+						}
 						break;
 					}
 				}

+ 1 - 0
ims-service/ims-eval/src/main/java/com/ims/eval/service/custom/WorkflowService.java

@@ -203,6 +203,7 @@ public class WorkflowService {
 				break;
 			case "yddwkplc"://月度单位考评流程
 				organizationEvaluationService.editState(bizKey,taskName);
+
 				break;
 			case "dwkpmbxd"://单位考评目标修订
 

+ 21 - 40
ims-service/ims-eval/src/main/java/com/ims/eval/service/impl/CalculateIndicatorItemInfoServiceImpl.java

@@ -11,9 +11,12 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
 
+import static org.codehaus.groovy.runtime.DefaultGroovyMethods.collect;
+
 /**
  * <p>
  * 计算指标项明细 服务实现类
@@ -76,8 +79,17 @@ public class CalculateIndicatorItemInfoServiceImpl extends ServiceImpl<Calculate
 	@Transactional
 	public int saveCalculate(List<CalculateIndicatorItemInfo> list) throws Exception {
 
-		//遍历list解析最大值和最小值
 		if (list.size() > 0){
+
+			//判断计算指标明细中之前是否存在记录 如果存在删除之前记录,重新新增
+			List<CalculateIndicatorItemInfo> calculateIndicatorItemInfo = calculateIndicatorItemInfoMapper.selectList(list.get(0).getOrganizationType(),list.get(0).getCheckCycle(),list.get(0).getYear(),list.get(0).getMonth());
+
+			if (calculateIndicatorItemInfo.size() > 0){
+				List<String> idList = calculateIndicatorItemInfo.stream().map(CalculateIndicatorItemInfo::getId).collect(Collectors.toList());
+				calculateIndicatorItemInfoMapper.deleteBatchIds(idList);
+			}
+
+			//遍历list解析最大值和最小值
 			Map<String, List<CalculateIndicatorItemInfo>> collect = list.stream().collect(Collectors.groupingBy(CalculateIndicatorItemInfo::getOptionCode));
 			for (Map.Entry<String, List<CalculateIndicatorItemInfo>> listEntry : collect.entrySet()){
 
@@ -86,9 +98,11 @@ public class CalculateIndicatorItemInfoServiceImpl extends ServiceImpl<Calculate
 					@Override
 					public int compare(CalculateIndicatorItemInfo u1, CalculateIndicatorItemInfo u2) {
 						double diff = u1.getQuantifiedValue() - u2.getQuantifiedValue();
-						if (diff > 0) {
+						BigDecimal two = new BigDecimal(diff);
+						double three = two.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue();
+						if (three > 0) {
 							return 1;
-						} else if (diff < 0) {
+						} else if (three < 0) {
 							return -1;
 						}
 						return 0; //相等为0
@@ -101,55 +115,22 @@ public class CalculateIndicatorItemInfoServiceImpl extends ServiceImpl<Calculate
 				CalculateIndicatorItemInfo minNum = listEntry.getValue().get(0);
 				minNum.setMark("0");
 
-				//判断计算指标明细中之前是否存在记录 如果存在删除之前记录,重新新增
-				QueryWrapper<CalculateIndicatorItemInfo> qw = new QueryWrapper<>();
-				qw.lambda().eq(CalculateIndicatorItemInfo::getYear, maxNum.getYear());
-				qw.lambda().eq(CalculateIndicatorItemInfo::getMonth, maxNum.getMonth());
-				qw.lambda().eq(CalculateIndicatorItemInfo::getOptionCode, maxNum.getOptionCode());
-				qw.lambda().eq(CalculateIndicatorItemInfo::getCheckCycle, maxNum.getCheckCycle());
-				qw.lambda().eq(CalculateIndicatorItemInfo::getOrganizationType, maxNum.getOrganizationType());
-				qw.lambda().eq(CalculateIndicatorItemInfo::getMark, maxNum.getMark());
-				CalculateIndicatorItemInfo calculateIndicatorItemInfo = calculateIndicatorItemInfoMapper.selectOne(qw);
-
-				if (calculateIndicatorItemInfo != null){
-					calculateIndicatorItemInfoMapper.deleteById(calculateIndicatorItemInfo.getId());
-				}
 
 				if (listEntry.getKey().equals("CZ")){
 					//存储最大值
 					maxNum.setOptionCode("CZMAX");
+					minNum.setOptionCode("CZMIN");
 				}else if (listEntry.getKey().equals("LRGXL")){
 					maxNum.setOptionCode("LRGXKLMAX");
+					minNum.setOptionCode("LRGXKLMIN");
 				}else if (listEntry.getKey().equals("DWQWLR")){
 					maxNum.setOptionCode("DWQWLRMAX");
+					minNum.setOptionCode("DWQWLRMIN");
 				}
 				int insert = calculateIndicatorItemInfoMapper.insert(maxNum);
 
-				//判断计算指标明细中之前是否存在记录 如果存在删除之前记录,重新新增
-				QueryWrapper<CalculateIndicatorItemInfo> qw1 = new QueryWrapper<>();
-				qw1.lambda().eq(CalculateIndicatorItemInfo::getYear, minNum.getYear());
-				qw1.lambda().eq(CalculateIndicatorItemInfo::getMonth, minNum.getMonth());
-				qw1.lambda().eq(CalculateIndicatorItemInfo::getOptionCode, minNum.getOptionCode());
-				qw1.lambda().eq(CalculateIndicatorItemInfo::getCheckCycle, minNum.getCheckCycle());
-				qw1.lambda().eq(CalculateIndicatorItemInfo::getOrganizationType, minNum.getOrganizationType());
-				qw1.lambda().eq(CalculateIndicatorItemInfo::getMark, minNum.getMark());
-				CalculateIndicatorItemInfo calculateIndicatorItemInfo1 = calculateIndicatorItemInfoMapper.selectOne(qw1);
-
-				if (calculateIndicatorItemInfo1 != null){
-					calculateIndicatorItemInfoMapper.deleteById(calculateIndicatorItemInfo1.getId());
-				}
-
-				if (listEntry.getKey().equals("CZ")){
-					//存储最小值
-					minNum.setOptionCode("CZMIN");
-				}else if (listEntry.getKey().equals("LRGXL")){
-					//存储最小值
-					minNum.setOptionCode("LRGXKLMIN");
-				}else if (listEntry.getKey().equals("DWQWLR")){
-					//存储最小值
-					minNum.setOptionCode("DWQWLRMIN");
-				}
 				int insert1 = calculateIndicatorItemInfoMapper.insert(minNum);
+				System.out.println(insert1);
 			}
 		}else {
 			throw new Exception("计算指标项明细为空");