【user】 用户选择树接口开发

pull/3/head
liuhanqing 2021-01-15 14:25:12 +08:00 committed by fengshuonan
parent 1619e5d2d7
commit de4d538f31
11 changed files with 395 additions and 4 deletions

View File

@ -0,0 +1,67 @@
package cn.stylefeng.roses.kernel.rule.enums;
import lombok.Getter;
/**
*
*
* @author liuhanqing
* @date 2021/1/15 13:36
*/
@Getter
public enum TreeNodeEnum {
/**
*
*/
ORG("org", "机构"),
/**
*
*/
USER("user", "用户");
private final String code;
private final String name;
TreeNodeEnum(String code, String name) {
this.code = code;
this.name = name;
}
/**
* code
*
* @author liuhanqing
* @date 2021/1/15 13:36
*/
public static TreeNodeEnum codeToEnum(String code) {
if (null != code) {
for (TreeNodeEnum e : TreeNodeEnum.values()) {
if (e.getCode().equals(code)) {
return e;
}
}
}
return null;
}
/**
*
*
* @author liuhanqing
* @date 2021/1/15 13:36
*/
public static String codeToMessage(String code) {
if (null != code) {
for (TreeNodeEnum e : TreeNodeEnum.values()) {
if (e.getCode().equals(code)) {
return e.getName();
}
}
}
return "未知";
}
}

View File

@ -0,0 +1,53 @@
package cn.stylefeng.roses.kernel.rule.pojo.tree;
import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.rule.enums.TreeNodeEnum;
import lombok.Data;
import java.util.List;
/**
*
* <p>
* id-1
*
* @author liuhanqing
* @date 2021/1/15 13:36
*/
@Data
public class UserSelectTreeNode extends DefaultTreeNode {
/**
* org: user:
*/
private String nodeType;
/**
*
*/
private String value;
/**
*
*/
private Boolean selected = false;
/**
*
*/
private Boolean disabled = false;
public Boolean getDisabled() {
if (this.disabled) {
return true;
}
if (TreeNodeEnum.ORG.getCode().equals(nodeType) && IterUtil.isEmpty(this.getChildren())) {
return true;
}
return this.disabled;
}
}

View File

@ -0,0 +1,23 @@
package cn.stylefeng.roses.kernel.system;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationResponse;
import java.util.List;
/**
* api
*
* @author liuhanqing
* @date 2021/1/15 10:40
*/
public interface OrganizationServiceApi {
/**
*
*
* @return
* @author liuhanqing
* @date 2021/1/15 10:41
*/
List<HrOrganizationResponse> orgList();
}

View File

@ -0,0 +1,61 @@
package cn.stylefeng.roses.kernel.system.pojo.organization;
import lombok.Data;
import java.math.BigDecimal;
/**
*
*
* @author fengshuonan
* @date 2020/11/04 11:05
*/
@Data
public class HrOrganizationResponse {
/**
*
*/
private Long orgId;
/**
* idid0
*/
private Long orgParentId;
/**
* ids
*/
private String orgPids;
/**
*
*/
private String orgName;
/**
*
*/
private String orgCode;
/**
*
*/
private BigDecimal orgSort;
/**
* 1-2-
*/
private Integer statusFlag;
/**
*
*/
private String orgRemark;
/**
* Y-N-
*/
private String delFlag;
}

View File

@ -3,8 +3,10 @@ package cn.stylefeng.roses.kernel.system.modular.organization.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.tree.DefaultTreeNode; import cn.stylefeng.roses.kernel.rule.pojo.tree.DefaultTreeNode;
import cn.stylefeng.roses.kernel.rule.pojo.ztree.ZTreeNode; import cn.stylefeng.roses.kernel.rule.pojo.ztree.ZTreeNode;
import cn.stylefeng.roses.kernel.system.OrganizationServiceApi;
import cn.stylefeng.roses.kernel.system.modular.organization.entity.HrOrganization; import cn.stylefeng.roses.kernel.system.modular.organization.entity.HrOrganization;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationRequest; import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationRequest;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationResponse;
import cn.stylefeng.roses.kernel.system.pojo.organization.layui.LayuiOrganizationTreeNode; import cn.stylefeng.roses.kernel.system.pojo.organization.layui.LayuiOrganizationTreeNode;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
@ -17,7 +19,7 @@ import java.util.Set;
* @author fengshuonan * @author fengshuonan
* @date 2020/11/04 11:05 * @date 2020/11/04 11:05
*/ */
public interface HrOrganizationService extends IService<HrOrganization> { public interface HrOrganizationService extends IService<HrOrganization>, OrganizationServiceApi {
/** /**
* *
@ -85,6 +87,7 @@ public interface HrOrganizationService extends IService<HrOrganization> {
*/ */
List<HrOrganization> list(HrOrganizationRequest hrOrganizationRequest); List<HrOrganization> list(HrOrganizationRequest hrOrganizationRequest);
/** /**
* *
* *

View File

@ -29,6 +29,7 @@ import cn.stylefeng.roses.kernel.system.modular.organization.factory.Organizatio
import cn.stylefeng.roses.kernel.system.modular.organization.mapper.HrOrganizationMapper; import cn.stylefeng.roses.kernel.system.modular.organization.mapper.HrOrganizationMapper;
import cn.stylefeng.roses.kernel.system.modular.organization.service.HrOrganizationService; import cn.stylefeng.roses.kernel.system.modular.organization.service.HrOrganizationService;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationRequest; import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationRequest;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationResponse;
import cn.stylefeng.roses.kernel.system.pojo.organization.layui.LayuiOrganizationTreeNode; import cn.stylefeng.roses.kernel.system.pojo.organization.layui.LayuiOrganizationTreeNode;
import cn.stylefeng.roses.kernel.system.util.DataScopeUtil; import cn.stylefeng.roses.kernel.system.util.DataScopeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -39,9 +40,9 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashSet; import java.util.*;
import java.util.List; import java.util.function.Function;
import java.util.Set; import java.util.stream.Collectors;
/** /**
* *
@ -169,6 +170,55 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
return this.list(wrapper); return this.list(wrapper);
} }
@Override
public List<HrOrganizationResponse> orgList(){
LambdaQueryWrapper<HrOrganization> queryWrapper = new LambdaQueryWrapper<>();
// 如果是超级管理员 或 数据范围是所有,则不过滤数据范围
boolean needToDataScope = true;
if (LoginContext.me().getSuperAdminFlag()) {
Set<DataScopeTypeEnum> dataScopeTypes = LoginContext.me().getLoginUser().getDataScopeTypeEnums();
if (dataScopeTypes != null && dataScopeTypes.contains(DataScopeTypeEnum.ALL)) {
needToDataScope = false;
}
}
// 如果需要数据范围过滤,则获取用户的数据范围,拼接查询条件
if (needToDataScope) {
Set<Long> dataScope = LoginContext.me().getLoginUser().getDataScopeOrganizationIds();
// 数据范围没有,直接返回空
if (ObjectUtil.isEmpty(dataScope)) {
return new ArrayList<>();
}
// 根据组织机构数据范围的上级组织,用于展示完整的树形结构
Set<Long> allLevelParentIdsByOrganizations = this.findAllLevelParentIdsByOrganizations(dataScope);
// 拼接查询条件
queryWrapper.in(HrOrganization::getOrgId, allLevelParentIdsByOrganizations);
}
// 只查询未删除的
queryWrapper.eq(HrOrganization::getDelFlag, YesOrNotEnum.N.getCode());
// 根据排序升序排列,序号越小越在前
queryWrapper.orderByAsc(HrOrganization::getOrgSort);
// 先实例化出Function接口
Function<Object, HrOrganizationResponse> mapper = e -> {
HrOrganizationResponse org = new HrOrganizationResponse();
HrOrganization hrOrg = (HrOrganization) e;
BeanUtil.copyProperties(hrOrg, org);
return org;
};
// 返回数据
List<HrOrganization> list = this.list(queryWrapper);
List<HrOrganizationResponse> resultList = list.stream().filter(Objects::nonNull).map(mapper).collect(Collectors.toList());
return resultList;
}
@Override @Override
public List<DefaultTreeNode> tree(HrOrganizationRequest hrOrganizationRequest) { public List<DefaultTreeNode> tree(HrOrganizationRequest hrOrganizationRequest) {

View File

@ -15,6 +15,8 @@ import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserService;
import cn.stylefeng.roses.kernel.system.pojo.user.request.SysUserRequest; import cn.stylefeng.roses.kernel.system.pojo.user.request.SysUserRequest;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -261,4 +263,14 @@ public class SysUserController {
return new SuccessResponseData(sysUserService.detail(sysUserRequest)); return new SuccessResponseData(sysUserService.detail(sysUserRequest));
} }
/**
*
*
* @author liuhanqing
* @date 2021/1/15 8:28
*/
@GetResource(name = "获取用户选择树数据", path = "/sysUser/getUserSelectTree")
public SuccessResponseData getUserTree() {
return new SuccessResponseData(this.sysUserService.userSelectTree(new SysUserRequest()));
}
} }

View File

@ -7,6 +7,8 @@ import cn.stylefeng.roses.kernel.system.pojo.user.request.SysUserRequest;
import cn.stylefeng.roses.kernel.system.modular.user.pojo.response.SysUserResponse; import cn.stylefeng.roses.kernel.system.modular.user.pojo.response.SysUserResponse;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* mapper * mapper
* *
@ -25,4 +27,13 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
*/ */
Page<SysUserResponse> findUserPage(@Param("page") Page<SysUser> page, @Param("sysUserRequest") SysUserRequest sysUserRequest); Page<SysUserResponse> findUserPage(@Param("page") Page<SysUser> page, @Param("sysUserRequest") SysUserRequest sysUserRequest);
/**
*
*
* @param sysUserRequest
* @author liuhanqing
* @date 2021/1/15 11:04
*/
List<SysUserResponse> findUserList(@Param("sysUserRequest") SysUserRequest sysUserRequest);
} }

View File

@ -39,4 +39,40 @@
</select> </select>
<!--获取用户列表-->
<select id="findUserList" resultType="cn.stylefeng.roses.kernel.system.modular.user.pojo.response.SysUserResponse">
select
suser.user_id as userId,
suser.account as account,
suser.nick_name as nickName,
suser.real_name as realName,
suser.avatar as avatar,
suser.birthday as birthday,
suser.sex as sex,
suser.email as email,
suser.phone as phone,
suser.tel as tel,
suser.status_flag as statusFlag,
suorg.org_id as orgId,
suorg.position_id as positionId
from sys_user suser
left join sys_user_org suorg on suser.user_id = suorg.user_id
<where>
<if test="sysUserRequest.realName != null and sysUserRequest.realName != ''">
and suser.real_name like concat('%',#{sysUserRequest.realName},'%')
</if>
<if test="sysUserRequest.account != null and sysUserRequest.account != ''">
and suser.account like concat('%',#{sysUserRequest.account},'%')
</if>
<if test="sysUserRequest.statusFlag != null and sysUserRequest.statusFlag != ''">
and suser.status_flag like concat('%',#{sysUserRequest.statusFlag},'%')
</if>
<if test="sysUserRequest.orgId != null and sysUserRequest.orgId != ''">
and suorg.org_id in(select org_id from hr_organization where org_pids like CONCAT('%[',#{sysUserRequest.orgId},']%') or org_id=#{sysUserRequest.orgId})
</if>
and suser.del_flag = 'N'
order by suser.create_time desc
</where>
</select>
</mapper> </mapper>

View File

@ -2,6 +2,8 @@ package cn.stylefeng.roses.kernel.system.modular.user.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict; import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
import cn.stylefeng.roses.kernel.rule.pojo.tree.DefaultTreeNode;
import cn.stylefeng.roses.kernel.rule.pojo.tree.UserSelectTreeNode;
import cn.stylefeng.roses.kernel.system.UserServiceApi; import cn.stylefeng.roses.kernel.system.UserServiceApi;
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUser; import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUser;
import cn.stylefeng.roses.kernel.system.modular.user.pojo.response.SysUserResponse; import cn.stylefeng.roses.kernel.system.modular.user.pojo.response.SysUserResponse;
@ -178,4 +180,21 @@ public interface SysUserService extends IService<SysUser>, UserServiceApi {
*/ */
String getUserAvatarUrl(Long fileId); String getUserAvatarUrl(Long fileId);
/**
*
*
* @param sysUserRequest
* @author liuhanqing
* @date 2021/1/15 11:16
*/
List<UserSelectTreeNode> userSelectTree(SysUserRequest sysUserRequest);
/**
* id
*
* @param orgId id
* @author liuhanqing
* @date 2021/1/15 11:16
*/
List<UserSelectTreeNode> getUserTreeNodeList(Long orgId);
} }

View File

@ -1,6 +1,7 @@
package cn.stylefeng.roses.kernel.system.modular.user.service.impl; package cn.stylefeng.roses.kernel.system.modular.user.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.auth.api.SessionManagerApi; import cn.stylefeng.roses.kernel.auth.api.SessionManagerApi;
@ -14,9 +15,14 @@ import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.file.FileInfoApi; import cn.stylefeng.roses.kernel.file.FileInfoApi;
import cn.stylefeng.roses.kernel.office.api.OfficeExcelApi; import cn.stylefeng.roses.kernel.office.api.OfficeExcelApi;
import cn.stylefeng.roses.kernel.office.api.pojo.report.ExcelExportParam; import cn.stylefeng.roses.kernel.office.api.pojo.report.ExcelExportParam;
import cn.stylefeng.roses.kernel.rule.enums.TreeNodeEnum;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum; import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import cn.stylefeng.roses.kernel.rule.factory.DefaultTreeBuildFactory;
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict; import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
import cn.stylefeng.roses.kernel.rule.pojo.tree.DefaultTreeNode;
import cn.stylefeng.roses.kernel.rule.pojo.tree.UserSelectTreeNode;
import cn.stylefeng.roses.kernel.system.DataScopeApi; import cn.stylefeng.roses.kernel.system.DataScopeApi;
import cn.stylefeng.roses.kernel.system.OrganizationServiceApi;
import cn.stylefeng.roses.kernel.system.ResourceServiceApi; import cn.stylefeng.roses.kernel.system.ResourceServiceApi;
import cn.stylefeng.roses.kernel.system.RoleServiceApi; import cn.stylefeng.roses.kernel.system.RoleServiceApi;
import cn.stylefeng.roses.kernel.system.enums.UserStatusEnum; import cn.stylefeng.roses.kernel.system.enums.UserStatusEnum;
@ -36,6 +42,7 @@ import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserOrgService;
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserRoleService; import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserRoleService;
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserService; import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserService;
import cn.stylefeng.roses.kernel.system.pojo.organization.DataScopeResponse; import cn.stylefeng.roses.kernel.system.pojo.organization.DataScopeResponse;
import cn.stylefeng.roses.kernel.system.pojo.organization.HrOrganizationResponse;
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResponse; import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResponse;
import cn.stylefeng.roses.kernel.system.pojo.user.OnlineUserResponse; import cn.stylefeng.roses.kernel.system.pojo.user.OnlineUserResponse;
import cn.stylefeng.roses.kernel.system.pojo.user.SysUserDTO; import cn.stylefeng.roses.kernel.system.pojo.user.SysUserDTO;
@ -46,6 +53,7 @@ import cn.stylefeng.roses.kernel.system.pojo.user.request.SysUserRequest;
import cn.stylefeng.roses.kernel.system.util.DataScopeUtil; import cn.stylefeng.roses.kernel.system.util.DataScopeUtil;
import com.alibaba.excel.support.ExcelTypeEnum; import com.alibaba.excel.support.ExcelTypeEnum;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -102,6 +110,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
@Resource @Resource
private SessionManagerApi sessionManagerApi; private SessionManagerApi sessionManagerApi;
@Resource
private OrganizationServiceApi organizationServiceApi;
@Override @Override
public void register(SysUserRequest sysUserRequest) { public void register(SysUserRequest sysUserRequest) {
SysUser sysUser = new SysUser(); SysUser sysUser = new SysUser();
@ -577,6 +588,51 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return sysUser; return sysUser;
} }
@Override
public List<UserSelectTreeNode> userSelectTree(SysUserRequest sysUserRequest) {
// 定义返回结果
List<UserSelectTreeNode> treeNodeList = CollectionUtil.newArrayList();
List<HrOrganizationResponse> orgList = organizationServiceApi.orgList();
UserSelectTreeNode orgTreeNode;
for (HrOrganizationResponse hrOrganization : orgList) {
orgTreeNode = new UserSelectTreeNode();
orgTreeNode.setId(String.valueOf(hrOrganization.getOrgId()));
orgTreeNode.setPId(String.valueOf(hrOrganization.getOrgParentId()));
orgTreeNode.setName(hrOrganization.getOrgName());
orgTreeNode.setNodeType(TreeNodeEnum.ORG.getCode());
orgTreeNode.setValue(String.valueOf(hrOrganization.getOrgId()));
orgTreeNode.setSort(hrOrganization.getOrgSort());
treeNodeList.add(orgTreeNode);
List<UserSelectTreeNode> userNodeList = this.getUserTreeNodeList(hrOrganization.getOrgId());
if(userNodeList.size()>0){
treeNodeList.addAll(userNodeList);
}
}
// 构建树并返回
return new DefaultTreeBuildFactory<UserSelectTreeNode>().doTreeBuild(treeNodeList);
}
@Override
public List<UserSelectTreeNode> getUserTreeNodeList(Long orgId) {
// 定义返回结果
List<UserSelectTreeNode> treeNodeList = CollectionUtil.newArrayList();
SysUserRequest userRequest = new SysUserRequest();
userRequest.setOrgId(orgId);
List<SysUserResponse> userList = this.baseMapper.findUserList(userRequest);
UserSelectTreeNode userTreeNode;
for (SysUserResponse user : userList) {
userTreeNode = new UserSelectTreeNode();
userTreeNode.setId(String.valueOf(user.getUserId()));
userTreeNode.setPId(String.valueOf(user.getOrgId()));
userTreeNode.setName(user.getRealName());
userTreeNode.setNodeType(TreeNodeEnum.USER.getCode());
userTreeNode.setValue(String.valueOf(user.getUserId()));
// userTreeNode.setSort(hrOrganization.getOrgSort());
treeNodeList.add(userTreeNode);
}
return treeNodeList;
}
/** /**
* wrapper * wrapper
* *