From 1c2d589c84a795888edb009599bc852163d9d0a3 Mon Sep 17 00:00:00 2001 From: zhangzhiguo <421587375@qq.com> Date: Thu, 8 Jan 2026 16:12:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=98=E6=AC=BE=E7=94=B3=E8=AF=B7=E5=8D=95?= =?UTF-8?q?=E7=94=9F=E6=88=90=E6=94=B6=E6=AC=BE=E5=A4=84=E7=90=86=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/kd/ec/contr/KsRepAmountService.java | 10 + .../kd/ec/contr/KsRepAmountServiceImpl.java | 369 ++++++++++++++++++ .../contr/servicehelper/ServiceFactory.java | 43 ++ 3 files changed, 422 insertions(+) create mode 100644 code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/KsRepAmountService.java create mode 100644 code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/KsRepAmountServiceImpl.java create mode 100644 code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/servicehelper/ServiceFactory.java diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/KsRepAmountService.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/KsRepAmountService.java new file mode 100644 index 0000000..234a0d6 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/KsRepAmountService.java @@ -0,0 +1,10 @@ +package kd.ec.contr; + +import java.util.List; +import java.util.Map; + +public interface KsRepAmountService { + void payRepAmount(List> var1); + + void incomeRepAmount(List> var1); +} \ No newline at end of file diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/KsRepAmountServiceImpl.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/KsRepAmountServiceImpl.java new file mode 100644 index 0000000..ccc5e6b --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/KsRepAmountServiceImpl.java @@ -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> dataList) { + super.payRepAmount(dataList); + log.info("KsRepAmountServiceImpl:payRepAmount"); + } + + @Override + public void incomeRepAmount(List> dataList) { + //super.incomeRepAmount(dataList); + try (TXHandle txType = TX.requiresNew("ksincomeRepAmount")) { + if (dataList != null && dataList.size() > 0) { + Map> fiBillIdEntryAmtMap = new HashMap(16); + Map> fiBillIdEcApplyIdMap = new HashMap(16); + boolean isCancel = false; + boolean isincomeapply = true; //是否来源与收款申请单 + + for(Map 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 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 entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId);//收款处理单id + if (entryAmtMap != null) { + entryAmtMap.put(srcEntryId, amount);//收款处理单费用明细id,收款金额 + } else { + Map newEntryAmtMap = new HashMap(16); + newEntryAmtMap.put(srcEntryId, amount);//收款处理单费用明细id,收款金额 + fiBillIdEntryAmtMap.put(fiBillId, newEntryAmtMap);//收款处理单id + } + } + + if (StringUtils.equals(operation, "cancelreceive")) { + isCancel = true; + } + + Set 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 entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId); + if (entryAmtMap != null) { + entryAmtMap.put(srcEntryId, amount); + } else { + Map newEntryAmtMap = new HashMap(16); + newEntryAmtMap.put(srcEntryId, amount); + fiBillIdEntryAmtMap.put(fiBillId, newEntryAmtMap); + } + } + + if (StringUtils.equals(operation, "cancelreceive")) { + isCancel = true; + } + + Set ecBillIds = (Set)fiBillIdEcApplyIdMap.getOrDefault(fiBillId, new HashSet(16)); + ecBillIds.add(reqBillId); + fiBillIdEcApplyIdMap.put(fiBillId, ecBillIds); + } + + + } + if(isincomeapply){ + if (isCancel) { + Set longs = fiBillIdEcApplyIdMap.keySet(); + Set 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 longs = fiBillIdEcApplyIdMap.keySet(); + Set 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> fiBillIdEcApplyIdMap = new HashMap(16); + //Map> fiBillIdEntryAmtMap = new HashMap(16);//收款处理单数据 + //try (TXHandle txType = TX.requiresNew("ksincomeRepAmount")) { + + // for(Map 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 entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId); + if (entryAmtMap != null) { + entryAmtMap.put(srcEntryId, amount); + } else { + Map newEntryAmtMap = new HashMap(16); + newEntryAmtMap.put(srcEntryId, amount); + fiBillIdEntryAmtMap.put(fiBillId, newEntryAmtMap); + }*/ + + /* + if (StringUtils.equals(operation, "receive")) { + Map entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId);//收款处理单id + if (entryAmtMap != null) { + entryAmtMap.put(srcEntryId, amount);//收款处理单费用明细id,收款金额 + } else { + Map 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 ecBillIds = (Set)fiBillIdEcApplyIdMap.getOrDefault(fiBillId, new HashSet(16));//收款处理单-付款申请单关联map + ecBillIds.add(Long.parseLong(zcgjEcPaymentapplyid));//付款申请单 + fiBillIdEcApplyIdMap.put(fiBillId, ecBillIds); + + if (isCancel) { + Set longs = fiBillIdEcApplyIdMap.keySet(); + Set 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 entryAmtMap = (Map)fiBillIdEntryAmtMap.get(fiBillId); + if (entryAmtMap != null) { + entryAmtMap.put(srcEntryId, amount); + } else { + Map newEntryAmtMap = new HashMap(16); + newEntryAmtMap.put(srcEntryId, amount); + fiBillIdEntryAmtMap.put(fiBillId, newEntryAmtMap); + } + } + + if (StringUtils.equals(operation, "cancelreceive")) { + isCancel = true; + } + + Set ecBillIds = (Set)fiBillIdEcApplyIdMap.getOrDefault(fiBillId, new HashSet(16)); + ecBillIds.add(reqBillId); + fiBillIdEcApplyIdMap.put(fiBillId, ecBillIds);*/ + // } + + // } + + } +} diff --git a/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/servicehelper/ServiceFactory.java b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/servicehelper/ServiceFactory.java new file mode 100644 index 0000000..8e0f779 --- /dev/null +++ b/code/zcdev/zcgj-zcdev-zcdev-pr/src/main/java/kd/ec/contr/servicehelper/ServiceFactory.java @@ -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 serviceMap = new HashMap(); + + public static T getService(Class 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"); + } + +}