73 lines
2.8 KiB
Java
73 lines
2.8 KiB
Java
package com.zhgd.xmgl.util;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.http.HttpUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @author 陶然同学
|
|
* @version 1.0
|
|
* @date 2022/10/15 10:41
|
|
*/
|
|
public class QQUtil {
|
|
private QQUtil() {
|
|
}
|
|
|
|
public static List<String> getCity(Integer adCode, Integer limit) {
|
|
//1 发送请求 连接 获得疫情数据
|
|
String resultBody = HttpUtil.get("https://api.inews.qq.com/newsqa/v1/query/pubished/daily/list?adCode=" + adCode + "&limit=" + limit);
|
|
JSONArray dataList = JSON.parseObject(resultBody).getJSONArray("data");
|
|
if (CollUtil.isEmpty(dataList)) {
|
|
return Collections.singletonList("日期:" + DateUtil.today() + ",目前累计确认人数为:" + 0 + "。当天新增本土确诊" + 0 + "人,新增本土无症状" + 0 + "人。");
|
|
}
|
|
List<String> datas = new ArrayList<>(dataList.size());
|
|
for (int i = dataList.size() - 1; i >= 0; i--) {
|
|
JSONObject data = dataList.getJSONObject(i);
|
|
String date = data.getString("date");
|
|
// 累计确诊
|
|
Integer confirm = data.getInteger("confirm");
|
|
// 新增确诊
|
|
Integer yesConfirmAdd = data.getInteger("yes_confirm_add");
|
|
// 昨日新增本土无症状新增
|
|
Integer yesWzzAdd = data.getInteger("yes_wzz_add");
|
|
datas.add("日期:" + date + ",目前累计确认人数为:" + confirm + "。当天新增本土确诊" + yesConfirmAdd + "人,新增本土无症状" + yesWzzAdd + "人。");
|
|
}
|
|
return datas;
|
|
}
|
|
|
|
public static void getProvince(Integer adCode) {
|
|
//1 发送请求 连接 获得疫情数据
|
|
String resultBody = HttpUtil.get("https://api.inews.qq.com/newsqa/v1/query/pubished/daily/list?adCode=440000&limit=1");
|
|
JSONArray data = JSON.parseObject(resultBody).getJSONArray("data");
|
|
if (CollUtil.isEmpty(data)) {
|
|
return;
|
|
}
|
|
JSONObject dataJSONObject = data.getJSONObject(0);
|
|
// 累计确诊
|
|
Integer confirm = dataJSONObject.getInteger("confirm");
|
|
|
|
// 累计死亡
|
|
Integer dead = dataJSONObject.getInteger("dead");
|
|
|
|
// 累计治愈
|
|
Integer heal = dataJSONObject.getInteger("heal");
|
|
|
|
// 新增确诊
|
|
Integer confirm_add = dataJSONObject.getInteger("confirm_add");
|
|
|
|
// 新增本土无症状新增
|
|
Integer wzz_add = dataJSONObject.getInteger("wzz_add");
|
|
|
|
// 新增本土
|
|
Integer all_local_confirm_add = dataJSONObject.getInteger("all_local_confirm_add");
|
|
// 现有确诊
|
|
Integer xyqz = confirm - dead - heal;
|
|
}
|
|
} |