package custom.AIO.businessLarge; import cn.hutool.http.HttpRequest; import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.fr.data.SimpleTableData; import com.fr.stable.ParameterProvider; import java.util.ArrayList; import java.util.List; /** * @author thh * @date 2023/6/29 */ public class SimpleParamTableDataInitColumn extends SimpleTableData { public static void main(String[] args) { SimpleParamTableDataInitColumn simpleParamTableData = new SimpleParamTableDataInitColumn(); List<Object[]> objects = simpleParamTableData.loadData(); System.out.println("1111"); } @Override public String[] initColumnNames() { String[] columnNames = {"index_code","index_name"}; return columnNames; } @Override public List<Object[]> loadData() { // 取到报表传的参数 Object[] params = parameters.get().toArray(); //取到第一条参数 String paramJson = ((ParameterProvider) params[0]).getValue().toString(); JSONObject paramObj = JSONUtil.parseObj(paramJson); //取出数组中的查询条件列 JSONArray paramsList = JSONUtil.parseArray(paramObj.getStr("paramsList")); //取出第一条json数据的url String url = paramObj.getStr("url"); //返回的结果集 List<Object[]> valueList = new ArrayList(); //调用接口需要传的参数 JSONObject json=new JSONObject(); //执行接口调用 String result = HttpRequest.post(url) .timeout(50000)//超时,毫秒 .body(JSONUtil.toJsonStr(json)) .execute().body(); //将接口返回的字符串json参数解析转换位bean格式 ResultDate resultJson = JSONUtil.toBean(result, ResultDate.class); //如果接口调用成功 if(resultJson.getCode().equals("200")){ //将解析好的resultJson中的fields取出来 List<Object[]> fields = resultJson.getData().get("fields"); //将字段英文名和字段中文名,存到objects数组中,将每条objects数组放到List返回 for(int i = 0;i<fields.get(0).length;i++){ Object[] objects = new Object[2]; objects[0] = fields.get(0)[i]; objects[1] = fields.get(1)[i]; valueList.add(objects); } //valueList = resultJson.getData().get("fields"); } return valueList; } } |