package com.inspect.bigmodel.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.inspect.base.core.utils.HttpClientUtils;
import com.inspect.bigmodel.service.IBigModelResultService;
import com.inspect.task.service.IPatrolTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BigModelResultServiceImpl implements IBigModelResultService {
    private final Logger log = LoggerFactory.getLogger(BigModelResultServiceImpl.class);
    @Autowired
    private IPatrolTaskService patrolTaskService;

    @Override
    public JSONObject getBigModelResult() {
        String analyseFilter = patrolTaskService.selectConfigByKey("ANALYSE_FILTER_URL");
        log.info("-----调用大模型结果接口地址，url:{}", analyseFilter + "/bigModel/record/latest");
        String resultStr = null;
        try {
            resultStr = HttpClientUtils.get(analyseFilter + "/bigModel/record/latest", "");
        } catch (Exception e) {
            log.error("调用大模型结果接口，返回数据异常，exception:{}", e.getMessage());
        }
        log.error("调用大模型结果接口，返回数据，resultStr:{}", resultStr);
        JSONObject result = JSONObject.parseObject(resultStr);
        if (result != null && "200".equals(result.getString("code"))) {
            return result.getJSONObject("data");
        } else {
            log.error("调用大模型结果接口，返回数据，resultStr:{}", resultStr);
            return result;
        }
    }
}
