|
@@ -1,90 +1,90 @@
|
|
|
-package com.qmth.themis.admin.api;
|
|
|
-
|
|
|
-import com.qmth.themis.business.bean.admin.ProblemBean;
|
|
|
-import com.qmth.themis.business.constant.SystemConstant;
|
|
|
-import com.qmth.themis.business.entity.TBProblem;
|
|
|
-import com.qmth.themis.business.entity.TBUser;
|
|
|
-import com.qmth.themis.business.service.TBProblemService;
|
|
|
-import com.qmth.themis.business.service.ThemisCacheService;
|
|
|
-import com.qmth.themis.business.util.RedisUtil;
|
|
|
-import com.qmth.themis.business.util.ServletUtil;
|
|
|
-import com.qmth.themis.common.exception.BusinessException;
|
|
|
-import com.qmth.themis.common.util.Result;
|
|
|
-import com.qmth.themis.common.util.ResultUtil;
|
|
|
-import io.swagger.annotations.*;
|
|
|
-import org.slf4j.Logger;
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
-import org.springframework.validation.BindingResult;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * @Description: 考试问题 前端控制器
|
|
|
- * @Param:
|
|
|
- * @return:
|
|
|
- * @Author: wangliang
|
|
|
- * @Date: 2023/3/14
|
|
|
- */
|
|
|
-@Api(tags = "考试问题 Controller")
|
|
|
-@RestController
|
|
|
-@RequestMapping(SystemConstant.PREFIX_URL_ADMIN + "/problem")
|
|
|
-@Validated
|
|
|
-public class TBProblemController {
|
|
|
- private final static Logger log = LoggerFactory.getLogger(TBProblemController.class);
|
|
|
-
|
|
|
- @Resource
|
|
|
- TBProblemService tbProblemService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- ThemisCacheService themisCacheService;
|
|
|
-
|
|
|
- @Resource
|
|
|
- RedisUtil redisUtil;
|
|
|
-
|
|
|
- @ApiOperation(value = "问题查询接口")
|
|
|
- @RequestMapping(value = "/list", method = RequestMethod.POST)
|
|
|
- @ApiResponses({@ApiResponse(code = 200, message = "问题信息", response = TBProblem.class)})
|
|
|
- public Result list() {
|
|
|
- return ResultUtil.ok(themisCacheService.problemCache());
|
|
|
- }
|
|
|
-
|
|
|
- @ApiOperation(value = "问题保存接口")
|
|
|
- @RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
|
- @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = Result.class)})
|
|
|
- @Transactional
|
|
|
- public Result save(@Validated @ApiParam(value = "问题信息", required = true) @RequestBody ProblemBean problemBean, BindingResult bindingResult) {
|
|
|
- if (bindingResult.hasErrors()) {
|
|
|
- return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
|
|
|
- }
|
|
|
- List<TBProblem> tbProblemList = themisCacheService.problemCache();
|
|
|
- if (!CollectionUtils.isEmpty(tbProblemList)) {
|
|
|
- TBProblem tbProblem = tbProblemList.stream().filter(e -> e.getId().longValue() == problemBean.getId().longValue()).collect(Collectors.toList()).get(0);
|
|
|
- Optional.ofNullable(tbProblem).orElseThrow(() -> new BusinessException("问题信息不存在"));
|
|
|
- if (redisUtil.lock(SystemConstant.REDIS_LOCK_PROBLEM_PREFIX + tbProblem.getId() + "_" + problemBean.getSolve(), SystemConstant.REDIS_LOCK_PROBLEM_TIME_OUT)) {
|
|
|
- try {
|
|
|
- if (problemBean.getSolve()) {
|
|
|
- tbProblem.setSolveCount(tbProblem.getSolveCount() + 1);
|
|
|
- } else {
|
|
|
- tbProblem.setUnSolveCount(tbProblem.getUnSolveCount() + 1);
|
|
|
- }
|
|
|
- tbProblem.setUpdateTime(System.currentTimeMillis());
|
|
|
- tbProblemService.updateById(tbProblem);
|
|
|
- themisCacheService.updateProblemCache();
|
|
|
- } finally {
|
|
|
- redisUtil.releaseLock(SystemConstant.REDIS_LOCK_PROBLEM_PREFIX + tbProblem.getId() + "_" + problemBean.getSolve());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return ResultUtil.ok(true);
|
|
|
- }
|
|
|
-}
|
|
|
+//package com.qmth.themis.admin.api;
|
|
|
+//
|
|
|
+//import com.qmth.themis.business.bean.admin.ProblemBean;
|
|
|
+//import com.qmth.themis.business.constant.SystemConstant;
|
|
|
+//import com.qmth.themis.business.entity.TBProblem;
|
|
|
+//import com.qmth.themis.business.entity.TBUser;
|
|
|
+//import com.qmth.themis.business.service.TBProblemService;
|
|
|
+//import com.qmth.themis.business.service.ThemisCacheService;
|
|
|
+//import com.qmth.themis.business.util.RedisUtil;
|
|
|
+//import com.qmth.themis.business.util.ServletUtil;
|
|
|
+//import com.qmth.themis.common.exception.BusinessException;
|
|
|
+//import com.qmth.themis.common.util.Result;
|
|
|
+//import com.qmth.themis.common.util.ResultUtil;
|
|
|
+//import io.swagger.annotations.*;
|
|
|
+//import org.slf4j.Logger;
|
|
|
+//import org.slf4j.LoggerFactory;
|
|
|
+//import org.springframework.transaction.annotation.Transactional;
|
|
|
+//import org.springframework.util.CollectionUtils;
|
|
|
+//import org.springframework.validation.BindingResult;
|
|
|
+//import org.springframework.validation.annotation.Validated;
|
|
|
+//import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+//import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+//import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+//import org.springframework.web.bind.annotation.RestController;
|
|
|
+//
|
|
|
+//import javax.annotation.Resource;
|
|
|
+//import java.util.List;
|
|
|
+//import java.util.Optional;
|
|
|
+//import java.util.stream.Collectors;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * @Description: 考试问题 前端控制器
|
|
|
+// * @Param:
|
|
|
+// * @return:
|
|
|
+// * @Author: wangliang
|
|
|
+// * @Date: 2023/3/14
|
|
|
+// */
|
|
|
+//@Api(tags = "考试问题 Controller")
|
|
|
+//@RestController
|
|
|
+//@RequestMapping(SystemConstant.PREFIX_URL_ADMIN + "/problem")
|
|
|
+//@Validated
|
|
|
+//public class TBProblemController {
|
|
|
+// private final static Logger log = LoggerFactory.getLogger(TBProblemController.class);
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// TBProblemService tbProblemService;
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// ThemisCacheService themisCacheService;
|
|
|
+//
|
|
|
+// @Resource
|
|
|
+// RedisUtil redisUtil;
|
|
|
+//
|
|
|
+// @ApiOperation(value = "问题查询接口")
|
|
|
+// @RequestMapping(value = "/list", method = RequestMethod.POST)
|
|
|
+// @ApiResponses({@ApiResponse(code = 200, message = "问题信息", response = TBProblem.class)})
|
|
|
+// public Result list() {
|
|
|
+// return ResultUtil.ok(themisCacheService.problemCache());
|
|
|
+// }
|
|
|
+//
|
|
|
+// @ApiOperation(value = "问题保存接口")
|
|
|
+// @RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
|
+// @ApiResponses({@ApiResponse(code = 200, message = "常规信息", response = Result.class)})
|
|
|
+// @Transactional
|
|
|
+// public Result save(@Validated @ApiParam(value = "问题信息", required = true) @RequestBody ProblemBean problemBean, BindingResult bindingResult) {
|
|
|
+// if (bindingResult.hasErrors()) {
|
|
|
+// return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
|
|
|
+// }
|
|
|
+// List<TBProblem> tbProblemList = themisCacheService.problemCache();
|
|
|
+// if (!CollectionUtils.isEmpty(tbProblemList)) {
|
|
|
+// TBProblem tbProblem = tbProblemList.stream().filter(e -> e.getId().longValue() == problemBean.getId().longValue()).collect(Collectors.toList()).get(0);
|
|
|
+// Optional.ofNullable(tbProblem).orElseThrow(() -> new BusinessException("问题信息不存在"));
|
|
|
+// if (redisUtil.lock(SystemConstant.REDIS_LOCK_PROBLEM_PREFIX + tbProblem.getId() + "_" + problemBean.getSolve(), SystemConstant.REDIS_LOCK_PROBLEM_TIME_OUT)) {
|
|
|
+// try {
|
|
|
+// if (problemBean.getSolve()) {
|
|
|
+// tbProblem.setSolveCount(tbProblem.getSolveCount() + 1);
|
|
|
+// } else {
|
|
|
+// tbProblem.setUnSolveCount(tbProblem.getUnSolveCount() + 1);
|
|
|
+// }
|
|
|
+// tbProblem.setUpdateTime(System.currentTimeMillis());
|
|
|
+// tbProblemService.updateById(tbProblem);
|
|
|
+// themisCacheService.updateProblemCache();
|
|
|
+// } finally {
|
|
|
+// redisUtil.releaseLock(SystemConstant.REDIS_LOCK_PROBLEM_PREFIX + tbProblem.getId() + "_" + problemBean.getSolve());
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return ResultUtil.ok(true);
|
|
|
+// }
|
|
|
+//}
|