BE_Order_Sync_RiderLocation_DYLK.groovy 3.7 KB

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