试卷缓存优化

master
cheney 1 month ago
parent aef19dec3a
commit 9ef676da96
  1. 18
      exam/src/main/java/com/huoran/exam/controller/ExamPaperController.java
  2. 1
      exam/src/main/java/com/huoran/exam/service/ExamPaperService.java
  3. 7
      exam/src/main/java/com/huoran/exam/service/impl/ExamPaperServiceImpl.java
  4. 18
      financial_product/src/main/java/com/huoran/financial_product/service/impl/BankProductsServiceImpl.java
  5. 2
      nakadai/src/main/java/com/huoran/nakadai/controller/EncryptionController.java
  6. 5
      users/src/main/java/com/huoran/users/service/impl/HrUserInfoServiceImpl.java

@ -7,7 +7,6 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.huoran.api.OccupationlabClient;
import com.huoran.api.UserClient;
import com.huoran.common.aop.annotation.NoRepeatSubmit;
import com.huoran.common.entity.CopyExamPaperReq;
import com.huoran.common.entity.EvaluationAssignedQuestionsDetails;
@ -36,6 +35,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
@ -109,9 +109,6 @@ public class ExamPaperController {
@Autowired
private QuestionVersionsToKnowledgePointsService versionsToKnowledgePointsService;
@Autowired
private UserClient userClient;
@PostMapping("/examPaperList")
@ApiOperation(value = "试卷列表", response = ExamPaper.class)
public R examPaperList(@RequestBody @Valid ExamPaperReq req) {
@ -122,9 +119,7 @@ public class ExamPaperController {
@ApiOperation(value = "新增或更新试卷")
@Transactional
public R saveExamPaper(@RequestBody @Valid ExamPaper examPaper) {
/* if (examPaper.getPaperId() != null) {
removeExamPaperCache(examPaper.getPaperId());
}*/
examPaper.setSchoolId(TokenUtils.getSchoolId());
examPaper.setCreateUser(TokenUtils.getUserName());
boolean ok = examPaperService.checkRepeat(examPaper);
@ -167,6 +162,9 @@ public class ExamPaperController {
// examPaper.setMedianScore(median);
// examPaperService.updateById(examPaper);
// }
if (examPaper.getPaperId() != null) {
examPaperService.removeExamPaperCache(examPaper.getPaperId());
}
return saveOrUpdate ? R.ok() : R.error();
}
@ -191,16 +189,12 @@ public class ExamPaperController {
@GetMapping("/examPaperDetails")
@ApiOperation(value = "试卷详情")
//@Cacheable(value = {"examPaperDetails"}, key = "#id")
@Cacheable(value = {"examPaperDetails"}, key = "#id")
public R examPaperDetails(@RequestParam Integer id) {
ExamPaper examPaper = getExamPaper(id);
return R.ok().put("examPaper", examPaper);
}
/* @CacheEvict(value = "examPaperDetails", key = "#id")
public void removeExamPaperCache(Integer id) {}*/
/**
* 根据id获取试卷信息(含已经删除的)
*

@ -38,6 +38,7 @@ public interface ExamPaperService extends IService<ExamPaper> {
List<MockSubmissionReq> notTurnInAnExaminationPaper(Integer competitionId, Integer stageId);
Integer getPaperId(Integer reportId);
void removeExamPaperCache(Integer id);
List<Integer> selectAllReportIds(Integer stageId);

@ -32,6 +32,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xwpf.usermodel.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
@ -327,6 +328,12 @@ public class ExamPaperServiceImpl extends ServiceImpl<ExamPaperMapper, ExamPaper
return baseMapper.getPaperId(reportId);
}
@Override
@CacheEvict(value = "examPaperDetails", key = "#id")
public void removeExamPaperCache(Integer id) {
}
@Override
public List<Integer> selectAllReportIds(Integer stageId) {
return baseMapper.selectAllReportIds(stageId);

@ -630,24 +630,6 @@ public class BankProductsServiceImpl extends ServiceImpl<BankProductsMapper, Ban
// 保存失败 操作回滚
throw new CustomException(ExceptionEnum.ADD_USER_SCORE_FAIL);
}
// 创建一个 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);

@ -6,6 +6,7 @@ import com.huoran.common.utils.RSAUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.codec.binary.Base64;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -24,6 +25,7 @@ import java.security.interfaces.RSAPublicKey;
public class EncryptionController {
@ApiOperation(value = "数据加密", notes = "数据加密")
@GetMapping("/encrypt")
@Cacheable(value = {"encrypt"},key = "#root.methodName")
public EncryptionResponse encryptData() {
try {
String sendMesg = ConstantPropertiesUtil.ACCESS_KEY_ID+"/"+ConstantPropertiesUtil.ACCESS_KEY_SECRET;

@ -644,6 +644,9 @@ public class HrUserInfoServiceImpl extends ServiceImpl<HrUserInfoMapper, HrUserI
return workNumberLogin(loginVo);
}else {
if (loginVo.getAccount().length()==11 | RegularUtil.isValidPhoneNumber(loginVo.getAccount())) {
return phoneLogin(loginVo);
}
//账号登录
return accountLogin(loginVo);
}
@ -707,7 +710,7 @@ public class HrUserInfoServiceImpl extends ServiceImpl<HrUserInfoMapper, HrUserI
public LoginDTO phoneLogin(LoginVo loginVo) {
LoginDTO loginDTO = new LoginDTO();
List<HrUserAccount> hrUserAccounts = hrUserAccountMapper.selectAccountListByPhoneAndPassword(loginVo.getPlatform(),loginVo.getWorkNumber(),MD5.encrypt(loginVo.getPassword()));
List<HrUserAccount> hrUserAccounts = hrUserAccountMapper.selectAccountListByPhoneAndPassword(loginVo.getPlatform(),loginVo.getAccount(),MD5.encrypt(loginVo.getPassword()));
//学号/工号不存在
if (hrUserAccounts.isEmpty()) {
return workNumberLogin(loginVo);

Loading…
Cancel
Save