|
|
@@ -1 +1,111 @@
|
|
|
+import com.alibaba.fastjson2.JSON
|
|
|
+import com.dderp.common.api.BusinessExecutor
|
|
|
+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.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
|
|
|
+
|
|
|
+class BE_Order_Sync_RiderLocation_DYLK 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.ORDER_API
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ OperatorWait getAWait(InvokeCallParams source) {
|
|
|
+ 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())
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
|