feat():部门相关内容使用mybatis-plus处理
parent
443667ef04
commit
23a50b66db
|
@ -8,6 +8,7 @@ import java.math.RoundingMode;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -278,6 +279,16 @@ public class Convert {
|
||||||
public static Long[] toLongArray (String str) {
|
public static Long[] toLongArray (String str) {
|
||||||
return toLongArray(",", str);
|
return toLongArray(",", str);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 转换为Long数组<br>
|
||||||
|
*
|
||||||
|
* @param str 被转换的值
|
||||||
|
*
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public static List<Long> toLongList (String str) {
|
||||||
|
return List.of(toLongArray(",", str));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换为Integer数组<br>
|
* 转换为Integer数组<br>
|
||||||
|
|
|
@ -99,7 +99,8 @@ public class SysDeptController extends BaseController {
|
||||||
return error("该部门包含未停用的子部门!");
|
return error("该部门包含未停用的子部门!");
|
||||||
}
|
}
|
||||||
dept.setUpdateBy(SecurityUtils.getUsername());
|
dept.setUpdateBy(SecurityUtils.getUsername());
|
||||||
return toAjax(deptService.updateDept(dept));
|
deptService.updateDept(dept);
|
||||||
|
return success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -70,24 +70,6 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
|
||||||
*/
|
*/
|
||||||
public SysDept checkDeptNameUnique (@Param("deptName") String deptName, @Param("parentId") Long parentId);
|
public SysDept checkDeptNameUnique (@Param("deptName") String deptName, @Param("parentId") Long parentId);
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增部门信息
|
|
||||||
*
|
|
||||||
* @param dept 部门信息
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int insertDept (SysDept dept);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改部门信息
|
|
||||||
*
|
|
||||||
* @param dept 部门信息
|
|
||||||
*
|
|
||||||
* @return 结果
|
|
||||||
*/
|
|
||||||
public int updateDept (SysDept dept);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改所在部门正常状态
|
* 修改所在部门正常状态
|
||||||
*
|
*
|
||||||
|
|
|
@ -124,7 +124,7 @@ public interface SysDeptService extends IService<SysDept> {
|
||||||
*
|
*
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int updateDept (SysDept dept);
|
public void updateDept (SysDept dept);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除部门管理信息
|
* 删除部门管理信息
|
||||||
|
|
|
@ -199,15 +199,13 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
Assert.notNull(checkDeptNameUniqueModel.getDeptName(), "部门名称不可为空");
|
Assert.notNull(checkDeptNameUniqueModel.getDeptName(), "部门名称不可为空");
|
||||||
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.eq(SysDept::getDeptName, checkDeptNameUniqueModel.getDeptName());
|
queryWrapper.eq(SysDept::getDeptName, checkDeptNameUniqueModel.getDeptName());
|
||||||
|
// 若不传入部门ID则查询内容为所有部门不唯一
|
||||||
queryWrapper.eq(Objects.nonNull(checkDeptNameUniqueModel.getParentDeptId()), SysDept::getParentId, checkDeptNameUniqueModel.getParentDeptId());
|
queryWrapper.eq(Objects.nonNull(checkDeptNameUniqueModel.getParentDeptId()), SysDept::getParentId, checkDeptNameUniqueModel.getParentDeptId());
|
||||||
|
//部门的状态必须为正常才可进行判断
|
||||||
queryWrapper.eq(SysDept::getStatus, SysDelFlag.EXIST.getCode());
|
queryWrapper.eq(SysDept::getStatus, SysDelFlag.EXIST.getCode());
|
||||||
|
// 如果存在传入的部门则校验除了当前部门之外的其他部门
|
||||||
Long deptId = StringUtils.isNull(checkDeptNameUniqueModel.getDeptId()) ? -1L : checkDeptNameUniqueModel.getDeptId();
|
queryWrapper.ne(Objects.nonNull(checkDeptNameUniqueModel.getDeptId()),SysDept::getDeptId, checkDeptNameUniqueModel.getDeptId());
|
||||||
SysDept info = deptMapper.checkDeptNameUnique(checkDeptNameUniqueModel.getDeptName(), checkDeptNameUniqueModel.getParentDeptId());
|
return this.count(queryWrapper) == 0 ? UserConstants.NOT_UNIQUE : UserConstants.UNIQUE;
|
||||||
if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) {
|
|
||||||
return UserConstants.NOT_UNIQUE;
|
|
||||||
}
|
|
||||||
return UserConstants.UNIQUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -252,7 +250,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int updateDept (SysDept dept) {
|
public void updateDept (SysDept dept) {
|
||||||
SysDept newParentDept = this.getById(dept.getParentId());
|
SysDept newParentDept = this.getById(dept.getParentId());
|
||||||
SysDept oldDept = this.getById(dept.getDeptId());
|
SysDept oldDept = this.getById(dept.getDeptId());
|
||||||
if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) {
|
if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) {
|
||||||
|
@ -261,13 +259,12 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
dept.setAncestors(newAncestors);
|
dept.setAncestors(newAncestors);
|
||||||
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
|
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
|
||||||
}
|
}
|
||||||
int result = deptMapper.updateDept(dept);
|
this.updateById(dept);
|
||||||
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
|
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
|
||||||
&& !StringUtils.equals("0", dept.getAncestors())) {
|
&& !StringUtils.equals("0", dept.getAncestors())) {
|
||||||
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
// 如果该部门是启用状态,则启用该部门的所有上级部门
|
||||||
updateParentDeptStatusNormal(dept);
|
updateParentDeptStatusNormal(dept);
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -277,8 +274,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
*/
|
*/
|
||||||
private void updateParentDeptStatusNormal (SysDept dept) {
|
private void updateParentDeptStatusNormal (SysDept dept) {
|
||||||
String ancestors = dept.getAncestors();
|
String ancestors = dept.getAncestors();
|
||||||
Long[] deptIds = Convert.toLongArray(ancestors);
|
List<Long> deptIdList = Convert.toLongList(ancestors);
|
||||||
deptMapper.updateDeptStatusNormal(deptIds);
|
LambdaUpdateWrapper<SysDept> updateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
updateWrapper.set(SysDept::getStatus, SysNormalDisable.ENABLE.getCode());
|
||||||
|
updateWrapper.in(SysDept::getDeptId, deptIdList);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -332,14 +331,14 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
/**
|
/**
|
||||||
* 得到子节点列表
|
* 得到子节点列表
|
||||||
*/
|
*/
|
||||||
private List<SysDept> getChildList (List<SysDept> list, SysDept t) {
|
private List<SysDept> getChildList (List<SysDept> list, SysDept parentSysDept) {
|
||||||
List<SysDept> tlist = new ArrayList<SysDept>();
|
List<SysDept> childSysDeptList = new ArrayList<>();
|
||||||
for (SysDept n : list) {
|
for (SysDept childSysDept : list) {
|
||||||
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) {
|
if (StringUtils.isNotNull(childSysDept.getParentId()) && childSysDept.getParentId().longValue() == parentSysDept.getDeptId().longValue()) {
|
||||||
tlist.add(n);
|
childSysDeptList.add(childSysDept);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tlist;
|
return childSysDeptList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -356,6 +355,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
|
||||||
*
|
*
|
||||||
* @return 部门列表
|
* @return 部门列表
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public List<SysDept> selectChildrenDeptById (Long deptId){
|
public List<SysDept> selectChildrenDeptById (Long deptId){
|
||||||
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
queryWrapper.apply("FIND_IN_SET('" + deptId + "', type)");
|
queryWrapper.apply("FIND_IN_SET('" + deptId + "', type)");
|
||||||
|
|
|
@ -98,51 +98,6 @@
|
||||||
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
|
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<insert id="insertDept" parameterType="com.muyu.common.system.domain.SysDept">
|
|
||||||
insert into sys_dept(
|
|
||||||
<if test="deptId != null and deptId != 0">dept_id,</if>
|
|
||||||
<if test="parentId != null and parentId != 0">parent_id,</if>
|
|
||||||
<if test="deptName != null and deptName != ''">dept_name,</if>
|
|
||||||
<if test="ancestors != null and ancestors != ''">ancestors,</if>
|
|
||||||
<if test="orderNum != null">order_num,</if>
|
|
||||||
<if test="leader != null and leader != ''">leader,</if>
|
|
||||||
<if test="phone != null and phone != ''">phone,</if>
|
|
||||||
<if test="email != null and email != ''">email,</if>
|
|
||||||
<if test="status != null">status,</if>
|
|
||||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
|
||||||
create_time
|
|
||||||
)values(
|
|
||||||
<if test="deptId != null and deptId != 0">#{deptId},</if>
|
|
||||||
<if test="parentId != null and parentId != 0">#{parentId},</if>
|
|
||||||
<if test="deptName != null and deptName != ''">#{deptName},</if>
|
|
||||||
<if test="ancestors != null and ancestors != ''">#{ancestors},</if>
|
|
||||||
<if test="orderNum != null">#{orderNum},</if>
|
|
||||||
<if test="leader != null and leader != ''">#{leader},</if>
|
|
||||||
<if test="phone != null and phone != ''">#{phone},</if>
|
|
||||||
<if test="email != null and email != ''">#{email},</if>
|
|
||||||
<if test="status != null">#{status},</if>
|
|
||||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
|
||||||
sysdate()
|
|
||||||
)
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
<update id="updateDept" parameterType="com.muyu.common.system.domain.SysDept">
|
|
||||||
update sys_dept
|
|
||||||
<set>
|
|
||||||
<if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
|
|
||||||
<if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
|
|
||||||
<if test="ancestors != null and ancestors != ''">ancestors = #{ancestors},</if>
|
|
||||||
<if test="orderNum != null">order_num = #{orderNum},</if>
|
|
||||||
<if test="leader != null">leader = #{leader},</if>
|
|
||||||
<if test="phone != null">phone = #{phone},</if>
|
|
||||||
<if test="email != null">email = #{email},</if>
|
|
||||||
<if test="status != null and status != ''">status = #{status},</if>
|
|
||||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
|
||||||
update_time = sysdate()
|
|
||||||
</set>
|
|
||||||
where dept_id = #{deptId}
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<update id="updateDeptChildren" parameterType="java.util.List">
|
<update id="updateDeptChildren" parameterType="java.util.List">
|
||||||
update sys_dept set ancestors =
|
update sys_dept set ancestors =
|
||||||
<foreach collection="depts" item="item" index="index"
|
<foreach collection="depts" item="item" index="index"
|
||||||
|
|
Loading…
Reference in New Issue