From 6247b1eba62379d9dd21c6895e87cc5c7494f52c Mon Sep 17 00:00:00 2001 From: luojian <1327479187@qq.com> Date: Tue, 11 Feb 2025 15:43:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E7=94=A8=E5=90=8C=E5=9F=8E=E6=80=A5?= =?UTF-8?q?=E9=80=81=E5=B9=B3=E5=8F=B0=E6=96=B0=E5=A2=9E=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E6=97=B6=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=86=85=E5=AD=90=E5=8D=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cpxt/biz/mapper/BizOrderSubMapper.java | 6 +- .../com/cpxt/biz/orderutil/CityDelivery.java | 193 +++++++++--------- .../biz/service/impl/BizOrderServiceImpl.java | 42 +++- 3 files changed, 136 insertions(+), 105 deletions(-) diff --git a/cpxt-system/src/main/java/com/cpxt/biz/mapper/BizOrderSubMapper.java b/cpxt-system/src/main/java/com/cpxt/biz/mapper/BizOrderSubMapper.java index d83393e..2946d57 100644 --- a/cpxt-system/src/main/java/com/cpxt/biz/mapper/BizOrderSubMapper.java +++ b/cpxt-system/src/main/java/com/cpxt/biz/mapper/BizOrderSubMapper.java @@ -5,6 +5,7 @@ import java.util.List; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.cpxt.biz.domain.BizOrderSub; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; /** * 订单子单Mapper接口 @@ -14,4 +15,7 @@ import org.apache.ibatis.annotations.Mapper; */ @Mapper public interface BizOrderSubMapper extends BaseMapper -{ } +{ + @Select("select * from biz_order_sub where sub_order_sn = #{subOrderSn}") + BizOrderSub selectBySubOrderSn(String subOrderSn); +} diff --git a/cpxt-system/src/main/java/com/cpxt/biz/orderutil/CityDelivery.java b/cpxt-system/src/main/java/com/cpxt/biz/orderutil/CityDelivery.java index aff8f0e..aaebc23 100644 --- a/cpxt-system/src/main/java/com/cpxt/biz/orderutil/CityDelivery.java +++ b/cpxt-system/src/main/java/com/cpxt/biz/orderutil/CityDelivery.java @@ -57,7 +57,101 @@ public class CityDelivery { /** * 同城急送平台工具,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 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)); + /** + * post请求,需要放data + */ + 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 sortedParams = new TreeMap<>(sortedMap); + Set> entrySet = sortedParams.entrySet(); + // 遍历排序后的字典,将所有参数按"key=value"格式拼接在一起 + StringBuilder stringToSign = new StringBuilder(); + for (Map.Entry 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 goodsType = bizOrderSub.getGoodsType(); String goodsTypeLabel = sysDictDataMapper.selectDictLabel("sys_goods_type", goodsType); @@ -286,104 +380,9 @@ public class CityDelivery { log.info("========================================请求结果========================================"); System.out.println("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 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)); - /** - * post请求,需要放data - */ - 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 sortedParams = new TreeMap<>(sortedMap); - Set> entrySet = sortedParams.entrySet(); - // 遍历排序后的字典,将所有参数按"key=value"格式拼接在一起 - StringBuilder stringToSign = new StringBuilder(); - for (Map.Entry 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 */ diff --git a/cpxt-system/src/main/java/com/cpxt/biz/service/impl/BizOrderServiceImpl.java b/cpxt-system/src/main/java/com/cpxt/biz/service/impl/BizOrderServiceImpl.java index 9635b6a..f01ff45 100644 --- a/cpxt-system/src/main/java/com/cpxt/biz/service/impl/BizOrderServiceImpl.java +++ b/cpxt-system/src/main/java/com/cpxt/biz/service/impl/BizOrderServiceImpl.java @@ -7,6 +7,8 @@ import java.util.List; import java.util.Map; import cn.hutool.core.date.DateUtil; 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.update.UpdateWrapper; 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.common.core.domain.entity.SysUser; import com.cpxt.common.exception.ServiceException; -import com.cpxt.common.utils.Helper; -import com.cpxt.common.utils.PositionUtil; -import com.cpxt.common.utils.SecurityUtils; -import com.cpxt.common.utils.StringUtils; +import com.cpxt.common.utils.*; import com.cpxt.system.mapper.SysUserMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -99,7 +98,7 @@ public class BizOrderServiceImpl implements IBizOrderService { return bizOrderMapper.selectPage(new Page<>(pageNum, pageSize), queryWrapper); } - /** + /** * 查询订单列表(主驾司机或者副驾司机是当前用户 - 分页) * * @return 订单 @@ -385,8 +384,37 @@ public class BizOrderServiceImpl implements IBizOrderService { BizOrder bizOrder = bizOrderMapper.selectByOrderSn(orderSn); bizOrder.setSubStatus(1); 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 result = (Map) 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); + } } } }