package cn.sh.stc.sict.theme.hphy.util;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;

@Slf4j
public class PythonUtil {

    /**
     * 黄埔高血压
     * 调用python程序获取医生list
     *
     * @return
     * @throws UnsupportedEncodingException
     */
    public static String getDcotorMatchListForHP(String params) throws UnsupportedEncodingException {

        log.error("py->syptomoList--->{}", params);
        String url = "http://localhost:9003/hello?aa=" + params;
        String body = HttpRequest.post(url)
                .setEncodeUrlParams(true)
                .execute()
                .body();
        log.error("pyresult -------------> {}", body);
        return body;
    }

    /**
     * 黄埔高血压
     * 调用python程序获取导医逻辑 label list
     *
     * @param params
     * @return
     */
    public static JSONArray getMatchLabel(String params) {

        log.error("getMatchLabel->params--->{}", params);
        String url = "http://localhost:9004/hello?aa=" + params;
        String body = HttpRequest.post(url)
                .setEncodeUrlParams(true)
                .execute()
                .body();
        log.error("getMatchLabel->pyresult-------------> {}", body);
        if(JSONUtil.isJsonObj(body)){
            JSONObject obj = JSONUtil.parseObj(body);
            JSONArray list = obj.getJSONArray("list");
            return list;
        }
        return null;
    }

//    public static void main(String[] args) {
//        try {
//            List<String> disease = new ArrayList<>();
//            disease.add("高血压");
//            disease.add("冠心病");
//            PythonCompareParam param = new PythonCompareParam("10000139", "215|42502884200|42502884231010112B1001", "65", disease);
//            String result = PythonUtil.getMatchLabel(JSONUtil.toJsonStr(param));
//            System.out.println(result);
//        } catch (Exception ex) {
//            log.error(ex.getMessage(), ex);
//        }
//    }
}
