调用同城急送平台新增订单时同步更新系统内子单信息

master
luojian 2025-02-11 15:43:04 +08:00
parent e948c3b71b
commit 6247b1eba6
3 changed files with 136 additions and 105 deletions

View File

@ -5,6 +5,7 @@ import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cpxt.biz.domain.BizOrderSub; import com.cpxt.biz.domain.BizOrderSub;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
/** /**
* Mapper * Mapper
@ -14,4 +15,7 @@ import org.apache.ibatis.annotations.Mapper;
*/ */
@Mapper @Mapper
public interface BizOrderSubMapper extends BaseMapper<BizOrderSub> public interface BizOrderSubMapper extends BaseMapper<BizOrderSub>
{ } {
@Select("select * from biz_order_sub where sub_order_sn = #{subOrderSn}")
BizOrderSub selectBySubOrderSn(String subOrderSn);
}

View File

@ -57,7 +57,101 @@ public class CityDelivery {
/** /**
* post * post
*/ */
public void addOrder(BizOrder bizOrder,BizOrderSub bizOrderSub) { public void cityDelivery_signBody22() {
Long timeStamp = System.currentTimeMillis();
String nonce = UUID.randomUUID().toString().replace("-", "");
System.out.println("nonce:" + nonce);
System.out.println("timeStamp:" + timeStamp);
//签名
Map<String, Object> sortedMap = new TreeMap<>();
//下单接口
String body = "{\n" +
" \"customerCode\": \"HFCP\",\n" +
" \"payTypeFirst\": \"03\",\n" +
" \"channelOrderNo\": \"Y202501021005-1\",\n" +
" \"platformOrderNo\": \"\",\n" +
" \"expressNbr\": \"\",\n" +
" \"coordinateTransformType\": \"02\",\n" +
" \"weight\": \"501\",\n" +
" \"expectedTime\": \"2025-01-22,18:12:00\",\n" +
" \"postageFee\": \"2000\",\n" +
// " \"convertFlag\": false,\n" +
" \"orderSource\": \"other\",\n" +
" \"orderSourcePlatform\": \"其他\",\n" +
" \"costFee\": \"0\",\n" +
" \"tipFee\": \"0\",\n" +
" \"insuredFee\": \"0\",\n" +
" \"otherFee1\": \"0\",\n" +
" \"otherFee2\": \"0\",\n" +
" \"packageDesc\": \"药品\",\n" +
" \"remark\": \"手机尾号1234\",\n" +
" \"addressFirst\": {\n" +
" \"senderProviceCode\": \"340000\",\n" +
" \"senderProviceName\": \"安徽省\",\n" +
" \"senderCityCode\": \"340100\",\n" +
" \"senderCityName\": \"合肥市\",\n" +
" \"senderCountyCode\": \"340102\",\n" +
" \"senderCountyName\": \"瑶海区\",\n" +
" \"senderContactName\": \"中山三院\",\n" +
" \"senderContactPhone\": \"17523029470\",\n" +
" \"senderLongitude\": \"117.307179\",\n" +
" \"senderLatitude\": \"31.856484\",\n" +
" \"senderStreetCode\": \"001\",\n" +
" \"senderStreetName\": \"明光路街道\",\n" +
" \"senderAddr\": \"明光路188号\",\n" +
" \"receiverProviceCode\": \"340000\",\n" +
" \"receiverProviceName\": \"安徽省\",\n" +
" \"receiverCityCode\": \"340100\",\n" +
" \"receiverCityName\": \"合肥市\",\n" +
" \"receiverCountyCode\": \"340103\",\n" +
" \"receiverCountyName\": \"庐阳区\",\n" +
" \"receiverContactName\": \"陈先生\",\n" +
" \"receiverContactPhone\": \"13711511111\",\n" +
" \"receiverAddr\": \"信源大厦20楼2007\",\n" +
" \"receiverLongitude\": \"117.285075\",\n" +
" \"receiverLatitude\": \"31.882703\",\n" +
" \"receiverStreetCode\": \"002\",\n" +
" \"receiverStreetName\": \"双岗街道\"\n" +
" },\n" +
" \"businessJson\": {\n" +
// " \"a\": \"a\",\n" +
// " \"b\": \"b\"\n" +
" }\n" +
"}";
//查询物流轨迹
// String body = "{\n" +
// " \"expressNbr\": \"1158114584567\",\n" +
// " \"channelOrderNo\": \"\"\n" +
// "}";
//get请求组装成 k v类型
// sortedMap.put(paramName,request.getParameter(paramName));
/**
* postdata
*/
String bodyjson = JSON.toJSONString(StrUtil.removeAll(body, specialChars));
System.out.println("bodyjson: " + bodyjson);
sortedMap.put("data", JSON.toJSONString(StrUtil.removeAll(body, specialChars)));
sortedMap.put("access_id", clientKey);
sortedMap.put("nonce", nonce);
sortedMap.put("timestamp", timeStamp);
//排序
Map<String, Object> sortedParams = new TreeMap<>(sortedMap);
Set<Map.Entry<String, Object>> entrySet = sortedParams.entrySet();
// 遍历排序后的字典,将所有参数按"key=value"格式拼接在一起
StringBuilder stringToSign = new StringBuilder();
for (Map.Entry<String, Object> param : entrySet) {
stringToSign.append(param.getKey()).append("=").append(param.getValue()).append(",");
}
stringToSign.append("accessSecret").append("=").append(clientSecret);
String genSign = CityDelivery_SM4Util.encryptCBC(stringToSign.toString(), clientSecret, sm4Key);
System.out.println("sign:" + genSign);
}
/**
* post
*/
public String addOrder(BizOrder bizOrder,BizOrderSub bizOrderSub) {
String url = "https://wyjcs.gdwyj.cn/szelec/city-delivery-api/api/base/order/add"; String url = "https://wyjcs.gdwyj.cn/szelec/city-delivery-api/api/base/order/add";
String goodsType = bizOrderSub.getGoodsType(); String goodsType = bizOrderSub.getGoodsType();
String goodsTypeLabel = sysDictDataMapper.selectDictLabel("sys_goods_type", goodsType); String goodsTypeLabel = sysDictDataMapper.selectDictLabel("sys_goods_type", goodsType);
@ -286,104 +380,9 @@ public class CityDelivery {
log.info("========================================请求结果========================================"); log.info("========================================请求结果========================================");
System.out.println("response" + response); System.out.println("response" + response);
log.info("response" + response); log.info("response" + response);
return response.body();
} }
/**
* post
*/
public void cityDelivery_signBody22() {
Long timeStamp = System.currentTimeMillis();
String nonce = UUID.randomUUID().toString().replace("-", "");
System.out.println("nonce:" + nonce);
System.out.println("timeStamp:" + timeStamp);
//签名
Map<String, Object> sortedMap = new TreeMap<>();
//下单接口
String body = "{\n" +
" \"customerCode\": \"HFCP\",\n" +
" \"payTypeFirst\": \"03\",\n" +
" \"channelOrderNo\": \"Y202501021005-1\",\n" +
" \"platformOrderNo\": \"\",\n" +
" \"expressNbr\": \"\",\n" +
" \"coordinateTransformType\": \"02\",\n" +
" \"weight\": \"501\",\n" +
" \"expectedTime\": \"2025-01-22,18:12:00\",\n" +
" \"postageFee\": \"2000\",\n" +
// " \"convertFlag\": false,\n" +
" \"orderSource\": \"other\",\n" +
" \"orderSourcePlatform\": \"其他\",\n" +
" \"costFee\": \"0\",\n" +
" \"tipFee\": \"0\",\n" +
" \"insuredFee\": \"0\",\n" +
" \"otherFee1\": \"0\",\n" +
" \"otherFee2\": \"0\",\n" +
" \"packageDesc\": \"药品\",\n" +
" \"remark\": \"手机尾号1234\",\n" +
" \"addressFirst\": {\n" +
" \"senderProviceCode\": \"340000\",\n" +
" \"senderProviceName\": \"安徽省\",\n" +
" \"senderCityCode\": \"340100\",\n" +
" \"senderCityName\": \"合肥市\",\n" +
" \"senderCountyCode\": \"340102\",\n" +
" \"senderCountyName\": \"瑶海区\",\n" +
" \"senderContactName\": \"中山三院\",\n" +
" \"senderContactPhone\": \"17523029470\",\n" +
" \"senderLongitude\": \"117.307179\",\n" +
" \"senderLatitude\": \"31.856484\",\n" +
" \"senderStreetCode\": \"001\",\n" +
" \"senderStreetName\": \"明光路街道\",\n" +
" \"senderAddr\": \"明光路188号\",\n" +
" \"receiverProviceCode\": \"340000\",\n" +
" \"receiverProviceName\": \"安徽省\",\n" +
" \"receiverCityCode\": \"340100\",\n" +
" \"receiverCityName\": \"合肥市\",\n" +
" \"receiverCountyCode\": \"340103\",\n" +
" \"receiverCountyName\": \"庐阳区\",\n" +
" \"receiverContactName\": \"陈先生\",\n" +
" \"receiverContactPhone\": \"13711511111\",\n" +
" \"receiverAddr\": \"信源大厦20楼2007\",\n" +
" \"receiverLongitude\": \"117.285075\",\n" +
" \"receiverLatitude\": \"31.882703\",\n" +
" \"receiverStreetCode\": \"002\",\n" +
" \"receiverStreetName\": \"双岗街道\"\n" +
" },\n" +
" \"businessJson\": {\n" +
// " \"a\": \"a\",\n" +
// " \"b\": \"b\"\n" +
" }\n" +
"}";
//查询物流轨迹
// String body = "{\n" +
// " \"expressNbr\": \"1158114584567\",\n" +
// " \"channelOrderNo\": \"\"\n" +
// "}";
//get请求组装成 k v类型
// sortedMap.put(paramName,request.getParameter(paramName));
/**
* postdata
*/
String bodyjson = JSON.toJSONString(StrUtil.removeAll(body, specialChars));
System.out.println("bodyjson: " + bodyjson);
sortedMap.put("data", JSON.toJSONString(StrUtil.removeAll(body, specialChars)));
sortedMap.put("access_id", clientKey);
sortedMap.put("nonce", nonce);
sortedMap.put("timestamp", timeStamp);
//排序
Map<String, Object> sortedParams = new TreeMap<>(sortedMap);
Set<Map.Entry<String, Object>> entrySet = sortedParams.entrySet();
// 遍历排序后的字典,将所有参数按"key=value"格式拼接在一起
StringBuilder stringToSign = new StringBuilder();
for (Map.Entry<String, Object> param : entrySet) {
stringToSign.append(param.getKey()).append("=").append(param.getValue()).append(",");
}
stringToSign.append("accessSecret").append("=").append(clientSecret);
String genSign = CityDelivery_SM4Util.encryptCBC(stringToSign.toString(), clientSecret, sm4Key);
System.out.println("sign:" + genSign);
}
/** /**
* token * token
*/ */

View File

@ -7,6 +7,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -17,10 +19,7 @@ import com.cpxt.biz.mapper.*;
import com.cpxt.biz.orderutil.CityDelivery; import com.cpxt.biz.orderutil.CityDelivery;
import com.cpxt.common.core.domain.entity.SysUser; import com.cpxt.common.core.domain.entity.SysUser;
import com.cpxt.common.exception.ServiceException; import com.cpxt.common.exception.ServiceException;
import com.cpxt.common.utils.Helper; import com.cpxt.common.utils.*;
import com.cpxt.common.utils.PositionUtil;
import com.cpxt.common.utils.SecurityUtils;
import com.cpxt.common.utils.StringUtils;
import com.cpxt.system.mapper.SysUserMapper; import com.cpxt.system.mapper.SysUserMapper;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -99,7 +98,7 @@ public class BizOrderServiceImpl implements IBizOrderService {
return bizOrderMapper.selectPage(new Page<>(pageNum, pageSize), queryWrapper); return bizOrderMapper.selectPage(new Page<>(pageNum, pageSize), queryWrapper);
} }
/** /**
* - * -
* *
* @return * @return
@ -385,8 +384,37 @@ public class BizOrderServiceImpl implements IBizOrderService {
BizOrder bizOrder = bizOrderMapper.selectByOrderSn(orderSn); BizOrder bizOrder = bizOrderMapper.selectByOrderSn(orderSn);
bizOrder.setSubStatus(1); bizOrder.setSubStatus(1);
bizOrderMapper.updateById(bizOrder); bizOrderMapper.updateById(bizOrder);
// 同步调用同城急送平台
cityDelivery.addOrder(bizOrder,bizOrderSub);
// 同步调用同城急送平台入口
String response = cityDelivery.addOrder(bizOrder, bizOrderSub);
JSONObject jsonObject = JSON.parseObject(response);
if (jsonObject.get("code").equals("200")){
// 同步更新运单信息
BizOrderSub orderSub = bizOrderSubMapper.selectBySubOrderSn((String) map1.get("subOrderSn"));
Map<String,Object> result = (Map<String, Object>) jsonObject.get("result");
// 预计送达时间(时间戳)
Long expectTime = (Long) result.get("expectTime");
// 配送距离
Long distance = (Long) result.get("distance");
String costFee = (String) result.get("costFee");
String tipFee = (String) result.get("tipFee");
String insuredFee = (String) result.get("insuredFee");
String otherFee1 = (String) result.get("otherFee1");
String otherFee2 = (String) result.get("otherFee2");
String totalFee = (String) result.get("totalFee");
String postageFee = (String) result.get("postageFee");
orderSub.setExpectTime(new Date(expectTime));
orderSub.setDistance(String.valueOf(distance));
orderSub.setCostFee(costFee);
orderSub.setTipFee(tipFee);
orderSub.setInsuredFee(insuredFee);
orderSub.setOtherFee1(otherFee1);
orderSub.setOtherFee2(otherFee2);
orderSub.setTotalFee(totalFee);
orderSub.setPostageFee(postageFee);
bizOrderSubMapper.updateById(orderSub);
}
} }
} }
} }