Browse Source

1、天气接口加个判断

develop
bobol 9 months ago
parent
commit
73c2ca4cfd
  1. 52
      lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiDataScreenMainController.java

52
lzbi-module/src/main/java/com/lzbi/bi/controller/DcBusiDataScreenMainController.java

@ -15,6 +15,7 @@ import com.lzbi.common.core.domain.entity.SysDept;
import com.lzbi.common.utils.StringUtils; import com.lzbi.common.utils.StringUtils;
import com.lzbi.system.service.impl.SysDeptServiceImpl; import com.lzbi.system.service.impl.SysDeptServiceImpl;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -31,6 +32,7 @@ import java.util.concurrent.atomic.AtomicReference;
* @author : zhousq * @author : zhousq
* @date : 2023-11-16 * @date : 2023-11-16
*/ */
@Slf4j
@Api(tags = "主数据大屏的页面接口") @Api(tags = "主数据大屏的页面接口")
@RestController @RestController
@RequestMapping("/assetData/dataScreenMain") @RequestMapping("/assetData/dataScreenMain")
@ -195,32 +197,36 @@ public class DcBusiDataScreenMainController extends BaseController{
String yikeapiAppsecret; String yikeapiAppsecret;
@GetMapping("/weather/{areaCode}") @GetMapping("/weather/{areaCode}")
public AjaxResult getWeather(@PathVariable String areaCode){ public AjaxResult getWeather(@PathVariable String areaCode){
JSONObject ret=new JSONObject();
String url=StrUtil.format("https://v1.yiketianqi.com/free/week?city=沈阳&unescape=1&appid={}&appsecret={}",yikeapiAppid,yikeapiAppsecret); String url=StrUtil.format("https://v1.yiketianqi.com/free/week?city=沈阳&unescape=1&appid={}&appsecret={}",yikeapiAppid,yikeapiAppsecret);
JSONObject weather=JSONObject.parseObject(HttpUtil.get(url)); JSONObject weather=JSONObject.parseObject(HttpUtil.get(url));
JSONArray weatherInfo=Optional.ofNullable(weather.getJSONArray("data")).orElse(new JSONArray()); JSONArray weatherInfo=Optional.ofNullable(weather.getJSONArray("data")).orElse(new JSONArray());
JSONArray we_date=new JSONArray(); if (null != weatherInfo && !weatherInfo.isEmpty()) {
JSONArray we_name=new JSONArray(); JSONArray we_date=new JSONArray();
JSONArray tem_day=new JSONArray(); JSONArray we_name=new JSONArray();
JSONArray tem_night=new JSONArray(); JSONArray tem_day=new JSONArray();
we_date.add("天气日期:"); JSONArray tem_night=new JSONArray();
we_name.add("天气情况:"); we_date.add("天气日期:");
tem_day.add("日间气温:"); we_name.add("天气情况:");
tem_night.add("夜间气温:"); tem_day.add("日间气温:");
weatherInfo.forEach(item->{ tem_night.add("夜间气温:");
JSONObject jsb=JSONObject.from(item); weatherInfo.forEach(item->{
we_date.add(jsb.getString("date")); JSONObject jsb=JSONObject.from(item);
tem_day.add(jsb.getString("tem_day")); we_date.add(jsb.getString("date"));
tem_night.add(jsb.getString("tem_night")); tem_day.add(jsb.getString("tem_day"));
we_name.add(jsb.getString("wea")); tem_night.add(jsb.getString("tem_night"));
}); we_name.add(jsb.getString("wea"));
JSONArray list=new JSONArray(); });
list.add(we_date); JSONArray list=new JSONArray();
list.add(tem_day); list.add(we_date);
list.add(tem_night); list.add(tem_day);
list.add(we_name); list.add(tem_night);
JSONObject ret=new JSONObject(); list.add(we_name);
ret.put("source",list); ret.put("source",list);
ret.put("realwe",weatherInfo.get(0)); ret.put("realwe",weatherInfo.get(0));
} else {
log.error("天气接口未返回数据");
}
return AjaxResult.success(ret); return AjaxResult.success(ret);
} }
/** /**

Loading…
Cancel
Save