| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import com.alibaba.fastjson2.JSON
- import com.dderp.common.api.BusinessExecutor
- import com.dderp.common.api.ERPLockDataService
- import com.dderp.common.datas.ERPModule
- import com.dderp.common.entity.base.InvokeCallParams
- import com.dderp.common.entity.base.InvokeCallResult
- import com.dderp.common.http.HttpTools
- import com.dySweetFishPlugin.sql.dao.OperatorWait
- import com.sweetfish.convert.json.JsonConvert
- import com.sweetfish.service.RetResult
- import groovy.json.JsonSlurper
- 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_PreCreateOrder_SFTC implements BusinessExecutor<InvokeCallParams, InvokeCallResult> {
- 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.apiUrl")
- String sfApiUrl
- @Resource
- JsonConvert jsonConvert
- @Resource
- ERPLockDataService lockDataService
- @Override
- String scriptName() {
- return "顺丰同城预创建订单--价格计算"
- }
- @Override
- ERPModule module() {
- return ERPModule.EXPRESS_API
- }
- @Override
- OperatorWait getAWait(InvokeCallParams source) {
- return OperatorWait.SYNC
- }
- @Override
- RetResult<InvokeCallParams> checkExecute(InvokeCallParams source) {
- //检查订单信息
- def jsonSlurper = new JsonSlurper()
- def invokeOrder = jsonSlurper.parseText(source.params)
- String orderId = invokeOrder["orderId"] as String
- //todo 获取订单信息
- return RetResult.<InvokeCallParams> successT().result(source)
- }
- RetResult<InvokeCallResult> execute(InvokeCallParams source) {
- //预创建订单,并非真正发单;用来验证是否可以发单并在成功时返回时效、计价等信息,也可用来验证地址以及时间是否在顺丰的配送范围内
- //秒级时间戳,groovy里面不让用system
- long currentTime = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))
- def sfOrder = [
- dev_id : sfAppId,
- shop_type : 1,
- user_address: "北京市海淀区国泰大厦",
- push_time : currentTime
- ]
- String postData = JSON.toJSONString(sfOrder)
- logger.info("请求数据: " + postData)
- String sign = ExpressApiSign.sfGenerateOpenSign(postData, sfAppId, sfAppKey)
- String url = sfApiUrl + "precreateorder?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)
- def jsonSlurper = new JsonSlurper()
- def sfOrderJson = jsonSlurper.parseText(orderResult)
- logger.info(sfOrderJson)
- return RetResult.<InvokeCallResult> successT()
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
- logger.error(e.getMessage(), e)
- return RetResult.<InvokeCallResult> errorT().retinfo(e.getMessage())
- }
- }
- }
|