|
@@ -2,13 +2,18 @@ package com.qmth.themis.backend.api;
|
|
|
|
|
|
import com.qmth.themis.backend.util.ServletUtil;
|
|
|
import com.qmth.themis.business.constant.SystemConstant;
|
|
|
+import com.qmth.themis.business.entity.TBOrg;
|
|
|
import com.qmth.themis.business.entity.TBUser;
|
|
|
import com.qmth.themis.business.entity.TEExam;
|
|
|
+import com.qmth.themis.business.enums.FieldUniqueEnum;
|
|
|
import com.qmth.themis.business.service.TEExamService;
|
|
|
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.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
@@ -38,11 +43,31 @@ public class TEExamController {
|
|
|
@RequestMapping(value = "/save", method = RequestMethod.POST)
|
|
|
@ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
|
|
|
public Result save(@ApiParam(value = "考试批次信息", required = true) @RequestBody TEExam teExam, HttpServletRequest request) throws NoSuchAlgorithmException {
|
|
|
- TBUser tbUser = (TBUser) ServletUtil.getRequestAccount(request);
|
|
|
- if (Objects.nonNull(teExam.getId())) {
|
|
|
- teExam.setUpdateId(tbUser.getId());
|
|
|
+ try {
|
|
|
+ TBUser tbUser = (TBUser) ServletUtil.getRequestAccount(request);
|
|
|
+ TBOrg tbOrg = (TBOrg) ServletUtil.getRequestOrg(request);
|
|
|
+ if (Objects.nonNull(tbOrg)) {
|
|
|
+ teExam.setOrgId(tbOrg.getId());
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(teExam.getId())) {
|
|
|
+ teExam.setUpdateId(tbUser.getId());
|
|
|
+ } else {
|
|
|
+ teExam.setId(Constants.idGen.next());
|
|
|
+ teExam.setCreateId(tbUser.getId());
|
|
|
+ }
|
|
|
+ teExamService.saveOrUpdate(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);
|
|
|
+ }
|
|
|
}
|
|
|
- teExamService.saveOrUpdate(teExam);
|
|
|
return ResultUtil.ok(JacksonUtil.parseJson(SystemConstant.SUCCESS));
|
|
|
}
|
|
|
}
|