|
|
|
@ -24,7 +24,6 @@ import com.huoran.financial_product.entity.vo.CacheVo; |
|
|
|
|
import com.huoran.financial_product.mapper.*; |
|
|
|
|
import com.huoran.financial_product.service.BankProductsService; |
|
|
|
|
import com.huoran.financial_product.util.ProductElementProcessingTools; |
|
|
|
|
import feign.FeignException; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
@ -516,95 +515,73 @@ public class BankProductsServiceImpl extends ServiceImpl<BankProductsMapper, Ban |
|
|
|
|
public R submit(SubmitDTO submitDTO) { |
|
|
|
|
Integer projectId = submitDTO.getProjectId(); |
|
|
|
|
Integer accountId = submitDTO.getAccountId(); |
|
|
|
|
List<ScoreInfo> scoreInfos = new ArrayList<>(); |
|
|
|
|
List<ScoreInfo> scoreInfos; |
|
|
|
|
HashMap<String, Object> retMap = new HashMap<>(); |
|
|
|
|
double scores = 0.0; |
|
|
|
|
// 获取项目下所有关卡的id
|
|
|
|
|
List<Integer> customsPassIds = mapper.getsTheLevelBoundToTheProject(projectId); |
|
|
|
|
List<Integer> levelIds = mapper.getsTheLevelBoundToTheProject(projectId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> userOperationRecordCache = new ArrayList<>(); |
|
|
|
|
// 获取所有关卡的用户操作记录缓存 key
|
|
|
|
|
for (Integer customsPassId : customsPassIds) { |
|
|
|
|
StringBuilder cacheKey = buildCacheKey(accountId, submitDTO.getSchoolId(), projectId, customsPassId, submitDTO.getAssessmentId(), submitDTO.getCompetitionId()); |
|
|
|
|
userOperationRecordCache.add(cacheKey.toString()); |
|
|
|
|
List<String> operationRecordCacheKeys = new ArrayList<>(); |
|
|
|
|
for (Integer levelId : levelIds) { |
|
|
|
|
StringBuilder cacheKey = buildCacheKey(accountId, submitDTO.getSchoolId(), projectId, levelId, submitDTO.getAssessmentId(), submitDTO.getCompetitionId()); |
|
|
|
|
operationRecordCacheKeys.add(cacheKey.toString()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取所有关卡操作记录
|
|
|
|
|
List<LcJudgmentRuleReq> ruleReqs = new ArrayList<>(); |
|
|
|
|
for (String cacheKey : userOperationRecordCache) { |
|
|
|
|
// 查看缓存
|
|
|
|
|
HashMap<String, List<LcJudgmentRuleReq>> listHashMap = (HashMap<String, List<LcJudgmentRuleReq>>) CacheUtil.get(cacheKey); |
|
|
|
|
if (listHashMap != null) { |
|
|
|
|
// 防止缓存返回null,避免空指针异常
|
|
|
|
|
for (Map.Entry<String, List<LcJudgmentRuleReq>> entry : listHashMap.entrySet()) { |
|
|
|
|
ruleReqs.addAll(entry.getValue()); |
|
|
|
|
List<LcJudgmentRuleReq> ruleRequests = new ArrayList<>(); |
|
|
|
|
for (String cacheKey : operationRecordCacheKeys) { |
|
|
|
|
HashMap<String, List<LcJudgmentRuleReq>> cachedListMap = (HashMap<String, List<LcJudgmentRuleReq>>) CacheUtil.get(cacheKey); |
|
|
|
|
if (cachedListMap != null) { |
|
|
|
|
for (Map.Entry<String, List<LcJudgmentRuleReq>> entry : cachedListMap.entrySet()) { |
|
|
|
|
if (entry.getValue() != null) { |
|
|
|
|
ruleRequests.addAll(entry.getValue()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CalculateScoreParameters calculateScoreParameters = new CalculateScoreParameters(); |
|
|
|
|
calculateScoreParameters.setOperationRules(ruleReqs); |
|
|
|
|
calculateScoreParameters.setOperationRules(ruleRequests); |
|
|
|
|
calculateScoreParameters.setProjectId(projectId); |
|
|
|
|
calculateScoreParameters.setLcIds(submitDTO.getLcId()); |
|
|
|
|
try { |
|
|
|
|
ScoreDetails scoreDetails = judgmentPointClient.scoreAndReturnScoreDetails(calculateScoreParameters); |
|
|
|
|
if (ObjectUtils.isEmpty(scoreDetails)|| scoreDetails.getScoreInfos().size()==0) { |
|
|
|
|
if (ObjectUtils.isEmpty(scoreDetails) || scoreDetails.getScoreInfos().isEmpty()) { |
|
|
|
|
throw new CustomException(ExceptionEnum.ADD_USER_SCORE_FAIL); |
|
|
|
|
} |
|
|
|
|
scoreInfos = scoreDetails.getScoreInfos(); |
|
|
|
|
scores = scoreDetails.getScores(); |
|
|
|
|
// 继续处理 scoreDetails
|
|
|
|
|
System.out.println("Score details: " + scoreDetails); |
|
|
|
|
} catch (FeignException e) { |
|
|
|
|
// 处理 Feign 异常
|
|
|
|
|
|
|
|
|
|
} catch (RuntimeException e) { |
|
|
|
|
throw new CustomException(ExceptionEnum.ADD_USER_SCORE_FAIL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (!ruleReqs.isEmpty()) {
|
|
|
|
|
//
|
|
|
|
|
// //判分点计算方法,并存储每个判分点分数以及计算总分
|
|
|
|
|
// for (Integer lcId : submitDTO.getLcId()) {
|
|
|
|
|
//
|
|
|
|
|
// //MD5生成标识 每个判分点不同
|
|
|
|
|
// String flag = MD5.encrypt(accountId + lcId + System.currentTimeMillis() + "");
|
|
|
|
|
//
|
|
|
|
|
// //判断单个判分点对错
|
|
|
|
|
// boolean calculate = judgmentPointClient.calculate(lcId, flag, ruleReqs);
|
|
|
|
|
//
|
|
|
|
|
// //获取项目管理判分点中间表的分数
|
|
|
|
|
// Double judgmentScore = occupationlabClient.getJudgmentScore(projectId, lcId);
|
|
|
|
|
// if (ObjectUtils.isEmpty(judgmentScore)) {
|
|
|
|
|
// throw new CustomException(ExceptionEnum.SELECT_JUDGMENT_SCORE_FAIL);
|
|
|
|
|
// }
|
|
|
|
|
// Double questionScore = 0.0;
|
|
|
|
|
// if (calculate) {
|
|
|
|
|
// questionScore = judgmentScore;
|
|
|
|
|
// }
|
|
|
|
|
// scoreInfos.add(new ScoreInfo(lcId, questionScore, calculate, judgmentScore, flag));
|
|
|
|
|
// if (calculate) {
|
|
|
|
|
// scores += judgmentScore;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// 保留一位小数并重新赋值给scores
|
|
|
|
|
scores = Math.round(scores * 10.0) / 10.0; |
|
|
|
|
double scores = scoreInfos.stream() |
|
|
|
|
.filter(ScoreInfo::getCalculate) |
|
|
|
|
.mapToDouble(ScoreInfo::getJudgmentScore) |
|
|
|
|
.sum(); |
|
|
|
|
|
|
|
|
|
long time = ((submitDTO.getSubmitTime().getTime() - submitDTO.getStartTime().getTime()) / 1000 / 60); |
|
|
|
|
//保存实验报告表
|
|
|
|
|
ExperimentalReport report = new ExperimentalReport(). |
|
|
|
|
setProjectId(projectId).setScore(scores).setAccountId(accountId). |
|
|
|
|
setCurriculumId(submitDTO.getCurriculumId()).setPurpose(submitDTO.getPurpose()). |
|
|
|
|
setProjectName(submitDTO.getProjectName()).setClassId(submitDTO.getClassId()). |
|
|
|
|
setStartTime(submitDTO.getStartTime()).setSubmitTime(submitDTO.getSubmitTime()). |
|
|
|
|
setEndTime(submitDTO.getEndTime()).setSchoolId(submitDTO.getSchoolId()). |
|
|
|
|
setData(submitDTO.getData()).setMallId(submitDTO.getMallId()); |
|
|
|
|
if (time == 0) { |
|
|
|
|
time = 1; |
|
|
|
|
time = 1; // 设置默认值为 1
|
|
|
|
|
} |
|
|
|
|
report.setTimeSum(Long.valueOf(time).intValue()); |
|
|
|
|
//保存实验报告表
|
|
|
|
|
ExperimentalReport report = new ExperimentalReport() |
|
|
|
|
.setProjectId(projectId) |
|
|
|
|
.setScore(scores) |
|
|
|
|
.setAccountId(accountId) |
|
|
|
|
.setCurriculumId(submitDTO.getCurriculumId()) |
|
|
|
|
.setPurpose(submitDTO.getPurpose()) |
|
|
|
|
.setProjectName(submitDTO.getProjectName()) |
|
|
|
|
.setClassId(submitDTO.getClassId()) |
|
|
|
|
.setStartTime(submitDTO.getStartTime()) |
|
|
|
|
.setSubmitTime(submitDTO.getSubmitTime()) |
|
|
|
|
.setEndTime(submitDTO.getEndTime()) |
|
|
|
|
.setSchoolId(submitDTO.getSchoolId()) |
|
|
|
|
.setData(submitDTO.getData()) |
|
|
|
|
.setMallId(submitDTO.getMallId()) |
|
|
|
|
.setTimeSum((int) time); // 直接设置 time 的值
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//考核id可为空 --为空为练习
|
|
|
|
|
if (!ObjectUtils.isEmpty(submitDTO.getAssessmentId())) { |
|
|
|
@ -623,10 +600,8 @@ public class BankProductsServiceImpl extends ServiceImpl<BankProductsMapper, Ban |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Integer reportId = occupationlabClient.addExperimentalReport(report); |
|
|
|
|
if (ObjectUtils.isEmpty(reportId) || reportId <= 0) { |
|
|
|
|
//保存失败 操作回滚
|
|
|
|
|
throw new CustomException(ExceptionEnum.ADD_EXPERIMENTAL_REPORT_FAIL); |
|
|
|
|
} |
|
|
|
|
System.out.println("reportId: " + reportId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<UserScore> userScores = new ArrayList<>(); |
|
|
|
|
for (ScoreInfo scoreInfo : scoreInfos) { |
|
|
|
@ -650,12 +625,29 @@ public class BankProductsServiceImpl extends ServiceImpl<BankProductsMapper, Ban |
|
|
|
|
} |
|
|
|
|
// 保存用户分数记录
|
|
|
|
|
boolean batchAddUserScore = occupationlabClient.batchAddUserScore(userScores); |
|
|
|
|
System.out.println("batchAddUserScore: " + batchAddUserScore); |
|
|
|
|
if (!batchAddUserScore) { |
|
|
|
|
// 保存失败 操作回滚
|
|
|
|
|
throw new CustomException(ExceptionEnum.ADD_USER_SCORE_FAIL); |
|
|
|
|
} |
|
|
|
|
//删除缓存
|
|
|
|
|
this.deleteCache(accountId.toString()); |
|
|
|
|
// 创建一个 CompletableFuture 用于保存实验报告
|
|
|
|
|
// CompletableFuture<Integer> saveReportFuture = CompletableFuture.supplyAsync(() -> {
|
|
|
|
|
//
|
|
|
|
|
// if (ObjectUtils.isEmpty(reportId) || reportId <= 0) {
|
|
|
|
|
// // 保存失败 操作回滚
|
|
|
|
|
// throw new CustomException(ExceptionEnum.ADD_EXPERIMENTAL_REPORT_FAIL);
|
|
|
|
|
// }
|
|
|
|
|
// return reportId;
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// 当保存实验报告完成后,异步保存用户分数记录
|
|
|
|
|
// List<ScoreInfo> finalScoreInfos = scoreInfos;
|
|
|
|
|
// CompletableFuture<Void> saveScoresFuture = saveReportFuture.thenAcceptAsync(reportId -> {
|
|
|
|
|
//
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
// 等待所有异步操作完成
|
|
|
|
|
// CompletableFuture.allOf(saveReportFuture, saveScoresFuture).join();
|
|
|
|
|
|
|
|
|
|
retMap.put("scoreInfo", scoreInfos); |
|
|
|
|
retMap.put("totalScore", scores); |
|
|
|
|