BE_Express_ListOrderFeed_SFTC.groovy 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import com.alibaba.fastjson2.JSON
  2. import com.dderp.common.api.BusinessExecutor
  3. import com.dderp.common.api.ERPLockDataService
  4. import com.dderp.common.datas.ERPModule
  5. import com.dderp.common.datas.RedisKeys
  6. import com.dderp.common.entity.base.InvokeCallParams
  7. import com.dderp.common.entity.base.InvokeCallResult
  8. import com.dderp.common.entity.base.ProcessStringItem
  9. import com.dderp.common.entity.express.SFCreateOrderResult
  10. import com.dderp.common.entity.store.StoreInfo
  11. import com.dderp.common.entity.store.StorePlatformRequire
  12. import com.dderp.common.http.HttpTools
  13. import com.dySweetFishPlugin.sql.dao.OperatorWait
  14. import com.sweetfish.service.RetResult
  15. import groovy.json.JsonSlurper
  16. import org.apache.commons.lang3.StringUtils
  17. import org.apache.logging.log4j.LogManager
  18. import org.apache.logging.log4j.Logger
  19. import javax.annotation.Resource
  20. import java.nio.charset.StandardCharsets
  21. import java.time.LocalDateTime
  22. import java.time.ZoneOffset
  23. import java.util.concurrent.CompletableFuture
  24. import java.util.concurrent.ExecutionException
  25. import java.util.concurrent.TimeUnit
  26. import java.util.concurrent.TimeoutException
  27. class BE_Express_ListOrderFeed_SFTC implements BusinessExecutor<InvokeCallParams, InvokeCallResult> {
  28. private final Logger logger = LogManager.getLogger(this.getClass().getSimpleName())
  29. @Resource(name = "property.sftc.appId")
  30. long sfAppId
  31. @Resource(name = "property.sftc.appKey")
  32. String sfAppKey
  33. @Resource(name = "property.sftc.apiUrl")
  34. String sfApiUrl
  35. @Override
  36. String scriptName() {
  37. return "顺丰同城订单状态流查询"
  38. }
  39. @Override
  40. ERPModule module() {
  41. return ERPModule.EXPRESS_API
  42. }
  43. @Override
  44. OperatorWait getAWait() {
  45. return OperatorWait.AWAIT
  46. }
  47. @Override
  48. RetResult<InvokeCallParams> checkExecute(InvokeCallParams source) {
  49. //检查订单信息
  50. def jsonSlurper = new JsonSlurper()
  51. def invokeOrder = jsonSlurper.parseText(source.params)
  52. String orderId = invokeOrder["orderId"] as String
  53. //todo 获取订单信息
  54. return RetResult.<InvokeCallParams> successT().result(source)
  55. }
  56. RetResult<InvokeCallResult> execute(InvokeCallParams source) {
  57. //todo
  58. def jsonSlurper = new JsonSlurper()
  59. def invokeOrder = jsonSlurper.parseText(source.params)
  60. //转成顺丰需要提交的信息
  61. long currentTime = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))
  62. def sfOrder = [
  63. dev_id: sfAppId,
  64. order_id: invokeOrder["sfOrderId"],
  65. shop_id: invokeOrder[""],
  66. push_time: currentTime
  67. ]
  68. String postData = JSON.toJSONString(sfOrder)
  69. logger.info("请求数据: " + postData)
  70. String sign = ExpressApiSign.sfGenerateOpenSign(postData, sfAppId, sfAppKey)
  71. String url = sfApiUrl + "listorderfeed?sign=" + sign
  72. CompletableFuture<String> apiResult = HttpTools.postHttpContentAsync(url,
  73. 5000,
  74. StandardCharsets.UTF_8,
  75. postData,
  76. ["Content-Type": "application/json;charset=utf-8"])
  77. try {
  78. String orderResult = apiResult.get(6000, TimeUnit.SECONDS)
  79. //直接输出orderResult一方面unicode编码,一方面有些数据不要,只要结果里面的feed即可这里在转换一下
  80. def sfOrderJson = jsonSlurper.parseText(orderResult)
  81. if (sfOrderJson["error_code"] != 0) {
  82. return RetResult.<InvokeCallResult> errorT().retinfo(sfOrderJson["error_msg"] as String)
  83. }
  84. return RetResult.<InvokeCallResult> successT().result(
  85. InvokeCallResult.success().data(JSON.toJSONString(sfOrderJson["result"]["feed"]))
  86. )
  87. } catch (InterruptedException | ExecutionException | TimeoutException e) {
  88. logger.error(e.getMessage(), e)
  89. return RetResult.<InvokeCallResult> errorT().retinfo(e.getMessage())
  90. }
  91. }
  92. }