weaver-hrm-salary/src/com/engine/salary/wrapper/SalaryItemWrapper.java

217 lines
8.7 KiB
Java
Raw Normal View History

2022-03-21 09:33:21 +08:00
package com.engine.salary.wrapper;
import com.engine.common.util.ServiceUtil;
import com.engine.core.impl.Service;
import com.engine.salary.component.WeaFormOption;
2022-04-15 13:54:47 +08:00
import com.engine.salary.entity.salaryformula.ExpressFormula;
2022-03-21 20:09:10 +08:00
import com.engine.salary.entity.salaryitem.bo.SalaryItemBO;
import com.engine.salary.entity.salaryitem.bo.SysSalaryItemBO;
import com.engine.salary.entity.salaryitem.dto.SalaryItemFormDTO;
import com.engine.salary.entity.salaryitem.dto.SalaryItemListDTO;
2022-03-21 09:33:21 +08:00
import com.engine.salary.entity.salaryitem.param.SalaryItemSaveParam;
import com.engine.salary.entity.salaryitem.param.SalaryItemSearchParam;
import com.engine.salary.entity.salaryitem.po.SalaryItemPO;
2022-03-21 20:09:10 +08:00
import com.engine.salary.entity.salaryitem.po.SysSalaryItemPO;
import com.engine.salary.entity.salarysob.po.SalarySobItemPO;
2022-03-21 09:33:21 +08:00
import com.engine.salary.enums.SalaryItemTypeEnum;
2022-03-21 20:09:10 +08:00
import com.engine.salary.exception.SalaryRunTimeException;
import com.engine.salary.service.SalaryFormulaService;
2022-03-21 09:33:21 +08:00
import com.engine.salary.service.SalaryItemService;
import com.engine.salary.service.SalarySobItemService;
import com.engine.salary.service.SysSalaryItemService;
2022-04-15 13:54:47 +08:00
import com.engine.salary.service.impl.SalaryFormulaServiceImpl;
2022-03-21 09:33:21 +08:00
import com.engine.salary.service.impl.SalaryItemServiceImpl;
2022-03-21 20:09:10 +08:00
import com.engine.salary.service.impl.SalarySobItemServiceImpl;
import com.engine.salary.service.impl.SysSalaryItemServiceImpl;
2022-03-21 09:33:21 +08:00
import com.engine.salary.util.SalaryEntityUtil;
import com.engine.salary.util.SalaryI18nUtil;
2022-04-15 13:54:47 +08:00
import com.engine.salary.util.page.PageInfo;
2022-03-22 10:42:26 +08:00
import com.engine.salary.util.valid.RuntimeTypeEnum;
2022-03-21 20:09:10 +08:00
import com.engine.salary.util.valid.ValidUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.math.NumberUtils;
2022-03-21 09:33:21 +08:00
import weaver.hrm.User;
import java.util.*;
/**
* 薪资项目
* <p>Copyright: Copyright (c) 2022</p>
* <p>Company: 泛微软件</p>
*
* @author qiantao
* @version 1.0
**/
public class SalaryItemWrapper extends Service {
private SalaryItemService getSalaryItemService(User user) {
2022-03-21 20:09:10 +08:00
return (SalaryItemService) ServiceUtil.getService(SalaryItemServiceImpl.class, user);
2022-03-21 09:33:21 +08:00
}
2022-03-21 20:09:10 +08:00
private SysSalaryItemService getSysSalaryItemService(User user) {
return (SysSalaryItemService) ServiceUtil.getService(SysSalaryItemServiceImpl.class, user);
}
2022-04-15 13:54:47 +08:00
private SalaryFormulaService getSalaryFormulaService(User user) {
return (SalaryFormulaService) ServiceUtil.getService(SalaryFormulaServiceImpl.class, user);
}
2022-03-21 09:33:21 +08:00
2022-03-21 20:09:10 +08:00
private SalarySobItemService getSalarySobItemService(User user) {
return (SalarySobItemService) ServiceUtil.getService(SalarySobItemServiceImpl.class, user);
}
2022-03-21 09:33:21 +08:00
/**
* 薪资项目列表
*
* @param searchParam 查询参数
* @return
*/
2022-04-15 13:54:47 +08:00
public PageInfo<SalaryItemListDTO> listPageV2(SalaryItemSearchParam searchParam) {
// 1、查询薪资项目
PageInfo<SalaryItemPO> page = getSalaryItemService(user).listPageByParam(searchParam);
List<SalaryItemPO> salaryItemList = page.getList();
//最终返回的分页对象
PageInfo<SalaryItemListDTO> salaryItemListDTOPage = new PageInfo<>(SalaryItemListDTO.class);
salaryItemListDTOPage.setPageSize(page.getPageSize());
salaryItemListDTOPage.setPageNum(page.getPageNum());
salaryItemListDTOPage.setTotal(page.getTotal());
// 被薪资账套引用的薪资项目
List<SalarySobItemPO> salarySobItems = new ArrayList<>();
if (CollectionUtils.isNotEmpty(salaryItemList)) {
//2、填充公式内容
Set<Long> formulaIds = SalaryEntityUtil.properties(salaryItemList, SalaryItemPO::getFormulaId);
List<ExpressFormula> expressFormulas = getSalaryFormulaService(user).listExpressFormula(formulaIds);
// 转换成薪资项目列表dto
List<SalaryItemListDTO> salaryItemListDTOS = SalaryItemBO.convert2ListDTO(salaryItemList, expressFormulas);
//3、被引用的薪资项目不能删除
Set<Long> salaryItemIds = SalaryEntityUtil.properties(salaryItemList, SalaryItemPO::getId);
salarySobItems = getSalarySobItemService(user).listBySalaryItemIds(salaryItemIds);
if (CollectionUtils.isNotEmpty(salarySobItems)) {
Set<Long> salaryItemIdsUseBySob = SalaryEntityUtil.properties(salarySobItems, SalarySobItemPO::getSalaryItemId);
salaryItemListDTOS.forEach(dto->{
if (salaryItemIdsUseBySob.contains(dto.getId())){
dto.setCanDelete(false);
}
});
}
salaryItemListDTOPage.setList(salaryItemListDTOS);
}
2022-03-21 20:09:10 +08:00
2022-04-15 13:54:47 +08:00
return salaryItemListDTOPage;
2022-03-21 20:09:10 +08:00
2022-04-15 13:54:47 +08:00
}
2022-03-23 18:41:38 +08:00
2022-03-21 20:09:10 +08:00
/**
* 可以删除的薪资项目列表
*
* @param searchParam 查询人员
* @return
*/
2022-04-15 13:54:47 +08:00
public PageInfo<SalaryItemListDTO> listPage4CanDelete(SalaryItemSearchParam searchParam) {
2022-03-21 20:09:10 +08:00
// 查询所有薪资账套中的薪资项目副本
List<SalarySobItemPO> salarySobItemPOS = getSalarySobItemService(user).list();
// 被引用的薪资项目id
Set<Long> salaryItemIds = SalaryEntityUtil.properties(salarySobItemPOS, SalarySobItemPO::getSalaryItemId);
// 排除被引用的薪资项目(被引用的薪资项目不可以删除)
searchParam.setExcludeIds(salaryItemIds);
// 转换成前端所需的数据格式
2022-04-15 13:54:47 +08:00
return listPageV2(searchParam);
2022-03-21 20:09:10 +08:00
}
/**
* 根据主键id获取薪资项目详情
*
* @param ids 薪资项目的主键id
* @return
*/
public List<SalaryItemListDTO> listByIds(Collection<Long> ids) {
List<SalaryItemPO> salaryItemPOS = getSalaryItemService(user).listByIds(ids);
if (CollectionUtils.isEmpty(salaryItemPOS)) {
return Collections.emptyList();
}
// 查询公式详情
Set<Long> formulaIds = SalaryEntityUtil.properties(salaryItemPOS, SalaryItemPO::getFormulaId);
2022-04-16 13:51:53 +08:00
List<ExpressFormula> expressFormulas = getSalaryFormulaService(user).listExpressFormula(formulaIds);
2022-03-21 20:09:10 +08:00
// 转换成薪资项目列表dto
2022-04-16 13:51:53 +08:00
return SalaryItemBO.convert2ListDTO(salaryItemPOS, expressFormulas);
2022-03-21 09:33:21 +08:00
}
2022-03-21 20:09:10 +08:00
/**
* 薪资项目详情
*
* @param id 主键id
* @return
*/
public SalaryItemFormDTO getForm(Long id) {
SalaryItemFormDTO salaryItemFormDTO = new SalaryItemFormDTO();
// 默认可以编辑
salaryItemFormDTO.setCanEdit(NumberUtils.INTEGER_ONE);
if (!Objects.isNull(id)) {
// 查询薪资项目
SalaryItemPO salaryItemPO = getSalaryItemService(user).getById(id);
// 系统薪资项目
SysSalaryItemPO sysSalaryItemPO = getSysSalaryItemService(user).getById(id);
if (Objects.isNull(salaryItemPO) && Objects.isNull(sysSalaryItemPO)) {
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98299, "参数错误,薪资项目不存在或已被删除"));
}
2022-04-16 13:51:53 +08:00
ExpressFormula expressFormula;
2022-03-17 15:14:35 +08:00
// // 转换成薪资项目详情dto
2022-03-21 20:09:10 +08:00
if (Objects.isNull(salaryItemPO)) {
salaryItemFormDTO = SysSalaryItemBO.convert2FormDTO(sysSalaryItemPO);
2022-04-16 13:51:53 +08:00
expressFormula = getSalaryFormulaService(user).getExpressFormula(sysSalaryItemPO.getFormulaId());
2022-03-21 20:09:10 +08:00
} else {
salaryItemFormDTO = SalaryItemBO.convert2FormDTO(salaryItemPO);
2022-04-16 13:51:53 +08:00
expressFormula = getSalaryFormulaService(user).getExpressFormula(salaryItemPO.getFormulaId());
2022-03-21 20:09:10 +08:00
}
2022-04-16 13:51:53 +08:00
salaryItemFormDTO.setFormulaContent(Optional.ofNullable(expressFormula).map(ExpressFormula::getFormula).orElse(""));
2022-03-21 20:09:10 +08:00
}
return salaryItemFormDTO;
}
2022-03-21 09:33:21 +08:00
/**
* 获取薪资项目可选的类型与属性有联动
*
* @return
*/
public Map<String, List<WeaFormOption>> listSalaryItemTypeOption() {
return SalaryEntityUtil.group2ListMap(Arrays.asList(SalaryItemTypeEnum.values()),
e -> e.getCategory().name(),
e -> new WeaFormOption(e.name(), SalaryI18nUtil.getI18nLabel(e.getLabelId(), e.getDefaultLabel())));
}
/**
* 保存薪资项目
*
* @param saveParam 保存参数
*/
public void save(SalaryItemSaveParam saveParam) {
2022-03-21 20:09:10 +08:00
ValidUtil.doValidator(saveParam);
getSalaryItemService(user).save(saveParam);
2022-03-21 09:33:21 +08:00
}
/**
* 编辑薪资项目
*
* @param saveParam 更新参数
*/
public void update(SalaryItemSaveParam saveParam) {
2022-03-22 10:42:26 +08:00
ValidUtil.doValidator(saveParam, RuntimeTypeEnum.UPDATE);
2022-03-21 20:09:10 +08:00
getSalaryItemService(user).update(saveParam);
2022-03-21 09:33:21 +08:00
}
/**
* 删除薪资项目
*
2022-03-21 20:09:10 +08:00
* @param ids 主键id
2022-03-21 09:33:21 +08:00
*/
2022-03-21 20:09:10 +08:00
public void delete(Collection<Long> ids) {
getSalaryItemService(user).deleteByIds(ids);
2022-03-21 09:33:21 +08:00
}
}