From cb45727a2e3ee1e1378d837b3ae9f8980bf70559 Mon Sep 17 00:00:00 2001 From: ljw Date: Thu, 28 Nov 2024 18:36:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=201.=E5=87=BA=E5=8F=A3=E5=8F=91=E7=A5=A8?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E7=94=9F=E6=88=90=E5=A4=87=E6=B3=A8=E5=8F=8A?= =?UTF-8?q?=E5=90=88=E5=90=8C=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exportinvoice/op/ExportInvoiceSaveOP.java | 188 ++++++++++++------ 1 file changed, 126 insertions(+), 62 deletions(-) diff --git a/src/main/java/com/yem/wm/es/exportinvoice/op/ExportInvoiceSaveOP.java b/src/main/java/com/yem/wm/es/exportinvoice/op/ExportInvoiceSaveOP.java index 3ba60b88..467b5502 100644 --- a/src/main/java/com/yem/wm/es/exportinvoice/op/ExportInvoiceSaveOP.java +++ b/src/main/java/com/yem/wm/es/exportinvoice/op/ExportInvoiceSaveOP.java @@ -4,7 +4,6 @@ import com.yem.wm.utils.DynamicObjectUtil; import com.yem.wm.utils.YEM; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; -import kd.bos.entity.datamodel.IDataModel; import kd.bos.entity.plugin.AbstractOperationServicePlugIn; import kd.bos.entity.plugin.PreparePropertysEventArgs; import kd.bos.entity.plugin.args.BeginOperationTransactionArgs; @@ -16,7 +15,11 @@ import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper; import java.math.BigDecimal; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; /** * @author xwudd @@ -33,8 +36,8 @@ public class ExportInvoiceSaveOP extends AbstractOperationServicePlugIn { @Override public void beginOperationTransaction(BeginOperationTransactionArgs e) { DynamicObject[] dataEntities = e.getDataEntities(); - for(DynamicObject dt:dataEntities){ - // setOutForm(dt); + for (DynamicObject dt : dataEntities) { + // setOutForm(dt); } } @@ -42,50 +45,113 @@ public class ExportInvoiceSaveOP extends AbstractOperationServicePlugIn { public void endOperationTransaction(EndOperationTransactionArgs e) { super.endOperationTransaction(e); DynamicObject[] dataEntities = e.getDataEntities(); - for(DynamicObject dataEntitie : dataEntities){ - Map map = new HashMap<>(); - Map seqs = new HashMap<>(); + for (DynamicObject dataEntitie : dataEntities) { + DynamicObjectCollection yemEsMaterialinfo = dataEntitie.getDynamicObjectCollection("yem_es_materialinfo"); + if (yemEsMaterialinfo.size() > 0) { + Map map = new HashMap<>(); + for (int i = 0; i < yemEsMaterialinfo.size(); i++) { + DynamicObject dynamicObject = yemEsMaterialinfo.get(i); + String yemContractnumbersM = dynamicObject.getString("yem_contractnumbers_m"); + map.put(yemContractnumbersM, yemContractnumbersM); + } + String queryString = map.values().stream().collect(Collectors.joining("&")); + dataEntitie.set("yem_contractnumber", queryString); + StringBuilder yemShipports = new StringBuilder(); + String yemTradeway = ""; + String yemSettlement = ""; + BigDecimal totalAmount = BigDecimal.ZERO; + StringBuilder yemDestports = new StringBuilder(); + String yemseatransfeecurr = ""; + String yeminsurefeecurr = ""; + DynamicObject yem_Tradeway = dataEntitie.getDynamicObject("yem_tradeway");//成交方式 + if (yem_Tradeway != null) { + yemTradeway = "成交方式:" + dataEntitie.getString("yem_tradeway.name");//成交方式 + } + DynamicObject yem_Settlement = dataEntitie.getDynamicObject("yem_currency");//币别 + if (yem_Settlement != null) { + yemSettlement = dataEntitie.getString("yem_currency.billno");//币别 + } + DynamicObjectCollection yemExportinvoiceC = dataEntitie.getDynamicObjectCollection("yem_exportinvoice_c"); + if (yemExportinvoiceC.size() > 0) { + totalAmount = yemExportinvoiceC.stream().map(dynamicObject -> dynamicObject.getBigDecimal("yem_cusamount")) + .reduce(BigDecimal.ZERO, BigDecimal::add);//成交总额 + } + DynamicObject yem_seatransfeecurr = dataEntitie.getDynamicObject("yem_seatransfeecurr");//海运币别 + if (yem_seatransfeecurr != null) { + yemseatransfeecurr = yem_seatransfeecurr.getString("billno"); + } + DynamicObject yem_insurefeecurr = dataEntitie.getDynamicObject("yem_insurefeecurr");//运保币别 + if (yem_insurefeecurr != null) { + yeminsurefeecurr = yem_insurefeecurr.getString("billno"); + } + BigDecimal yemExrate = dataEntitie.getBigDecimal("yem_exrate");//汇率 + BigDecimal yemSeatransfee = dataEntitie.getBigDecimal("yem_seatransfee");//海运费 + BigDecimal yemInsurefee = dataEntitie.getBigDecimal("yem_insurefee");//保险费 + String yemLadbillnum = dataEntitie.getString("yem_ladbillnum");//提单号 +// queryString//合同号 + DynamicObjectCollection yem_shipports = dataEntitie.getDynamicObjectCollection("yem_shipports");//起运港 + if (yem_shipports != null) { + for (DynamicObject yemShipport : yem_shipports) { + String ssa = yemShipport.getDynamicObject("fbasedataid").getString("name");//起运港 + yemShipports.append(ssa); + } + } + DynamicObjectCollection yem_Destports = dataEntitie.getDynamicObjectCollection("yem_destports");//目的港 + if (yem_Destports != null) { + for (DynamicObject yemShipport : yem_Destports) { + String string = yemShipport.getDynamicObject("fbasedataid").getString("name"); + yemDestports.append(string);//目的港 + } + } + dataEntitie.set("yem_remark", ":" + yemTradeway + " 成交总额:" + yemSettlement + totalAmount + " 汇率:" + yemExrate + " 海运费:" + + yemseatransfeecurr + yemSeatransfee + " 保险费:" + yeminsurefeecurr + yemInsurefee + " 提单号:" + yemLadbillnum + " 合同号:" + + queryString + " 起运港:" + yemShipports + " 目的港:" + yemDestports); + dataEntitie.getInt("yem_currency");//币别 + + } + Map map = new HashMap<>(); + Map seqs = new HashMap<>(); Set ids = new HashSet<>(); DynamicObjectCollection exportInvoice_cs = dataEntitie.getDynamicObjectCollection("yem_exportinvoice_c"); - for(DynamicObject exportInvoice_c : exportInvoice_cs){ + for (DynamicObject exportInvoice_c : exportInvoice_cs) { long sourceBillId = exportInvoice_c.getLong("yem_sourcebillid_ec"); long sourceBillEntryId = exportInvoice_c.getLong("yem_sourcebillentryid"); BigDecimal sourceCusQty = exportInvoice_c.getBigDecimal("yem_cusqty"); ids.add(sourceBillId); - if(map.containsKey(sourceBillEntryId)){ - map.put(sourceBillEntryId,map.get(sourceBillEntryId).add(sourceCusQty)); - }else{ - map.put(sourceBillEntryId,sourceCusQty); + if (map.containsKey(sourceBillEntryId)) { + map.put(sourceBillEntryId, map.get(sourceBillEntryId).add(sourceCusQty)); + } else { + map.put(sourceBillEntryId, sourceCusQty); } - seqs.put(sourceBillEntryId,exportInvoice_c.getInt("seq")); + seqs.put(sourceBillEntryId, exportInvoice_c.getInt("seq")); } map = getQtyMap(dataEntitie, map); StringBuffer sb = new StringBuffer(); DynamicObject[] declareDocxs = BusinessDataServiceHelper.load("yem_es_declaredocx", "id,billno,yem_es_declare_ec.yem_cusqty,yem_es_declare_ec.yem_billingnoticeqty", new QFilter[]{new QFilter("id", QCP.in, ids)}); Set entryIds = map.keySet(); - for(Long entryId : entryIds){ + for (Long entryId : entryIds) { BigDecimal sourceCusQty = map.get(entryId); - for(DynamicObject declareDocx : declareDocxs){//源单(出口报关单) + for (DynamicObject declareDocx : declareDocxs) {//源单(出口报关单) DynamicObjectCollection declare_ecs = declareDocx.getDynamicObjectCollection("yem_es_declare_ec");//源单报关商品分录 - for(int j = 0; j < declare_ecs.size(); j++){ + for (int j = 0; j < declare_ecs.size(); j++) { DynamicObject declare_ec = declare_ecs.get(j); long declare_ecId = declare_ec.getLong("id"); - if(entryId == declare_ecId){ + if (entryId == declare_ecId) { BigDecimal cusQty = declare_ec.getBigDecimal("yem_cusqty"); - if(sourceCusQty.compareTo(cusQty) <= 0){ - declare_ec.set("yem_billingnoticeqty",sourceCusQty); - }else{ + if (sourceCusQty.compareTo(cusQty) <= 0) { + declare_ec.set("yem_billingnoticeqty", sourceCusQty); + } else { sb.append(String.format("[出口发票单(%s),报关商品第%s行]反写[出口报关单(%s),报关商品第%s行:已开票数量大于数量,不允许超额!!!]\n", - dataEntitie.getString("billno"),seqs.get(entryId),declareDocx.getString("billno"),j + 1)); + dataEntitie.getString("billno"), seqs.get(entryId), declareDocx.getString("billno"), j + 1)); } } } } } - if(sb.length() > 0){ + if (sb.length() > 0) { throw new KDBizException(sb.toString()); - }else{ + } else { SaveServiceHelper.save(declareDocxs); } } @@ -93,7 +159,7 @@ public class ExportInvoiceSaveOP extends AbstractOperationServicePlugIn { } - public Map getQtyMap(DynamicObject dataEntitie,Map map){ + public Map getQtyMap(DynamicObject dataEntitie, Map map) { long id = dataEntitie.getLong("id"); Set entryIds = map.keySet(); String name = dataEntitie.getDynamicObjectType().getName(); @@ -102,15 +168,15 @@ public class ExportInvoiceSaveOP extends AbstractOperationServicePlugIn { DynamicObject[] exportInvoices = BusinessDataServiceHelper.load(name, selectFields, new QFilter[]{new QFilter("yem_exportinvoice_c.yem_sourcebillentryid", QCP.in, entryIds), new QFilter("id", QCP.not_equals, id)}); - for(DynamicObject exportInvoice : exportInvoices){ + for (DynamicObject exportInvoice : exportInvoices) { DynamicObjectCollection exportInvoice_cs = exportInvoice.getDynamicObjectCollection("yem_exportinvoice_c"); - for(DynamicObject exportInvoice_c : exportInvoice_cs){ + for (DynamicObject exportInvoice_c : exportInvoice_cs) { long sourceBillEntryId = exportInvoice_c.getLong("yem_sourcebillentryid"); BigDecimal sourceCusQty = exportInvoice_c.getBigDecimal("yem_cusqty"); - if(map.containsKey(sourceBillEntryId)){ - map.put(sourceBillEntryId,map.get(sourceBillEntryId).add(sourceCusQty)); - }else{ - map.put(sourceBillEntryId,sourceCusQty); + if (map.containsKey(sourceBillEntryId)) { + map.put(sourceBillEntryId, map.get(sourceBillEntryId).add(sourceCusQty)); + } else { + map.put(sourceBillEntryId, sourceCusQty); } } } @@ -118,19 +184,19 @@ public class ExportInvoiceSaveOP extends AbstractOperationServicePlugIn { } /** - * 最后一张出口发票保存时 处理海运费(原币)尾零 (暂时废弃 11-21) - * */ + * 最后一张出口发票保存时 处理海运费(原币)尾零 (暂时废弃 11-21) + */ private static void setOutForm(DynamicObject dt) { //确定本次为 最后一次生成出口发票 boolean flag = true; //储运托单 海运费 BigDecimal decimal = BigDecimal.ZERO; long aLong = dt.getLong("yem_sourcebillid"); - if(YEM.isNotEmpty(aLong)){ + if (YEM.isNotEmpty(aLong)) { DynamicObject object2 = BusinessDataServiceHelper.loadSingle(aLong, "yem_es_declaredocx"); - if(object2 != null){ - DynamicObject object = BusinessDataServiceHelper.loadSingle(object2.getPkValue(),object2.getDynamicObjectType().getName()); - if(object != null){ + if (object2 != null) { + DynamicObject object = BusinessDataServiceHelper.loadSingle(object2.getPkValue(), object2.getDynamicObjectType().getName()); + if (object != null) { decimal = object.getBigDecimal("yem_reightamt"); DynamicObjectCollection dynamicObjectCollection1 = object.getDynamicObjectCollection("yem_es_materialinfo"); DynamicObjectCollection dynamicObjectCollectionNow = dt.getDynamicObjectCollection("yem_es_materialinfo"); @@ -140,24 +206,24 @@ public class ExportInvoiceSaveOP extends AbstractOperationServicePlugIn { //储运未报关总数量 BigDecimal faCount = BigDecimal.ZERO; //子父分录行数相同 - if(dynamicObjectCollection1 != null && dynamicObjectCollectionNow != null && dynamicObjectCollectionNow.size() == dynamicObjectCollection1.size()){ - for(DynamicObject dc:dynamicObjectCollection1){ + if (dynamicObjectCollection1 != null && dynamicObjectCollectionNow != null && dynamicObjectCollectionNow.size() == dynamicObjectCollection1.size()) { + for (DynamicObject dc : dynamicObjectCollection1) { BigDecimal yemQty = dc.getBigDecimal("yem_qty"); BigDecimal yemInvoicedqty = dc.getBigDecimal("yem_invoicedqty"); BigDecimal yemUnassdeclaqty = BigDecimal.ZERO; - if(yemQty != null){ + if (yemQty != null) { yemUnassdeclaqty = yemQty.subtract(yemInvoicedqty); } - if(BigDecimal.ZERO.compareTo(yemUnassdeclaqty) != 0){ - if(dynamicObjectCollectionNow != null && dynamicObjectCollectionNow.size() > row){ + if (BigDecimal.ZERO.compareTo(yemUnassdeclaqty) != 0) { + if (dynamicObjectCollectionNow != null && dynamicObjectCollectionNow.size() > row) { DynamicObject object1 = dynamicObjectCollectionNow.get(row); - if(object1 !=null){ + if (object1 != null) { //来源分录id等于父明细内码时 Object pkValue = dc.getPkValue(); long sourceentryid = object1.getLong("yem_sourceentryid"); - if(pkValue != null && pkValue.equals(sourceentryid)){ + if (pkValue != null && pkValue.equals(sourceentryid)) { BigDecimal yemQtys = object1.getBigDecimal("yem_qty"); - if(YEM.isNotEmpty(yemUnassdeclaqty) && yemUnassdeclaqty.compareTo(yemQtys) != 0){ + if (YEM.isNotEmpty(yemUnassdeclaqty) && yemUnassdeclaqty.compareTo(yemQtys) != 0) { flag = false; } } @@ -167,40 +233,40 @@ public class ExportInvoiceSaveOP extends AbstractOperationServicePlugIn { } row++; } - }else { + } else { int rowCount = 0; - for(DynamicObject dts:dynamicObjectCollection1){ + for (DynamicObject dts : dynamicObjectCollection1) { BigDecimal yemQty = dts.getBigDecimal("yem_qty"); BigDecimal yemInvoicedqty = dts.getBigDecimal("yem_invoicedqty"); BigDecimal yemUnassdeclaqty = BigDecimal.ZERO; - if(yemQty != null){ + if (yemQty != null) { yemUnassdeclaqty = yemQty.subtract(yemInvoicedqty); } - if(YEM.isNotEmpty(yemUnassdeclaqty)){ - rowCount ++; + if (YEM.isNotEmpty(yemUnassdeclaqty)) { + rowCount++; } } //子父分录行数不同 //父分录 未报关数量不为0的行数要不等于子分类行数 - if(dynamicObjectCollectionNow != null && dynamicObjectCollectionNow.size() != rowCount){ + if (dynamicObjectCollectionNow != null && dynamicObjectCollectionNow.size() != rowCount) { flag = false; - }else { + } else { // //父分录 未报关数量不为0的行数要等于子分类行数 且数量之和要等于父分录 未报关数量之和 - for(DynamicObject dynamicObject:dynamicObjectCollectionNow){ + for (DynamicObject dynamicObject : dynamicObjectCollectionNow) { BigDecimal yemQty = dynamicObject.getBigDecimal("yem_qty"); sonCount = sonCount.add(yemQty); } - for(DynamicObject dc:dynamicObjectCollection1){ + for (DynamicObject dc : dynamicObjectCollection1) { BigDecimal yemQty = dc.getBigDecimal("yem_qty"); BigDecimal yemInvoicedqty = dc.getBigDecimal("yem_invoicedqty"); BigDecimal yemUnassdeclaqty = BigDecimal.ZERO; - if(yemQty != null){ + if (yemQty != null) { yemUnassdeclaqty = yemQty.subtract(yemInvoicedqty); } faCount = faCount.add(yemUnassdeclaqty); } - if(faCount.compareTo(sonCount) != 0){ + if (faCount.compareTo(sonCount) != 0) { flag = false; } @@ -208,30 +274,28 @@ public class ExportInvoiceSaveOP extends AbstractOperationServicePlugIn { } - - } } } //处理海运费尾零 - if(flag){ + if (flag) { DynamicObject[] load = BusinessDataServiceHelper.load("yem_exportinvoice", "yem_seatransfee", new QFilter[]{ //new QFilter("billstatus", QCP.equals, "C"), new QFilter("yem_sourcebillid", QCP.equals, aLong) }); - if(load != null){ + if (load != null) { BigDecimal count = BigDecimal.ZERO; - for(DynamicObject dc:load){ + for (DynamicObject dc : load) { BigDecimal yemReightamt = dc.getBigDecimal("yem_seatransfee"); count = count.add(yemReightamt); } BigDecimal yemReightamt = dt.getBigDecimal("yem_seatransfee"); yemReightamt = count.add(yemReightamt); - if(yemReightamt.compareTo(decimal) != 0){ - dt.set("yem_seatransfee",decimal.subtract(count)); + if (yemReightamt.compareTo(decimal) != 0) { + dt.set("yem_seatransfee", decimal.subtract(count)); } } }