fix(): 修改代码规范
1. 增加枚举工具类 2. 部门添加为mybatis-plus方式进行添加 3. 部门删除改为mybatis-plus方式进行删除boot3.0
parent
989cef6f65
commit
347a329b0a
|
@ -0,0 +1,30 @@
|
||||||
|
package com.muyu.common.core.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dongzeliang
|
||||||
|
* @version 1.0
|
||||||
|
* @description: 系统逻辑删除
|
||||||
|
* @date 2025/1/16 18:48
|
||||||
|
*/
|
||||||
|
public enum SysDelFlag {
|
||||||
|
// 存在
|
||||||
|
EXIST("0", "存在"),
|
||||||
|
// 删除
|
||||||
|
NOT_EXIST("2", "删除")
|
||||||
|
;
|
||||||
|
private final String code;
|
||||||
|
private final String info;
|
||||||
|
|
||||||
|
SysDelFlag(String code, String info) {
|
||||||
|
this.code = code;
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfo() {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package com.muyu.common.core.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dongzeliang
|
||||||
|
* @version 1.0
|
||||||
|
* @description: 系统开关
|
||||||
|
* @date 2025/1/16 18:44
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum SysNormalDisable {
|
||||||
|
ENABLE("0", "正常"),
|
||||||
|
DISABLE("1", "停用");
|
||||||
|
private final String code;
|
||||||
|
private final String info;
|
||||||
|
|
||||||
|
SysNormalDisable(String code, String info) {
|
||||||
|
this.code = code;
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否启用
|
||||||
|
* @param code 编码
|
||||||
|
* @return 启用:true 禁用:false
|
||||||
|
*/
|
||||||
|
public static boolean isEnable(String code) {
|
||||||
|
return ENABLE.getCode().equals(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否禁用
|
||||||
|
* @param code 编码
|
||||||
|
* @return 启用:false 禁用:true
|
||||||
|
*/
|
||||||
|
public static boolean isDisable(String code) {
|
||||||
|
return !isEnable(code);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -113,4 +113,5 @@ public class SysDept extends BaseEntity {
|
||||||
public String getEmail () {
|
public String getEmail () {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,9 @@ import com.muyu.common.log.enums.BusinessType;
|
||||||
import com.muyu.common.security.annotation.RequiresPermissions;
|
import com.muyu.common.security.annotation.RequiresPermissions;
|
||||||
import com.muyu.common.security.utils.SecurityUtils;
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.common.system.domain.SysDept;
|
import com.muyu.common.system.domain.SysDept;
|
||||||
|
import com.muyu.system.domain.model.CheckDeptNameUniqueModel;
|
||||||
import com.muyu.system.domain.model.SysDeptPageQueryModel;
|
import com.muyu.system.domain.model.SysDeptPageQueryModel;
|
||||||
|
import com.muyu.system.domain.rep.SysDeptAddReq;
|
||||||
import com.muyu.system.domain.rep.SysDeptListReq;
|
import com.muyu.system.domain.rep.SysDeptListReq;
|
||||||
import com.muyu.system.service.SysDeptService;
|
import com.muyu.system.service.SysDeptService;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
@ -70,12 +72,12 @@ public class SysDeptController extends BaseController {
|
||||||
@RequiresPermissions("system:dept:add")
|
@RequiresPermissions("system:dept:add")
|
||||||
@Log(title = "部门管理", businessType = BusinessType.INSERT)
|
@Log(title = "部门管理", businessType = BusinessType.INSERT)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
public Result add (@Validated @RequestBody SysDept dept) {
|
public Result<String> add (@Validated @RequestBody SysDeptAddReq sysDeptAddReq) {
|
||||||
if (!deptService.checkDeptNameUnique(dept)) {
|
if (!deptService.checkDeptNameUnique(CheckDeptNameUniqueModel.of(sysDeptAddReq.getDeptName()))) {
|
||||||
return error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
return error("新增部门'" + sysDeptAddReq.getDeptName() + "'失败,部门名称已存在");
|
||||||
}
|
}
|
||||||
dept.setCreateBy(SecurityUtils.getUsername());
|
deptService.insertDept(sysDeptAddReq.buildSysDept());
|
||||||
return toAjax(deptService.insertDept(dept));
|
return success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,7 +89,9 @@ public class SysDeptController extends BaseController {
|
||||||
public Result edit (@Validated @RequestBody SysDept dept) {
|
public Result edit (@Validated @RequestBody SysDept dept) {
|
||||||
Long deptId = dept.getDeptId();
|
Long deptId = dept.getDeptId();
|
||||||
deptService.checkDeptDataScope(deptId);
|
deptService.checkDeptDataScope(deptId);
|
||||||
if (!deptService.checkDeptNameUnique(dept)) {
|
if (!deptService.checkDeptNameUnique(
|
||||||
|
CheckDeptNameUniqueModel.of(dept.getDeptName(),deptId,dept.getParentId())
|
||||||
|
)) {
|
||||||
return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
return error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
|
||||||
} else if (dept.getParentId().equals(deptId)) {
|
} else if (dept.getParentId().equals(deptId)) {
|
||||||
return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
|
return error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
|
||||||
|
@ -104,7 +108,7 @@ public class SysDeptController extends BaseController {
|
||||||
@RequiresPermissions("system:dept:remove")
|
@RequiresPermissions("system:dept:remove")
|
||||||
@Log(title = "部门管理", businessType = BusinessType.DELETE)
|
@Log(title = "部门管理", businessType = BusinessType.DELETE)
|
||||||
@DeleteMapping("/{deptId}")
|
@DeleteMapping("/{deptId}")
|
||||||
public Result remove (@PathVariable("deptId") Long deptId) {
|
public Result<String> remove (@PathVariable("deptId") Long deptId) {
|
||||||
if (deptService.hasChildByDeptId(deptId)) {
|
if (deptService.hasChildByDeptId(deptId)) {
|
||||||
return warn("存在下级部门,不允许删除");
|
return warn("存在下级部门,不允许删除");
|
||||||
}
|
}
|
||||||
|
@ -112,6 +116,7 @@ public class SysDeptController extends BaseController {
|
||||||
return warn("部门存在用户,不允许删除");
|
return warn("部门存在用户,不允许删除");
|
||||||
}
|
}
|
||||||
deptService.checkDeptDataScope(deptId);
|
deptService.checkDeptDataScope(deptId);
|
||||||
return toAjax(deptService.deleteDeptById(deptId));
|
deptService.deleteDeptById(deptId);
|
||||||
|
return success();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
package com.muyu.system.domain.model;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dongzeliang
|
||||||
|
* @version 1.0
|
||||||
|
* @description: 校验部门名称唯一性模型
|
||||||
|
* @date 2025/1/16 18:18
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class CheckDeptNameUniqueModel {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门名称
|
||||||
|
*/
|
||||||
|
private String deptName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门ID 若传入部门ID则排除此部门
|
||||||
|
*/
|
||||||
|
private Long deptId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门父级ID 传入父级ID则只校验子集ID
|
||||||
|
*/
|
||||||
|
private Long parentDeptId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据部门名称进行唯一性查询模型构建
|
||||||
|
* @param deptName 部门名称
|
||||||
|
* @return 唯一性查询模型
|
||||||
|
*/
|
||||||
|
public static CheckDeptNameUniqueModel of(String deptName){
|
||||||
|
return CheckDeptNameUniqueModel.builder()
|
||||||
|
.deptName(deptName)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据部门名称进行唯一性查询模型构建
|
||||||
|
* @param deptName 部门名称
|
||||||
|
* @param deptId 部门ID
|
||||||
|
* @return 唯一性查询模型
|
||||||
|
*/
|
||||||
|
public static CheckDeptNameUniqueModel of(String deptName, Long deptId){
|
||||||
|
return CheckDeptNameUniqueModel.builder()
|
||||||
|
.deptName(deptName)
|
||||||
|
.deptId(deptId)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据部门名称进行唯一性查询模型构建
|
||||||
|
* @param deptName 部门名称
|
||||||
|
* @param deptId 部门ID
|
||||||
|
* @param parentDeptId 部门父级ID
|
||||||
|
* @return 唯一性查询模型
|
||||||
|
*/
|
||||||
|
public static CheckDeptNameUniqueModel of(String deptName, Long deptId, Long parentDeptId){
|
||||||
|
return CheckDeptNameUniqueModel.builder()
|
||||||
|
.deptName(deptName)
|
||||||
|
.deptId(deptId)
|
||||||
|
.parentDeptId(parentDeptId)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
package com.muyu.system.domain.rep;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
|
import com.muyu.common.system.domain.SysDept;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dongzeliang
|
||||||
|
* @version 1.0
|
||||||
|
* @description: 部门管理添加请求对象
|
||||||
|
* @date 2025/1/16 18:06
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class SysDeptAddReq {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父部门ID
|
||||||
|
*/
|
||||||
|
private Long parentId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门名称
|
||||||
|
*/
|
||||||
|
private String deptName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 显示顺序
|
||||||
|
*/
|
||||||
|
private Integer orderNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 负责人
|
||||||
|
*/
|
||||||
|
private String leader;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 联系电话
|
||||||
|
*/
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 邮箱
|
||||||
|
*/
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门状态:0正常,1停用
|
||||||
|
*/
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除标志(0代表存在 2代表删除)
|
||||||
|
*/
|
||||||
|
private String delFlag;
|
||||||
|
|
||||||
|
public SysDept buildSysDept(){
|
||||||
|
return SysDept.builder()
|
||||||
|
.deptName(this.deptName)
|
||||||
|
.orderNum(this.orderNum)
|
||||||
|
.email(this.email)
|
||||||
|
.delFlag(this.delFlag)
|
||||||
|
.phone(this.phone)
|
||||||
|
.status(this.status)
|
||||||
|
.leader(this.leader)
|
||||||
|
.parentId(this.parentId)
|
||||||
|
.createBy(SecurityUtils.getUsername())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.muyu.system.mapper;
|
package com.muyu.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
import com.muyu.common.system.domain.SysDept;
|
import com.muyu.common.system.domain.SysDept;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
@ -31,23 +32,6 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
|
||||||
*/
|
*/
|
||||||
public List<Long> selectDeptListByRoleId (@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly);
|
public List<Long> selectDeptListByRoleId (@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据部门ID查询信息
|
|
||||||
*
|
|
||||||
* @param deptId 部门ID
|
|
||||||
*
|
|
||||||
* @return 部门信息
|
|
||||||
*/
|
|
||||||
public SysDept selectDeptById (Long deptId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据ID查询所有子部门
|
|
||||||
*
|
|
||||||
* @param deptId 部门ID
|
|
||||||
*
|
|
||||||
* @return 部门列表
|
|
||||||
*/
|
|
||||||
public List<SysDept> selectChildrenDeptById (Long deptId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据ID查询所有子部门(正常状态)
|
* 根据ID查询所有子部门(正常状态)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.system.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.muyu.common.system.domain.SysDept;
|
import com.muyu.common.system.domain.SysDept;
|
||||||
|
import com.muyu.system.domain.model.CheckDeptNameUniqueModel;
|
||||||
import com.muyu.system.domain.model.SysDeptPageQueryModel;
|
import com.muyu.system.domain.model.SysDeptPageQueryModel;
|
||||||
import com.muyu.system.domain.vo.TreeSelect;
|
import com.muyu.system.domain.vo.TreeSelect;
|
||||||
|
|
||||||
|
@ -95,11 +96,10 @@ public interface SysDeptService extends IService<SysDept> {
|
||||||
/**
|
/**
|
||||||
* 校验部门名称是否唯一
|
* 校验部门名称是否唯一
|
||||||
*
|
*
|
||||||
* @param dept 部门信息
|
* @param checkDeptNameUniqueModel 部门信息
|
||||||
*
|
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public boolean checkDeptNameUnique (SysDept dept);
|
public boolean checkDeptNameUnique (CheckDeptNameUniqueModel checkDeptNameUniqueModel);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 校验部门是否有数据权限
|
* 校验部门是否有数据权限
|
||||||
|
@ -115,7 +115,7 @@ public interface SysDeptService extends IService<SysDept> {
|
||||||
*
|
*
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int insertDept (SysDept dept);
|
public void insertDept (SysDept dept);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改保存部门信息
|
* 修改保存部门信息
|
||||||
|
@ -133,7 +133,7 @@ public interface SysDeptService extends IService<SysDept> {
|
||||||
*
|
*
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteDeptById (Long deptId);
|
public void deleteDeptById (Long deptId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询部门信息
|
* 查询部门信息
|
||||||
|
@ -141,4 +141,13 @@ public interface SysDeptService extends IService<SysDept> {
|
||||||
* @return 分页返回结果
|
* @return 分页返回结果
|
||||||
*/
|
*/
|
||||||
List<SysDept> queryList(SysDeptPageQueryModel sysDeptPageQueryModel);
|
List<SysDept> queryList(SysDeptPageQueryModel sysDeptPageQueryModel);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询所有子部门
|
||||||
|
*
|
||||||
|
* @param deptId 部门ID
|
||||||
|
*
|
||||||
|
* @return 部门列表
|
||||||
|
*/
|
||||||
|
public List<SysDept> selectChildrenDeptById (Long deptId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
package com.muyu.system.service.impl;
|
package com.muyu.system.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.muyu.common.core.constant.UserConstants;
|
import com.muyu.common.core.constant.UserConstants;
|
||||||
|
import com.muyu.common.core.enums.SysDelFlag;
|
||||||
|
import com.muyu.common.core.enums.SysNormalDisable;
|
||||||
import com.muyu.common.core.exception.ServiceException;
|
import com.muyu.common.core.exception.ServiceException;
|
||||||
import com.muyu.common.core.text.Convert;
|
import com.muyu.common.core.text.Convert;
|
||||||
import com.muyu.common.core.utils.SpringUtils;
|
import com.muyu.common.core.utils.SpringUtils;
|
||||||
|
@ -12,6 +15,7 @@ import com.muyu.common.security.utils.SecurityUtils;
|
||||||
import com.muyu.common.system.domain.SysDept;
|
import com.muyu.common.system.domain.SysDept;
|
||||||
import com.muyu.common.system.domain.SysRole;
|
import com.muyu.common.system.domain.SysRole;
|
||||||
import com.muyu.common.system.domain.SysUser;
|
import com.muyu.common.system.domain.SysUser;
|
||||||
|
import com.muyu.system.domain.model.CheckDeptNameUniqueModel;
|
||||||
import com.muyu.system.domain.model.SysDeptPageQueryModel;
|
import com.muyu.system.domain.model.SysDeptPageQueryModel;
|
||||||
import com.muyu.system.domain.vo.TreeSelect;
|
import com.muyu.system.domain.vo.TreeSelect;
|
||||||
import com.muyu.system.mapper.SysDeptMapper;
|
import com.muyu.system.mapper.SysDeptMapper;
|
||||||
|
@ -19,6 +23,7 @@ import com.muyu.system.mapper.SysRoleMapper;
|
||||||
import com.muyu.system.service.SysDeptService;
|
import com.muyu.system.service.SysDeptService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -45,6 +50,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.like(StringUtils.isNotEmpty(sysDeptPageQueryModel.getDeptName()),SysDept::getDeptName, sysDeptPageQueryModel.getDeptName());
|
queryWrapper.like(StringUtils.isNotEmpty(sysDeptPageQueryModel.getDeptName()),SysDept::getDeptName, sysDeptPageQueryModel.getDeptName());
|
||||||
queryWrapper.eq(StringUtils.isNotEmpty(sysDeptPageQueryModel.getStatus()),SysDept::getStatus,sysDeptPageQueryModel.getStatus());
|
queryWrapper.eq(StringUtils.isNotEmpty(sysDeptPageQueryModel.getStatus()),SysDept::getStatus,sysDeptPageQueryModel.getStatus());
|
||||||
|
queryWrapper.eq(SysDept::getStatus, SysDelFlag.EXIST.getCode());
|
||||||
return this.list(queryWrapper);
|
return this.list(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +147,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public SysDept selectDeptById (Long deptId) {
|
public SysDept selectDeptById (Long deptId) {
|
||||||
return deptMapper.selectDeptById(deptId);
|
return this.getById(deptId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -185,14 +191,19 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
/**
|
/**
|
||||||
* 校验部门名称是否唯一
|
* 校验部门名称是否唯一
|
||||||
*
|
*
|
||||||
* @param dept 部门信息
|
* @param checkDeptNameUniqueModel 检查模型
|
||||||
*
|
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean checkDeptNameUnique (SysDept dept) {
|
public boolean checkDeptNameUnique (CheckDeptNameUniqueModel checkDeptNameUniqueModel) {
|
||||||
Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
|
Assert.notNull(checkDeptNameUniqueModel.getDeptName(), "部门名称不可为空");
|
||||||
SysDept info = deptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId());
|
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(SysDept::getDeptName, checkDeptNameUniqueModel.getDeptName());
|
||||||
|
queryWrapper.eq(Objects.nonNull(checkDeptNameUniqueModel.getParentDeptId()), SysDept::getParentId, checkDeptNameUniqueModel.getParentDeptId());
|
||||||
|
queryWrapper.eq(SysDept::getStatus, SysDelFlag.EXIST.getCode());
|
||||||
|
|
||||||
|
Long deptId = StringUtils.isNull(checkDeptNameUniqueModel.getDeptId()) ? -1L : checkDeptNameUniqueModel.getDeptId();
|
||||||
|
SysDept info = deptMapper.checkDeptNameUnique(checkDeptNameUniqueModel.getDeptName(), checkDeptNameUniqueModel.getParentDeptId());
|
||||||
if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) {
|
if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) {
|
||||||
return UserConstants.NOT_UNIQUE;
|
return UserConstants.NOT_UNIQUE;
|
||||||
}
|
}
|
||||||
|
@ -207,9 +218,9 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
@Override
|
@Override
|
||||||
public void checkDeptDataScope (Long deptId) {
|
public void checkDeptDataScope (Long deptId) {
|
||||||
if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
|
if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
|
||||||
List<SysDept> depts = SpringUtils.getAopProxy(this)
|
List<SysDept> deptList = SpringUtils.getAopProxy(this)
|
||||||
.selectDeptList(SysDeptPageQueryModel.ofToDeptId(deptId));
|
.selectDeptList(SysDeptPageQueryModel.ofToDeptId(deptId));
|
||||||
if (StringUtils.isEmpty(depts)) {
|
if (StringUtils.isEmpty(deptList)) {
|
||||||
throw new ServiceException("没有权限访问部门数据!");
|
throw new ServiceException("没有权限访问部门数据!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,14 +234,14 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int insertDept (SysDept dept) {
|
public void insertDept (SysDept dept) {
|
||||||
SysDept info = deptMapper.selectDeptById(dept.getParentId());
|
SysDept parentSysDept = this.getById(dept.getParentId());
|
||||||
// 如果父节点不为正常状态,则不允许新增子节点
|
// 如果父节点不为正常状态,则不允许新增子节点
|
||||||
if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
|
if (SysNormalDisable.isDisable(dept.getStatus())) {
|
||||||
throw new ServiceException("部门停用,不允许新增");
|
throw new ServiceException("部门停用,不允许新增");
|
||||||
}
|
}
|
||||||
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
|
dept.setAncestors(parentSysDept.getAncestors() + "," + dept.getParentId());
|
||||||
return deptMapper.insertDept(dept);
|
this.save(dept);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -242,8 +253,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int updateDept (SysDept dept) {
|
public int updateDept (SysDept dept) {
|
||||||
SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
|
SysDept newParentDept = this.getById(dept.getParentId());
|
||||||
SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
|
SysDept oldDept = this.getById(dept.getDeptId());
|
||||||
if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) {
|
if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) {
|
||||||
String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
|
String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
|
||||||
String oldAncestors = oldDept.getAncestors();
|
String oldAncestors = oldDept.getAncestors();
|
||||||
|
@ -278,7 +289,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
* @param oldAncestors 旧的父ID集合
|
* @param oldAncestors 旧的父ID集合
|
||||||
*/
|
*/
|
||||||
public void updateDeptChildren (Long deptId, String newAncestors, String oldAncestors) {
|
public void updateDeptChildren (Long deptId, String newAncestors, String oldAncestors) {
|
||||||
List<SysDept> children = deptMapper.selectChildrenDeptById(deptId);
|
List<SysDept> children = this.selectChildrenDeptById(deptId);
|
||||||
for (SysDept child : children) {
|
for (SysDept child : children) {
|
||||||
child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
|
child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
|
||||||
}
|
}
|
||||||
|
@ -295,8 +306,11 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int deleteDeptById (Long deptId) {
|
public void deleteDeptById (Long deptId) {
|
||||||
return deptMapper.deleteDeptById(deptId);
|
LambdaUpdateWrapper<SysDept> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.set(SysDept::getStatus, SysDelFlag.NOT_EXIST.getCode());
|
||||||
|
updateWrapper.eq(SysDept::getDeptId, deptId);
|
||||||
|
this.update(updateWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -334,4 +348,17 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
private boolean hasChild (List<SysDept> list, SysDept t) {
|
private boolean hasChild (List<SysDept> list, SysDept t) {
|
||||||
return !getChildList(list, t).isEmpty();
|
return !getChildList(list, t).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询所有子部门
|
||||||
|
*
|
||||||
|
* @param deptId 部门ID
|
||||||
|
*
|
||||||
|
* @return 部门列表
|
||||||
|
*/
|
||||||
|
public List<SysDept> selectChildrenDeptById (Long deptId){
|
||||||
|
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.apply("FIND_IN_SET('" + deptId + "', type)");
|
||||||
|
return this.list(queryWrapper);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,11 +70,6 @@
|
||||||
order by d.parent_id, d.order_num
|
order by d.parent_id, d.order_num
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectDeptById" parameterType="Long" resultMap="SysDeptResult">
|
|
||||||
<include refid="selectDeptVo"/>
|
|
||||||
where dept_id = #{deptId}
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="checkDeptExistUser" parameterType="Long" resultType="int">
|
<select id="checkDeptExistUser" parameterType="Long" resultType="int">
|
||||||
select count(1)
|
select count(1)
|
||||||
from sys_user
|
from sys_user
|
||||||
|
@ -90,12 +85,6 @@
|
||||||
limit 1
|
limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectChildrenDeptById" parameterType="Long" resultMap="SysDeptResult">
|
|
||||||
select *
|
|
||||||
from sys_dept
|
|
||||||
where find_in_set(#{deptId}, ancestors)
|
|
||||||
</select>
|
|
||||||
|
|
||||||
<select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
|
<select id="selectNormalChildrenDeptById" parameterType="Long" resultType="int">
|
||||||
select count(*)
|
select count(*)
|
||||||
from sys_dept
|
from sys_dept
|
||||||
|
|
Loading…
Reference in New Issue