mirror of https://gitee.com/stylefeng/roses
【7.6.0】【sys】【org】更新批量删除接口
parent
de3f518212
commit
14fd6e2960
|
@ -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<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑组织机构
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue