BE_Express_CancelOrder_SFTC.groovy 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_CancelOrder_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. @Resource
  36. ERPLockDataService lockDataService
  37. @Override
  38. String scriptName() {
  39. return "顺丰同城取消订单"
  40. }
  41. @Override
  42. ERPModule module() {
  43. return ERPModule.EXPRESS_API
  44. }
  45. @Override
  46. OperatorWait getAWait() {
  47. return OperatorWait.ASNYC
  48. }
  49. @Override
  50. RetResult<InvokeCallParams> beforeExecute(InvokeCallParams source) {
  51. //锁定下订单数据
  52. def jsonSlurper = new JsonSlurper()
  53. def invokeOrder = jsonSlurper.parseText(source.params)
  54. String orderId = invokeOrder["orderId"] as String
  55. //todo 获取订单信息
  56. if (lockDataService.hLockAdd(orderId, RedisKeys.KEY_ERP_WORKING_ORDER, source.supplierCode) > 1) {
  57. return RetResult.<InvokeCallParams> errorT().retinfo(orderId + "提交工作中,请稍后刷新即可,无需重复操作")
  58. }
  59. return RetResult.<InvokeCallParams> successT().result(source)
  60. }
  61. @Override
  62. RetResult<InvokeCallParams> checkExecute(InvokeCallParams source) {
  63. //检查订单信息
  64. def jsonSlurper = new JsonSlurper()
  65. def invokeOrder = jsonSlurper.parseText(source.params)
  66. String orderId = invokeOrder["orderId"] as String
  67. //todo 获取订单信息
  68. return RetResult.<InvokeCallParams> successT().result(source)
  69. }
  70. RetResult<InvokeCallResult> execute(InvokeCallParams source) {
  71. //todo
  72. def jsonSlurper = new JsonSlurper()
  73. def invokeOrder = jsonSlurper.parseText(source.params)
  74. //转成顺丰需要提交的信息
  75. long currentTime = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))
  76. def sfOrder = [
  77. dev_id: sfAppId,
  78. order_id: invokeOrder[""],
  79. shop_id: invokeOrder[""],
  80. push_time: currentTime
  81. ]
  82. String postData = JSON.toJSONString(sfOrder)
  83. logger.info("请求数据: " + postData)
  84. String sign = ExpressApiSign.sfGenerateOpenSign(postData, sfAppId, sfAppKey)
  85. String url = sfApiUrl + "cancelorder?sign=" + sign
  86. CompletableFuture<String> apiResult = HttpTools.postHttpContentAsync(url,
  87. 5000,
  88. StandardCharsets.UTF_8,
  89. postData,
  90. ["Content-Type": "application/json;charset=utf-8"])
  91. try {
  92. String orderResult = apiResult.get(6000, TimeUnit.SECONDS)
  93. def sfOrderJson = jsonSlurper.parseText(orderResult)
  94. logger.info(sfOrderJson)
  95. return RetResult.<InvokeCallResult> successT()
  96. } catch (InterruptedException | ExecutionException | TimeoutException e) {
  97. logger.error(e.getMessage(), e)
  98. return RetResult.<InvokeCallResult> errorT().retinfo(e.getMessage())
  99. }
  100. }
  101. }