|
|
@@ -0,0 +1,188 @@
|
|
|
+import com.dderp.business.dao.OrderDao
|
|
|
+import com.dderp.common.api.BusinessExecutor
|
|
|
+import com.dderp.common.api.StoreService
|
|
|
+import com.dderp.common.api.SupplierInitService
|
|
|
+import com.dderp.common.api.flycat.DouyinService
|
|
|
+import com.dderp.common.api.flycat.OrderSearchService
|
|
|
+import com.dderp.common.api.flycat.OrderService
|
|
|
+import com.dderp.common.api.flycat.OrderStepService
|
|
|
+import com.dderp.common.datas.BusinessOrderStatus
|
|
|
+import com.dderp.common.datas.ERPModule
|
|
|
+import com.dderp.common.datas.ESKeys
|
|
|
+import com.dderp.common.datas.ReadOrderOption
|
|
|
+import com.dderp.common.datas.business.PlatformType
|
|
|
+import com.dderp.common.entity.base.InvokeCallParams
|
|
|
+import com.dderp.common.entity.base.InvokeCallResult
|
|
|
+import com.dderp.common.entity.base.ProcessStringItem
|
|
|
+import com.dderp.common.entity.geo.GeoPoiLocation
|
|
|
+import com.dderp.common.entity.order.*
|
|
|
+import com.dderp.common.entity.site.ERPTokenUser
|
|
|
+import com.dderp.common.entity.store.StorePlatform
|
|
|
+import com.dderp.common.entity.store.ViewStoreInfo
|
|
|
+import com.dySweetFishPlugin.elasticsearch.ESClient
|
|
|
+import com.dySweetFishPlugin.sql.TableIdService
|
|
|
+import com.dySweetFishPlugin.sql.dao.TunaService
|
|
|
+import com.sweetfish.convert.json.JsonConvert
|
|
|
+import com.sweetfish.service.RetResult
|
|
|
+import groovy.json.JsonSlurper
|
|
|
+import org.apache.logging.log4j.LogManager
|
|
|
+import org.apache.logging.log4j.Logger
|
|
|
+import org.elasticsearch.action.bulk.BulkRequestBuilder
|
|
|
+import org.elasticsearch.action.bulk.BulkResponse
|
|
|
+import org.elasticsearch.action.index.IndexRequestBuilder
|
|
|
+import org.elasticsearch.action.support.WriteRequest
|
|
|
+import org.elasticsearch.action.update.UpdateRequestBuilder
|
|
|
+import org.elasticsearch.common.xcontent.XContentType
|
|
|
+
|
|
|
+import javax.annotation.Resource
|
|
|
+import java.math.RoundingMode
|
|
|
+import java.time.LocalDateTime
|
|
|
+import java.time.ZoneOffset
|
|
|
+
|
|
|
+import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder
|
|
|
+
|
|
|
+@SuppressWarnings("unused")
|
|
|
+class BE_Order_AcceptOrder implements BusinessExecutor<InvokeCallParams, InvokeCallResult> {
|
|
|
+
|
|
|
+ private final Logger logger = LogManager.getLogger(this.getClass().getSimpleName())
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private JsonConvert jsonConvert
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TableIdService tableIdService
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private StoreService storeService
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ESClient esClient
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private SupplierInitService supplierInitService
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private OrderStepService orderStepService
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private OrderService orderService
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private OrderSearchService orderSearchService
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private DouyinService douyinService
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TunaService tunaService
|
|
|
+
|
|
|
+ private OrderDao orderDao
|
|
|
+
|
|
|
+ @Override
|
|
|
+ String scriptName() {
|
|
|
+ return "订单商户接单"
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ ERPModule module() {
|
|
|
+ return ERPModule.ORDER_API
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ RetResult<InvokeCallParams> beforeExecute(InvokeCallParams source) {
|
|
|
+ return super.beforeExecute(source)
|
|
|
+ }
|
|
|
+//params:{idOrder:xxx}
|
|
|
+ RetResult<InvokeCallResult> execute(InvokeCallParams source) {
|
|
|
+ //秒级时间戳,groovy里面不让用system
|
|
|
+ long currentTime = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))
|
|
|
+ String dataSourceId = source.dataSourceId
|
|
|
+ long supplierCode = source.supplierCode
|
|
|
+ ERPTokenUser currentUser = source.currentUser
|
|
|
+
|
|
|
+ def jsonSlurper = new JsonSlurper()
|
|
|
+ def invokeOrder = jsonSlurper.parseText(source.params)
|
|
|
+ long idOrder = invokeOrder["idOrder"] as Long
|
|
|
+ RetResult<BusinessOrder> orderResult = orderSearchService.getBusinessOrder(idOrder, currentUser, dataSourceId, supplierCode, null)
|
|
|
+ if (!orderResult.isSuccess()) return RetResult.<InvokeCallResult> errorT().retinfo(orderResult.retinfo)
|
|
|
+
|
|
|
+ BusinessOrder esOrder = orderResult.result
|
|
|
+ esOrder.setOrderStatus(BusinessOrderStatus.accept.value)
|
|
|
+ BusinessOrder.update(esOrder, currentUser.id)
|
|
|
+
|
|
|
+ StorePlatform storePlatform = storeService.getStorePlatformInfo(esOrder.incomePlatformId, supplierCode)
|
|
|
+ if (storePlatform == null) return RetResult.<InvokeCallResult> errorT().retinfo("订单来源平台未知!")
|
|
|
+
|
|
|
+ OrderStep orderStep = orderStepService.parseOrderStep(esOrder.id, 0, "[" + storePlatform.platformName + "]商家接单完成", storePlatform.platformCode, currentUser)
|
|
|
+
|
|
|
+
|
|
|
+ def callSuccess = ["success": false, "errorMsg": ""]
|
|
|
+ //根据订单来源平台,回调平台的接单接口
|
|
|
+ switch (storePlatform.platformCode) {
|
|
|
+ case "DYLK": {
|
|
|
+ //抖音来客
|
|
|
+ def postBody = {
|
|
|
+ order_id:
|
|
|
+ esOrder.incomePlatformOrderCode
|
|
|
+ }
|
|
|
+ String responseStr = douyinService.postInvoker("/goodlife/v1/trade/buy/merchant_confirm_order/", jsonConvert.convertTo(postBody))
|
|
|
+ def response = jsonSlurper.parseText(responseStr)
|
|
|
+ if (response["data"]["error_code"] as Integer == 0) {
|
|
|
+ callSuccess["success"] = true
|
|
|
+ } else {
|
|
|
+ //todo 抖音侧调用失败,怎么处理?
|
|
|
+ logger.error("[抖音来客]商户接单平台接口调用失败:" + response["data"]["description"] as String)
|
|
|
+ callSuccess["success"] = false
|
|
|
+ callSuccess["errorMsg"] = "[抖音来客]商户接单平台接口调用失败:" + response["data"]["description"] as String
|
|
|
+ }
|
|
|
+
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (callSuccess["success"]) {
|
|
|
+ //持久化
|
|
|
+ //订单主表
|
|
|
+ BulkRequestBuilder bulkRequest = esClient.getClient().prepareBulk().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
|
|
|
+
|
|
|
+ UpdateRequestBuilder orderRequest = esClient.getClient().prepareUpdate(
|
|
|
+ supplierInitService.getDateYearESIndex(supplierCode, ESKeys.ES_DELIVER_BUSINESS_ORDER_INDEX, 0),
|
|
|
+ ESKeys.ES_DELIVER_BUSINESS_ORDER_TYPE,
|
|
|
+ String.valueOf(esOrder.getId()))
|
|
|
+ .setDoc(jsonBuilder()
|
|
|
+ .startObject()
|
|
|
+ .field("orderStatus", esOrder.orderStatus)
|
|
|
+ .field("updateBy", esOrder.getUpdateBy())
|
|
|
+ .field("updateTimeLong", esOrder.getUpdateTimeLong())
|
|
|
+ .endObject())
|
|
|
+ bulkRequest.add(orderRequest)
|
|
|
+ //订单脚印
|
|
|
+ IndexRequestBuilder orderStepRequest = esClient.getClient()
|
|
|
+ .prepareIndex(supplierInitService.getDateYearESIndex(supplierCode, ESKeys.ES_DELIVER_ORDER_STEP_INDEX, 0),
|
|
|
+ ESKeys.ES_DELIVER_ORDER_STEP_TYPE)
|
|
|
+ .setId(String.valueOf(orderStep.id))
|
|
|
+ .setSource(jsonConvert.convertTo(orderStep), XContentType.JSON)
|
|
|
+ bulkRequest.add(orderStepRequest)
|
|
|
+
|
|
|
+
|
|
|
+ BulkResponse bulkResponse = bulkRequest.get();
|
|
|
+ orderDao = tunaService.generate(OrderDao.class)
|
|
|
+ if (bulkResponse.hasFailures()) {
|
|
|
+ logger.error("商户接单出错:" + bulkResponse.buildFailureMessage());
|
|
|
+ return RetResult.<InvokeCallResult> errorT().retinfo("商户接单出错:" + esOrder.orderName);
|
|
|
+ } else {
|
|
|
+ logger.info("商户接单成功");
|
|
|
+ //写数据库
|
|
|
+ orderDao.acceptBusinessOrder(esOrder,
|
|
|
+ [orderStep],
|
|
|
+ dataSourceId,
|
|
|
+ String.valueOf(supplierCode))
|
|
|
+
|
|
|
+
|
|
|
+ return RetResult.<InvokeCallResult> successT().result(InvokeCallResult.success().data(jsonConvert.convertTo(esOrder)))
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return RetResult.<InvokeCallResult> errorT().retinfo("商户接单出错:" + callSuccess["errorMsg"]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|