From 0ceac9a468401524578eecbb9e6f763045bf4ca9 Mon Sep 17 00:00:00 2001 From: chenshuichuan <1154693969@qq.com> Date: Tue, 25 Jun 2024 17:10:38 +0800 Subject: [PATCH] add weather --- .../controller/admin/home/HomeController.java | 78 +++++++++++++++++++ .../controller/admin/home/weather/Cast.java | 21 +++++ .../admin/home/weather/Forecast.java | 19 +++++ .../home/weather/WeatherInfoGaodeVO.java | 21 +++++ .../ProduceReportDetailMapper.java | 2 +- .../src/main/resources/application.yaml | 4 +- 6 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/HomeController.java create mode 100644 yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/weather/Cast.java create mode 100644 yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/weather/Forecast.java create mode 100644 yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/weather/WeatherInfoGaodeVO.java diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/HomeController.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/HomeController.java new file mode 100644 index 0000000000..6e72908e22 --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/HomeController.java @@ -0,0 +1,78 @@ +package cn.iocoder.yudao.module.mes.controller.admin.home; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.iot.framework.gateway.util.HttpUtils; +import cn.iocoder.yudao.module.mes.controller.admin.home.weather.Forecast; +import cn.iocoder.yudao.module.mes.controller.admin.home.weather.WeatherInfoGaodeVO; +import com.alibaba.fastjson.JSON; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.apache.http.StatusLine; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.util.EntityUtils; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.io.IOException; +import java.util.ArrayList; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "登录首页信息") +@RestController +@RequestMapping("/home/info") +@Validated +public class HomeController { + + + + //中文名 adcode citycode 呼和浩特市 150100 0471 + //https://restapi.amap.com/v3/weather/weatherInfo?key=1a63897dd11e83ae0be4cc922c07b523&city=150100 + @GetMapping("/weatherInfo") + @Operation(summary = "获得天气") + public CommonResult getTask() { + WeatherInfoGaodeVO gaodeVO = getWeather(); + Forecast forecast = null; + if(gaodeVO.getStatus().equals("1") && gaodeVO.getForecasts()!=null && gaodeVO.getForecasts().size()>0){ + forecast = gaodeVO.getForecasts().get(0); + forecast.setIsEnable(true); + } + else { + forecast = new Forecast(); + forecast.setIsEnable(false); + } + return success(forecast); + } + + public WeatherInfoGaodeVO getWeather() { + String key = "2f0de30f37da59122eeb774d3a2ba6da"; + String city = "150100"; + String extensions = "all"; + String URL= "https://restapi.amap.com/v3/weather/weatherInfo?key="+ key +"&city="+city+"&extensions="+extensions; + // 创建 HttpClient 客户端 + CloseableHttpClient httpClient = HttpUtils.createSSLClientDefault(); + CloseableHttpResponse httpResponse = null; + WeatherInfoGaodeVO gaodeVO = null; + try { + HttpGet httpGet = HttpUtils.getHttpGet(URL,new ArrayList<>()); + httpResponse = httpClient.execute(httpGet); + StatusLine statusLine = httpResponse.getStatusLine(); + if (statusLine.getStatusCode() == 200) { + String entityStr = EntityUtils.toString(httpResponse.getEntity()); + gaodeVO = JSON.parseObject(entityStr, WeatherInfoGaodeVO.class); + } + } + // 无论如何必须关闭连接 + catch (IOException e) { + e.printStackTrace(); + } finally { + HttpUtils.closeHttp(httpClient, httpResponse); + } + return gaodeVO; + } + +} \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/weather/Cast.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/weather/Cast.java new file mode 100644 index 0000000000..d9eb8e64d6 --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/weather/Cast.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.mes.controller.admin.home.weather; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class Cast { + private String date; + private String week; + private String dayweather; + private String nightweather; + private String daytemp; + private String nighttemp; + private String daywind; + private String nightwind; + private String daypower; + private String nightpower; +} diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/weather/Forecast.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/weather/Forecast.java new file mode 100644 index 0000000000..d4710a99fc --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/weather/Forecast.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.mes.controller.admin.home.weather; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class Forecast { + private Boolean isEnable; + private String city; + private String adcode; + private String province; + private String reporttime; + private List casts; +} diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/weather/WeatherInfoGaodeVO.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/weather/WeatherInfoGaodeVO.java new file mode 100644 index 0000000000..9b60a6dc75 --- /dev/null +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/home/weather/WeatherInfoGaodeVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.mes.controller.admin.home.weather; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; +import java.util.Map; + +@Schema(description = "管理后台 - 高得请求结果VO") +@Data +@ExcelIgnoreUnannotated +public class WeatherInfoGaodeVO { + + private String status; + private String info; + private String count; + private String infocode; + private List> lives; + private List forecasts; +} \ No newline at end of file diff --git a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/producereport/ProduceReportDetailMapper.java b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/producereport/ProduceReportDetailMapper.java index 824225ea6a..4f2b5bd3b9 100644 --- a/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/producereport/ProduceReportDetailMapper.java +++ b/yudao-module-mes/yudao-module-mes-biz/src/main/java/cn/iocoder/yudao/module/mes/dal/mysql/producereport/ProduceReportDetailMapper.java @@ -21,7 +21,7 @@ public interface ProduceReportDetailMapper extends BaseMapperX selectPage(ProduceReportDetailPageReqVO reqVO) { List status =null; - if(reqVO.getReportStatus() == 100){ + if(reqVO.getReportStatus()!=null && reqVO.getReportStatus() == 100){ status = ReportStatusEnum.getEnableEditStatus(); reqVO.setReportStatus(null); } diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index 30a49496f3..5ffc9b40e9 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -155,6 +155,7 @@ yudao: permit-all_urls: - /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,不需要登录 - /admin-api/iot/mqtt-server/** + - /admin-api/home/info/** websocket: enable: true # websocket的开关 path: /infra/ws # 路径 @@ -196,6 +197,7 @@ yudao: - /jmreport/* # 积木报表,无法携带租户编号 - /admin-api/mp/open/** # 微信公众号开放平台,微信回调接口,无法携带租户编号 - /admin-api/iot/mqtt-server/** + - /admin-api/home/info/** ignore-tables: - system_tenant - system_tenant_package @@ -271,7 +273,7 @@ jeecg: #tcp://47.112.167.85:1883 tcp://47.106.185.127:1883 emqx: - isEnable: true + isEnable: false broker: tcp://localhost:1883 #broker地址47.112.167.85 clientId: emqx-9521 userName: admin #授权账号 一定要授权的