package com.santos.iost;


import com.alibaba.fastjson.JSON;

import com.alibaba.fastjson.parser.Feature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.santos.iost.dao.SoSsDao;
import com.santos.iost.dto.SoSsRequestData;
import com.santos.iost.dto.SoSsResponseDate;
import com.santos.iost.utils.*;
import com.santos.iost.vo.SoSsRequestVo;

import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;

import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.*;
import org.apache.http.util.TextUtils;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.io.IOException;
import java.net.URI;
import java.text.SimpleDateFormat;
import java.util.*;

//
//@SpringBootTest
//@Slf4j
//@RunWith(SpringJUnit4ClassRunner.class)
@EnableScheduling
class JintaiDomeApplicationTests {
    String getTokenUrl = "http://123.58.109.39:86/K3API/Token/Create?authorityCode=606d25b51be50949e768241934225bc05bfd6db0bae63e82";
    String getGetMaterialUrl = "http://123.58.109.39:86/K3API/Material/GetList?token=";
    String includeDetailUrl = "http://123.58.109.39:86/K3API/SO/GetDetail?token=";
    String token;
    @Autowired
    SoSsDao soSsDao;

    @Test
    void contextLoads() throws Exception {
//        String s = HttpUtil.get(getTokenUrl);
//        Map map = JSON.parseObject(s, Map.class);
//        String D = map.get("Data").toString();
//        Map mapDate = JSON.parseObject(D, Map.class);
//        token = mapDate.get("Token").toString();
////        System.out.println(token);
//        Map paramsMap = new HashMap();
//        Map Data = new LinkedHashMap();
//        Data.put("Top", "100");
//        Data.put("PageSize", "17");
//        Data.put("PageIndex", "1");
////        Data.put("Filter","FNumber like '%003%' ");
//        Data.put("OrderBy", "FNumber asc");
//        Data.put("Fields", "FNumber,FName,F_101,FUnitID,FSalePrice");
//        paramsMap.put("Data", Data);
//
//        Map<String, String> hreader = new HashMap<>();
//        hreader.put("Content-Type", "application/json");
//        String post = HttpClientUtil.doPostJson(getGetMaterialUrl + token,JsonUtil.Mapjson(paramsMap));
//        String post = HttpUtil.post(getGetMaterialUrl + token, JsonUtil.Mapjson(paramsMap), hreader);
//        System.out.println(post);
    }

    @Test
    void dsads() throws Exception {
//
//        String s = HttpUtil.get(getTokenUrl);
//        Map map = JSON.parseObject(s, Map.class);
//        String D = map.get("Data").toString();
//        Map mapDate = JSON.parseObject(D, Map.class);
//        token = mapDate.get("Token").toString();
////        System.out.println(token);
//        Map paramsMap = new HashMap();
//        Map Data = new LinkedHashMap();
//        Data.put("FBillNo", "1220200102001");
//        paramsMap.put("Data", Data);
//
//        Map<String, String> hreader = new HashMap<>();
//        hreader.put("Content-Type", "application/json");
////        System.out.println(JsonUtil.Mapjson(paramsMap));
//        String post = HttpUtil.post(includeDetailUrl + token, JsonUtil.Mapjson(paramsMap), hreader);
////        SoSsResponseDate soSsResponseDate = JSON.parseObject(post, SoSsResponseDate.class, Feature.OrderedField);//转换数据类型
////        System.out.println(soSsResponseDate);
//        SoSsResponseDate soSsResponseDate = JSON.parseObject(post, SoSsResponseDate.class, Feature.OrderedField);//转换数据类型
//        String statusCode = soSsResponseDate.getStatusCode();
////        System.out.println(soSsResponseDate.getStatusCode().equals("200"));
////        System.out.println(soSsResponseDate);
//        if (null != soSsResponseDate.getStatusCode() && soSsResponseDate.getStatusCode().equals("200")) {
//            Map Datas = JSON.parseObject(soSsResponseDate.getData().toString(), Map.class, Feature.OrderedField);//转换数据类型
//            List list = JSON.parseObject(Datas.get("Page2").toString(), List.class, Feature.OrderedField);
//            int i = 1;
//            for (Object o : list) {
//                Map listDateMap = JSON.parseObject(o.toString(), Map.class, Feature.OrderedField);
////                System.out.println(listDateMap);
////                returnDate.put(apiName + i, new ArrayList<Map>() {{
////                    add(listDateMap);
////                }});
//                i++;
//            }
//        }
    }

    @Test
    void asd() throws Exception {
        long i = Long.parseLong("1640966400000");
//        float v = Float.parseFloat("f");


        System.out.println(i);
//        System.out.println(TimeStamp2Date("1641398499000", "yyyy-MM-dd HH:mm:ss"));
//        System.out.println(TimeStamp2Date("1609999999000", "yyyy-MM-dd HH:mm:ss"));
//        System.out.println(""+new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date (1641398400000L)));
    }

    public static String TimeStamp2Date(String timestampString, String formats) {
//        System.out.println(TimeStamp2Date("1609499999", "yyyy-MM-dd HH:mm:ss"));
//        System.out.println(TimeStamp2Date("1609999999", "yyyy-MM-dd HH:mm:ss"));
        if (TextUtils.isEmpty(formats))
            formats = "yyyy-MM-dd HH:mm:ss";
        Long timestamp = Long.parseLong(timestampString);
        String date = new SimpleDateFormat(formats, Locale.CHINA).format(new Date(timestamp));
        return date;
    }
    @Test
    public void testTimestamp(){
        Date time = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(time);
        calendar.add(Calendar.HOUR,-1);
        Date startTime = calendar.getTime();
        calendar.add(Calendar.HOUR,2);
        Date endTime = calendar.getTime();
        System.out.println(time);
        System.out.println(startTime);
        System.out.println(endTime);

        long timestamp = 1640966400000l;
        long startTimestamp = startTime.getTime();
        long endTimestamp = endTime.getTime();

        System.out.println(timestamp);
        System.out.println(startTimestamp);
        System.out.println(endTimestamp);
        System.out.println(timestamp>startTimestamp);
        System.out.println(timestamp>endTimestamp);

    }

}


