222 lines
9.6 KiB
Java
222 lines
9.6 KiB
Java
|
|
package com.engine.salary.service.impl;
|
||
|
|
|
||
|
|
import cn.hutool.core.bean.BeanUtil;
|
||
|
|
import com.engine.common.util.ServiceUtil;
|
||
|
|
import com.engine.core.impl.Service;
|
||
|
|
import com.engine.salary.entity.ly.param.LyPZGenParam;
|
||
|
|
import com.engine.salary.entity.ly.param.LySalaryReportQueryParam;
|
||
|
|
import com.engine.salary.entity.ly.po.LyKjkmTest;
|
||
|
|
import com.engine.salary.entity.ly.po.LySalaryReportPO;
|
||
|
|
import com.engine.salary.entity.ly.po.LySocialReportPO;
|
||
|
|
import com.engine.salary.entity.salaryformula.ExpressFormula;
|
||
|
|
import com.engine.salary.entity.salaryformula.po.FormulaVar;
|
||
|
|
import com.engine.salary.enums.ly.LyPZTypeEnum;
|
||
|
|
import com.engine.salary.enums.salaryformula.ReferenceTypeEnum;
|
||
|
|
import com.engine.salary.formlua.entity.parameter.DataType;
|
||
|
|
import com.engine.salary.formlua.entity.standard.ExcelResult;
|
||
|
|
import com.engine.salary.service.FormulaRunService;
|
||
|
|
import com.engine.salary.service.LyPZService;
|
||
|
|
import com.engine.salary.service.LySalaryReportService;
|
||
|
|
import com.engine.salary.service.LySocialReportService;
|
||
|
|
import com.engine.salary.util.page.PageInfo;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.apache.commons.lang3.math.NumberUtils;
|
||
|
|
import weaver.conn.RecordSet;
|
||
|
|
import weaver.general.Util;
|
||
|
|
import weaver.hrm.User;
|
||
|
|
|
||
|
|
import java.math.BigDecimal;
|
||
|
|
import java.util.ArrayList;
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.List;
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @author Harryxzy
|
||
|
|
* @ClassName LyPZServiceImpl
|
||
|
|
* @date 2024/08/27 10:14
|
||
|
|
* @description
|
||
|
|
*/
|
||
|
|
@Slf4j
|
||
|
|
public class LyPZServiceImpl extends Service implements LyPZService {
|
||
|
|
|
||
|
|
private LySalaryReportService getLySalaryReportService(User user) {
|
||
|
|
return ServiceUtil.getService(LySalaryReportServiceImpl.class, user);
|
||
|
|
}
|
||
|
|
|
||
|
|
private LySocialReportService getLySocialReportService(User user) {
|
||
|
|
return ServiceUtil.getService(LySocialReportServiceImpl.class, user);
|
||
|
|
}
|
||
|
|
|
||
|
|
private FormulaRunService getFormulaRunService(User user) {
|
||
|
|
return ServiceUtil.getService(FormulaRunServiceImpl.class, user);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void genPZ(LyPZGenParam queryParam) {
|
||
|
|
List<List<FormulaVar>> formulaVarsList = new ArrayList<>();
|
||
|
|
if (queryParam.getPzlx().equals(LyPZTypeEnum.XZFFPZ.getValue()) || queryParam.getPzlx().equals(LyPZTypeEnum.XZJTPZ.getValue())) {
|
||
|
|
// 是工资单凭证
|
||
|
|
Map<String, Object> resultMap = getLySalaryReportService(user).listSalaryReport(LySalaryReportQueryParam.builder().salaryMonth(queryParam.getSalaryMonth()).export(true).build());
|
||
|
|
List<LySalaryReportPO> dataList = ((PageInfo<LySalaryReportPO>)resultMap.get("data")).getList();
|
||
|
|
// 将每一个结果转换成map的格式并作为变量存储
|
||
|
|
for (LySalaryReportPO po : dataList) {
|
||
|
|
Map<String, Object> dataMap = BeanUtil.beanToMap(po);
|
||
|
|
List<FormulaVar> formulaVars = new ArrayList<>();
|
||
|
|
for (Map.Entry<String,Object> entry : dataMap.entrySet()) {
|
||
|
|
FormulaVar build = FormulaVar.builder()
|
||
|
|
.fieldId(entry.getKey())
|
||
|
|
.content(Util.null2String(entry.getValue()))
|
||
|
|
.fieldType(DataType.STRING)
|
||
|
|
.build();
|
||
|
|
formulaVars.add(build);
|
||
|
|
}
|
||
|
|
formulaVarsList.add(formulaVars);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
// 是社保公积金凭证
|
||
|
|
Map<String, Object> resultMap = getLySocialReportService(user).listSIReport(LySalaryReportQueryParam.builder().salaryMonth(queryParam.getSalaryMonth()).export(true).build());
|
||
|
|
List<LySocialReportPO> dataList = ((PageInfo<LySocialReportPO>)resultMap.get("data")).getList();
|
||
|
|
// 将每一个结果转换成map的格式并作为变量存储
|
||
|
|
for (LySocialReportPO po : dataList) {
|
||
|
|
Map<String, Object> dataMap = BeanUtil.beanToMap(po);
|
||
|
|
List<FormulaVar> formulaVars = new ArrayList<>();
|
||
|
|
for (Map.Entry<String,Object> entry : dataMap.entrySet()) {
|
||
|
|
FormulaVar build = FormulaVar.builder()
|
||
|
|
.fieldId(entry.getKey())
|
||
|
|
.content(Util.null2String(entry.getValue()))
|
||
|
|
.fieldType(DataType.STRING)
|
||
|
|
.build();
|
||
|
|
formulaVars.add(build);
|
||
|
|
}
|
||
|
|
formulaVarsList.add(formulaVars);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
RecordSet rs = new RecordSet();
|
||
|
|
|
||
|
|
// 根据科目编码获取科会计科目全路径名称
|
||
|
|
// 获取所有科目编码信息
|
||
|
|
Map<String, String> kmbmInfoMap = new HashMap<>();
|
||
|
|
rs.execute("select kmbm,kmmc from uf_lytest");
|
||
|
|
while (rs.next()) {
|
||
|
|
kmbmInfoMap.put(rs.getString("kmbm"), rs.getString("kmmc"));
|
||
|
|
}
|
||
|
|
String fullNameKmgm = getFullPathKjkm("1234", kmbmInfoMap);
|
||
|
|
|
||
|
|
// 查询这个凭证对应所需的会计科目
|
||
|
|
rs.execute("select kmbm,kmmc,xzxm,fx from uf_lytest");
|
||
|
|
List<LyKjkmTest> kjkmList = new ArrayList<>();
|
||
|
|
while (rs.next()) {
|
||
|
|
String xzxm = rs.getString("xzxm");
|
||
|
|
ExpressFormula expressFormula = ExpressFormula.builder().name("t")
|
||
|
|
.referenceType(ReferenceTypeEnum.FORMULA.getValue())
|
||
|
|
.formula(xzxm)
|
||
|
|
.formulaRunScript(xzxm)
|
||
|
|
.extendParam("{}")
|
||
|
|
.build();
|
||
|
|
kjkmList.add(LyKjkmTest.builder()
|
||
|
|
.kjkmId(rs.getString("kmbm"))
|
||
|
|
.kjkmName(rs.getString("kmmc"))
|
||
|
|
.kjkmDirection(rs.getString("fx"))
|
||
|
|
.kjkmSalaryItemFormula(expressFormula)
|
||
|
|
.build());
|
||
|
|
}
|
||
|
|
|
||
|
|
Map<String, BigDecimal> kjkmValueMap = new HashMap<>();
|
||
|
|
for(List<FormulaVar> varList : formulaVarsList) {
|
||
|
|
// 每一条记录都需要执行一遍公式并把结果相加
|
||
|
|
for (LyKjkmTest kjkm : kjkmList) {
|
||
|
|
// 给公式中的变量填入值
|
||
|
|
ExcelResult result = new ExcelResult();
|
||
|
|
try {
|
||
|
|
result = getFormulaRunService(user).run(kjkm.getKjkmSalaryItemFormula(), varList, null);
|
||
|
|
} catch (Exception e) {
|
||
|
|
log.error("express execute fail ", e);
|
||
|
|
result.setStatus(false);
|
||
|
|
result.setErrorMsg(e.getMessage());
|
||
|
|
}
|
||
|
|
//核算出错,给个默认值
|
||
|
|
if (!result.isStatus() || result.getData() == null) {
|
||
|
|
log.error("express execute fail status ", result.getErrorMsg());
|
||
|
|
result.setData("0");
|
||
|
|
}
|
||
|
|
String resultStr = result.getData() == null ? "0" : result.getData().toString();
|
||
|
|
BigDecimal resultBigDecimal = NumberUtils.isCreatable(resultStr) ? new BigDecimal(resultStr) : BigDecimal.ZERO;
|
||
|
|
kjkmValueMap.put(kjkm.getKjkmId(), kjkmValueMap.getOrDefault(kjkm.getKjkmId(), new BigDecimal(0)).add(resultBigDecimal));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
// 所有的结果都算好了,封装凭证预览
|
||
|
|
System.out.println(kjkmValueMap);
|
||
|
|
|
||
|
|
|
||
|
|
// test 生成xml
|
||
|
|
// List<LyVoucherAss> assList = new ArrayList<>();
|
||
|
|
// assList.add(LyVoucherAss.builder()
|
||
|
|
// .pkChecktype("first")
|
||
|
|
// .pkCheckvalue("ff")
|
||
|
|
// .build());
|
||
|
|
// assList.add(LyVoucherAss.builder()
|
||
|
|
// .pkChecktype("second")
|
||
|
|
// .pkCheckvalue("fd")
|
||
|
|
// .build());
|
||
|
|
//
|
||
|
|
// List<LyVoucherDetail> lyVoucherDetails = new ArrayList<>();
|
||
|
|
// lyVoucherDetails.add(LyVoucherDetail.builder()
|
||
|
|
// .detailindex("what")
|
||
|
|
// .explanation("hfdsuhfad")
|
||
|
|
// .debitamount("1000")
|
||
|
|
// .pkCurrtype("RMB")
|
||
|
|
// .pkAccasoa("kemu")
|
||
|
|
// .ass(assList)
|
||
|
|
// .build());
|
||
|
|
//
|
||
|
|
// LyVoucher build = LyVoucher.builder()
|
||
|
|
// .pkVoucher("123")
|
||
|
|
// .pkVouchertype("type")
|
||
|
|
// .year("2024")
|
||
|
|
// .pkSystem("system")
|
||
|
|
// .voucherkind("0")
|
||
|
|
// .pkAccountingbook("1")
|
||
|
|
// .period("04")
|
||
|
|
// .prepareddate("2024-08-01")
|
||
|
|
// .pkPrepared("par")
|
||
|
|
// .pkOrg("org")
|
||
|
|
// .details(lyVoucherDetails)
|
||
|
|
// .build();
|
||
|
|
//
|
||
|
|
// String xml = XStreamUtil.marshal(build);
|
||
|
|
// System.out.println(xml);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 根据科目编码获取对应的全路径名称
|
||
|
|
* @param kmbm
|
||
|
|
* @param kmbmInfoMap
|
||
|
|
* @return
|
||
|
|
*/
|
||
|
|
private String getFullPathKjkm(String kmbm, Map<String, String> kmbmInfoMap) {
|
||
|
|
int length = kmbm.length();
|
||
|
|
if (length == 4) {
|
||
|
|
// 是一级科目,不需要拼接
|
||
|
|
return kmbmInfoMap.getOrDefault(kmbm, "");
|
||
|
|
} else if (length == 6) {
|
||
|
|
// 是二级科目,先找一级科目
|
||
|
|
String firstKjkmbm = kmbm.substring(0, 4);
|
||
|
|
String firstKjkm = kmbmInfoMap.getOrDefault(firstKjkmbm, "");
|
||
|
|
return firstKjkm + "/" + kmbmInfoMap.getOrDefault(kmbm, "");
|
||
|
|
} else if (length == 8) {
|
||
|
|
// 是三级科目
|
||
|
|
String firstKjkmbm = kmbm.substring(0, 4);
|
||
|
|
String firstKjkm = kmbmInfoMap.getOrDefault(firstKjkmbm, "");
|
||
|
|
String secondKjkmbm = kmbm.substring(0, 6);
|
||
|
|
String secondKjkm = kmbmInfoMap.getOrDefault(secondKjkmbm, "");
|
||
|
|
return firstKjkm + "/" + secondKjkm + "/" +kmbmInfoMap.getOrDefault(kmbm, "");
|
||
|
|
} else {
|
||
|
|
return "科目编码格式错误!";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|