|
@@ -1,17 +1,35 @@
|
|
|
|
|
+import com.dderp.business.dao.OrderDao
|
|
|
import com.dderp.common.api.BusinessExecutor
|
|
import com.dderp.common.api.BusinessExecutor
|
|
|
import com.dderp.common.api.StoreService
|
|
import com.dderp.common.api.StoreService
|
|
|
|
|
+import com.dderp.common.api.SupplierInitService
|
|
|
|
|
+import com.dderp.common.api.flycat.OrderStepService
|
|
|
import com.dderp.common.datas.BusinessOrderStatus
|
|
import com.dderp.common.datas.BusinessOrderStatus
|
|
|
import com.dderp.common.datas.ERPModule
|
|
import com.dderp.common.datas.ERPModule
|
|
|
|
|
+import com.dderp.common.datas.ESKeys
|
|
|
|
|
+import com.dderp.common.datas.business.PlatformType
|
|
|
import com.dderp.common.entity.base.ProcessStringItem
|
|
import com.dderp.common.entity.base.ProcessStringItem
|
|
|
|
|
+import com.dderp.common.entity.geo.GeoPoiLocation
|
|
|
import com.dderp.common.entity.order.BusinessOrder
|
|
import com.dderp.common.entity.order.BusinessOrder
|
|
|
import com.dderp.common.entity.order.OrderDeliveryInfo
|
|
import com.dderp.common.entity.order.OrderDeliveryInfo
|
|
|
|
|
+import com.dderp.common.entity.order.OrderDetailItem
|
|
|
import com.dderp.common.entity.order.OrderFinances
|
|
import com.dderp.common.entity.order.OrderFinances
|
|
|
|
|
+import com.dderp.common.entity.order.OrderStep
|
|
|
|
|
+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.TableIdService
|
|
|
|
|
+import com.dySweetFishPlugin.sql.dao.TunaService
|
|
|
import com.sweetfish.convert.json.JsonConvert
|
|
import com.sweetfish.convert.json.JsonConvert
|
|
|
import com.sweetfish.service.RetResult
|
|
import com.sweetfish.service.RetResult
|
|
|
import groovy.json.JsonSlurper
|
|
import groovy.json.JsonSlurper
|
|
|
import org.apache.logging.log4j.LogManager
|
|
import org.apache.logging.log4j.LogManager
|
|
|
import org.apache.logging.log4j.Logger
|
|
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.common.xcontent.XContentType
|
|
|
|
|
|
|
|
import javax.annotation.Resource
|
|
import javax.annotation.Resource
|
|
|
import java.math.RoundingMode
|
|
import java.math.RoundingMode
|
|
@@ -32,6 +50,20 @@ class BE_Order_CreateOrder_Douyin implements BusinessExecutor<ProcessStringItem,
|
|
|
@Resource
|
|
@Resource
|
|
|
private StoreService storeService
|
|
private StoreService storeService
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private ESClient esClient
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private SupplierInitService supplierInitService
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private OrderStepService orderStepService
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private TunaService tunaService
|
|
|
|
|
+
|
|
|
|
|
+ private OrderDao orderDao
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
String scriptName() {
|
|
String scriptName() {
|
|
|
return "抖音来客创建订单"
|
|
return "抖音来客创建订单"
|
|
@@ -42,11 +74,13 @@ class BE_Order_CreateOrder_Douyin implements BusinessExecutor<ProcessStringItem,
|
|
|
return ERPModule.ORDER_API
|
|
return ERPModule.ORDER_API
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
RetResult<BusinessOrder> execute(ProcessStringItem source) {
|
|
RetResult<BusinessOrder> execute(ProcessStringItem source) {
|
|
|
//秒级时间戳,groovy里面不让用system
|
|
//秒级时间戳,groovy里面不让用system
|
|
|
long currentTime = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))
|
|
long currentTime = LocalDateTime.now().toEpochSecond(ZoneOffset.ofHours(8))
|
|
|
String dataSourceId = source.dataSourceId
|
|
String dataSourceId = source.dataSourceId
|
|
|
long supplierCode = source.supplierCode
|
|
long supplierCode = source.supplierCode
|
|
|
|
|
+ ERPTokenUser currentUser = source.currentUser
|
|
|
|
|
|
|
|
def jsonSlurper = new JsonSlurper()
|
|
def jsonSlurper = new JsonSlurper()
|
|
|
def invokeOrder = jsonSlurper.parseText(source.itemValue)
|
|
def invokeOrder = jsonSlurper.parseText(source.itemValue)
|
|
@@ -56,10 +90,10 @@ class BE_Order_CreateOrder_Douyin implements BusinessExecutor<ProcessStringItem,
|
|
|
businessOrder.setOrderName(invokeOrder["merchant"]["account_name"] as String)
|
|
businessOrder.setOrderName(invokeOrder["merchant"]["account_name"] as String)
|
|
|
businessOrder.setOrderCode(tableIdService.getTableCodeMulti("deBusinessOrder.code", dataSourceId, String.valueOf(supplierCode)))
|
|
businessOrder.setOrderCode(tableIdService.getTableCodeMulti("deBusinessOrder.code", dataSourceId, String.valueOf(supplierCode)))
|
|
|
businessOrder.setOrderStatus(BusinessOrderStatus.init.value)
|
|
businessOrder.setOrderStatus(BusinessOrderStatus.init.value)
|
|
|
- //todo 商户平台需求一个绑定逻辑,用以判断该平台适用于哪一个脚本
|
|
|
|
|
-// storeService.getStorePlatformByInvokeInfo(invokeOrder["poi"]["poi_id"] )
|
|
|
|
|
- //businessOrder.setIncomePlatformId(0)
|
|
|
|
|
- //businessOrder.setIncomePlatformName("")
|
|
|
|
|
|
|
+ StorePlatform storePlatform = storeService.getStorePlatformByInvokeInfo(invokeOrder["poi"]["poi_id"] as String,
|
|
|
|
|
+ "DYLK", PlatformType.order.value, supplierCode)
|
|
|
|
|
+ businessOrder.setIncomePlatformId(storePlatform.id)
|
|
|
|
|
+ businessOrder.setIncomePlatformName(storePlatform.platformName)
|
|
|
businessOrder.setIncomePlatformOrderCode(invokeOrder["order"]["order_id"] as String)
|
|
businessOrder.setIncomePlatformOrderCode(invokeOrder["order"]["order_id"] as String)
|
|
|
businessOrder.setIncomePlatformOrderTimeLong(invokeOrder["order"]["pay_time"] as long * 1000)//抖音传过来的时间戳单位是秒
|
|
businessOrder.setIncomePlatformOrderTimeLong(invokeOrder["order"]["pay_time"] as long * 1000)//抖音传过来的时间戳单位是秒
|
|
|
businessOrder.setIncomePlatformOrderTime(new Date(businessOrder.incomePlatformOrderTimeLong))
|
|
businessOrder.setIncomePlatformOrderTime(new Date(businessOrder.incomePlatformOrderTimeLong))
|
|
@@ -67,14 +101,15 @@ class BE_Order_CreateOrder_Douyin implements BusinessExecutor<ProcessStringItem,
|
|
|
long suggestTimeLong = (invokeOrder["order"]["sys_expect_time"] as String).split("-")[0] as long
|
|
long suggestTimeLong = (invokeOrder["order"]["sys_expect_time"] as String).split("-")[0] as long
|
|
|
businessOrder.setSuggestDeliverTimeLong(suggestTimeLong * 1000)
|
|
businessOrder.setSuggestDeliverTimeLong(suggestTimeLong * 1000)
|
|
|
businessOrder.setSuggestDeliverTime(new Date(businessOrder.suggestDeliverTimeLong))
|
|
businessOrder.setSuggestDeliverTime(new Date(businessOrder.suggestDeliverTimeLong))
|
|
|
- //todo 商户id同上
|
|
|
|
|
- //businessOrder.setIdStore(0)
|
|
|
|
|
- //businessOrder.setStoreName("")
|
|
|
|
|
|
|
+ ViewStoreInfo viewStoreInfo = storeService.getViewStoreInfo(storePlatform.idStore, supplierCode, false, false, false);
|
|
|
|
|
+ businessOrder.setIdStore(viewStoreInfo.storeInfo.id)
|
|
|
|
|
+ businessOrder.setStoreName(viewStoreInfo.storeInfo.storeName)
|
|
|
BigDecimal deliverFee = new BigDecimal((invokeOrder["amount_info"]["freight_pay_amount"] as int) / 100).setScale(2, RoundingMode.CEILING)
|
|
BigDecimal deliverFee = new BigDecimal((invokeOrder["amount_info"]["freight_pay_amount"] as int) / 100).setScale(2, RoundingMode.CEILING)
|
|
|
businessOrder.setDeliverFee(deliverFee)
|
|
businessOrder.setDeliverFee(deliverFee)
|
|
|
String address = "[" + invokeOrder["receiver_info"]["city"] + "]" + invokeOrder["receiver_info"]["province"] +
|
|
String address = "[" + invokeOrder["receiver_info"]["city"] + "]" + invokeOrder["receiver_info"]["province"] +
|
|
|
invokeOrder["receiver_info"]["city"] +
|
|
invokeOrder["receiver_info"]["city"] +
|
|
|
invokeOrder["receiver_info"]["district"] +
|
|
invokeOrder["receiver_info"]["district"] +
|
|
|
|
|
+ invokeOrder["receiver_info"]["town"] +
|
|
|
invokeOrder["receiver_info"]["location_address"] +
|
|
invokeOrder["receiver_info"]["location_address"] +
|
|
|
invokeOrder["receiver_info"]["location_name"] + "-" +
|
|
invokeOrder["receiver_info"]["location_name"] + "-" +
|
|
|
invokeOrder["receiver_info"]["receiver_name"]
|
|
invokeOrder["receiver_info"]["receiver_name"]
|
|
@@ -93,8 +128,101 @@ class BE_Order_CreateOrder_Douyin implements BusinessExecutor<ProcessStringItem,
|
|
|
|
|
|
|
|
//订单配送类信息
|
|
//订单配送类信息
|
|
|
OrderDeliveryInfo orderDeliveryInfo = new OrderDeliveryInfo()
|
|
OrderDeliveryInfo orderDeliveryInfo = new OrderDeliveryInfo()
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ orderDeliveryInfo.setId(tableIdService.getTableIdMulti("deOrderDeliveryInfo.id", 1, dataSourceId, String.valueOf(supplierCode)))
|
|
|
|
|
+ orderDeliveryInfo.setIdOrder(businessOrder.id)
|
|
|
|
|
+ orderDeliveryInfo.setDeliverProvince(invokeOrder["receiver_info"]["province"] as String)
|
|
|
|
|
+ orderDeliveryInfo.setDeliverCity(invokeOrder["receiver_info"]["city"] as String)
|
|
|
|
|
+ orderDeliveryInfo.setDeliverDistract(invokeOrder["receiver_info"]["district"] as String)
|
|
|
|
|
+ orderDeliveryInfo.setDeliverAddress(invokeOrder["receiver_info"]["location_address"] as String)
|
|
|
|
|
+ orderDeliveryInfo.setGeoPoiLocation(new GeoPoiLocation(invokeOrder["receiver_info"]["lng"] as double, invokeOrder["receiver_info"]["lat"] as double))
|
|
|
|
|
+ orderDeliveryInfo.setReceiveMan(invokeOrder["receiver_info"]["receiver_name"] as String)
|
|
|
|
|
+ orderDeliveryInfo.setContractPhone(invokeOrder["receiver_info"]["secret_number"] as String + "(" + invokeOrder["receiver_info"]["receiver_phone"] as String + ")")
|
|
|
|
|
+ orderDeliveryInfo.setDeliverTimeliness(invokeOrder["order"]["is_book"] as int - 1) //抖音1表示即时单,2表示预订单
|
|
|
|
|
+ orderDeliveryInfo.setBookingDeliverTimeLong(suggestTimeLong * 1000)
|
|
|
|
|
+ orderDeliveryInfo.setBookingDeliverTime(new Date(orderDeliveryInfo.bookingDeliverTimeLong))
|
|
|
|
|
+ orderDeliveryInfo.setCustomerMemo(invokeOrder["order"]["remark"] as String)
|
|
|
|
|
+
|
|
|
|
|
+ businessOrder.setOrderDeliveryInfo(orderDeliveryInfo)
|
|
|
|
|
+
|
|
|
|
|
+ //订单明细详情
|
|
|
|
|
+ List<OrderDetailItem> itemList = new ArrayList<>()
|
|
|
|
|
+ long itemId = tableIdService.getTableIdMulti("deOrderDetailItem.id", (invokeOrder["products"] as ArrayList).size(),
|
|
|
|
|
+ dataSourceId, String.valueOf(supplierCode))
|
|
|
|
|
+ (invokeOrder["products"] as ArrayList).each {
|
|
|
|
|
+ OrderDetailItem item = new OrderDetailItem()
|
|
|
|
|
+ item.setId(itemId)
|
|
|
|
|
+ item.setIdOrder(businessOrder.id)
|
|
|
|
|
+ item.setItemName(it["product_name"] as String)
|
|
|
|
|
+ item.setItemCount(it["num"] as int)
|
|
|
|
|
+ item.setItemMoney(it["origin_amount"] as BigDecimal)
|
|
|
|
|
+
|
|
|
|
|
+ itemList.add(item)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ businessOrder.setDetailItemList(itemList)
|
|
|
|
|
+
|
|
|
|
|
+ OrderStep orderStep = orderStepService.parseOrderStep(businessOrder.id, 0, "抖音来客顾客完成下单,平台接单完成", "DYLK", currentUser)
|
|
|
|
|
+
|
|
|
|
|
+ //持久化
|
|
|
|
|
+ //订单主表
|
|
|
|
|
+ BulkRequestBuilder bulkRequest = esClient.getClient().prepareBulk().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
|
|
|
|
|
+ IndexRequestBuilder orderRequest = esClient.getClient()
|
|
|
|
|
+ .prepareIndex(supplierInitService.getDateYearESIndex(supplierCode, ESKeys.ES_DELIVER_BUSINESS_ORDER_INDEX, 0),
|
|
|
|
|
+ ESKeys.ES_DELIVER_BUSINESS_ORDER_TYPE)
|
|
|
|
|
+ .setId(String.valueOf(businessOrder.id))
|
|
|
|
|
+ .setSource(jsonConvert.convertTo(businessOrder), XContentType.JSON)
|
|
|
|
|
+ bulkRequest.add(orderRequest)
|
|
|
|
|
+ //订单金额信息
|
|
|
|
|
+ IndexRequestBuilder financesRequest = esClient.getClient()
|
|
|
|
|
+ .prepareIndex(supplierInitService.getDateYearESIndex(supplierCode, ESKeys.ES_DELIVER_BUSINESS_ORDER_INDEX, 0),
|
|
|
|
|
+ ESKeys.ES_DELIVER_ORDER_FINANCES_TYPE)
|
|
|
|
|
+ .setId(String.valueOf(orderFinances.id))
|
|
|
|
|
+ .setParent(String.valueOf(orderFinances.idOrder))
|
|
|
|
|
+ .setSource(jsonConvert.convertTo(orderFinances), XContentType.JSON)
|
|
|
|
|
+ bulkRequest.add(financesRequest)
|
|
|
|
|
+ //订单配送信息
|
|
|
|
|
+ IndexRequestBuilder deliveryRequest = esClient.getClient()
|
|
|
|
|
+ .prepareIndex(supplierInitService.getDateYearESIndex(supplierCode, ESKeys.ES_DELIVER_BUSINESS_ORDER_INDEX, 0),
|
|
|
|
|
+ ESKeys.ES_DELIVER_ORDER_DELIVERY_INFO_TYPE)
|
|
|
|
|
+ .setId(String.valueOf(orderDeliveryInfo.id))
|
|
|
|
|
+ .setParent(String.valueOf(orderDeliveryInfo.idOrder))
|
|
|
|
|
+ .setSource(jsonConvert.convertTo(orderDeliveryInfo), XContentType.JSON)
|
|
|
|
|
+ bulkRequest.add(deliveryRequest)
|
|
|
|
|
+ //订单明细详情
|
|
|
|
|
+ itemList.each {
|
|
|
|
|
+ IndexRequestBuilder itemRequest = esClient.getClient()
|
|
|
|
|
+ .prepareIndex(supplierInitService.getDateYearESIndex(supplierCode, ESKeys.ES_DELIVER_BUSINESS_ORDER_INDEX, 0),
|
|
|
|
|
+ ESKeys.ES_DELIVER_ORDER_DETAIL_ITEM_TYPE)
|
|
|
|
|
+ .setId(String.valueOf(it.id))
|
|
|
|
|
+ .setParent(String.valueOf(it.idOrder))
|
|
|
|
|
+ .setSource(jsonConvert.convertTo(it), XContentType.JSON)
|
|
|
|
|
+ bulkRequest.add(itemRequest)
|
|
|
|
|
+ }
|
|
|
|
|
+ //订单脚印
|
|
|
|
|
+ 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.<BusinessOrder> errorT().retinfo("新建订单出错[抖音来客]:" + businessOrder.orderName);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ logger.info("新建订单成功[抖音来客]");
|
|
|
|
|
+ //写数据库
|
|
|
|
|
+ orderDao.addBusinessOrder(businessOrder,
|
|
|
|
|
+ businessOrder.orderFinances,
|
|
|
|
|
+ businessOrder.orderDeliveryInfo,
|
|
|
|
|
+ businessOrder.detailItemList,
|
|
|
|
|
+ [orderStep],
|
|
|
|
|
+ dataSourceId,
|
|
|
|
|
+ String.valueOf(supplierCode))
|
|
|
|
|
+ return RetResult.<BusinessOrder> successT().result(businessOrder)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|