【7.6.0】【sys】【org】更新通用组织机构树接口

pull/55/MERGE
fengshuonan 2023-06-11 11:35:49 +08:00
parent 097994499b
commit b2b45bee8b
7 changed files with 189 additions and 75 deletions

View File

@ -0,0 +1,41 @@
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.sys.modular.org.entity.HrOrganization;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.HrOrganizationRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.service.HrOrganizationService;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
*
*
* @author fengshuonan
* @since 2023/6/11 10:04
*/
@RestController
@ApiResource(name = "通用组织机构接口")
public class CommonOrgController {
@Resource
private HrOrganizationService hrOrganizationService;
/**
*
* <p>
* ps
*
* @author fengshuonan
* @since 2023/6/11 10:31
*/
@GetResource(name = "分页查询", path = "/common/org/tree")
public ResponseData<List<HrOrganization>> commonOrgTree(HrOrganizationRequest hrOrganizationRequest) {
return new SuccessResponseData<>(hrOrganizationService.commonOrgTree(hrOrganizationRequest));
}
}

View File

@ -1,4 +1,4 @@
package cn.stylefeng.roses.kernel.sys.modular.org.controller;
package cn.stylefeng.roses.kernel.sys.modular.org.controller.bak;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;

View File

@ -1,4 +1,4 @@
package cn.stylefeng.roses.kernel.sys.modular.org.controller;
package cn.stylefeng.roses.kernel.sys.modular.org.controller.bak;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;

View File

@ -1,7 +1,8 @@
package cn.stylefeng.roses.kernel.sys.modular.org.entity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseExpandFieldEntity;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.tree.factory.base.AbstractTreeNode;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
@ -10,6 +11,7 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
import java.util.List;
/**
*
@ -17,10 +19,10 @@ import java.math.BigDecimal;
* @author fengshuonan
* @date 2023/06/10 21:23
*/
@TableName("hr_organization")
@TableName(value = "hr_organization", autoResultMap = true)
@Data
@EqualsAndHashCode(callSuper = true)
public class HrOrganization extends BaseEntity {
public class HrOrganization extends BaseExpandFieldEntity implements AbstractTreeNode<HrOrganization> {
/**
*
@ -120,32 +122,37 @@ public class HrOrganization extends BaseEntity {
@ChineseDescription("对接外部主数据的父级机构id")
private String masterOrgParentId;
/**
*
*/
@TableField("expand_field")
@ChineseDescription("拓展字段")
private String expandField;
//-------------------------------非实体字段-------------------------------
//-------------------------------非实体字段-------------------------------
//-------------------------------非实体字段-------------------------------
/**
*
*
*/
@TableField("version_flag")
@ChineseDescription("乐观锁")
private Long versionFlag;
@ChineseDescription("子节点的集合")
private List<HrOrganization> children;
/**
* Y-N-
*/
@TableField("del_flag")
@ChineseDescription("删除标记Y-已删除N-未删除")
private String delFlag;
@Override
public String getNodeId() {
if (this.orgId == null) {
return null;
} else {
return this.orgId.toString();
}
}
/**
*
*/
@TableField("tenant_id")
@ChineseDescription("租户号")
private Long tenantId;
@Override
public String getNodeParentId() {
if (this.orgParentId == null) {
return null;
} else {
return this.orgParentId.toString();
}
}
@Override
public void setChildrenNodes(List<HrOrganization> childrenNodes) {
this.children = childrenNodes;
}
}

View File

@ -0,0 +1,47 @@
package cn.stylefeng.roses.kernel.sys.modular.org.factory;
import cn.hutool.core.convert.Convert;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.HrOrganization;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*
*
* @author fengshuonan
* @since 2023/6/11 11:22
*/
public class OrganizationFactory {
/**
* id
*
* @author fengshuonan
* @since 2023/6/11 11:22
*/
public static Set<Long> getOrgParentIdList(List<HrOrganization> organizationList) {
Set<Long> orgIdList = new HashSet<>();
for (HrOrganization hrOrganization : organizationList) {
String orgParentIdListStr = hrOrganization.getOrgPids();
// 去掉中括号符号
orgParentIdListStr = orgParentIdListStr.replaceAll("\\[", "");
orgParentIdListStr = orgParentIdListStr.replaceAll("]", "");
// 获取所有上级id列表
String[] orgParentIdList = orgParentIdListStr.split(",");
for (String orgIdStr : orgParentIdList) {
Long orgId = Convert.toLong(orgIdStr);
orgIdList.add(orgId);
}
}
return orgIdList;
}
}

View File

@ -15,7 +15,7 @@ import java.util.List;
*/
public interface HrOrganizationService extends IService<HrOrganization> {
/**
/**
*
*
* @param hrOrganizationRequest
@ -24,7 +24,7 @@ public interface HrOrganizationService extends IService<HrOrganization> {
*/
void add(HrOrganizationRequest hrOrganizationRequest);
/**
/**
*
*
* @param hrOrganizationRequest
@ -33,7 +33,7 @@ public interface HrOrganizationService extends IService<HrOrganization> {
*/
void del(HrOrganizationRequest hrOrganizationRequest);
/**
/**
*
*
* @param hrOrganizationRequest
@ -42,7 +42,7 @@ public interface HrOrganizationService extends IService<HrOrganization> {
*/
void edit(HrOrganizationRequest hrOrganizationRequest);
/**
/**
*
*
* @param hrOrganizationRequest
@ -51,24 +51,34 @@ public interface HrOrganizationService extends IService<HrOrganization> {
*/
HrOrganization detail(HrOrganizationRequest hrOrganizationRequest);
/**
/**
*
*
* @param hrOrganizationRequest
* @param hrOrganizationRequest
* @return List<HrOrganization>
* @author fengshuonan
* @date 2023/06/10 21:23
*/
List<HrOrganization> findList(HrOrganizationRequest hrOrganizationRequest);
/**
/**
*
*
* @param hrOrganizationRequest
* @param hrOrganizationRequest
* @return PageResult<HrOrganization>
* @author fengshuonan
* @date 2023/06/10 21:23
*/
PageResult<HrOrganization> findPage(HrOrganizationRequest hrOrganizationRequest);
/**
*
* <p>
* ps
*
* @author fengshuonan
* @since 2023/6/11 10:40
*/
List<HrOrganization> commonOrgTree(HrOrganizationRequest hrOrganizationRequest);
}

View File

@ -2,12 +2,15 @@ package cn.stylefeng.roses.kernel.sys.modular.org.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.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.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.rule.tree.factory.DefaultTreeBuildFactory;
import cn.stylefeng.roses.kernel.sys.modular.org.entity.HrOrganization;
import cn.stylefeng.roses.kernel.sys.modular.org.enums.HrOrganizationExceptionEnum;
import cn.stylefeng.roses.kernel.sys.modular.org.factory.OrganizationFactory;
import cn.stylefeng.roses.kernel.sys.modular.org.mapper.HrOrganizationMapper;
import cn.stylefeng.roses.kernel.sys.modular.org.pojo.request.HrOrganizationRequest;
import cn.stylefeng.roses.kernel.sys.modular.org.service.HrOrganizationService;
@ -16,8 +19,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
*
@ -28,7 +32,7 @@ import java.util.List;
@Service
public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper, HrOrganization> implements HrOrganizationService {
@Override
@Override
public void add(HrOrganizationRequest hrOrganizationRequest) {
HrOrganization hrOrganization = new HrOrganization();
BeanUtil.copyProperties(hrOrganizationRequest, hrOrganization);
@ -53,6 +57,12 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
return this.queryHrOrganization(hrOrganizationRequest);
}
@Override
public List<HrOrganization> findList(HrOrganizationRequest hrOrganizationRequest) {
LambdaQueryWrapper<HrOrganization> wrapper = this.createWrapper(hrOrganizationRequest);
return this.list(wrapper);
}
@Override
public PageResult<HrOrganization> findPage(HrOrganizationRequest hrOrganizationRequest) {
LambdaQueryWrapper<HrOrganization> wrapper = createWrapper(hrOrganizationRequest);
@ -61,9 +71,33 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
}
@Override
public List<HrOrganization> findList(HrOrganizationRequest hrOrganizationRequest) {
public List<HrOrganization> commonOrgTree(HrOrganizationRequest hrOrganizationRequest) {
// 根据条件查询组织机构列表
LambdaQueryWrapper<HrOrganization> wrapper = this.createWrapper(hrOrganizationRequest);
return this.list(wrapper);
wrapper.select(HrOrganization::getOrgId, HrOrganization::getOrgParentId, HrOrganization::getOrgPids,
HrOrganization::getOrgName, HrOrganization::getOrgSort, HrOrganization::getOrgType);
List<HrOrganization> hrOrganizationList = this.list(wrapper);
if (ObjectUtil.isEmpty(hrOrganizationList)) {
return hrOrganizationList;
}
// 如果查询条件不为空,则把相关的查询结果的父级也查询出来,组成一颗完整树
String searchText = hrOrganizationRequest.getSearchText();
List<HrOrganization> parentOrgList = new ArrayList<>();
if (ObjectUtil.isNotEmpty(searchText)) {
Set<Long> orgParentIdList = OrganizationFactory.getOrgParentIdList(hrOrganizationList);
LambdaQueryWrapper<HrOrganization> parentWrapper = new LambdaQueryWrapper<>();
parentWrapper.in(HrOrganization::getOrgId, orgParentIdList);
parentOrgList = this.list(parentWrapper);
}
// 合并两个集合
hrOrganizationList.addAll(parentOrgList);
// 构建树形结构
return new DefaultTreeBuildFactory<HrOrganization>().doTreeBuild(hrOrganizationList);
}
/**
@ -89,43 +123,18 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
private LambdaQueryWrapper<HrOrganization> createWrapper(HrOrganizationRequest hrOrganizationRequest) {
LambdaQueryWrapper<HrOrganization> queryWrapper = new LambdaQueryWrapper<>();
Long orgId = hrOrganizationRequest.getOrgId();
Long orgParentId = hrOrganizationRequest.getOrgParentId();
String orgPids = hrOrganizationRequest.getOrgPids();
String orgName = hrOrganizationRequest.getOrgName();
String orgShortName = hrOrganizationRequest.getOrgShortName();
String orgCode = hrOrganizationRequest.getOrgCode();
BigDecimal orgSort = hrOrganizationRequest.getOrgSort();
Integer statusFlag = hrOrganizationRequest.getStatusFlag();
Integer orgType = hrOrganizationRequest.getOrgType();
String taxNo = hrOrganizationRequest.getTaxNo();
String remark = hrOrganizationRequest.getRemark();
Integer orgLevel = hrOrganizationRequest.getOrgLevel();
String masterOrgId = hrOrganizationRequest.getMasterOrgId();
String masterOrgParentId = hrOrganizationRequest.getMasterOrgParentId();
String expandField = hrOrganizationRequest.getExpandField();
Long versionFlag = hrOrganizationRequest.getVersionFlag();
String delFlag = hrOrganizationRequest.getDelFlag();
Long tenantId = hrOrganizationRequest.getTenantId();
// 如果按文本查询条件不为空,则判断组织机构名称、简称、税号、备注是否有匹配
String searchText = hrOrganizationRequest.getSearchText();
if (StrUtil.isNotEmpty(searchText)) {
queryWrapper.like(HrOrganization::getOrgName, searchText);
queryWrapper.or().like(HrOrganization::getOrgShortName, searchText);
queryWrapper.or().like(HrOrganization::getTaxNo, searchText);
queryWrapper.or().like(HrOrganization::getOrgCode, searchText);
queryWrapper.or().like(HrOrganization::getRemark, searchText);
}
queryWrapper.eq(ObjectUtil.isNotNull(orgId), HrOrganization::getOrgId, orgId);
queryWrapper.eq(ObjectUtil.isNotNull(orgParentId), HrOrganization::getOrgParentId, orgParentId);
queryWrapper.like(ObjectUtil.isNotEmpty(orgPids), HrOrganization::getOrgPids, orgPids);
queryWrapper.like(ObjectUtil.isNotEmpty(orgName), HrOrganization::getOrgName, orgName);
queryWrapper.like(ObjectUtil.isNotEmpty(orgShortName), HrOrganization::getOrgShortName, orgShortName);
queryWrapper.like(ObjectUtil.isNotEmpty(orgCode), HrOrganization::getOrgCode, orgCode);
queryWrapper.eq(ObjectUtil.isNotNull(orgSort), HrOrganization::getOrgSort, orgSort);
queryWrapper.eq(ObjectUtil.isNotNull(statusFlag), HrOrganization::getStatusFlag, statusFlag);
queryWrapper.eq(ObjectUtil.isNotNull(orgType), HrOrganization::getOrgType, orgType);
queryWrapper.like(ObjectUtil.isNotEmpty(taxNo), HrOrganization::getTaxNo, taxNo);
queryWrapper.like(ObjectUtil.isNotEmpty(remark), HrOrganization::getRemark, remark);
queryWrapper.eq(ObjectUtil.isNotNull(orgLevel), HrOrganization::getOrgLevel, orgLevel);
queryWrapper.like(ObjectUtil.isNotEmpty(masterOrgId), HrOrganization::getMasterOrgId, masterOrgId);
queryWrapper.like(ObjectUtil.isNotEmpty(masterOrgParentId), HrOrganization::getMasterOrgParentId, masterOrgParentId);
queryWrapper.like(ObjectUtil.isNotEmpty(expandField), HrOrganization::getExpandField, expandField);
queryWrapper.eq(ObjectUtil.isNotNull(versionFlag), HrOrganization::getVersionFlag, versionFlag);
queryWrapper.like(ObjectUtil.isNotEmpty(delFlag), HrOrganization::getDelFlag, delFlag);
queryWrapper.eq(ObjectUtil.isNotNull(tenantId), HrOrganization::getTenantId, tenantId);
// 根据排序正序查询
queryWrapper.orderByAsc(HrOrganization::getOrgSort);
return queryWrapper;
}