mirror of https://gitee.com/stylefeng/roses
【system】【user】【org】调整user和org的业务
parent
be952c5827
commit
8e19ef6257
|
@ -26,12 +26,12 @@ public interface ResourceServiceApi {
|
|||
/**
|
||||
* 获取资源详情,根据资源id集合
|
||||
*
|
||||
* @param resourceIds 资源id集合
|
||||
* @param resourceCodes 资源code集合
|
||||
* @return 资源详情列表
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/29 19:49
|
||||
*/
|
||||
List<ResourceDefinition> getResourceListByIds(List<String> resourceIds);
|
||||
List<ResourceDefinition> getResourceListByIds(List<String> resourceCodes);
|
||||
|
||||
/**
|
||||
* 获取资源的url列表,根据资源ids查询
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.system;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 企业员工的管理API
|
||||
* <p>
|
||||
* 企业员工管理就是用户和组织架构的管理
|
||||
*
|
||||
* @author luojie
|
||||
* @date 2020/11/5 16:23
|
||||
*/
|
||||
public interface SysEmployeeApi {
|
||||
|
||||
/**
|
||||
* 添加或修改员工信息
|
||||
* <p>
|
||||
* 业务步骤都是,先删除该用户的所有员工信息,再添加参数上的员工信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param sysEmployeeRequest 企业员工信息
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/04 11:05
|
||||
*/
|
||||
void updateEmployee(Long userId, List<SysEmployeeRequest> sysEmployeeRequest);
|
||||
|
||||
/**
|
||||
* 根据用户id删除员工信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @author luojie
|
||||
* @date 2020/11/14 14:21
|
||||
*/
|
||||
void deleteEmployeeByUserId(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户主任职信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 用户的主任职信息
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/19 21:42
|
||||
*/
|
||||
SysEmployeeResponse getUserMainEmployee(Long userId);
|
||||
|
||||
/**
|
||||
* 获取用户所有的任职信息,包含主任职信息和附属任职信息
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @return 用户所有的任职信息
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/19 21:43
|
||||
*/
|
||||
List<SysEmployeeResponse> getUserAllEmployee(Long userId);
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package cn.stylefeng.roses.kernel.system;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.pojo.user.SysUserOrgResponse;
|
||||
|
||||
/**
|
||||
* 用户组织机构服务api
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/19 22:21
|
||||
*/
|
||||
public interface UserOrgServiceApi {
|
||||
|
||||
/**
|
||||
* 获取组织机构或职务下是否有人绑定
|
||||
*
|
||||
* @return true-有人绑定,false-无人
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/19 22:42
|
||||
*/
|
||||
Boolean getUserOrgFlag(Long orgId, Long positionId);
|
||||
|
||||
/**
|
||||
* 获取用户的组织机构信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/19 22:33
|
||||
*/
|
||||
SysUserOrgResponse getUserOrgInfo(Long userId);
|
||||
|
||||
}
|
|
@ -12,7 +12,7 @@ import lombok.Getter;
|
|||
* @date 2020/11/19 23:07
|
||||
*/
|
||||
@Getter
|
||||
public enum EmployeeExceptionEnum implements AbstractExceptionEnum {
|
||||
public enum SysUserOrgExceptionEnum implements AbstractExceptionEnum {
|
||||
|
||||
/**
|
||||
* 企业员工信息不存在
|
||||
|
@ -20,9 +20,9 @@ public enum EmployeeExceptionEnum implements AbstractExceptionEnum {
|
|||
EMPLOYEE_NOT_FOUND(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "21", "企业员工信息不存在,用户id:{}"),
|
||||
|
||||
/**
|
||||
* 用户存在多个主部门信息(系统不允许)
|
||||
* 用户绑定多个或未绑定机构信息
|
||||
*/
|
||||
EMPLOYEE_MANY_MAIN_NOT_FOUND(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "22", "获取用户主部门失败,用户存在多个主部门信息,用户id:{}"),
|
||||
EMPLOYEE_MANY_MAIN_NOT_FOUND(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "22", "用户绑定多个或未绑定机构信息"),
|
||||
|
||||
/**
|
||||
* 用户未设置主部门,或主部门信息为多个
|
||||
|
@ -39,7 +39,7 @@ public enum EmployeeExceptionEnum implements AbstractExceptionEnum {
|
|||
*/
|
||||
private final String userTip;
|
||||
|
||||
EmployeeExceptionEnum(String errorCode, String userTip) {
|
||||
SysUserOrgExceptionEnum(String errorCode, String userTip) {
|
||||
this.errorCode = errorCode;
|
||||
this.userTip = userTip;
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.system.pojo.organization;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 企业员工表,用户-组织机构的关联
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/04 11:05
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class SysEmployeeRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@NotNull(message = "主键id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@NotNull(message = "用户id不能为空", groups = {add.class})
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 所属机构id
|
||||
*/
|
||||
@NotNull(message = "所属机构id不能为空", groups = {add.class})
|
||||
private Long organizationId;
|
||||
|
||||
/**
|
||||
* 职位id集合,用逗号隔开
|
||||
*/
|
||||
@NotBlank(message = "职位id集合,用逗号隔开不能为空", groups = add.class)
|
||||
private String positionIds;
|
||||
|
||||
/**
|
||||
* 是否是主要部门,Y-是,N-否,一个人只能有一个主要部门
|
||||
*/
|
||||
@NotBlank(message = "是否是主要部门,Y-是,N-否,一个人只能有一个主要部门不能为空", groups = {add.class})
|
||||
private String mainDeptFlag;
|
||||
|
||||
/**
|
||||
* 员工编号
|
||||
*/
|
||||
private String employeeNo;
|
||||
|
||||
/**
|
||||
* 职位id,用在查询某个职位下的企业员工时候用
|
||||
*/
|
||||
private Long positionId;
|
||||
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.system.pojo.organization;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 用户员工信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/4/2 20:22
|
||||
*/
|
||||
@Data
|
||||
public class SysEmployeeResponse implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 所属机构id
|
||||
*/
|
||||
private Long organizationId;
|
||||
|
||||
/**
|
||||
* 所属机构名称
|
||||
*/
|
||||
private String organizationName;
|
||||
|
||||
/**
|
||||
* 职位id集合,用逗号隔开
|
||||
*/
|
||||
private String positionIds;
|
||||
|
||||
/**
|
||||
* 职位id名称集合,用逗号隔开
|
||||
*/
|
||||
private String positionNames;
|
||||
|
||||
/**
|
||||
* 是否是主要部门,Y-是,N-否,一个人只能有一个主要部门
|
||||
*/
|
||||
private String mainDeptFlag;
|
||||
|
||||
/**
|
||||
* 员工编号
|
||||
*/
|
||||
private String employeeNo;
|
||||
|
||||
}
|
|
@ -48,34 +48,34 @@ public class SysRoleRequest extends BaseRequest {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
@NotNull(message = "id不能为空,请检查id参数", groups = {edit.class, delete.class, detail.class, updateStatus.class, grantResource.class, grantData.class})
|
||||
private Long id;
|
||||
@NotNull(message = "roleId不能为空", groups = {edit.class, delete.class, detail.class, updateStatus.class, grantResource.class, grantData.class})
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
* 角色名称
|
||||
*/
|
||||
@NotBlank(message = "名称不能为空,请检查name参数", groups = {add.class, edit.class})
|
||||
private String name;
|
||||
@NotBlank(message = "角色名称不能为空", groups = {add.class, edit.class})
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
* 角色编码
|
||||
*/
|
||||
@NotBlank(message = "编码不能为空,请检查code参数", groups = {add.class, edit.class})
|
||||
@NotBlank(message = "角色编码不能为空", groups = {add.class, edit.class})
|
||||
@TableUniqueValue(
|
||||
message = "编码存在重复,请检查code参数",
|
||||
message = "角色编码存在重复",
|
||||
groups = {add.class, edit.class},
|
||||
tableName = "sys_menu",
|
||||
columnName = "code")
|
||||
private String code;
|
||||
tableName = "sys_role",
|
||||
columnName = "role_code")
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@NotNull(message = "排序不能为空,请检查sort参数", groups = {add.class, edit.class})
|
||||
private BigDecimal sort;
|
||||
@NotNull(message = "排序不能为空", groups = {add.class, edit.class})
|
||||
private BigDecimal roleSort;
|
||||
|
||||
/**
|
||||
* 数据范围类型(字典 10全部数据 20本部门及以下数据 30本部门数据 40仅本人数据 50自定义数据)
|
||||
* 数据范围类型:10-全部数据,20-本部门及以下数据,30-本部门数据,40-仅本人数据,50-自定义数据
|
||||
*/
|
||||
@Null(message = "数据范围类型应该为空, 请移除dataScopeType参数", groups = {add.class, edit.class})
|
||||
@NotNull(message = "数据范围类型不能为空,请检查dataScopeType参数", groups = {grantData.class})
|
||||
|
|
|
@ -16,25 +16,25 @@ public class SysRoleResponse extends BaseRequest {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long id;
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String code;
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
private Integer roleSort;
|
||||
|
||||
/**
|
||||
* 数据范围类型(枚举 10全部数据 20本部门及以下数据 30本部门数据 40仅本人数据 50自定义数据)
|
||||
* 数据范围类型:10-全部数据,20-本部门及以下数据,30-本部门数据,40-仅本人数据,50-自定义数据
|
||||
*/
|
||||
private Integer dataScopeType;
|
||||
|
||||
|
@ -49,7 +49,8 @@ public class SysRoleResponse extends BaseRequest {
|
|||
private String remark;
|
||||
|
||||
/**
|
||||
* 状态(字典 1正常 2停用)
|
||||
* 状态:1-启用,2-禁用
|
||||
*/
|
||||
private Integer statusFlag;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package cn.stylefeng.roses.kernel.system.pojo.user;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 企业员工表,用户-组织机构的关联
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/04 11:05
|
||||
*/
|
||||
@Data
|
||||
public class SysUserOrgResponse {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
private Long userOrgId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 所属机构id
|
||||
*/
|
||||
private Long orgId;
|
||||
|
||||
/**
|
||||
* 职位id
|
||||
*/
|
||||
private Long positionId;
|
||||
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.organization.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 企业员工表,用户-组织机构的关联
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/04 11:05
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_employee")
|
||||
public class SysEmployee extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId("id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@TableField("user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 所属机构id
|
||||
*/
|
||||
@TableField("organization_id")
|
||||
private Long organizationId;
|
||||
|
||||
/**
|
||||
* 职位id集合,用逗号隔开
|
||||
*/
|
||||
@TableField("position_ids")
|
||||
private String positionIds;
|
||||
|
||||
/**
|
||||
* 是否是主要部门,Y-是,N-否,一个人只能有一个主要部门
|
||||
*/
|
||||
@TableField("main_dept_flag")
|
||||
private String mainDeptFlag;
|
||||
|
||||
/**
|
||||
* 员工编号
|
||||
*/
|
||||
@TableField("employee_no")
|
||||
private String employeeNo;
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.organization.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.entity.SysEmployee;
|
||||
|
||||
/**
|
||||
* 企业员工表,用户-组织机构的关联 Mapper 接口
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/04 11:05
|
||||
*/
|
||||
public interface SysEmployeeMapper extends BaseMapper<SysEmployee> {
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.stylefeng.roses.kernel.system.modular.organization.mapper.SysEmployeeMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.stylefeng.roses.kernel.system.modular.organization.entity.SysEmployee">
|
||||
<id column="id" property="id" />
|
||||
<result column="user_id" property="userId" />
|
||||
<result column="organization_id" property="organizationId" />
|
||||
<result column="position_ids" property="positionIds" />
|
||||
<result column="main_dept_flag" property="mainDeptFlag" />
|
||||
<result column="employee_no" property="employeeNo" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="create_user" property="createUser" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="update_user" property="updateUser" />
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
|
@ -3,15 +3,15 @@ package cn.stylefeng.roses.kernel.system.modular.organization.service;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.db.api.DbOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.system.exception.DataScopeException;
|
||||
import cn.stylefeng.roses.kernel.system.exception.enums.DataScopeExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeResponse;
|
||||
import cn.stylefeng.roses.kernel.system.DataScopeApi;
|
||||
import cn.stylefeng.roses.kernel.system.RoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.SysEmployeeApi;
|
||||
import cn.stylefeng.roses.kernel.system.UserOrgServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.exception.DataScopeException;
|
||||
import cn.stylefeng.roses.kernel.system.exception.enums.DataScopeExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.DataScopeResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.user.SysUserOrgResponse;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -36,7 +36,7 @@ public class DataScopeService implements DataScopeApi {
|
|||
private RoleServiceApi roleServiceApi;
|
||||
|
||||
@Resource
|
||||
private SysEmployeeApi sysEmployeeApi;
|
||||
private UserOrgServiceApi userOrgServiceApi;
|
||||
|
||||
@Resource
|
||||
private DbOperatorApi dbOperatorApi;
|
||||
|
@ -78,19 +78,19 @@ public class DataScopeService implements DataScopeApi {
|
|||
if (dataScopeTypeEnums.contains(DataScopeTypeEnum.DEFINE)) {
|
||||
|
||||
// 获取角色对应的组织机构范围
|
||||
List<Long> roleIds = sysRoles.stream().map(SysRoleResponse::getId).collect(Collectors.toList());
|
||||
List<Long> roleIds = sysRoles.stream().map(SysRoleResponse::getRoleId).collect(Collectors.toList());
|
||||
List<Long> orgIds = roleServiceApi.getRoleDataScopes(roleIds);
|
||||
organizationIds.addAll(orgIds);
|
||||
}
|
||||
|
||||
// 获取用户的主要部门信息
|
||||
SysEmployeeResponse userMainEmployee = sysEmployeeApi.getUserMainEmployee(userId);
|
||||
SysUserOrgResponse sysUserOrgResponse = userOrgServiceApi.getUserOrgInfo(userId);
|
||||
|
||||
// 本部门和本部门以下,查出用户的主要部门,并且查询该部门本部门及以下的组织机构id列表
|
||||
if (dataScopeTypeEnums.contains(DataScopeTypeEnum.DEPT_WITH_CHILD)) {
|
||||
|
||||
// 获取部门及以下部门的id列表
|
||||
Long organizationId = userMainEmployee.getOrganizationId();
|
||||
Long organizationId = sysUserOrgResponse.getOrgId();
|
||||
Set<Long> subOrgIds = dbOperatorApi.findSubListByParentId("sys_organization", "pids", "id", organizationId);
|
||||
organizationIds.add(organizationId);
|
||||
organizationIds.addAll(subOrgIds);
|
||||
|
@ -100,7 +100,7 @@ public class DataScopeService implements DataScopeApi {
|
|||
if (dataScopeTypeEnums.contains(DataScopeTypeEnum.DEPT)) {
|
||||
|
||||
// 获取本部门的id
|
||||
Long organizationId = userMainEmployee.getOrganizationId();
|
||||
Long organizationId = sysUserOrgResponse.getOrgId();
|
||||
organizationIds.add(organizationId);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.organization.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.entity.SysEmployee;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 企业员工的管理,用户和组织机构的绑定
|
||||
* <p>
|
||||
* 用户在添加到sys_user表后没有和组织机构关联,通过employee这个表来关联用户和组织机构
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/04 11:05
|
||||
*/
|
||||
public interface SysEmployeeService extends IService<SysEmployee> {
|
||||
|
||||
/**
|
||||
* 分页查询企业员工
|
||||
*
|
||||
* @param sysEmployeeRequest 企业员工查询条件
|
||||
* @return 企业员工详情分页列表
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/04 11:05
|
||||
*/
|
||||
PageResult<SysEmployee> page(SysEmployeeRequest sysEmployeeRequest);
|
||||
|
||||
/**
|
||||
* 查询所有企业员工
|
||||
*
|
||||
* @param sysEmployeeRequest 企业员工查询条件
|
||||
* @return 企业员工详情列表
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/04 11:05
|
||||
*/
|
||||
List<SysEmployee> list(SysEmployeeRequest sysEmployeeRequest);
|
||||
|
||||
}
|
|
@ -1,212 +0,0 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.organization.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.exception.enums.EmployeeExceptionEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.system.SysEmployeeApi;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.entity.SysEmployee;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.entity.SysOrganization;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.mapper.SysEmployeeMapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.service.SysEmployeeService;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.service.SysOrganizationService;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.service.SysPositionService;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeResponse;
|
||||
import org.springframework.aop.framework.AopContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 企业员工表,用户-组织机构的关联 服务实现类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/04 11:05
|
||||
*/
|
||||
@Service
|
||||
public class SysEmployeeServiceImpl extends ServiceImpl<SysEmployeeMapper, SysEmployee> implements SysEmployeeService, SysEmployeeApi {
|
||||
|
||||
@Resource
|
||||
private SysOrganizationService sysOrganizationService;
|
||||
|
||||
@Resource
|
||||
private SysPositionService sysPositionService;
|
||||
|
||||
@Override
|
||||
public PageResult<SysEmployee> page(SysEmployeeRequest sysEmployeeRequest) {
|
||||
|
||||
// 构造条件
|
||||
LambdaQueryWrapper<SysEmployee> queryWrapper = createWrapper(sysEmployeeRequest);
|
||||
|
||||
// 查询分页结果
|
||||
return PageResultFactory.createPageResult(this.page(PageFactory.defaultPage(), queryWrapper));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysEmployee> list(SysEmployeeRequest sysEmployeeRequest) {
|
||||
|
||||
// 构造条件
|
||||
LambdaQueryWrapper<SysEmployee> queryWrapper = createWrapper(sysEmployeeRequest);
|
||||
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateEmployee(Long userId, List<SysEmployeeRequest> sysEmployeeRequest) {
|
||||
|
||||
// 删除用户对应的所有员工关联信息
|
||||
SysEmployeeServiceImpl sysEmployeeService = (SysEmployeeServiceImpl) AopContext.currentProxy();
|
||||
sysEmployeeService.deleteEmployeeByUserId(userId);
|
||||
|
||||
// 添加用户的组织架构关联
|
||||
ArrayList<SysEmployee> sysEmployees = new ArrayList<>();
|
||||
for (SysEmployeeRequest employeeRequest : sysEmployeeRequest) {
|
||||
SysEmployee sysEmployee = new SysEmployee();
|
||||
BeanUtil.copyProperties(employeeRequest, sysEmployee);
|
||||
sysEmployees.add(sysEmployee);
|
||||
}
|
||||
|
||||
// 批量添加雇员信息
|
||||
sysEmployeeService.saveBatch(sysEmployees);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteEmployeeByUserId(Long userId) {
|
||||
|
||||
// 删除用户id对应的员工信息
|
||||
LambdaUpdateWrapper<SysEmployee> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(SysEmployee::getUserId, userId);
|
||||
|
||||
this.remove(updateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysEmployeeResponse getUserMainEmployee(Long userId) {
|
||||
|
||||
// 组装用户主部门员工信息查询条件
|
||||
SysEmployeeRequest sysEmployeeRequest = new SysEmployeeRequest();
|
||||
sysEmployeeRequest.setUserId(userId);
|
||||
sysEmployeeRequest.setMainDeptFlag(YesOrNotEnum.Y.getCode());
|
||||
|
||||
LambdaQueryWrapper<SysEmployee> wrapper = createWrapper(sysEmployeeRequest);
|
||||
List<SysEmployee> sysEmployees = this.list(wrapper);
|
||||
|
||||
// 查询不到,提示企业员工信息不存在
|
||||
if (sysEmployees == null || sysEmployees.isEmpty()) {
|
||||
String userTip = StrUtil.format(EmployeeExceptionEnum.EMPLOYEE_NOT_FOUND.getUserTip(), userId);
|
||||
throw new SystemModularException(EmployeeExceptionEnum.EMPLOYEE_NOT_FOUND, userTip);
|
||||
}
|
||||
|
||||
// 查询出多个主部门,提示该用户异常
|
||||
if (sysEmployees.size() > 1) {
|
||||
String userTip = StrUtil.format(EmployeeExceptionEnum.EMPLOYEE_MANY_MAIN_NOT_FOUND.getUserTip(), userId);
|
||||
throw new SystemModularException(EmployeeExceptionEnum.EMPLOYEE_MANY_MAIN_NOT_FOUND, userTip);
|
||||
}
|
||||
|
||||
return parseSysEmployee(sysEmployees.get(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysEmployeeResponse> getUserAllEmployee(Long userId) {
|
||||
|
||||
// 组装用户主部门员工信息查询条件
|
||||
SysEmployeeRequest sysEmployeeRequest = new SysEmployeeRequest();
|
||||
sysEmployeeRequest.setUserId(userId);
|
||||
|
||||
LambdaQueryWrapper<SysEmployee> wrapper = createWrapper(sysEmployeeRequest);
|
||||
List<SysEmployee> sysEmployees = this.list(wrapper);
|
||||
|
||||
// 查询不到员工信息报异常
|
||||
if (sysEmployees.isEmpty()) {
|
||||
String userTip = StrUtil.format(EmployeeExceptionEnum.EMPLOYEE_NOT_FOUND.getUserTip(), userId);
|
||||
throw new SystemModularException(EmployeeExceptionEnum.EMPLOYEE_NOT_FOUND, userTip);
|
||||
}
|
||||
|
||||
// 转化为SysEmployeeResponse对象,拼接组织机构名称和职位名称
|
||||
ArrayList<SysEmployeeResponse> sysEmployeeResponses = new ArrayList<>();
|
||||
for (SysEmployee sysEmployee : sysEmployees) {
|
||||
sysEmployeeResponses.add(parseSysEmployee(sysEmployee));
|
||||
}
|
||||
|
||||
return sysEmployeeResponses;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 企业雇员的查询条件
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/6 16:37
|
||||
*/
|
||||
private LambdaQueryWrapper<SysEmployee> createWrapper(SysEmployeeRequest sysEmployeeRequest) {
|
||||
LambdaQueryWrapper<SysEmployee> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (ObjectUtil.isNotNull(sysEmployeeRequest)) {
|
||||
|
||||
// 拼接用户id
|
||||
if (ObjectUtil.isNotEmpty(sysEmployeeRequest.getUserId())) {
|
||||
queryWrapper.eq(SysEmployee::getUserId, sysEmployeeRequest.getUserId());
|
||||
}
|
||||
|
||||
// 拼接组织机构id
|
||||
if (ObjectUtil.isNotEmpty(sysEmployeeRequest.getOrganizationId())) {
|
||||
queryWrapper.eq(SysEmployee::getOrganizationId, sysEmployeeRequest.getOrganizationId());
|
||||
}
|
||||
|
||||
// 拼接职位id查询条件
|
||||
if (ObjectUtil.isNotEmpty(sysEmployeeRequest.getPositionId())) {
|
||||
queryWrapper.like(SysEmployee::getPositionIds, sysEmployeeRequest.getPositionId());
|
||||
}
|
||||
|
||||
// 拼接主部门标识
|
||||
if (ObjectUtil.isNotEmpty(sysEmployeeRequest.getMainDeptFlag())) {
|
||||
queryWrapper.eq(SysEmployee::getMainDeptFlag, sysEmployeeRequest.getMainDeptFlag());
|
||||
}
|
||||
|
||||
}
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转化实体类为Response对象,填充机构名称和职位名称
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/20 22:44
|
||||
*/
|
||||
private SysEmployeeResponse parseSysEmployee(SysEmployee sysEmployee) {
|
||||
|
||||
SysEmployeeResponse sysEmployeeResponse = new SysEmployeeResponse();
|
||||
BeanUtil.copyProperties(sysEmployee, sysEmployeeResponse);
|
||||
|
||||
// 组装组织机构名称
|
||||
SysOrganization sysOrganization = sysOrganizationService.getById(sysEmployee.getOrganizationId());
|
||||
if (sysOrganization != null) {
|
||||
sysEmployeeResponse.setOrganizationName(sysOrganization.getName());
|
||||
}
|
||||
|
||||
// 组装职位名称,用逗号隔开多个
|
||||
String[] positionIdsString = StrUtil.split(sysEmployee.getPositionIds(), StrUtil.COMMA);
|
||||
List<Long> positionIds = Arrays.stream(positionIdsString).map(Long::valueOf).collect(Collectors.toList());
|
||||
List<String> positionNamesByPositionIds = sysPositionService.getPositionNamesByPositionIds(positionIds);
|
||||
String join = StrUtil.join(StrUtil.COMMA, positionNamesByPositionIds);
|
||||
sysEmployeeResponse.setPositionNames(join);
|
||||
|
||||
return sysEmployeeResponse;
|
||||
}
|
||||
|
||||
}
|
|
@ -5,14 +5,6 @@ import cn.hutool.core.collection.CollectionUtil;
|
|||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stylefeng.roses.kernel.system.constants.SystemConstants;
|
||||
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.exception.enums.DataScopeExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.exception.enums.OrganizationExceptionEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.db.api.context.DbOperatorContext;
|
||||
|
@ -24,15 +16,21 @@ import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
|||
import cn.stylefeng.roses.kernel.rule.factory.DefaultTreeBuildFactory;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.tree.DefaultTreeNode;
|
||||
import cn.stylefeng.roses.kernel.system.RoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.UserOrgServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.entity.SysEmployee;
|
||||
import cn.stylefeng.roses.kernel.system.constants.SystemConstants;
|
||||
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.exception.enums.DataScopeExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.exception.enums.OrganizationExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.entity.SysOrganization;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.mapper.SysOrganizationMapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.service.SysEmployeeService;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.service.SysOrganizationService;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysOrganizationRequest;
|
||||
import cn.stylefeng.roses.kernel.system.util.DataScopeUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -51,7 +49,7 @@ import java.util.Set;
|
|||
public class SysOrganizationServiceImpl extends ServiceImpl<SysOrganizationMapper, SysOrganization> implements SysOrganizationService {
|
||||
|
||||
@Resource
|
||||
private SysEmployeeService sysEmployeeService;
|
||||
private UserOrgServiceApi userOrgServiceApi;
|
||||
|
||||
@Resource
|
||||
private RoleServiceApi roleServiceApi;
|
||||
|
@ -121,10 +119,8 @@ public class SysOrganizationServiceImpl extends ServiceImpl<SysOrganizationMappe
|
|||
}
|
||||
|
||||
// 该机构下有员工,则不能删
|
||||
SysEmployeeRequest sysEmployeeRequest = new SysEmployeeRequest();
|
||||
sysEmployeeRequest.setOrganizationId(organizationId);
|
||||
List<SysEmployee> sysEmployees = sysEmployeeService.list(sysEmployeeRequest);
|
||||
if (sysEmployees != null && !sysEmployees.isEmpty()) {
|
||||
Boolean userOrgFlag = userOrgServiceApi.getUserOrgFlag(organizationId, null);
|
||||
if (userOrgFlag) {
|
||||
throw new SystemModularException(OrganizationExceptionEnum.DELETE_ORGANIZATION_ERROR);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,24 +3,22 @@ package cn.stylefeng.roses.kernel.system.modular.organization.service.impl;
|
|||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.exception.enums.PositionExceptionEnum;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.entity.SysEmployee;
|
||||
import cn.stylefeng.roses.kernel.system.UserOrgServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.exception.enums.PositionExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.entity.SysPosition;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.mapper.SysPositionMapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.service.SysEmployeeService;
|
||||
import cn.stylefeng.roses.kernel.system.modular.organization.service.SysPositionService;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysPositionRequest;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -38,7 +36,7 @@ import java.util.stream.Collectors;
|
|||
public class SysPositionServiceImpl extends ServiceImpl<SysPositionMapper, SysPosition> implements SysPositionService {
|
||||
|
||||
@Resource
|
||||
private SysEmployeeService sysEmployeeService;
|
||||
private UserOrgServiceApi userOrgServiceApi;
|
||||
|
||||
@Override
|
||||
public void add(SysPositionRequest sysPositionRequest) {
|
||||
|
@ -70,12 +68,9 @@ public class SysPositionServiceImpl extends ServiceImpl<SysPositionMapper, SysPo
|
|||
SysPosition sysPosition = this.querySysPosition(sysPositionRequest);
|
||||
|
||||
// 该职位下是否有员工
|
||||
SysEmployeeRequest sysEmployeeRequest = new SysEmployeeRequest();
|
||||
sysEmployeeRequest.setPositionId(sysPosition.getId());
|
||||
List<SysEmployee> haveEmployee = sysEmployeeService.list(sysEmployeeRequest);
|
||||
|
||||
// 职位有绑定员工,不能删除
|
||||
if (!haveEmployee.isEmpty()) {
|
||||
Boolean userOrgFlag = userOrgServiceApi.getUserOrgFlag(null, sysPosition.getId());
|
||||
if (userOrgFlag) {
|
||||
throw new SystemModularException(PositionExceptionEnum.CANT_DELETE_POSITION);
|
||||
}
|
||||
|
||||
|
|
|
@ -170,17 +170,17 @@ public class SysResourceServiceImpl extends ServiceImpl<SysResourceMapper, SysRe
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<ResourceDefinition> getResourceListByIds(List<String> resourceIds) {
|
||||
public List<ResourceDefinition> getResourceListByIds(List<String> resourceCodes) {
|
||||
|
||||
ArrayList<ResourceDefinition> resourceDefinitions = new ArrayList<>();
|
||||
|
||||
if (resourceIds == null || resourceIds.isEmpty()) {
|
||||
if (resourceCodes == null || resourceCodes.isEmpty()) {
|
||||
return resourceDefinitions;
|
||||
}
|
||||
|
||||
// 拼接in条件
|
||||
LambdaQueryWrapper<SysResource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(SysResource::getResourceId, resourceIds);
|
||||
queryWrapper.in(SysResource::getResourceCode, resourceCodes);
|
||||
|
||||
// 获取资源详情
|
||||
List<SysResource> list = this.list(queryWrapper);
|
||||
|
|
|
@ -136,7 +136,7 @@ public class SysRoleController {
|
|||
*/
|
||||
@GetResource(name = "角色拥有菜单", path = "/sysRole/getRoleMenus")
|
||||
public ResponseData getRoleMenus(@Validated(SysRoleRequest.detail.class) SysRoleRequest sysRoleRequest) {
|
||||
Long roleId = sysRoleRequest.getId();
|
||||
Long roleId = sysRoleRequest.getRoleId();
|
||||
return new SuccessResponseData(roleServiceApi.getMenuIdsByRoleIds(ListUtil.toList(roleId)));
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.role.modular.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
|
@ -46,35 +46,35 @@ public class SysRole extends BaseEntity {
|
|||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@TableField("id")
|
||||
private Long id;
|
||||
@TableField("role_id")
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
* 角色名称
|
||||
*/
|
||||
@TableField("name")
|
||||
private String name;
|
||||
@TableField("role_name")
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
* 角色编码
|
||||
*/
|
||||
@TableField("code")
|
||||
private String code;
|
||||
@TableField("role_code")
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
@TableField("sort")
|
||||
private BigDecimal sort;
|
||||
@TableField("role_sort")
|
||||
private BigDecimal roleSort;
|
||||
|
||||
/**
|
||||
* 数据范围类型(枚举 10全部数据 20本部门及以下数据 30本部门数据 40仅本人数据 50自定义数据)
|
||||
* 数据范围类型:10-全部数据,20-本部门及以下数据,30-本部门数据,40-仅本人数据,50-自定义数据
|
||||
*/
|
||||
@TableField("data_scope_type")
|
||||
private Integer dataScopeType;
|
||||
|
||||
/**
|
||||
* 状态(1-启用,2-禁用)
|
||||
* 状态:1-启用,2-禁用
|
||||
*/
|
||||
@TableField("status_flag")
|
||||
private Integer statusFlag;
|
||||
|
|
|
@ -24,11 +24,11 @@ Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.role.modular.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
|
@ -47,18 +47,19 @@ public class SysRoleDataScope extends BaseEntity {
|
|||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@TableField("id")
|
||||
private Long id;
|
||||
@TableField("role_data_scope_id")
|
||||
private Long roleDataScopeId;
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
@TableField("roleId")
|
||||
@TableField("role_id")
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 机构id
|
||||
*/
|
||||
@TableField("organizationId")
|
||||
@TableField("organization_id")
|
||||
private Long organizationId;
|
||||
|
||||
}
|
||||
|
|
|
@ -44,8 +44,8 @@ public class SysRoleResource {
|
|||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@TableField("id")
|
||||
private Long id;
|
||||
@TableField("role_resource_id")
|
||||
private Long roleResourceId;
|
||||
|
||||
/**
|
||||
* 角色id
|
||||
|
@ -54,9 +54,9 @@ public class SysRoleResource {
|
|||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 资源id
|
||||
* 资源编码
|
||||
*/
|
||||
@TableField("resource_id")
|
||||
private String resourceId;
|
||||
@TableField("resource_code")
|
||||
private String resourceCode;
|
||||
|
||||
}
|
||||
|
|
|
@ -26,12 +26,12 @@ package cn.stylefeng.roses.kernel.role.modular.service.impl;
|
|||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.stylefeng.roses.kernel.role.modular.entity.SysRoleDataScope;
|
||||
import cn.stylefeng.roses.kernel.role.modular.mapper.SysRoleDataScopeMapper;
|
||||
import cn.stylefeng.roses.kernel.role.modular.service.SysRoleDataScopeService;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.request.SysRoleRequest;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class SysRoleDataScopeServiceImpl extends ServiceImpl<SysRoleDataScopeMap
|
|||
|
||||
@Override
|
||||
public void grantDataScope(SysRoleRequest sysRoleParam) {
|
||||
Long roleId = sysRoleParam.getId();
|
||||
Long roleId = sysRoleParam.getRoleId();
|
||||
|
||||
LambdaQueryWrapper<SysRoleDataScope> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysRoleDataScope::getRoleId, roleId);
|
||||
|
|
|
@ -49,7 +49,7 @@ public class SysRoleResourceServiceImpl extends ServiceImpl<SysRoleResourceMappe
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public void grantResource(SysRoleRequest sysRoleRequest) {
|
||||
|
||||
Long roleId = sysRoleRequest.getId();
|
||||
Long roleId = sysRoleRequest.getRoleId();
|
||||
|
||||
// 删除所拥有角色关联的资源
|
||||
LambdaQueryWrapper<SysRoleResource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
@ -64,7 +64,7 @@ public class SysRoleResourceServiceImpl extends ServiceImpl<SysRoleResourceMappe
|
|||
for (String resourceId : grantResourceList) {
|
||||
SysRoleResource sysRoleMenu = new SysRoleResource();
|
||||
sysRoleMenu.setRoleId(roleId);
|
||||
sysRoleMenu.setResourceId(resourceId);
|
||||
sysRoleMenu.setResourceCode(resourceId);
|
||||
sysRoleResources.add(sysRoleMenu);
|
||||
}
|
||||
this.saveBatch(sysRoleResources);
|
||||
|
@ -74,7 +74,7 @@ public class SysRoleResourceServiceImpl extends ServiceImpl<SysRoleResourceMappe
|
|||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteRoleResourceListByResourceIds(List<Long> resourceIds) {
|
||||
LambdaQueryWrapper<SysRoleResource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(SysRoleResource::getResourceId, resourceIds);
|
||||
queryWrapper.in(SysRoleResource::getResourceCode, resourceIds);
|
||||
this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ import cn.stylefeng.roses.kernel.role.modular.service.SysRoleService;
|
|||
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
|
||||
import cn.stylefeng.roses.kernel.system.MenuServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.RoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.constants.SymbolConstant;
|
||||
|
@ -85,9 +84,6 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
@Resource
|
||||
private SysRoleDataScopeService sysRoleDataScopeService;
|
||||
|
||||
@Resource
|
||||
private MenuServiceApi menuServiceApi;
|
||||
|
||||
@Resource
|
||||
private SysRoleMenuService roleMenuService;
|
||||
|
||||
|
@ -98,6 +94,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
|
||||
// 默认设置为启用
|
||||
sysRole.setStatusFlag(StatusEnum.ENABLE.getCode());
|
||||
|
||||
this.save(sysRole);
|
||||
}
|
||||
|
||||
|
@ -122,7 +119,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
|
||||
this.updateById(sysRole);
|
||||
|
||||
Long id = sysRole.getId();
|
||||
Long id = sysRole.getRoleId();
|
||||
|
||||
// 级联删除该角色对应的角色-数据范围关联信息
|
||||
sysRoleDataScopeService.deleteRoleDataScopeListByRoleId(id);
|
||||
|
@ -204,7 +201,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
if (ObjectUtil.isEmpty(loginUserRoleIds)) {
|
||||
return dictList;
|
||||
}
|
||||
queryWrapper.in(SysRole::getId, loginUserRoleIds);
|
||||
queryWrapper.in(SysRole::getRoleId, loginUserRoleIds);
|
||||
}
|
||||
|
||||
// 只查询正常状态
|
||||
|
@ -212,9 +209,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
|
||||
this.list(queryWrapper).forEach(sysRole -> {
|
||||
SimpleDict simpleDict = new SimpleDict();
|
||||
simpleDict.setId(sysRole.getId());
|
||||
simpleDict.setCode(sysRole.getCode());
|
||||
simpleDict.setName(sysRole.getName());
|
||||
simpleDict.setId(sysRole.getRoleId());
|
||||
simpleDict.setCode(sysRole.getRoleCode());
|
||||
simpleDict.setName(sysRole.getRoleName());
|
||||
dictList.add(simpleDict);
|
||||
});
|
||||
return dictList;
|
||||
|
@ -223,7 +220,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
@Override
|
||||
public List<Long> getRoleDataScope(SysRoleRequest sysRoleRequest) {
|
||||
SysRole sysRole = this.querySysRole(sysRoleRequest);
|
||||
return sysRoleDataScopeService.getRoleDataScopeIdList(CollectionUtil.newArrayList(sysRole.getId()));
|
||||
return sysRoleDataScopeService.getRoleDataScopeIdList(CollectionUtil.newArrayList(sysRole.getRoleId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -234,16 +231,16 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
List<Long> roleIdList = userServiceApi.getUserRoleIdList(userId);
|
||||
if (ObjectUtil.isNotEmpty(roleIdList)) {
|
||||
LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(SysRole::getId, roleIdList)
|
||||
queryWrapper.in(SysRole::getRoleId, roleIdList)
|
||||
.eq(SysRole::getStatusFlag, StatusEnum.ENABLE.getCode())
|
||||
.ne(SysRole::getDelFlag, YesOrNotEnum.N.getCode());
|
||||
|
||||
// 根据角色id集合查询并返回结果
|
||||
this.list(queryWrapper).forEach(sysRole -> {
|
||||
SimpleDict simpleDict = new SimpleDict();
|
||||
simpleDict.setId(sysRole.getId());
|
||||
simpleDict.setCode(sysRole.getCode());
|
||||
simpleDict.setName(sysRole.getName());
|
||||
simpleDict.setId(sysRole.getRoleId());
|
||||
simpleDict.setCode(sysRole.getRoleCode());
|
||||
simpleDict.setName(sysRole.getRoleName());
|
||||
dictList.add(simpleDict);
|
||||
});
|
||||
}
|
||||
|
@ -257,8 +254,8 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
if (ObjectUtil.isNotNull(sysRoleParam)) {
|
||||
|
||||
// 根据角色名称或编码模糊查询
|
||||
if (ObjectUtil.isNotEmpty(sysRoleParam.getName())) {
|
||||
queryWrapper.and(i -> i.like(SysRole::getName, sysRoleParam.getName()).or().like(SysRole::getCode, sysRoleParam.getName()));
|
||||
if (ObjectUtil.isNotEmpty(sysRoleParam.getRoleName())) {
|
||||
queryWrapper.and(i -> i.like(SysRole::getRoleName, sysRoleParam.getRoleName()).or().like(SysRole::getRoleCode, sysRoleParam.getRoleName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,11 +263,11 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
queryWrapper.eq(SysRole::getStatusFlag, StatusEnum.ENABLE.getCode());
|
||||
|
||||
// 根据排序升序排列,序号越小越在前
|
||||
queryWrapper.orderByAsc(SysRole::getSort);
|
||||
queryWrapper.orderByAsc(SysRole::getRoleSort);
|
||||
this.list(queryWrapper).forEach(sysRole -> {
|
||||
SimpleDict simpleDict = new SimpleDict();
|
||||
simpleDict.setId(sysRole.getId());
|
||||
simpleDict.setName(sysRole.getName() + SymbolConstant.LEFT_SQUARE_BRACKETS + sysRole.getCode() + SymbolConstant.RIGHT_SQUARE_BRACKETS);
|
||||
simpleDict.setId(sysRole.getRoleId());
|
||||
simpleDict.setName(sysRole.getRoleName() + SymbolConstant.LEFT_SQUARE_BRACKETS + sysRole.getRoleCode() + SymbolConstant.RIGHT_SQUARE_BRACKETS);
|
||||
dictList.add(simpleDict);
|
||||
});
|
||||
return dictList;
|
||||
|
@ -282,7 +279,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
if (ObjectUtil.isEmpty(sysRole)) {
|
||||
throw new SystemModularException(SysRoleExceptionEnum.ROLE_NOT_EXIST);
|
||||
}
|
||||
return sysRole.getName();
|
||||
return sysRole.getRoleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -296,7 +293,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
ArrayList<SysRoleResponse> sysRoleResponses = new ArrayList<>();
|
||||
|
||||
LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(SysRole::getId, roleIds);
|
||||
queryWrapper.in(SysRole::getRoleId, roleIds);
|
||||
List<SysRole> sysRoles = this.list(queryWrapper);
|
||||
|
||||
// 角色列表不为空,角色信息转化为SysRoleResponse
|
||||
|
@ -351,7 +348,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
List<String> resourceList = CollectionUtil.newArrayList();
|
||||
LambdaQueryWrapper<SysRoleResource> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(SysRoleResource::getRoleId, roleIdList);
|
||||
sysRoleResourceService.list(queryWrapper).forEach(sysRoleResource -> resourceList.add(sysRoleResource.getResourceId()));
|
||||
sysRoleResourceService.list(queryWrapper).forEach(sysRoleResource -> resourceList.add(sysRoleResource.getResourceCode()));
|
||||
return resourceList;
|
||||
}
|
||||
|
||||
|
@ -363,7 +360,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
* @date 2020/11/5 下午4:12
|
||||
*/
|
||||
private SysRole querySysRole(SysRoleRequest sysRoleRequest) {
|
||||
SysRole sysRole = this.getById(sysRoleRequest.getId());
|
||||
SysRole sysRole = this.getById(sysRoleRequest.getRoleId());
|
||||
if (ObjectUtil.isNull(sysRole)) {
|
||||
throw new SystemModularException(SysRoleExceptionEnum.ROLE_NOT_EXIST);
|
||||
}
|
||||
|
@ -381,13 +378,13 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
if (ObjectUtil.isNotNull(sysRoleRequest)) {
|
||||
|
||||
// 根据名称模糊查询
|
||||
if (ObjectUtil.isNotEmpty(sysRoleRequest.getName())) {
|
||||
queryWrapper.like(SysRole::getName, sysRoleRequest.getName());
|
||||
if (ObjectUtil.isNotEmpty(sysRoleRequest.getRoleName())) {
|
||||
queryWrapper.like(SysRole::getRoleName, sysRoleRequest.getRoleName());
|
||||
}
|
||||
|
||||
// 根据编码模糊查询
|
||||
if (ObjectUtil.isNotEmpty(sysRoleRequest.getCode())) {
|
||||
queryWrapper.like(SysRole::getCode, sysRoleRequest.getCode());
|
||||
if (ObjectUtil.isNotEmpty(sysRoleRequest.getRoleCode())) {
|
||||
queryWrapper.like(SysRole::getRoleCode, sysRoleRequest.getRoleCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -395,7 +392,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||
queryWrapper.eq(SysRole::getDelFlag, YesOrNotEnum.N.getCode());
|
||||
|
||||
// 根据排序升序排列,序号越小越在前
|
||||
queryWrapper.orderByAsc(SysRole::getSort);
|
||||
queryWrapper.orderByAsc(SysRole::getRoleSort);
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.user.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
|
@ -25,37 +25,37 @@ public class SysUser extends BaseEntity {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
@TableId(value = "user_id", type = IdType.ASSIGN_ID)
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@ExcelProperty(value = {"姓名"}, index = 0)
|
||||
@TableField("real_name")
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@ExcelProperty(value = {"昵称"}, index = 1)
|
||||
@TableField("nick_name")
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 账号
|
||||
*/
|
||||
@ExcelProperty(value = {"账号"}, index = 0)
|
||||
@ExcelProperty(value = {"账号"}, index = 2)
|
||||
@TableField("account")
|
||||
private String account;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@ExcelProperty(value = {"密码"}, index = 1)
|
||||
@ExcelProperty(value = {"密码"}, index = 3)
|
||||
@TableField("password")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@ExcelProperty(value = {"昵称"}, index = 2)
|
||||
@TableField("nick_name")
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@ExcelProperty(value = {"姓名"}, index = 3)
|
||||
@TableField("name")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
|
@ -98,34 +98,34 @@ public class SysUser extends BaseEntity {
|
|||
@TableField("tel")
|
||||
private String tel;
|
||||
|
||||
/**
|
||||
* 最后登陆IP
|
||||
*/
|
||||
@ExcelProperty(value = {"最后登陆IP"}, index = 10)
|
||||
@TableField("last_login_ip")
|
||||
private String lastLoginIp;
|
||||
|
||||
/**
|
||||
* 最后登陆时间
|
||||
*/
|
||||
@ExcelProperty(value = {"最后登陆时间"}, index = 11)
|
||||
@TableField("last_login_time")
|
||||
private Date lastLoginTime;
|
||||
|
||||
/**
|
||||
* 是否是超级管理员,超级管理员可以拥有所有权限(Y-是,N-否)
|
||||
*/
|
||||
@ExcelProperty(value = {"是否是超级管理员"}, index = 12)
|
||||
@ExcelProperty(value = {"是否是超级管理员"}, index = 10)
|
||||
@TableField("super_admin_flag")
|
||||
private String superAdminFlag;
|
||||
|
||||
/**
|
||||
* 状态(字典 1正常 2禁用 3冻结)
|
||||
*/
|
||||
@ExcelProperty(value = {"状态"}, index = 13)
|
||||
@ExcelProperty(value = {"状态"}, index = 11)
|
||||
@TableField("status_flag")
|
||||
private Integer statusFlag;
|
||||
|
||||
/**
|
||||
* 最后登陆IP
|
||||
*/
|
||||
@ExcelProperty(value = {"最后登陆IP"}, index = 12)
|
||||
@TableField("last_login_ip")
|
||||
private String lastLoginIp;
|
||||
|
||||
/**
|
||||
* 最后登陆时间
|
||||
*/
|
||||
@ExcelProperty(value = {"最后登陆时间"}, index = 13)
|
||||
@TableField("last_login_time")
|
||||
private Date lastLoginTime;
|
||||
|
||||
/**
|
||||
* 删除标记(Y-已删除,N-未删除)
|
||||
*/
|
||||
|
|
|
@ -19,8 +19,8 @@ public class SysUserDataScope {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
@TableId(value = "user_data_scope_id", type = IdType.ASSIGN_ID)
|
||||
private Long userDataScopeId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
|
@ -31,6 +31,7 @@ public class SysUserDataScope {
|
|||
/**
|
||||
* 机构id
|
||||
*/
|
||||
@TableField("organization_id")
|
||||
private Long organizationId;
|
||||
@TableField("org_id")
|
||||
private Long orgId;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.user.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 企业员工表,用户-组织机构的关联
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/04 11:05
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("sys_user_org")
|
||||
public class SysUserOrg extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId("user_org_id")
|
||||
private Long userOrgId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
@TableField("user_id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 所属机构id
|
||||
*/
|
||||
@TableField("org_id")
|
||||
private Long orgId;
|
||||
|
||||
/**
|
||||
* 职位id
|
||||
*/
|
||||
@TableField("position_id")
|
||||
private Long positionId;
|
||||
|
||||
}
|
|
@ -19,8 +19,8 @@ public class SysUserRole {
|
|||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
@TableId(value = "user_role_id", type = IdType.ASSIGN_ID)
|
||||
private Long userRoleId;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
|
@ -33,4 +33,5 @@ public class SysUserRole {
|
|||
*/
|
||||
@TableField("role_id")
|
||||
private Long roleId;
|
||||
|
||||
}
|
||||
|
|
|
@ -12,11 +12,15 @@ import cn.stylefeng.roses.kernel.resource.api.pojo.resource.ResourceDefinition;
|
|||
import cn.stylefeng.roses.kernel.rule.enums.SexEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
|
||||
import cn.stylefeng.roses.kernel.system.*;
|
||||
import cn.stylefeng.roses.kernel.system.AppServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.DataScopeApi;
|
||||
import cn.stylefeng.roses.kernel.system.ResourceServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.RoleServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUser;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserOrgService;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.DataScopeResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.role.response.SysRoleResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.user.SysUserOrgResponse;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
@ -44,18 +48,18 @@ public class LoginUserFactory {
|
|||
FileInfoApi fileInfoApi = SpringUtil.getBean(FileInfoApi.class);
|
||||
RoleServiceApi roleServiceApi = SpringUtil.getBean(RoleServiceApi.class);
|
||||
ResourceServiceApi resourceServiceApi = SpringUtil.getBean(ResourceServiceApi.class);
|
||||
SysEmployeeApi sysEmployeeApi = SpringUtil.getBean(SysEmployeeApi.class);
|
||||
SysUserOrgService sysUserOrgService = SpringUtil.getBean(SysUserOrgService.class);
|
||||
DataScopeApi dataScopeApi = SpringUtil.getBean(DataScopeApi.class);
|
||||
AppServiceApi appServiceApi = SpringUtil.getBean(AppServiceApi.class);
|
||||
|
||||
// 填充基本信息
|
||||
LoginUser loginUser = new LoginUser();
|
||||
BeanUtil.copyProperties(sysUser, loginUser);
|
||||
Long userId = sysUser.getId();
|
||||
Long userId = sysUser.getUserId();
|
||||
|
||||
// 填充用户主组织机构id
|
||||
SysEmployeeResponse userMainEmployee = sysEmployeeApi.getUserMainEmployee(userId);
|
||||
loginUser.setOrganizationId(userMainEmployee.getOrganizationId());
|
||||
SysUserOrgResponse userOrgInfo = sysUserOrgService.getUserOrgInfo(userId);
|
||||
loginUser.setOrganizationId(userOrgInfo.getOrgId());
|
||||
|
||||
// 获取头像文件详细信息
|
||||
SysFileInfoResponse fileInfoWithoutContent = fileInfoApi.getFileInfoWithoutContent(sysUser.getAvatar());
|
||||
|
@ -122,9 +126,9 @@ public class LoginUserFactory {
|
|||
Set<SimpleDict> simpleRoles = new HashSet<>();
|
||||
for (SysRoleResponse sysRoleResponse : sysRoleResponses) {
|
||||
SimpleDict simpleRole = new SimpleDict();
|
||||
simpleRole.setId(sysRoleResponse.getId());
|
||||
simpleRole.setName(sysRoleResponse.getName());
|
||||
simpleRole.setCode(sysRoleResponse.getCode());
|
||||
simpleRole.setId(sysRoleResponse.getRoleId());
|
||||
simpleRole.setName(sysRoleResponse.getRoleName());
|
||||
simpleRole.setCode(sysRoleResponse.getRoleCode());
|
||||
simpleRoles.add(simpleRole);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.user.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUserOrg;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 企业员工表,用户-组织机构的关联 Mapper 接口
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/04 11:05
|
||||
*/
|
||||
public interface SysUserOrgMapper extends BaseMapper<SysUserOrg> {
|
||||
|
||||
}
|
|
@ -2,20 +2,6 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.stylefeng.roses.kernel.system.modular.user.mapper.SysUserMapper">
|
||||
|
||||
<resultMap id="sysUserResponse" type="cn.stylefeng.roses.kernel.system.modular.user.pojo.response.SysUserResponse">
|
||||
<id column="id" property="id"/>
|
||||
<result column="account" property="account"/>
|
||||
<result column="nick_name" property="nickName"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="avatar" property="avatar"/>
|
||||
<result column="birthday" property="birthday"/>
|
||||
<result column="sex" property="sex"/>
|
||||
<result column="email" property="email"/>
|
||||
<result column="phone" property="phone"/>
|
||||
<result column="tel" property="tel"/>
|
||||
<result column="status_flag" property="statusFlag"/>
|
||||
</resultMap>
|
||||
|
||||
<!--获取用户分页列表-->
|
||||
<select id="findUserPage" resultType="cn.stylefeng.roses.kernel.system.modular.user.pojo.response.SysUserResponse">
|
||||
select sys_user.*,
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="cn.stylefeng.roses.kernel.system.modular.user.mapper.SysUserOrgMapper">
|
||||
|
||||
</mapper>
|
|
@ -1,17 +1,12 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.user.pojo.request;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.exception.enums.EmployeeExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeRequest;
|
||||
import cn.stylefeng.roses.kernel.validator.validators.date.DateValue;
|
||||
import cn.stylefeng.roses.kernel.validator.validators.status.StatusValue;
|
||||
import cn.stylefeng.roses.kernel.validator.validators.unique.TableUniqueValue;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
@ -116,11 +111,17 @@ public class SysUserRequest extends BaseRequest {
|
|||
@NotNull(message = "授权数据不能为空,请检查grantOrgIdList参数", groups = {grantData.class})
|
||||
private List<Long> grantOrgIdList;
|
||||
|
||||
/*==============员工相关信息==========*/
|
||||
/**
|
||||
* 用户所属机构
|
||||
*/
|
||||
@NotNull(message = "用户所属机构不能为空", groups = {add.class, edit.class})
|
||||
private Long orgId;
|
||||
|
||||
@NotNull(message = "员工信息不能为空,请检查sysEmpParam参数", groups = {add.class, edit.class})
|
||||
@Valid
|
||||
private List<SysEmployeeRequest> sysEmployeeRequest;
|
||||
/**
|
||||
* 用户所属机构的职务
|
||||
*/
|
||||
@NotNull(message = "用户职务不能为空", groups = {add.class, edit.class})
|
||||
private Long positionId;
|
||||
|
||||
/**
|
||||
* 状态(字典 1正常 2冻结)
|
||||
|
@ -129,55 +130,6 @@ public class SysUserRequest extends BaseRequest {
|
|||
@StatusValue(message = "状态不正确,请检查状态值是否正确", groups = updateStatus.class)
|
||||
private Integer statusFlag;
|
||||
|
||||
/**
|
||||
* 机构id,这个参数用来查询用户时候传
|
||||
*/
|
||||
private Long organizationId;
|
||||
|
||||
/**
|
||||
* 校验用户主部门是否设置,并且是否设置了多个
|
||||
* <p>
|
||||
* 如果不满足,则会抛出异常
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/21 12:52
|
||||
*/
|
||||
public void validateUserMainEmployee() {
|
||||
int i = 0;
|
||||
|
||||
for (SysEmployeeRequest employeeRequest : sysEmployeeRequest) {
|
||||
if (YesOrNotEnum.Y.getCode().equals(employeeRequest.getMainDeptFlag())) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
// 如果有多个主部门,报错
|
||||
if (i == 0 || i > 1) {
|
||||
throw new SystemModularException(EmployeeExceptionEnum.EMPLOYEE_NOT_OR_MANY);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户的主部门信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/11/21 12:43
|
||||
*/
|
||||
public SysEmployeeRequest getUserMainEmployee() {
|
||||
|
||||
// 校验数据正确性
|
||||
this.validateUserMainEmployee();
|
||||
|
||||
// 查找用户主部门
|
||||
for (SysEmployeeRequest employeeRequest : sysEmployeeRequest) {
|
||||
if (YesOrNotEnum.Y.getCode().equals(employeeRequest.getMainDeptFlag())) {
|
||||
return employeeRequest;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数校验分组:修改密码
|
||||
*/
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.user.pojo.response;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeResponse;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统用户结果
|
||||
|
@ -68,12 +66,18 @@ public class SysUserResponse {
|
|||
private String tel;
|
||||
|
||||
/**
|
||||
* 用户员工信息
|
||||
* 用户所属机构
|
||||
*/
|
||||
private List<SysEmployeeResponse> sysEmployeeResponse;
|
||||
private Long orgId;
|
||||
|
||||
/**
|
||||
* 用户所属机构的职务
|
||||
*/
|
||||
private Long positionId;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Integer statusFlag;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.user.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.system.UserOrgServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUserOrg;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* 用户组织机构关联信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/19 22:17
|
||||
*/
|
||||
public interface SysUserOrgService extends IService<SysUserOrg>, UserOrgServiceApi {
|
||||
|
||||
/**
|
||||
* 更新用户组织机构绑定
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/19 22:29
|
||||
*/
|
||||
void updateUserOrg(Long userId, Long orgId, Long positionId);
|
||||
|
||||
/**
|
||||
* 删除用户对应的组织机构信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/19 22:38
|
||||
*/
|
||||
void deleteUserOrg(Long userId);
|
||||
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.user.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUser;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.pojo.request.SysUserRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.pojo.response.SysUserResponse;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
|
|
@ -3,9 +3,9 @@ package cn.stylefeng.roses.kernel.system.modular.user.service.impl;
|
|||
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUserDataScope;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.mapper.SysUserDataScopeMapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.pojo.request.SysUserRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserDataScopeService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserDataScopeService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -39,7 +39,7 @@ public class SysUserDataScopeServiceImpl extends ServiceImpl<SysUserDataScopeMap
|
|||
for (Long orgId : orgIdList) {
|
||||
SysUserDataScope sysUserDataScope = new SysUserDataScope();
|
||||
sysUserDataScope.setUserId(userId);
|
||||
sysUserDataScope.setOrganizationId(orgId);
|
||||
sysUserDataScope.setOrgId(orgId);
|
||||
sysUserDataScopes.add(sysUserDataScope);
|
||||
}
|
||||
this.saveBatch(sysUserDataScopes);
|
||||
|
@ -49,10 +49,10 @@ public class SysUserDataScopeServiceImpl extends ServiceImpl<SysUserDataScopeMap
|
|||
public List<Long> getUserDataScopeIdList(Long uerId) {
|
||||
LambdaQueryWrapper<SysUserDataScope> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysUserDataScope::getUserId, uerId);
|
||||
queryWrapper.select(SysUserDataScope::getOrganizationId);
|
||||
queryWrapper.select(SysUserDataScope::getOrgId);
|
||||
|
||||
List<SysUserDataScope> list = this.list(queryWrapper);
|
||||
return list.stream().map(SysUserDataScope::getOrganizationId).collect(Collectors.toList());
|
||||
return list.stream().map(SysUserDataScope::getOrgId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.user.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.stylefeng.roses.kernel.system.UserOrgServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUserOrg;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.mapper.SysUserOrgMapper;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserOrgService;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.user.SysUserOrgResponse;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static cn.stylefeng.roses.kernel.system.exception.enums.SysUserOrgExceptionEnum.EMPLOYEE_MANY_MAIN_NOT_FOUND;
|
||||
|
||||
/**
|
||||
* 用户组织机构关联信息
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/19 22:17
|
||||
*/
|
||||
@Service
|
||||
public class SysUserOrgServiceServiceImpl extends ServiceImpl<SysUserOrgMapper, SysUserOrg> implements SysUserOrgService, UserOrgServiceApi {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateUserOrg(Long userId, Long orgId, Long positionId) {
|
||||
|
||||
// 删除旧的绑定信息
|
||||
LambdaUpdateWrapper<SysUserOrg> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(SysUserOrg::getUserId, userId);
|
||||
this.remove(updateWrapper);
|
||||
|
||||
// 新增新的绑定信息
|
||||
SysUserOrg sysUserOrg = new SysUserOrg();
|
||||
sysUserOrg.setUserId(userId);
|
||||
sysUserOrg.setOrgId(orgId);
|
||||
sysUserOrg.setPositionId(positionId);
|
||||
this.save(sysUserOrg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUserOrgResponse getUserOrgInfo(Long userId) {
|
||||
|
||||
LambdaQueryWrapper<SysUserOrg> sysUserOrgLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysUserOrgLambdaQueryWrapper.eq(SysUserOrg::getUserId, userId);
|
||||
|
||||
List<SysUserOrg> list = this.list(sysUserOrgLambdaQueryWrapper);
|
||||
if (list.size() != 1) {
|
||||
throw new SystemModularException(EMPLOYEE_MANY_MAIN_NOT_FOUND);
|
||||
} else {
|
||||
SysUserOrg sysUserOrg = list.get(0);
|
||||
SysUserOrgResponse sysUserOrgResponse = new SysUserOrgResponse();
|
||||
BeanUtil.copyProperties(sysUserOrg, sysUserOrgResponse);
|
||||
return sysUserOrgResponse;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUserOrg(Long userId) {
|
||||
LambdaUpdateWrapper<SysUserOrg> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(SysUserOrg::getUserId, userId);
|
||||
this.remove(updateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getUserOrgFlag(Long orgId, Long positionId) {
|
||||
|
||||
// TODO 测试
|
||||
LambdaQueryWrapper<SysUserOrg> sysUserOrgLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysUserOrgLambdaQueryWrapper.eq(true, SysUserOrg::getOrgId, orgId);
|
||||
sysUserOrgLambdaQueryWrapper.eq(true, SysUserOrg::getPositionId, positionId);
|
||||
|
||||
List<SysUserOrg> list = this.list(sysUserOrgLambdaQueryWrapper);
|
||||
return list.size() > 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package cn.stylefeng.roses.kernel.system.modular.user.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
|
@ -14,8 +13,6 @@ import cn.stylefeng.roses.kernel.office.api.OfficeExcelApi;
|
|||
import cn.stylefeng.roses.kernel.office.api.pojo.report.ExcelExportParam;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict;
|
||||
import cn.stylefeng.roses.kernel.system.DataScopeApi;
|
||||
import cn.stylefeng.roses.kernel.system.SysEmployeeApi;
|
||||
import cn.stylefeng.roses.kernel.system.UserServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.enums.UserStatusEnum;
|
||||
import cn.stylefeng.roses.kernel.system.exception.SystemModularException;
|
||||
|
@ -30,10 +27,10 @@ import cn.stylefeng.roses.kernel.system.modular.user.mapper.SysUserMapper;
|
|||
import cn.stylefeng.roses.kernel.system.modular.user.pojo.request.SysUserRequest;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.pojo.response.SysUserResponse;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserDataScopeService;
|
||||
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.SysUserService;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeRequest;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.organization.SysEmployeeResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.user.SysUserOrgResponse;
|
||||
import cn.stylefeng.roses.kernel.system.pojo.user.UserLoginInfoDTO;
|
||||
import cn.stylefeng.roses.kernel.system.util.DataScopeUtil;
|
||||
import com.alibaba.excel.support.ExcelTypeEnum;
|
||||
|
@ -64,7 +61,7 @@ import java.util.stream.Collectors;
|
|||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService, UserServiceApi {
|
||||
|
||||
@Resource
|
||||
private SysEmployeeApi sysEmployeeApi;
|
||||
private SysUserOrgService sysUserOrgService;
|
||||
|
||||
@Resource
|
||||
private SysUserRoleService sysUserRoleService;
|
||||
|
@ -75,15 +72,12 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
@Resource
|
||||
private OfficeExcelApi officeExcelApi;
|
||||
|
||||
@Resource
|
||||
private DataScopeApi dataScopeApi;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void add(SysUserRequest sysUserRequest) {
|
||||
|
||||
// 获取被添加用户的主组织机构id
|
||||
Long organizationId = sysUserRequest.getUserMainEmployee().getOrganizationId();
|
||||
Long organizationId = sysUserRequest.getOrgId();
|
||||
|
||||
// 获取用户有无该企业的数据权限
|
||||
if (DataScopeUtil.validateDataScopeByOrganizationId(organizationId)) {
|
||||
|
@ -99,16 +93,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
// 保存用户
|
||||
this.save(sysUser);
|
||||
|
||||
Long sysUserId = sysUser.getId();
|
||||
|
||||
// 增加员工信息
|
||||
List<SysEmployeeRequest> sysEmployeeRequest = sysUserRequest.getSysEmployeeRequest();
|
||||
for (SysEmployeeRequest employeeRequest : sysEmployeeRequest) {
|
||||
employeeRequest.setUserId(sysUserId);
|
||||
}
|
||||
|
||||
// 更新用户员工信息
|
||||
sysEmployeeApi.updateEmployee(sysUserId, ListUtil.toList(sysEmployeeRequest));
|
||||
sysUserOrgService.updateUserOrg(sysUser.getUserId(), sysUserRequest.getOrgId(), sysUserRequest.getPositionId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -116,7 +102,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
public void edit(SysUserRequest sysUserRequest) {
|
||||
|
||||
// 获取被添加用户的主组织机构id
|
||||
Long organizationId = sysUserRequest.getUserMainEmployee().getOrganizationId();
|
||||
Long organizationId = sysUserRequest.getOrgId();
|
||||
|
||||
// 获取用户有无该企业的数据权限
|
||||
if (DataScopeUtil.validateDataScopeByOrganizationId(organizationId)) {
|
||||
|
@ -132,16 +118,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
SysUserFactory.fillEditSysUser(sysUser);
|
||||
this.updateById(sysUser);
|
||||
|
||||
Long sysUserId = sysUser.getId();
|
||||
|
||||
// 编辑员工信息
|
||||
List<SysEmployeeRequest> sysEmployeeRequest = sysUserRequest.getSysEmployeeRequest();
|
||||
for (SysEmployeeRequest employeeRequest : sysEmployeeRequest) {
|
||||
employeeRequest.setUserId(sysUserId);
|
||||
}
|
||||
Long sysUserId = sysUser.getUserId();
|
||||
|
||||
// 更新用户员工信息
|
||||
sysEmployeeApi.updateEmployee(sysUserId, ListUtil.toList(sysEmployeeRequest));
|
||||
sysUserOrgService.updateUserOrg(sysUser.getUserId(), sysUserRequest.getOrgId(), sysUserRequest.getPositionId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -168,11 +148,11 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
throw new SystemModularException(SysUserExceptionEnum.USER_CAN_NOT_UPDATE_ADMIN);
|
||||
}
|
||||
|
||||
Long id = sysUser.getId();
|
||||
Long id = sysUser.getUserId();
|
||||
|
||||
// 更新枚举,更新只能更新未删除状态的
|
||||
LambdaUpdateWrapper<SysUser> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.eq(SysUser::getId, id)
|
||||
updateWrapper.eq(SysUser::getUserId, id)
|
||||
.and(i -> i.ne(SysUser::getDelFlag, YesOrNotEnum.Y.getCode()))
|
||||
.set(SysUser::getStatusFlag, statusFlag);
|
||||
|
||||
|
@ -225,8 +205,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
SysUser sysUser = this.querySysUser(sysUserRequest);
|
||||
|
||||
// 获取要授权角色的用户的所属机构
|
||||
SysEmployeeResponse sysEmployeeResponse = sysEmployeeApi.getUserMainEmployee(sysUser.getId());
|
||||
Long organizationId = sysEmployeeResponse.getOrganizationId();
|
||||
SysUserOrgResponse userOrgInfo = sysUserOrgService.getUserOrgInfo(sysUser.getUserId());
|
||||
Long organizationId = userOrgInfo.getOrgId();
|
||||
|
||||
// 判断当前用户有无该用户的权限
|
||||
DataScopeUtil.validateDataScopeByOrganizationId(organizationId);
|
||||
|
@ -241,8 +221,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
SysUser sysUser = this.querySysUser(sysUserRequest);
|
||||
|
||||
// 获取被授权用户的所属机构
|
||||
SysEmployeeResponse sysEmployeeResponse = sysEmployeeApi.getUserMainEmployee(sysUser.getId());
|
||||
Long organizationId = sysEmployeeResponse.getOrganizationId();
|
||||
SysUserOrgResponse userOrgInfo = sysUserOrgService.getUserOrgInfo(sysUser.getUserId());
|
||||
Long organizationId = userOrgInfo.getOrgId();
|
||||
|
||||
// 判断当前用户有无该用户的权限
|
||||
DataScopeUtil.validateDataScopeByOrganizationId(organizationId);
|
||||
|
@ -261,8 +241,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
}
|
||||
|
||||
// 获取被授权用户的所属机构
|
||||
SysEmployeeResponse sysEmployeeResponse = sysEmployeeApi.getUserMainEmployee(sysUser.getId());
|
||||
Long organizationId = sysEmployeeResponse.getOrganizationId();
|
||||
SysUserOrgResponse userOrgInfo = sysUserOrgService.getUserOrgInfo(sysUser.getUserId());
|
||||
Long organizationId = userOrgInfo.getOrgId();
|
||||
|
||||
// 判断当前用户有无该用户的权限
|
||||
DataScopeUtil.validateDataScopeByOrganizationId(organizationId);
|
||||
|
@ -271,10 +251,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
sysUser.setDelFlag(YesOrNotEnum.Y.getCode());
|
||||
this.updateById(sysUser);
|
||||
|
||||
Long userId = sysUser.getId();
|
||||
Long userId = sysUser.getUserId();
|
||||
|
||||
// 删除该用户对应的员工表信息
|
||||
sysEmployeeApi.deleteEmployeeByUserId(userId);
|
||||
sysUserOrgService.deleteUserOrg(userId);
|
||||
|
||||
// 删除该用户对应的用户-角色表关联信息
|
||||
sysUserRoleService.deleteUserRoleListByUserId(userId);
|
||||
|
@ -291,9 +271,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
SysUser sysUser = this.querySysUser(sysUserRequest);
|
||||
BeanUtil.copyProperties(sysUser, sysUserResponse);
|
||||
|
||||
// 获取对应员工信息
|
||||
List<SysEmployeeResponse> sysEmployeeResponse = sysEmployeeApi.getUserAllEmployee(sysUser.getId());
|
||||
sysUserResponse.setSysEmployeeResponse(sysEmployeeResponse);
|
||||
// 获取用户组织绑定信息
|
||||
SysUserOrgResponse userOrgInfo = sysUserOrgService.getUserOrgInfo(sysUser.getUserId());
|
||||
sysUserResponse.setOrgId(userOrgInfo.getOrgId());
|
||||
sysUserResponse.setPositionId(userOrgInfo.getPositionId());
|
||||
|
||||
return sysUserResponse;
|
||||
}
|
||||
|
@ -321,14 +302,14 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
wrapper.ne(SysUser::getSuperAdminFlag, YesOrNotEnum.Y.getCode());
|
||||
|
||||
// 只查询id和name
|
||||
wrapper.select(SysUser::getName, SysUser::getId);
|
||||
wrapper.select(SysUser::getRealName, SysUser::getUserId);
|
||||
List<SysUser> list = this.list(wrapper);
|
||||
|
||||
ArrayList<SimpleDict> results = new ArrayList<>();
|
||||
for (SysUser sysUser : list) {
|
||||
SimpleDict simpleDict = new SimpleDict();
|
||||
simpleDict.setId(sysUser.getId());
|
||||
simpleDict.setName(sysUser.getName());
|
||||
simpleDict.setId(sysUser.getUserId());
|
||||
simpleDict.setName(sysUser.getRealName());
|
||||
results.add(simpleDict);
|
||||
}
|
||||
|
||||
|
@ -383,13 +364,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
|
||||
// 根据用户id获取用户信息实体
|
||||
LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysUserLambdaQueryWrapper.eq(SysUser::getId, userId).eq(SysUser::getDelFlag, YesOrNotEnum.N.getCode());
|
||||
sysUserLambdaQueryWrapper.eq(SysUser::getUserId, userId).eq(SysUser::getDelFlag, YesOrNotEnum.N.getCode());
|
||||
SysUser sysUser = this.getOne(sysUserLambdaQueryWrapper);
|
||||
|
||||
if (sysUser != null) {
|
||||
// 更新用户登录信息
|
||||
SysUser newSysUser = new SysUser();
|
||||
newSysUser.setId(sysUser.getId());
|
||||
newSysUser.setUserId(sysUser.getUserId());
|
||||
newSysUser.setLastLoginIp(ip);
|
||||
newSysUser.setLastLoginTime(date);
|
||||
this.updateById(newSysUser);
|
||||
|
@ -401,7 +382,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
public void deleteUserDataScopeListByOrgIdList(Set<Long> organizationIds) {
|
||||
if (organizationIds != null && organizationIds.size() > 0) {
|
||||
LambdaQueryWrapper<SysUserDataScope> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.in(SysUserDataScope::getOrganizationId, organizationIds);
|
||||
queryWrapper.in(SysUserDataScope::getOrgId, organizationIds);
|
||||
sysUserDataScopeService.remove(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
@ -462,7 +443,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
|
||||
// 组装用户姓名的查询条件
|
||||
if (ObjectUtil.isNotEmpty(sysUserRequest.getName())) {
|
||||
queryWrapper.eq(SysUser::getName, sysUserRequest.getName());
|
||||
queryWrapper.eq(SysUser::getRealName, sysUserRequest.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue