Bläddra i källkod

12.9代码提交

“lqy 1 vecka sedan
förälder
incheckning
4141ab425d

+ 1 - 1
mjava-huagao/src/main/java/com/malk/huagao/controller/KdYdCustomerController.java

@@ -51,7 +51,7 @@ private YDClient ydClient;
 ////                .updateFormDataJson(JSONObject.toJSONString(UtilMap.map(employ,id)))//xz04
 //                .useLatestVersion(true)
 //                .build(), YDConf.FORM_OPERATION.update);
-        ydHuaGaoService.synckdYdTRANSFER();
+        ydHuaGaoService.synckdYdMaterial();
 //        ydHuaGaoService.synckdYdPayment();
 //        ydHuaGaoService.syncKdYdReceivable();
 //        kdYdZpService.insertkdYdZp(data);

+ 6 - 0
mjava-huagao/src/main/java/com/malk/huagao/entity/KdYdCustomer.java

@@ -77,6 +77,12 @@ public class KdYdCustomer implements Serializable {
 
     private String qyxygl;
 
+    private String khlx;
+
+    private String sfjtkh;
+
+    private String dyjtkh;
+
     private LocalDateTime createTime;
 
     private LocalDateTime updateTime;

+ 4 - 3
mjava-huagao/src/main/java/com/malk/huagao/entity/KdYdMaterial.java

@@ -1,8 +1,7 @@
 package com.malk.huagao.entity;
 
-import com.baomidou.mybatisplus.annotation.IdType;
-import com.baomidou.mybatisplus.annotation.TableId;
-import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.*;
+
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
@@ -71,6 +70,8 @@ public class KdYdMaterial implements Serializable {
     private LocalDateTime updateTime;
 
     private String forminstid;
+@TableField("FMATERIALID")
+    private int FMATERIALID;
 
       @TableId(value = "id", type = IdType.AUTO)
       private Long id;

+ 194 - 56
mjava-huagao/src/main/java/com/malk/huagao/service/impl/KdYdCustomerServiceImpl.java

@@ -2,7 +2,11 @@ package com.malk.huagao.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.malk.huagao.entity.KdYdCustomer;
+import com.malk.huagao.entity.KdYdCustomerLiaison;
+import com.malk.huagao.entity.KdYdDeliveryDetail;
+import com.malk.huagao.mapper.KdYdCustomerLiaisonMapper;
 import com.malk.huagao.mapper.KdYdCustomerMapper;
 import com.malk.huagao.service.IKdYdCustomerService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -16,7 +20,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.time.LocalDateTime;
-import java.util.Map;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * <p>
@@ -32,6 +38,8 @@ public class KdYdCustomerServiceImpl extends ServiceImpl<KdYdCustomerMapper, KdY
     private YDClient ydClient;
     @Autowired
     private KdYdCustomerMapper kdYdCustomerMapper;
+    @Autowired
+    private KdYdCustomerLiaisonMapper kdYdCustomerLiaisonMapper;
 
     @Override
     public void insertCustomer(Map map) {
@@ -39,19 +47,25 @@ public class KdYdCustomerServiceImpl extends ServiceImpl<KdYdCustomerMapper, KdY
         String formInstId = UtilMap.getString(map, "formInstId");
         String type = UtilMap.getString(map, "type");
 
+        // === 操作类型 3:仅软删除客户(根据 khbm 标记 operation_type=3)===
         if ("3".equals(type)) {
-            String bm = UtilMap.getString(map, "bm");
-            KdYdCustomer kdYdCustomer = new KdYdCustomer();
-            kdYdCustomer.setOperationType("3");
-            kdYdCustomer.setSyncStatus("0");
-            kdYdCustomerMapper.update(kdYdCustomer, new LambdaQueryWrapper<KdYdCustomer>().eq(KdYdCustomer::getKhbm, bm));
-            return; // 或者根据你的业务逻辑返回相应的结果
+            String khbm = UtilMap.getString(map, "bm"); // 注意:这里 map 中的 "bm" 实际是 khbm
+            KdYdCustomer updateObj = new KdYdCustomer();
+            updateObj.setOperationType("3");
+            updateObj.setSyncStatus("0");
+            kdYdCustomerMapper.update(updateObj,
+                    new LambdaQueryWrapper<KdYdCustomer>().eq(KdYdCustomer::getKhbm, khbm));
+            return;
         }
-        DDR_New ddrNew = ydClient.queryData(YDParam.builder()
-                .formInstId(formInstId)
-                .build(), YDConf.FORM_QUERY.retrieve_id);
+
+        // === 获取表单数据 ===
+        DDR_New ddrNew = ydClient.queryData(
+                YDParam.builder().formInstId(formInstId).build(),
+                YDConf.FORM_QUERY.retrieve_id
+        );
         Map formData = ddrNew.getFormData();
 
+        // === 提取主表字段(完全保留原有写法)===
         String khmc = UtilMap.getString(formData, "textField_lqanqe6j");
         String khbm = UtilMap.getString(formData, "textField_meqhqqvg");
         String xssx = UtilMap.getString(formData, "selectField_megi74y7");
@@ -64,10 +78,10 @@ public class KdYdCustomerServiceImpl extends ServiceImpl<KdYdCustomerMapper, KdY
         String nsdjh = UtilMap.getString(formData, "textField_meqhqqvm");
         String khyh = UtilMap.getString(formData, "textField_meqhqqvn");
         String yhzh = UtilMap.getString(formData, "textField_meqhqqvs");
+        String jxslx = UtilMap.getString(formData, "selectField_mis6kl56");
         String kplx = UtilMap.getString(formData, "selectField_lwopqbye");
         String kplxdh = UtilMap.getString(formData, "textField_llujklkp");
         String kptxdz = UtilMap.getString(formData, "textField_llujklkv");
-        String uuid = UtilMap.getString(formData, "textField_mgowmnlf");
         String tyshxydm = UtilMap.getString(formData, "textField_mfxrrysq");
         String spdzyx = UtilMap.getString(formData, "textField_mg0fq6l4");
         String khtjr = UtilMap.getString(formData, "textField_mfdrrg87");
@@ -78,53 +92,177 @@ public class KdYdCustomerServiceImpl extends ServiceImpl<KdYdCustomerMapper, KdY
         String qyxygl = UtilMap.getString(formData, "radioField_mfxs7rd2");
         String mrsl = UtilMap.getString(formData, "selectField_mfxrryt3");
         String sfl = UtilMap.getString(formData, "selectField_mfxrryt2");
-        String tjruuid = UtilMap.getString(formData, "textField_mgqbiov3");
-        KdYdCustomer kdYdCustomer = new KdYdCustomer();
-        kdYdCustomer.setKhmc(khmc);
-        kdYdCustomer.setXssx(xssx);
-        kdYdCustomer.setSpdzyx(spdzyx);
-        kdYdCustomer.setKhsx(khsx);
-        kdYdCustomer.setKhlb(khlb);
-        kdYdCustomer.setKhfz(khfz);
-        kdYdCustomer.setFptt(fptt);
-        kdYdCustomer.setNsdjh(nsdjh);
-        kdYdCustomer.setKhyh(khyh);
-        kdYdCustomer.setYhzh(yhzh);
-        kdYdCustomer.setKplx(kplx);
-        kdYdCustomer.setKplxdh(kplxdh);
-        kdYdCustomer.setKptxdz(kptxdz);
-        kdYdCustomer.setTyshxydm(tyshxydm);
-        kdYdCustomer.setKhtjr(khtjr);
-//        kdYdCustomer.setUuid(uuid);
-        kdYdCustomer.setSktj(sktj);
-        kdYdCustomer.setXsy(xsy);
-        kdYdCustomer.setJsbb(jsbb);
-        kdYdCustomer.setKhyxj(khyxj);
-        kdYdCustomer.setQyxygl(qyxygl);
-        kdYdCustomer.setMrsl(mrsl);
-        kdYdCustomer.setSfl(sfl);
-        kdYdCustomer.setKhbm(khbm);
-        kdYdCustomer.setJxr(jxr);
-        kdYdCustomer.setKhxypj(khxypj);
-//        kdYdCustomer.setFormInstId(formInstId);
-//        kdYdCustomer.setTjruuid(tjruuid);
-        kdYdCustomer.setSyncStatus("0");
-        kdYdCustomer.setOperationType("1");
-        if ("2".equals(type)) {
-            kdYdCustomer.setOperationType(type);
-            kdYdCustomerMapper.update(kdYdCustomer, new LambdaQueryWrapper<KdYdCustomer>().eq(KdYdCustomer::getKhbm, khbm));
+
+        // === 构建客户对象 ===
+        KdYdCustomer customer = new KdYdCustomer();
+        customer.setKhmc(khmc);
+        customer.setXssx(xssx);
+        customer.setSpdzyx(spdzyx);
+        customer.setKhsx(khsx);
+        customer.setKhlb(khlb);
+        customer.setKhfz(khfz);
+        customer.setFptt(fptt);
+        customer.setNsdjh(nsdjh);
+        customer.setKhyh(khyh);
+        customer.setYhzh(yhzh);
+        customer.setKplx(kplx);
+        customer.setKhlx(jxslx);
+        customer.setKplxdh(kplxdh);
+        customer.setKptxdz(kptxdz);
+        customer.setTyshxydm(tyshxydm);
+        customer.setKhtjr(khtjr);
+        customer.setSktj(sktj);
+        customer.setXsy(xsy);
+        customer.setJsbb(jsbb);
+        customer.setKhyxj(khyxj);
+        customer.setQyxygl(qyxygl);
+        customer.setMrsl(mrsl);
+        customer.setSfl(sfl);
+        customer.setKhbm(khbm);
+        customer.setJxr(jxr);
+        customer.setKhxypj(khxypj);
+        customer.setFormInstId(formInstId);
+        customer.setSyncStatus("0");
+        customer.setOperationType(type);
+
+        // === 判断是新增还是更新 ===
+        LambdaQueryWrapper<KdYdCustomer> wrapper = new LambdaQueryWrapper<>();
+        wrapper.eq(KdYdCustomer::getKhbm, khbm);
+        KdYdCustomer existing = kdYdCustomerMapper.selectOne(wrapper);
+
+        Long customerId;
+        if (existing != null) {
+            customer.setId(existing.getId());
+            kdYdCustomerMapper.updateById(customer);
+            customerId = existing.getId();
         } else {
-            this.save(kdYdCustomer);
+            if ("2".equals(type)) {
+                throw new RuntimeException("客户不存在,无法更新: " + khbm);
+            }
+            this.save(customer);
+            customerId = customer.getId();
+        }
+
+        // === 处理联系人子表 ===
+        List<Map> tableField = (List<Map>) formData.get("tableField_mfkks8ww");
+        if (tableField == null || tableField.isEmpty()) {
+            return;
         }
 
-//        LambdaQueryWrapper<KdYdCustomer> YdCustomerLambdaQueryWrapper = new LambdaQueryWrapper<>();
-//        YdCustomerLambdaQueryWrapper.eq(KdYdCustomer::getFormInstId, formInstId);
-//        KdYdCustomer kdYdCustomer1 = kdYdCustomerMapper.selectOne(YdCustomerLambdaQueryWrapper);
-//        Long id = kdYdCustomer1.getId();
-//        ydClient.operateData(
-//                YDParam.builder()
-//                        .formInstanceId(formInstId)
-//                        .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("textField_mgowmnli", id)))
-//                        .useLatestVersion(true).build(), YDConf.FORM_OPERATION.update);
+        // ✅【修改点1】全局查找最大 bm(不按 customer_id 筛选)
+        String currentMaxBm = null;
+        QueryWrapper<KdYdCustomerLiaison> maxBmWrapper = new QueryWrapper<>();
+        maxBmWrapper.select("MAX(bm)");
+        List<Object> maxResults = kdYdCustomerLiaisonMapper.selectObjs(maxBmWrapper);
+        if (!maxResults.isEmpty()) {
+            Object obj = maxResults.get(0);
+            if (obj != null) {
+                if (obj instanceof Object[]) {
+                    Object[] arr = (Object[]) obj;
+                    if (arr.length > 0 && arr[0] != null) {
+                        currentMaxBm = arr[0].toString();
+                    }
+                } else {
+                    currentMaxBm = obj.toString();
+                }
+            }
+        }
+
+        // ✅【新增】用于收集回写用的子表行
+        List<Map> updatedTableRowsForYD = new ArrayList<>();
+
+        for (Map item : tableField) {
+            String xm = safeGetString(item, "textField_l3s6ubhq");
+            String dh = safeGetString(item, "textField_lqbzc3gq");
+            String zw = safeGetString(item, "textField_l3s6ubht");
+            String gddh = safeGetString(item, "textField_mfxu5dnk");
+            String bm = safeGetString(item, "textField_mfkp33s5");
+
+            String finalBm;
+            if (bm != null && !bm.trim().isEmpty()) {
+                finalBm = bm.trim();
+            } else {
+                // 全局自增
+                if (currentMaxBm == null) {
+                    finalBm = "CXR00001";
+                } else {
+                    finalBm = incrementCode(currentMaxBm);
+                }
+                currentMaxBm = finalBm; // 下一条继续递增
+            }
+
+            // ✅【新增】构造回写行(复制原行并覆盖 bm)
+            Map updatedRow = new HashMap(item);
+            updatedRow.put("textField_mfkp33s5", finalBm);
+            updatedTableRowsForYD.add(updatedRow);
+
+            KdYdCustomerLiaison liaison = new KdYdCustomerLiaison();
+            liaison.setXm(xm);
+            liaison.setZw(zw);
+            liaison.setBm(finalBm);
+            liaison.setGddh(gddh);
+            liaison.setCustomerId(customerId);
+            liaison.setSyncStatus("0");
+            liaison.setOperationType(type);
+
+            if ("2".equals(type)) {
+                LambdaQueryWrapper<KdYdCustomerLiaison> updateWrapper = new LambdaQueryWrapper<>();
+                updateWrapper.eq(KdYdCustomerLiaison::getBm, finalBm);
+                KdYdCustomerLiaison exists = kdYdCustomerLiaisonMapper.selectOne(updateWrapper);
+                if (exists != null) {
+                    liaison.setId(exists.getId());
+                    kdYdCustomerLiaisonMapper.updateById(liaison);
+                } else {
+                    kdYdCustomerLiaisonMapper.insert(liaison);
+                }
+            } else {
+                kdYdCustomerLiaisonMapper.insert(liaison);
+            }
+        }
+
+        // ✅【修改点2】回写 bm 到宜搭表单(仅在此处新增)
+        try {
+            Map<String, Object> updatePayload = new HashMap<>();
+            updatePayload.put("tableField_mfkks8ww", updatedTableRowsForYD);
+            ydClient.operateData(
+                    YDParam.builder()
+                            .formInstId(formInstId)
+                            .updateFormDataJson(JSONObject.toJSONString(updatePayload))
+                            .build(),
+                    YDConf.FORM_OPERATION.update
+            );
+        } catch (Exception e) {
+            // 使用兼容性日志写法(避免占位符问题)
+            log.warn("回写 bm 到宜搭失败,formInstId: " + formInstId + ", 错误: " + e.getMessage());
+        }
     }
+
+    // === 工具方法(保持不变)===
+    private String safeGetString(Map formData, String key) {
+        Object val = formData.get(key);
+        return val == null ? "" : String.valueOf(val);
+    }
+
+    /**
+     * 从编码如 CXR04454 生成 CXR04455
+     */
+    private String incrementCode(String code) {
+        if (code == null || code.isEmpty()) {
+            return "CXR00001";
+        }
+        Pattern pattern = Pattern.compile("^(\\D*)(\\d+)$");
+        Matcher matcher = pattern.matcher(code.trim());
+        if (matcher.matches()) {
+            String prefix = matcher.group(1);
+            String numberPart = matcher.group(2);
+            long number = Long.parseLong(numberPart);
+            String newNumber = String.format("%0" + numberPart.length() + "d", number + 1);
+            return prefix + newNumber;
+        } else {
+            return "CXR00001";
+        }
+    }
+
+
+
 }

+ 3 - 0
mjava-huagao/src/main/java/com/malk/huagao/service/impl/KdYdDeliveryServiceImpl.java

@@ -68,6 +68,9 @@ public class KdYdDeliveryServiceImpl extends ServiceImpl<KdYdDeliveryMapper, KdY
         String kh = UtilMap.getString(formData, "textField_mejnamf2");
         String jsbb = UtilMap.getString(formData, "selectField_mg3fuqvn");
         String djbh = UtilMap.getString(formData, "serialNumberField_mheazm7w");
+        if("2".equals(type)){
+             djbh = UtilMap.getString(formData, "textField_miwwha1a");
+        }
         String xsbm = UtilMap.getString(formData, "textField_krnn5bmr");
 //        String xsy = UtilMap.getString(formData, "employeeField_mejowmng").replace("[\"", "").replace("\"]", "").trim();
         String lllx = UtilMap.getString(formData, "selectField_mejowmnc");

+ 3 - 0
mjava-huagao/src/main/java/com/malk/huagao/service/impl/KdYdOrderServiceImpl.java

@@ -73,6 +73,9 @@ public class KdYdOrderServiceImpl extends ServiceImpl<KdYdOrderMapper, KdYdOrder
         String djlx = UtilMap.getString(formData, "selectField_mejowmna");
         String khmc = UtilMap.getString(formData, "textField_mejnamf2");
         String djbh = UtilMap.getString(formData, "serialNumberField_mewfgzku");
+        if("2".equals(type)){
+             djbh = UtilMap.getString(formData, "textField_miwvnkep");
+        }
         LocalDateTime rq = parseTimestamp(UtilMap.getString(formData, "dateField_mejowmnb"));
         String khxypj = UtilMap.getString(formData, "selectField_mewirdx4");
         String ywlx = UtilMap.getString(formData, "textField_mfxv2vfz");

+ 6 - 4
mjava-huagao/src/main/java/com/malk/huagao/service/impl/YdHuaGaoServiceImpl.java

@@ -820,7 +820,7 @@ public class YdHuaGaoServiceImpl implements YdHuaGaoService {
         log.info("定时同步-物料单");
         // 查询需要删除的数据
         LambdaQueryWrapper<KdYdMaterial> materialdel = new LambdaQueryWrapper<>();
-        materialdel.eq(KdYdMaterial::getOperationType, 3)  // 修正:使用 materialdel 而不是 materialqw
+        materialdel.eq(KdYdMaterial::getOperationType, "3")  // 修正:使用 materialdel 而不是 materialqw
                 .eq(KdYdMaterial::getSyncStatus, "0");
         List<KdYdMaterial> kdYdMaterialdels = kdYdMaterialMapper.selectList(materialdel);
 
@@ -832,12 +832,12 @@ public class YdHuaGaoServiceImpl implements YdHuaGaoService {
 
             for (KdYdMaterial kdYdMaterial : kdYdMaterialdels) {
                 try {
-                    String wlbm = kdYdMaterial.getWlbm();
+                    String wlbm = String.valueOf(kdYdMaterial.getFMATERIALID());
                     List<Map> list1 = (List<Map>) ydClient.queryData(YDParam.builder()
                             .formUuid("FORM-E64114E9F2C9426E91F92886EDFFA2C08Q90")
                             .appType("APP_VQDMMWS6OR1VHL8VMFD3")  // 新增:添加应用参数
                             .systemToken("XE766X81JHKXK4Z27SYOI86CPCLQ3J1LV7ODMH2")  // 新增:添加系统令牌
-                            .searchFieldJson(JSONObject.toJSONString(UtilMap.map("textField_mfxbtcdh", wlbm)))
+                            .searchFieldJson(JSONObject.toJSONString(UtilMap.map("textField_misfb2ft", wlbm)))
                             .build(), YDConf.FORM_QUERY.retrieve_list_all).getData();
 
                     if (list1 != null && !list1.isEmpty()) {
@@ -897,6 +897,7 @@ public class YdHuaGaoServiceImpl implements YdHuaGaoService {
                 String wlmc = kdYdMaterial.getWlmc();
                 String xh = kdYdMaterial.getXh();
                 String gg = kdYdMaterial.getGg();
+                String jdnm = String.valueOf(kdYdMaterial.getFMATERIALID());
                 String wlfz = kdYdMaterial.getWlfz();
                 String wlsx = kdYdMaterial.getWlsx();
                 String jbdw = kdYdMaterial.getJbdw();
@@ -920,6 +921,7 @@ public class YdHuaGaoServiceImpl implements YdHuaGaoService {
                 updateFormData.put("textField_mfxbtcdh", wlbm);
                 updateFormData.put("textField_l43jpnsg", xh);
                 updateFormData.put("textField_lqbxkzbq", gg);
+                updateFormData.put("textField_misfb2ft", jdnm);
                 updateFormData.put("textField_mhlbx8hi", wlfz);
                 updateFormData.put("textField_l43jpnsh", wlsx);
                 updateFormData.put("textField_mfxbtcdo", jbdw);
@@ -948,7 +950,7 @@ public class YdHuaGaoServiceImpl implements YdHuaGaoService {
                         .appType("APP_VQDMMWS6OR1VHL8VMFD3")
                         .systemToken("XE766X81JHKXK4Z27SYOI86CPCLQ3J1LV7ODMH2")
 //                        .searchCondition(JSONObject.toJSONString(UtilMap.map("textField_mg4h6mz5", wlbt)))
-                        .searchCondition(JSONObject.toJSONString(UtilMap.map("textField_mfxbtcdh", wlbm)))
+                        .searchCondition(JSONObject.toJSONString(UtilMap.map("textField_misfb2ft", jdnm)))
                         .formDataJson(JSONObject.toJSONString(updateFormData))
                         .build(), YDConf.FORM_OPERATION.upsert);
 

+ 15 - 1
mjava-huagao/src/test/java/com/malk/huagao/KdTest.java

@@ -1,10 +1,13 @@
 package com.malk.huagao;
 
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.kingdee.bos.webapi.entity.IdentifyInfo;
 import com.kingdee.bos.webapi.sdk.K3CloudApi;
 import com.malk.huagao.KdEntity.BillQuery;
 import com.malk.huagao.config.KDWebApiConf;
+import com.malk.huagao.entity.KdYdMaterial;
+import com.malk.huagao.mapper.KdYdMaterialMapper;
 import com.malk.huagao.service.KdHuaGaoService;
 import com.malk.server.aliwork.YDConf;
 import com.malk.server.aliwork.YDParam;
@@ -33,7 +36,18 @@ public class KdTest {
 
     @Autowired
     private YDClient ydClient;
-
+    @Autowired
+    private KdYdMaterialMapper kdYdMaterialMapper;
+@Test
+public void test50() throws Exception {
+    LambdaQueryWrapper<KdYdMaterial> materialdel = new LambdaQueryWrapper<>();
+//    materialdel.eq(KdYdMaterial::getOperationType, "3")  // 修正:使用 materialdel 而不是 materialqw
+//            .eq(KdYdMaterial::getSyncStatus, "0");
+
+    List<KdYdMaterial> kdYdMaterialdels = kdYdMaterialMapper.selectList(materialdel);
+    int size =kdYdMaterialdels.size();
+    System.out.println(size);
+}
     @Test
     public void test() throws Exception {
         K3CloudApi client = new K3CloudApi(initIden());