瀏覽代碼

考务接口修改

wangliang 5 年之前
父節點
當前提交
ed71dbf648

+ 65 - 1
themis-backend/src/main/java/com/qmth/themis/backend/api/TEExamController.java

@@ -114,7 +114,7 @@ public class TEExamController {
     @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
     @Transactional
     public Result toggle(@ApiJsonObject(name = "toggle", value = {
-            @ApiJsonProperty(key = "id", type = "long", example = "1", description = "考试批次id"),
+            @ApiJsonProperty(key = "id", type = "long", example = "1", description = "考试批次ID"),
             @ApiJsonProperty(key = "enable", type = "int", example = "1", description = "是否启用")
     }) @ApiParam(value = "考试批次信息", required = true) @RequestBody Map<String, Object> mapParameter) {
         if (Objects.isNull(mapParameter.get("id")) || Objects.equals(mapParameter.get("id"), "")) {
@@ -136,4 +136,68 @@ public class TEExamController {
         teExamService.updateById(teExam);
         return ResultUtil.ok(JSONObject.parseObject(SystemConstant.SUCCESS));
     }
+
+    @ApiOperation(value = "考试批次详情接口")
+    @RequestMapping(value = "/detail", method = RequestMethod.GET)
+    @ApiResponses({@ApiResponse(code = 200, message = "考试批次信息", response = TEExam.class)})
+    public Result detail(@ApiParam(value = "考试批次id", required = true) @RequestParam Long id) {
+        TEExam teExam = teExamService.getById(id);
+        if (Objects.isNull(teExam)) {
+            throw new BusinessException(ExceptionResultEnum.EXAM_NO);
+        }
+        Map map = new HashMap<>();
+        map.put(SystemConstant.RECORDS, teExam);
+        return ResultUtil.ok(map);
+    }
+
+    @ApiOperation(value = "考试批次复制接口")
+    @RequestMapping(value = "/copy", method = RequestMethod.POST)
+    @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
+    @Transactional
+    public Result copy(@ApiJsonObject(name = "copy", value = {
+            @ApiJsonProperty(key = "sourceId", type = "long", example = "1", description = "来源批次ID"),
+            @ApiJsonProperty(key = "code", description = "代码"),
+            @ApiJsonProperty(key = "name", description = "名称")
+    }) @ApiParam(value = "考试批次信息", required = true) @RequestBody Map<String, Object> mapParameter) {
+        if (Objects.isNull(mapParameter.get("sourceId")) || Objects.equals(mapParameter.get("sourceId"), "")) {
+            throw new BusinessException(ExceptionResultEnum.EXAM_ID_IS_NULL);
+        }
+        Long examId = Long.parseLong(String.valueOf(mapParameter.get("sourceId")));
+        if (Objects.isNull(mapParameter.get("code")) || Objects.equals(mapParameter.get("code"), "")) {
+            throw new BusinessException(ExceptionResultEnum.EXAM_CODE_IS_NULL);
+        }
+        String code = String.valueOf(mapParameter.get("code"));
+        if (Objects.isNull(mapParameter.get("name")) || Objects.equals(mapParameter.get("name"), "")) {
+            throw new BusinessException(ExceptionResultEnum.EXAM_NAME_IS_NULL);
+        }
+        String name = String.valueOf(mapParameter.get("name"));
+        TEExam teExam = teExamService.getById(examId);
+        if (Objects.isNull(teExam)) {
+            throw new BusinessException(ExceptionResultEnum.EXAM_NO);
+        }
+        try {
+            teExam.setId(null);
+            teExam.setUpdateId(null);
+            teExam.setUpdateTime(null);
+            HttpServletRequest request = ServletUtil.getRequest();
+            TBUser tbUser = (TBUser) ServletUtil.getRequestAccount(request);
+            teExam.setCreateId(tbUser.getId());
+            teExam.setCode(code);
+            teExam.setName(name);
+            teExamService.save(teExam);
+        } 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[" + teExam.getOrgId() + "]下的" + FieldUniqueEnum.convertToCode(columnStr) + "数据不允许重复插入");
+            } else if (e instanceof BusinessException) {
+                throw new BusinessException(e.getMessage());
+            } else {
+                throw new RuntimeException(e);
+            }
+        }
+        //todo 还需增加场次设置
+        return ResultUtil.ok(JSONObject.parseObject(SystemConstant.SUCCESS));
+    }
 }

+ 1 - 1
themis-business/src/main/resources/mapper/TEExamActivityMapper.xml

@@ -32,7 +32,7 @@
           `create_id` bigint DEFAULT NULL COMMENT '创建人id',
           `update_id` bigint DEFAULT NULL COMMENT '更新人id',
           PRIMARY KEY (`id`),
-          UNIQUE KEY `${tableName}_orgId_code_Idx` (`org_id`,`code`)
+          UNIQUE KEY `${tableName}_examId_code_Idx` (`exam_id`,`code`)
         ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='考试场次'
     </update>
 

+ 4 - 0
themis-common/src/main/java/com/qmth/themis/common/enums/ExceptionResultEnum.java

@@ -62,6 +62,10 @@ public enum ExceptionResultEnum {
 
     ENABLE_IS_NULL("102", "禁用/启用状态不能为空"),
 
+    EXAM_CODE_IS_NULL("102", "考试批次编码不能为空"),
+
+    EXAM_NAME_IS_NULL("102", "考试批次名称不能为空"),
+
     ATTACHMENT_ID_IS_NULL("102", "附件id不能为空"),
 
     ATTACHMENT_NO("102", "附件不存在"),