薪资项目删除校验

This commit is contained in:
钱涛 2023-02-17 14:37:59 +08:00
parent da9b548480
commit abeb4d891d
4 changed files with 117 additions and 112 deletions

View File

@ -4,6 +4,7 @@ import com.engine.salary.entity.salaryitem.param.SalaryItemSaveParam;
import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
import com.engine.salary.enums.SalarySystemTypeEnum;
import com.engine.salary.service.impl.SalaryItemServiceImpl;
import com.engine.salary.util.page.PageInfo;
import java.util.Collection;
@ -38,7 +39,7 @@ public interface SalaryItemService {
/**
* 根据主键id获取薪资项目
*
* @param ids 主键id
* @param ids 主键id
* @return
*/
List<SalaryItemPO> listByIds(Collection<Long> ids);
@ -54,7 +55,7 @@ public interface SalaryItemService {
/**
* 根据名称精确匹配获取薪资项目
*
* @param name 薪资项目名称
* @param name 薪资项目名称
* @return
*/
List<SalaryItemPO> listByName(String name);
@ -92,7 +93,7 @@ public interface SalaryItemService {
/**
* 保存
*
* @param saveParam 保存参数
* @param saveParam 保存参数
*/
void save(SalaryItemSaveParam saveParam);
@ -106,14 +107,21 @@ public interface SalaryItemService {
/**
* 更新
*
* @param saveParam 更新参数
* @param saveParam 更新参数
*/
void update(SalaryItemSaveParam saveParam);
/**
* 根据主键id删除薪资项目
*
* @param ids 主键id
* @param ids 主键id
*/
void deleteByIds(Collection<Long> ids);
/**
* 获取使用中的项目情况
*
* @return
*/
SalaryItemServiceImpl.UsingItem getUsingItem();
}

View File

@ -5,24 +5,28 @@ import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.biz.SalaryItemBiz;
import com.engine.salary.biz.SysSalaryItemBiz;
import com.engine.salary.entity.salaryformula.po.FormulaVar;
import com.engine.salary.entity.salaryitem.bo.SalaryItemBO;
import com.engine.salary.entity.salaryitem.param.SalaryItemSaveParam;
import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
import com.engine.salary.entity.salaryitem.po.SysSalaryItemPO;
import com.engine.salary.entity.salarysob.po.SalarySobBackItemPO;
import com.engine.salary.entity.salarysob.po.SalarySobItemPO;
import com.engine.salary.entity.taxagent.po.TaxAgentPO;
import com.engine.salary.enums.SalarySystemTypeEnum;
import com.engine.salary.enums.SalaryValueTypeEnum;
import com.engine.salary.enums.sicategory.SharedTypeEnum;
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.service.SalaryItemService;
import com.engine.salary.service.SalarySobItemService;
import com.engine.salary.service.TaxAgentService;
import com.engine.salary.service.*;
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.page.SalaryPageUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.BeanUtils;
import weaver.hrm.User;
@ -43,11 +47,24 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService
private SalaryItemBiz salaryItemBiz = new SalaryItemBiz();
private SalarySobItemService getSalarySobItemService(User user) {
return (SalarySobItemService) ServiceUtil.getService(SalarySobItemServiceImpl.class, user);
return ServiceUtil.getService(SalarySobItemServiceImpl.class, user);
}
private TaxAgentService getTaxAgentService(User user) {
return (TaxAgentServiceImpl) ServiceUtil.getService(TaxAgentServiceImpl.class, user);
return ServiceUtil.getService(TaxAgentServiceImpl.class, user);
}
private SysSalaryItemService getSysSalaryItemService(User user) {
return ServiceUtil.getService(SysSalaryItemServiceImpl.class, user);
}
private SalaryFormulaService getSalaryFormulaService(User user) {
return ServiceUtil.getService(SalaryFormulaServiceImpl.class, user);
}
private SalarySobBackItemService getSalarySobBackItemService(User user) {
return ServiceUtil.getService(SalarySobBackItemServiceImpl.class, user);
}
@ -215,16 +232,22 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService
@Override
public void deleteByIds(Collection<Long> ids) {
SalaryItemServiceImpl.UsingItem usingItem = getUsingItem();
List<Long> usingItemIds = usingItem.getUsingItemIds();
List<String> usingCodes = usingItem.getUsingCodes();
// 查询薪资项目
List<SalaryItemPO> salaryItemPOS = listByIds(ids);
if (CollectionUtils.isEmpty(salaryItemPOS)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98299, "参数错误,薪资项目不存在或已被删除"));
}
List<SalarySobItemPO> salarySobItemPOS = getSalarySobItemService(user).listBySalaryItemIds(ids);
if (CollectionUtils.isNotEmpty(salarySobItemPOS)) {
if (CollectionUtils.containsAny(usingItemIds, ids)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98322, "薪资账套正在使用该薪资项目,不允许删除"));
}
List<String> codes = SalaryEntityUtil.properties(salaryItemPOS, SalaryItemPO::getCode, Collectors.toList());
if (CollectionUtils.containsAny(usingCodes, codes)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98322, "公式正在使用该薪资项目,不允许删除"));
}
// 删除薪资项目
@ -242,4 +265,64 @@ public class SalaryItemServiceImpl extends Service implements SalaryItemService
// salaryItemLoggerTemplate.write(loggerContext);
// });
}
/**
* 获取使用中的项目id项目编码公式id
*
* @return 项目id项目编码公式id
*/
@Override
public UsingItem getUsingItem() {
//系统项目
List<SysSalaryItemPO> sysItems = getSysSalaryItemService(user).listAll();
List<Long> sysItemFormulaIds = SalaryEntityUtil.properties(sysItems, SysSalaryItemPO::getFormulaId, Collectors.toList());
//薪资项目
List<SalaryItemPO> items = listAll();
List<Long> itemFormulaIds = SalaryEntityUtil.properties(items, SalaryItemPO::getFormulaId, Collectors.toList());
//账套项目
List<SalarySobItemPO> sobItems = getSalarySobItemService(user).list();
List<Long> sobItemFormulaIds = SalaryEntityUtil.properties(sobItems, SalarySobItemPO::getFormulaId, Collectors.toList());
//回算项目
List<SalarySobBackItemPO> backItems = getSalarySobBackItemService(user).listAll();
List<Long> backItemFormulaIds = SalaryEntityUtil.properties(backItems, SalarySobBackItemPO::getFormulaId, Collectors.toList());
List<Long> usingFormulaIds = new ArrayList<>();
usingFormulaIds.addAll(sysItemFormulaIds);
usingFormulaIds.addAll(itemFormulaIds);
usingFormulaIds.addAll(sobItemFormulaIds);
usingFormulaIds.addAll(backItemFormulaIds);
//账套里的项目项目里的项目
List<Long> sobItemIds = SalaryEntityUtil.properties(sobItems, SalarySobItemPO::getSalaryItemId, Collectors.toList());
List<Long> backItemIds = SalaryEntityUtil.properties(backItems, SalarySobBackItemPO::getSalaryItemId, Collectors.toList());
List<Long> usingItemIds = new ArrayList<>();
usingItemIds.addAll(sobItemIds);
usingItemIds.addAll(backItemIds);
//使用中的code
List<FormulaVar> formulaVars = getSalaryFormulaService(user).listVarByFormulaIds(usingFormulaIds);
List<String> itemCode = formulaVars.stream().map(FormulaVar::getFieldId).map(v -> v.replaceAll("salaryItem_", "")).collect(Collectors.toList());
return UsingItem.builder().usingFormulaIds(usingFormulaIds).usingItemIds(usingItemIds).usingCodes(itemCode).build();
}
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class UsingItem {
private List<Long> usingFormulaIds;
private List<Long> usingItemIds;
private List<String> usingCodes;
}
}

View File

@ -46,16 +46,20 @@ import java.util.*;
public class SalaryFieldWrapper extends Service {
private SalaryItemService getSalaryItemService(User user) {
return (SalaryItemService) ServiceUtil.getService(SalaryItemServiceImpl.class, user);
return ServiceUtil.getService(SalaryItemServiceImpl.class, user);
}
private SalaryFormulaService getSalaryFormulaService(User user) {
return (SalaryFormulaService) ServiceUtil.getService(SalaryFormulaServiceImpl.class, user);
return ServiceUtil.getService(SalaryFormulaServiceImpl.class, user);
}
private SalarySobItemService getSalarySobItemService(User user) {
return (SalarySobItemService) ServiceUtil.getService(SalarySobItemServiceImpl.class, user);
return ServiceUtil.getService(SalarySobItemServiceImpl.class, user);
}
private SalaryItemWrapper getSalaryItemWrapper(User user) {
return ServiceUtil.getService(SalaryItemWrapper.class, user);
}
/**

View File

@ -4,7 +4,6 @@ import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.component.WeaFormOption;
import com.engine.salary.entity.salaryformula.ExpressFormula;
import com.engine.salary.entity.salaryformula.po.FormulaVar;
import com.engine.salary.entity.salaryitem.bo.SalaryItemBO;
import com.engine.salary.entity.salaryitem.bo.SysSalaryItemBO;
import com.engine.salary.entity.salaryitem.dto.SalaryItemFormDTO;
@ -13,7 +12,6 @@ import com.engine.salary.entity.salaryitem.param.SalaryItemSaveParam;
import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
import com.engine.salary.entity.salaryitem.po.SysSalaryItemPO;
import com.engine.salary.entity.salarysob.po.SalarySobBackItemPO;
import com.engine.salary.entity.salarysob.po.SalarySobItemPO;
import com.engine.salary.enums.*;
import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum;
@ -25,14 +23,12 @@ import com.engine.salary.util.SalaryI18nUtil;
import com.engine.salary.util.page.PageInfo;
import com.engine.salary.util.valid.RuntimeTypeEnum;
import com.engine.salary.util.valid.ValidUtil;
import lombok.Builder;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.hrm.User;
import java.util.*;
import java.util.stream.Collectors;
/**
* 薪资项目
@ -72,37 +68,14 @@ public class SalaryItemWrapper extends Service {
* @return
*/
public PageInfo<SalaryItemListDTO> listPage(SalaryItemSearchParam searchParam) {
//清除未被引用的公式
List<SysSalaryItemPO> sysItems = getSysSalaryItemService(user).listAll();
List<Long> sysItemFormulaIds = SalaryEntityUtil.properties(sysItems, SysSalaryItemPO::getFormulaId, Collectors.toList());
List<SalaryItemPO> items = getSalaryItemService(user).listAll();
List<Long> itemFormulaIds = SalaryEntityUtil.properties(items, SalaryItemPO::getFormulaId, Collectors.toList());
List<SalarySobItemPO> sobItems = getSalarySobItemService(user).list();
List<Long> sobItemFormulaIds = SalaryEntityUtil.properties(sobItems, SalarySobItemPO::getFormulaId, Collectors.toList());
List<SalarySobBackItemPO> backItems = getSalarySobBackItemService(user).listAll();
List<Long> backItemFormulaIds = SalaryEntityUtil.properties(backItems, SalarySobBackItemPO::getFormulaId, Collectors.toList());
List<Long> effectiveFormulaIds = new ArrayList<>();
effectiveFormulaIds.addAll(sysItemFormulaIds);
effectiveFormulaIds.addAll(itemFormulaIds);
effectiveFormulaIds.addAll(sobItemFormulaIds);
effectiveFormulaIds.addAll(backItemFormulaIds);
SalaryItemServiceImpl.UsingItem usingItem = getSalaryItemService(user).getUsingItem();
List<Long> usingFormulaIds = usingItem.getUsingFormulaIds();
List<Long> usingItemIds = usingItem.getUsingItemIds();
List<String> usingCodes = usingItem.getUsingCodes();
//删除无用公式
// getSalaryFormulaService(user).deleteNotIn(effectiveFormulaIds);
getSalaryFormulaService(user).deleteNotIn(usingFormulaIds);
//账套里的项目项目里的项目
List<Long> sobItemIds = SalaryEntityUtil.properties(sobItems, SalarySobItemPO::getSalaryItemId, Collectors.toList());
List<Long> backItemIds = SalaryEntityUtil.properties(backItems, SalarySobBackItemPO::getSalaryItemId, Collectors.toList());
List<Long> usingItemIds = new ArrayList<>();
usingItemIds.addAll(sobItemIds);
usingItemIds.addAll(backItemIds);
List<FormulaVar> formulaVars = getSalaryFormulaService(user).listVarByFormulaIds(effectiveFormulaIds);
List<String> itemCode = formulaVars.stream().map(FormulaVar::getFieldId).map(v -> v.replaceAll("salaryItem_", "")).collect(Collectors.toList());
//!!! 从2023-01-23起薪资项目这里不再查询薪资档案引用的项目 !!!
//薪资档案引用的项目转移到字段管理功能项
searchParam.setUseInEmployeeSalary(SalaryOnOffEnum.OFF.getValue());
@ -129,7 +102,7 @@ public class SalaryItemWrapper extends Service {
List<SalaryItemListDTO> salaryItemListDTOS = SalaryItemBO.convert2ListDTO(salaryItemList, expressFormulas, sysSalaryItemPOS);
//系统项目不删除
salaryItemListDTOS.forEach(dto -> {
if (StringUtils.isNotBlank(dto.getSystemName()) || usingItemIds.contains(dto.getId()) || itemCode.contains(dto.getCode())) {
if (StringUtils.isNotBlank(dto.getSystemName()) || usingItemIds.contains(dto.getId()) || usingCodes.contains(dto.getCode())) {
dto.setCanDelete(false);
}
});
@ -267,71 +240,8 @@ public class SalaryItemWrapper extends Service {
* @param ids 主键id
*/
public void delete(Collection<Long> ids) {
//清除未被引用的公式
List<Long> effectiveFormulaIds = getEffectiveFormulaIds();
//删除无用公式
// getSalaryFormulaService(user).deleteNotIn(effectiveFormulaIds);
//账套里的项目项目里的项目
List<Long> sobItemIds = SalaryEntityUtil.properties(sobItems, SalarySobItemPO::getSalaryItemId, Collectors.toList());
List<Long> backItemIds = SalaryEntityUtil.properties(backItems, SalarySobBackItemPO::getSalaryItemId, Collectors.toList());
List<Long> usingItemIds = new ArrayList<>();
usingItemIds.addAll(sobItemIds);
usingItemIds.addAll(backItemIds);
List<FormulaVar> formulaVars = getSalaryFormulaService(user).listVarByFormulaIds(effectiveFormulaIds);
List<String> itemCode = formulaVars.stream().map(FormulaVar::getFieldId).map(v -> v.replaceAll("salaryItem_", "")).collect(Collectors.toList());
// 查询薪资项目
List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listByIds(ids);
if (CollectionUtils.isEmpty(salaryItemPOS)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98299, "参数错误,薪资项目不存在或已被删除"));
}
if (CollectionUtils.containsAny(usingItemIds, ids)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98322, "薪资账套正在使用该薪资项目,不允许删除"));
}
List<String> codes = SalaryEntityUtil.properties(salaryItemPOS, SalaryItemPO::getCode, Collectors.toList());
if (CollectionUtils.containsAny(itemCode, codes)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98322, "公式正在使用该薪资项目,不允许删除"));
}
getSalaryItemService(user).deleteByIds(ids);
}
private usingItemAndFormulaIds getUsingFormulaIds() {
//系统项目
List<SysSalaryItemPO> sysItems = getSysSalaryItemService(user).listAll();
List<Long> sysItemFormulaIds = SalaryEntityUtil.properties(sysItems, SysSalaryItemPO::getFormulaId, Collectors.toList());
//薪资项目
List<SalaryItemPO> items = getSalaryItemService(user).listAll();
List<Long> itemFormulaIds = SalaryEntityUtil.properties(items, SalaryItemPO::getFormulaId, Collectors.toList());
//账套项目
List<SalarySobItemPO> sobItems = getSalarySobItemService(user).list();
List<Long> sobItemFormulaIds = SalaryEntityUtil.properties(sobItems, SalarySobItemPO::getFormulaId, Collectors.toList());
//回算项目
List<SalarySobBackItemPO> backItems = getSalarySobBackItemService(user).listAll();
List<Long> backItemFormulaIds = SalaryEntityUtil.properties(backItems, SalarySobBackItemPO::getFormulaId, Collectors.toList());
List<Long> usingFormulaIds = new ArrayList<>();
usingFormulaIds.addAll(sysItemFormulaIds);
usingFormulaIds.addAll(itemFormulaIds);
usingFormulaIds.addAll(sobItemFormulaIds);
usingFormulaIds.addAll(backItemFormulaIds);
return usingFormulaIds;
}
@Builder
class UsingItemAndFormulaIds {
private List<Long> usingFormulaIds;
private List<Long> usingItemIds;
}
}