付款申请单生成收款处理单

This commit is contained in:
zhangzhiguo 2026-01-08 16:12:18 +08:00
parent 17f5956972
commit 1c2d589c84
3 changed files with 422 additions and 0 deletions

View File

@ -0,0 +1,10 @@
package kd.ec.contr;
import java.util.List;
import java.util.Map;
public interface KsRepAmountService {
void payRepAmount(List<Map<String, Object>> var1);
void incomeRepAmount(List<Map<String, Object>> var1);
}

View File

@ -0,0 +1,369 @@
package kd.ec.contr;
import kd.bos.dataentity.OperateOption;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.db.tx.TX;
import kd.bos.db.tx.TXHandle;
import kd.bos.entity.EntityMetadataCache;
import kd.bos.entity.MainEntityType;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.exception.KDBizException;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.DeleteServiceHelper;
import kd.bos.servicehelper.operation.OperationServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.ec.basedata.common.enums.BillStatusEnum;
import kd.ec.basedata.common.enums.PayDirectionEnum;
import kd.ec.contract.mservice.bill.RepAmountServiceImpl;
import java.math.BigDecimal;
import java.util.*;
public class KsRepAmountServiceImpl extends RepAmountServiceImpl implements KsRepAmountService {
private static final Log log = LogFactory.getLog(KsRepAmountServiceImpl.class);
public static final String SOURCEPK = "sourcepk";
public static final String SOURCEENTRYPK = "sourceentrypk";
public static final String OPERATE = "operate";
public static final String OPERATION = "operation";
public static final String AMOUNT = "amount";
public static final String REFUND_AMOUNT = "refundamt";
@Override
public void payRepAmount(List<Map<String, Object>> dataList) {
super.payRepAmount(dataList);
log.info("KsRepAmountServiceImpl:payRepAmount");
}
@Override
public void incomeRepAmount(List<Map<String, Object>> dataList) {
//super.incomeRepAmount(dataList);
try (TXHandle txType = TX.requiresNew("ksincomeRepAmount")) {
if (dataList != null && dataList.size() > 0) {
Map<Long, Map<String, BigDecimal>> fiBillIdEntryAmtMap = new HashMap(16);
Map<Long, Set<Long>> fiBillIdEcApplyIdMap = new HashMap(16);
boolean isCancel = false;
boolean isincomeapply = true; //是否来源与收款申请单
for(Map<String, Object> entryData : dataList) {
Long reqBillId = (Long)entryData.get("sourcepk");
String operation = String.valueOf(entryData.get("operation"));
String srcEntryId = String.valueOf(entryData.get("sourceentrypk"));
BigDecimal amount = (BigDecimal)entryData.get("amount");
Long fiBillId = (Long)entryData.get("targetpk");
if (StringUtils.isBlank(operation)) {
throw new KDBizException(ResManager.loadKDString("操作类型为空,反写失败!", "RepAmountServiceImpl_0", "ec-contract-mservice", new Object[0]));
}
List<String> operateKeyList = new ArrayList();
operateKeyList.add("receive");
operateKeyList.add("cancelreceive");
if (!operateKeyList.contains(operation)) {
log.info("操作无需处理:" + operation);
return;
}
if (null == srcEntryId) {
throw new KDBizException(ResManager.loadKDString("分录的源单分录ID不存在反写失败", "RepAmountServiceImpl_1", "ec-contract-mservice", new Object[0]));
}
if (null == reqBillId) {
throw new KDBizException(ResManager.loadKDString("源申请单ID不存在反写失败", "RepAmountServiceImpl_2", "ec-contract-mservice", new Object[0]));
}
DynamicObject casRecbill = BusinessDataServiceHelper.loadSingle("cas_recbill",
"zcgj_ec_paymentapplyid,zcgj_ec_paymentapplyenid",
new QFilter[]{new QFilter("id", "=", fiBillId)});
if(casRecbill!=null) {
String zcgjEcPaymentapplyid = casRecbill.getString("zcgj_ec_paymentapplyid");//收款处理关联付款申请id
String zcgjEcPaymentapplyenid = casRecbill.getString("zcgj_ec_paymentapplyenid"); //收款处理关联付款申请费用明细id
if(StringUtils.isNotBlank(zcgjEcPaymentapplyid) && StringUtils.isNotBlank(zcgjEcPaymentapplyenid)) {
isincomeapply = false;
if (StringUtils.equals(operation, "receive")) {
Map<String, BigDecimal> entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId);//收款处理单id
if (entryAmtMap != null) {
entryAmtMap.put(srcEntryId, amount);//收款处理单费用明细id收款金额
} else {
Map<String, BigDecimal> newEntryAmtMap = new HashMap(16);
newEntryAmtMap.put(srcEntryId, amount);//收款处理单费用明细id收款金额
fiBillIdEntryAmtMap.put(fiBillId, newEntryAmtMap);//收款处理单id
}
}
if (StringUtils.equals(operation, "cancelreceive")) {
isCancel = true;
}
Set<Long> ecBillIds = (Set)fiBillIdEcApplyIdMap.getOrDefault(fiBillId, new HashSet(16));//收款处理单-付款申请单关联map
ecBillIds.add(Long.parseLong(zcgjEcPaymentapplyid));//付款申请单
fiBillIdEcApplyIdMap.put(fiBillId, ecBillIds);
//工程付款申请单
DynamicObject ecPaymentapply = BusinessDataServiceHelper.loadSingle("ec_paymentapply",
"billcompletepay,sumamount," +
"entryentity.id," +
"entryentity.completepay," +
"entryentity.thisapplyoftax",
new QFilter[]{new QFilter("id", "=", zcgjEcPaymentapplyid)});
ecPaymentapply.set("billcompletepay",!isCancel);//付款完成
ecPaymentapply.set("sumamount",amount);//本次申请金额(单头汇总)
DynamicObjectCollection dynamicObjectCollection = ecPaymentapply.getDynamicObjectCollection("entryentity");
for (DynamicObject dynamicObject : dynamicObjectCollection) {
long pkValue = dynamicObject.getLong("id");
if(Long.parseLong(zcgjEcPaymentapplyenid) == pkValue) {
dynamicObject.set("completepay", !isCancel);
dynamicObject.set("thisapplyoftax", amount); //本次申请金额
}
}
SaveServiceHelper.save(new DynamicObject[]{ecPaymentapply});
}
}
if(isincomeapply){ //如果是来源付款申请单则不进行校验
DynamicObject incomeBill = BusinessDataServiceHelper.loadSingle(reqBillId, "ec_incomeapply");
if (null == incomeBill) {
throw new KDBizException(ResManager.loadKDString("源申请单不存在,反写失败!", "RepAmountServiceImpl_3", "ec-contract-mservice", new Object[0]));
}
if (StringUtils.equals(operation, "receive")) {
Map<String, BigDecimal> entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId);
if (entryAmtMap != null) {
entryAmtMap.put(srcEntryId, amount);
} else {
Map<String, BigDecimal> newEntryAmtMap = new HashMap(16);
newEntryAmtMap.put(srcEntryId, amount);
fiBillIdEntryAmtMap.put(fiBillId, newEntryAmtMap);
}
}
if (StringUtils.equals(operation, "cancelreceive")) {
isCancel = true;
}
Set<Long> ecBillIds = (Set)fiBillIdEcApplyIdMap.getOrDefault(fiBillId, new HashSet(16));
ecBillIds.add(reqBillId);
fiBillIdEcApplyIdMap.put(fiBillId, ecBillIds);
}
}
if(isincomeapply){
if (isCancel) {
Set<Long> longs = fiBillIdEcApplyIdMap.keySet();
Set<String> longIdStringSet = new HashSet(16);
for(Long id : longs) {
longIdStringSet.add(id.toString());
}
DynamicObject[] referRegisterArr = BusinessDataServiceHelper.load("ec_income_register", "entryentity,contract,receiptoftaxamount,receiptamount", new QFilter[]{new QFilter("referregisterid", "in", longIdStringSet)});
for(DynamicObject register : referRegisterArr) {
OperateOption operateOption = OperateOption.create();
operateOption.setVariableValue("ishasright", String.valueOf(true));
OperationResult operationResult = OperationServiceHelper.executeOperate("unaudit", "ec_income_register", new Object[]{register.getPkValue()}, operateOption);
if (operationResult != null) {
boolean success = operationResult.isSuccess();
if (!success) {
log.error(operationResult.getAllErrorOrValidateInfo().toString());
throw new KDBizException(operationResult.getMessage());
}
DeleteServiceHelper.delete("ec_income_register", new QFilter[]{new QFilter("id", "=", register.getPkValue())});
}
}
} else {
this.generateInRegisterBill(fiBillIdEntryAmtMap, fiBillIdEcApplyIdMap);
}
}else{
if (isCancel) {
Set<Long> longs = fiBillIdEcApplyIdMap.keySet();
Set<String> longIdStringSet = new HashSet(16);
for(Long id : longs) {
longIdStringSet.add(id.toString());
}
DynamicObject[] referRegisterArr = BusinessDataServiceHelper.load("ec_payment_register", "entryentity,contract,thispaymentoftaxamount,thispaymentamount", new QFilter[]{new QFilter("referregisterid", "in", longIdStringSet)});
for(DynamicObject register : referRegisterArr) {
log.info("开始执行之前生成的付款登记单的反审核逻辑:" + register.getPkValue());
OperateOption operateOption = OperateOption.create();
operateOption.setVariableValue("ishasright", String.valueOf(true));
OperationResult operationResult = OperationServiceHelper.executeOperate("unaudit", "ec_payment_register", new Object[]{register.getPkValue()}, operateOption);
log.info("完成执行之前生成的付款登记单的反审核逻辑:" + register.getPkValue());
log.info("开始删除之前生成的付款登记单:" + register.getPkValue());
if (operationResult != null) {
boolean success = operationResult.isSuccess();
if (!success) {
log.error(operationResult.getAllErrorOrValidateInfo().toString());
throw new KDBizException(operationResult.getMessage());
}
DeleteServiceHelper.delete("ec_payment_register", new QFilter[]{new QFilter("id", "=", register.getPkValue())});
}
log.info("完成删除之前生成的付款登记单:" + register.getPkValue());
}
} else {
this.generatePayRegisterBill(fiBillIdEntryAmtMap, fiBillIdEcApplyIdMap);
}
}
} else {
log.error("接口传递参数为空");
}
}
//log.info("KsRepAmountServiceImpl:incomeRepAmount");
//boolean isCancel = false;
//Map<Long, Set<Long>> fiBillIdEcApplyIdMap = new HashMap(16);
//Map<Long, Map<String, BigDecimal>> fiBillIdEntryAmtMap = new HashMap(16);//收款处理单数据
//try (TXHandle txType = TX.requiresNew("ksincomeRepAmount")) {
// for(Map<String, Object> entryData : dataList) {
/*Long reqBillId = (Long)entryData.get("sourcepk"); //工程收款申请单id
String operation = String.valueOf(entryData.get("operation")); //操作类型
String srcEntryId = String.valueOf(entryData.get("sourceentrypk")); //出纳收款处理-收款明细分录id
BigDecimal amount = (BigDecimal)entryData.get("amount"); //实付金额
Long fiBillId = (Long)entryData.get("targetpk");//出纳收款处理单id
if (StringUtils.isBlank(operation)) {
throw new KDBizException(ResManager.loadKDString("操作类型为空,反写失败!", "RepAmountServiceImpl_0", "ec-contract-mservice", new Object[0]));
}*/
//出纳收款处理 zcgj_ec_paymentapplyid
/*DynamicObject casRecbill = BusinessDataServiceHelper.loadSingle("cas_recbill",
"zcgj_ec_paymentapplyid,zcgj_ec_paymentapplyenid",
new QFilter[]{new QFilter("id", "=", fiBillId)});*/
/*if(casRecbill!=null){
String zcgjEcPaymentapplyid = casRecbill.getString("zcgj_ec_paymentapplyid");//收款处理关联付款申请id
String zcgjEcPaymentapplyenid = casRecbill.getString("zcgj_ec_paymentapplyenid"); //收款处理关联付款申请费用明细id
*//*Map<String, BigDecimal> entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId);
if (entryAmtMap != null) {
entryAmtMap.put(srcEntryId, amount);
} else {
Map<String, BigDecimal> newEntryAmtMap = new HashMap(16);
newEntryAmtMap.put(srcEntryId, amount);
fiBillIdEntryAmtMap.put(fiBillId, newEntryAmtMap);
}*/
/*
if (StringUtils.equals(operation, "receive")) {
Map<String, BigDecimal> entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId);//收款处理单id
if (entryAmtMap != null) {
entryAmtMap.put(srcEntryId, amount);//收款处理单费用明细id收款金额
} else {
Map<String, BigDecimal> newEntryAmtMap = new HashMap(16);
newEntryAmtMap.put(srcEntryId, amount);//收款处理单费用明细id收款金额
fiBillIdEntryAmtMap.put(fiBillId, newEntryAmtMap);//收款处理单id
}
}
if (StringUtils.equals(operation, "cancelreceive")) {
isCancel = true;
}
if(org.apache.commons.lang3.StringUtils.isNotBlank(zcgjEcPaymentapplyid) &&
org.apache.commons.lang3.StringUtils.isNotBlank(zcgjEcPaymentapplyenid) ){
//工程付款申请单
DynamicObject ecPaymentapply = BusinessDataServiceHelper.loadSingle("ec_paymentapply",
"billcompletepay,sumamount," +
"entryentity.id," +
"entryentity.completepay," +
"entryentity.thisapplyoftax",
new QFilter[]{new QFilter("id", "=", zcgjEcPaymentapplyid)});
ecPaymentapply.set("billcompletepay",!isCancel);//付款完成
ecPaymentapply.set("sumamount",amount);//本次申请金额(单头汇总)
DynamicObjectCollection dynamicObjectCollection = ecPaymentapply.getDynamicObjectCollection("entryentity");
for (DynamicObject dynamicObject : dynamicObjectCollection) {
long pkValue = dynamicObject.getLong("id");
if(Long.parseLong(zcgjEcPaymentapplyenid) == pkValue) {
dynamicObject.set("completepay", !isCancel);
dynamicObject.set("thisapplyoftax", amount); //本次申请金额
}
}
SaveServiceHelper.save(new DynamicObject[]{ecPaymentapply});
}
Set<Long> ecBillIds = (Set)fiBillIdEcApplyIdMap.getOrDefault(fiBillId, new HashSet(16));//收款处理单-付款申请单关联map
ecBillIds.add(Long.parseLong(zcgjEcPaymentapplyid));//付款申请单
fiBillIdEcApplyIdMap.put(fiBillId, ecBillIds);
if (isCancel) {
Set<Long> longs = fiBillIdEcApplyIdMap.keySet();
Set<String> longIdStringSet = new HashSet(16);
for(Long id : longs) {
longIdStringSet.add(id.toString());
}
DynamicObject[] referRegisterArr = BusinessDataServiceHelper.load("ec_payment_register", "entryentity,contract,thispaymentoftaxamount,thispaymentamount", new QFilter[]{new QFilter("referregisterid", "in", longIdStringSet)});
for(DynamicObject register : referRegisterArr) {
log.info("开始执行之前生成的付款登记单的反审核逻辑:" + register.getPkValue());
OperateOption operateOption = OperateOption.create();
operateOption.setVariableValue("ishasright", String.valueOf(true));
OperationResult operationResult = OperationServiceHelper.executeOperate("unaudit", "ec_payment_register", new Object[]{register.getPkValue()}, operateOption);
log.info("完成执行之前生成的付款登记单的反审核逻辑:" + register.getPkValue());
log.info("开始删除之前生成的付款登记单:" + register.getPkValue());
if (operationResult != null) {
boolean success = operationResult.isSuccess();
if (!success) {
log.error(operationResult.getAllErrorOrValidateInfo().toString());
throw new KDBizException(operationResult.getMessage());
}
DeleteServiceHelper.delete("ec_payment_register", new QFilter[]{new QFilter("id", "=", register.getPkValue())});
}
log.info("完成删除之前生成的付款登记单:" + register.getPkValue());
}
} else {
this.generatePayRegisterBill(fiBillIdEntryAmtMap, fiBillIdEcApplyIdMap);
}
}*/
//工程收款申请单
/*DynamicObject contractBillCols = BusinessDataServiceHelper.loadSingle("ec_incomeapply",
"billname,billno",
new QFilter[]{new QFilter("id", "=", reqBillId)});*/
/*if (StringUtils.equals(operation, "receive")) {
Map<String, BigDecimal> entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId);
if (entryAmtMap != null) {
entryAmtMap.put(srcEntryId, amount);
} else {
Map<String, BigDecimal> newEntryAmtMap = new HashMap(16);
newEntryAmtMap.put(srcEntryId, amount);
fiBillIdEntryAmtMap.put(fiBillId, newEntryAmtMap);
}
}
if (StringUtils.equals(operation, "cancelreceive")) {
isCancel = true;
}
Set<Long> ecBillIds = (Set)fiBillIdEcApplyIdMap.getOrDefault(fiBillId, new HashSet(16));
ecBillIds.add(reqBillId);
fiBillIdEcApplyIdMap.put(fiBillId, ecBillIds);*/
// }
// }
}
}

View File

@ -0,0 +1,43 @@
package kd.ec.contr.servicehelper;
import kd.bos.dataentity.TypesContainer;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.ec.contr.KsRepAmountServiceImpl;
import java.util.HashMap;
import java.util.Map;
public class ServiceFactory {
private static final Log log = LogFactory.getLog(ServiceFactory.class);
private static Map<String, String> serviceMap = new HashMap();
public static <T> T getService(Class<T> clazz) {
return (T)getService(clazz.getSimpleName());
}
public static Object getService(String serviceName) {
log.info("KsServiceFactory::getService");
String className = (String)serviceMap.get(serviceName);
if (className == null) {
throw new RuntimeException(String.format(ResManager.loadKDString("%s对应的服务实现未找到", "ServiceFactory_0", "ec-contract-servicehelper", new Object[0]), serviceName));
} else {
return TypesContainer.getOrRegisterSingletonInstance(className);
}
}
static {
serviceMap.put("ApplyAmoutUpdateService", "kd.ec.contract.mservice.ApplyAmountUpdateServiceImpl");
serviceMap.put("RepAmountService", "kd.ec.contract.mservice.bill.RepAmountServiceImpl");
serviceMap.put("ContMeasureAmountUpgradeService", "kd.ec.cont.servicehelper.upgrade.ContMeasureAmountUpgradeService");
serviceMap.put("OutContractPayMethodUpgradeService", "kd.ec.cont.servicehelper.upgrade.OutContractPayMethodUpgradeService");
serviceMap.put("IncomeApplyInvoiceUpgradeService", "kd.ec.cont.servicehelper.upgrade.IncomeApplyInvoiceUpgradeService");
serviceMap.put("PayApplyInvoiceUpgradeService", "kd.ec.cont.servicehelper.upgrade.PayApplyInvoiceUpgradeService");
serviceMap.put("IndustryEntryDisplayNameUpgradeService", "kd.ec.cont.servicehelper.upgrade.IndustryEntryDisplayNameUpgradeService");
serviceMap.put("KsRepAmountService", "kd.ec.contr.KsRepAmountServiceImpl");
}
}