update 优化部门类别编码获取

This commit is contained in:
AprilWind 2024-05-16 17:52:16 +08:00
parent 727df8dd94
commit 624fd87751
7 changed files with 58 additions and 4 deletions

View File

@ -142,7 +142,6 @@ public class SysLoginService {
SpringUtils.context().publishEvent(logininforEvent);
}
/**
* 构建登录用户
*/
@ -162,6 +161,7 @@ public class SysLoginService {
dept = deptService.selectDeptById(user.getDeptId());
}
loginUser.setDeptName(ObjectUtil.isNull(dept) ? "" : dept.getDeptName());
loginUser.setDeptCategory(ObjectUtil.isNull(dept) ? "" : dept.getDeptCategory());
List<SysRoleVo> roles = roleService.selectRolesByUserId(user.getUserId());
loginUser.setRoles(BeanUtil.copyToList(roles, RoleDTO.class));
});

View File

@ -14,7 +14,6 @@ import java.util.Set;
*
* @author Lion Li
*/
@Data
@NoArgsConstructor
public class LoginUser implements Serializable {
@ -37,6 +36,11 @@ public class LoginUser implements Serializable {
*/
private Long deptId;
/**
* 部门类别编码
*/
private String deptCategory;
/**
* 部门名
*/

View File

@ -35,6 +35,7 @@ public class LoginHelper {
public static final String USER_NAME_KEY = "userName";
public static final String DEPT_KEY = "deptId";
public static final String DEPT_NAME_KEY = "deptName";
public static final String DEPT_CATEGORY_KEY = "deptCategory";
public static final String CLIENT_KEY = "clientid";
/**
@ -52,6 +53,7 @@ public class LoginHelper {
.setExtra(USER_NAME_KEY, loginUser.getUsername())
.setExtra(DEPT_KEY, loginUser.getDeptId())
.setExtra(DEPT_NAME_KEY, loginUser.getDeptName())
.setExtra(DEPT_CATEGORY_KEY, loginUser.getDeptCategory())
);
StpUtil.getTokenSession().set(LOGIN_USER_KEY, loginUser);
}
@ -99,6 +101,20 @@ public class LoginHelper {
return Convert.toLong(getExtra(DEPT_KEY));
}
/**
* 获取部门名
*/
public static String getDeptName() {
return Convert.toStr(getExtra(DEPT_NAME_KEY));
}
/**
* 获取部门类别编码
*/
public static String getDeptCategory() {
return Convert.toStr(getExtra(DEPT_CATEGORY_KEY));
}
/**
* 获取当前 Token 的扩展信息
*

View File

@ -75,6 +75,8 @@ public class SysDeptController extends BaseController {
public R<Void> add(@Validated @RequestBody SysDeptBo dept) {
if (!deptService.checkDeptNameUnique(dept)) {
return R.fail("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
} else if (StringUtils.isNotBlank(dept.getDeptCategory()) && !deptService.checkDeptCategoryUnique(dept)) {
return R.fail("新增部门'" + dept.getDeptName() + "'失败,部门类别编码已存在");
}
return toAjax(deptService.insertDept(dept));
}
@ -90,6 +92,8 @@ public class SysDeptController extends BaseController {
deptService.checkDeptDataScope(deptId);
if (!deptService.checkDeptNameUnique(dept)) {
return R.fail("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
} else if (StringUtils.isNotBlank(dept.getDeptCategory()) && !deptService.checkDeptCategoryUnique(dept)) {
return R.fail("修改部门'" + dept.getDeptName() + "'失败,部门类别编码已存在");
} else if (dept.getParentId().equals(deptId)) {
return R.fail("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
} else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())) {

View File

@ -41,6 +41,11 @@ public class SysDeptVo implements Serializable {
*/
private String parentName;
/**
* 父部门类别编码
*/
private String parentCategory;
/**
* 祖级列表
*/

View File

@ -92,6 +92,14 @@ public interface ISysDeptService {
*/
boolean checkDeptNameUnique(SysDeptBo dept);
/**
* 校验部门类别编码是否唯一
*
* @param dept 部门信息
* @return 结果
*/
boolean checkDeptCategoryUnique(SysDeptBo dept);
/**
* 校验部门是否有数据权限
*

View File

@ -135,8 +135,11 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
return null;
}
SysDeptVo parentDept = baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>()
.select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId()));
dept.setParentName(ObjectUtil.isNotNull(parentDept) ? parentDept.getDeptName() : null);
.select(SysDept::getDeptName, SysDept::getDeptCategory).eq(SysDept::getDeptId, dept.getParentId()));
if (ObjectUtil.isNotNull(parentDept)) {
dept.setParentName(parentDept.getDeptName());
dept.setParentCategory(parentDept.getDeptCategory());
}
return dept;
}
@ -218,6 +221,20 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
return !exist;
}
/**
* 校验部门类别编码是否唯一
*
* @param dept 部门信息
* @return 结果
*/
@Override
public boolean checkDeptCategoryUnique(SysDeptBo dept) {
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysDept>()
.eq(SysDept::getDeptCategory, dept.getDeptCategory())
.ne(ObjectUtil.isNotNull(dept.getDeptId()), SysDept::getDeptId, dept.getDeptId()));
return !exist;
}
/**
* 校验部门是否有数据权限
*