|
@@ -3,17 +3,21 @@ package com.qmth.distributed.print.api;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.qmth.boot.api.constant.ApiConstant;
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.distributed.print.business.bean.result.EditResult;
|
|
|
import com.qmth.distributed.print.business.entity.TBVersion;
|
|
|
import com.qmth.distributed.print.business.service.TBVersionService;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
+import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
+import com.qmth.teachcloud.common.enums.FieldUniqueEnum;
|
|
|
import com.qmth.teachcloud.common.util.Result;
|
|
|
import com.qmth.teachcloud.common.util.ResultUtil;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
import io.swagger.annotations.*;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
@@ -55,15 +59,29 @@ public class TBVersionController {
|
|
|
if (bindingResult.hasErrors()) {
|
|
|
return ResultUtil.error(bindingResult.getAllErrors().get(0).getDefaultMessage());
|
|
|
}
|
|
|
- SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
- if (Objects.isNull(tbVersion.getId())) {
|
|
|
- tbVersion.insertInfo(sysUser.getId());
|
|
|
- } else {
|
|
|
- TBVersion tbVersionDb = tbVersionService.getById(tbVersion.getId());
|
|
|
- Objects.requireNonNull(tbVersionDb, "未找到版本信息");
|
|
|
- tbVersion.updateInfo(sysUser.getId());
|
|
|
+ try {
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
+ if (Objects.isNull(tbVersion.getId())) {
|
|
|
+ tbVersion.insertInfo(sysUser.getId());
|
|
|
+ } else {
|
|
|
+ TBVersion tbVersionDb = tbVersionService.getById(tbVersion.getId());
|
|
|
+ Objects.requireNonNull(tbVersionDb, "未找到版本信息");
|
|
|
+ tbVersion.updateInfo(sysUser.getId());
|
|
|
+ }
|
|
|
+ tbVersionService.saveOrUpdate(tbVersion);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ if (e instanceof DuplicateKeyException) {
|
|
|
+ String errorColumn = e.getCause().toString();
|
|
|
+ String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
|
|
|
+ throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
|
|
|
+ } else if (e instanceof ApiException) {
|
|
|
+ ResultUtil.error((ApiException) e, ((ApiException) e).getCode(), e.getMessage());
|
|
|
+ } else {
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
- return ResultUtil.ok(tbVersionService.saveOrUpdate(tbVersion));
|
|
|
+ return ResultUtil.ok(true);
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "版本管理编辑")
|