|
|
@@ -0,0 +1,377 @@
|
|
|
+package com.malk.huagao.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.malk.huagao.entity.*;
|
|
|
+import com.malk.huagao.mapper.*;
|
|
|
+import com.malk.huagao.service.YdHuaGaoService;
|
|
|
+import com.malk.server.aliwork.YDConf;
|
|
|
+import com.malk.server.aliwork.YDParam;
|
|
|
+import com.malk.service.aliwork.YDClient;
|
|
|
+import com.malk.utils.UtilMap;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.checkerframework.checker.units.qual.A;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class YdHuaGaoServiceImpl implements YdHuaGaoService {
|
|
|
+ @Autowired
|
|
|
+ private KdYdCustomerMapper kdYdCustomerMapper;
|
|
|
+ @Autowired
|
|
|
+ private YDClient ydClient;
|
|
|
+ @Autowired
|
|
|
+ private KdYdCustomerReferrerMapper kdYdCustomerReferrerMapper;
|
|
|
+ @Autowired
|
|
|
+ private KdYdOrderMapper kdYdOrderMapper;
|
|
|
+ @Autowired
|
|
|
+ private KdYdDeliveryMapper kdYdDeliveryMapper;
|
|
|
+ @Autowired
|
|
|
+ private KdYdOutboundMapper kdYdOutboundMapper;
|
|
|
+ @Autowired
|
|
|
+ private KdYdReceivableMapper kdYdReceivableMapper;
|
|
|
+ @Autowired
|
|
|
+ private KdYdZpMapper kdYdZpMapper;
|
|
|
+ @Autowired
|
|
|
+ private KdYdMaterialMapper kdYdMaterialMapper;
|
|
|
+ @Override
|
|
|
+ public void syncKdYdCustomer() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncKdYDcustomerLiaison() {
|
|
|
+ log.info("定时同步-客户推荐人");
|
|
|
+ try {
|
|
|
+
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime fiveMinutesAgo = now.minusMinutes(5);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<KdYdCustomerReferrer> KdYdCustomerReferrers = kdYdCustomerReferrerMapper.selectRecentUpdated(fiveMinutesAgo);
|
|
|
+ if (KdYdCustomerReferrers.isEmpty()) {
|
|
|
+ log.info("【客户推荐人同步任务】无需要同步的数据,结束");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KdYdCustomerReferrer kdYdCustomerReferrer : KdYdCustomerReferrers) {
|
|
|
+ try {
|
|
|
+ String bm = kdYdCustomerReferrer.getBm();
|
|
|
+ String tjruuid = kdYdCustomerReferrer.getTjruuid();
|
|
|
+ String formInstId = kdYdCustomerReferrer.getFormInstId();
|
|
|
+ if (ObjectUtil.hasEmpty(formInstId, bm)) {
|
|
|
+ log.warn("跳过同步: formInstId 或 khbm 为空, customer={}", kdYdCustomerReferrer.getId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+// if (tjruuid == null) {
|
|
|
+// List<Map> khdata = (List<Map>) ydClient.queryData(
|
|
|
+// YDParam.builder()
|
|
|
+// .formUuid("FORM-68154CC0A7054BF0B1C933752CD3881FB0SR")
|
|
|
+// .searchFieldJson(JSONObject.toJSONString(UtilMap.map("textField_mgqbiov3", tjruuid)))
|
|
|
+// .build(),
|
|
|
+// YDConf.FORM_QUERY.retrieve_list_all
|
|
|
+// ).getData();
|
|
|
+// if (khdata.size() > 0) {
|
|
|
+// khbm = UtilMap.getString(khdata.get(0), "textField_meqhqqvg");
|
|
|
+// }
|
|
|
+//// }
|
|
|
+// LambdaQueryWrapper<KdYdCustomer> YdCustomerLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+// YdCustomerLambdaQueryWrapper.eq(KdYdCustomer::getTjruuid, tjruuid);
|
|
|
+// KdYdCustomer kdYdCustomer1 = kdYdCustomerMapper.selectOne(YdCustomerLambdaQueryWrapper);
|
|
|
+// String formInstId1 = kdYdCustomer1.getFormInstId();
|
|
|
+// ydClient.operateData(
|
|
|
+// YDParam.builder()
|
|
|
+// .formInstanceId(formInstId1)
|
|
|
+// .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("textField_mfdrrg87", bm)))
|
|
|
+// .useLatestVersion(true).build(), YDConf.FORM_OPERATION.update);
|
|
|
+ ydClient.operateData(
|
|
|
+ YDParam.builder()
|
|
|
+ .formInstanceId(formInstId)
|
|
|
+ .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("textField_mgqbiouy", bm)))
|
|
|
+ .useLatestVersion(true).build(), YDConf.FORM_OPERATION.update);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步单条客户推荐人数据异常: formInstId={}", kdYdCustomerReferrer.getFormInstId(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("【客户推荐人同步任务】执行完成,共处理 {} 条记录", KdYdCustomerReferrers.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("【客户推荐人同步任务】执行过程中发生严重错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncKdYdOrder() {
|
|
|
+ log.info("定时同步-订单");
|
|
|
+ try {
|
|
|
+
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime fiveMinutesAgo = now.minusMinutes(5);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<KdYdOrder> KdYdOrders = kdYdOrderMapper.selectRecentUpdated(fiveMinutesAgo);
|
|
|
+ if (KdYdOrders.isEmpty()) {
|
|
|
+ log.info("【订单同步任务】无需要同步的数据,结束");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KdYdOrder kdYdOrder : KdYdOrders) {
|
|
|
+ try {
|
|
|
+ String bm = kdYdOrder.getDjbh();
|
|
|
+// String tjruuid = kdYdOrder.getTjruuid();
|
|
|
+ String formInstId = kdYdOrder.getForminstid();
|
|
|
+ if (ObjectUtil.hasEmpty(formInstId, bm)) {
|
|
|
+ log.warn("跳过同步: formInstId 或 khbm 为空, customer={}", kdYdOrder.getId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+// if (tjruuid == null) {
|
|
|
+// List<Map> khdata = (List<Map>) ydClient.queryData(
|
|
|
+// YDParam.builder()
|
|
|
+// .formUuid("FORM-68154CC0A7054BF0B1C933752CD3881FB0SR")
|
|
|
+// .searchFieldJson(JSONObject.toJSONString(UtilMap.map("textField_mgqbiov3", tjruuid)))
|
|
|
+// .build(),
|
|
|
+// YDConf.FORM_QUERY.retrieve_list_all
|
|
|
+// ).getData();
|
|
|
+// if (khdata.size() > 0) {
|
|
|
+// khbm = UtilMap.getString(khdata.get(0), "textField_meqhqqvg");
|
|
|
+// }
|
|
|
+//// }
|
|
|
+// LambdaQueryWrapper<KdYdCustomer> YdCustomerLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+// YdCustomerLambdaQueryWrapper.eq(KdYdCustomer::getTjruuid, tjruuid);
|
|
|
+// KdYdCustomer kdYdCustomer1 = kdYdCustomerMapper.selectOne(YdCustomerLambdaQueryWrapper);
|
|
|
+// String formInstId1 = kdYdCustomer1.getFormInstId();
|
|
|
+// ydClient.operateData(
|
|
|
+// YDParam.builder()
|
|
|
+// .formInstanceId(formInstId1)
|
|
|
+// .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("textField_mfdrrg87", bm)))
|
|
|
+// .useLatestVersion(true).build(), YDConf.FORM_OPERATION.update);
|
|
|
+ ydClient.operateData(
|
|
|
+ YDParam.builder()
|
|
|
+ .formInstanceId(formInstId)
|
|
|
+ .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("textField_mg327tqe", bm)))
|
|
|
+ .useLatestVersion(true).build(), YDConf.FORM_OPERATION.update);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步单条订单数据异常: formInstId={}", kdYdOrder.getForminstid(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("【订单同步任务】执行完成,共处理 {} 条记录", KdYdOrders.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("【订单同步任务】执行过程中发生严重错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncKdYdDelivery() {
|
|
|
+ log.info("定时同步-发货单");
|
|
|
+ try {
|
|
|
+
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime fiveMinutesAgo = now.minusMinutes(5);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<KdYdDelivery> KdYdDeliverys = kdYdDeliveryMapper.selectRecentUpdated(fiveMinutesAgo);
|
|
|
+ if (KdYdDeliverys.isEmpty()) {
|
|
|
+ log.info("【发货单同步任务】无需要同步的数据,结束");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KdYdDelivery kdYdDelivery : KdYdDeliverys) {
|
|
|
+ try {
|
|
|
+ String djbh = kdYdDelivery.getDjbh();
|
|
|
+// String tjruuid = kdYdOrder.getTjruuid();
|
|
|
+ String formInstId = kdYdDelivery.getForminstid();
|
|
|
+ if (ObjectUtil.hasEmpty(formInstId, djbh)) {
|
|
|
+ log.warn("跳过同步: formInstId 或 khbm 为空, customer={}", kdYdDelivery.getId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ ydClient.operateData(
|
|
|
+ YDParam.builder()
|
|
|
+ .formInstanceId(formInstId)
|
|
|
+ .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("textField_mg3fuqvh", djbh)))
|
|
|
+ .useLatestVersion(true).build(), YDConf.FORM_OPERATION.update);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步单条发货单数据异常: formInstId={}", kdYdDelivery.getForminstid(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("【发货单同步任务】执行完成,共处理 {} 条记录", KdYdDeliverys.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("【发货单同步任务】执行过程中发生严重错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+//TODO: 2022/5/10 订单出库同步
|
|
|
+ @Override
|
|
|
+ public void synckdYdOutbound() {
|
|
|
+ log.info("定时同步-出库单");
|
|
|
+ try {
|
|
|
+
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime fiveMinutesAgo = now.minusMinutes(5);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<KdYdOutbound> KdYdOutbounds = kdYdOutboundMapper.selectRecentUpdated(fiveMinutesAgo);
|
|
|
+ if (KdYdOutbounds.isEmpty()) {
|
|
|
+ log.info("【出库单同步任务】无需要同步的数据,结束");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KdYdOutbound kdYdOutbound : KdYdOutbounds) {
|
|
|
+ try {
|
|
|
+ String djbh = kdYdOutbound.getDjbh();
|
|
|
+// String tjruuid = kdYdOrder.getTjruuid();
|
|
|
+ String formInstId = kdYdOutbound.getForminstid();
|
|
|
+ if (ObjectUtil.hasEmpty(formInstId, djbh)) {
|
|
|
+ log.warn("跳过同步: formInstId 或 khbm 为空, customer={}", kdYdOutbound.getId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ ydClient.operateData(
|
|
|
+ YDParam.builder()
|
|
|
+ .formInstanceId(formInstId)
|
|
|
+ .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("textField_mg34txgm", djbh)))
|
|
|
+ .useLatestVersion(true).build(), YDConf.FORM_OPERATION.update);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步单条出库单数据异常: formInstId={}", kdYdOutbound.getForminstid(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("【出库单同步任务】执行完成,共处理 {} 条记录", KdYdOutbounds.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("【出库单同步任务】执行过程中发生严重错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncKdYdReceivable() {
|
|
|
+ log.info("定时同步-应收单");
|
|
|
+ try {
|
|
|
+
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime fiveMinutesAgo = now.minusMinutes(5);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<KdYdReceivable> KdYdReceivables = kdYdReceivableMapper.selectRecentUpdated(fiveMinutesAgo);
|
|
|
+ if (KdYdReceivables.isEmpty()) {
|
|
|
+ log.info("【应收单同步任务】无需要同步的数据,结束");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KdYdReceivable kdYdReceivable : KdYdReceivables) {
|
|
|
+ try {
|
|
|
+ String djbh = kdYdReceivable.getDjbh();
|
|
|
+// String tjruuid = kdYdOrder.getTjruuid();
|
|
|
+ String formInstId = kdYdReceivable.getForminstid();
|
|
|
+ if (ObjectUtil.hasEmpty(formInstId, djbh)) {
|
|
|
+ log.warn("跳过同步: formInstId 或 khbm 为空, customer={}", kdYdReceivable.getId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ ydClient.operateData(
|
|
|
+ YDParam.builder()
|
|
|
+ .formInstanceId(formInstId)
|
|
|
+ .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("textField_mg34txgm", djbh)))
|
|
|
+ .useLatestVersion(true).build(), YDConf.FORM_OPERATION.update);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步单条应收单数据异常: formInstId={}", kdYdReceivable.getForminstid(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("【应收单同步任务】执行完成,共处理 {} 条记录", KdYdReceivables.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("【应收单同步任务】执行过程中发生严重错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void synckdYdZp() {
|
|
|
+ log.info("定时同步-发票单");
|
|
|
+ try {
|
|
|
+
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime fiveMinutesAgo = now.minusMinutes(5);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<KdYdZp> kdYdZps = kdYdZpMapper.selectRecentUpdated(fiveMinutesAgo);
|
|
|
+ if (kdYdZps.isEmpty()) {
|
|
|
+ log.info("【发票单同步任务】无需要同步的数据,结束");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KdYdZp kdYdZp : kdYdZps) {
|
|
|
+ try {
|
|
|
+ String djbh = kdYdZp.getDjbh();
|
|
|
+ String fph = kdYdZp.getFph();
|
|
|
+ String formInstId = kdYdZp.getForminstid();
|
|
|
+ if (ObjectUtil.hasEmpty(formInstId, djbh,fph)) {
|
|
|
+ log.warn("跳过同步: formInstId 或 khbm 为空, customer={}", kdYdZp.getId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ ydClient.operateData(
|
|
|
+ YDParam.builder()
|
|
|
+ .formInstanceId(formInstId)
|
|
|
+ .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("textField_mgt6lcqq, textField_mejmml3a", djbh, fph)))
|
|
|
+ .useLatestVersion(true).build(), YDConf.FORM_OPERATION.update);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步单条发票单数据异常: formInstId={}", kdYdZp.getForminstid(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("【发票单同步任务】执行完成,共处理 {} 条记录", kdYdZps.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("【发票单同步任务】执行过程中发生严重错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void synckdYdMaterial() {
|
|
|
+ log.info("定时同步-物料单");
|
|
|
+ try {
|
|
|
+
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime fiveMinutesAgo = now.minusMinutes(5);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ List<KdYdMaterial> kdYdMaterials = kdYdMaterialMapper.selectRecentUpdated(fiveMinutesAgo);
|
|
|
+ if (kdYdMaterials.isEmpty()) {
|
|
|
+ log.info("【物料单同步任务】无需要同步的数据,结束");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (KdYdMaterial kdYdMaterial : kdYdMaterials) {
|
|
|
+ try {
|
|
|
+ String wlbm = kdYdMaterial.getWlbm();
|
|
|
+ String wlmc = kdYdMaterial.getWlmc();
|
|
|
+ String wlbt = wlmc + wlbm ;
|
|
|
+ String formInstId = kdYdMaterial.getForminstid();
|
|
|
+
|
|
|
+ if (ObjectUtil.hasEmpty(wlbm, wlmc)) {
|
|
|
+ log.warn("跳过同步: formInstId 或 khbm 为空, customer={}", kdYdMaterial.getId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ ydClient.operateData(
|
|
|
+ YDParam.builder()
|
|
|
+ .formInstanceId(formInstId)
|
|
|
+ .updateFormDataJson(JSONObject.toJSONString(UtilMap.map("textField_mfxbtcdh, textField_mg4h6mz5", wlbm, wlbt)))
|
|
|
+ .useLatestVersion(true).build(), YDConf.FORM_OPERATION.update);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("同步单条物料单数据异常: formInstId={}", kdYdMaterial.getForminstid(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("【物料单同步任务】执行完成,共处理 {} 条记录", kdYdMaterials.size());
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("【物料单同步任务】执行过程中发生严重错误", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|