评估考察过期自动打分(80%)提交
This commit is contained in:
		
							parent
							
								
									c1f8d27004
								
							
						
					
					
						commit
						49766c770e
					
				| 
						 | 
					@ -0,0 +1,233 @@
 | 
				
			||||||
 | 
					package shkd.repc.resm.task;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import kd.bos.context.RequestContext;
 | 
				
			||||||
 | 
					import kd.bos.dataentity.OperateOption;
 | 
				
			||||||
 | 
					import kd.bos.dataentity.entity.DynamicObject;
 | 
				
			||||||
 | 
					import kd.bos.dataentity.entity.DynamicObjectCollection;
 | 
				
			||||||
 | 
					import kd.bos.entity.operate.result.OperationResult;
 | 
				
			||||||
 | 
					import kd.bos.exception.KDException;
 | 
				
			||||||
 | 
					import kd.bos.logging.Log;
 | 
				
			||||||
 | 
					import kd.bos.logging.LogFactory;
 | 
				
			||||||
 | 
					import kd.bos.orm.query.QCP;
 | 
				
			||||||
 | 
					import kd.bos.orm.query.QFilter;
 | 
				
			||||||
 | 
					import kd.bos.schedule.api.MessageHandler;
 | 
				
			||||||
 | 
					import kd.bos.schedule.executor.AbstractTask;
 | 
				
			||||||
 | 
					import kd.bos.servicehelper.BusinessDataServiceHelper;
 | 
				
			||||||
 | 
					import kd.bos.servicehelper.operation.OperationServiceHelper;
 | 
				
			||||||
 | 
					import kd.sdk.plugin.Plugin;
 | 
				
			||||||
 | 
					import oracle.jdbc.driver.DatabaseError;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.math.BigDecimal;
 | 
				
			||||||
 | 
					import java.math.RoundingMode;
 | 
				
			||||||
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 评估考察过期自动打分(80%)提交
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class AutomaticScoringTaskPlugin extends AbstractTask implements Plugin {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static final Log logger = LogFactory.getLog(AutomaticScoringTaskPlugin.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 我的评估
 | 
				
			||||||
 | 
					    private static final String MY_EVAL = "resm_myeval_new";
 | 
				
			||||||
 | 
					    // 我的考察
 | 
				
			||||||
 | 
					    private static final String MY_EXAM = "resm_myexam";
 | 
				
			||||||
 | 
					    // 默认评分比例
 | 
				
			||||||
 | 
					    private static final BigDecimal DEFAULT_SCORE_RATIO = new BigDecimal("0.8");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public void execute(RequestContext requestContext, Map<String, Object> map) throws KDException {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            logger.info("开始执行评估考察过期自动打分任务");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 查询过期的我的评估||我的考察
 | 
				
			||||||
 | 
					            Date currentDate = new Date();
 | 
				
			||||||
 | 
					            QFilter qFilter = new QFilter("billstatus", QCP.equals, "A");
 | 
				
			||||||
 | 
					            qFilter.and(new QFilter("evalenddate", QCP.less_than, currentDate));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            logger.debug("构建查询条件: " + qFilter.toString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 处理我的评估
 | 
				
			||||||
 | 
					            processMyEval(qFilter);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 处理我的考察
 | 
				
			||||||
 | 
					            processMyExam(qFilter);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            logger.info("评估考察过期自动打分任务执行完成");
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            logger.error("执行评估考察过期自动打分任务时发生异常", e);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 我的评估处理
 | 
				
			||||||
 | 
					     * @param qFilter
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private void processMyEval(QFilter qFilter) {
 | 
				
			||||||
 | 
					        logger.info("开始处理我的评估数据");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        DynamicObject[] evalRecords = BusinessDataServiceHelper.load(MY_EVAL, "id", qFilter.toArray());
 | 
				
			||||||
 | 
					        if (evalRecords.length == 0) {
 | 
				
			||||||
 | 
					            logger.info("没有找到符合条件的我的评估记录");
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        logger.info("找到" + evalRecords.length + "条待处理的我的评估记录");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        List<DynamicObject> pendingRecords = new ArrayList<>();
 | 
				
			||||||
 | 
					        List<Long> recordIds = Arrays.stream(evalRecords)
 | 
				
			||||||
 | 
					                .map(record -> record.getLong("id"))
 | 
				
			||||||
 | 
					                .collect(Collectors.toList());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Map<Object, DynamicObject> evalMap = BusinessDataServiceHelper.loadFromCache(recordIds.toArray(), MY_EVAL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (DynamicObject evalRecord : evalMap.values()) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                DynamicObjectCollection scoreEntries = evalRecord.getDynamicObjectCollection("entry_stadardscore");
 | 
				
			||||||
 | 
					                if (scoreEntries != null && !scoreEntries.isEmpty()) {
 | 
				
			||||||
 | 
					                    boolean hasUpdate = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    for (DynamicObject scoreEntry : scoreEntries) {
 | 
				
			||||||
 | 
					                        BigDecimal inputScore = scoreEntry.getBigDecimal("std_inputscore");
 | 
				
			||||||
 | 
					                        if (inputScore != null && inputScore.compareTo(BigDecimal.ZERO) == 0) {
 | 
				
			||||||
 | 
					                            BigDecimal standardScore = scoreEntry.getBigDecimal("std_standardscore");
 | 
				
			||||||
 | 
					                            if (standardScore != null && standardScore.compareTo(BigDecimal.ZERO) != 0) {
 | 
				
			||||||
 | 
					                                BigDecimal autoScore = calculateAutoScore(standardScore);
 | 
				
			||||||
 | 
					                                scoreEntry.set("std_inputscore", autoScore);
 | 
				
			||||||
 | 
					                                hasUpdate = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                logger.debug(String.format(
 | 
				
			||||||
 | 
					                                        "评估ID[%s]自动打分: 标准分=%s, 自动分=%s",
 | 
				
			||||||
 | 
					                                        evalRecord.getLong("id"),
 | 
				
			||||||
 | 
					                                        standardScore,
 | 
				
			||||||
 | 
					                                        autoScore
 | 
				
			||||||
 | 
					                                ));
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (hasUpdate) {
 | 
				
			||||||
 | 
					                        pendingRecords.add(evalRecord);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } catch (Exception e) {
 | 
				
			||||||
 | 
					                logger.error("处理评估记录[" + evalRecord.getLong("id") + "]时发生异常", e);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!pendingRecords.isEmpty()) {
 | 
				
			||||||
 | 
					            logger.info("准备处理" + pendingRecords.size() + "条更新的评估记录");
 | 
				
			||||||
 | 
					            operationalProcessing(pendingRecords, MY_EVAL);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            logger.info("没有需要更新的评估记录");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 我的考察处理
 | 
				
			||||||
 | 
					     * @param qFilter
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private void processMyExam(QFilter qFilter) {
 | 
				
			||||||
 | 
					        logger.info("开始处理我的考察数据");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        DynamicObject[] examRecords = BusinessDataServiceHelper.load(MY_EXAM, "id", qFilter.toArray());
 | 
				
			||||||
 | 
					        if (examRecords.length == 0) {
 | 
				
			||||||
 | 
					            logger.info("没有找到符合条件的我的考察记录");
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        logger.info("找到" + examRecords.length + "条待处理的我的考察记录");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        List<DynamicObject> pendingRecords = new ArrayList<>();
 | 
				
			||||||
 | 
					        List<Long> recordIds = Arrays.stream(examRecords)
 | 
				
			||||||
 | 
					                .map(record -> record.getLong("id"))
 | 
				
			||||||
 | 
					                .collect(Collectors.toList());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Map<Object, DynamicObject> examMap = BusinessDataServiceHelper.loadFromCache(recordIds.toArray(), MY_EXAM);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for (DynamicObject examRecord : examMap.values()) {
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                DynamicObjectCollection scoreEntries = examRecord.getDynamicObjectCollection("entry_evalscore");
 | 
				
			||||||
 | 
					                if (scoreEntries != null && !scoreEntries.isEmpty()) {
 | 
				
			||||||
 | 
					                    boolean hasUpdate = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    for (DynamicObject scoreEntry : scoreEntries) {
 | 
				
			||||||
 | 
					                        BigDecimal inputScore = scoreEntry.getBigDecimal("inputscore");
 | 
				
			||||||
 | 
					                        if (inputScore != null && inputScore.compareTo(BigDecimal.ZERO) == 0) {
 | 
				
			||||||
 | 
					                            BigDecimal standardScore = scoreEntry.getBigDecimal("standardscore");
 | 
				
			||||||
 | 
					                            if (standardScore != null && standardScore.compareTo(BigDecimal.ZERO) != 0) {
 | 
				
			||||||
 | 
					                                BigDecimal autoScore = calculateAutoScore(standardScore);
 | 
				
			||||||
 | 
					                                scoreEntry.set("inputscore", autoScore);
 | 
				
			||||||
 | 
					                                hasUpdate = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                                logger.debug(String.format(
 | 
				
			||||||
 | 
					                                        "考察ID[%s]自动打分: 标准分=%s, 自动分=%s",
 | 
				
			||||||
 | 
					                                        examRecord.getLong("id"),
 | 
				
			||||||
 | 
					                                        standardScore,
 | 
				
			||||||
 | 
					                                        autoScore
 | 
				
			||||||
 | 
					                                ));
 | 
				
			||||||
 | 
					                            }
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (hasUpdate) {
 | 
				
			||||||
 | 
					                        pendingRecords.add(examRecord);
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } catch (Exception e) {
 | 
				
			||||||
 | 
					                logger.error("处理考察记录[" + examRecord.getLong("id") + "]时发生异常", e);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (!pendingRecords.isEmpty()) {
 | 
				
			||||||
 | 
					            logger.info("准备处理" + pendingRecords.size() + "条更新的考察记录");
 | 
				
			||||||
 | 
					            operationalProcessing(pendingRecords, MY_EXAM);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            logger.info("没有需要更新的考察记录");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 计算公式
 | 
				
			||||||
 | 
					     * @param standardScore 标准分
 | 
				
			||||||
 | 
					     * @return 分数
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private BigDecimal calculateAutoScore(BigDecimal standardScore) {
 | 
				
			||||||
 | 
					        return standardScore.multiply(DEFAULT_SCORE_RATIO)
 | 
				
			||||||
 | 
					                .setScale(0, RoundingMode.HALF_UP);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 操作处理
 | 
				
			||||||
 | 
					     * @param pendingRecords 待处理数据
 | 
				
			||||||
 | 
					     * @param entityName 单据标识
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private void operationalProcessing(List<DynamicObject> pendingRecords, String entityName) {
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            logger.info("开始处理" + entityName + "的" + pendingRecords.size() + "条记录");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            OperateOption option = OperateOption.create();
 | 
				
			||||||
 | 
					            DynamicObject[] recordsArray = pendingRecords.toArray(new DynamicObject[0]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 保存记录
 | 
				
			||||||
 | 
					            OperationResult saveResult = OperationServiceHelper.executeOperate("save", entityName, recordsArray, option);
 | 
				
			||||||
 | 
					            if (saveResult.isSuccess()) {
 | 
				
			||||||
 | 
					                logger.info("保存" + entityName + "记录成功,共" + pendingRecords.size() + "条");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // 提交记录
 | 
				
			||||||
 | 
					                OperationResult submitResult = OperationServiceHelper.executeOperate("submit", entityName, recordsArray, option);
 | 
				
			||||||
 | 
					                if (submitResult.isSuccess()) {
 | 
				
			||||||
 | 
					                    logger.info("提交" + entityName + "记录成功,共" + pendingRecords.size() + "条");
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    logger.error("提交" + entityName + "记录失败: " + submitResult.getMessage());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                logger.error("保存" + entityName + "记录失败: " + saveResult.getMessage());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            logger.error("处理" + entityName + "记录时发生异常", e);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue