master
Gitea 2 weeks ago
parent 0af152f4b6
commit 6fe3274649
  1. 5
      jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/shiro/ShiroConfig.java
  2. 28
      jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysDepartController.java
  3. 9
      jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysDepartService.java
  4. 595
      jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java
  5. 8
      jeecgboot-vue3/src/api/common/api.ts
  6. 207
      jeecgboot-vue3/src/components/Form/src/jeecg/components/JSelectDept4FaRen.vue
  7. 131
      jeecgboot-vue3/src/components/Form/src/jeecg/components/modal/DeptSelectModal4FaRen.vue
  8. 3
      jeecgboot-vue3/src/views/system/loginmini/MiniRegister4faren.vue

@ -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");//法人注册时,选择部门列表

@ -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;
/**
* <p>
@ -170,6 +171,33 @@ public class SysDepartController {
return result;
}
/**
* @description: 法人注册时只显示市和县区科技局不显示下属单位
* @param: [parentId, ids, primaryKey]
* @return: org.jeecg.common.api.vo.Result<java.util.List<org.jeecg.modules.system.model.SysDepartTreeModel>>
* @author: z.h.c
* @date: 24/11/9 16:07
*/
@RequestMapping(value = "/queryDepartTreeSync4FaRen", method = RequestMethod.GET)
public Result<List<SysDepartTreeModel>> queryDepartTreeSync4FaRen(@RequestParam(name = "pid", required = false) String parentId,
@RequestParam(name = "ids", required = false) String ids,
@RequestParam(name = "primaryKey", required = false) String primaryKey) {
Result<List<SysDepartTreeModel>> result = new Result<>();
try {
// parentId = "1839495887972130817";
List<SysDepart> sysDeparts = sysDepartService.list(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getParentId, "1839495887972130817"));
ids = Optional.ofNullable(sysDeparts).orElse(new LinkedList<>()).stream().map(e -> e.getId()).collect(Collectors.joining(","));
List<SysDepartTreeModel> 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
*

@ -73,7 +73,7 @@ public interface ISysDepartService extends IService<SysDepart>{
* @param id
* @return
*/
/* boolean removeDepartDataById(String id); */
/* boolean removeDepartDataById(String id); */
/**
* 根据关键字搜索相关的部门数据
@ -96,7 +96,7 @@ public interface ISysDepartService extends IService<SysDepart>{
* @param userId
* @return
*/
public List<SysDepart> queryUserDeparts(String userId);
public List<SysDepart> queryUserDeparts(String userId);
/**
* 根据用户名查询部门
@ -114,12 +114,12 @@ public interface ISysDepartService extends IService<SysDepart>{
*/
List<String> queryDepartsByUserId(String userId);
/**
/**
* 根据部门id批量删除并删除其可能存在的子级部门
* @param ids 多个部门id
* @return
*/
void deleteBatchWithChildren(List<String> ids);
void deleteBatchWithChildren(List<String> ids);
/**
* 根据部门Id查询,当前和下级所有部门IDS
@ -148,6 +148,7 @@ public interface ISysDepartService extends IService<SysDepart>{
* @return
*/
List<SysDepartTreeModel> queryTreeListByPid(String parentId,String ids, String primaryKey);
List<SysDepartTreeModel> queryTreeListByPid4FaRen(String parentId,String ids, String primaryKey);
/**
* 获取某个部门的所有父级部门的ID

@ -119,10 +119,10 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
query.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
query.orderByAsc(SysDepart::getDepartOrder);
List<SysDepart> 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<SysDepartTreeModel> listResult = FindsDepartsChildrenUtil.wrapTreeDataToTreeList(list);
return listResult;
@ -215,13 +215,13 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
}
}
this.save(sysDepart);
//update-begin---author:wangshuai ---date:20220307 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理
//update-begin---author:wangshuai ---date:20220307 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理
//新增部门的时候新增负责部门
if(oConvertUtils.isNotEmpty(sysDepart.getDirectorUserIds())){
this.addDepartByUserIds(sysDepart,sysDepart.getDirectorUserIds());
}
//update-end---author:wangshuai ---date:20220307 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理
}
if(oConvertUtils.isNotEmpty(sysDepart.getDirectorUserIds())){
this.addDepartByUserIds(sysDepart,sysDepart.getDirectorUserIds());
}
//update-end---author:wangshuai ---date:20220307 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理
}
}
@ -233,61 +233,61 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
*/
private String[] generateOrgCode(String parentId) {
//update-begin--Author:Steve Date:20190201 for:组织机构添加数据代码调整
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
LambdaQueryWrapper<SysDepart> query1 = new LambdaQueryWrapper<SysDepart>();
String[] strArray = new String[2];
// 创建一个List集合,存储查询返回的所有SysDepart对象
List<SysDepart> 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<SysDepart> 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<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
LambdaQueryWrapper<SysDepart> query1 = new LambdaQueryWrapper<SysDepart>();
String[] strArray = new String[2];
// 创建一个List集合,存储查询返回的所有SysDepart对象
List<SysDepart> 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<SysDepart> 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<SysDepartMapper, SysDepart
sysDepart.setUpdateTime(new Date());
sysDepart.setUpdateBy(username);
this.updateById(sysDepart);
//update-begin---author:wangshuai ---date:20220307 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理
//update-begin---author:wangshuai ---date:20220307 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理
//修改部门管理的时候,修改负责部门
this.updateChargeDepart(sysDepart);
//update-begin---author:wangshuai ---date:20220307 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理
this.updateChargeDepart(sysDepart);
//update-begin---author:wangshuai ---date:20220307 for:[JTC-119]在部门管理菜单下设置部门负责人 创建用户的时候不需要处理
return true;
} else {
return false;
@ -423,7 +423,7 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
for(SysDepart depart : departList) {
model = new SysDepartTreeModel(depart);
model.setChildren(null);
//update-end--Author:huangzhilin Date:20140417 for:[bugfree号]组织机构搜索功回显优化----------------------
//update-end--Author:huangzhilin Date:20140417 for:[bugfree号]组织机构搜索功回显优化----------------------
newList.add(model);
}
return newList;
@ -566,32 +566,32 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
for(int i =1;i<str.length;i++){
if(str[i].length()<=min){
min = str[i].length();
orgCodeBuilder.append(SymbolConstant.COMMA).append(str[i]);
orgCodeBuilder.append(SymbolConstant.COMMA).append(str[i]);
}
}
return orgCodeBuilder.toString();
}
/**
* 获取部门树信息根据关键字
* @param keyWord
* @return
*/
@Override
public List<SysDepartTreeModel> queryTreeByKeyWord(String keyWord) {
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
query.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
query.orderByAsc(SysDepart::getDepartOrder);
List<SysDepart> list = this.list(query);
// 调用wrapTreeDataToTreeList方法生成树状数据
List<SysDepartTreeModel> listResult = FindsDepartsChildrenUtil.wrapTreeDataToTreeList(list);
List<SysDepartTreeModel> treelist =new ArrayList<>();
if(StringUtils.isNotBlank(keyWord)){
this.getTreeByKeyWord(keyWord,listResult,treelist);
}else{
return listResult;
}
return treelist;
}
/**
* 获取部门树信息根据关键字
* @param keyWord
* @return
*/
@Override
public List<SysDepartTreeModel> queryTreeByKeyWord(String keyWord) {
LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
query.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
query.orderByAsc(SysDepart::getDepartOrder);
List<SysDepart> list = this.list(query);
// 调用wrapTreeDataToTreeList方法生成树状数据
List<SysDepartTreeModel> listResult = FindsDepartsChildrenUtil.wrapTreeDataToTreeList(list);
List<SysDepartTreeModel> 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<SysDepartMapper, SysDepart
//------------------------------------------------------------------------------------------------
lqw.eq(true,SysDepart::getDelFlag,CommonConstant.DEL_FLAG_0.toString());
lqw.func(square);
//update-begin---author:wangshuai ---date:20220527 for:[VUEN-1143]排序不对,vue3和2应该都有问题,应该按照升序排------------
//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应该都有问题,应该按照升序排--------------
List<SysDepart> 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<SysDepartTreeModel> 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<SysDepartTreeModel> queryTreeListByPid4FaRen(String parentId,String ids, String primaryKey) {
/*Consumer<LambdaQueryWrapper<SysDepart>> 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<SysDepart> 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<SysDepart> 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<SysDepartTreeModel> 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<SysDepartMapper, SysDepart
return this.baseMapper.queryDeptByPid(pid);
}
/**
* 根据关键字筛选部门信息
* @param keyWord
* @return
*/
public void getTreeByKeyWord(String keyWord,List<SysDepartTreeModel> allResult,List<SysDepartTreeModel> 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<SysUserDepart> 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<String> 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<SysUser> query = new LambdaQueryWrapper<>();
query.like(SysUser::getDepartIds,departId);
//删除全部的情况下用户id不存在
if(oConvertUtils.isNotEmpty(userId)){
query.eq(SysUser::getId,userId);
}
List<SysUser> userList = sysUserMapper.selectList(query);
for (SysUser sysUser:userList) {
//将不存在的部门id删除掉
String departIds = sysUser.getDepartIds();
List<String> 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<SysDepart> departList) {
//查询负责部门不为空的情况
LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>();
query.isNotNull(SysUser::getDepartIds);
List<SysUser> users = sysUserMapper.selectList(query);
Map<String,Object> 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<SysDepart> getMyDepartList() {
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String userId = user.getId();
//字典code集合
List<String> list = new ArrayList<>();
//查询我加入的部门
List<SysDepart> 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<SysDepart> 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<SysDepartTreeModel> allResult,List<SysDepartTreeModel> 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<SysUserDepart> 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<String> 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<SysUser> query = new LambdaQueryWrapper<>();
query.like(SysUser::getDepartIds,departId);
//删除全部的情况下用户id不存在
if(oConvertUtils.isNotEmpty(userId)){
query.eq(SysUser::getId,userId);
}
List<SysUser> userList = sysUserMapper.selectList(query);
for (SysUser sysUser:userList) {
//将不存在的部门id删除掉
String departIds = sysUser.getDepartIds();
List<String> 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<SysDepart> departList) {
//查询负责部门不为空的情况
LambdaQueryWrapper<SysUser> query = new LambdaQueryWrapper<>();
query.isNotNull(SysUser::getDepartIds);
List<SysUser> users = sysUserMapper.selectList(query);
Map<String,Object> 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<SysDepart> getMyDepartList() {
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String userId = user.getId();
//字典code集合
List<String> list = new ArrayList<>();
//查询我加入的部门
List<SysDepart> 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<SysDepart> 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<SysDepartMapper, SysDepart
}
sysDepart.setOrgCode(departExportVo.getOrgCode());
if(oConvertUtils.isNotEmpty(sysDepart.getParentId())){
//上级
//上级
sysDepart.setOrgType("2");
}else{
//下级

@ -8,6 +8,7 @@ enum Api {
userList = '/sys/user/list',
roleList = '/sys/role/list',
queryDepartTreeSync = '/sys/sysDepart/queryDepartTreeSync',
queryDepartTreeSync4FaRen = '/sys/sysDepart/queryDepartTreeSync4FaRen',
queryTreeList = '/sys/sysDepart/queryTreeList',
loadTreeData = '/sys/category/loadTreeData',
loadDictItem = '/sys/category/loadDictItem/',
@ -51,6 +52,13 @@ export const getRoleList = (params) => {
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 });
};
/**
* 获取部门树列表
*/

@ -0,0 +1,207 @@
<!--部门选择组件-->
<template>
<div class="JSelectDept">
<JSelectBiz @change="handleSelectChange" @handleOpen="handleOpen" :loading="loadingEcho" v-bind="attrs"/>
<!-- update-begin--author:liaozhiyang---date:20240515---forQQYUN-9260必填模式下会影响到弹窗内antd组件的样式 -->
<a-form-item>
<DeptSelectModal4FaRen @register="regModal" @getSelectResult="setValue" v-bind="getBindValue" :multiple="multiple" @close="handleClose"/>
</a-form-item>
<!-- update-end--author:liaozhiyang---date:20240515---forQQYUN-9260必填模式下会影响到弹窗内antd组件的样式 -->
</div>
</template>
<script lang="ts">
import DeptSelectModal4FaRen from './modal/DeptSelectModal4FaRen.vue';
import JSelectBiz from './base/JSelectBiz.vue';
import { defineComponent, ref, reactive, watchEffect, watch, provide, unref, toRaw } from 'vue';
import { useModal } from '/@/components/Modal';
import { propTypes } from '/@/utils/propTypes';
import { useRuleFormItem } from '/@/hooks/component/useFormItem';
import { useAttrs } from '/@/hooks/core/useAttrs';
import { SelectValue } from 'ant-design-vue/es/select';
import { cloneDeep } from 'lodash-es';
export default defineComponent({
name: 'JSelectDept4FaRen',
components: {
DeptSelectModal4FaRen,
JSelectBiz,
},
inheritAttrs: false,
props: {
value: propTypes.oneOfType([propTypes.string, propTypes.array]),
// true
multiple: propTypes.bool.def(true),
},
emits: ['options-change', 'change', 'select', 'update:value'],
setup(props, { emit, refs }) {
const emitData = ref<any[]>();
//model
const [regModal, { openModal }] = useModal();
//
// const [state] = useRuleFormItem(props, 'value', 'change', emitData);
//
const selectOptions = ref<SelectValue>([]);
//
let selectValues = reactive<Recordable>({
value: [],
});
let tempSave: any = [];
//
const loadingEcho = ref<boolean>(false);
// selectOptions,xxxBiz
provide('selectOptions', selectOptions);
// selectValues,xxxBiz
provide('selectValues', selectValues);
// loadingEcho,xxxBiz
provide('loadingEcho', loadingEcho);
const tag = ref(false);
const attrs = useAttrs();
/**
* 监听组件值
*/
watchEffect(() => {
// update-begin--author:liaozhiyang---date:20240611---forTV360X-576JSelectDept
//update-begin-author:liusq---date:2024-06-03--for: [TV360X-840]
tempSave = [];
//update-end-author:liusq---date:2024-06-03--for:[TV360X-840]
// update-end--author:liaozhiyang---date:20240611---forTV360X-576JSelectDept
props.value && initValue();
});
//update-begin-author:liusq---date:20220609--for: form ---
watch(
() => props.value,
() => {
initValue();
}
);
//update-end-author:liusq---date:20220609--for: form ---
/**
* 监听selectValues变化
*/
// update-begin--author:liaozhiyang---date:20240527---forTV360X-414(JSelectUser)
// watch(selectValues, () => {
// if (selectValues) {
// state.value = selectValues.value;
// }
// });
// update-end--author:liaozhiyang---date:20240527---forTV360X-414(JSelectUser)
/**
* 监听selectOptions变化
*/
watch(selectOptions, () => {
if (selectOptions) {
emit('select', toRaw(unref(selectOptions)), toRaw(unref(selectValues)));
}
});
/**
* 打卡弹出框
*/
function handleOpen() {
tag.value = true;
openModal(true, {
isUpdate: false,
});
}
/**
* 将字符串值转化为数组
*/
function initValue() {
let value = props.value ? props.value : [];
if (value && typeof value === 'string') {
// state.value = value.split(',');
selectValues.value = value.split(',');
tempSave = value.split(',');
} else {
// VUEN-857
selectValues.value = value;
tempSave = cloneDeep(value);
}
}
/**
* 设置下拉框的值
*/
function setValue(options, values) {
selectOptions.value = options;
//emitData.value = values.join(",");
// state.value = values;
selectValues.value = values;
send(values);
}
const getBindValue = Object.assign({}, unref(props), unref(attrs));
// update-begin--author:liaozhiyang---date:20240527---forTV360X-414(JSelectUser)
const handleClose = () => {
if (tempSave.length) {
selectValues.value = cloneDeep(tempSave);
} else {
send(tempSave);
}
};
const handleSelectChange = (values) => {
tempSave = cloneDeep(values);
send(tempSave);
};
const send = (values) => {
let result = typeof props.value == 'string' ? values.join(',') : values;
emit('update:value', result);
emit('change', result);
// update-begin--author:liaozhiyang---date:20240627---forTV360X-1648
if (!values || values.length == 0) {
emit('select', null, null);
}
// update-end--author:liaozhiyang---date:20240627---forTV360X-1648
};
// update-end--author:liaozhiyang---date:20240527---forTV360X-414(JSelectUser)
return {
// state,
attrs,
selectOptions,
selectValues,
loadingEcho,
getBindValue,
tag,
regModal,
setValue,
handleOpen,
handleClose,
handleSelectChange,
};
},
});
</script>
<style lang="less" scoped>
// update-begin--author:liaozhiyang---date:20240515---forQQYUN-9260antd
.JSelectDept {
> .ant-form-item {
display: none;
}
}
// update-end--author:liaozhiyang---date:20240515---forQQYUN-9260antd
.j-select-row {
@width: 82px;
.left {
width: calc(100% - @width - 8px);
}
.right {
width: @width;
}
.full {
width: 100%;
}
:deep(.ant-select-search__field) {
display: none !important;
}
}
</style>

@ -0,0 +1,131 @@
<!--部门选择框-->
<template>
<div>
<BasicModal v-bind="$attrs" @register="register" :title="modalTitle" width="500px" :maxHeight="maxHeight" @ok="handleOk" destroyOnClose @visible-change="visibleChange">
<BasicTree
ref="treeRef"
:treeData="treeData"
:load-data="sync == false ? null : onLoadData"
v-bind="getBindValue"
@select="onSelect"
@check="onCheck"
:fieldNames="fieldNames"
:checkedKeys="checkedKeys"
:multiple="multiple"
:checkStrictly="getCheckStrictly"
/>
<!--树操作部分-->
<!-- <template #insertFooter>
<a-dropdown placement="top">
<template #overlay>
<a-menu>
<a-menu-item v-if="multiple" key="1" @click="checkALL(true)">全部勾选</a-menu-item>
<a-menu-item v-if="multiple" key="2" @click="checkALL(false)">取消全选</a-menu-item>
<a-menu-item key="3" @click="expandAll(true)">展开全部</a-menu-item>
<a-menu-item key="4" @click="expandAll(false)">折叠全部</a-menu-item>
</a-menu>
</template>
<a-button style="float: left"> 树操作 <Icon icon="ant-design:up-outlined" /> </a-button>
</a-dropdown>
</template>-->
</BasicModal>
</div>
</template>
<script lang="ts">
import { defineComponent, ref, unref } from 'vue';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { queryDepartTreeSync4FaRen, queryTreeList } from '/@/api/common/api';
import { useAttrs } from '/@/hooks/core/useAttrs';
import { treeProps } from '/@/components/Form/src/jeecg/props/props';
import { BasicTree, TreeActionType } from '/@/components/Tree';
import { useTreeBiz } from '/@/components/Form/src/jeecg/hooks/useTreeBiz';
import {propTypes} from "/@/utils/propTypes";
import { omit } from 'lodash-es';
export default defineComponent({
name: 'DeptSelectModal4FaRen',
components: {
BasicModal,
BasicTree,
},
props: {
...treeProps,
//
modalTitle: {
type: String,
default: '单位选择',
},
// update-begin--author:liaozhiyang---date:20231220---forQQYUN-7678
maxHeight: {
type: Number,
default: 500,
},
// update-end--author:liaozhiyang---date:20231220---forQQYUN-7678
value: propTypes.oneOfType([propTypes.string, propTypes.array])
},
emits: ['register', 'getSelectResult', 'close'],
setup(props, { emit, refs }) {
//
const [register, { closeModal }] = useModalInner();
const attrs = useAttrs();
const treeRef = ref<Nullable<TreeActionType>>(null);
//update-begin-author:taoyan date:2022-10-28 for:
let propValue = props.value === ''?[]:props.value;
//update-begin-author:liusq date:2023-05-26 for: [issues/538]JSelectDept dynamicDisabled
let temp = Object.assign({}, unref(props), unref(attrs), {value: propValue},{disabled: false});
const getBindValue = omit(temp, 'multiple');
//update-end-author:liusq date:2023-05-26 for: [issues/538]JSelectDept dynamicDisabled
//update-end-author:taoyan date:2022-10-28 for:
const queryUrl = getQueryUrl();
const [{ visibleChange, checkedKeys, getCheckStrictly, getSelectTreeData, onCheck, onLoadData, treeData, checkALL, expandAll, onSelect }] =
useTreeBiz(treeRef, queryUrl, getBindValue, props, emit);
const searchInfo = ref(props.params);
const tree = ref([]);
//treeNodekeytreeData
const fieldNames = {
key: props.rowKey,
};
// {children:'children', title:'title', key:'key' }
/**
* 确定选择
*/
function handleOk() {
getSelectTreeData((options, values) => {
//
emit('getSelectResult', options, values);
//
closeModal();
});
}
/** 获取查询数据方法 */
function getQueryUrl() {
let queryFn = props.sync ? queryDepartTreeSync4FaRen : queryTreeList;
//update-begin-author:taoyan date:2022-7-4 for: issues/I5F3P4 online
return (params) => queryFn(Object.assign({}, params, { primaryKey: props.rowKey }));
//update-end-author:taoyan date:2022-7-4 for: issues/I5F3P4 online
}
return {
tree,
handleOk,
searchInfo,
treeRef,
treeData,
onCheck,
onSelect,
checkALL,
expandAll,
fieldNames,
checkedKeys,
register,
getBindValue,
getCheckStrictly,
visibleChange,
onLoadData,
};
},
});
</script>

@ -41,7 +41,7 @@
</a-form-item>
<a-form-item>
<div class="aui-input-line">
<JSelectDept :placeholder="t('sys.login.selectorgPlaceholder4Kejiju')" v-model:value="formData.department" :multiple="false" />
<JSelectDept4FaRen :placeholder="t('sys.login.selectorgPlaceholder4Kejiju')" v-model:value="formData.department" :multiple="false" />
</div>
</a-form-item>
<a-form-item>
@ -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';

Loading…
Cancel
Save