|
@@ -1,8 +1,29 @@
|
|
|
package com.qmth.themis.backend.api;
|
|
|
|
|
|
-import io.swagger.annotations.Api;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.qmth.themis.backend.util.ServletUtil;
|
|
|
+import com.qmth.themis.business.constant.SystemConstant;
|
|
|
+import com.qmth.themis.business.entity.TBUser;
|
|
|
+import com.qmth.themis.business.entity.TEExamPaper;
|
|
|
+import com.qmth.themis.business.enums.FieldUniqueEnum;
|
|
|
+import com.qmth.themis.business.service.TEExamPaperService;
|
|
|
+import com.qmth.themis.business.util.JacksonUtil;
|
|
|
+import com.qmth.themis.common.contanst.Constants;
|
|
|
+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.springframework.dao.DuplicateKeyException;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* @Description: 考试试卷 前端控制器
|
|
@@ -13,7 +34,58 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
*/
|
|
|
@Api(tags = "考试试卷Controller")
|
|
|
@RestController
|
|
|
-@RequestMapping("/${prefix.url.admin}/examPaper")
|
|
|
+@RequestMapping("/${prefix.url.admin}/paper")
|
|
|
public class TEExamPaperController {
|
|
|
|
|
|
+ @Resource
|
|
|
+ TEExamPaperService teExamPaperService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "考试试卷查询接口")
|
|
|
+ @RequestMapping(value = "/query", method = RequestMethod.GET)
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "考试科目信息", response = TEExamPaper.class)})
|
|
|
+ public Result query(@ApiParam(value = "考试批次id", required = true) @RequestParam Long examId, @ApiParam(value = "科目编码", required = true) @RequestParam String courseCode) {
|
|
|
+ QueryWrapper<TEExamPaper> teExamPaperQueryWrapper = new QueryWrapper<>();
|
|
|
+ teExamPaperQueryWrapper.lambda().eq(TEExamPaper::getExamId, examId).eq(TEExamPaper::getCourseCode, courseCode);
|
|
|
+ List<TEExamPaper> teExamPaperList = teExamPaperService.list(teExamPaperQueryWrapper);
|
|
|
+ Map map = new HashMap<>();
|
|
|
+ map.put(SystemConstant.RECORDS, teExamPaperList);
|
|
|
+ return ResultUtil.ok(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "考试试卷参数修改接口")
|
|
|
+ @RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
|
|
|
+ public Result save(@ApiParam(value = "考试试卷信息", required = true) @RequestBody List<TEExamPaper> teExamPaperList) {
|
|
|
+ try {
|
|
|
+ HttpServletRequest request = ServletUtil.getRequest();
|
|
|
+ TBUser tbUser = (TBUser) ServletUtil.getRequestAccount(request);
|
|
|
+ teExamPaperList.forEach(s -> {
|
|
|
+ if (Objects.nonNull(s.getId())) {
|
|
|
+ s.setUpdateId(tbUser.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ teExamPaperService.updateBatchById(teExamPaperList);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ if (e instanceof DuplicateKeyException) {
|
|
|
+ String errorColumn = e.getCause().toString();
|
|
|
+ String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
|
|
|
+ throw new BusinessException("机构id[" + teExamPaperList.get(0).getExamId() + "]下的" + FieldUniqueEnum.convertToCode(columnStr) + "数据不允许重复插入");
|
|
|
+ } else if (e instanceof BusinessException) {
|
|
|
+ throw new BusinessException(e.getMessage());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "考试试卷数据包上传接口")
|
|
|
+ @RequestMapping(value = "/import", method = RequestMethod.POST)
|
|
|
+ @Transactional
|
|
|
+ @ApiResponses({@ApiResponse(code = 200, message = "{\"taskId\":0", response = Result.class)})
|
|
|
+ public Result importData(@ApiParam(value = "上传文件", required = true) @RequestParam MultipartFile file) {
|
|
|
+ return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
+ }
|
|
|
}
|