feat():部门相关内容使用mybatis-plus处理

boot3.0
dongzeliang 2025-01-19 00:01:31 +08:00
parent 443667ef04
commit 23a50b66db
6 changed files with 32 additions and 83 deletions

View File

@ -8,6 +8,7 @@ import java.math.RoundingMode;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.text.NumberFormat;
import java.util.List;
import java.util.Set;
/**
@ -278,6 +279,16 @@ public class Convert {
public static Long[] toLongArray (String str) {
return toLongArray(",", str);
}
/**
* Long<br>
*
* @param str
*
* @return
*/
public static List<Long> toLongList (String str) {
return List.of(toLongArray(",", str));
}
/**
* Integer<br>

View File

@ -99,7 +99,8 @@ public class SysDeptController extends BaseController {
return error("该部门包含未停用的子部门!");
}
dept.setUpdateBy(SecurityUtils.getUsername());
return toAjax(deptService.updateDept(dept));
deptService.updateDept(dept);
return success();
}
/**

View File

@ -70,24 +70,6 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
*/
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);
/**
*
*

View File

@ -124,7 +124,7 @@ public interface SysDeptService extends IService<SysDept> {
*
* @return
*/
public int updateDept (SysDept dept);
public void updateDept (SysDept dept);
/**
*

View File

@ -199,15 +199,13 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
Assert.notNull(checkDeptNameUniqueModel.getDeptName(), "部门名称不可为空");
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysDept::getDeptName, checkDeptNameUniqueModel.getDeptName());
// 若不传入部门ID则查询内容为所有部门不唯一
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()) {
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
// 如果存在传入的部门则校验除了当前部门之外的其他部门
queryWrapper.ne(Objects.nonNull(checkDeptNameUniqueModel.getDeptId()),SysDept::getDeptId, checkDeptNameUniqueModel.getDeptId());
return this.count(queryWrapper) == 0 ? UserConstants.NOT_UNIQUE : UserConstants.UNIQUE;
}
/**
@ -252,7 +250,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
* @return
*/
@Override
public int updateDept (SysDept dept) {
public void updateDept (SysDept dept) {
SysDept newParentDept = this.getById(dept.getParentId());
SysDept oldDept = this.getById(dept.getDeptId());
if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept)) {
@ -261,13 +259,12 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
dept.setAncestors(newAncestors);
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
}
int result = deptMapper.updateDept(dept);
this.updateById(dept);
if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
&& !StringUtils.equals("0", dept.getAncestors())) {
// 如果该部门是启用状态,则启用该部门的所有上级部门
updateParentDeptStatusNormal(dept);
}
return result;
}
/**
@ -277,8 +274,10 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
*/
private void updateParentDeptStatusNormal (SysDept dept) {
String ancestors = dept.getAncestors();
Long[] deptIds = Convert.toLongArray(ancestors);
deptMapper.updateDeptStatusNormal(deptIds);
List<Long> deptIdList = Convert.toLongList(ancestors);
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) {
List<SysDept> tlist = new ArrayList<SysDept>();
for (SysDept n : list) {
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) {
tlist.add(n);
private List<SysDept> getChildList (List<SysDept> list, SysDept parentSysDept) {
List<SysDept> childSysDeptList = new ArrayList<>();
for (SysDept childSysDept : list) {
if (StringUtils.isNotNull(childSysDept.getParentId()) && childSysDept.getParentId().longValue() == parentSysDept.getDeptId().longValue()) {
childSysDeptList.add(childSysDept);
}
}
return tlist;
return childSysDeptList;
}
/**
@ -356,6 +355,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
*
* @return
*/
@Override
public List<SysDept> selectChildrenDeptById (Long deptId){
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.apply("FIND_IN_SET('" + deptId + "', type)");

View File

@ -98,51 +98,6 @@
where dept_name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
</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 sys_dept set ancestors =
<foreach collection="depts" item="item" index="index"