guoshilong
2023-08-04 e8ca684e5efa645a3954d507c0763e8b183bcd61
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package cn.gistack.nky.service.impl;
 
import cn.gistack.common.utils.CommonUtil;
import cn.gistack.nky.resultpojo.HsybGetFuturePo;
import cn.gistack.nky.service.IHsybService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
 
import java.util.List;
import java.util.stream.Collectors;
 
@Service
@AllArgsConstructor
public class HsybServiceImpl implements IHsybService {
 
    private static String GET_FUTURE = "https://sk.hubeishuiyi.cn/hsybApi/api/fh-admin/skkr/getFuture";
 
    private static String AUTHORIZATION = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX25hbWUiOiJBRE1JTiIsIlVzZXJJZCI6IjEiLCJzY29wZSI6WyJhbGwiXSwiVXNlclJlYWxOYW1lIjoi6LaF57qn566h55CG5ZGYIiwiVXNlclh6cWhkbSI6IjQyMDUiLCJleHAiOjI1MTk3NzIwMTAsImp0aSI6ImExNTcxYzk1LTBkNjMtNDkyYi1iOWEyLTE2ZTIzNTQ5ZTY1ZiIsImNsaWVudF9pZCI6InVzZXItc2VydmljZSJ9.ebNVZrw9LbhKaj2w6RR8b2wccQiDkhvBeq79SxxCK-yWiOlIFqBkotTN4TNJg8umcpyYvLILwvqXWRJhffEtgi25sX2y6MqLIWM4kMZ9d8ptdnSmTpBPhltSiQOM0KFa1kl5nSDCBwYOLn-pESJglam76cjpgZNoC88x3iNHacdiXDItY0rtY85HrQ26uyJu9UovKtmYmZRHsIbGMpDta5Q1p4vfaCIr-YUayDrCweZJiQDEEcOSpWJ7O7RMk3pRkX_4UmPHFzrOI2lMp1jQIhxnSTE7EVAz_4z8h8r46muSkpF54Ic4XSawHKqdSLHx8T05LB0MpvOzWMPS6c1uHA";
 
 
    @Override
    public List<List<String>> getFuture(String resCd) {
        HsybGetFuturePo hsybGetFuturePo  = apiRequest(GET_FUTURE, resCd);
 
        if (hsybGetFuturePo != null && hsybGetFuturePo.getRespCode().equals("200")){
            List<List<String>> data = hsybGetFuturePo.getData();
 
            //过滤空值数据,过滤过去时间
            List<List<String>> collect =
                data.stream().filter(item -> item.get(0) != null).filter(item -> CommonUtil.strToDate(item.get(0)).after(DateUtil.now())).collect(Collectors.toList());
            return collect;
        }else {
            return null;
        }
    }
 
    public HsybGetFuturePo apiRequest(String url, String jsonparams){
 
//        Long param = Long.parseLong(jsonparams);
        System.out.println("请求参数:"+ jsonparams);
        // 声明一个header变量
        HttpHeaders headers = new HttpHeaders();
        // 设置为json格式
        MediaType mediaType = MediaType.parseMediaType("application/json;charset=utf-8");
        headers.setContentType(mediaType);
        //设置请求头
        headers.set("Authorization",AUTHORIZATION);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
 
        HttpEntity<String> httpEntity = new HttpEntity(jsonparams, headers);
        RestTemplate template = new RestTemplate();
        try {
            HsybGetFuturePo hsybGetFuturePo = template.postForObject(url, httpEntity, HsybGetFuturePo.class);
            System.out.println(hsybGetFuturePo.toString());
            return hsybGetFuturePo;
        }catch (Exception e){
            System.out.println(e);
        }
 
        return null;
    }
}