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_Express_RiderLocation_SFTC implements BusinessExecutor { 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(InvokeCallParams source) { return OperatorWait.AWAIT } @Override RetResult checkExecute(InvokeCallParams source) { //检查订单信息 def jsonSlurper = new JsonSlurper() def invokeOrder = jsonSlurper.parseText(source.params) String orderId = invokeOrder["orderId"] as String //todo 获取订单信息 return RetResult. successT().result(source) } RetResult 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 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. errorT().retinfo(sfOrderJson["error_msg"] as String) } return RetResult. successT().result( InvokeCallResult.success().data(JSON.toJSONString(sfOrderJson["result"]["feed"])) ) } catch (InterruptedException | ExecutionException | TimeoutException e) { logger.error(e.getMessage(), e) return RetResult. errorT().retinfo(e.getMessage()) } } }