公式异常信息

This commit is contained in:
钱涛 2023-05-16 18:01:38 +08:00
parent cf6b35f6a0
commit a7cc99fdd3
4 changed files with 57 additions and 13 deletions

View File

@ -248,6 +248,8 @@ public class SalaryAcctResultBO {
}
// 主键id
map.put("id", e.getId());
//人员id
map.put("employeeId", e.getEmployeeId());
// 个税扣缴义务人
String taxAgentName = taxAgentNameMap.getOrDefault(e.getTaxAgentId(), StringUtils.EMPTY);
map.put("taxAgentName", taxAgentName);

View File

@ -30,6 +30,10 @@ public interface SalaryAcctProgressService {
*/
void getAndAddCalculatedQty(String cacheKey, Integer calculatedQuantity);
//
void getAndAddCalculatedQty(String cacheKey, Integer calculatedQuantity, String message);
/**
* 计算失败
*

View File

@ -34,6 +34,7 @@ import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import weaver.hrm.User;
import weaver.wechat.util.Utils;
import java.time.Month;
import java.util.*;
@ -168,12 +169,14 @@ public class SalaryAcctCalculateServiceImpl extends Service implements SalaryAcc
Map<Long, SalarySobBackItemPO> salarySobBackItemMap = SalaryEntityUtil.convert2Map(salarySobBackItems, SalarySobBackItemPO::getSalaryItemId);
List<SalaryAcctResultTempPO> salaryAcctResultTempPOS = Lists.newArrayList();
// 开始核算
String noticeMsg = "";
for (SalaryAcctEmployeePO salaryAcctEmployeePO : salaryAcctCalculateBO.getSalaryAcctEmployeePOS()) {
Long salaryAcctEmployeePOId = salaryAcctEmployeePO.getId();
//1 获取当前薪资核算人员的公式中的变量的值
List<CalculateFormulaVarBO.FormulaVarValue> formulaVarValues = formulaVarMap.get(salaryAcctEmployeePO.getEmployeeId() + "_" + salaryAcctEmployeePO.getTaxAgentId());
//2 人员信息
formulaVarValues.addAll(formulaVarMap.get(salaryAcctEmployeePO.getEmployeeId() + ""));
List<CalculateFormulaVarBO.FormulaVarValue> empInfo = formulaVarMap.get(salaryAcctEmployeePO.getEmployeeId() + "");
formulaVarValues.addAll(empInfo);
Map<String, String> formulaVarValueMap = SalaryEntityUtil.convert2Map(formulaVarValues, CalculateFormulaVarBO.FormulaVarValue::getFieldId, CalculateFormulaVarBO.FormulaVarValue::getFieldValue);
// 按照计算好的优先级计算薪资项目的值
for (List<Long> salaryItemIds : salaryAcctCalculateBO.getSalaryItemIdWithPriorityList()) {
@ -195,7 +198,14 @@ public class SalaryAcctCalculateServiceImpl extends Service implements SalaryAcc
}
if (Objects.nonNull(expressFormula)) {
// 运行公式
resultValue = runExpressFormula(expressFormula, formulaVarValueMap, simpleEmployee);
ExcelResult result = runExpressFormula(expressFormula, formulaVarValueMap, simpleEmployee);
resultValue = Utils.null2String(result.getData());
//公式异常
if (!result.isStatus()) {
String username = empInfo.stream().filter(emp -> StringUtils.equals("employeeInfo_username", emp.getFieldId())).findFirst().map(CalculateFormulaVarBO.FormulaVarValue::getFieldValue).orElse("");
String errorMsg = username + "" + salaryItemPO.getName() + "核算异常,原因:" + result.getErrorMsg();
noticeMsg = noticeMsg + errorMsg + "/n";
}
} else {
// 处理取值类型为输入/导入的薪资项目
String key = SalaryFormulaReferenceEnum.SALARY_ITEM.getValue() + SalaryFormulaFieldConstant.FIELD_ID_SEPARATOR + salaryItemPO.getCode();
@ -246,7 +256,9 @@ public class SalaryAcctCalculateServiceImpl extends Service implements SalaryAcc
getSalaryAcctResultTempService(user).batchSave(salaryAcctResultTempPOS);
// 更新薪资核算进度
getSalaryAcctProgressService(user).getAndAddCalculatedQty(SalaryCacheKey.ACCT_PROGRESS + salaryAcctCalculateBO.getSalaryAcctRecordPO().getId(),
salaryAcctCalculateBO.getSalaryAcctEmployeePOS().size());
salaryAcctCalculateBO.getSalaryAcctEmployeePOS().size(),
noticeMsg
);
// 记录子线程执行结果
salaryAcctCalculateBO.getResults().add(new SalaryAcctCalculateBO.Result(true, StringUtils.EMPTY));
} catch (Exception e) {
@ -267,24 +279,27 @@ public class SalaryAcctCalculateServiceImpl extends Service implements SalaryAcc
* @param formulaVarValueMap
* @return
*/
private String runExpressFormula(ExpressFormula expressFormula, Map<String, String> formulaVarValueMap, DataCollectionEmployee simpleEmployee) {
private ExcelResult runExpressFormula(ExpressFormula expressFormula, Map<String, String> formulaVarValueMap, DataCollectionEmployee simpleEmployee) {
// 给公式中的变量填入值
ExcelResult result = new ExcelResult();
try {
List<FormulaVar> formulaVars = ExpressFormulaBO.buildFormulaVar4Accounting(expressFormula, formulaVarValueMap);
ExcelResult run = getFormulaRunService(user).run(expressFormula, formulaVars, simpleEmployee);
if (run.isStatus()) {
return run.getData().toString();
}
result = getFormulaRunService(user).run(expressFormula, formulaVars, simpleEmployee);
} catch (Exception e) {
log.error("express execute fail ", e);
result.setStatus(false);
result.setErrorMsg(e.getMessage());
}
if ("number".equals(expressFormula.getReturnType())) {
return "0";
//核算出错给个默认值
if (!result.isStatus() || result.getData() == null) {
if ("number".equals(expressFormula.getReturnType())) {
result.setData("0");
} else {
result.setData(StringUtils.EMPTY);
}
}
return StringUtils.EMPTY;
return result;
}
/**

View File

@ -6,6 +6,7 @@ import com.engine.salary.entity.salaryacct.dto.SalaryAcctProgressDTO;
import com.engine.salary.service.SalaryAcctProgressService;
import com.engine.salary.util.JsonUtil;
import org.apache.commons.lang3.StringUtils;
import weaver.wechat.util.Utils;
import java.math.BigDecimal;
import java.math.RoundingMode;
@ -44,6 +45,28 @@ public class SalaryAcctProgressServiceImpl extends Service implements SalaryAcct
}
}
@Override
public synchronized void getAndAddCalculatedQty(String cacheKey, Integer calculatedQuantity, String message) {
String resultStr = (String) Util_DataCache.getObjVal(cacheKey);
if (StringUtils.isNotEmpty(resultStr)) {
SalaryAcctProgressDTO salaryAcctProgress = JsonUtil.parseObject(resultStr, SalaryAcctProgressDTO.class);
if (salaryAcctProgress == null || !salaryAcctProgress.isStatus()) {
return;
}
Integer currentCalculatedQuantity = salaryAcctProgress.getCalculatedQuantity() + calculatedQuantity;
salaryAcctProgress.setCalculatedQuantity(
currentCalculatedQuantity > salaryAcctProgress.getTotalQuantity() ? salaryAcctProgress.getTotalQuantity() : currentCalculatedQuantity);
BigDecimal progress = BigDecimal.valueOf(salaryAcctProgress.getCalculatedQuantity())
.divide(BigDecimal.valueOf(salaryAcctProgress.getTotalQuantity()), 4, RoundingMode.HALF_DOWN);
salaryAcctProgress.setProgress(progress.compareTo(BigDecimal.ONE) > 0 ? BigDecimal.ONE : progress);
if (StringUtils.isNotBlank(message)) {
salaryAcctProgress.setMessage(Utils.null2String(salaryAcctProgress.getMessage()) + message);
}
Util_DataCache.setObjVal(cacheKey, JsonUtil.toJsonString(salaryAcctProgress));
}
}
@Override
public void fail(String cacheKey, String message) {
SalaryAcctProgressDTO salaryAcctProgress = new SalaryAcctProgressDTO();