|
@@ -2,6 +2,7 @@ package com.qmth.teachcloud.common.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.teachcloud.common.bean.dto.OrgDto;
|
|
import com.qmth.teachcloud.common.bean.dto.OrgDto;
|
|
import com.qmth.teachcloud.common.bean.params.UserSaveParams;
|
|
import com.qmth.teachcloud.common.bean.params.UserSaveParams;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
@@ -9,13 +10,16 @@ import com.qmth.teachcloud.common.entity.SysOrg;
|
|
import com.qmth.teachcloud.common.entity.SysRole;
|
|
import com.qmth.teachcloud.common.entity.SysRole;
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
|
+import com.qmth.teachcloud.common.enums.FieldUniqueEnum;
|
|
import com.qmth.teachcloud.common.enums.RoleTypeEnum;
|
|
import com.qmth.teachcloud.common.enums.RoleTypeEnum;
|
|
import com.qmth.teachcloud.common.mapper.SysOrgMapper;
|
|
import com.qmth.teachcloud.common.mapper.SysOrgMapper;
|
|
import com.qmth.teachcloud.common.service.SysOrgService;
|
|
import com.qmth.teachcloud.common.service.SysOrgService;
|
|
import com.qmth.teachcloud.common.service.SysRoleService;
|
|
import com.qmth.teachcloud.common.service.SysRoleService;
|
|
import com.qmth.teachcloud.common.service.SysUserService;
|
|
import com.qmth.teachcloud.common.service.SysUserService;
|
|
|
|
+import com.qmth.teachcloud.common.util.ResultUtil;
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.dao.DuplicateKeyException;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -75,35 +79,40 @@ public class SysOrgServiceImpl extends ServiceImpl<SysOrgMapper, SysOrg> impleme
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public boolean saveOrg(SysOrg org) {
|
|
public boolean saveOrg(SysOrg org) {
|
|
- Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
|
|
- org.setSchoolId(schoolId);
|
|
|
|
- SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
-
|
|
|
|
- QueryWrapper<SysOrg> queryWrapper = new QueryWrapper<>();
|
|
|
|
- queryWrapper.lambda().eq(SysOrg::getSchoolId, org.getSchoolId()).eq(SysOrg::getParentId, org.getParentId()).eq(SysOrg::getCode, org.getCode());
|
|
|
|
- SysOrg sysOrg = this.getOne(queryWrapper);
|
|
|
|
-
|
|
|
|
- // 新增
|
|
|
|
- if (org.getId() == null) {
|
|
|
|
- if (sysOrg != null) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("机构代码已存在");
|
|
|
|
|
|
+ try {
|
|
|
|
+ Long schoolId = Long.valueOf(ServletUtil.getRequestHeaderSchoolId().toString());
|
|
|
|
+ org.setSchoolId(schoolId);
|
|
|
|
+ SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
|
+
|
|
|
|
+ QueryWrapper<SysOrg> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.lambda().eq(SysOrg::getSchoolId, org.getSchoolId()).eq(SysOrg::getParentId, org.getParentId()).eq(SysOrg::getCode, org.getCode());
|
|
|
|
+ SysOrg sysOrg = this.getOne(queryWrapper);
|
|
|
|
+
|
|
|
|
+ if (org.getId() == null) {// 新增
|
|
|
|
+ if (sysOrg != null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("机构代码已存在");
|
|
|
|
+ }
|
|
|
|
+ org.insertInfo(sysUser.getId());
|
|
|
|
+ return this.save(org);
|
|
|
|
+ } else { // 修改
|
|
|
|
+ if (sysOrg != null && org.getId().longValue() != sysOrg.getId().longValue()) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("机构代码已存在");
|
|
|
|
+ }
|
|
|
|
+ org.updateInfo(sysUser.getId());
|
|
|
|
+ return this.updateById(org);
|
|
}
|
|
}
|
|
- org.setId(SystemConstant.getDbUuid());
|
|
|
|
- org.setCreateId(sysUser.getId());
|
|
|
|
- org.setCreateTime(System.currentTimeMillis());
|
|
|
|
- org.setCreateTime(System.currentTimeMillis());
|
|
|
|
- return this.save(org);
|
|
|
|
- }
|
|
|
|
- // 修改
|
|
|
|
- else {
|
|
|
|
- if (sysOrg != null && org.getId().longValue() != sysOrg.getId().longValue()) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("机构代码已存在");
|
|
|
|
|
|
+ } catch (Exception 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, e.getMessage());
|
|
|
|
+ } else {
|
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
}
|
|
}
|
|
- org.setUpdateId(sysUser.getId());
|
|
|
|
- org.setUpdateTime(System.currentTimeMillis());
|
|
|
|
- return this.updateById(org);
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|