|
|
@@ -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";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|