2023-01-18 09:38:43 +08:00
|
|
|
package com.engine.salary.wrapper;
|
|
|
|
|
|
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
|
|
|
import com.engine.core.impl.Service;
|
|
|
|
|
import com.engine.salary.entity.salaryformula.ExpressFormula;
|
|
|
|
|
import com.engine.salary.entity.salaryitem.bo.SalaryItemBO;
|
|
|
|
|
import com.engine.salary.entity.salaryitem.dto.SalaryFieldListDTO;
|
|
|
|
|
import com.engine.salary.entity.salaryitem.dto.SalaryItemFormDTO;
|
|
|
|
|
import com.engine.salary.entity.salaryitem.dto.SalaryItemListDTO;
|
|
|
|
|
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.salarysob.po.SalarySobItemPO;
|
|
|
|
|
import com.engine.salary.enums.SalaryOnOffEnum;
|
|
|
|
|
import com.engine.salary.enums.SalaryRoundingModeEnum;
|
|
|
|
|
import com.engine.salary.enums.SalarySystemTypeEnum;
|
|
|
|
|
import com.engine.salary.enums.SalaryValueTypeEnum;
|
|
|
|
|
import com.engine.salary.enums.salaryitem.SalaryDataTypeEnum;
|
|
|
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
|
|
|
|
import com.engine.salary.service.SalaryFormulaService;
|
|
|
|
|
import com.engine.salary.service.SalaryItemService;
|
|
|
|
|
import com.engine.salary.service.SalarySobItemService;
|
|
|
|
|
import com.engine.salary.service.impl.SalaryFormulaServiceImpl;
|
|
|
|
|
import com.engine.salary.service.impl.SalaryItemServiceImpl;
|
|
|
|
|
import com.engine.salary.service.impl.SalarySobItemServiceImpl;
|
|
|
|
|
import com.engine.salary.util.SalaryEntityUtil;
|
|
|
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
|
|
|
|
import com.engine.salary.util.page.Column;
|
|
|
|
|
import com.engine.salary.util.page.PageInfo;
|
|
|
|
|
import com.engine.salary.util.valid.RuntimeTypeEnum;
|
|
|
|
|
import com.engine.salary.util.valid.ValidUtil;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang.math.NumberUtils;
|
|
|
|
|
import weaver.hrm.User;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 字段管理
|
|
|
|
|
* <p>Copyright: Copyright (c) 2022</p>
|
|
|
|
|
* <p>Company: 泛微软件</p>
|
|
|
|
|
*
|
|
|
|
|
* @author qiantao
|
|
|
|
|
* @version 1.0
|
|
|
|
|
**/
|
|
|
|
|
public class SalaryFieldWrapper extends Service {
|
|
|
|
|
|
|
|
|
|
private SalaryItemService getSalaryItemService(User user) {
|
|
|
|
|
return (SalaryItemService) ServiceUtil.getService(SalaryItemServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SalaryFormulaService getSalaryFormulaService(User user) {
|
|
|
|
|
return (SalaryFormulaService) ServiceUtil.getService(SalaryFormulaServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SalarySobItemService getSalarySobItemService(User user) {
|
|
|
|
|
return (SalarySobItemService) ServiceUtil.getService(SalarySobItemServiceImpl.class, user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 薪资项目列表
|
|
|
|
|
*
|
|
|
|
|
* @param searchParam 查询参数
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public PageInfo<SalaryItemListDTO> listPage(SalaryItemSearchParam searchParam) {
|
|
|
|
|
// 1、查询薪资项目
|
|
|
|
|
//设置查询档案引用项目
|
|
|
|
|
searchParam.setUseInEmployeeSalary(SalaryOnOffEnum.ON.getValue());
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
//获取字段管理的字段列表
|
|
|
|
|
PageInfo<SalaryFieldListDTO> fieldColumnsPage = new PageInfo<>(SalaryFieldListDTO.class);
|
|
|
|
|
List<Column> fieldColumns = fieldColumnsPage.getColumns();
|
|
|
|
|
salaryItemListDTOPage.getColumns().clear();
|
|
|
|
|
salaryItemListDTOPage.setColumns(fieldColumns);
|
|
|
|
|
|
|
|
|
|
// 被薪资账套引用的薪资项目
|
|
|
|
|
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, Collections.emptyList());
|
|
|
|
|
//薪资档案引用时不能删除
|
|
|
|
|
salaryItemListDTOS.forEach(dto -> {
|
|
|
|
|
if (dto.getUseInEmployeeSalary() == 1) {
|
|
|
|
|
dto.setCanDelete(false);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
//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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return salaryItemListDTOPage;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 薪资项目详情
|
|
|
|
|
*
|
|
|
|
|
* @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);
|
|
|
|
|
// 系统薪资项目
|
|
|
|
|
if (Objects.isNull(salaryItemPO)) {
|
|
|
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(98299, "参数错误,薪资项目不存在或已被删除"));
|
|
|
|
|
}
|
|
|
|
|
ExpressFormula expressFormula;
|
|
|
|
|
// // 转换成薪资项目详情dto
|
|
|
|
|
|
|
|
|
|
salaryItemFormDTO = SalaryItemBO.convert2FormDTO(salaryItemPO);
|
|
|
|
|
expressFormula = getSalaryFormulaService(user).getExpressFormula(salaryItemPO.getFormulaId());
|
|
|
|
|
salaryItemFormDTO.setFormulaContent(Optional.ofNullable(expressFormula).map(ExpressFormula::getFormula).orElse(""));
|
|
|
|
|
}
|
|
|
|
|
return salaryItemFormDTO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 保存薪资项目
|
|
|
|
|
*
|
|
|
|
|
* @param saveParam 保存参数
|
|
|
|
|
*/
|
|
|
|
|
public void save(SalaryItemSaveParam saveParam) {
|
|
|
|
|
saveParam.setValueType(SalaryValueTypeEnum.INPUT.getValue());
|
2023-02-09 11:08:03 +08:00
|
|
|
if (null == saveParam.getUseInEmployeeSalary()) {
|
|
|
|
|
saveParam.setUseInEmployeeSalary(NumberUtils.INTEGER_ONE);
|
|
|
|
|
}
|
2023-01-18 09:38:43 +08:00
|
|
|
saveParam.setSystemType(SalarySystemTypeEnum.CUSTOM.getValue());
|
|
|
|
|
|
|
|
|
|
ValidUtil.doValidator(saveParam);
|
|
|
|
|
validParam(saveParam);
|
|
|
|
|
|
|
|
|
|
getSalaryItemService(user).save(saveParam);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validParam(SalaryItemSaveParam saveParam) {
|
|
|
|
|
if (SalarySystemTypeEnum.parseByValue(saveParam.getSystemType()) == null) {
|
|
|
|
|
throw new SalaryRunTimeException("系统内置的薪资项目异常");
|
|
|
|
|
}
|
|
|
|
|
if (SalaryRoundingModeEnum.parseByValue(saveParam.getRoundingMode()) == null) {
|
|
|
|
|
throw new SalaryRunTimeException("舍入规则异常");
|
|
|
|
|
}
|
|
|
|
|
if (SalaryValueTypeEnum.parseByValue(saveParam.getValueType()) == null) {
|
|
|
|
|
throw new SalaryRunTimeException("取值方式异常");
|
|
|
|
|
}
|
|
|
|
|
if (SalaryDataTypeEnum.parseByValue(saveParam.getDataType()) == null) {
|
|
|
|
|
throw new SalaryRunTimeException("字段类型异常");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 编辑薪资项目
|
|
|
|
|
*
|
|
|
|
|
* @param saveParam 更新参数
|
|
|
|
|
*/
|
|
|
|
|
public void update(SalaryItemSaveParam saveParam) {
|
|
|
|
|
saveParam.setValueType(SalaryValueTypeEnum.INPUT.getValue());
|
2023-02-09 18:47:48 +08:00
|
|
|
if (null == saveParam.getUseInEmployeeSalary()) {
|
|
|
|
|
saveParam.setUseInEmployeeSalary(NumberUtils.INTEGER_ONE);
|
|
|
|
|
}
|
2023-01-18 09:38:43 +08:00
|
|
|
saveParam.setSystemType(SalarySystemTypeEnum.CUSTOM.getValue());
|
|
|
|
|
|
|
|
|
|
ValidUtil.doValidator(saveParam, RuntimeTypeEnum.UPDATE);
|
|
|
|
|
validParam(saveParam);
|
|
|
|
|
getSalaryItemService(user).update(saveParam);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除薪资项目
|
|
|
|
|
*
|
|
|
|
|
* @param ids 主键id
|
|
|
|
|
*/
|
|
|
|
|
public void delete(Collection<Long> ids) {
|
|
|
|
|
getSalaryItemService(user).deleteByIds(ids);
|
|
|
|
|
}
|
|
|
|
|
}
|