| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import com.alibaba.fastjson2.JSON
- import com.alibaba.fastjson2.JSONWriter
- import com.dderp.common.api.BusinessExecutor
- import com.dderp.common.datas.ERPModule
- import com.dderp.common.entity.base.ProcessStringItem
- import com.dderp.common.entity.express.SFCreateOrderResult
- import com.dderp.common.entity.express.SFOrder
- import com.dderp.common.entity.express.SFOrderDetail
- import com.dderp.common.entity.express.SFOrderProductDetail
- import com.dderp.common.entity.express.SFOrderReceive
- import com.dderp.common.http.HttpTools
- import com.sweetfish.convert.json.JsonConvert
- import com.sweetfish.service.RetResult
- import org.apache.logging.log4j.LogManager
- import org.apache.logging.log4j.Logger
- import javax.annotation.Resource
- import java.nio.charset.StandardCharsets
- import java.time.LocalDateTime
- import java.time.ZoneOffset
- import java.util.concurrent.CompletableFuture
- import java.util.concurrent.ExecutionException
- import java.util.concurrent.TimeUnit
- import java.util.concurrent.TimeoutException
- @SuppressWarnings("unused")
- class BE_Express_CreateOrder_SFTC implements BusinessExecutor<ProcessStringItem, ProcessStringItem> {
- private final Logger logger = LogManager.getLogger(this.getClass().getSimpleName())
- @Resource(name = "property.sftc.appId")
- long sfAppId
- @Resource(name = "property.sftc.appKey")
- String sfAppKey
- @Resource(name = "property.sftc.createOrderUrl")
- String sfCreateOrderUrl
- @Resource
- JsonConvert jsonConvert
- @Override
- String scriptName() {
- return "顺丰同城创建订单"
- }
- @Override
- ERPModule module() {
- return ERPModule.EXPRESS_API
- }
- RetResult<ProcessStringItem> execute(ProcessStringItem source) {
- //秒级时间戳,groovy里面不让用system
- long currentTime = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))
- long testTime = LocalDateTime.now().toInstant(ZoneOffset.ofHours(8)).toEpochMilli()
- SFOrder sfOrder = new SFOrder(
- dev_id: sfAppId,
- shop_id: "3243279847393",
- shop_type: 1,
- shop_order_id: "JY" + testTime + "L",
- order_sequence: "测试",
- lbs_type: 2,
- order_time: currentTime,
- push_time: currentTime,
- vehicle: 0,
- four_wheeler_type: 10,
- rider_pick_method: 1,
- version: 19,
- order_detail: new SFOrderDetail(
- total_price: 30100L,
- product_type: 6,
- weight_gram: 3000L,
- product_num: 15,
- product_type_num: 5,
- product_detail: [
- new SFOrderProductDetail(
- product_name: "测试商品1",
- product_num: 1
- ),
- new SFOrderProductDetail(
- product_name: "测试商品2",
- product_num: 3
- ),
- ]
- ),
- receive: new SFOrderReceive(
- user_name: "顺丰同城",
- user_phone: "18237171439",
- user_lng: "116.339392",
- user_lat: "40.002349",
- user_address: "北京市海淀区学清嘉创大厦A座15层"
- )
- )
- String postData = JSON.toJSONString(sfOrder)
- logger.info("请求数据: " + postData)
- String sign = ExpressApiSign.sfGenerateOpenSign(postData, sfAppId, sfAppKey)
- String url = sfCreateOrderUrl + "sign=" + sign
- CompletableFuture<String> apiResult = HttpTools.postHttpContentAsync(url,
- 5000,
- StandardCharsets.UTF_8,
- postData,
- ["Content-Type": "application/json;charset=utf-8"])
- try {
- String orderResult = apiResult.get(6000, TimeUnit.SECONDS)
- SFCreateOrderResult createOrderResult = jsonConvert.convertFromO(SFCreateOrderResult.class, orderResult)
- logger.info(orderResult)
- logger.info(jsonConvert.convertTo(createOrderResult))
- return RetResult.<ProcessStringItem> successT().result(
- ProcessStringItem.newBuilder()
- .itemValue("")
- .build()
- )
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
- logger.error(e.getMessage(), e)
- return RetResult.<ProcessStringItem> successT().result(
- ProcessStringItem.newBuilder()
- .itemValue("")
- .build()
- )
- }
- }
- }
|