【添加】添加接口 1、根据部门id查询部门所有的父级(不包含自己)2、根据部门id查询部门所有的子级(不包含自己)
This commit is contained in:
+21
-5
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
* <p>
|
||||
* 部门表 服务实现类
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
* @Author:Steve
|
||||
* @Since: 2019-01-22
|
||||
*/
|
||||
@@ -46,28 +46,28 @@ public interface ISysDepartService extends IService<SysDepart>{
|
||||
* @return
|
||||
*/
|
||||
Boolean updateDepartDataById(SysDepart sysDepart,String username);
|
||||
|
||||
|
||||
/**
|
||||
* 删除depart数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
/* boolean removeDepartDataById(String id); */
|
||||
|
||||
|
||||
/**
|
||||
* 根据关键字搜索相关的部门数据
|
||||
* @param keyWord
|
||||
* @return
|
||||
*/
|
||||
List<SysDepartTreeModel> searhBy(String keyWord,String myDeptSearch,String departIds);
|
||||
|
||||
|
||||
/**
|
||||
* 根据部门id删除并删除其可能存在的子级部门
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
boolean delete(String id);
|
||||
|
||||
|
||||
/**
|
||||
* 查询SysDepart集合
|
||||
* @param userId
|
||||
@@ -107,4 +107,20 @@ public interface ISysDepartService extends IService<SysDepart>{
|
||||
* @return
|
||||
*/
|
||||
List<SysDepartTreeModel> queryTreeByKeyWord(String keyWord);
|
||||
|
||||
/**
|
||||
* 根据部门id查询部门所有的父级(不包含自己)
|
||||
* @author 马志朝
|
||||
* @date 2021/3/24 8:50
|
||||
* @param departId 部门id
|
||||
*/
|
||||
List<SysDepartTreeModel> listParentDepartsByDepId(String departId);
|
||||
|
||||
/**
|
||||
* 根据部门id查询部门所有的子级(不包含自己)
|
||||
* @author 马志朝
|
||||
* @date 2021/3/24 8:54
|
||||
* @param departId 部门id
|
||||
*/
|
||||
List<SysDepartTreeModel> listSonDepartsByDepId(String departId);
|
||||
}
|
||||
|
||||
+28
-2
@@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.jero.modules.system.model.SysDepartTreeModel;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
@@ -846,7 +847,7 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||
|
||||
/**
|
||||
* 36根据多个用户账号(逗号分隔),查询返回多个用户信息
|
||||
* @param orgCodes
|
||||
* @param usernames
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@@ -865,7 +866,7 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||
|
||||
/**
|
||||
* 37根据多个部门编码(逗号分隔),查询返回多个部门信息
|
||||
* @param usernames
|
||||
* @param orgCodes
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@@ -991,4 +992,29 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||
emailHandle.SendMsg(email, title, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门id查询部门所有的父级(不包含自己)
|
||||
* @author 马志朝
|
||||
* @date 2021/3/24 8:50
|
||||
* @param departId 部门id
|
||||
* @return JSONObject
|
||||
*/
|
||||
@Override
|
||||
public List<JSONObject> listParentDepartsByDepId(String departId) {
|
||||
List<SysDepartTreeModel> sysDepartTreeModels = sysDepartService.listParentDepartsByDepId(departId);
|
||||
return JSON.parseArray(JSON.toJSONString(sysDepartTreeModels)).toJavaList(JSONObject.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 42根据部门id查询部门所有的子级(不包含自己)
|
||||
* @author 马志朝
|
||||
* @date 2021/3/24 8:54
|
||||
* @param departId 部门id
|
||||
* @return JSONObject
|
||||
*/
|
||||
@Override
|
||||
public List<JSONObject> listSonDepartsByDepId(String departId) {
|
||||
List<SysDepartTreeModel> sysDepartTreeModels = sysDepartService.listSonDepartsByDepId(departId);
|
||||
return JSON.parseArray(JSON.toJSONString(sysDepartTreeModels)).toJavaList(JSONObject.class);
|
||||
}
|
||||
}
|
||||
+67
-11
@@ -30,7 +30,7 @@ import io.netty.util.internal.StringUtil;
|
||||
* <p>
|
||||
* 部门表 服务实现类
|
||||
* <p>
|
||||
*
|
||||
*
|
||||
* @Author Steve
|
||||
* @Since 2019-01-22
|
||||
*/
|
||||
@@ -130,14 +130,14 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* saveDepartData 的调用方法,生成部门编码和部门类型(作废逻辑)
|
||||
* @deprecated
|
||||
* @param parentId
|
||||
* @return
|
||||
*/
|
||||
private String[] generateOrgCode(String parentId) {
|
||||
private String[] generateOrgCode(String parentId) {
|
||||
//update-begin--Author:Steve Date:20190201 for:组织机构添加数据代码调整
|
||||
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
|
||||
LambdaQueryWrapper<SysDepart> query1 = new LambdaQueryWrapper<SysDepart>();
|
||||
@@ -195,16 +195,16 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
|
||||
strArray[1] = orgType;
|
||||
return strArray;
|
||||
//update-end--Author:Steve Date:20190201 for:组织机构添加数据代码调整
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* removeDepartDataById 对应 delete方法 根据ID删除相关部门数据
|
||||
*
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* @Override
|
||||
*
|
||||
*
|
||||
* @Transactional public boolean removeDepartDataById(String id) {
|
||||
* System.out.println("要删除的ID 为=============================>>>>>"+id); boolean
|
||||
* flag = this.removeById(id); return flag; }
|
||||
@@ -226,7 +226,7 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteBatchWithChildren(List<String> ids) {
|
||||
@@ -342,13 +342,13 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* delete 方法调用
|
||||
* @param id
|
||||
* @param idList
|
||||
*/
|
||||
private void checkChildrenExists(String id, List<String> idList) {
|
||||
private void checkChildrenExists(String id, List<String> idList) {
|
||||
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
|
||||
query.eq(SysDepart::getParentId,id);
|
||||
List<SysDepart> departList = this.list(query);
|
||||
@@ -454,7 +454,8 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
|
||||
}
|
||||
return treelist;
|
||||
}
|
||||
/**
|
||||
|
||||
/**
|
||||
* 根据关键字筛选部门信息
|
||||
* @param keyWord
|
||||
* @return
|
||||
@@ -469,4 +470,59 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 根据部门id查询部门所有的父级(不包含自己)
|
||||
* @author 马志朝
|
||||
* @date 2021/3/24 9:10
|
||||
* @param departId 部门id
|
||||
* @return java.util.List<com.jero.modules.system.entity.SysDepart>
|
||||
*/
|
||||
@Override
|
||||
public List<SysDepartTreeModel> listParentDepartsByDepId(String departId) {
|
||||
List<SysDepart> list = new ArrayList<>();
|
||||
SysDepart depart = this.getById(departId);
|
||||
String parentId = depart.getParentId();
|
||||
// 查询父部门
|
||||
SysDepart parentDepart = this.getById(parentId);
|
||||
while (parentDepart != null){
|
||||
list.add(parentDepart);
|
||||
parentId = parentDepart.getParentId();
|
||||
parentDepart = this.getById(parentId);
|
||||
}
|
||||
Collections.reverse(list);
|
||||
// 调用wrapTreeDataToTreeList方法生成树状数据
|
||||
return FindsDepartsChildrenUtil.wrapTreeDataToTreeList(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门id查询部门所有的子级(不包含自己)
|
||||
* @author 马志朝
|
||||
* @date 2021/3/24 9:11
|
||||
* @param departId 部门id
|
||||
* @return java.util.List<com.jero.modules.system.entity.SysDepart>
|
||||
*/
|
||||
@Override
|
||||
public List<SysDepartTreeModel> listSonDepartsByDepId(String departId) {
|
||||
List<SysDepartTreeModel> realResult = new ArrayList<>();
|
||||
LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();
|
||||
//获取直接子节点
|
||||
List<SysDepart> sonDepartList = this.list(queryWrapper.eq(SysDepart::getParentId, departId));
|
||||
for(SysDepart depart : sonDepartList){
|
||||
String tempId = depart.getId();
|
||||
List<SysDepart> listResult = new ArrayList<>();
|
||||
// 将每个直接子节点的parentId设为空来构成树的头节点
|
||||
depart.setParentId(null);
|
||||
listResult.add(depart);
|
||||
List<String> idListTemp = new ArrayList<>();
|
||||
this.checkChildrenExists(tempId, idListTemp);
|
||||
idListTemp.forEach(id -> {
|
||||
SysDepart sysDepartTemp = this.getById(id);
|
||||
listResult.add(sysDepartTemp);
|
||||
});
|
||||
List<SysDepartTreeModel> sysDepartTreeModels = FindsDepartsChildrenUtil.wrapTreeDataToTreeList(listResult);
|
||||
realResult.addAll(sysDepartTreeModels);
|
||||
}
|
||||
|
||||
return realResult;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user