|
@@ -7,6 +7,7 @@ import com.qmth.themis.business.constant.SystemConstant;
|
|
import com.qmth.themis.business.dto.response.TBOrgDto;
|
|
import com.qmth.themis.business.dto.response.TBOrgDto;
|
|
import com.qmth.themis.business.entity.TBOrg;
|
|
import com.qmth.themis.business.entity.TBOrg;
|
|
import com.qmth.themis.business.entity.TBUser;
|
|
import com.qmth.themis.business.entity.TBUser;
|
|
|
|
+import com.qmth.themis.business.enums.FieldUniqueEnum;
|
|
import com.qmth.themis.business.service.TBOrgService;
|
|
import com.qmth.themis.business.service.TBOrgService;
|
|
import com.qmth.themis.business.util.RedisUtil;
|
|
import com.qmth.themis.business.util.RedisUtil;
|
|
import com.qmth.themis.business.util.ServletUtil;
|
|
import com.qmth.themis.business.util.ServletUtil;
|
|
@@ -16,6 +17,9 @@ import com.qmth.themis.common.exception.BusinessException;
|
|
import com.qmth.themis.common.util.Result;
|
|
import com.qmth.themis.common.util.Result;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
import com.qmth.themis.common.util.ResultUtil;
|
|
import io.swagger.annotations.*;
|
|
import io.swagger.annotations.*;
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
@@ -35,6 +39,7 @@ import java.util.Objects;
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/${prefix.url.admin}/org")
|
|
@RequestMapping("/${prefix.url.admin}/org")
|
|
public class TBOrgController {
|
|
public class TBOrgController {
|
|
|
|
+ private final static Logger log = LoggerFactory.getLogger(TBOrgController.class);
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
TBOrgService tbOrgService;
|
|
TBOrgService tbOrgService;
|
|
@@ -61,18 +66,31 @@ public class TBOrgController {
|
|
throw new BusinessException(ExceptionResultEnum.ORG_INFO_IS_NULL);
|
|
throw new BusinessException(ExceptionResultEnum.ORG_INFO_IS_NULL);
|
|
}
|
|
}
|
|
if (Objects.nonNull(tbOrg.getCode()) && Objects.equals(tbOrg.getCode().toUpperCase(), SystemConstant.ADMIN)) {
|
|
if (Objects.nonNull(tbOrg.getCode()) && Objects.equals(tbOrg.getCode().toUpperCase(), SystemConstant.ADMIN)) {
|
|
- throw new BusinessException("admin为超级管理员专属code,请重新输入");
|
|
|
|
|
|
+ throw new BusinessException("admin为超级管理员专属编码,请重新输入");
|
|
}
|
|
}
|
|
- TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
|
|
|
|
- if (Objects.isNull(tbOrg.getId())) {
|
|
|
|
- tbOrg.setId(Constants.idGen.next());
|
|
|
|
- tbOrg.setCreateId(tbUser.getId());
|
|
|
|
- } else {
|
|
|
|
- tbOrg.setUpdateId(tbUser.getId());
|
|
|
|
|
|
+ try {
|
|
|
|
+ TBUser tbUser = (TBUser) ServletUtil.getRequestAccount();
|
|
|
|
+ if (Objects.isNull(tbOrg.getId())) {
|
|
|
|
+ tbOrg.setId(Constants.idGen.next());
|
|
|
|
+ tbOrg.setCreateId(tbUser.getId());
|
|
|
|
+ } else {
|
|
|
|
+ tbOrg.setUpdateId(tbUser.getId());
|
|
|
|
+ }
|
|
|
|
+ tbOrgService.saveOrUpdate(tbOrg);
|
|
|
|
+ redisUtil.setOrg(tbOrg.getId(), tbOrg);
|
|
|
|
+ redisUtil.setOrgCode(tbOrg.getCode(), tbOrg);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("请求出错", e);
|
|
|
|
+ if (e instanceof DuplicateKeyException) {
|
|
|
|
+ String errorColumn = e.getCause().toString();
|
|
|
|
+ String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
|
|
|
|
+ throw new BusinessException(FieldUniqueEnum.convertToCode(columnStr) + "数据不允许重复插入");
|
|
|
|
+ } else if (e instanceof BusinessException) {
|
|
|
|
+ throw new BusinessException(e.getMessage());
|
|
|
|
+ } else {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- redisUtil.setOrg(tbOrg.getId(), tbOrg);
|
|
|
|
- redisUtil.setOrgCode(tbOrg.getCode(), tbOrg);
|
|
|
|
- tbOrgService.saveOrUpdate(tbOrg);
|
|
|
|
return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
|
|
return ResultUtil.ok(Collections.singletonMap(SystemConstant.SUCCESS, true));
|
|
}
|
|
}
|
|
|
|
|