|
|
@ -24,7 +24,6 @@ import com.huoran.financial_product.entity.vo.CacheVo; |
|
|
|
import com.huoran.financial_product.mapper.*; |
|
|
|
import com.huoran.financial_product.mapper.*; |
|
|
|
import com.huoran.financial_product.service.BankProductsService; |
|
|
|
import com.huoran.financial_product.service.BankProductsService; |
|
|
|
import com.huoran.financial_product.util.ProductElementProcessingTools; |
|
|
|
import com.huoran.financial_product.util.ProductElementProcessingTools; |
|
|
|
import feign.FeignException; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
@ -516,95 +515,73 @@ public class BankProductsServiceImpl extends ServiceImpl<BankProductsMapper, Ban |
|
|
|
public R submit(SubmitDTO submitDTO) { |
|
|
|
public R submit(SubmitDTO submitDTO) { |
|
|
|
Integer projectId = submitDTO.getProjectId(); |
|
|
|
Integer projectId = submitDTO.getProjectId(); |
|
|
|
Integer accountId = submitDTO.getAccountId(); |
|
|
|
Integer accountId = submitDTO.getAccountId(); |
|
|
|
List<ScoreInfo> scoreInfos = new ArrayList<>(); |
|
|
|
List<ScoreInfo> scoreInfos; |
|
|
|
HashMap<String, Object> retMap = new HashMap<>(); |
|
|
|
HashMap<String, Object> retMap = new HashMap<>(); |
|
|
|
double scores = 0.0; |
|
|
|
|
|
|
|
// 获取项目下所有关卡的id
|
|
|
|
// 获取项目下所有关卡的id
|
|
|
|
List<Integer> customsPassIds = mapper.getsTheLevelBoundToTheProject(projectId); |
|
|
|
List<Integer> levelIds = mapper.getsTheLevelBoundToTheProject(projectId); |
|
|
|
|
|
|
|
|
|
|
|
List<String> userOperationRecordCache = new ArrayList<>(); |
|
|
|
|
|
|
|
// 获取所有关卡的用户操作记录缓存key
|
|
|
|
// 获取所有关卡的用户操作记录缓存 key
|
|
|
|
for (Integer customsPassId : customsPassIds) { |
|
|
|
List<String> operationRecordCacheKeys = new ArrayList<>(); |
|
|
|
StringBuilder cacheKey = buildCacheKey(accountId, submitDTO.getSchoolId(), projectId, customsPassId, submitDTO.getAssessmentId(), submitDTO.getCompetitionId()); |
|
|
|
for (Integer levelId : levelIds) { |
|
|
|
userOperationRecordCache.add(cacheKey.toString()); |
|
|
|
StringBuilder cacheKey = buildCacheKey(accountId, submitDTO.getSchoolId(), projectId, levelId, submitDTO.getAssessmentId(), submitDTO.getCompetitionId()); |
|
|
|
|
|
|
|
operationRecordCacheKeys.add(cacheKey.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//获取所有关卡操作记录
|
|
|
|
// 获取所有关卡操作记录
|
|
|
|
List<LcJudgmentRuleReq> ruleReqs = new ArrayList<>(); |
|
|
|
List<LcJudgmentRuleReq> ruleRequests = new ArrayList<>(); |
|
|
|
for (String cacheKey : userOperationRecordCache) { |
|
|
|
for (String cacheKey : operationRecordCacheKeys) { |
|
|
|
// 查看缓存
|
|
|
|
HashMap<String, List<LcJudgmentRuleReq>> cachedListMap = (HashMap<String, List<LcJudgmentRuleReq>>) CacheUtil.get(cacheKey); |
|
|
|
HashMap<String, List<LcJudgmentRuleReq>> listHashMap = (HashMap<String, List<LcJudgmentRuleReq>>) CacheUtil.get(cacheKey); |
|
|
|
if (cachedListMap != null) { |
|
|
|
if (listHashMap != null) { |
|
|
|
for (Map.Entry<String, List<LcJudgmentRuleReq>> entry : cachedListMap.entrySet()) { |
|
|
|
// 防止缓存返回null,避免空指针异常
|
|
|
|
if (entry.getValue() != null) { |
|
|
|
for (Map.Entry<String, List<LcJudgmentRuleReq>> entry : listHashMap.entrySet()) { |
|
|
|
ruleRequests.addAll(entry.getValue()); |
|
|
|
ruleReqs.addAll(entry.getValue()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CalculateScoreParameters calculateScoreParameters = new CalculateScoreParameters(); |
|
|
|
CalculateScoreParameters calculateScoreParameters = new CalculateScoreParameters(); |
|
|
|
calculateScoreParameters.setOperationRules(ruleReqs); |
|
|
|
calculateScoreParameters.setOperationRules(ruleRequests); |
|
|
|
calculateScoreParameters.setProjectId(projectId); |
|
|
|
calculateScoreParameters.setProjectId(projectId); |
|
|
|
calculateScoreParameters.setLcIds(submitDTO.getLcId()); |
|
|
|
calculateScoreParameters.setLcIds(submitDTO.getLcId()); |
|
|
|
try { |
|
|
|
try { |
|
|
|
ScoreDetails scoreDetails = judgmentPointClient.scoreAndReturnScoreDetails(calculateScoreParameters); |
|
|
|
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); |
|
|
|
throw new CustomException(ExceptionEnum.ADD_USER_SCORE_FAIL); |
|
|
|
} |
|
|
|
} |
|
|
|
scoreInfos = scoreDetails.getScoreInfos(); |
|
|
|
scoreInfos = scoreDetails.getScoreInfos(); |
|
|
|
scores = scoreDetails.getScores(); |
|
|
|
|
|
|
|
// 继续处理 scoreDetails
|
|
|
|
} catch (RuntimeException e) { |
|
|
|
System.out.println("Score details: " + scoreDetails); |
|
|
|
|
|
|
|
} catch (FeignException e) { |
|
|
|
|
|
|
|
// 处理 Feign 异常
|
|
|
|
|
|
|
|
throw new CustomException(ExceptionEnum.ADD_USER_SCORE_FAIL); |
|
|
|
throw new CustomException(ExceptionEnum.ADD_USER_SCORE_FAIL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
double scores = scoreInfos.stream() |
|
|
|
|
|
|
|
.filter(ScoreInfo::getCalculate) |
|
|
|
|
|
|
|
.mapToDouble(ScoreInfo::getJudgmentScore) |
|
|
|
// if (!ruleReqs.isEmpty()) {
|
|
|
|
.sum(); |
|
|
|
//
|
|
|
|
|
|
|
|
// //判分点计算方法,并存储每个判分点分数以及计算总分
|
|
|
|
|
|
|
|
// 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; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
long time = ((submitDTO.getSubmitTime().getTime() - submitDTO.getStartTime().getTime()) / 1000 / 60); |
|
|
|
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) { |
|
|
|
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可为空 --为空为练习
|
|
|
|
//考核id可为空 --为空为练习
|
|
|
|
if (!ObjectUtils.isEmpty(submitDTO.getAssessmentId())) { |
|
|
|
if (!ObjectUtils.isEmpty(submitDTO.getAssessmentId())) { |
|
|
@ -623,10 +600,8 @@ public class BankProductsServiceImpl extends ServiceImpl<BankProductsMapper, Ban |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Integer reportId = occupationlabClient.addExperimentalReport(report); |
|
|
|
Integer reportId = occupationlabClient.addExperimentalReport(report); |
|
|
|
if (ObjectUtils.isEmpty(reportId) || reportId <= 0) { |
|
|
|
System.out.println("reportId: " + reportId); |
|
|
|
//保存失败 操作回滚
|
|
|
|
|
|
|
|
throw new CustomException(ExceptionEnum.ADD_EXPERIMENTAL_REPORT_FAIL); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<UserScore> userScores = new ArrayList<>(); |
|
|
|
List<UserScore> userScores = new ArrayList<>(); |
|
|
|
for (ScoreInfo scoreInfo : scoreInfos) { |
|
|
|
for (ScoreInfo scoreInfo : scoreInfos) { |
|
|
@ -641,21 +616,38 @@ public class BankProductsServiceImpl extends ServiceImpl<BankProductsMapper, Ban |
|
|
|
userScore.setTimeSum(submitDTO.getTimeSum()); |
|
|
|
userScore.setTimeSum(submitDTO.getTimeSum()); |
|
|
|
userScore.setSubmitTime(submitDTO.getSubmitTime()); |
|
|
|
userScore.setSubmitTime(submitDTO.getSubmitTime()); |
|
|
|
userScore.setTeamId(submitDTO.getTeamId()); |
|
|
|
userScore.setTeamId(submitDTO.getTeamId()); |
|
|
|
//判分正确 错误默认值为0
|
|
|
|
// 判分正确 错误默认值为 0
|
|
|
|
if (scoreInfo.getCalculate()) { |
|
|
|
if (scoreInfo.getCalculate()) { |
|
|
|
userScore.setScore(scoreInfo.getJudgmentScore()); |
|
|
|
userScore.setScore(scoreInfo.getJudgmentScore()); |
|
|
|
userScore.setIsCorrect(1); |
|
|
|
userScore.setIsCorrect(1); |
|
|
|
} |
|
|
|
} |
|
|
|
userScores.add(userScore); |
|
|
|
userScores.add(userScore); |
|
|
|
} |
|
|
|
} |
|
|
|
//保存用户分数记录
|
|
|
|
// 保存用户分数记录
|
|
|
|
boolean batchAddUserScore = occupationlabClient.batchAddUserScore(userScores); |
|
|
|
boolean batchAddUserScore = occupationlabClient.batchAddUserScore(userScores); |
|
|
|
|
|
|
|
System.out.println("batchAddUserScore: " + batchAddUserScore); |
|
|
|
if (!batchAddUserScore) { |
|
|
|
if (!batchAddUserScore) { |
|
|
|
//保存失败 操作回滚
|
|
|
|
// 保存失败 操作回滚
|
|
|
|
throw new CustomException(ExceptionEnum.ADD_USER_SCORE_FAIL); |
|
|
|
throw new CustomException(ExceptionEnum.ADD_USER_SCORE_FAIL); |
|
|
|
} |
|
|
|
} |
|
|
|
//删除缓存
|
|
|
|
// 创建一个 CompletableFuture 用于保存实验报告
|
|
|
|
this.deleteCache(accountId.toString()); |
|
|
|
// 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("scoreInfo", scoreInfos); |
|
|
|
retMap.put("totalScore", scores); |
|
|
|
retMap.put("totalScore", scores); |
|
|
|