174 lines
6.3 KiB
Java
174 lines
6.3 KiB
Java
package com.engine.salary.service.impl;
|
|
|
|
import com.engine.core.impl.Service;
|
|
import com.engine.salary.entity.salaryformula.ExpressFormula;
|
|
import com.engine.salary.entity.salaryformula.param.SalaryFormulaSaveParam;
|
|
import com.engine.salary.entity.salaryformula.po.FormulaPO;
|
|
import com.engine.salary.entity.salaryformula.po.FormulaVar;
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
|
import com.engine.salary.mapper.formula.FormulaMapper;
|
|
import com.engine.salary.mapper.formula.FormulaVarMapper;
|
|
import com.engine.salary.service.SalaryFormulaService;
|
|
import com.engine.salary.util.db.MapperProxyFactory;
|
|
import com.engine.salary.util.valid.RuntimeTypeEnum;
|
|
import com.engine.salary.util.valid.ValidUtil;
|
|
import com.google.common.collect.Lists;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 薪酬管理公式编辑器
|
|
* <p>Copyright: Copyright (c) 2022</p>
|
|
* <p>Company: 泛微软件</p>
|
|
*
|
|
* @author qiantao
|
|
* @version 1.0
|
|
**/
|
|
@Slf4j
|
|
public class SalaryFormulaServiceImpl extends Service implements SalaryFormulaService {
|
|
|
|
|
|
private FormulaMapper getFormulaMapper() {
|
|
return MapperProxyFactory.getProxy(FormulaMapper.class);
|
|
}
|
|
|
|
private FormulaVarMapper getFormulaVarMapper() {
|
|
return MapperProxyFactory.getProxy(FormulaVarMapper.class);
|
|
}
|
|
|
|
|
|
@Override
|
|
public List<ExpressFormula> listExpressFormula(Collection<Long> formulaIds) {
|
|
formulaIds = formulaIds.stream().filter(id -> id != null && id > 0).collect(Collectors.toList());
|
|
if (CollectionUtils.isEmpty(formulaIds)) {
|
|
return Collections.emptyList();
|
|
}
|
|
try {
|
|
// 当前租户自己新建的公式
|
|
List<FormulaPO> expressFormulas = getFormulaMapper().listByIds(Lists.newArrayList(formulaIds));
|
|
|
|
return expressFormulas.stream()
|
|
.filter(Objects::nonNull)
|
|
.map(m -> {
|
|
ExpressFormula expressFormula = new ExpressFormula();
|
|
BeanUtils.copyProperties(m, expressFormula);
|
|
List<FormulaVar> formulaVarPOS = getFormulaVarMapper().listSome(FormulaVar.builder().formulaId(m.getId()).build());
|
|
expressFormula.setParameters(formulaVarPOS);
|
|
return expressFormula;
|
|
})
|
|
.collect(Collectors.toList());
|
|
} catch (Exception e) {
|
|
log.info("获取公示详情失败", e);
|
|
throw new SalaryRunTimeException("获取公示详情失败");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public ExpressFormula getExpressFormula(Long formulaId) {
|
|
if (formulaId == null || formulaId <= 0) {
|
|
return null;
|
|
}
|
|
try {
|
|
// 当前租户自己新建的公式
|
|
FormulaPO formulaPO = getFormulaMapper().getById(formulaId);
|
|
ExpressFormula expressFormula = new ExpressFormula();
|
|
BeanUtils.copyProperties(formulaPO, expressFormula);
|
|
List<FormulaVar> formulaVarPOS = getFormulaVarMapper().listSome(FormulaVar.builder().formulaId(formulaId).build());
|
|
expressFormula.setParameters(formulaVarPOS);
|
|
|
|
return expressFormula;
|
|
} catch (Exception e) {
|
|
log.info("获取公示详情失败", e);
|
|
throw new SalaryRunTimeException("获取公示详情失败");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public FormulaPO save(SalaryFormulaSaveParam param) {
|
|
|
|
FormulaPO formulaPO = new FormulaPO();
|
|
|
|
String formula = param.getFormula();
|
|
|
|
formulaPO.setName(param.getName());
|
|
formulaPO.setDescription(param.getDescription());
|
|
formulaPO.setModule(param.getModule());
|
|
formulaPO.setUseFor(param.getUseFor());
|
|
formulaPO.setReferenceType(param.getReferenceType());
|
|
formulaPO.setReturnType(param.getReturnType());
|
|
formulaPO.setValidateType(param.getValidateType());
|
|
formulaPO.setExtendParam(param.getExtendParam());
|
|
formulaPO.setFormula(formula);
|
|
formulaPO.setDeleteType(NumberUtils.INTEGER_ZERO);
|
|
|
|
Date now = new Date();
|
|
formulaPO.setCreateTime(now);
|
|
formulaPO.setUpdateTime(now);
|
|
formulaPO.setCreator((long) user.getUID());
|
|
getFormulaMapper().insertIgnoreNull(formulaPO);
|
|
|
|
List<FormulaVar> parameters = param.getParameters();
|
|
parameters.forEach(po -> {
|
|
|
|
formula.replace(po.getFieldName(), po.getFieldId());
|
|
|
|
|
|
po.setFormulaId(formulaPO.getId());
|
|
po.setDeleteType(NumberUtils.INTEGER_ZERO);
|
|
po.setCreator((long) user.getUID());
|
|
po.setCreateTime(now);
|
|
po.setUpdateTime(now);
|
|
getFormulaVarMapper().insertIgnoreNull(po);
|
|
});
|
|
|
|
|
|
return formulaPO;
|
|
}
|
|
|
|
|
|
@Override
|
|
public FormulaPO update(SalaryFormulaSaveParam param) {
|
|
|
|
ValidUtil.doValidator(param, RuntimeTypeEnum.UPDATE);
|
|
|
|
Long id = param.getId();
|
|
FormulaPO formulaPO = getFormulaMapper().getById(id);
|
|
if (formulaPO == null) {
|
|
throw new SalaryRunTimeException("公式不存在或已删除");
|
|
}
|
|
|
|
formulaPO.setName(param.getName());
|
|
formulaPO.setDescription(param.getDescription());
|
|
formulaPO.setModule(param.getModule());
|
|
formulaPO.setUseFor(param.getUseFor());
|
|
formulaPO.setReferenceType(param.getReferenceType());
|
|
formulaPO.setReturnType(param.getReturnType());
|
|
formulaPO.setValidateType(param.getValidateType());
|
|
formulaPO.setExtendParam(param.getExtendParam());
|
|
formulaPO.setFormula(param.getFormula());
|
|
formulaPO.setDeleteType(NumberUtils.INTEGER_ZERO);
|
|
|
|
Date now = new Date();
|
|
formulaPO.setUpdateTime(now);
|
|
formulaPO.setCreator((long) user.getUID());
|
|
getFormulaMapper().updateIgnoreNull(formulaPO);
|
|
|
|
List<FormulaVar> parameters = param.getParameters();
|
|
//删除公式下的变量
|
|
getFormulaVarMapper().deleteByFormulaId(id);
|
|
parameters.forEach(po -> {
|
|
po.setCreator((long) user.getUID());
|
|
po.setCreateTime(now);
|
|
po.setUpdateTime(now);
|
|
getFormulaVarMapper().insertIgnoreNull(po);
|
|
});
|
|
return formulaPO;
|
|
}
|
|
|
|
}
|