Selaa lähdekoodia

0701留存版

CRK 1 kuukausi sitten
vanhempi
commit
b5b5cb1e41

+ 21 - 21
mjava-wlh3tok3/src/main/java/com/malk/schedule/InventorySyncTask.java

@@ -194,16 +194,16 @@ public class InventorySyncTask {
     /**
      * 应用启动完成后立即执行一次金蝶库存汇总同步
      */
-//    @EventListener(ApplicationReadyEvent.class)
-//    public void runInventorySyncOnStartup() {
-//        log.info("应用启动完成,立即执行一次金蝶库存汇总同步任务");
-//        executeKingdeeInventorySync();
-//    }
+    @EventListener(ApplicationReadyEvent.class)
+    public void runInventorySyncOnStartup() {
+        log.info("应用启动完成,立即执行一次金蝶库存汇总同步任务");
+        executeKingdeeInventorySync();
+    }
 
     /**
      * 每30分钟全量同步一次金蝶库存汇总到氚云分仓库存表
      */
-    @Scheduled(cron = "0 0/30 * * * ?")
+    @Scheduled(cron = "0 0/20 * * * ?")
     public void syncKingdeeInventorySumToH3yun() {
         executeKingdeeInventorySync();
     }
@@ -229,19 +229,19 @@ public class InventorySyncTask {
     /**
      * 应用启动完成后立即执行一次金蝶银行行名行号同步
      */
-    @EventListener(ApplicationReadyEvent.class)
-    public void runBankSyncOnStartup() {
-        log.info("应用启动完成,立即执行一次金蝶银行行名行号同步任务");
-        executeKingdeeBankSync();
-    }
-
-    private void executeKingdeeBankSync() {
-        log.info("开始执行金蝶银行行名行号同步任务");
-        try {
-            Map<String, Object> result = syncService.syncKingdeeBankListToH3yun();
-            log.info("金蝶银行行名行号同步完成, result: {}", JSONObject.toJSONString(result));
-        } catch (Exception e) {
-            log.error("执行金蝶银行行名行号同步任务异常", e);
-        }
-    }
+//    @EventListener(ApplicationReadyEvent.class)
+//    public void runBankSyncOnStartup() {
+//        log.info("应用启动完成,立即执行一次金蝶银行行名行号同步任务");
+//        executeKingdeeBankSync();
+//    }
+//
+//    private void executeKingdeeBankSync() {
+//        log.info("开始执行金蝶银行行名行号同步任务");
+//        try {
+//            Map<String, Object> result = syncService.syncKingdeeBankListToH3yun();
+//            log.info("金蝶银行行名行号同步完成, result: {}", JSONObject.toJSONString(result));
+//        } catch (Exception e) {
+//            log.error("执行金蝶银行行名行号同步任务异常", e);
+//        }
+//    }
 }

+ 9 - 4
mjava-wlh3tok3/src/main/java/com/malk/service/h3yun/H3yunService.java

@@ -623,7 +623,6 @@ public class H3yunService {
         formData.put("F0000048", currencyid);
 
 
-
         formData.put("F0000030", this.getObjectIdByFieldValue("D29365537feb4e5e8644b21b7fd938dd322dab3", "F0000002", orgNumber));
         formData.put("F0000024", this.getObjectIdByFieldValue("D29365537feb4e5e8644b21b7fd938dd322dab3", "F0000002", orgNumber));
         //根据编号获取氚云集团公司ID
@@ -635,13 +634,16 @@ public class H3yunService {
         JSONArray billentry = webhookData.getJSONArray("billentry");//采购明细
         List<Map<String, Object>> detailList = new ArrayList<>();
         if (billentry != null && !billentry.isEmpty()) {
+            int n = 1;
             for (int i = 0; i < billentry.size(); i++) {
                 JSONObject entry = billentry.getJSONObject(i);
                 Map<String, Object> detail = new LinkedHashMap<>();
-                detail.put("F0000042", entry.getString("id"));//id
+                detail.put("F0000049", n);//序号
+                n++;
+
+                detail.put("F0000042", entry.getString("id"));//金蝶采购入库单明细ID
                 // 采购单
                 detail.put("F0000040", this.getObjectIdByFieldValue("D2936559700b1d66a0e4ee69a84e13da8dbbe95", "SeqNo", entry.getString("mainbillnumber")));
-
                 // 数量
                 Double qty = entry.getDouble("qty");
                 detail.put("F0000021", qty != null ? qty : 0);
@@ -827,14 +829,17 @@ public class H3yunService {
         formData.put("F0000068", currencyid);
 
 
-
         // 5. 明细行数据
         JSONArray billentry = webhookData.getJSONArray("billentry");
         List<Map<String, Object>> detailList = new ArrayList<>();
         if (billentry != null && !billentry.isEmpty()) {
+            int n=1;
             for (int i = 0; i < billentry.size(); i++) {
                 JSONObject entry = billentry.getJSONObject(i);
                 Map<String, Object> detail = new LinkedHashMap<>();
+
+
+                detail.put("F0000070", n);//序号
                 detail.put("F0000061", entry.getString("id"));//id
                 // 5.1 物料信息
                 String materialMasterId = entry.getString("materialmasterid");

+ 171 - 85
mjava-wlh3tok3/src/main/java/com/malk/service/sync/SyncService.java

@@ -1937,6 +1937,11 @@ public class SyncService {
                 // entry.put("seq", i);
                 entry.put("qty", entryData.getDouble("F0000017")); // 数量
                 entry.put("baseqty", entryData.getDouble("F0000017")); // 物料明细.基本数量
+                entry.put("qualifiedqty", entryData.getDouble("F0000017")); // 合格数量
+                entry.put("qualifiedbaseqty", entryData.getDouble("F0000017"));// 合格基本数量
+                entry.put("unverifyqty", entryData.getString("F0000017"));//物料明细.未勾稽数量
+                entry.put("unverifybaseqty", entryData.getString("F0000017"));//物料明细.未勾稽基本数量
+
                 entry.put("linetype_number", "010");
                 entry.put("discounttype", "NULL"); //物料明细.折扣方式 A:折扣率(%), B:单位折扣额, NULL:无
                 entry.put("ownertype", "bd_supplier");//物料明细.入库货主类型 bos_org:业务组织, bd_supplier:供应商, bd_customer:客户
@@ -1949,10 +1954,10 @@ public class SyncService {
                 entry.put("baseunit_name", h3yunService.getFieldValueById(
                         "D293655248b1d9bf6c448f0a291341ec58bb943", entryData.getString("F0000032"), "F0000002"));//基本单位.名称
                 // entry.put("price", entryData.getDouble("F0000043")); // 物料明细.单价
-                entry.put("price", divByOnePlusRate(entryData.getDouble("F0000043"), entryData.getDouble("F0000016"))); // 单价(不含税)
+                entry.put("price", java.math.BigDecimal.valueOf(divByOnePlusRate(entryData.getDouble("F0000043"), entryData.getDouble("F0000016"))).setScale(2, java.math.RoundingMode.HALF_UP).doubleValue()); // 单价(不含税)
                 entry.put("priceandtax", entryData.getDouble("F0000043")); // 物料明细.含税单价
                 //entry.put("taxrate", entryData.getDouble("F0000016"));//物料明细.税率%
-                entry.put("amount", divByOnePlusRate(entryData.getDouble("F0000043"), entryData.getDouble("F0000016")) * entryData.getDouble("F0000017"));//物料明细.金额
+                entry.put("amount", java.math.BigDecimal.valueOf(divByOnePlusRate(entryData.getDouble("F0000043"), entryData.getDouble("F0000016")) * entryData.getDouble("F0000017")).setScale(2, java.math.RoundingMode.HALF_UP).doubleValue());//物料明细.金额
                 entry.put("amountandtax", entryData.getDouble("F0000018"));//物料明细.价税合计
                 entry.put("taxamount", entryData.getDouble("F0000045"));//物料明细.税额
 
@@ -2020,7 +2025,7 @@ public class SyncService {
                 entry.put("srcbillentryid", ida);//物料明细.来源系统单据分录ID
                 entry.put("srcbillnumber", h3yunService.getFieldValueById(
                         "D2936559700b1d66a0e4ee69a84e13da8dbbe95", bizData.getString("F0000037"), "SeqNo"));//物料明细.来源单据编号
-                //  entry.put("srcbillentryseq", i);//物料明细.来源单据分录序号 	"1"
+                entry.put("srcbillentryseq", entryData.getString("F0000058"));//物料明细.来源单据分录序号 	"1"
 
 
                 entry.put("mainbillentity", "pm_purorderbill");//物料明细.来源单据实体
@@ -2030,7 +2035,7 @@ public class SyncService {
                 entry.put("mainbillentryid", ida);//物料明细.来源系统单据分录ID
                 entry.put("mainbillnumber", h3yunService.getFieldValueById(
                         "D2936559700b1d66a0e4ee69a84e13da8dbbe95", bizData.getString("F0000037"), "SeqNo"));//物料明细.来源单据编号
-
+                // entry.put("taxrate", entryData.getDouble("F0000016"));//税点
 
 //                entry.put("srcsystem", "8upAr");
 //                entry.put("srcsysbillid", "pt08C");
@@ -2115,32 +2120,34 @@ public class SyncService {
                 entry.put("entryinvcorg_number", bizData.getString("F0000049")); // 库存组织.编码
                 entry.put("entrysettleorg_number", bizData.getString("F0000049")); // 库存组织.编码
                 entry.put("entryreqorg_number", bizData.getString("F0000049")); // 库存组织.编码
+                entry.put("price", entryData.getDouble("F0000066"));//单价
+                entry.put("priceandtax", entryData.getDouble("F0000066"));//含税单价
+                entry.put("taxrateid_number", h3yunService.getFieldValueById(
+                        "D293655sl91vt6h8d0qg1heqw5aq", entryData.getString("F0000065"), "F0000001"));//F0000065
+                entry.put("warehouse_number", h3yunService.getFieldValueById(
+                        "D293655scvrhqr64jemxdkqk6gf", entryData.getString("F0000033"), "SeqNo"));//仓库
 
 
                 //退料申请单关联采购入库单
+                long ida = Long.parseUnsignedLong(entryData.getString("F0000061"));
                 entry.put("srcbillentity", "im_purinbill");//物料明细.来源单据实体
-
                 entry.put("srcbillid", h3yunService.getFieldValueById(
                         "D293655srqj5uui3keso9oraeqm", bizData.getString("F0000044"), "F0000038"));//物料明细.来源单据ID
                 entry.put("srcbillnumber", h3yunService.getFieldValueById(
                         "D293655srqj5uui3keso9oraeqm", bizData.getString("F0000044"), "F0000041"));//物料明细.来源单据编号
+                entry.put("srcbillentryid", ida);//物料明细.来源单据行ID
 
-                long ida = Long.parseUnsignedLong(entryData.getString("F0000061"));
+                entry.put("srcbillentryseq", entryData.getString("F0000069"));//物料明细.来源单据分录序号
 
-                entry.put("srcbillentryid", ida);//物料明细.来源系统单据分录ID
-                entry.put("mainbillentity", "im_purinbill");
-                entry.put("mainbillid", h3yunService.getFieldValueById(
+                entry.put("mainbillentity", "im_purinbill");//物料明细.核心单据实体
+                entry.put("mainbillid", h3yunService.getFieldValueById(//物料明细.核心单据ID
                         "D293655srqj5uui3keso9oraeqm", bizData.getString("F0000044"), "F0000038"));
+                ///采购订单编号
+                entry.put("mainbillnumber", h3yunService.getFieldValueById(//物料明细.核心单据编号
+                        "D2936559700b1d66a0e4ee69a84e13da8dbbe95", entryData.getString("F0000068"), "SeqNo"));
 
-                entry.put("mainbillnumber", ida);
-                entry.put("mainbillentryid", h3yunService.getFieldValueById(
-                        "D293655srqj5uui3keso9oraeqm", bizData.getString("F0000044"), "F0000041"));//物料明细.来源单据编号
-
-                entry.put("price", entryData.getDouble("F0000066"));//单价
-                entry.put("priceandtax", entryData.getDouble("F0000066"));//含税单价
-
-                entry.put("taxrateid_number", h3yunService.getFieldValueById(
-                        "D293655sl91vt6h8d0qg1heqw5aq", entryData.getString("F0000065"), "F0000001"));//F0000065
+                entry.put("mainbillentryid", ida);//物料明细.核心单据行ID
+                entry.put("mainbillentryseq", entryData.getString("F0000069"));//物料明细.核心单据分录序号
 
                 List<Map<String, Object>> lkList = new ArrayList<>();
                 Map<String, Object> lkEntry = new LinkedHashMap<>();
@@ -2213,6 +2220,12 @@ public class SyncService {
                 JSONObject entryData = billentryArray.getJSONObject(i);
                 Map<String, Object> entry = new LinkedHashMap<>();
                 entry.put("qty", entryData.getDouble("F0000031")); // 数量
+                entry.put("passqty", entryData.getDouble("F0000031")); // 物料明细.合格数量
+                entry.put("passbaseqty", entryData.getDouble("F0000031")); //物料明细.合格基本数量
+
+//                entry.put("qty", entryData.getDouble("F0000031")); // 数量
+//                entry.put("qty", entryData.getDouble("F0000031")); // 数量
+
                 entry.put("producttype", "standard");//物料明细.产品类别 standard:标准产品, kitparent:套件父项, kitchild:套件子项
 
                 entry.put("linetype_number", "010"); // 物料编码
@@ -2239,6 +2252,7 @@ public class SyncService {
                 entry.put("srcbillnumber", h3yunService.getFieldValueById(
                         "D29365523b214414c2b4e50b9bdca110a9a5951", bizData.getString("F0000050"), "SeqNo"));//物料明细.来源单据编号
                 entry.put("srcbillentryid", ida);//物料明细.来源系统单据分录ID
+                entry.put("srcbillentryseq", entryData.getString("F0000069"));
 
                 entry.put("mainbillentity", "sm_salorder");
                 entry.put("mainbillid", h3yunService.getFieldValueById(
@@ -2246,7 +2260,7 @@ public class SyncService {
                 entry.put("mainbillentryid", ida);
                 entry.put("mainbillnumber", h3yunService.getFieldValueById(
                         "D29365523b214414c2b4e50b9bdca110a9a5951", bizData.getString("F0000050"), "SeqNo"));//物料明细.来源单据编号
-
+                entry.put("mainbillentryseq", entryData.getString("F0000069"));
                 //税率
                 entry.put("taxrateid_number", h3yunService.getFieldValueById(
                         "D293655sl91vt6h8d0qg1heqw5aq", entryData.getString("F0000068"), "F0000001"));//税率
@@ -2352,8 +2366,11 @@ public class SyncService {
                         "D29365537feb4e5e8644b21b7fd938dd322dab3", bizData.getString("F0000049"), "F0000002")); // 结算组织.编码
 
                 //  entry.put("price", entryData.getDouble("F0000062"));//
-                entry.put("priceandtax", entryData.getDouble("F0000071"));//
-//税率
+
+                entry.put("taxrate", entryData.getDouble("F0000073"));//物料明细.税率值
+                entry.put("priceandtax", entryData.getDouble("F0000071"));//物料明细.含税单价
+                entry.put("curamountandtax", entryData.getDouble("F0000072"));//价税合计
+
                 entry.put("taxrateid_number", h3yunService.getFieldValueById(
                         "D293655sl91vt6h8d0qg1heqw5aq", entryData.getString("F0000070"), "F0000001"));//税率
 
@@ -2362,25 +2379,38 @@ public class SyncService {
                         "D293655scvrhqr64jemxdkqk6gf", entryData.getString("F0000062"), "SeqNo"));//仓库
 
 
+                entry.put("discounttype", "NULL");//折扣方式
+                //物料明细.退货类型 1:退货, 2:退补货, 3:仅退款不退货
+                if (entryData.getString("F0000061").equals("退补货")) {
+                    entry.put("returntype", "2");
+                } else if (entryData.getString("F0000061").equals("退货")) {
+                    entry.put("returntype", "1");
+                } else if (entryData.getString("F0000061").equals("仅退款不退货")) {
+                    entry.put("returntype", "3");
+                }
+                entry.put("producttype", "standard");//物料明细.产品类别 standard:标准产品, kitparent:套件父项, kitchild:套件子项
+
+
                 //退货申请单关联销售出库单
+                long ida = Long.parseUnsignedLong(entryData.getString("F0000064"));
                 entry.put("srcbillentity", "im_saloutbill");//物料明细.来源单据实体
-
                 entry.put("srcbillid", h3yunService.getFieldValueById(
                         "D293655suomjudbplkoxrgs42dqj", bizData.getString("F0000058"), "K3id"));//物料明细.来源单据ID
                 entry.put("srcbillnumber", h3yunService.getFieldValueById(
                         "D293655suomjudbplkoxrgs42dqj", bizData.getString("F0000058"), "F0000053"));//物料明细.来源单据编号
+                entry.put("srcbillentryid", ida);//物料明细.来源系统单据分录ID
+                entry.put("srcbillentryseq", entryData.getString("F0000076"));//物料明细.来源单据分录序号
 
-                long ida = Long.parseUnsignedLong(entryData.getString("F0000064"));
 
-                entry.put("srcbillentryid", ida);//物料明细.来源系统单据分录ID
                 entry.put("mainbillentity", "im_saloutbill");
-                entry.put("mainbillid", h3yunService.getFieldValueById(
+                entry.put("mainbillid", h3yunService.getFieldValueById(//物料明细.核心单据ID
                         "D293655suomjudbplkoxrgs42dqj", bizData.getString("F0000058"), "K3id"));
 
-                entry.put("mainbillnumber", ida);
-                entry.put("mainbillentryid", h3yunService.getFieldValueById(
-                        "D293655suomjudbplkoxrgs42dqj", bizData.getString("F0000058"), "F0000053"));//物料明细.来源单据编号
-
+                //销售订单编码
+                entry.put("mainbillnumber", h3yunService.getFieldValueById(//物料明细.核心单据编号
+                        "D29365523b214414c2b4e50b9bdca110a9a5951", entryData.getString("F0000074"), "SeqNo"));
+                entry.put("mainbillentryid", ida);//物料明细.核心单据行ID
+                entry.put("mainbillentryseq", entryData.getString("F0000076"));//物料明细.核心单据分录序号
 
                 List<Map<String, Object>> lkList = new ArrayList<>();
                 Map<String, Object> lkEntry = new LinkedHashMap<>();
@@ -2478,9 +2508,16 @@ public class SyncService {
                 Map<String, Object> entry = new LinkedHashMap<>();
                 // entry.put("id", i);
                 // entry.put("e_paymenttype_number", "180908615723421696"); // 付款用途.id
-                entry.put("e_paymenttype_number", "201"); // 付款用途.编码
+
+
+                if (entryData.getString("F0000045").equals("是")) {
+                    entry.put("e_paymenttype_number", "202"); // 付款用途.编码  201 采购付款  202 预付款
+                } else {
+                    entry.put("e_paymenttype_number", "201"); // 付款用途.编码  201 采购付款  202 预付款
+                }
                 entry.put("e_actamt", entryData.getDouble("F0000024")); // 分录.实付金额
                 entry.put("e_payableamt", entryData.getDouble("F0000024"));//分录.应付金额
+
 //                entry.put("taxrate", h3yunService.getFieldValueById(
 //                        "D293655sl91vt6h8d0qg1heqw5aq", entryData.getString("F0000044"), "F0000001"));//分录.税率(%)
                 entry.put("taxrate", entryData.getDouble("F0000029"));//分录.税率(%)
@@ -2524,6 +2561,10 @@ public class SyncService {
 
                 }
 
+                entry.put("e_material_number",  h3yunService.getFieldValueById(
+                        "D293655fc1a38f7956f400a886f376911a54a30", entryData.getString("F0000046"), "SeqNo"));
+
+
 
 //                entry.put("e_asstacttype", "bd_supplier");//明细.往来单位类型 bd_supplier:供应商, bos_user:人员, bos_org:公司, bd_customer:客户, cas_othercontactunit:其他往来单位
 //                entry.put("e_asstact_number",  h3yunService.getFieldValueById(
@@ -2591,6 +2632,10 @@ public class SyncService {
         payableBill.put("trdbillno", bizData.getString("SeqNo"));//第三方业务编码(防止重复新增,每次新增需要传入唯一值)
         payableBill.put("billtypeid_number", bizData.getString("F0000019")); // 单据类型编码
 
+        //价内税
+        //   payableBill.put("isinclusivetax","true");
+//
+        // payableBill.put("isincludetax", "true");
         // 结算组织(复用查询结果)
         String settleOrgNumber = (String) h3yunService.getFieldValueById(
                 "D29365537feb4e5e8644b21b7fd938dd322dab3", bizData.getString("F0000018"), "F0000002");
@@ -2604,37 +2649,6 @@ public class SyncService {
         payableBill.put("bizdate", formatDate(bizData.getString("F0000021"))); // 业务日期
         payableBill.put("bookdate", formatDate(bizData.getString("F0000048"))); // 记账日期
 
-        // ========== 付款计划分录 planentity(先处理以获取最大日期) ==========
-        List<Map<String, Object>> recPlanList = new ArrayList<>();
-        JSONArray recplanentryArray = bizData.getJSONArray("D293655st5tmoistukggjookxut");
-        String maxPlanDueDate = ""; // 记录明细中最大的到期日
-        if (recplanentryArray != null && !recplanentryArray.isEmpty()) {
-            for (int i = 0; i < recplanentryArray.size(); i++) {
-                JSONObject recData = recplanentryArray.getJSONObject(i);
-                Map<String, Object> recPlan = new LinkedHashMap<>();
-                String uuidHex = recData.getString("ObjectId").replace("-", "");
-// 取后16位(64bit),解析为无符号long,避免溢出和负数问题
-                long id = Long.parseUnsignedLong(uuidHex.substring(uuidHex.length() - 16), 16);
-                recPlan.put("id", id);
-                String planDueDate = formatDate(recData.getString("F0000037"));
-                recPlan.put("planduedate", planDueDate); // 到期日
-                recPlan.put("planpricerate", recData.getDouble("F0000035")); // 应付比例%
-                recPlan.put("planpricetax", recData.getDouble("F0000036")); // 应付金额
-                recPlanList.add(recPlan);
-                // 取最大日期
-                if (maxPlanDueDate.isEmpty() || planDueDate.compareTo(maxPlanDueDate) > 0) {
-                    maxPlanDueDate = planDueDate;
-                }
-            }
-        }
-        payableBill.put("planentity", recPlanList);
-
-        // 最后到期日:取F0000047和明细中最大日期的较大值
-        String dueDate = formatDate(bizData.getString("F0000047"));
-        if (!maxPlanDueDate.isEmpty() && maxPlanDueDate.compareTo(dueDate) > 0) {
-            dueDate = maxPlanDueDate;
-        }
-        payableBill.put("duedate", dueDate); // 最后到期日
 
         payableBill.put("asstacttype", "bd_supplier"); // 往来类型
 
@@ -2665,6 +2679,9 @@ public class SyncService {
 
         payableBill.put("remark", bizData.getString("F0000051")); // 备注
 
+        String CGDDBM = "";//采购订单编码
+        String CGDDid = "";//采购订单ID
+
         // ========== 明细分录 detailentry ==========
         List<Map<String, Object>> entryList = new ArrayList<>();
         JSONArray billentryArray = bizData.getJSONArray("D293655sgomjaqmtouk80lfxhwlk");
@@ -2674,13 +2691,19 @@ public class SyncService {
             for (int i = 0; i < billentryArray.size(); i++) {
                 JSONObject entryData = billentryArray.getJSONObject(i);
                 Map<String, Object> entry = new LinkedHashMap<>();
+                //获取采购订单信息
+                CGDDid = entryData.getString("F0000090");
+                CGDDBM = (String) h3yunService.getFieldValueById(
+                        "D2936559700b1d66a0e4ee69a84e13da8dbbe95", CGDDid, "SeqNo");
+
+
                 // 物料编码
                 entry.put("material_number", h3yunService.getFieldValueById(
                         "D293655fc1a38f7956f400a886f376911a54a30", entryData.getString("F0000027"), "SeqNo"));
                 entry.put("quantity", entryData.getDouble("F0000031")); // 数量
-                entry.put("price", entryData.getDouble("F0000032")); // 单价
+                //   entry.put("price", entryData.getDouble("F0000032")); // 单价
                 entry.put("pricetax", entryData.getDouble("F0000080"));//明细.含税单价
-                entry.put("e_amount", entryData.getDouble("F0000084")); // 金额
+                //  entry.put("e_amount", entryData.getDouble("F0000084")); // 金额
                 entry.put("e_pricetaxtotal", entryData.getDouble("F0000033"));//价税合计
                 entry.put("discountmode", "NULL"); // 折扣方式默认写死无
                 // 单位
@@ -2689,7 +2712,7 @@ public class SyncService {
 
                 entry.put("taxrateid_number", h3yunService.getFieldValueById(
                         "D293655sl91vt6h8d0qg1heqw5aq", entryData.getString("F0000078"), "F0000001"));//明细.税率.编码(为空时,默认取物料组织公共信息下的默认税率)
-                entry.put("e_tax", entryData.getDouble("F0000079"));//税额
+                //  entry.put("e_tax", entryData.getDouble("F0000079"));//税额
                 String F0000085 = entryData.getString("F0000085");
                 if (F0000085.equals("是")) {
                     entry.put("ispresent", true);
@@ -2697,6 +2720,9 @@ public class SyncService {
                     entry.put("ispresent", false);
                 }
 
+                entry.put("e_loss_baseunitqty", 0);
+                entry.put("e_loss_quantity", 0);
+
 
                 List<Map<String, Object>> lkList = new ArrayList<>();
                 Map<String, Object> lkEntry = new LinkedHashMap<>();
@@ -2715,22 +2741,41 @@ public class SyncService {
             }
         }
         payableBill.put("detailentry", entryList);
+        // ========== 付款计划分录 planentity(先处理以获取最大日期) ==========
+        List<Map<String, Object>> recPlanList = new ArrayList<>();
+        JSONArray recplanentryArray = bizData.getJSONArray("D293655st5tmoistukggjookxut");
+        String maxPlanDueDate = ""; // 记录明细中最大的到期日
+        if (recplanentryArray != null && !recplanentryArray.isEmpty()) {
+            for (int i = 0; i < recplanentryArray.size(); i++) {
+                JSONObject recData = recplanentryArray.getJSONObject(i);
+                Map<String, Object> recPlan = new LinkedHashMap<>();
+                String uuidHex = recData.getString("ObjectId").replace("-", "");
+// 取后16位(64bit),解析为无符号long,避免溢出和负数问题
+                long id = Long.parseUnsignedLong(uuidHex.substring(uuidHex.length() - 16), 16);
+                recPlan.put("id", id);
+                String planDueDate = formatDate(recData.getString("F0000037"));
+                recPlan.put("planduedate", planDueDate); // 到期日
+                recPlan.put("planpricerate", recData.getDouble("F0000035")); // 应付比例%
+                recPlan.put("planpricetax", recData.getDouble("F0000036")); // 应付金额
 
-//        // ========== 付款计划分录 planentity ==========
-//        List<Map<String, Object>> recPlanList = new ArrayList<>();
-//        JSONArray recplanentryArray = bizData.getJSONArray("D293655st5tmoistukggjookxut");
-//        if (recplanentryArray != null && !recplanentryArray.isEmpty()) {
-//            for (int i = 0; i < recplanentryArray.size(); i++) {
-//                JSONObject recData = recplanentryArray.getJSONObject(i);
-//                Map<String, Object> recPlan = new LinkedHashMap<>();
-//                recPlan.put("planduedate", formatDate(recData.getString("F0000037"))); // 到期日
-//                recPlan.put("planpricerate", recData.getDouble("F0000035")); // 应付比例%
-//                recPlan.put("planpricetax", recData.getDouble("F0000036")); // 应付金额
-//                recPlanList.add(recPlan);
-//            }
-//        }
-//        payableBill.put("planentity", recPlanList);
+                recPlan.put("plancorebilltype", "pm_purorderbill");//付款计划.核心单据类型 pm_purorderbill:采购订单, conm_purcontract:采购合同, ec_paymentapply:付款单申请单, pm_om_purorderbill:简单委外订单, sctm_scpo:委外采购订单, sm_salorder:销售订单, im_transapply:调拨申请单, sfc_processplanbill:工序计划
+                recPlan.put("plancorebillno", CGDDBM);
+                recPlan.put("planmaterial_number", h3yunService.getFieldValueById("D293655fc1a38f7956f400a886f376911a54a30", recData.getString("F0000087"), "SeqNo"));
+                recPlanList.add(recPlan);
+                // 取最大日期
+                if (maxPlanDueDate.isEmpty() || planDueDate.compareTo(maxPlanDueDate) > 0) {
+                    maxPlanDueDate = planDueDate;
+                }
+            }
+        }
+        payableBill.put("planentity", recPlanList);
 
+        // 最后到期日:取F0000047和明细中最大日期的较大值
+        String dueDate = formatDate(bizData.getString("F0000047"));
+        if (!maxPlanDueDate.isEmpty() && maxPlanDueDate.compareTo(dueDate) > 0) {
+            dueDate = maxPlanDueDate;
+        }
+        payableBill.put("duedate", dueDate); // 最后到期日
         dataList.add(payableBill);
         data.put("data", dataList);
         return data;
@@ -2946,7 +2991,7 @@ public class SyncService {
         // 头部信息
         invoiceApply.put("billno", bizData.getString("SeqNo")); // 单据编号
         invoiceApply.put("trdbillno", bizData.getString("SeqNo"));//第三方业务编码(防止重复新增,每次新增需要传入唯一值)
-         invoiceApply.put("istax", true);//含税
+        invoiceApply.put("istax", true);//含税
 
 
         invoiceApply.put("billtype_number", "arfin_standard_BT_S");//单据类型.编码(arfin_borrowar_BT_S-应收款项调整、arfin_other_BT_S-其他应收、arfin_project_BT_S-项目应收、arfin_salefee_BT_S-销售费用应收、arfin_sersal_BT_S-服务销售应收、arfin_standard_BT_S-标准销售应收、arfin_transfer_BT_S-资产调拨应收)
@@ -2986,6 +3031,9 @@ public class SyncService {
         invoiceApply.put("remark", bizData.getString("F0000012")); // 备注
 //        invoiceApply.put("operator_operatornumber", bizData.getString("CreatedBy")); // 操作人
 
+
+        String XSDDBH = "";
+        String XSDDid = "";
         // 分录信息 iv_invoiceapplyentry
         List<Map<String, Object>> entryList = new ArrayList<>();
         JSONArray billentryArray = bizData.getJSONArray("D293655F95117110d28044aa81b904ec6bafb8d9");
@@ -2993,20 +3041,19 @@ public class SyncService {
             for (int i = 0; i < billentryArray.size(); i++) {
                 JSONObject entryData = billentryArray.getJSONObject(i);
                 Map<String, Object> entry = new LinkedHashMap<>();
+                XSDDid = entryData.getString("F0000042");
+                XSDDBH = (String) h3yunService.getFieldValueById("D29365523b214414c2b4e50b9bdca110a9a5951", XSDDid, "SeqNo");
+
 
                 entry.put("e_quantity", entryData.getDouble("F0000022")); // 数量
-               entry.put("e_taxunitprice", entryData.getDouble("F0000027")); //  含税单价
+                entry.put("e_taxunitprice", entryData.getDouble("F0000027")); //  含税单价
                 //      entry.put("e_unitprice", entryData.getDouble("F0000027")); // 含税单价
-                entry.put("e_amount", entryData.getDouble("F0000028")); // 金额
+                entry.put("e_recamount", entryData.getDouble("F0000028")); // 金额
                 entry.put("e_discountmode", "NULL"); // 明细.折扣方式 PERCENT:折扣率(%), PERUNIT:单位折扣额, NULL:无, TOTAL:固定折扣额
 
                 entry.put("taxrateid_number", h3yunService.getFieldValueById("D293655sl91vt6h8d0qg1heqw5aq", entryData.getString("F0000033"), "F0000001"));
                 entry.put("e_material_number", entryData.getString("F0000026")); // 物料编码
 
-
-                /////这里
-
-
                 /////////应收单关联销售出库单
 
                 String uuidHex = entryData.getString("F0000030").replace("-", "");
@@ -3039,6 +3086,45 @@ public class SyncService {
                 entryList.add(entry);
             }
         }
+
+
+        // ========== 收款计划分录 planentity(先处理以获取最大日期) ==========
+        List<Map<String, Object>> recPlanList = new ArrayList<>();
+        JSONArray recplanentryArray = bizData.getJSONArray("D293655164d230a50df4ad4bc933d3a30c0d154");
+        String maxPlanDueDate = ""; // 记录明细中最大的到期日
+        if (recplanentryArray != null && !recplanentryArray.isEmpty()) {
+            for (int i = 0; i < recplanentryArray.size(); i++) {
+                JSONObject recData = recplanentryArray.getJSONObject(i);
+                Map<String, Object> recPlan = new LinkedHashMap<>();
+                String uuidHex = recData.getString("ObjectId").replace("-", "");
+// 取后16位(64bit),解析为无符号long,避免溢出和负数问题
+                long id = Long.parseUnsignedLong(uuidHex.substring(uuidHex.length() - 16), 16);
+                recPlan.put("id", id);
+                String planDueDate = formatDate(recData.getString("F0000023"));
+                recPlan.put("planduedate", planDueDate); // 到期日
+                recPlan.put("planpricerate", recData.getDouble("F0000024")); // 应收比例%
+                recPlan.put("planpricetax", recData.getDouble("F0000025")); // 应收金额
+
+                recPlan.put("plancorebilltype", "sm_salorder");//付款计划.核心单据类型 pm_purorderbill:采购订单, conm_purcontract:采购合同, ec_paymentapply:付款单申请单, pm_om_purorderbill:简单委外订单, sctm_scpo:委外采购订单, sm_salorder:销售订单, im_transapply:调拨申请单, sfc_processplanbill:工序计划
+                recPlan.put("plancorebillno", XSDDBH);
+                recPlan.put("planmaterial_number", h3yunService.getFieldValueById("D293655fc1a38f7956f400a886f376911a54a30", recData.getString("F0000037"), "SeqNo"));
+                recPlanList.add(recPlan);
+                // 取最大日期
+                if (maxPlanDueDate.isEmpty() || planDueDate.compareTo(maxPlanDueDate) > 0) {
+                    maxPlanDueDate = planDueDate;
+                }
+            }
+        }
+        invoiceApply.put("planentity", recPlanList);
+
+        // 最后到期日:取F0000047和明细中最大日期的较大值
+//        String dueDate = formatDate(bizData.getString("F0000047"));
+//        if (!maxPlanDueDate.isEmpty() && maxPlanDueDate.compareTo(dueDate) > 0) {
+//            dueDate = maxPlanDueDate;
+//        }
+        invoiceApply.put("duedate", maxPlanDueDate); // 最后到期日
+
+
         invoiceApply.put("entry", entryList);
 
         dataList.add(invoiceApply);