refactor(系统微服务代码逻辑优化): 组织类型通过常量判断

This commit is contained in:
OTTO 2024-06-19 14:30:50 +08:00
parent 426351894b
commit e66e088cda
3 changed files with 28 additions and 68 deletions

View File

@ -116,11 +116,6 @@ public class CacheConstants
*/
public static final String SYS_LOGIN_BLACKIPLIST = SYS_CONFIG_KEY + "sys.login.blackIPList";
/**
* 组织类型 sys_dict key
*/
public static final String SYS_DICT_DEPT_TYPE = "dept_type";
/**
* 文件类型 sys_dict key
*/
@ -131,14 +126,14 @@ public class CacheConstants
public static final String SYS_DICT_GITLINK_PROJECT_PROPERTIES = "gitlink_project_properties";
/**
* 组织类型-特色专区 sys_dict_data label
* 组织类型-特色专区
*/
public static final String SYS_DICT_DEPT_TYPE_TSZQ = "特色专区";
public static final int DEPT_TYPE_TSZQ = 1;
/**
* 组织类型-项目管理 sys_dict_data label
* 组织类型-项目管理
*/
public static final String SYS_DICT_DEPT_TYPE_PMS = "项目管理";
public static final int DEPT_TYPE_PMS = 2;
/**
* 特色专区字典 zone key

View File

@ -9,11 +9,9 @@ import com.microservices.common.core.text.Convert;
import com.microservices.common.core.utils.DateUtils;
import com.microservices.common.core.utils.StringUtils;
import com.microservices.common.datascope.annotation.DataScope;
import com.microservices.common.security.utils.DictUtils;
import com.microservices.common.security.utils.SecurityUtils;
import com.microservices.system.api.RemoteZoneService;
import com.microservices.system.api.domain.SysDept;
import com.microservices.system.api.domain.SysDictData;
import com.microservices.system.api.domain.SysRole;
import com.microservices.system.api.domain.SysUser;
import com.microservices.system.api.utils.FeignUtils;
@ -243,12 +241,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
@Override
public Long addDeptByZone(String zoneName) {
SysDictData deptTypeData = DictUtils.getDictDataCacheByLabel(CacheConstants.SYS_DICT_DEPT_TYPE, CacheConstants.SYS_DICT_DEPT_TYPE_TSZQ);
if (deptTypeData == null) {
throw new ServiceException("当前不支持[%s]类型", CacheConstants.SYS_DICT_DEPT_TYPE_TSZQ);
}
Integer deptTypeValue = Integer.valueOf(deptTypeData.getDictValue());
SysDept parentDept = deptMapper.selectParentDeptByType(deptTypeValue);
SysDept parentDept = deptMapper.selectParentDeptByType(CacheConstants.DEPT_TYPE_TSZQ);
// 如果父节点不为正常状态,则不允许新增子节点
if (parentDept == null || !UserConstants.DEPT_NORMAL.equals(parentDept.getStatus())) {
throw new ServiceException("当前部门停用,不允许新增");
@ -277,12 +270,8 @@ public class SysDeptServiceImpl implements ISysDeptService {
@Override
public Long addDeptByPmsEnterprise(String pmsEnterpriseName) {
SysDictData deptTypeData = DictUtils.getDictDataCacheByLabel(CacheConstants.SYS_DICT_DEPT_TYPE, CacheConstants.SYS_DICT_DEPT_TYPE_PMS);
if (deptTypeData == null) {
throw new ServiceException("当前不支持[%s]类型", CacheConstants.SYS_DICT_DEPT_TYPE_PMS);
}
Integer deptTypeValue = Integer.valueOf(deptTypeData.getDictValue());
SysDept parentDept = deptMapper.selectParentDeptByType(deptTypeValue);
SysDept parentDept = deptMapper.selectParentDeptByType(CacheConstants.DEPT_TYPE_PMS);
if (parentDept == null) {
SysDept firstDept = deptMapper.selectFirstDept();
parentDept = insertSysDept(firstDept, "项目管理部");
@ -332,13 +321,8 @@ public class SysDeptServiceImpl implements ISysDeptService {
@Override
public Boolean deleteDeptByPmsEnterprise(String pmsEnterpriseName) {
SysDictData deptTypeData = DictUtils.getDictDataCacheByLabel(CacheConstants.SYS_DICT_DEPT_TYPE, CacheConstants.SYS_DICT_DEPT_TYPE_PMS);
if (deptTypeData == null) {
throw new ServiceException("当前不支持[%s]类型", CacheConstants.SYS_DICT_DEPT_TYPE_PMS);
}
Integer deptTypeValue = Integer.valueOf(deptTypeData.getDictValue());
// 查找项目管理父级部门若不存在则返回true
SysDept parentDept = deptMapper.selectParentDeptByType(deptTypeValue);
SysDept parentDept = deptMapper.selectParentDeptByType(CacheConstants.DEPT_TYPE_PMS);
if (parentDept == null) {
return true;
}
@ -421,25 +405,20 @@ public class SysDeptServiceImpl implements ISysDeptService {
if (dept.getDeptType() == null) {
errorMessage = "请先设置上级组织的组织类型(上级组织Id[" + dept.getParentId() + "])";
} else {
String deptTypeLabel = DictUtils.getDictDataLabelByValue(CacheConstants.SYS_DICT_DEPT_TYPE, String.valueOf(dept.getDeptType()));
if (deptTypeLabel == null) {
errorMessage = "该组织的组织类型错误(组织类型Id[" + dept.getDeptType() + "])";
} else {
switch (deptTypeLabel) {
case CacheConstants.SYS_DICT_DEPT_TYPE_TSZQ:
if (isAdd) {
// 设置该组织下可选角色为专区管理员专区运营人员专区会员
addDefaultRoleForDept(dept);
errorMessage = createProjectByDept(dept);
} else {
errorMessage = updateProjectByDept(dept);
}
switch (dept.getDeptType()) {
case CacheConstants.DEPT_TYPE_TSZQ:
if (isAdd) {
// 设置该组织下可选角色为专区管理员专区运营人员专区会员
addDefaultRoleForDept(dept);
errorMessage = createProjectByDept(dept);
} else {
errorMessage = updateProjectByDept(dept);
}
result = !StringUtils.isNotEmpty(errorMessage);
break;
default:
errorMessage = "该组织类型当前不存在对应的业务方自动处理逻辑(组织类型[" + deptTypeLabel + "])";
}
result = !StringUtils.isNotEmpty(errorMessage);
break;
default:
errorMessage = "该组织类型当前不存在对应的业务方自动处理逻辑(组织类型[" + dept.getDeptType() + "])";
}
}
@ -588,11 +567,7 @@ public class SysDeptServiceImpl implements ISysDeptService {
SysDept dept = selectDeptById(deptId);
// 删除组织下用户
sysUserDeptRoleService.deleteSysUserDeptRoleByDeptId(deptId);
SysDictData deptTypeData = DictUtils.getDictDataCacheByValue(CacheConstants.SYS_DICT_DEPT_TYPE, String.valueOf(dept.getDeptType()));
if (deptTypeData == null) {
throw new ServiceException("该组织的组织类型错误(组织类型Id[" + dept.getDeptType() + "])");
}
if (CacheConstants.SYS_DICT_DEPT_TYPE_TSZQ.equals(deptTypeData.getDictLabel())) {
if (CacheConstants.DEPT_TYPE_TSZQ == dept.getDeptType()) {
// 删除专区相关数据
remoteZoneService.deleteByDeptName(dept.getDeptName(), SecurityConstants.INNER);
// 删除组织下用户

View File

@ -13,7 +13,6 @@ import com.microservices.common.httpClient.domain.GitLinkRequestUrl;
import com.microservices.common.httpClient.util.GitLinkRequestHelper;
import com.microservices.common.redis.service.RedisService;
import com.microservices.common.security.service.TokenService;
import com.microservices.common.security.utils.DictUtils;
import com.microservices.common.security.utils.SecurityUtils;
import com.microservices.system.api.RemoteCmsService;
import com.microservices.system.api.RemotePmsService;
@ -25,7 +24,6 @@ import com.microservices.system.api.domain.SysUserDeptRole;
import com.microservices.system.api.utils.FeignUtils;
import com.microservices.system.domain.dto.GitLinkUserDeptRoleByDeptInput;
import com.microservices.system.domain.dto.SysUserDeptRoleByDeptInput;
import com.microservices.system.domain.dto.SysUserDeptRoleByUserInput;
import com.microservices.system.domain.vo.GitLinkUserSearchVo;
import com.microservices.system.mapper.SysDeptMapper;
import com.microservices.system.mapper.SysUserDeptRoleMapper;
@ -223,12 +221,8 @@ public class SysUserDeptRoleServiceImpl implements ISysUserDeptRoleService {
if (!secondaryDeptIds.contains(dept.getDeptId())) {
if (secondaryDeptIds.contains(dept.getParentId())) {
String deptTypeLabel = DictUtils.getDictDataLabelByValue(CacheConstants.SYS_DICT_DEPT_TYPE, String.valueOf(dept.getDeptType()));
if (deptTypeLabel == null) {
throw new ServiceException("该组织的组织类型错误(组织类型Id[" + dept.getDeptType() + "])");
}
switch (deptTypeLabel) {
case CacheConstants.SYS_DICT_DEPT_TYPE_TSZQ: {
switch (dept.getDeptType()) {
case CacheConstants.DEPT_TYPE_TSZQ: {
//如果用户为三级组织则将用户加入到专区对应项目中
switch (operate) {
case OPERATE_ADD: {
@ -260,7 +254,7 @@ public class SysUserDeptRoleServiceImpl implements ISysUserDeptRoleService {
}
break;
}
case CacheConstants.SYS_DICT_DEPT_TYPE_PMS: {
case CacheConstants.DEPT_TYPE_PMS: {
// 更新或移出用户时需检查角色是否为组织管理员项目管理中至少保留一位组织管理员
if (oldRoleId != null) {
SysRole orgAdminRole = sysRoleService.selectRoleByKey(SystemRole.PMS_ORG_ADMIN.getRoleKey());
@ -354,11 +348,10 @@ public class SysUserDeptRoleServiceImpl implements ISysUserDeptRoleService {
sysUserDeptRole.setUserId(userId);
sysUserDeptRole.setDeptId(deptId);
sysUserDeptRole.setRoleId(roleId);
return updateSysUserDeptRole(sysUserDeptRole);
updateSysUserDeptRole(sysUserDeptRole);
}
private int updateSysUserDeptRole(SysUserDeptRole sysUserDeptRoleInput) {
int success = 0;
private void updateSysUserDeptRole(SysUserDeptRole sysUserDeptRoleInput) {
SysDept sysDept = sysDeptRoleService.selectSysDeptById(sysUserDeptRoleInput.getDeptId());
SysUserDeptRole sysUserDeptRole = getSysUserDeptRole(sysUserDeptRoleInput);
@ -369,12 +362,9 @@ public class SysUserDeptRoleServiceImpl implements ISysUserDeptRoleService {
"部门名称[" + sysDept.getDeptName() + "])");
}
if (!sysUserDeptRole.equals(sysUserDeptRoleInput)) {
success += sysUserDeptRoleMapper.updateSysUserDeptRole(sysUserDeptRoleInput);
sysUserDeptRoleMapper.updateSysUserDeptRole(sysUserDeptRoleInput);
updateUserLoginInfoByUserId(sysUserDeptRoleInput.getUserId());
} else {
success++;
}
return success;
}
@Override