diff --git a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/operation/DrafttradebillOP.java b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/operation/DrafttradebillOP.java index 9d9be1d..a39e108 100644 --- a/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/operation/DrafttradebillOP.java +++ b/sys/shkd-sys-sys/src/main/java/shkd/sys/sys/plugin/operation/DrafttradebillOP.java @@ -5,6 +5,7 @@ import kd.bos.algo.DataSet; import kd.bos.algo.Row; import kd.bos.dataentity.OperateOption; import kd.bos.dataentity.entity.DynamicObject; +import kd.bos.entity.operate.OperateOptionConst; import kd.bos.entity.operate.result.OperationResult; import kd.bos.entity.plugin.AbstractOperationServicePlugIn; import kd.bos.entity.plugin.args.ReturnOperationArgs; @@ -20,7 +21,6 @@ import kd.tmc.cdm.common.constant.CdmEntityConst; import kd.tmc.cdm.common.enums.BillStatusEnum; import kd.tmc.cdm.common.enums.DraftTradeTypeEnum; import kd.tmc.cdm.common.enums.DraftTranStatusEnum; -import shkd.sys.sys.plugin.task.redeemTaskPlugin; import java.math.BigDecimal; import java.util.*; @@ -29,14 +29,91 @@ import java.util.stream.Collectors; public class DrafttradebillOP extends AbstractOperationServicePlugIn { private static final Log logger = LogFactory.getLog(DrafttradebillOP.class); + @Override public void onReturnOperation(ReturnOperationArgs e) { super.onReturnOperation(e); List successPkIds = e.getOperationResult().getSuccessPkIds();//执行成功的数据 - for (Object successPkId : successPkIds) { - Long id=(Long)successPkId; - Map> srcBills = BFTrackerServiceHelper.findSourceBills("cdm_drafttradebill", new Long[]{id}); + List list = new ArrayList<>();//用于存放要处理的开票登记 + + // 过滤掉不符合类型的数据 + check(successPkIds,list); + + // 使用 Stream 获取 DynamicObject 集合 + List dynamicObjects = list.stream() + .map(id -> BusinessDataServiceHelper.loadSingle(id, CdmEntityConst.CDM_PAYABLEBILL)) + .collect(Collectors.toList()); + + List numbers = dynamicObjects.stream() + .map(dynamicObject -> dynamicObject.getString("billno")) + .collect(Collectors.toList()); + logger.info("单据编码:"+numbers+"进入检验"); + + // 调用方法检查所有 drawercompany资金组织 是否相同 + boolean drawercompany = checkIfAllNumbersAreSame(dynamicObjects,"company"); + boolean draftbilltype = checkIfAllNumbersAreSame(dynamicObjects,"draftbilltype"); + +// if(draftbilltype&&drawercompany){ + logger.info(numbers+"验证通过可以合并下推兑付"); + OperateOption option = OperateOption.create(); + option.setVariableValue("tradeType", "redeem"); + option.setVariableValue("remarks", "后台下推"); + + option.setVariableValue(OperateOptionConst.BATCHOP_BATCHSIZE, String.valueOf(100)); // 设置每批处理量 + //调用方法执行数据 - 自动兑付下推 + OperationResult operationResult = OperationServiceHelper.executeOperate("pushandsaveredeem", + CdmEntityConst.CDM_PAYABLEBILL, + list.toArray(new Object[]{}), option); + if (operationResult.getAllErrorInfo().size() != 0) { + logger.info("单据编号:" + numbers + "后台生单失败,原因:" + operationResult.getAllErrorInfo().get(0).getMessage()); + String targetpkvalue = operationResult.getAllErrorInfo().get(0).getErrorCustInfos().get("targetpkvalue"); + if (!StringUtil.isEmpty(targetpkvalue)) { + DynamicObject cdm_drafttradebill = BusinessDataServiceHelper.loadSingle(targetpkvalue, "cdm_drafttradebill"); + OperationResult delete = OperationServiceHelper.executeOperate("delete", "cdm_drafttradebill", new DynamicObject[]{cdm_drafttradebill}, OperateOption.create()); + if (delete.isSuccess()) { + logger.info("删除单据编号:" + numbers + "成功"); + } else { + logger.info("删除单据编号:" + numbers + "失败,原因:" + delete.getMessage()); + } + } + } +// }else { +// logger.info(numbers+"验证不通过,分开生单兑付"); +// //生单 +// for (int i = 0; i < list.size(); i++) { +// DynamicObject cdm_payablebill = BusinessDataServiceHelper.loadSingle(list.get(i), CdmEntityConst.CDM_PAYABLEBILL); +// List dataEntitys = new ArrayList<>(); +// dataEntitys.add(Long.parseLong(cdm_payablebill.getString("id"))); +// OperateOption option = OperateOption.create(); +// option.setVariableValue("tradeType", "redeem"); +// option.setVariableValue("remarks", "后台下推"); +// //调用方法执行数据 - 自动兑付下推 +// OperationResult operationResult = OperationServiceHelper.executeOperate("pushandsaveredeem", +// CdmEntityConst.CDM_PAYABLEBILL, +// dataEntitys.toArray(new Object[]{}), option); +// if (operationResult.getAllErrorInfo().size() != 0) { +// logger.info("单据编号:" + cdm_payablebill.getString("billno") + "后台生单失败,原因:" + operationResult.getAllErrorInfo().get(0).getMessage()); +// String targetpkvalue = operationResult.getAllErrorInfo().get(0).getErrorCustInfos().get("targetpkvalue"); +// if (!StringUtil.isEmpty(targetpkvalue)) { +// DynamicObject cdm_drafttradebill = BusinessDataServiceHelper.loadSingle(targetpkvalue, "cdm_drafttradebill"); +// OperationResult delete = OperationServiceHelper.executeOperate("delete", "cdm_drafttradebill", new DynamicObject[]{cdm_drafttradebill}, OperateOption.create()); +// if (delete.isSuccess()) { +// logger.info("删除单据编号:" + cdm_payablebill.getString("billno") + "成功"); +// } else { +// logger.info("删除单据编号:" + cdm_payablebill.getString("billno") + "失败,原因:" + delete.getMessage()); +// } +// } +// } +// } +// } + } + + + private void check(List successPkIds,List list) { + for (Object successPkId : successPkIds) { + Long id = (Long) successPkId; + Map> srcBills = BFTrackerServiceHelper.findSourceBills("cdm_drafttradebill", new Long[]{id});//上查开票登记 if (srcBills.containsKey(CdmEntityConst.CDM_PAYABLEBILL)) { HashSet ar_invoice = srcBills.get(CdmEntityConst.CDM_PAYABLEBILL); // 获取第一个元素,如果集合不为空 @@ -44,31 +121,31 @@ public class DrafttradebillOP extends AbstractOperationServicePlugIn { DynamicObject cdm_payablebill = BusinessDataServiceHelper.loadSingle(firstElement, CdmEntityConst.CDM_PAYABLEBILL); String draftbillstatus = cdm_payablebill.getString("draftbillstatus"); String settlementtype = cdm_payablebill.getString("draftbilltype.settlementtype"); - if (!draftbillstatus.equals("payoffed")){ + if (!draftbillstatus.equals("payoffed")) { continue; } - if (!settlementtype.equals("5")){ + if (!settlementtype.equals("5")) { continue; } QFilter filter = new QFilter("id", QCP.equals, firstElement); DynamicObject[] CDM_PAYABLEBILLs = BusinessDataServiceHelper.load(CdmEntityConst.CDM_PAYABLEBILL, "id,billno,amount,billstatus,draftbilltranstatus", filter.toArray()); - Set draftIds = (Set)Arrays.stream(CDM_PAYABLEBILLs).map((s) -> { + Set draftIds = Arrays.stream(CDM_PAYABLEBILLs).map((s) -> { return s.getPkValue(); }).collect(Collectors.toSet()); QFilter filter1 = new QFilter("entrys.draftbill.id", "in", draftIds); filter1.and("tradetype", "=", DraftTradeTypeEnum.REDEEM.getValue()); filter1.and("draftbilltranstatus", "=", "success"); Map amountMap = new HashMap(16); - DataSet rows = QueryServiceHelper.queryDataSet("PayableBillRedeemValidator", "cdm_drafttradebill", "entrys.draftbill.id,entrys.billamt", filter1.toArray(), (String)null); + DataSet rows = QueryServiceHelper.queryDataSet("PayableBillRedeemValidator", "cdm_drafttradebill", "entrys.draftbill.id,entrys.billamt", filter1.toArray(), null); Throwable var8 = null; try { Iterator var9 = rows.iterator(); - while(var9.hasNext()) { - Row row = (Row)var9.next(); + while (var9.hasNext()) { + Row row = (Row) var9.next(); Long draftBillId = row.getLong("entrys.draftbill.id"); - BigDecimal orDefault = (BigDecimal)amountMap.getOrDefault(draftBillId, BigDecimal.ZERO); + BigDecimal orDefault = amountMap.getOrDefault(draftBillId, BigDecimal.ZERO); amountMap.put(draftBillId, orDefault.add(row.getBigDecimal("entrys.billamt"))); } } catch (Throwable throwable) { @@ -88,72 +165,38 @@ public class DrafttradebillOP extends AbstractOperationServicePlugIn { } } - - - try { - Long draftId = cdm_payablebill.getLong("id"); - BigDecimal sumBillAmt = (BigDecimal)amountMap.getOrDefault(draftId, BigDecimal.ZERO); - BigDecimal amount = cdm_payablebill.getBigDecimal("amount"); - boolean isNoAmount = sumBillAmt.compareTo(BigDecimal.ZERO) != 0 && amount.compareTo(sumBillAmt) == 0; - String billStatus = cdm_payablebill.getString("billstatus"); - String draftbillTranstatus = cdm_payablebill.getString("draftbilltranstatus"); - if (!BillStatusEnum.AUDIT.getValue().equals(billStatus) || !DraftTranStatusEnum.SUCCESS.getValue().equals(draftbillTranstatus) || isNoAmount) { - logger.info("单据编号:"+cdm_payablebill.getString("billno")+"单据状态为“已审核”且票据交易状态为“交易成功”的未兑付票据才能操作票据兑付。"); - continue; - } - - List dataEntitys = new ArrayList<>(); - dataEntitys.add(Long.parseLong(cdm_payablebill.getString("id"))); - OperateOption option = OperateOption.create(); - option.setVariableValue("tradeType", "redeem"); - option.setVariableValue("remarks", "后台下推"); - //调用方法执行数据 - 自动兑付下推 - OperationResult operationResult = OperationServiceHelper.executeOperate("pushandsaveredeem", - CdmEntityConst.CDM_PAYABLEBILL, - dataEntitys.toArray(new Object[]{}), option); - if (operationResult.getAllErrorInfo().size()!=0) { - logger.info("单据编号:"+cdm_payablebill.getString("billno")+"后台生单失败,原因:"+operationResult.getAllErrorInfo().get(0).getMessage()); - String targetpkvalue = operationResult.getAllErrorInfo().get(0).getErrorCustInfos().get("targetpkvalue"); - if (!StringUtil.isEmpty(targetpkvalue)){ - DynamicObject cdm_drafttradebill = BusinessDataServiceHelper.loadSingle(targetpkvalue, "cdm_drafttradebill"); - OperationResult delete = OperationServiceHelper.executeOperate("delete", "cdm_drafttradebill", new DynamicObject[]{cdm_drafttradebill}, OperateOption.create()); - if (delete.isSuccess()==true){ - logger.info("删除单据编号:"+cdm_payablebill.getString("billno")+"成功"); - }else { - logger.info("删除单据编号:"+cdm_payablebill.getString("billno")+"失败,原因:"+delete.getMessage()); - } - } - }else { -// logger.info("单据编号:"+cdm_payablebill.getString("billno")+"后台生单成功"); -// //根据源单id查询源单下游单据 -// Map> tarBills = BFTrackerServiceHelper.findTargetBills("cdm_payablebill", new Long[]{cdm_payablebill.getLong("id")}); -// //返回的Map对象 如果有数据 String 对应的是 目标单据标识 ,value 对应的目标单ids -// Set bill = new HashSet(); -// if (tarBills.containsKey("cdm_drafttradebill")) { -// HashSet billId = tarBills.get("cdm_drafttradebill"); -// for (Long aLong : billId) { -// QFilter billfilter = new QFilter("ltradetype", QCP.equals, "redeem"); -// billfilter.and(new QFilter("billstatus", QCP.equals, "C")); -// billfilter.and(new QFilter("id", QCP.equals, aLong)); -// DynamicObject cdm_drafttradebill = BusinessDataServiceHelper.loadSingle("cdm_drafttradebill", "id,billno", billfilter.toArray()); -// if (cdm_drafttradebill != null) { -// OperationResult operation = OperationServiceHelper.executeOperate("drawbillsave", "cdm_drafttradebill", new Object[]{aLong}, OperateOption.create()); -// if (operation.isSuccess()) { -// logger.info("单据编号:" + cdm_drafttradebill.getString("billno") + "确认交易成功"); -// } else { -// logger.info("单据编号:" + cdm_drafttradebill.getString("billno") + "确认交易失败,请检查交易状态或者手动操作"); -// } -// } -// } -// } - } - } catch (NumberFormatException exception) { - logger.error("单据编号:"+cdm_payablebill.getString("billno")+"后台生单錯誤原因:"+exception.getMessage()); + Long draftId = cdm_payablebill.getLong("id"); + BigDecimal sumBillAmt = amountMap.getOrDefault(draftId, BigDecimal.ZERO); + BigDecimal amount = cdm_payablebill.getBigDecimal("amount"); + boolean isNoAmount = sumBillAmt.compareTo(BigDecimal.ZERO) != 0 && amount.compareTo(sumBillAmt) == 0; + String billStatus = cdm_payablebill.getString("billstatus"); + String draftbillTranstatus = cdm_payablebill.getString("draftbilltranstatus"); + if (!BillStatusEnum.AUDIT.getValue().equals(billStatus) || !DraftTranStatusEnum.SUCCESS.getValue().equals(draftbillTranstatus) || isNoAmount) { + logger.info("单据编号:" + cdm_payablebill.getString("billno") + "单据状态为“已审核”且票据交易状态为“交易成功”的未兑付票据才能操作票据兑付。"); + continue; } + list.add(Long.parseLong(cdm_payablebill.getString("id"))); } - - } } + + public boolean checkIfAllNumbersAreSame(List dynamicObjects,String s) { + if (dynamicObjects == null || dynamicObjects.isEmpty()) { + return true; // 空集合可以认为是所有 number 相同 + } + + // 获取第一个 DynamicObject 的 number 值 + Object firstNumber = dynamicObjects.get(0).get(s); + + // 检查其余的 DynamicObject 的 number 值是否与第一个相同 + for (DynamicObject dynamicObject : dynamicObjects) { + Object currentNumber = dynamicObject.get(s); + if (!currentNumber.equals(firstNumber)) { + return false; // 如果发现不同的 number,则返回 false + } + } + + return true; // 所有 number 值相同,返回 true + } }