From 6fe3274649d033bdb9dfef51799c3930b2c98c04 Mon Sep 17 00:00:00 2001 From: Gitea Date: Sun, 10 Nov 2024 14:18:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E6=96=B0=E5=88=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jeecg/config/shiro/ShiroConfig.java | 5 +- .../controller/SysDepartController.java | 28 + .../system/service/ISysDepartService.java | 9 +- .../service/impl/SysDepartServiceImpl.java | 595 ++++++++++-------- jeecgboot-vue3/src/api/common/api.ts | 8 + .../jeecg/components/JSelectDept4FaRen.vue | 207 ++++++ .../modal/DeptSelectModal4FaRen.vue | 131 ++++ .../system/loginmini/MiniRegister4faren.vue | 3 +- 8 files changed, 706 insertions(+), 280 deletions(-) create mode 100644 jeecgboot-vue3/src/components/Form/src/jeecg/components/JSelectDept4FaRen.vue create mode 100644 jeecgboot-vue3/src/components/Form/src/jeecg/components/modal/DeptSelectModal4FaRen.vue diff --git a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java index 687f96f..9501820 100644 --- a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java +++ b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java @@ -177,7 +177,10 @@ public class ShiroConfig { filterChainDefinitionMap.put("/sys/user/userRegister4Faren", "anon"); //法人注册接口 filterChainDefinitionMap.put("/sys/user/userRegister4Shenbaoren", "anon");//申报人注册 - filterChainDefinitionMap.put("/sys/sysDepart/queryDepartTreeSync", "anon");//申报人用户注册 + + filterChainDefinitionMap.put("/sys/sysDepart/queryDepartTreeSync", "anon");//申报人注册时,选择部门列表 + + filterChainDefinitionMap.put("/sys/sysDepart/queryDepartTreeSync4FaRen", "anon");//法人注册时,选择部门列表 diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysDepartController.java b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysDepartController.java index 836fa6f..384ecc6 100644 --- a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysDepartController.java +++ b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysDepartController.java @@ -44,6 +44,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.*; +import java.util.stream.Collectors; /** *

@@ -170,6 +171,33 @@ public class SysDepartController { return result; } + /** + * @description: 法人注册时,只显示市和县区科技局,不显示下属单位 + * @param: [parentId, ids, primaryKey] + * @return: org.jeecg.common.api.vo.Result> + * @author: z.h.c + * @date: 24/11/9 16:07 + */ + @RequestMapping(value = "/queryDepartTreeSync4FaRen", method = RequestMethod.GET) + public Result> queryDepartTreeSync4FaRen(@RequestParam(name = "pid", required = false) String parentId, + @RequestParam(name = "ids", required = false) String ids, + @RequestParam(name = "primaryKey", required = false) String primaryKey) { + Result> result = new Result<>(); + try { +// parentId = "1839495887972130817"; + List sysDeparts = sysDepartService.list(new LambdaQueryWrapper().eq(SysDepart::getParentId, "1839495887972130817")); + ids = Optional.ofNullable(sysDeparts).orElse(new LinkedList<>()).stream().map(e -> e.getId()).collect(Collectors.joining(",")); + List list = sysDepartService.queryTreeListByPid4FaRen(parentId, ids, primaryKey); + result.setResult(list); + result.setSuccess(true); + } catch (Exception e) { + log.error(e.getMessage(), e); + result.setSuccess(false); + result.setMessage("查询失败"); + } + return result; + } + /** * 获取某个部门的所有父级部门的ID * diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysDepartService.java b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysDepartService.java index 95503a8..132b24f 100644 --- a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysDepartService.java +++ b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysDepartService.java @@ -73,7 +73,7 @@ public interface ISysDepartService extends IService{ * @param id * @return */ - /* boolean removeDepartDataById(String id); */ + /* boolean removeDepartDataById(String id); */ /** * 根据关键字搜索相关的部门数据 @@ -96,7 +96,7 @@ public interface ISysDepartService extends IService{ * @param userId * @return */ - public List queryUserDeparts(String userId); + public List queryUserDeparts(String userId); /** * 根据用户名查询部门 @@ -114,12 +114,12 @@ public interface ISysDepartService extends IService{ */ List queryDepartsByUserId(String userId); - /** + /** * 根据部门id批量删除并删除其可能存在的子级部门 * @param ids 多个部门id * @return */ - void deleteBatchWithChildren(List ids); + void deleteBatchWithChildren(List ids); /** * 根据部门Id查询,当前和下级所有部门IDS @@ -148,6 +148,7 @@ public interface ISysDepartService extends IService{ * @return */ List queryTreeListByPid(String parentId,String ids, String primaryKey); + List queryTreeListByPid4FaRen(String parentId,String ids, String primaryKey); /** * 获取某个部门的所有父级部门的ID diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java index 279ad83..79f0c3a 100644 --- a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java +++ b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java @@ -119,10 +119,10 @@ public class SysDepartServiceImpl extends ServiceImpl list = this.list(query); - //update-begin---author:wangshuai ---date:20220307 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理 + //update-begin---author:wangshuai ---date:20220307 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理 //设置用户id,让前台显示 - this.setUserIdsByDepList(list); - //update-begin---author:wangshuai ---date:20220307 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理 + this.setUserIdsByDepList(list); + //update-begin---author:wangshuai ---date:20220307 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理 // 调用wrapTreeDataToTreeList方法生成树状数据 List listResult = FindsDepartsChildrenUtil.wrapTreeDataToTreeList(list); return listResult; @@ -215,13 +215,13 @@ public class SysDepartServiceImpl extends ServiceImpl query = new LambdaQueryWrapper(); - LambdaQueryWrapper query1 = new LambdaQueryWrapper(); - String[] strArray = new String[2]; - // 创建一个List集合,存储查询返回的所有SysDepart对象 - List departList = new ArrayList<>(); - // 定义新编码字符串 - String newOrgCode = ""; - // 定义旧编码字符串 - String oldOrgCode = ""; - // 定义部门类型 - String orgType = ""; - // 如果是最高级,则查询出同级的org_code, 调用工具类生成编码并返回 - if (StringUtil.isNullOrEmpty(parentId)) { - // 线判断数据库中的表是否为空,空则直接返回初始编码 - query1.eq(SysDepart::getParentId, "").or().isNull(SysDepart::getParentId); - query1.orderByDesc(SysDepart::getOrgCode); - departList = this.list(query1); - if(departList == null || departList.size() == 0) { - strArray[0] = YouBianCodeUtil.getNextYouBianCode(null); - strArray[1] = "1"; - return strArray; - }else { - SysDepart depart = departList.get(0); - oldOrgCode = depart.getOrgCode(); - orgType = depart.getOrgType(); - newOrgCode = YouBianCodeUtil.getNextYouBianCode(oldOrgCode); - } - } else { // 反之则查询出所有同级的部门,获取结果后有两种情况,有同级和没有同级 - // 封装查询同级的条件 - query.eq(SysDepart::getParentId, parentId); - // 降序排序 - query.orderByDesc(SysDepart::getOrgCode); - // 查询出同级部门的集合 - List parentList = this.list(query); - // 查询出父级部门 - SysDepart depart = this.getById(parentId); - // 获取父级部门的Code - String parentCode = depart.getOrgCode(); - // 根据父级部门类型算出当前部门的类型 - orgType = String.valueOf(Integer.valueOf(depart.getOrgType()) + 1); - // 处理同级部门为null的情况 - if (parentList == null || parentList.size() == 0) { - // 直接生成当前的部门编码并返回 - newOrgCode = YouBianCodeUtil.getSubYouBianCode(parentCode, null); - } else { //处理有同级部门的情况 - // 获取同级部门的编码,利用工具类 - String subCode = parentList.get(0).getOrgCode(); - // 返回生成的当前部门编码 - newOrgCode = YouBianCodeUtil.getSubYouBianCode(parentCode, subCode); - } - } - // 返回最终封装了部门编码和部门类型的数组 - strArray[0] = newOrgCode; - strArray[1] = orgType; + LambdaQueryWrapper query = new LambdaQueryWrapper(); + LambdaQueryWrapper query1 = new LambdaQueryWrapper(); + String[] strArray = new String[2]; + // 创建一个List集合,存储查询返回的所有SysDepart对象 + List departList = new ArrayList<>(); + // 定义新编码字符串 + String newOrgCode = ""; + // 定义旧编码字符串 + String oldOrgCode = ""; + // 定义部门类型 + String orgType = ""; + // 如果是最高级,则查询出同级的org_code, 调用工具类生成编码并返回 + if (StringUtil.isNullOrEmpty(parentId)) { + // 线判断数据库中的表是否为空,空则直接返回初始编码 + query1.eq(SysDepart::getParentId, "").or().isNull(SysDepart::getParentId); + query1.orderByDesc(SysDepart::getOrgCode); + departList = this.list(query1); + if(departList == null || departList.size() == 0) { + strArray[0] = YouBianCodeUtil.getNextYouBianCode(null); + strArray[1] = "1"; return strArray; + }else { + SysDepart depart = departList.get(0); + oldOrgCode = depart.getOrgCode(); + orgType = depart.getOrgType(); + newOrgCode = YouBianCodeUtil.getNextYouBianCode(oldOrgCode); + } + } else { // 反之则查询出所有同级的部门,获取结果后有两种情况,有同级和没有同级 + // 封装查询同级的条件 + query.eq(SysDepart::getParentId, parentId); + // 降序排序 + query.orderByDesc(SysDepart::getOrgCode); + // 查询出同级部门的集合 + List parentList = this.list(query); + // 查询出父级部门 + SysDepart depart = this.getById(parentId); + // 获取父级部门的Code + String parentCode = depart.getOrgCode(); + // 根据父级部门类型算出当前部门的类型 + orgType = String.valueOf(Integer.valueOf(depart.getOrgType()) + 1); + // 处理同级部门为null的情况 + if (parentList == null || parentList.size() == 0) { + // 直接生成当前的部门编码并返回 + newOrgCode = YouBianCodeUtil.getSubYouBianCode(parentCode, null); + } else { //处理有同级部门的情况 + // 获取同级部门的编码,利用工具类 + String subCode = parentList.get(0).getOrgCode(); + // 返回生成的当前部门编码 + newOrgCode = YouBianCodeUtil.getSubYouBianCode(parentCode, subCode); + } + } + // 返回最终封装了部门编码和部门类型的数组 + strArray[0] = newOrgCode; + strArray[1] = orgType; + return strArray; //update-end--Author:Steve Date:20190201 for:组织机构添加数据代码调整 } @@ -314,10 +314,10 @@ public class SysDepartServiceImpl extends ServiceImpl queryTreeByKeyWord(String keyWord) { - LambdaQueryWrapper query = new LambdaQueryWrapper(); - query.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString()); - query.orderByAsc(SysDepart::getDepartOrder); - List list = this.list(query); - // 调用wrapTreeDataToTreeList方法生成树状数据 - List listResult = FindsDepartsChildrenUtil.wrapTreeDataToTreeList(list); - List treelist =new ArrayList<>(); - if(StringUtils.isNotBlank(keyWord)){ - this.getTreeByKeyWord(keyWord,listResult,treelist); - }else{ - return listResult; - } - return treelist; - } + /** + * 获取部门树信息根据关键字 + * @param keyWord + * @return + */ + @Override + public List queryTreeByKeyWord(String keyWord) { + LambdaQueryWrapper query = new LambdaQueryWrapper(); + query.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString()); + query.orderByAsc(SysDepart::getDepartOrder); + List list = this.list(query); + // 调用wrapTreeDataToTreeList方法生成树状数据 + List listResult = FindsDepartsChildrenUtil.wrapTreeDataToTreeList(list); + List treelist =new ArrayList<>(); + if(StringUtils.isNotBlank(keyWord)){ + this.getTreeByKeyWord(keyWord,listResult,treelist); + }else{ + return listResult; + } + return treelist; + } /** * 根据parentId查询部门树 @@ -626,22 +626,69 @@ public class SysDepartServiceImpl extends ServiceImpl list = list(lqw); + //update-begin---author:wangshuai ---date:20220316 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理 + //设置用户id,让前台显示 + this.setUserIdsByDepList(list); + //update-end---author:wangshuai ---date:20220316 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理 + List records = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + SysDepart depart = list.get(i); + SysDepartTreeModel treeModel = new SysDepartTreeModel(depart); + //TODO 异步树加载key拼接__+时间戳,以便于每次展开节点会刷新数据 + //treeModel.setKey(treeModel.getKey()+"__"+System.currentTimeMillis()); + records.add(treeModel); + } + return records; + } + + public List queryTreeListByPid4FaRen(String parentId,String ids, String primaryKey) { + /*Consumer> square = i -> { + if (oConvertUtils.isNotEmpty(ids)) { + if (CommonConstant.DEPART_KEY_ORG_CODE.equals(primaryKey)) { + i.in(SysDepart::getOrgCode, ids.split(SymbolConstant.COMMA)); + } else { + i.in(SysDepart::getId, ids.split(SymbolConstant.COMMA)); + } + } else { + if(oConvertUtils.isEmpty(parentId)){ + i.and(q->q.isNull(true,SysDepart::getParentId).or().eq(true,SysDepart::getParentId,"")); + }else{ + i.eq(true,SysDepart::getParentId,parentId); + } + } + };*/ + LambdaQueryWrapper lqw=new LambdaQueryWrapper<>(); + + lqw.in(SysDepart::getId,ids.split(SymbolConstant.COMMA)); +// i.in(SysDepart::getOrgCode, ids.split(SymbolConstant.COMMA)); + //------------------------------------------------------------------------------------------------ + //是否开启系统管理模块的 SASS 控制 + /*if(MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL){ + lqw.eq(SysDepart::getTenantId, oConvertUtils.getInt(TenantContext.getTenant(), 0)); + }*/ + //------------------------------------------------------------------------------------------------ + lqw.eq(true,SysDepart::getDelFlag,CommonConstant.DEL_FLAG_0.toString()); +// lqw.func(square); + //update-begin---author:wangshuai ---date:20220527 for:[VUEN-1143]排序不对,vue3和2应该都有问题,应该按照升序排------------ lqw.orderByAsc(SysDepart::getDepartOrder); - //update-end---author:wangshuai ---date:20220527 for:[VUEN-1143]排序不对,vue3和2应该都有问题,应该按照升序排-------------- + //update-end---author:wangshuai ---date:20220527 for:[VUEN-1143]排序不对,vue3和2应该都有问题,应该按照升序排-------------- List list = list(lqw); - //update-begin---author:wangshuai ---date:20220316 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理 - //设置用户id,让前台显示 - this.setUserIdsByDepList(list); - //update-end---author:wangshuai ---date:20220316 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理 + //update-begin---author:wangshuai ---date:20220316 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理 + //设置用户id,让前台显示 +// this.setUserIdsByDepList(list); + //update-end---author:wangshuai ---date:20220316 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理 List records = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { SysDepart depart = list.get(i); - SysDepartTreeModel treeModel = new SysDepartTreeModel(depart); - //TODO 异步树加载key拼接__+时间戳,以便于每次展开节点会刷新数据 + SysDepartTreeModel treeModel = new SysDepartTreeModel(depart); + //TODO 异步树加载key拼接__+时间戳,以便于每次展开节点会刷新数据 //treeModel.setKey(treeModel.getKey()+"__"+System.currentTimeMillis()); - records.add(treeModel); - } + records.add(treeModel); + } return records; } @@ -713,183 +760,183 @@ public class SysDepartServiceImpl extends ServiceImpl allResult,List newResult){ - for (SysDepartTreeModel model:allResult) { - if (model.getDepartName().contains(keyWord)){ - newResult.add(model); - continue; - }else if(model.getChildren()!=null){ - getTreeByKeyWord(keyWord,model.getChildren(),newResult); - } - } - } - - //update-begin---author:wangshuai ---date:20200308 for:[JTC-119]在部门管理菜单下设置部门负责人,新增方法添加部门负责人、删除负责部门负责人、查询部门对应的负责人 - /** - * 通过用户id设置负责部门 - * @param sysDepart SysDepart部门对象 - * @param userIds 多个负责用户id - */ - public void addDepartByUserIds(SysDepart sysDepart, String userIds) { - //获取部门id,保存到用户 - String departId = sysDepart.getId(); - //循环用户id - String[] userIdArray = userIds.split(","); - for (String userId:userIdArray) { - //查询用户表增加负责部门 - SysUser sysUser = sysUserMapper.selectById(userId); - //如果部门id不为空,那么就需要拼接 - if(oConvertUtils.isNotEmpty(sysUser.getDepartIds())){ - if(!sysUser.getDepartIds().contains(departId)) { - sysUser.setDepartIds(sysUser.getDepartIds() + "," + departId); - } - }else{ - sysUser.setDepartIds(departId); - } - //设置身份为上级 - sysUser.setUserIdentity(CommonConstant.USER_IDENTITY_2); - //跟新用户表 - sysUserMapper.updateById(sysUser); - //判断当前用户是否包含所属部门 - List userDepartList = userDepartMapper.getUserDepartByUid(userId); - boolean isExistDepId = userDepartList.stream().anyMatch(item -> departId.equals(item.getDepId())); - //如果不存在需要设置所属部门 - if(!isExistDepId){ - userDepartMapper.insert(new SysUserDepart(userId,departId)); - } - } - } - - /** - * 修改用户负责部门 - * @param sysDepart SysDepart对象 - */ - private void updateChargeDepart(SysDepart sysDepart) { - //新的用户id - String directorIds = sysDepart.getDirectorUserIds(); - //旧的用户id(数据库中存在的) - String oldDirectorIds = sysDepart.getOldDirectorUserIds(); - String departId = sysDepart.getId(); - //如果用户id为空,那么用户的负责部门id应该去除 - if(oConvertUtils.isEmpty(directorIds)){ - this.deleteChargeDepId(departId,null); - }else if(oConvertUtils.isNotEmpty(directorIds) && oConvertUtils.isEmpty(oldDirectorIds)){ - //如果用户id不为空但是用户原来负责部门的用户id为空 - this.addDepartByUserIds(sysDepart,directorIds); - }else{ - //都不为空,需要比较,进行添加或删除 - //找到新的负责部门用户id与原来负责部门的用户id,进行删除 - List userIdList = Arrays.stream(oldDirectorIds.split(",")).filter(item -> !directorIds.contains(item)).collect(Collectors.toList()); - for (String userId:userIdList){ - this.deleteChargeDepId(departId,userId); - } - //找到原来负责部门的用户id与新的负责部门用户id,进行新增 - String addUserIds = Arrays.stream(directorIds.split(",")).filter(item -> !oldDirectorIds.contains(item)).collect(Collectors.joining(",")); - if(oConvertUtils.isNotEmpty(addUserIds)){ - this.addDepartByUserIds(sysDepart,addUserIds); - } - } - } - - /** - * 删除用户负责部门 - * @param departId 部门id - * @param userId 用户id - */ - private void deleteChargeDepId(String departId,String userId){ - //先查询负责部门的用户id,因为负责部门的id使用逗号拼接起来的 - LambdaQueryWrapper query = new LambdaQueryWrapper<>(); - query.like(SysUser::getDepartIds,departId); - //删除全部的情况下用户id不存在 - if(oConvertUtils.isNotEmpty(userId)){ - query.eq(SysUser::getId,userId); - } - List userList = sysUserMapper.selectList(query); - for (SysUser sysUser:userList) { - //将不存在的部门id删除掉 - String departIds = sysUser.getDepartIds(); - List list = new ArrayList<>(Arrays.asList(departIds.split(","))); - list.remove(departId); - //删除之后再将新的id用逗号拼接起来进行更新 - String newDepartIds = String.join(",",list); - sysUser.setDepartIds(newDepartIds); - sysUserMapper.updateById(sysUser); - } - } - - /** - * 通过部门集合为部门设置用户id,用于前台展示 - * @param departList 部门集合 - */ - private void setUserIdsByDepList(List departList) { - //查询负责部门不为空的情况 - LambdaQueryWrapper query = new LambdaQueryWrapper<>(); - query.isNotNull(SysUser::getDepartIds); - List users = sysUserMapper.selectList(query); - Map map = new HashMap(5); - //先循环一遍找到不同的负责部门id - for (SysUser user:users) { - String departIds = user.getDepartIds(); - String[] departIdArray = departIds.split(","); - for (String departId:departIdArray) { - //mao中包含部门key,负责用户直接拼接 - if(map.containsKey(departId)){ - String userIds = map.get(departId) + "," + user.getId(); - map.put(departId,userIds); - }else{ - map.put(departId,user.getId()); - } - } - } - //循环部门集合找到部门id对应的负责用户 - for (SysDepart sysDepart:departList) { - if(map.containsKey(sysDepart.getId())){ - sysDepart.setDirectorUserIds(map.get(sysDepart.getId()).toString()); - } - } - } - //update-end---author:wangshuai ---date:20200308 for:[JTC-119]在部门管理菜单下设置部门负责人,新增方法添加部门负责人、删除负责部门负责人、查询部门对应的负责人 - - /** - * 获取我的部门已加入的公司 - * @return - */ - @Override - public List getMyDepartList() { - LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); - String userId = user.getId(); - //字典code集合 - List list = new ArrayList<>(); - //查询我加入的部门 - List sysDepartList = this.baseMapper.queryUserDeparts(userId); - for (SysDepart sysDepart : sysDepartList) { - //获取一级部门编码 - String orgCode = sysDepart.getOrgCode(); - if (YouBianCodeUtil.ZHANWEI_LENGTH <= orgCode.length()) { - int length = YouBianCodeUtil.ZHANWEI_LENGTH; - String companyOrgCode = orgCode.substring(0, length); - list.add(companyOrgCode); - } - } - //字典code集合不为空 - if (oConvertUtils.isNotEmpty(list)) { - //查询一级部门的数据 - LambdaQueryWrapper query = new LambdaQueryWrapper<>(); - query.select(SysDepart::getDepartName, SysDepart::getId, SysDepart::getOrgCode); - query.eq(SysDepart::getDelFlag, String.valueOf(CommonConstant.DEL_FLAG_0)); - query.in(SysDepart::getOrgCode, list); - return this.baseMapper.selectList(query); - } - return null; - } + * 根据关键字筛选部门信息 + * @param keyWord + * @return + */ + public void getTreeByKeyWord(String keyWord,List allResult,List newResult){ + for (SysDepartTreeModel model:allResult) { + if (model.getDepartName().contains(keyWord)){ + newResult.add(model); + continue; + }else if(model.getChildren()!=null){ + getTreeByKeyWord(keyWord,model.getChildren(),newResult); + } + } + } + + //update-begin---author:wangshuai ---date:20200308 for:[JTC-119]在部门管理菜单下设置部门负责人,新增方法添加部门负责人、删除负责部门负责人、查询部门对应的负责人 + /** + * 通过用户id设置负责部门 + * @param sysDepart SysDepart部门对象 + * @param userIds 多个负责用户id + */ + public void addDepartByUserIds(SysDepart sysDepart, String userIds) { + //获取部门id,保存到用户 + String departId = sysDepart.getId(); + //循环用户id + String[] userIdArray = userIds.split(","); + for (String userId:userIdArray) { + //查询用户表增加负责部门 + SysUser sysUser = sysUserMapper.selectById(userId); + //如果部门id不为空,那么就需要拼接 + if(oConvertUtils.isNotEmpty(sysUser.getDepartIds())){ + if(!sysUser.getDepartIds().contains(departId)) { + sysUser.setDepartIds(sysUser.getDepartIds() + "," + departId); + } + }else{ + sysUser.setDepartIds(departId); + } + //设置身份为上级 + sysUser.setUserIdentity(CommonConstant.USER_IDENTITY_2); + //跟新用户表 + sysUserMapper.updateById(sysUser); + //判断当前用户是否包含所属部门 + List userDepartList = userDepartMapper.getUserDepartByUid(userId); + boolean isExistDepId = userDepartList.stream().anyMatch(item -> departId.equals(item.getDepId())); + //如果不存在需要设置所属部门 + if(!isExistDepId){ + userDepartMapper.insert(new SysUserDepart(userId,departId)); + } + } + } + + /** + * 修改用户负责部门 + * @param sysDepart SysDepart对象 + */ + private void updateChargeDepart(SysDepart sysDepart) { + //新的用户id + String directorIds = sysDepart.getDirectorUserIds(); + //旧的用户id(数据库中存在的) + String oldDirectorIds = sysDepart.getOldDirectorUserIds(); + String departId = sysDepart.getId(); + //如果用户id为空,那么用户的负责部门id应该去除 + if(oConvertUtils.isEmpty(directorIds)){ + this.deleteChargeDepId(departId,null); + }else if(oConvertUtils.isNotEmpty(directorIds) && oConvertUtils.isEmpty(oldDirectorIds)){ + //如果用户id不为空但是用户原来负责部门的用户id为空 + this.addDepartByUserIds(sysDepart,directorIds); + }else{ + //都不为空,需要比较,进行添加或删除 + //找到新的负责部门用户id与原来负责部门的用户id,进行删除 + List userIdList = Arrays.stream(oldDirectorIds.split(",")).filter(item -> !directorIds.contains(item)).collect(Collectors.toList()); + for (String userId:userIdList){ + this.deleteChargeDepId(departId,userId); + } + //找到原来负责部门的用户id与新的负责部门用户id,进行新增 + String addUserIds = Arrays.stream(directorIds.split(",")).filter(item -> !oldDirectorIds.contains(item)).collect(Collectors.joining(",")); + if(oConvertUtils.isNotEmpty(addUserIds)){ + this.addDepartByUserIds(sysDepart,addUserIds); + } + } + } + + /** + * 删除用户负责部门 + * @param departId 部门id + * @param userId 用户id + */ + private void deleteChargeDepId(String departId,String userId){ + //先查询负责部门的用户id,因为负责部门的id使用逗号拼接起来的 + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.like(SysUser::getDepartIds,departId); + //删除全部的情况下用户id不存在 + if(oConvertUtils.isNotEmpty(userId)){ + query.eq(SysUser::getId,userId); + } + List userList = sysUserMapper.selectList(query); + for (SysUser sysUser:userList) { + //将不存在的部门id删除掉 + String departIds = sysUser.getDepartIds(); + List list = new ArrayList<>(Arrays.asList(departIds.split(","))); + list.remove(departId); + //删除之后再将新的id用逗号拼接起来进行更新 + String newDepartIds = String.join(",",list); + sysUser.setDepartIds(newDepartIds); + sysUserMapper.updateById(sysUser); + } + } + + /** + * 通过部门集合为部门设置用户id,用于前台展示 + * @param departList 部门集合 + */ + private void setUserIdsByDepList(List departList) { + //查询负责部门不为空的情况 + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.isNotNull(SysUser::getDepartIds); + List users = sysUserMapper.selectList(query); + Map map = new HashMap(5); + //先循环一遍找到不同的负责部门id + for (SysUser user:users) { + String departIds = user.getDepartIds(); + String[] departIdArray = departIds.split(","); + for (String departId:departIdArray) { + //mao中包含部门key,负责用户直接拼接 + if(map.containsKey(departId)){ + String userIds = map.get(departId) + "," + user.getId(); + map.put(departId,userIds); + }else{ + map.put(departId,user.getId()); + } + } + } + //循环部门集合找到部门id对应的负责用户 + for (SysDepart sysDepart:departList) { + if(map.containsKey(sysDepart.getId())){ + sysDepart.setDirectorUserIds(map.get(sysDepart.getId()).toString()); + } + } + } + //update-end---author:wangshuai ---date:20200308 for:[JTC-119]在部门管理菜单下设置部门负责人,新增方法添加部门负责人、删除负责部门负责人、查询部门对应的负责人 + + /** + * 获取我的部门已加入的公司 + * @return + */ + @Override + public List getMyDepartList() { + LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); + String userId = user.getId(); + //字典code集合 + List list = new ArrayList<>(); + //查询我加入的部门 + List sysDepartList = this.baseMapper.queryUserDeparts(userId); + for (SysDepart sysDepart : sysDepartList) { + //获取一级部门编码 + String orgCode = sysDepart.getOrgCode(); + if (YouBianCodeUtil.ZHANWEI_LENGTH <= orgCode.length()) { + int length = YouBianCodeUtil.ZHANWEI_LENGTH; + String companyOrgCode = orgCode.substring(0, length); + list.add(companyOrgCode); + } + } + //字典code集合不为空 + if (oConvertUtils.isNotEmpty(list)) { + //查询一级部门的数据 + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.select(SysDepart::getDepartName, SysDepart::getId, SysDepart::getOrgCode); + query.eq(SysDepart::getDelFlag, String.valueOf(CommonConstant.DEL_FLAG_0)); + query.in(SysDepart::getOrgCode, list); + return this.baseMapper.selectList(query); + } + return null; + } @Override public void deleteDepart(String id) { - //删除部门设置父级的叶子结点 + //删除部门设置父级的叶子结点 this.setIzLeaf(id); this.delete(id); //删除部门用户关系表 @@ -1325,7 +1372,7 @@ public class SysDepartServiceImpl extends ServiceImpl { export const queryDepartTreeSync = (params?) => { return defHttp.get({ url: Api.queryDepartTreeSync, params }); }; + +// 法人注册时,弹出列表只显示市和县区科技局,不显示下属单位 add by zhc 11.10 +export const queryDepartTreeSync4FaRen = (params?) => { + return defHttp.get({ url: Api.queryDepartTreeSync4FaRen, params }); +}; + + /** * 获取部门树列表 */ diff --git a/jeecgboot-vue3/src/components/Form/src/jeecg/components/JSelectDept4FaRen.vue b/jeecgboot-vue3/src/components/Form/src/jeecg/components/JSelectDept4FaRen.vue new file mode 100644 index 0000000..6429ee3 --- /dev/null +++ b/jeecgboot-vue3/src/components/Form/src/jeecg/components/JSelectDept4FaRen.vue @@ -0,0 +1,207 @@ + + + + diff --git a/jeecgboot-vue3/src/components/Form/src/jeecg/components/modal/DeptSelectModal4FaRen.vue b/jeecgboot-vue3/src/components/Form/src/jeecg/components/modal/DeptSelectModal4FaRen.vue new file mode 100644 index 0000000..ec88712 --- /dev/null +++ b/jeecgboot-vue3/src/components/Form/src/jeecg/components/modal/DeptSelectModal4FaRen.vue @@ -0,0 +1,131 @@ + + + diff --git a/jeecgboot-vue3/src/views/system/loginmini/MiniRegister4faren.vue b/jeecgboot-vue3/src/views/system/loginmini/MiniRegister4faren.vue index c7cd55d..cf258ab 100644 --- a/jeecgboot-vue3/src/views/system/loginmini/MiniRegister4faren.vue +++ b/jeecgboot-vue3/src/views/system/loginmini/MiniRegister4faren.vue @@ -41,7 +41,7 @@

- +
@@ -126,6 +126,7 @@ import eyeKImg from '/@/assets/loginmini/icon/icon-eye-k.png'; import eyeGImg from '/@/assets/loginmini/icon/icon-eye-g.png'; import JSelectDept from '/@/components/Form/src/jeecg/components/JSelectDept.vue'; + import JSelectDept4FaRen from '/@/components/Form/src/jeecg/components/JSelectDept4FaRen.vue'; import { useI18n } from '/@/hooks/web/useI18n'; import codeImg from '/@/assets/images/checkcode.png';