package com.qs.mp.api;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.junit.jupiter.api.Test;

import com.alibaba.fastjson.JSON;
import com.qs.mp.common.BaseControllerTest;

/**
 * @auther duota
 * @create 2021 2021/9/7 6:36 下午
 * @describe
 */
public class ChannelControllerTest extends BaseControllerTest {

	/**
	 * 获取我的下级渠道列表信息，支持翻页
	 * 调用场景：渠道端查询子渠道列表
	 */
	@Test
	public void testGetSubChannelList() {
		Map<String, Object> map = new HashMap<String, Object>();
		int pageNum = 1;
		int pageSize = 10;
		map.put("pageNum", pageNum);
		map.put("pageSize", pageSize);
		String params = JSON.toJSONString(map);
		System.out.println("params = " + params);
		String url = "http://localhost:8080/api/v1/mp/channel/subchannel/list?";
		System.out.println(request(url, params));
	}

	/**
	 * 获取我的下级渠道详情信息
	 * 调用场景：渠道端查询子渠道详情
	 */
	@Test
	public void testGetChannelDetail() {
		String channelId = "4";
		String params = "{\"channelId\":\"" + channelId + "\"}";
		String url = "http://localhost:8080/api/v1/mp/channel/subchannel/detail?";
		System.out.println(request(url, params));
	}

	/**
	 * 渠道端新增子渠道
	 * 调用场景：渠道端新增子渠道
	 */
	@Test
	public void testSubChannelAdd() {
		String mobile = "15112682431";
		String name = "西湖渠道";
		Long provinceId = 330000000000L;
		String province = "浙江省";
		Long cityId = 330100000000L;
		String city = "杭州市";
		Long areaId = 330106000000L;
		String area = "西湖区";
		BigDecimal commRate = new BigDecimal(10);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("mobile", mobile);
		map.put("name", name);
		map.put("provinceId", provinceId);
		map.put("province", province);
		map.put("cityId", cityId);
		map.put("city", city);
		map.put("areaId", areaId);
		map.put("area", area);
		map.put("commRate", commRate);
		String params = JSON.toJSONString(map);
		System.out.println("params = " + params);
		String url = "http://localhost:8080/api/v1/mp/channel/subchannel/create?";
		System.out.println(request(url, params));
	}

	/**
	 * 渠道端编辑子渠道信息
	 * 调用场景：渠道端编辑子渠道信息
	 */
	@Test
	public void testSubChannelEdit() {
		Long channelId = 2L;
		String mobile = "15112682435";
		String name = "西湖渠道";
		Long provinceId = 330000000000L;
		String province = "浙江省";
		Long cityId = 330100000000L;
		String city = "杭州市";
		Long areaId = 330106000000L;
		String area = "西湖区";
		BigDecimal commRate = new BigDecimal(10);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("channelId", channelId);
		map.put("mobile", mobile);
		map.put("name", name);
		map.put("provinceId", provinceId);
		map.put("province", province);
		map.put("cityId", cityId);
		map.put("city", city);
		map.put("areaId", areaId);
		map.put("area", area);
		map.put("commRate", commRate);
		String params = JSON.toJSONString(map);
		System.out.println("params = " + params);
		String url = "http://localhost:8080/api/v1/mp/channel/subchannel/update?";
		System.out.println(request(url, params));
	}
	
	
	/**
	 * 获取当前用户渠道或者某个子渠道的经营数据
	 * 调用场景：渠道端首页查询当前渠道经营数据、子渠道详情页面查询经营数据
	 */
	@Test
	public void testGetSubChannelOperData() {
		Long channelId = 1L;
		int days =1;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("channelId", channelId);
		map.put("days", days);
		String params = JSON.toJSONString(map);
		System.out.println("params = " + params);
		String url = "http://localhost:8080/api/v1/mp/channel/subchannel/operdata/query?";
		System.out.println(request(url, params));
	}
	
	/**
	 * 获取子渠道的经营数据列表
	 * 调用场景：渠道端首页子渠道经营数据列表
	 */
	@Test
	public void testGetSubChannelOperDataList() {
		int days =1;
		int pageNum = 1;
		int pageSize = 10;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("days", days);
		map.put("pageNum", pageNum);
		map.put("pageSize", pageSize);
		String params = JSON.toJSONString(map);
		System.out.println("params = " + params);
		String url = "http://localhost:8080/api/v1/mp/channel/subchannel/operdata/list?";
		System.out.println(request(url, params));
	}
	
	
	/**
	 * 获取我的经销商列表信息，支持翻页
	 * 调用场景：渠道端查询经销商列表
	 */
	@Test
	public void testGetSiteList() {
		Map<String, Object> map = new HashMap<String, Object>();
		int pageNum = 1;
		int pageSize = 10;
		String certifyStatus = "y";
		String verifyStatus = "wait";
		map.put("pageNum", pageNum);
		map.put("pageSize", pageSize);
		map.put("certifyStatus", certifyStatus);
		map.put("verifyStatus", verifyStatus);
		String params = JSON.toJSONString(map);
		System.out.println("params = " + params);
		String url = "http://localhost:8080/api/v1/mp/channel/site/list?";
		System.out.println(request(url, params));
	}

	/**
	 * 获取我的经销商详情信息
	 * 调用场景：渠道端查询经销商详情
	 */
	@Test
	public void testGetSiteDetail() {
		String channelId = "1";
		String params = "{\"channelId\":\"" + channelId + "\"}";
		String url = "http://localhost:8080/api/v1/mp/channel/site/detail?";
		System.out.println(request(url, params));
	}

	/**
	 * 新增经销商信息
	 * 调用场景：渠道端新增经销商
	 */
	@Test
	public void testSiteAdd() {
		String mobile = "15112682436";
		String name = "西湖第一经销商";
		String contact = "张三";
		Long provinceId = 330000000000L;
		String province = "浙江省";
		Long cityId = 330100000000L;
		String city = "杭州市";
		Long areaId = 330106000000L;
		String area = "西湖区";
		String address = "趵突泉往前100米";
		BigDecimal commRate = new BigDecimal(10);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("mobile", mobile);
		map.put("name", name);
		map.put("contact", contact);
		map.put("provinceId", provinceId);
		map.put("province", province);
		map.put("cityId", cityId);
		map.put("city", city);
		map.put("areaId", areaId);
		map.put("area", area);
		map.put("address", address);
		map.put("commRate", commRate);
		String params = JSON.toJSONString(map);
		System.out.println("params = " + params);
		String url = "http://localhost:8080/api/v1/mp/channel/site/create?";
		System.out.println(request(url, params));
	}

	/**
	 * 渠编辑经销商信息
	 * 调用场景：渠道端编辑经销商信息
	 */
	@Test
	public void testSiteEdit() {
		Long channelId = 2L;
		String mobile = "15112682436";
		String name = "西湖第一经销商";
		String contact = "张三";
		Long provinceId = 330000000000L;
		String province = "浙江省";
		Long cityId = 330100000000L;
		String city = "杭州市";
		Long areaId = 330106000000L;
		String area = "西湖区";
		String address = "趵突泉往前100米";
		BigDecimal commRate = new BigDecimal(10);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("channelId", channelId);
		map.put("mobile", mobile);
		map.put("contact", contact);
		map.put("provinceId", provinceId);
		map.put("province", province);
		map.put("cityId", cityId);
		map.put("city", city);
		map.put("areaId", areaId);
		map.put("area", area);
		map.put("address", address);
		map.put("commRate", commRate);
		String params = JSON.toJSONString(map);
		System.out.println("params = " + params);
		String url = "http://localhost:8080/api/v1/mp/channel/site/update?";
		System.out.println(request(url, params));
	}
	
	
	/**
	 * 经销商认证审核
	 * 调用场景：渠道端审核经销商认证
	 */
	@Test
	public void testSiteVerify() {
		Long channelId = 2L;
		String verifyStatus = "accept";
		String memo = "备注，拒绝时必填";
		BigDecimal commRate = new BigDecimal(10);  // 分润比例，通过时必填
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("channelId", channelId);
		map.put("verifyStatus", verifyStatus);
		map.put("memo", memo);
		map.put("commRate", commRate);
		String params = JSON.toJSONString(map);
		System.out.println("params = " + params);
		String url = "http://localhost:8080/api/v1/mp/channel/site/verify?";
		System.out.println(request(url, params));
	}
	
	
	/**
	 * 提交认证
	 * 调用场景：经销商认证页面点提交
	 */
	@Test
	public void testSiteVerifySubmit() {
		Long channelId = 2L;
		String contact = "张三";
		String siteType = "1";
		Long provinceId = 330000000000L;
		String province = "浙江省";
		Long cityId = 330100000000L;
		String city = "杭州市";
		Long areaId = 330106000000L;
		String area = "西湖区";
		String address = "趵突泉往前100米";
		String bizLicensePic = "111.png";  // 营业执照，多张图用逗号隔开
		String doorPic = "222.png";// 门店照片，多张图用逗号隔开
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("channelId", channelId);
		map.put("contact", contact);
		map.put("siteType", siteType);
		map.put("provinceId", provinceId);
		map.put("province", province);
		map.put("cityId", cityId);
		map.put("city", city);
		map.put("areaId", areaId);
		map.put("area", area);
		map.put("address", address);
		map.put("bizLicensePic", bizLicensePic);
		map.put("doorPic", doorPic);
		String params = JSON.toJSONString(map);
		System.out.println("params = " + params);
		String url = "http://localhost:8080/api/v1/mp/channel/site/verify/submit?";
		System.out.println(request(url, params));
	}
	
	
	/**
	 * 我的（渠道）
	 * 调用场景：渠道端点击我的
	 */
	@Test
	public void testGetChannelMineDetail() {
		String params = "{}";
		String url = "http://localhost:8080/api/v1/mp/channel/mine/detail?";
		System.out.println(request(url, params));
	}
	
	
	/**
	 * 我的（经销商）
	 * 调用场景：经销商端点击我的
	 */
	@Test
	public void testGetSiteMineDetail() {
		String params = "{}";
		String url = "http://localhost:8080/api/v1/mp/channel/site/mine/detail?";
		System.out.println(request(url, params));
	}

}
