【8.3.3】【sys】【org】初始化组织机构的层级维护

dev-8.3.3
stylefeng 2025-01-22 10:28:12 +08:00
parent 0ba098f14e
commit a18827a820
10 changed files with 426 additions and 1 deletions

View File

@ -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", "机构层级参数为空,参数为:{}");
/**
*

View File

@ -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<>();
}
}

View File

@ -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;
/**
* 12
*/
@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;
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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>

View File

@ -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;
}

View File

@ -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 {
}

View File

@ -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);
}

View File

@ -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;
}
}