采购相关接口

20230922-ljl-fixBug
elf 1 year ago
parent a60c306710
commit 5c29887500

@ -0,0 +1,37 @@
package com.ms.api.dto.dsapi.request;
import com.ms.api.dto.dsapi.response.GetPurchaseOrderItemsAndSourceItemsResponseDTO;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
@Data
public class BatchAddPurchaseConfirmLogRequestDTO {
private String purchaseSource;
private String purchasePlatform;
@Data
public static class PlatformOrder implements Serializable {
private String platformOrderId;
private String userId;
private List<PlatformOrderItem> items;
}
@Data
public static class PlatformOrderItem implements Serializable {
private String platformOrderId;
private String platformItemId;
private String platformSkuId;
private Integer itemTotal;
private String platformSkuSubName;
private String sourceItemId;
private String sourceSkuId;
private Integer sourceNum;
private String sourceSkuPurchaseQuantity;
private String sourceSkuSubName;
private Integer isSkuSubNameEqual;
private Integer isItemTotalEqual;
private String dsRefundStatus;
}
}

@ -0,0 +1,13 @@
package com.ms.api.dto.dsapi.request;
import lombok.Data;
import java.util.List;
@Data
public class GetPurchaseOrderItemsAndSourceItemsRequestDTO {
private List<Long> shopIds;
private String platform;
private List<String> platformItemIds;
private List<String> platformOrderIds;
}

@ -0,0 +1,167 @@
package com.ms.api.dto.dsapi.response;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
@Data
public class GetPurchaseOrderItemsAndSourceItemsResponseDTO extends CommonResponseDTO {
private Map<String, ProductInfo> sourceItemIdAndProductInfoMap;
private Map<String, CommonResponseDTO> sourceItemIdAndProductApiRetMap;
private Map<String, SourceItemSkuRelation> platformItemIdAndSourceItemSkuRelationMap;
private Map<String, List<PurchaseOrderItem>> platformOrderIdAndPurchaseOrderItemsMap;
private Map<String, List<PurchaseOrder>> platformOrderIdAndPurchaseOrdersMap;
private Map<String, SourceItemInfo> platformItemIdAndSourceItemInfoMap;
@Data
public static class ProductInfo implements Serializable {
private Long sourceItemId;
private String productType;
private String categoryName;
private String status;
private String title;
private String productUrl;
private List<String> images;
private String instanceCode;
private Integer isJxhyOffer;
private String sellerLoginId;
private Long sellerId;
private String resourceOwner;
private List<Sku> skus;
}
@Data
public static class Sku implements Serializable {
private Long sourceSkuId;
private String specId;
private Double retailPrice;
private Double price;
private Double consignPrice;
private String img;
private String skuSubName;
private Long sourceItemId;
private Integer stock;
private String instanceCode;
private Integer isJxhyOffer;
private Double jxhyPrice;
}
@Data
public static class SourceItemSkuRelation implements Serializable {
private Integer moveProductManualSourceSkuRelationId;
private Integer moveProductManualSourceId;
private Long platformSkuId;
private Long sourceSkuId;
private Integer sourceNum;
private String confirmNumRatio;
private String gmtCreate;
private String gmtModified;
private Long platformItemId;
}
@Data
public static class PurchaseOrderItem implements Serializable {
private Long purchaseOrderItemId;
private Long purchaseOrderId;
private Long sourceOrderId;
private Long productId;
private Long skuId;
private String memberId;
private String productImgUrl;
private String statusStr;
private String refundStatus;
private String productSnapshotUrl;
private Double itemAmount;
private Double price;
private Long subItemId;
private String specId;
private String weight;
private String quantity;
private String subItemIdString;
private String unit;
private Integer quantityFactor;
private String name;
private Integer logisticsStatus;
private Double refund;
private String status;
private String weightUnit;
private String skuSubName;
private String gmtCreate;
private String gmtModified;
private String platformOrderId;
private Long platformItemId;
private Long platformSkuId;
private String flow;
private String refundStatusText;
private String statusText;
}
@Data
public static class PurchaseOrder implements Serializable {
private Long purchaseOrderId;
private String sourceOrderId;
private String memberId;
private String payTime;
private Double discount;
private String buyerLevel;
private Double sumProductPayment;
private String buyerFeedback;
private Integer sellerOrder;
private String buyerLoginId;
private String modifyTime;
private String subBuyerLoginId;
private String completeTime;
private String sellerLoginId;
private String buyerId;
private String closeOperateType;
private Double totalAmount;
private Double shippingFee;
private String sellerId;
private String buyerUserId;
private Double refund;
private String status;
private Double refundPayment;
private Double couponFee;
private String refundStatus;
private String remark;
private String confirmedTime;
private String tradeType;
private String receivingTime;
private String idOfStr;
private String refundStatusForAs;
private String sellerUserId;
private String createTime;
private String refundId;
private String tradeTypeDesc;
private String tradeTypeCode;
private String waybill;
private Integer logisticsId;
private String logisticsName;
private String alibabaLogisticsIds;
private String toFullNameMd5;
private String toMobileMd5;
private String toFullNameS;
private String toMobileS;
private String filterIsTown;
private String filterItemCount;
private String filterItemTotal;
private String sellerNote;
private String platformPushStatus;
private String purchaseSource;
private String exceptionType;
private String oldExceptionType;
private String gmtCreate;
private String gmtModified;
private String duplicateSmd5;
}
@Data
public static class SourceItemInfo implements Serializable {
private ProductInfo productInfo;
private Long sourceItemId;
private CommonResponseDTO productApiRet;
}
}

@ -0,0 +1,11 @@
package com.ms.api.dto.dsorder;
import lombok.Data;
@Data
public class OrderItemDTO {
private String orderId;
private String wareId;
private String skuId;
private String isPurchase;
}

@ -1,13 +1,22 @@
package com.ms.api.service;
import com.ms.api.dto.dsapi.request.BatchAddPurchaseConfirmLogRequestDTO;
import com.ms.api.dto.dsapi.request.BatchCreateDistributionOrdersRequestDTO;
import com.ms.api.dto.dsapi.request.GetPurchaseOrderItemsAndSourceItemsRequestDTO;
import com.ms.api.dto.dsapi.request.SavePlatformManualSelectedSkuRequestDTO;
import com.ms.api.dto.dsapi.response.BatchCreateDistributionOrdersResponseDTO;
import com.ms.api.dto.dsapi.response.CommonResponseDTO;
import com.ms.api.dto.dsapi.response.GetPlatformShopPurchaseSettingResponseDTO;
import com.ms.api.dto.dsapi.response.GetPurchaseOrderItemsAndSourceItemsResponseDTO;
import java.util.List;
public interface DsApiService {
GetPlatformShopPurchaseSettingResponseDTO getPlatformShopPurchaseSetting(String userId, String platform);
BatchCreateDistributionOrdersResponseDTO batchCreateDistributionOrders(BatchCreateDistributionOrdersRequestDTO request);
CommonResponseDTO saveDsManualSelectedSku(SavePlatformManualSelectedSkuRequestDTO request);
GetPurchaseOrderItemsAndSourceItemsResponseDTO getPurchaseOrderItemsAndSourceItems(GetPurchaseOrderItemsAndSourceItemsRequestDTO request);
CommonResponseDTO batchAddPurchaseConfirmLog(BatchAddPurchaseConfirmLogRequestDTO request);
CommonResponseDTO cancelPurchaseOrderRelate(String platform, Long shopId, String orderId, List<Long> skuIds);
CommonResponseDTO cancelPurchaseOrder(String platform, Long shopId, String orderId, String purchaseOrderSn);
}

@ -30,4 +30,6 @@ public interface PurchaseOrderItemService {
List<PurchaseOrderItem> getListByOrderId(Long shopId, String orderId);
int updateStatusByIds(String status, List<Long> ids);
List<PurchaseOrderItem> getRelatePurchaseOrderItemsByPurchaseOrderId(Long purchaseOrderId);
}

@ -1,6 +1,7 @@
package com.ms.api.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.ms.api.common.R;
import com.ms.api.consts.*;
import com.ms.api.dto.dsapi.request.*;
import com.ms.api.dto.dsapi.response.*;
@ -1239,4 +1240,90 @@ public class DistributionOrderServiceImpl implements DistributionOrderService {
}
return isReapt;
}
public void get1688DsSourceSkuInfos(Long shopId, List<OrderItemDTO> orderItems) {
Stream<String> orderIdsStream = orderItems.stream().map(OrderItemDTO::getOrderId);
List<String> orderIdList = orderIdsStream.collect(Collectors.toList());
List<OpOrder> orders = opOrderService.getListByOrderIds(orderIdList);
Map<String, OpOrder> orderIdAndOpOrderMap = orders.stream().collect(Collectors.toMap(OpOrder::getOrderId, x->x));
Stream<Long> shopIdsStream = orders.stream().map(OpOrder::getShopId);
Set<Long> shopIdSet = shopIdsStream.collect(Collectors.toSet());
if (shopIdSet.size() != 1 || shopIdSet.contains(shopId)) {
throw new RuntimeException("订单归属异常");
}
List<String> platformOrderIds = new ArrayList<>();
List<String> platformItemIds = new ArrayList<>();
for (OrderItemDTO orderItem : orderItems) {
if (!orderIdAndOpOrderMap.containsKey(orderItem.getOrderId())) {
continue;
}
if (orderItem.getIsPurchase().equals("1")) {
platformOrderIds.add(orderItem.getOrderId());
continue;
}
platformItemIds.add(orderItem.getWareId());
}
GetPurchaseOrderItemsAndSourceItemsRequestDTO request = new GetPurchaseOrderItemsAndSourceItemsRequestDTO();
List<Long> shopIds = new ArrayList<>();
shopIds.add(shopId);
request.setPlatform("dd");
request.setShopIds(shopIds);
request.setPlatformItemIds(platformItemIds);
request.setPlatformOrderIds(platformOrderIds);
dsApiService.getPurchaseOrderItemsAndSourceItems(request);
}
public CommonResponseDTO batchAddDsPurchaseConfirmLog(BatchAddPurchaseConfirmLogRequestDTO request) {
return dsApiService.batchAddPurchaseConfirmLog(request);
}
public CommonResponseDTO cancelPurchaseOrder(Long shopId, String orderId, List<Long> skuIds, String source, boolean isForce) {
OpOrder opOrder = opOrderService.selectByOrderId(orderId);
if (opOrder == null || !Objects.equals(opOrder.getShopId(), shopId)) {
throw new RuntimeException("店铺不存在");
}
CommonResponseDTO response = dsApiService.cancelPurchaseOrderRelate("dd", shopId, orderId, skuIds);
if (!response.isSuccess()) {
throw new RuntimeException(response.getMessage());
}
if (!skuIds.isEmpty()) {
} else {
}
buildAndUpdateNewPurchaseOrderRemark(opOrder);
return response;
}
public CommonResponseDTO closeSourceOrderAndCancelRelatePurchaseOrder(Long shopId, String orderId, String purchaseOrderSn) {
OpOrder opOrder = opOrderService.selectByOrderId(orderId);
if (opOrder == null || !Objects.equals(opOrder.getShopId(), shopId)) {
throw new RuntimeException("订单不存在");
}
PurchaseOrder purchaseOrder = purchaseOrderService.getByPlatformAndPurchaseOrderSn("1688DS", purchaseOrderSn);
if (purchaseOrder == null) {
throw new RuntimeException("1688采购单不存在");
}
if (!Objects.equals(purchaseOrder.getOrderId(), orderId)) {
throw new RuntimeException("采购单异常");
}
if (purchaseOrder.getStatus().equals(StatusConst.normal)) {
throw new RuntimeException("采购单已取消关联");
}
List<PurchaseOrderItem> items = purchaseOrderItemService.getRelatePurchaseOrderItemsByPurchaseOrderId(purchaseOrder.getPurchaseOrderId());
if (items.isEmpty()) {
throw new RuntimeException("采购单" + purchaseOrderSn + "不存在关联中的商品");
}
CommonResponseDTO response = dsApiService.cancelPurchaseOrder("dd", shopId, orderId, purchaseOrderSn);
if (!response.isSuccess()) {
throw new RuntimeException(response.getMessage());
}
String cancelSource = PurchaseOrderConst.PURCHASE_ORDER_CANCEL_SOURCE_DS_CLOSE_CANCEL;
List<Long> skuIds = items.stream().map(PurchaseOrderItem::getSkuId).collect(Collectors.toList());
return cancelPurchaseOrder(shopId, orderId, skuIds, cancelSource, false);
}
}

@ -1,11 +1,11 @@
package com.ms.api.service.impl;
import com.alibaba.fastjson.JSON;
import com.ms.api.dto.dsapi.request.BatchCreateDistributionOrdersRequestDTO;
import com.ms.api.dto.dsapi.request.SavePlatformManualSelectedSkuRequestDTO;
import com.ms.api.dto.dsapi.request.*;
import com.ms.api.dto.dsapi.response.BatchCreateDistributionOrdersResponseDTO;
import com.ms.api.dto.dsapi.response.CommonResponseDTO;
import com.ms.api.dto.dsapi.response.GetPlatformShopPurchaseSettingResponseDTO;
import com.ms.api.dto.dsapi.response.GetPurchaseOrderItemsAndSourceItemsResponseDTO;
import com.ms.api.service.DsApiService;
import com.ms.api.tool.DsJsonRequestTemplate;
import com.ms.api.tool.SecurityTool;
@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@ -42,6 +43,44 @@ public class DsApiServiceImpl implements DsApiService {
return JSON.parseObject(resp, CommonResponseDTO.class);
}
@Override
public GetPurchaseOrderItemsAndSourceItemsResponseDTO getPurchaseOrderItemsAndSourceItems(GetPurchaseOrderItemsAndSourceItemsRequestDTO request) {
String resp = execute("/order/getPurchaseOrderItemsAndSourceItems", objectToMap(request));
return JSON.parseObject(resp, GetPurchaseOrderItemsAndSourceItemsResponseDTO.class);
}
@Override
public CommonResponseDTO batchAddPurchaseConfirmLog(BatchAddPurchaseConfirmLogRequestDTO request) {
String resp = execute("/order/batchAddPurchaseConfirmLog", objectToMap(request));
return JSON.parseObject(resp, CommonResponseDTO.class);
}
@Override
public CommonResponseDTO cancelPurchaseOrderRelate(String platform, Long shopId, String orderId, List<Long> skuIds) {
OperateInfoDTO operateInfo = new OperateInfoDTO(String.valueOf(shopId));
Map<String, Object> params = new HashMap<>();
params.put("platform", platform);
params.put("shopId", shopId);
params.put("platformOrderId", orderId);
params.put("platformSkuId", skuIds);
params.put("operateInfo", operateInfo);
String resp = execute("/order/cancelPurchaseOrderRelate", params);
return JSON.parseObject(resp, CommonResponseDTO.class);
}
@Override
public CommonResponseDTO cancelPurchaseOrder(String platform, Long shopId, String orderId, String purchaseOrderSn) {
OperateInfoDTO operateInfo = new OperateInfoDTO(String.valueOf(shopId));
Map<String, Object> params = new HashMap<>();
params.put("platform", platform);
params.put("userId", shopId);
params.put("platformOrderId", orderId);
params.put("sourceOrderId", purchaseOrderSn);
params.put("operateInfo", operateInfo);
String resp = execute("/order/cancelPurchaseOrder", params);
return JSON.parseObject(resp, CommonResponseDTO.class);
}
private Map<String, Object> objectToMap(Object obj) {
Map<String, Object> map = new HashMap<>();
Class<?> clazz = obj.getClass();

@ -68,6 +68,12 @@ public class PurchaseOrderItemServiceImpl implements PurchaseOrderItemService{
public int updateStatusByIds(String status, List<Long> ids) {
return purchaseOrderItemMapper.updateStatusByIds(status, ids);
}
@Override
public List<PurchaseOrderItem> getRelatePurchaseOrderItemsByPurchaseOrderId(Long purchaseOrderId) {
// TODO
return null;
}
}

Loading…
Cancel
Save