package common;

import com.alibaba.fastjson.JSONObject;
import com.hai.ScheduleApplication;
import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.RedisUtil;
import com.hai.config.HuiLianTongConfig;
import com.hai.service.HighDiscountAgentCodeService;
import com.hai.service.HighDiscountUserRelService;
import com.hai.service.HighUserService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName RegionTest
 * @Description: TODO ()
 * @Author 胡锐
 * @Date 2020/12/29
 **/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = ScheduleApplication.class)
@WebAppConfiguration
public class test {

    @Resource
    private HighUserService highUserService;

    @Resource
    private HighDiscountUserRelService highDiscountUserRelService;

    @Resource
    private HighDiscountAgentCodeService highDiscountAgentCodeService;

    @Resource
    private RedisUtil redisUtil;

    @Resource
    private HuiLianTongConfig huiLianTongConfig;

    @Test
    public void test(){
        try {
            huiLianTongConfig.getToken();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void main(String[] args) {

        requestOrder();
    }

    public static void requestOrder(){

        Map<String, Object> heard = new HashMap<>();
        heard.put("Cookie", "_ida=oArhO6XxKSvjI9wLP3cTK-iSG8yY");


        Map<String, Object> map = new HashMap<>();;
        map.put("goodsId", "23423529");
        map.put("goodsType", "1");
        map.put("saleCount", "1");

        List<Map<String, Object>> orderList = new ArrayList<>();
        orderList.add(map);

        Map<String, Object> param = new HashMap<>();
        param.put("highChildOrderList", orderList);

        int success = 0 ;
        int fail = 0;

        JSONObject object = HttpsUtils.doPost("https://hsgcs.dctpay.com/crest/highOrder/addOrder", param, heard);
        if (object.getString("return_code").equals("000000")) {
            success++;
            System.out.println("提交订单成功");
        } else {
            fail++;
            System.out.println(object.getString("return_msg"));
        }

        System.out.println("成功数量" + success);
        System.out.println("失败数量" + fail);

    }

}
