| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- 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.datas.RedisKeys
- import com.dderp.common.entity.base.InvokeCallParams
- import com.dderp.common.entity.base.InvokeCallResult
- import com.dderp.common.entity.base.ProcessStringItem
- import com.dderp.common.entity.express.SFCreateOrderResult
- import com.dderp.common.entity.store.StoreInfo
- import com.dderp.common.entity.store.StorePlatformRequire
- import com.dderp.common.http.HttpTools
- import com.dySweetFishPlugin.sql.dao.OperatorWait
- import com.sweetfish.service.RetResult
- import groovy.json.JsonSlurper
- import org.apache.commons.lang3.StringUtils
- 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
- class BE_Express_ListOrderFeed_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
- @Override
- String scriptName() {
- return "顺丰同城订单状态流查询"
- }
- @Override
- ERPModule module() {
- return ERPModule.EXPRESS_API
- }
- @Override
- OperatorWait getAWait() {
- return OperatorWait.AWAIT
- }
- @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) {
- //todo
- def jsonSlurper = new JsonSlurper()
- def invokeOrder = jsonSlurper.parseText(source.params)
- //转成顺丰需要提交的信息
- long currentTime = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))
- def sfOrder = [
- dev_id: sfAppId,
- order_id: invokeOrder["sfOrderId"],
- shop_id: invokeOrder[""],
- push_time: currentTime
- ]
- String postData = JSON.toJSONString(sfOrder)
- logger.info("请求数据: " + postData)
- String sign = ExpressApiSign.sfGenerateOpenSign(postData, sfAppId, sfAppKey)
- String url = sfApiUrl + "listorderfeed?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)
- //直接输出orderResult一方面unicode编码,一方面有些数据不要,只要结果里面的feed即可这里在转换一下
- def sfOrderJson = jsonSlurper.parseText(orderResult)
- if (sfOrderJson["error_code"] != 0) {
- return RetResult.<InvokeCallResult> errorT().retinfo(sfOrderJson["error_msg"] as String)
- }
- return RetResult.<InvokeCallResult> successT().result(
- InvokeCallResult.success().data(JSON.toJSONString(sfOrderJson["result"]["feed"]))
- )
- } catch (InterruptedException | ExecutionException | TimeoutException e) {
- logger.error(e.getMessage(), e)
- return RetResult.<InvokeCallResult> errorT().retinfo(e.getMessage())
- }
- }
- }
|