mirror of https://gitee.com/stylefeng/roses
【8.3.3】【sys】【org】初始化组织机构的层级维护
parent
0ba098f14e
commit
a18827a820
|
@ -26,7 +26,12 @@ public enum OrgExceptionEnum implements AbstractExceptionEnum {
|
|||
/**
|
||||
* 用户没有该组织机构的权限,无法切换组织机构
|
||||
*/
|
||||
UPDATE_LOGIN_USER_ORG_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10003", "用户没有该组织机构的权限,无法切换组织机构");
|
||||
UPDATE_LOGIN_USER_ORG_ERROR(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10003", "用户没有该组织机构的权限,无法切换组织机构"),
|
||||
|
||||
/**
|
||||
* 机构层级参数为空,参数为:{}
|
||||
*/
|
||||
ORG_LEVEL_EMPTY(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10004", "机构层级参数为空,参数为:{}");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.org.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.OrganizationLevelRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.service.OrganizationLevelService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 组织机构层级控制器
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
@RestController
|
||||
@ApiResource(name = "组织机构层级")
|
||||
public class OrganizationLevelController {
|
||||
|
||||
@Resource
|
||||
private OrganizationLevelService organizationLevelService;
|
||||
|
||||
/**
|
||||
* 获取所有组织机构层级列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/1/22 9:51
|
||||
*/
|
||||
@GetResource(name = "获取机构层级列表", path = "/organizationLevel/list")
|
||||
public ResponseData<List<OrganizationLevel>> list(OrganizationLevelRequest organizationLevelRequest) {
|
||||
return new SuccessResponseData<>(organizationLevelService.findList(organizationLevelRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加组织机构层级
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
@PostResource(name = "添加组织机构层级", path = "/organizationLevel/updateTotal")
|
||||
public ResponseData<?> add(@RequestBody @Validated(OrganizationLevelRequest.edit.class) OrganizationLevelRequest organizationLevelRequest) {
|
||||
organizationLevelService.updateTotal(organizationLevelRequest);
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.org.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 组织机构层级实例类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
@TableName("sys_hr_organization_level")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class OrganizationLevel extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 层级的id
|
||||
*/
|
||||
@TableId(value = "org_level_id", type = IdType.ASSIGN_ID)
|
||||
@ChineseDescription("层级的id")
|
||||
private Long orgLevelId;
|
||||
|
||||
/**
|
||||
* 层级的级别,例如:1、2
|
||||
*/
|
||||
@TableField("level_number")
|
||||
@ChineseDescription("层级的级别,例如:1、2")
|
||||
private Integer levelNumber;
|
||||
|
||||
/**
|
||||
* 层级的名称
|
||||
*/
|
||||
@TableField("level_name")
|
||||
@ChineseDescription("层级的名称")
|
||||
private String levelName;
|
||||
|
||||
/**
|
||||
* 层级的编码,需要填在org表中
|
||||
*/
|
||||
@TableField("level_code")
|
||||
@ChineseDescription("层级的编码,需要填在org表中")
|
||||
private String levelCode;
|
||||
|
||||
/**
|
||||
* 层级的颜色,16进制,不带#
|
||||
*/
|
||||
@TableField("level_color")
|
||||
@ChineseDescription("层级的颜色,16进制,不带#")
|
||||
private String levelColor;
|
||||
|
||||
/**
|
||||
* 删除标记:Y-已删除,N-未删除
|
||||
*/
|
||||
@TableField(value = "del_flag", fill = FieldFill.INSERT)
|
||||
@ChineseDescription("删除标记:Y-已删除,N-未删除")
|
||||
@TableLogic
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 租户号
|
||||
*/
|
||||
@TableField(value = "tenant_id", fill = FieldFill.INSERT)
|
||||
@ChineseDescription("租户号")
|
||||
private Long tenantId;
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.org.enums;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 组织机构层级异常相关枚举
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
@Getter
|
||||
public enum OrganizationLevelExceptionEnum implements AbstractExceptionEnum {
|
||||
|
||||
/**
|
||||
* 查询结果不存在
|
||||
*/
|
||||
ORGANIZATION_LEVEL_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10001", "查询结果不存在");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
*/
|
||||
private final String errorCode;
|
||||
|
||||
/**
|
||||
* 提示用户信息
|
||||
*/
|
||||
private final String userTip;
|
||||
|
||||
OrganizationLevelExceptionEnum(String errorCode, String userTip) {
|
||||
this.errorCode = errorCode;
|
||||
this.userTip = userTip;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.org.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.OrganizationLevelRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.OrganizationLevelVo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 组织机构层级 Mapper 接口
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
public interface OrganizationLevelMapper extends BaseMapper<OrganizationLevel> {
|
||||
|
||||
/**
|
||||
* 获取自定义查询列表
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
List<OrganizationLevelVo> customFindList(@Param("page") Page page, @Param("param")OrganizationLevelRequest request);
|
||||
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
<?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.sys.modular.org.mapper.OrganizationLevelMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel">
|
||||
<id column="org_level_id" property="orgLevelId" />
|
||||
<result column="level_number" property="levelNumber" />
|
||||
<result column="level_name" property="levelName" />
|
||||
<result column="level_code" property="levelCode" />
|
||||
<result column="level_color" property="levelColor" />
|
||||
<result column="del_flag" property="delFlag" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="create_user" property="createUser" />
|
||||
<result column="update_time" property="updateTime" />
|
||||
<result column="update_user" property="updateUser" />
|
||||
<result column="tenant_id" property="tenantId" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
org_level_id,level_number,level_name,level_code,level_color,del_flag,create_time,create_user,update_time,update_user,tenant_id
|
||||
</sql>
|
||||
|
||||
<resultMap id="customResultMap" type="cn.stylefeng.roses.kernel.sys.modular.org.pojo.response.OrganizationLevelVo" extends="BaseResultMap">
|
||||
</resultMap>
|
||||
|
||||
<select id="customFindList" resultMap="customResultMap">
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
sys_hr_organization_level tbl
|
||||
WHERE
|
||||
<where>
|
||||
<if test="param.orgLevelId != null and param.orgLevelId != ''">
|
||||
and tbl.org_level_id like concat('%',#{param.orgLevelId},'%')
|
||||
</if>
|
||||
<if test="param.levelNumber != null and param.levelNumber != ''">
|
||||
and tbl.level_number like concat('%',#{param.levelNumber},'%')
|
||||
</if>
|
||||
<if test="param.levelName != null and param.levelName != ''">
|
||||
and tbl.level_name like concat('%',#{param.levelName},'%')
|
||||
</if>
|
||||
<if test="param.levelCode != null and param.levelCode != ''">
|
||||
and tbl.level_code like concat('%',#{param.levelCode},'%')
|
||||
</if>
|
||||
<if test="param.levelColor != null and param.levelColor != ''">
|
||||
and tbl.level_color like concat('%',#{param.levelColor},'%')
|
||||
</if>
|
||||
<if test="param.delFlag != null and param.delFlag != ''">
|
||||
and tbl.del_flag like concat('%',#{param.delFlag},'%')
|
||||
</if>
|
||||
<if test="param.createTime != null and param.createTime != ''">
|
||||
and tbl.create_time like concat('%',#{param.createTime},'%')
|
||||
</if>
|
||||
<if test="param.createUser != null and param.createUser != ''">
|
||||
and tbl.create_user like concat('%',#{param.createUser},'%')
|
||||
</if>
|
||||
<if test="param.updateTime != null and param.updateTime != ''">
|
||||
and tbl.update_time like concat('%',#{param.updateTime},'%')
|
||||
</if>
|
||||
<if test="param.updateUser != null and param.updateUser != ''">
|
||||
and tbl.update_user like concat('%',#{param.updateUser},'%')
|
||||
</if>
|
||||
<if test="param.tenantId != null and param.tenantId != ''">
|
||||
and tbl.tenant_id like concat('%',#{param.tenantId},'%')
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,29 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.org.pojo.request;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 组织机构层级封装类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class OrganizationLevelRequest extends BaseRequest {
|
||||
|
||||
/**
|
||||
* 组织机构层级不能为空
|
||||
*/
|
||||
@NotEmpty(message = "组织机构层级不能为空", groups = edit.class)
|
||||
@ChineseDescription("组织机构层级")
|
||||
private List<OrganizationLevel> levelList;
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.org.pojo.response;
|
||||
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 组织机构层级返回值封装
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class OrganizationLevelVo extends OrganizationLevel {
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.org.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.OrganizationLevelRequest;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 组织机构层级服务类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
public interface OrganizationLevelService extends IService<OrganizationLevel> {
|
||||
|
||||
/**
|
||||
* 获取机构层级列表
|
||||
*
|
||||
* @param organizationLevelRequest 请求参数
|
||||
* @return List<OrganizationLevel> 返回结果
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
List<OrganizationLevel> findList(OrganizationLevelRequest organizationLevelRequest);
|
||||
|
||||
/**
|
||||
* 新增组织机构层级
|
||||
*
|
||||
* @param organizationLevelRequest 请求参数
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
void updateTotal(OrganizationLevelRequest organizationLevelRequest);
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package cn.stylefeng.roses.kernel.sys.modular.org.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.sys.api.exception.SysException;
|
||||
import cn.stylefeng.roses.kernel.sys.api.exception.enums.OrgExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.entity.OrganizationLevel;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.mapper.OrganizationLevelMapper;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.OrganizationLevelRequest;
|
||||
import cn.stylefeng.roses.kernel.sys.modular.org.service.OrganizationLevelService;
|
||||
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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 组织机构层级业务实现层
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
@Service
|
||||
public class OrganizationLevelServiceImpl extends ServiceImpl<OrganizationLevelMapper, OrganizationLevel> implements OrganizationLevelService {
|
||||
|
||||
@Override
|
||||
public List<OrganizationLevel> findList(OrganizationLevelRequest organizationLevelRequest) {
|
||||
LambdaQueryWrapper<OrganizationLevel> wrapper = this.createWrapper(organizationLevelRequest);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateTotal(OrganizationLevelRequest organizationLevelRequest) {
|
||||
|
||||
// 删除所有的层级数据
|
||||
this.remove(new LambdaQueryWrapper<>());
|
||||
|
||||
// 插入层级数据
|
||||
List<OrganizationLevel> paramLevelList = organizationLevelRequest.getLevelList();
|
||||
|
||||
// 去掉不需要的属性并校验参数
|
||||
List<OrganizationLevel> newList = new ArrayList<>();
|
||||
for (OrganizationLevel organizationLevel : paramLevelList) {
|
||||
if (ObjectUtil.isEmpty(organizationLevel.getLevelNumber())) {
|
||||
throw new SysException(OrgExceptionEnum.ORG_LEVEL_EMPTY, "levelNumber");
|
||||
}
|
||||
if (ObjectUtil.isEmpty(organizationLevel.getLevelName())) {
|
||||
throw new SysException(OrgExceptionEnum.ORG_LEVEL_EMPTY, "levelName");
|
||||
}
|
||||
if (ObjectUtil.isEmpty(organizationLevel.getLevelCode())) {
|
||||
throw new SysException(OrgExceptionEnum.ORG_LEVEL_EMPTY, "levelCode");
|
||||
}
|
||||
|
||||
OrganizationLevel temp = new OrganizationLevel();
|
||||
temp.setLevelNumber(organizationLevel.getLevelNumber());
|
||||
temp.setLevelName(organizationLevel.getLevelName());
|
||||
temp.setLevelCode(organizationLevel.getLevelCode());
|
||||
temp.setLevelColor(organizationLevel.getLevelColor());
|
||||
newList.add(temp);
|
||||
}
|
||||
this.saveBatch(newList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建查询wrapper
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2025/01/22 09:44
|
||||
*/
|
||||
private LambdaQueryWrapper<OrganizationLevel> createWrapper(OrganizationLevelRequest organizationLevelRequest) {
|
||||
LambdaQueryWrapper<OrganizationLevel> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
queryWrapper.orderByAsc(OrganizationLevel::getLevelNumber);
|
||||
|
||||
return queryWrapper;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue