package cn.freemud.service.impl

import cn.freemud.adapter.OrderAdapter
import cn.freemud.entities.bo.CreateOrderBONew
import cn.freemud.entities.dto.shoppingCart.ShoppingCartGoodsDto
import cn.freemud.entities.dto.store.StoreMixResponseDto
import cn.freemud.entities.vo.CreateOrderVo
import cn.freemud.service.business.impl.OrderBusinessServiceImpl
import com.alibaba.fastjson.JSON
import com.freemud.api.assortment.datamanager.entity.vo.AssortmentCustomerInfoVo
import com.freemud.application.sdk.api.ordercenter.request.OrderExtInfoDto
import com.freemud.sdk.api.assortment.order.adapter.OrderSdkAdapter
import spock.lang.Specification

/**
 * @author : xh.Z
 * @email : fisherman0510@163.com
 * @Date : 2022/2/23 17:17
 * @description : 
 */
class OrderAdapterServiceImplTest extends Specification {

    def orderServiceImpl = new OrderServiceImpl()

    def orderAdapter = new OrderAdapter(mcCafePartnerId: ["9999"], cocoPartnerId: ["9999"])

    def itemService = Mock(ItemServiceImpl.class)

    def orderBusinessService = new OrderBusinessServiceImpl()

    def orderSdkAdapter = new OrderSdkAdapter()

    void setup() {
        orderServiceImpl.orderAdapter = orderAdapter
        orderServiceImpl.itemService = itemService
        orderBusinessService.orderSdkAdapter = orderSdkAdapter
        orderServiceImpl.orderBusinessService = orderBusinessService

    }

    def "测试华莱士订单问题"() {
        given: "参数设置"
        def createOrderBO = new CreateOrderBONew()
        // 接口请求信息
        String createVOStr = "{\"buyType\":0,\"channel\":\"1\",\"channelType\":\"saas\",\"couponCode\":\"\",\"couponCodes\":[],\"expectTime\":\"\",\"latitude\":\"29.984989691840276\",\"longitude\":\"120.57954399956597\",\"menuType\":\"saas\",\"mobile\":\"17681529088\",\"orderRemark\":\"\",\"orderType\":1,\"partnerId\":\"2209\",\"payChannelType\":1,\"reachStoreType\":4,\"sessionId\":\"e7a870f14f237d181b464e8a4a46d6b72e3d4a53\",\"sessionKey\":\"jTe2egiG9AWlk8SpixS+AA==\",\"shopId\":\"810428538\",\"storeAddress\":\"浙江省绍兴市越城区塔山街道解放南路777号金帝银泰城1幢4F002-1号\",\"storeName\":\"如创于茶（绍兴银泰店）\",\"storeNameEn\":\"\",\"tableNumber\":\"\",\"takeMealFlag\":\"0\",\"takeMealTime\":\"\",\"thirdShopId\":\"810428538\",\"useCustomerScore\":2,\"userId\":\"3645274120780529080\",\"userName\":\"\",\"version\":\"2.0.62.1\"}";
        def createOrderVo = JSON.parseObject(createVOStr, CreateOrderVo.class)
        createOrderBO.setCreateOrderVo(createOrderVo)
        // 登录信息
        def userLoginInfoDto = JSON.parseObject("{\"accessToken\":\"\",\"alipayUserId\":\"\",\"appId\":\"wx3f7ca0c75b213380\",\"appSecret\":\"\",\"appsecret\":\"\",\"channel\":\"1\",\"customerId\":\"\",\"devBrand\":\"\",\"devModel\":\"\",\"iappId\":\"7\",\"memberId\":\"3614319825989629832\",\"mobile\":\"17327190802\",\"newMember\":false,\"nickName\":\"SWEET SUGA\",\"openId\":\"o98fP4qjUo7xm-nT-JAaVEk9yBqM\",\"openid\":\"o98fP4qjUo7xm-nT-JAaVEk9yBqM\",\"partnerId\":\"2581\",\"photoUrl\":\"https://thirdwx.qlogo.cn/mmopen/vi_32/zahIlicTNSM0IA0qjOryv6s0SzIhlwW9EpQKvL63GbPhBwficMAibDohDEibSCQU0I5KohibIpp0yL57TWRcVKrRH2A/132\",\"registerTime\":\"2021-02-26 14:10:26\",\"sessionId\":\"cef46527f632a961af7a84209bdb8fcd0997c936\",\"sessionKey\":\"hZtQ1Usx/NhEUyoyduF+FQ==\",\"session_key\":\"hZtQ1Usx/NhEUyoyduF+FQ==\",\"storeId\":\"\",\"tableNumber\":\"\",\"thirdPartyMemberID\":\"\",\"thirdPartyPartnerID\":\"\",\"unionId\":\"o7cEm68JPFhbrzqb0a0BcQE-dDVA\",\"wxAppId\":\"wx3f7ca0c75b213380\",\"wxAppid\":\"wx3f7ca0c75b213380\"}"
                , AssortmentCustomerInfoVo.class)
        createOrderBO.setUserLoginInfoDto(userLoginInfoDto)
        //  购物车信息
        def shoppingCartGoodsDto = JSON.parseObject("{\"activityDiscountsDtos\":[],\"isDiscountDelivery\":false,\"originalTotalAmount\":1600,\"packageAmount\":0,\"packageAmountCollectType\":1,\"products\":[{\"activityDiscountsDtos\":[],\"cartGoodsUid\":\"22a31cf2-2589-4430-9853-589a0ab86007\",\"classificationId\":\"\",\"classificationName\":\"\",\"comboProducts\":[],\"customerCode\":\"SKU0316\",\"extraList\":[{\"attributeId\":\"208146925075177758\",\"attributeName\":\"少冰\"},{\"attributeId\":\"208146664688556827\",\"attributeName\":\"三分糖\"}],\"hasProductCoupon\":false,\"isB3S1Coupon\":0,\"isB3S1CouponGoods\":0,\"isMonthCard\":0,\"isSendGoods\":false,\"isTableware\":0,\"linkedId\":\"\",\"materialList\":[],\"originalPrice\":1600,\"originalProductType\":1,\"picture\":\"https://picture.sandload.cn/1621303466545.jpg\",\"productCode\":\"SKU0316\",\"qty\":1,\"skuForeignName\":\"\",\"skuId\":\"208142777442212610\",\"skuName\":\"蛋糕布蕾奶茶\",\"specialExtra\":[],\"spuForeignName\":\"\",\"spuId\":\"208142777442212610\",\"spuName\":\"蛋糕布蕾奶茶\",\"stockLimit\":false,\"tax\":0.01,\"taxId\":\"\",\"totalDiscountAmount\":0,\"unit\":\"\",\"weight\":0.0}],\"reduceScore\":0,\"scoreReduceAmount\":0,\"totalAmount\":1600,\"totalDiscountAmount\":0}"
                , ShoppingCartGoodsDto.class)
        createOrderBO.setShoppingCartGoodsDto(shoppingCartGoodsDto)

        //拓展信息
        def extInfo = new OrderExtInfoDto()
        createOrderBO.setExtInfo(extInfo)

        // 门店信息  /api/v2/organization/getStoreMix
        def storeMixResponseDto = JSON.parseObject("{\"businessInfo\":{\"appointAutoDeliveryTakeOrderWorkflowFinishTime\":3,\"appointAutoSelfmentionMakerWorkflowFinishTime\":3,\"appointAutoSelfmentionTakeOrderWorkflowFinishTime\":3,\"appointAutoTakeOutTakeOrderWorkflowFinishTime\":4,\"appointThirdDeliveryPickCompleteWorkflowFinishTime\":5,\"appointThirdDeliveryTakeOrderWorkflowFinishTime\":6,\"autoChargebackOrderTime\":1,\"autoChargebackOrderType\":1,\"autoDeliveryTakeOrderWorkflowFinishTime\":3,\"autoSelfmentionMakerWorkflowFinishTime\":4,\"autoSelfmentionTakeOrderWorkflowFinishTime\":3,\"autoTakeOutTakeOrderWorkflowFinishTime\":3,\"autoThirdDeliveryPickCompleteWorkflowFinishTime\":5,\"autoThirdDeliveryTakeOrderWorkflowFinishTime\":6,\"automaticRefund\":0,\"deliveryAppoint\":0,\"deliveryFinishedAfterMinute\":45,\"deliveryHours\":\"\",\"deliveryOrderWarnTime\":\"1\",\"deliveryProcessingAfterMinute\":15,\"deliveryProcessingBeforeMinute\":45,\"expandFields\":{\"appendMinutePerKilometer\":0,\"likesConfigValue\":0,\"likesShow\":0,\"monthlySalesConfigValue\":0,\"monthlySalesShow\":0,\"peakTimeDelivery\":[],\"preOrderSwitch\":0,\"scanOrderSwitch\":0},\"expectedTime\":0,\"goodsAvgTimeOfMaking\":0,\"id\":189248192683154460,\"invoice\":0,\"invoiceExplain\":\"\",\"isAutoTakeOrder\":3,\"maxOrderQuantity\":100,\"minPriceForInvoice\":0,\"orderPrintConfig\":\"1\",\"orderProgressBarStatus\":2,\"orderType\":\"pickup\",\"orderWarnTime\":\"1\",\"overTimeCloseOrder\":1,\"overTimeCloseOrderTime\":30,\"partnerId\":\"2209\",\"pickupAutomaticOrderTime\":1,\"selfMentionSwitch\":0,\"tableware\":0,\"takePartInSettleAccounts\":2,\"takeoutAutomaticOrderTime\":1,\"templateName\":\"30分钟\",\"templateType\":1,\"timeOfRefund\":\"48\",\"timeTypeOfRefund\":2,\"turnOnTimeOfMaking\":2},\"storeBusyTimeInfoList\":[],\"storeImageList\":[],\"storeInfo\":{\"activeFlag\":1,\"address\":\"浙江省绍兴市越城区塔山街道解放南路777号金帝银泰城1幢4F002-1号\",\"briefName\":\"\",\"businessHours\":\"10:00-22:00\",\"businessHoursDay\":\"10:00-22:00\",\"businessType\":\"1\",\"city\":\"绍兴市\",\"delivery\":2,\"deliveryHours\":\"\",\"deliveryHoursDay\":\"\",\"deliveryPrice\":0.0,\"distributionScope\":\"\",\"freeDeliveryPrice\":0.0,\"isSelfMention\":1,\"latitude\":\"29.985151\",\"logoUrl\":\"\",\"longitude\":\"120.58086\",\"parentCode\":\"szcdcyglyxgsC4\",\"parentId\":\"fad5b35d-5671-4ae6-93d4-484a50a5cda7\",\"parentName\":\"苏州茶朵餐饮管理有限公司\",\"partnerId\":\"2209\",\"phone\":\"18258503233\",\"province\":\"浙江省\",\"region\":\"越城区\",\"remark\":\"\",\"state\":\"1\",\"storeCode\":\"810428538\",\"storeId\":\"92409098-8f9d-4e4d-90b4-d48315cf4083\",\"storeName\":\"如创于茶（绍兴银泰店）\",\"storeNameEn\":\"\",\"thirdPartCode\":\"810428538\"}}"
                , StoreMixResponseDto.class)
        createOrderBO.setStoreMixResponseDto(storeMixResponseDto)

        when: "调用方法"
        def order = orderServiceImpl.sdkCreateOrder(createOrderBO)

        then: "验证"

    }

}
