|
@@ -5,6 +5,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
|
import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission;
|
|
|
|
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
|
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
|
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO;
|
|
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
|
|
import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO;
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
@@ -49,6 +50,9 @@ public class DeptServiceImpl implements DeptService {
|
|
// 校验部门名的唯一性
|
|
// 校验部门名的唯一性
|
|
validateDeptNameUnique(null, createReqVO.getParentId(), createReqVO.getName());
|
|
validateDeptNameUnique(null, createReqVO.getParentId(), createReqVO.getName());
|
|
|
|
|
|
|
|
+ // 校验联系电话和邮箱
|
|
|
|
+ validateDeptEmailExists(createReqVO.getEmail());
|
|
|
|
+ validateDeptPhoneExists(createReqVO.getPhone());
|
|
// 插入部门
|
|
// 插入部门
|
|
DeptDO dept = BeanUtils.toBean(createReqVO, DeptDO.class);
|
|
DeptDO dept = BeanUtils.toBean(createReqVO, DeptDO.class);
|
|
deptMapper.insert(dept);
|
|
deptMapper.insert(dept);
|
|
@@ -64,11 +68,26 @@ public class DeptServiceImpl implements DeptService {
|
|
}
|
|
}
|
|
// 校验自己存在
|
|
// 校验自己存在
|
|
validateDeptExists(updateReqVO.getId());
|
|
validateDeptExists(updateReqVO.getId());
|
|
|
|
+
|
|
|
|
+ if (updateReqVO.getId() == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ DeptDO dept = deptMapper.selectById(updateReqVO.getId());
|
|
|
|
+ if (dept == null) {
|
|
|
|
+ throw exception(DEPT_NOT_FOUND);
|
|
|
|
+ }
|
|
|
|
+
|
|
// 校验父部门的有效性
|
|
// 校验父部门的有效性
|
|
// validateParentDept(updateReqVO.getId(), updateReqVO.getParentId());
|
|
// validateParentDept(updateReqVO.getId(), updateReqVO.getParentId());
|
|
// 校验部门名的唯一性
|
|
// 校验部门名的唯一性
|
|
// validateDeptNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName());
|
|
// validateDeptNameUnique(updateReqVO.getId(), updateReqVO.getParentId(), updateReqVO.getName());
|
|
-
|
|
|
|
|
|
+ // 校验联系电话和邮箱
|
|
|
|
+ if(!dept.getEmail().equals(updateReqVO.getEmail())){
|
|
|
|
+ validateDeptEmailExists(updateReqVO.getEmail());
|
|
|
|
+ }
|
|
|
|
+ if(!dept.getPhone().equals(updateReqVO.getPhone())){
|
|
|
|
+ validateDeptPhoneExists(updateReqVO.getPhone());
|
|
|
|
+ }
|
|
// 更新部门
|
|
// 更新部门
|
|
DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
|
|
DeptDO updateObj = BeanUtils.toBean(updateReqVO, DeptDO.class);
|
|
deptMapper.updateById(updateObj);
|
|
deptMapper.updateById(updateObj);
|
|
@@ -88,6 +107,30 @@ public class DeptServiceImpl implements DeptService {
|
|
deptMapper.deleteById(id);
|
|
deptMapper.deleteById(id);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @VisibleForTesting
|
|
|
|
+ void validateDeptPhoneExists(String phone) {
|
|
|
|
+ if (phone == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ DeptDO dept = deptMapper.selectOne(
|
|
|
|
+ new LambdaQueryWrapperX<DeptDO>().eq(DeptDO::getPhone, phone)
|
|
|
|
+ );
|
|
|
|
+ if (dept != null) {
|
|
|
|
+ throw exception(DEPT_PHONE_FOUND);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ @VisibleForTesting
|
|
|
|
+ void validateDeptEmailExists(String email) {
|
|
|
|
+ if (email == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ DeptDO dept = deptMapper.selectOne(
|
|
|
|
+ new LambdaQueryWrapperX<DeptDO>().eq(DeptDO::getEmail, email)
|
|
|
|
+ );
|
|
|
|
+ if (dept != null) {
|
|
|
|
+ throw exception(DEPT_EMAIL_FOUND);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
@VisibleForTesting
|
|
@VisibleForTesting
|
|
void validateDeptExists(Long id) {
|
|
void validateDeptExists(Long id) {
|
|
if (id == null) {
|
|
if (id == null) {
|
|
@@ -205,6 +248,9 @@ public class DeptServiceImpl implements DeptService {
|
|
Map<Long, DeptDO> deptMap = getDeptMap(ids);
|
|
Map<Long, DeptDO> deptMap = getDeptMap(ids);
|
|
// 校验
|
|
// 校验
|
|
ids.forEach(id -> {
|
|
ids.forEach(id -> {
|
|
|
|
+ if(id == 0L){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
DeptDO dept = deptMap.get(id);
|
|
DeptDO dept = deptMap.get(id);
|
|
if (dept == null) {
|
|
if (dept == null) {
|
|
throw exception(DEPT_NOT_FOUND);
|
|
throw exception(DEPT_NOT_FOUND);
|