【7.6.0】【sys】【org】更新批量删除接口

pull/55/MERGE
fengshuonan 2023-06-11 17:03:34 +08:00
parent de3f518212
commit 14fd6e2960
4 changed files with 76 additions and 21 deletions

View File

@ -1,6 +1,7 @@
package cn.stylefeng.roses.kernel.sys.modular.org.controller;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
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;
@ -52,6 +53,18 @@ public class HrOrganizationController {
return new SuccessResponseData<>();
}
/**
*
*
* @author fengshuonan
* @date 2023/06/10 21:23
*/
@PostResource(name = "批量删除组织机构", path = "/hrOrganization/batchDelete")
public ResponseData<?> batchDelete(@RequestBody @Validated(BaseRequest.batchDelete.class) HrOrganizationRequest hrOrganizationRequest) {
hrOrganizationService.batchDelete(hrOrganizationRequest);
return new SuccessResponseData<>();
}
/**
*
*

View File

@ -7,8 +7,10 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Set;
/**
*
@ -58,13 +60,7 @@ public class HrOrganizationRequest extends BaseRequest {
*/
@NotBlank(message = "组织编码不能为空", groups = {add.class, edit.class})
@ChineseDescription("组织编码")
@TableUniqueValue(
message = "组织编码存在重复",
groups = {add.class, edit.class},
tableName = "hr_organization",
columnName = "org_code",
idFieldName = "org_id",
excludeLogicDeleteItems = true)
@TableUniqueValue(message = "组织编码存在重复", groups = {add.class, edit.class}, tableName = "hr_organization", columnName = "org_code", idFieldName = "org_id", excludeLogicDeleteItems = true)
private String orgCode;
/**
@ -118,4 +114,13 @@ public class HrOrganizationRequest extends BaseRequest {
@ChineseDescription("对接外部主数据的父级机构id")
private String masterOrgParentId;
/**
* id
* <p>
*
*/
@NotEmpty(message = "组织机构id集合不能为空", groups = {batchDelete.class})
@ChineseDescription("组织机构id集合")
private Set<Long> orgIdList;
}

View File

@ -33,6 +33,14 @@ public interface HrOrganizationService extends IService<HrOrganization> {
*/
void del(HrOrganizationRequest hrOrganizationRequest);
/**
*
*
* @author fengshuonan
* @since 2023/6/11 16:59
*/
void batchDelete(HrOrganizationRequest hrOrganizationRequest);
/**
*
*

View File

@ -53,22 +53,30 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
public void del(HrOrganizationRequest hrOrganizationRequest) {
// 查询被删除组织机构的所有子级节点
Set<Long> totalOrgIdSet = DbOperatorContext.me().findSubListByParentId("hr_organization", "org_pids", "org_id", hrOrganizationRequest.getOrgId());
Set<Long> totalOrgIdSet = DbOperatorContext.me().findSubListByParentId(
"hr_organization", "org_pids", "org_id", hrOrganizationRequest.getOrgId());
totalOrgIdSet.add(hrOrganizationRequest.getOrgId());
// 判断业务是否和组织机构有绑定关系
Map<String, RemoveOrgCallbackApi> callbackApiMap = SpringUtil.getBeansOfType(RemoveOrgCallbackApi.class);
for (RemoveOrgCallbackApi removeOrgCallbackApi : callbackApiMap.values()) {
removeOrgCallbackApi.validateHaveOrgBind(totalOrgIdSet);
// 执行删除操作
this.baseDelete(totalOrgIdSet);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void batchDelete(HrOrganizationRequest hrOrganizationRequest) {
Set<Long> orgIdList = hrOrganizationRequest.getOrgIdList();
// 批量查询组织机构下的下属机构
for (Long orgId : orgIdList) {
// 查询被删除组织机构的所有子级节点
Set<Long> tempSubOrgIdList = DbOperatorContext.me().findSubListByParentId(
"hr_organization", "org_pids", "org_id", orgId);
orgIdList.addAll(tempSubOrgIdList);
}
// 联动删除所有和本组织机构相关其他业务数据
for (RemoveOrgCallbackApi removeOrgCallbackApi : callbackApiMap.values()) {
removeOrgCallbackApi.removeOrgAction(totalOrgIdSet);
}
// 批量删除所有相关节点
this.removeBatchByIds(totalOrgIdSet);
// 执行删除操作
this.baseDelete(orgIdList);
}
@Override
@ -105,8 +113,7 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
// 根据条件查询组织机构列表
LambdaQueryWrapper<HrOrganization> wrapper = this.createWrapper(hrOrganizationRequest);
wrapper.select(HrOrganization::getOrgId, HrOrganization::getOrgParentId, HrOrganization::getOrgPids,
HrOrganization::getOrgName, HrOrganization::getOrgSort, HrOrganization::getOrgType);
wrapper.select(HrOrganization::getOrgId, HrOrganization::getOrgParentId, HrOrganization::getOrgPids, HrOrganization::getOrgName, HrOrganization::getOrgSort, HrOrganization::getOrgType);
List<HrOrganization> hrOrganizationList = this.list(wrapper);
if (ObjectUtil.isEmpty(hrOrganizationList)) {
@ -173,4 +180,26 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
return queryWrapper;
}
/**
*
*
* @author fengshuonan
* @since 2023/6/11 17:00
*/
private void baseDelete(Set<Long> totalOrgIdSet) {
// 判断业务是否和组织机构有绑定关系
Map<String, RemoveOrgCallbackApi> callbackApiMap = SpringUtil.getBeansOfType(RemoveOrgCallbackApi.class);
for (RemoveOrgCallbackApi removeOrgCallbackApi : callbackApiMap.values()) {
removeOrgCallbackApi.validateHaveOrgBind(totalOrgIdSet);
}
// 联动删除所有和本组织机构相关其他业务数据
for (RemoveOrgCallbackApi removeOrgCallbackApi : callbackApiMap.values()) {
removeOrgCallbackApi.removeOrgAction(totalOrgIdSet);
}
// 批量删除所有相关节点
this.removeBatchByIds(totalOrgIdSet);
}
}