20230922-ljl-fixBug
parent
d87e1af065
commit
00f05d142c
@ -0,0 +1,9 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class AllowDsEncryptOrderSourceSellerDto {
|
||||||
|
private String sellerName;
|
||||||
|
private String sellerIdMd5;
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class BatchCreateDistributionOrdersDto {
|
||||||
|
private List<PlatformOrderDto> platformOrders;
|
||||||
|
private boolean isRepurchase;
|
||||||
|
private String actionSource;
|
||||||
|
private String purchaseSource;
|
||||||
|
private HashMap<String, String> platformOrderIdAndPurchaseConfirmLogIdMap;
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ConsigneeInfoDto {
|
||||||
|
private String fullname;
|
||||||
|
private String telephone;
|
||||||
|
private String mobile;
|
||||||
|
private Integer provinceAreaId;
|
||||||
|
private String province;
|
||||||
|
private Integer cityAreaId;
|
||||||
|
private String city;
|
||||||
|
private Integer countyAreaId;
|
||||||
|
private String county;
|
||||||
|
private Integer townAreaId;
|
||||||
|
private String town;
|
||||||
|
private String address;
|
||||||
|
private String fullAddress;
|
||||||
|
private Boolean hasHide = true;
|
||||||
|
private List<String> hasDecryptFields;
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
public class DsErrorRetDto {
|
||||||
|
private String platformOrderId;
|
||||||
|
|
||||||
|
private String[] platformSkuIds;
|
||||||
|
private String reson;
|
||||||
|
private String code;
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
public class DsPayRetDto {
|
||||||
|
private String result;
|
||||||
|
private String code;
|
||||||
|
private String reason;
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DsPurchaseOrderDto {
|
||||||
|
private String platformOrderId;
|
||||||
|
private String purchasePlatform;
|
||||||
|
private String purchaseOrderSn;
|
||||||
|
private String purchaseOrderBuyer;
|
||||||
|
private String purchaseOrderSeller;
|
||||||
|
private String purchaseOrderPayment;
|
||||||
|
private String purchaseOrderFullname;
|
||||||
|
private String purchaseOrderMobile;
|
||||||
|
private String purchaseOrderFullAddress;
|
||||||
|
private String purchaseOrderStartTime;
|
||||||
|
private String platformPushStatus;
|
||||||
|
private String purchaseOrderLogisticsName;
|
||||||
|
private String purchaseOrderWaybillCode;
|
||||||
|
private String purchaseOrderStatus;
|
||||||
|
private String purchaseOrderFlow;
|
||||||
|
private String alibabaOrderStatus;
|
||||||
|
private Boolean isUseManualConsignee;
|
||||||
|
private List<PurchaseOrderItemDto> items;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
public class DsPurchaseOrderItemDto {
|
||||||
|
private String skuId;
|
||||||
|
private String wareId;
|
||||||
|
private String purchaseNum;
|
||||||
|
private String purchasePrice;
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class DsRetDto {
|
||||||
|
private String result;
|
||||||
|
private String message;
|
||||||
|
private String code;
|
||||||
|
private Integer successCount;
|
||||||
|
private Integer failCount;
|
||||||
|
private List<DsSuccessRetDto> successList;
|
||||||
|
private List<DsErrorRetDto> errorList;
|
||||||
|
|
||||||
|
|
||||||
|
public Boolean isSuccess() {
|
||||||
|
return result.equals("success");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class DsSuccessRetDto {
|
||||||
|
private String platformOrderId;
|
||||||
|
private String result;
|
||||||
|
private String reason;
|
||||||
|
private String code;
|
||||||
|
private Integer createAlibabaOrderLogId;
|
||||||
|
private Integer isEncryptOrder;
|
||||||
|
private Integer isUseManualConsignee;
|
||||||
|
private String flow;
|
||||||
|
private Boolean includeSplitJxhy;
|
||||||
|
private HashMap<String, DsPayRetDto> dsPayRet;
|
||||||
|
private HashMap<String, DsPurchaseOrderDto> relatePurchaseOrderInfos;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class EncryptOutOrderInfoDto {
|
||||||
|
private Boolean encryptOrder;
|
||||||
|
private String outPlatformCode;
|
||||||
|
private String outPlatformOrderNo;
|
||||||
|
private String outPlatformAppkey;
|
||||||
|
private String encryptReceiverName;
|
||||||
|
private String encryptReceiverMobile;
|
||||||
|
private String encryptReceiverAddress;
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ItemDto {
|
||||||
|
private String sourceItemId;
|
||||||
|
private String specId;
|
||||||
|
private Integer sourceSkuId;
|
||||||
|
private String platformItemId;
|
||||||
|
private String platformOrderId;
|
||||||
|
private Integer itemTotal;
|
||||||
|
private Double jxhyPrice;
|
||||||
|
private Boolean isJxhyOffer;
|
||||||
|
private String instanceCode;
|
||||||
|
private String platformSkuSubName;
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
import com.ms.api.dsorder.ConsigneeInfoDto;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PlatformOrderDto {
|
||||||
|
private String platformOrderId;
|
||||||
|
private Integer shopId;
|
||||||
|
private ConsigneeInfoDto consigneeInfo;
|
||||||
|
private String buyerRemark;
|
||||||
|
private EncryptOutOrderInfoDto encryptOutOrderInfo;
|
||||||
|
private List<ItemDto> items;
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
public class PurchaseOrderInfoDto {
|
||||||
|
private String platformOrderId;
|
||||||
|
private String purchasePlatform;
|
||||||
|
private String purchaseOrderSn;
|
||||||
|
private String purchaseOrderBuyer;
|
||||||
|
private String purchaseOrderSeller;
|
||||||
|
private String purchaseOrderPayment;
|
||||||
|
private String purchaseOrderFullname;
|
||||||
|
private String purchaseOrderMobile;
|
||||||
|
private String purchaseOrderFullAddress;
|
||||||
|
private String purchaseOrderStartTime;
|
||||||
|
private String platformPushStatus;
|
||||||
|
private String purchaseOrderLogisticsName;
|
||||||
|
private String purchaseOrderWaybillCode;
|
||||||
|
private String purchaseOrderStatus;
|
||||||
|
private String purchaseOrderFlow;
|
||||||
|
private String alibabaOrderStatus;
|
||||||
|
private Boolean isUseManualConsignee;
|
||||||
|
private PurchaseOrderItemDto items;
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
public class PurchaseOrderItemDto {
|
||||||
|
private Integer skuId;
|
||||||
|
private Integer wareId;
|
||||||
|
private Integer purchaseNum;
|
||||||
|
private Double purchasePrice;
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.ms.api.dsorder;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ShopPurchaseSettingDto {
|
||||||
|
private Integer isEncryptDsOrder;
|
||||||
|
private String encryptDsOrderType;
|
||||||
|
private Integer isEncryptDsOrderIfSellerSupport;
|
||||||
|
private HashMap<String, AllowDsEncryptOrderSourceSellerDto> allowDsEncryptOrderSourceSellers;
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.ms.api;
|
||||||
|
|
||||||
|
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.dsorder.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ExtensionService("batchCreateDistributionOrders")
|
||||||
|
@Slf4j
|
||||||
|
public class BathCreateDistributionOrdersService implements ExtensionServiceHandler<Integer, ItemDTO> {
|
||||||
|
@Override
|
||||||
|
public BaseResponse<ItemDTO> handle(BaseRequest<Integer> req) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(3000);//让线程暂停1秒
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemDTO itemDTO = new ItemDTO();
|
||||||
|
itemDTO.setPrice(11);
|
||||||
|
itemDTO.setTitle("測試");
|
||||||
|
return BaseResponse.<ItemDTO>builder().success(true).code("1000").message("成功").data(itemDTO).build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package com.ms.api.service;
|
||||||
|
|
||||||
|
public interface DistributionOrderService {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,150 @@
|
|||||||
|
package com.ms.api.service.impl;
|
||||||
|
|
||||||
|
import com.ms.api.dsorder.*;
|
||||||
|
import com.ms.api.service.DistributionOrderService;
|
||||||
|
import com.ms.api.service.OpOrderChildService;
|
||||||
|
import com.ms.api.service.OpOrderEncryptService;
|
||||||
|
import com.ms.api.service.OpOrderService;
|
||||||
|
import com.ms.dal.entity.OpOrder;
|
||||||
|
import com.ms.dal.entity.OpOrderEncrypt;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class DistributionOrderServiceImpl implements DistributionOrderService {
|
||||||
|
@Autowired
|
||||||
|
private OpOrderChildService opOrderChildService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OpOrderService opOrderService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OpOrderEncryptService opOrderEncryptService;
|
||||||
|
|
||||||
|
private DsRetDto batchCreateDistributionOrders(Integer shopId, BatchCreateDistributionOrdersDto batchCreateDistributionOrdersDto) {
|
||||||
|
checkPurchaseOrders(batchCreateDistributionOrdersDto.getPlatformOrders());
|
||||||
|
|
||||||
|
List<String> orderIdList = new ArrayList<>();
|
||||||
|
for (PlatformOrderDto platformOrder: batchCreateDistributionOrdersDto.getPlatformOrders()) {
|
||||||
|
orderIdList.add(platformOrder.getPlatformOrderId());
|
||||||
|
}
|
||||||
|
|
||||||
|
List<OpOrder> orders = opOrderService.getListByOrderIds(orderIdList);
|
||||||
|
if (orders.isEmpty()) {
|
||||||
|
throw new RuntimeException("订单不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
Stream<Long> shopIdsStream = orders.stream().map(OpOrder::getShopId);
|
||||||
|
List<Long> shopIds = shopIdsStream.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<OpOrderEncrypt> orderEncrypts = opOrderEncryptService.getListByOrderIds(orderIdList);
|
||||||
|
Map<String, OpOrderEncrypt> orderIdAndOpOrderEncryptMap = new HashMap<>();
|
||||||
|
for (OpOrderEncrypt opOrderEncrypt: orderEncrypts) {
|
||||||
|
orderIdAndOpOrderEncryptMap.put(opOrderEncrypt.getOrderId(), opOrderEncrypt);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PlatformOrderDto platformOrderDto: batchCreateDistributionOrdersDto.getPlatformOrders()) {
|
||||||
|
OpOrderEncrypt opOrderEncrypt = orderIdAndOpOrderEncryptMap.get(platformOrderDto.getPlatformOrderId());
|
||||||
|
EncryptOutOrderInfoDto encryptOutOrderInfoDto = new EncryptOutOrderInfoDto();
|
||||||
|
encryptOutOrderInfoDto.setEncryptOrder(true);
|
||||||
|
encryptOutOrderInfoDto.setOutPlatformCode("douyin");
|
||||||
|
encryptOutOrderInfoDto.setOutPlatformOrderNo(opOrderEncrypt.getEncryptPostReceiver());
|
||||||
|
encryptOutOrderInfoDto.setEncryptReceiverMobile(opOrderEncrypt.getEncryptPostTel());
|
||||||
|
encryptOutOrderInfoDto.setEncryptReceiverAddress(opOrderEncrypt.getEncryptDetail());
|
||||||
|
encryptOutOrderInfoDto.setOutPlatformAppkey("");
|
||||||
|
platformOrderDto.setEncryptOutOrderInfo(encryptOutOrderInfoDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DsRetDto();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkNeedDecryptConsigneeInfo(PlatformOrderDto platformOrder, ShopPurchaseSettingDto shopPurchaseSetting, String sourceSellerId) {
|
||||||
|
boolean isSettingEncryptDsOrder = false;
|
||||||
|
if (shopPurchaseSetting.getIsEncryptDsOrderIfSellerSupport() == 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (shopPurchaseSetting.getIsEncryptDsOrder() == 1) {
|
||||||
|
if (shopPurchaseSetting.getEncryptDsOrderType().equals("allSeller")) {
|
||||||
|
isSettingEncryptDsOrder = true;
|
||||||
|
}
|
||||||
|
Stream<String> sellerIdMd5sStream = shopPurchaseSetting.getAllowDsEncryptOrderSourceSellers().values().stream().map(AllowDsEncryptOrderSourceSellerDto::getSellerIdMd5);
|
||||||
|
List<String> sellerIdMd5sList = sellerIdMd5sStream.collect(Collectors.toList());
|
||||||
|
if (sellerIdMd5sList.contains(sourceSellerId)) {
|
||||||
|
isSettingEncryptDsOrder = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isSettingEncryptDsOrder && platformOrder.getEncryptOutOrderInfo().getEncryptOrder()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return platformOrder.getConsigneeInfo().getHasDecryptFields().size() != 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkPurchaseOrders(List<PlatformOrderDto> platformOrders) {
|
||||||
|
if (platformOrders.isEmpty()) {
|
||||||
|
throw new RuntimeException("采购订单数量不能为空");
|
||||||
|
}
|
||||||
|
if (platformOrders.size() > 20) {
|
||||||
|
throw new RuntimeException("批量采购订单数据不能超过20");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PlatformOrderDto platformOrder: platformOrders) {
|
||||||
|
if (platformOrder.getPlatformOrderId() == null || platformOrder.getConsigneeInfo() == null || platformOrder.getItems() == null) {
|
||||||
|
throw new RuntimeException("采购单参数异常");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkConsigneeInfo(ConsigneeInfoDto consigneeInfo) {
|
||||||
|
if (
|
||||||
|
StringUtils.isNotBlank(consigneeInfo.getFullname()) ||
|
||||||
|
StringUtils.isNotBlank(consigneeInfo.getMobile()) ||
|
||||||
|
StringUtils.isNotBlank(consigneeInfo.getProvince()) ||
|
||||||
|
StringUtils.isNotBlank(consigneeInfo.getCity()) ||
|
||||||
|
StringUtils.isNotBlank(consigneeInfo.getCounty()) ||
|
||||||
|
StringUtils.isNotBlank(consigneeInfo.getAddress()) ||
|
||||||
|
StringUtils.isNotBlank(consigneeInfo.getFullAddress())
|
||||||
|
) {
|
||||||
|
throw new RuntimeException("采购单参数异常");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkItems(List<ItemDto> items) {
|
||||||
|
for (ItemDto item: items) {
|
||||||
|
if (item.getSourceSkuId() == 0 || item.getItemTotal() == 0) {
|
||||||
|
throw new RuntimeException("items参数错误");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PlatformOrderDto> rebuildPlatformOrderItems(List<PlatformOrderDto> platformOrders) {
|
||||||
|
Stream<String> orderIdsStream = platformOrders.stream().map(PlatformOrderDto::getPlatformOrderId);
|
||||||
|
List<String> orderIds = orderIdsStream.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<Integer> skuIds = new ArrayList<>();
|
||||||
|
for (PlatformOrderDto platformOrder: platformOrders) {
|
||||||
|
for (ItemDto item: platformOrder.getItems()) {
|
||||||
|
skuIds.add(item.getSourceSkuId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, HashMap<Integer, String>> orderIdAndSkuIdAndSkuSubNameMap = opOrderChildService.getOrderIdAndSkuIdAndSkuSubNameMap(orderIds, skuIds);
|
||||||
|
for (PlatformOrderDto platformOrder: platformOrders) {
|
||||||
|
for (ItemDto item: platformOrder.getItems()) {
|
||||||
|
item.setPlatformSkuSubName(orderIdAndSkuIdAndSkuSubNameMap.get(platformOrder.getPlatformOrderId()).get(item.getSourceSkuId()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return platformOrders;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dsRelatePurchaseOrder(DsPurchaseOrderDto $purchaseOrder, OpOrder opOrder) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
package com.ms.common.util;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.ms.api.SaveItemService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class DsClient {
|
||||||
|
|
||||||
|
private static final String TOKEN = "dighgfghf^&)l3sedi&(.D@BC";
|
||||||
|
|
||||||
|
private static final String BASE_URL = "https://acn-ds-test.chengji-inc.com";
|
||||||
|
|
||||||
|
// 分销采购
|
||||||
|
private static final String API_BATCH_CREATE_DISTRIBUTION_ORDERS = "/open/order/batchCreateDistributionOrders";
|
||||||
|
|
||||||
|
public String sign(HashMap<String, Object> data) {
|
||||||
|
TreeMap<String, Object> map = new TreeMap<>(data);
|
||||||
|
Iterator<String> its = map.keySet().iterator();
|
||||||
|
StringBuffer buf = new StringBuffer();
|
||||||
|
buf.append(TOKEN);
|
||||||
|
while(its.hasNext()) {
|
||||||
|
String key = its.next();
|
||||||
|
buf.append(key);
|
||||||
|
if (map.get(key).getClass() == String.class) {
|
||||||
|
buf.append(map.get(key));
|
||||||
|
} else {
|
||||||
|
buf.append(JSON.toJSONString(map.get(key)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buf.append(TOKEN);
|
||||||
|
|
||||||
|
String signStr = buf.toString();
|
||||||
|
String sign = md5(signStr);
|
||||||
|
|
||||||
|
System.out.println(signStr);
|
||||||
|
System.out.println(sign);
|
||||||
|
return sign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean verify(HashMap<String, Object> map, String sign) {
|
||||||
|
return sign(map).equals(sign);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String batchCreateDistributionOrders(HashMap<String, Object> data) {
|
||||||
|
String sign = sign(data);
|
||||||
|
HashMap<String, String> headers = new HashMap<>();
|
||||||
|
headers.put("x-dd-micro-app-sign", sign);
|
||||||
|
headers.put("x-app-name", "msddMicro");
|
||||||
|
HttpClient client = new HttpClient();
|
||||||
|
return client.post(BASE_URL + API_BATCH_CREATE_DISTRIBUTION_ORDERS, data, headers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String md5(String str) {
|
||||||
|
try {
|
||||||
|
// 创建MessageDigest对象
|
||||||
|
MessageDigest md5Digest = MessageDigest.getInstance("MD5");
|
||||||
|
|
||||||
|
// 将字符串转换为字节数组
|
||||||
|
byte[] strBytes = str.getBytes();
|
||||||
|
|
||||||
|
// 计算MD5值
|
||||||
|
byte[] md5Bytes = md5Digest.digest(strBytes);
|
||||||
|
|
||||||
|
// 将字节数组转换为十六进制字符串
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (byte b : md5Bytes) {
|
||||||
|
sb.append(String.format("%02x", b));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.ms.common.util;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import javax.annotation.security.RunAs;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class HttpClient {
|
||||||
|
public String post(String url, Map<String, Object> data, HashMap<String, String> headers){
|
||||||
|
try {
|
||||||
|
String json = JSON.toJSONString(data);
|
||||||
|
HttpPost httpPost = new HttpPost(url);
|
||||||
|
for (String key:
|
||||||
|
headers.keySet()) {
|
||||||
|
httpPost.setHeader(key, headers.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseableHttpClient client = HttpClients.createDefault();
|
||||||
|
|
||||||
|
String charset = "UTF-8";
|
||||||
|
StringEntity entity = new StringEntity(json, charset);
|
||||||
|
entity.setContentEncoding(charset);
|
||||||
|
entity.setContentType("application/json");
|
||||||
|
httpPost.setEntity(entity);
|
||||||
|
|
||||||
|
HttpResponse response = client.execute(httpPost);
|
||||||
|
if(response.getStatusLine().getStatusCode() == 200){
|
||||||
|
HttpEntity httpEntity = response.getEntity();
|
||||||
|
return EntityUtils.toString(httpEntity, charset);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPost() {
|
||||||
|
Map<String, Object> data = new HashMap<>();
|
||||||
|
data.put("test", "nihao");
|
||||||
|
String body = post("https://www.baidu.com", data, null);
|
||||||
|
System.out.println(body);
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,60 @@
|
|||||||
package com.ms.web;
|
package com.ms.web;
|
||||||
|
|
||||||
|
import com.ms.api.service.OpOrderService;
|
||||||
|
import com.ms.api.service.ShopService;
|
||||||
|
import com.ms.common.util.DsClient;
|
||||||
|
import com.ms.common.util.HttpClient;
|
||||||
|
import com.ms.dal.entity.Shop;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author: laixw
|
* @Author: laixw
|
||||||
* @Date: 2023/8/22
|
* @Date: 2023/8/22
|
||||||
*/
|
*/
|
||||||
|
@RestController
|
||||||
public class Test {
|
public class Test {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ShopService shopService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OpOrderService opOrderService;
|
||||||
|
|
||||||
|
@GetMapping("/hello")
|
||||||
|
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
|
||||||
|
return String.format("Hello %s!", name);
|
||||||
|
}
|
||||||
|
@GetMapping("/test-http")
|
||||||
|
public String testHttp() {
|
||||||
|
HttpClient client = new HttpClient();
|
||||||
|
return client.post("https://www.baidu.com", null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/test-ds")
|
||||||
|
public String testDs() {
|
||||||
|
DsClient client = new DsClient();
|
||||||
|
HashMap<String, Object> data = new HashMap<>();
|
||||||
|
HashMap<String, String> listData = new HashMap<>();
|
||||||
|
listData.put("test", "testMulit");
|
||||||
|
data.put("province", "北京");
|
||||||
|
data.put("name", "hello");
|
||||||
|
data.put("listData", listData);
|
||||||
|
return client.batchCreateDistributionOrders(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/test-db")
|
||||||
|
public String testDb() {
|
||||||
|
Shop shop = shopService.selectByPrimaryKey(1L);
|
||||||
|
List<String> orderIdList = new ArrayList<>();
|
||||||
|
orderIdList.add("1");
|
||||||
|
System.out.println(opOrderService.getListByOrderIds(orderIdList));
|
||||||
|
return shop.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue