package cn.freemud.client;

import cn.freemud.entities.dto.*;
import cn.freemud.service.thirdparty.StoreClient;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.List;

/**
 * All rights Reserved, Designed By www.freemud.cn
 *
 * @version V1.0
 * @Title: StoreClientTest
 * @Package cn.freemud.client
 * @Description: 测试
 * @author: zhenghuan.yang
 * @date: 2018/6/25 15:41
 * @Copyright: 2018 www.freemud.cn Inc. All rights reserved.
 * 注意：本内容仅限于上海非码科技内部传阅，禁止外泄以及用于其他的商业目
 */
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
@EnableDiscoveryClient
@EnableFeignClients
@EnableAutoConfiguration
public class StoreClientTest {
    @Autowired
    private StoreClient storeClient;

    /**
     * 查询附近门店
     */
    @Test
    public void findNearStores() {
        NearStoreRequestDto nearStoreRequestDto=new NearStoreRequestDto();
        nearStoreRequestDto.setPartnerId("1832");
        nearStoreRequestDto.setLatitude("31.269248962402344");
        nearStoreRequestDto.setLongitude("121.37284088134766");
        nearStoreRequestDto.setActiveFlag("1");
        nearStoreRequestDto.setTypeFlag("3");
        nearStoreRequestDto.setPageNo(1);
        nearStoreRequestDto.setPlaceOrderFlag("1");
        nearStoreRequestDto.setPageSize(100);
        nearStoreRequestDto.setDistance("100000");
        StoreBaseResponseDto<StoreListResponseDto> response = storeClient.findNearStores(nearStoreRequestDto);
        StoreListResponseDto storeListResponseDto=response.getBizVO();
        List<StoreResponseDto> list=storeListResponseDto.getList();
        log.info("storeId  " + "freeDeliveryPrice   "+"deliveryPrice   " +"delivery" );
        for (StoreResponseDto store:list){
            String insert="INSERT INTO open_platform_partner_store_delivery_config (`partner_id`, `store_id`, `delivery_limit_amount`, `delivery_amount`, `default_delivery_range`, `add_range_count`, `add_range_amount`, `gmt_created`, `gmt_modified`) VALUES ('"+nearStoreRequestDto.getPartnerId()+"', '"+store.getStoreCode()+"','"+store.getFreeDeliveryPrice()*100+"','"+store.getDeliveryPrice()*100+"', '3000', '3000', '250', '2018-12-13 17:08:25', '2018-12-13 18:15:43');";
            System.out.println(insert);
           /* System.out.println(store.getStoreCode()+"   "+store.getFreeDeliveryPrice()+"   "+store.getDeliveryPrice()+"   "+store.getDelivery());*/
        }
    }
    /**
     * 查询单个门店信息
     */
    @Test
    public void getStoreInfo() {
        StoreInfoRequestDto storeInfoRequestDto=new StoreInfoRequestDto();
        storeInfoRequestDto.setPartnerId("360bb48b-5316-458a-903e-9a44c7f339b1");
        storeInfoRequestDto.setStoreCode("");
        StoreBaseResponseDto<StoreResponseDto> storeBaseResponseDto = storeClient.getStoreInfo(storeInfoRequestDto);
        log.info("storeBaseResponseDto==="+storeBaseResponseDto);
    }
    /**
     * 查询门店轮播图
     */
    @Test
    public void findStoreImages() {
        StoreImagesRequestDto toreImagesRequestDto=new StoreImagesRequestDto();
        toreImagesRequestDto.setPartnerId("360bb48b-5316-458a-903e-9a44c7f339b1");
        toreImagesRequestDto.setBusinessId("");
        toreImagesRequestDto.setTypeFlag(1);
        StoreBaseResponseDto<StoreImageListResponseDto> storeBaseResponseDto = storeClient.findStoreImages(toreImagesRequestDto);
        log.info("storeBaseResponseDto==="+storeBaseResponseDto);
    }
}
