采购单同步

20230922-ljl-fixBug
wangchaoxu 1 year ago
parent aba85eaf7f
commit 4041d27f31

@ -0,0 +1,9 @@
package com.ms.api.dto.order;
import lombok.Data;
@Data
public class RsyncDdOrdersAndPurchaseOrdersRequestDTO {
private String orderIds;
private String sourceOrderIds;
}

@ -7,10 +7,7 @@ import com.ms.api.dto.order.OriginalAndCustomConsigneeInfoRequestDTO;
import com.ms.api.dto.order.OriginalAndCustomConsigneeInfoResponseDTO;
import com.ms.dal.entity.OpOrder;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
*
@ -83,4 +80,19 @@ public interface OpOrderService {
Long tryRsyncOpOrder(Long shopid, String app, Integer priority, Date forceStart);
Map<String, Object> checkRsyncDataFinished(List<String> shopIds);
/**
* ID"订单ID"-"订单对象"Map
* @param orderIds
* @return
*/
Map<String, OpOrder> getOpOrdersByOrderIds(List<String> orderIds);
/**
*
* @param shopId
* @param orders
* @return
*/
boolean checkOrdersBelongShop(Long shopId, Collection<OpOrder> orders);
}

@ -1,14 +1,6 @@
package com.ms.api.service.impl;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -1739,6 +1731,26 @@ public class OpOrderServiceImpl implements OpOrderService {
result.put("synchronizingUserIds", opOrderRsyncQueueList.stream().map(OpOrderRsyncQueue::getShopId).collect(Collectors.toList()));
return result;
}
@Override
public Map<String, OpOrder> getOpOrdersByOrderIds(List<String> orderIds) {
List<OpOrder> opOrderList = opOrderMapper.getListByOrderIds(orderIds);
Map<String, OpOrder> map = new HashMap<>();
for (OpOrder opOrder : opOrderList) {
map.put(opOrder.getOrderId(), opOrder);
}
return map;
}
@Override
public boolean checkOrdersBelongShop(Long shopId, Collection<OpOrder> orders) {
for (OpOrder opOrder : orders) {
if (opOrder.getShopId() != shopId) {
return false;
}
}
return true;
}
}

@ -0,0 +1,73 @@
package com.ms.api.spi.order;
import com.alibaba.fastjson.JSON;
import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.api.common.R;
import com.ms.api.common.Ret;
import com.ms.api.common.SPIBaseService;
import com.ms.api.dto.order.RsyncDdOrdersAndPurchaseOrdersRequestDTO;
import com.ms.api.service.OpOrderService;
import com.ms.api.tool.CommonTool;
import com.ms.api.tool.DsJsonRequestTemplate;
import com.ms.api.tool.SecurityTool;
import com.ms.dal.entity.OpOrder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ExtensionService("rsyncDdOrdersAndPurchaseOrders")
@Slf4j
public class RsyncDdOrdersAndPurchaseOrdersService extends SPIBaseService implements ExtensionServiceHandler<RsyncDdOrdersAndPurchaseOrdersRequestDTO, Ret> {
@Autowired
private DsJsonRequestTemplate dsJsonRequestTemplate;
@Autowired
private OpOrderService opOrderService;
@Override
public BaseResponse<Ret> handle(BaseRequest<RsyncDdOrdersAndPurchaseOrdersRequestDTO> req) {
initHandle(req);
String orderIdsStr = req.getData().getOrderIds();
String sourceOrderIdsStr = req.getData().getSourceOrderIds();
if (!StringUtils.isEmpty(orderIdsStr)) {
List<String> orderIds = CommonTool.splitWithComma(orderIdsStr);
Map<String, OpOrder> orderIdAndOrderMap = opOrderService.getOpOrdersByOrderIds(orderIds);
if (!opOrderService.checkOrdersBelongShop(shopId, orderIdAndOrderMap.values())) {
return R.ok(Ret.fail("无法操作不属于本店铺的订单"));
}
}
// 请求DS,同步1688订单
if (!StringUtils.isEmpty(sourceOrderIdsStr)) {
List<String> sourceOrderIds = CommonTool.splitWithComma(sourceOrderIdsStr);
try {
Map<String, Object> params = new HashMap<>();
params.put("platform", "ddMicroApp");
params.put("sourceOrderIds", sourceOrderIds);
String res = dsJsonRequestTemplate.execute("/order/rsyncPurchaseOrderBySourceOrderIds", params);
log.info(res);
Map retMap = JSON.parseObject(res, Map.class);
if (retMap.get("result").equals("fail")) {
log.error("同步1688订单失败");
};
} catch (Exception e) {
log.error("同步1688订单失败原因" + e.getMessage());
}
}
// todo:
return R.ok(Ret.success());
}
}
Loading…
Cancel
Save