|
@@ -4,7 +4,6 @@ import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
-import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.fjhx.tenant.entity.dict.po.DictCommonData;
|
|
import com.fjhx.tenant.entity.dict.po.DictCommonData;
|
|
import com.fjhx.tenant.service.dict.DictCommonDataService;
|
|
import com.fjhx.tenant.service.dict.DictCommonDataService;
|
|
@@ -22,6 +21,9 @@ import com.sd.wln.util.WlnUtil;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.PlatformTransactionManager;
|
|
|
|
+import org.springframework.transaction.TransactionDefinition;
|
|
|
|
+import org.springframework.transaction.TransactionStatus;
|
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -31,6 +33,12 @@ import java.util.stream.Collectors;
|
|
public class WlnOrderServiceImpl implements WlnOrderService {
|
|
public class WlnOrderServiceImpl implements WlnOrderService {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
|
+ private PlatformTransactionManager platformTransactionManager;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private TransactionDefinition transactionDefinition;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
private DictCommonDataService dictCommonDataService;
|
|
private DictCommonDataService dictCommonDataService;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
@@ -45,7 +53,6 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
@Autowired
|
|
@Autowired
|
|
private SkuSpecService skuSpecService;
|
|
private SkuSpecService skuSpecService;
|
|
|
|
|
|
- @DSTransactional
|
|
|
|
@Override
|
|
@Override
|
|
public boolean syncOrder() {
|
|
public boolean syncOrder() {
|
|
Date endDate = new Date();
|
|
Date endDate = new Date();
|
|
@@ -65,11 +72,12 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
Map<String, OrderInfo> orderMap = orderService.mapKEntity(OrderInfo::getWlnUid,
|
|
Map<String, OrderInfo> orderMap = orderService.mapKEntity(OrderInfo::getWlnUid,
|
|
q -> q.between(OrderInfo::getWlnApproveTime, DateUtil.offsetDay(endDate, -3), endDate));
|
|
q -> q.between(OrderInfo::getWlnApproveTime, DateUtil.offsetDay(endDate, -3), endDate));
|
|
|
|
|
|
|
|
+ Map<String, SkuSpec> skuSpecMap = getSkuSpecMap(wlnOrderList);
|
|
|
|
+
|
|
for (JSONObject wlnOrder : wlnOrderList) {
|
|
for (JSONObject wlnOrder : wlnOrderList) {
|
|
|
|
|
|
// 如果订单存在,修改订单状态
|
|
// 如果订单存在,修改订单状态
|
|
- String uid = wlnOrder.getString("uid");
|
|
|
|
- OrderInfo orderInfo = orderMap.get(uid);
|
|
|
|
|
|
+ OrderInfo orderInfo = orderMap.get(wlnOrder.getString("uid"));
|
|
if (orderInfo != null) {
|
|
if (orderInfo != null) {
|
|
Integer processStatus = wlnOrder.getInteger("process_status");
|
|
Integer processStatus = wlnOrder.getInteger("process_status");
|
|
if (ObjectUtil.notEqual(orderInfo.getWlnStatus(), processStatus)) {
|
|
if (ObjectUtil.notEqual(orderInfo.getWlnStatus(), processStatus)) {
|
|
@@ -80,37 +88,35 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
}
|
|
}
|
|
|
|
|
|
orderInfo = createOrder(wlnOrder, departmentMap);
|
|
orderInfo = createOrder(wlnOrder, departmentMap);
|
|
- List<JSONObject> wlnOrderSkuList = wlnOrder.getJSONArray("orders").toJavaList(JSONObject.class);
|
|
|
|
-
|
|
|
|
- if (ObjectUtil.isNotEmpty(wlnOrderSkuList)) {
|
|
|
|
- Map<String, SkuSpec> skuSpecMap = new HashMap<>();
|
|
|
|
-
|
|
|
|
- List<String> skuCodeList = wlnOrderSkuList.stream().map(item -> item.getString("sys_spec_uid"))
|
|
|
|
- .filter(ObjectUtil::isNotNull).distinct().collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- if (skuCodeList.size() > 0) {
|
|
|
|
- skuSpecMap = skuSpecService.mapKEntity(SkuSpec::getWlnUid, q -> q.in(SkuSpec::getWlnUid, skuCodeList));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (JSONObject wlnOrderSku : wlnOrderSkuList) {
|
|
|
|
- SkuSpec skuSpec = skuSpecMap.get(wlnOrderSku.getString("sys_spec_uid"));
|
|
|
|
- OrderSku orderSku = createOrderSku(wlnOrderSku, orderInfo, skuSpec);
|
|
|
|
- saveOrderSkuList.add(orderSku);
|
|
|
|
- }
|
|
|
|
|
|
+ for (JSONObject wlnOrderSku : wlnOrder.getJSONArray("orders").toJavaList(JSONObject.class)) {
|
|
|
|
+ SkuSpec skuSpec = skuSpecMap.get(wlnOrderSku.getString("sys_spec_uid"));
|
|
|
|
+ OrderSku orderSku = createOrderSku(wlnOrderSku, orderInfo, skuSpec);
|
|
|
|
+ saveOrderSkuList.add(orderSku);
|
|
}
|
|
}
|
|
saveOrderListInfo.add(orderInfo);
|
|
saveOrderListInfo.add(orderInfo);
|
|
}
|
|
}
|
|
|
|
|
|
- if (saveOrderListInfo.size() > 0) {
|
|
|
|
- orderService.saveBatch(saveOrderListInfo);
|
|
|
|
- }
|
|
|
|
- if (updateOrderListInfo.size() > 0) {
|
|
|
|
- orderService.updateBatchById(updateOrderListInfo);
|
|
|
|
- }
|
|
|
|
- if (saveOrderSkuList.size() > 0) {
|
|
|
|
- orderSkuService.saveBatch(saveOrderSkuList);
|
|
|
|
|
|
+ // 开启事务
|
|
|
|
+ TransactionStatus transactionStatus = platformTransactionManager.getTransaction(transactionDefinition);
|
|
|
|
+ try {
|
|
|
|
+ if (saveOrderListInfo.size() > 0) {
|
|
|
|
+ orderService.saveBatch(saveOrderListInfo);
|
|
|
|
+ }
|
|
|
|
+ if (updateOrderListInfo.size() > 0) {
|
|
|
|
+ orderService.updateBatchById(updateOrderListInfo);
|
|
|
|
+ }
|
|
|
|
+ if (saveOrderSkuList.size() > 0) {
|
|
|
|
+ orderSkuService.saveBatch(saveOrderSkuList);
|
|
|
|
+ }
|
|
|
|
+ // 提交事务
|
|
|
|
+ platformTransactionManager.commit(transactionStatus);
|
|
|
|
+ return true;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ // 回滚事务
|
|
|
|
+ platformTransactionManager.rollback(transactionStatus);
|
|
|
|
+ log.error("同步订单失败", e);
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
- return true;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -152,6 +158,9 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
return list;
|
|
return list;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 事业部id Map
|
|
|
|
+ */
|
|
private Map<String, Department> getDepartmentMap() {
|
|
private Map<String, Department> getDepartmentMap() {
|
|
Map<String, Department> departmentMap = new HashMap<>();
|
|
Map<String, Department> departmentMap = new HashMap<>();
|
|
for (Department department : departmentService.list()) {
|
|
for (Department department : departmentService.list()) {
|
|
@@ -166,6 +175,20 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
return departmentMap;
|
|
return departmentMap;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取sku规格
|
|
|
|
+ */
|
|
|
|
+ private Map<String, SkuSpec> getSkuSpecMap(List<JSONObject> wlnOrderList) {
|
|
|
|
+ List<String> wlnUidList = wlnOrderList.stream()
|
|
|
|
+ .flatMap(item -> item.getJSONArray("orders").toJavaList(JSONObject.class).stream())
|
|
|
|
+ .map(item -> item.getString("sys_spec_uid"))
|
|
|
|
+ .filter(ObjectUtil::isNotNull).distinct().collect(Collectors.toList());
|
|
|
|
+ return skuSpecService.mapKEntity(SkuSpec::getWlnUid, q -> q.in(SkuSpec::getWlnUid, wlnUidList));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建订单
|
|
|
|
+ */
|
|
private OrderInfo createOrder(JSONObject wlnOrder, Map<String, Department> departmentMap) {
|
|
private OrderInfo createOrder(JSONObject wlnOrder, Map<String, Department> departmentMap) {
|
|
Department department = departmentMap.get(wlnOrder.getString("storage_code"));
|
|
Department department = departmentMap.get(wlnOrder.getString("storage_code"));
|
|
|
|
|
|
@@ -216,6 +239,9 @@ public class WlnOrderServiceImpl implements WlnOrderService {
|
|
return orderInfo;
|
|
return orderInfo;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 创建订单sku
|
|
|
|
+ */
|
|
private OrderSku createOrderSku(JSONObject wlnOrderSku, OrderInfo orderInfo, SkuSpec skuSpec) {
|
|
private OrderSku createOrderSku(JSONObject wlnOrderSku, OrderInfo orderInfo, SkuSpec skuSpec) {
|
|
OrderSku orderSku = new OrderSku();
|
|
OrderSku orderSku = new OrderSku();
|
|
orderSku.setId(IdWorker.getId());
|
|
orderSku.setId(IdWorker.getId());
|