diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/config/WeatherConf.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/config/WeatherConf.java new file mode 100644 index 00000000..b8dac533 --- /dev/null +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/config/WeatherConf.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.farm.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +/** + * @description: + * @author: binda + * @date: 2025/10/11 20:45 + */ +@Data +@Configuration +@ConfigurationProperties(prefix = "weather") +public class WeatherConf { + + private String webkey; + private String url1; + private String url2; + +} diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/digitalcockpit/DigitalCockpitController.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/digitalcockpit/DigitalCockpitController.java index 993219f3..af3be54c 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/digitalcockpit/DigitalCockpitController.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/digitalcockpit/DigitalCockpitController.java @@ -180,8 +180,11 @@ public class DigitalCockpitController { @GetMapping("/device-info/monitor-data") @Operation(summary = "监测数据") @Parameter(name = "baseId", description = "基地ID", required = true) - public CommonResult getMonitoringData(@RequestParam("baseId") String baseId) { - return success("暂时不做"); + public CommonResult getMonitoringData(@RequestParam("baseId") String baseId) { + + + DeviceMonitorDataRespVO res = new DeviceMonitorDataRespVO(); + return success(res); } @GetMapping("/species/get") diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/digitalcockpit/vo/DeviceMonitorDataRespVO.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/digitalcockpit/vo/DeviceMonitorDataRespVO.java new file mode 100644 index 00000000..cd1033ed --- /dev/null +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/digitalcockpit/vo/DeviceMonitorDataRespVO.java @@ -0,0 +1,55 @@ +package cn.iocoder.yudao.module.farm.controller.admin.digitalcockpit.vo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @description: TODO + * @author: binda + * @date: 2025/10/11 19:55 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class DeviceMonitorDataRespVO { + + private Soil soilInfo; + private Wf wfInfo; + private VideoMonitor videoMonitorInfo; + + @Data + @AllArgsConstructor + @NoArgsConstructor + public static class Soil { + private String deviceTypeName; + private List data; + } + + @Data + @AllArgsConstructor + @NoArgsConstructor + public static class Wf { + private String deviceTypeName; + private List data; + } + + @Data + @AllArgsConstructor + @NoArgsConstructor + public static class VideoMonitor { + private String deviceTypeName; + private List data; + } + + @Data + @AllArgsConstructor + @NoArgsConstructor + public static class Row { + private String name; + private String status; + } + +} diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/home/HomeController.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/home/HomeController.java index c6c1ca6b..8808af07 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/home/HomeController.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/home/HomeController.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.farm.controller.admin.home.vo.BaseNameVO; import cn.iocoder.yudao.module.farm.controller.admin.home.vo.HomeInfo; import cn.iocoder.yudao.module.farm.controller.admin.home.vo.QrDetailsRespVO; import cn.iocoder.yudao.module.farm.service.home.HomeService; +import cn.iocoder.yudao.module.farm.utils.WeatherUtil; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -31,6 +32,8 @@ public class HomeController { @Resource private HomeService homeService; + @Resource + private WeatherUtil weatherUtil; @Operation(summary = "农场首页") @GetMapping("") @@ -45,11 +48,28 @@ public class HomeController { return success(homeService.getBaseNameList()); } + @Operation(summary = "农场首页-天气信息-获取天气信息") + @GetMapping("/weather/{lng}/{lat}") + public CommonResult getBaseNameList(@PathVariable("lng") String lng, + @PathVariable("lat") String lat) { + String res = weatherUtil.getWeatherInfo(lng, lat); + return success(res); + } + + +// @Operation(summary = "农场首页-天气信息-获取天气信息") +// @GetMapping("/weather/{city}") +// public CommonResult getBaseNameList(@PathVariable("city") String city) { +// +// return success("天气信息!"); +// } + @PermitAll @Operation(summary = "农场首页-扫描二维码") @GetMapping("/scan-qr") @Parameter(name = "baseId", description = "基地ID") public CommonResult scanQrCodes(@RequestParam("baseId") String baseId) { + // TODO: 2025/10/11 待实现 QrDetailsRespVO mockData = new QrDetailsRespVO(); // 设置基地基本信息 diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/home/vo/GeocodeResponse.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/home/vo/GeocodeResponse.java new file mode 100644 index 00000000..49a96c34 --- /dev/null +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/home/vo/GeocodeResponse.java @@ -0,0 +1,142 @@ +package cn.iocoder.yudao.module.farm.controller.admin.home.vo; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +/** + * 逆地理编码响应数据封装类 + */ +@Data +public class GeocodeResponse { + + @JsonProperty("status") + private String status; + + @JsonProperty("regeocode") + private Regeocode regeocode; + + @JsonProperty("info") + private String info; + + @JsonProperty("infocode") + private String infocode; + + /** + * 判断请求是否成功 + * @return true-成功, false-失败 + */ + public boolean isSuccess() { + return "1".equals(this.status); + } + + /** + * 获取adcode + * @return adcode + */ + public String getAdcode() { + if (regeocode != null && regeocode.getAddressComponent() != null) { + return regeocode.getAddressComponent().getAdcode(); + } + return null; + } + + /** + * 获取格式化地址 + * @return 格式化地址 + */ + public String getFormattedAddress() { + if (regeocode != null) { + return regeocode.getFormattedAddress(); + } + return null; + } + + @Data + public static class Regeocode { + + @JsonProperty("addressComponent") + private AddressComponent addressComponent; + + @JsonProperty("formatted_address") + private String formattedAddress; + } + + @Data + public static class AddressComponent { + + @JsonProperty("city") + private String city; + + @JsonProperty("province") + private String province; + + @JsonProperty("adcode") + private String adcode; + + @JsonProperty("district") + private String district; + + @JsonProperty("towncode") + private String towncode; + + @JsonProperty("streetNumber") + private StreetNumber streetNumber; + + @JsonProperty("country") + private String country; + + @JsonProperty("township") + private String township; + + @JsonProperty("businessAreas") + private Object businessAreas; + + @JsonProperty("building") + private Building building; + + @JsonProperty("neighborhood") + private Neighborhood neighborhood; + + @JsonProperty("citycode") + private String citycode; + } + + @Data + public static class StreetNumber { + + @JsonProperty("number") + private String number; + + @JsonProperty("location") + private String location; + + @JsonProperty("direction") + private String direction; + + @JsonProperty("distance") + private String distance; + + @JsonProperty("street") + private String street; + } + + @Data + public static class Building { + + @JsonProperty("name") + private Object name; + + @JsonProperty("type") + private Object type; + } + + @Data + public static class Neighborhood { + + @JsonProperty("name") + private Object name; + + @JsonProperty("type") + private Object type; + } +} diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/farmnews/FarmInformationController.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/farmnews/FarmInformationController.java new file mode 100644 index 00000000..95832700 --- /dev/null +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/farmnews/FarmInformationController.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.farm.controller.admin.managementcenter.farmnews; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.farmnews.vo.FarmInformationPageRespVO; +import cn.iocoder.yudao.module.farm.service.farminformation.FarmInformationService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +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; + +/** + * @description: + * @author: binda + * @date: 2025/10/13 10:23 + */ +@Tag(name = "管理中心 - 农业资讯") +@RestController +@RequestMapping("/farm/news") +@Validated +public class FarmInformationController { + + private final FarmInformationService farmInformationService; + + public FarmInformationController(FarmInformationService farmInformationService) { + this.farmInformationService = farmInformationService; + } + + @GetMapping("/page") + @Operation(summary = "资讯信息-分页") + public CommonResult> pageInfo() { + + PageResult res = null; + return CommonResult.success(res); + } + + + +} diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/farmnews/vo/FarmInformationPageReqVO.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/farmnews/vo/FarmInformationPageReqVO.java new file mode 100644 index 00000000..83c43840 --- /dev/null +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/farmnews/vo/FarmInformationPageReqVO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.farm.controller.admin.managementcenter.farmnews.vo; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import lombok.Data; + +/** + * @description: TODO + * @author: binda + * @date: 2025/10/13 10:58 + */ +@Data +public class FarmInformationPageReqVO extends PageParam { + + private String id; + +} diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/wx/vo/FarmInformationRespVO.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/farmnews/vo/FarmInformationPageRespVO.java similarity index 81% rename from yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/wx/vo/FarmInformationRespVO.java rename to yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/farmnews/vo/FarmInformationPageRespVO.java index 01d81a49..2a7d134b 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/wx/vo/FarmInformationRespVO.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/farmnews/vo/FarmInformationPageRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.farm.controller.admin.wx.vo; +package cn.iocoder.yudao.module.farm.controller.admin.managementcenter.farmnews.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; @@ -13,7 +13,7 @@ import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor -public class FarmInformationRespVO { +public class FarmInformationPageRespVO { @Schema(description = "资讯类型 (1: 要闻; 99:其他)") private String infoType; diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/personnelmanagement/vo/PersonnelManagementSaveReqVO.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/personnelmanagement/vo/PersonnelManagementSaveReqVO.java index a12ed03e..be6f94fa 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/personnelmanagement/vo/PersonnelManagementSaveReqVO.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/managementcenter/personnelmanagement/vo/PersonnelManagementSaveReqVO.java @@ -30,7 +30,7 @@ public class PersonnelManagementSaveReqVO { @Schema(description = "头像集合") private List pictureList; - @Schema(description = "0=启用,1=停用", example = "2") + @Schema(description = "0=启用,1=停用") private Integer accountStatus; @Schema(description = "基地id", example = "30077") diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/wx/WxController.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/wx/WxController.java index 06c47535..773b5618 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/wx/WxController.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/wx/WxController.java @@ -3,6 +3,8 @@ package cn.iocoder.yudao.module.farm.controller.admin.wx; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.farm.controller.admin.api.vo.DeviceStateRespVO; +import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.farmnews.vo.FarmInformationPageReqVO; +import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.farmnews.vo.FarmInformationPageRespVO; import cn.iocoder.yudao.module.farm.controller.admin.wx.vo.*; import cn.iocoder.yudao.module.farm.dal.dataobject.baseinfo.BaseInfoDO; import cn.iocoder.yudao.module.farm.dal.dataobject.deviceinfo.DeviceInfoDO; @@ -65,8 +67,8 @@ public class WxController { @Operation(summary = "农业资讯") @GetMapping("/farm-information/page") - public CommonResult> getFarmInformation(@Valid FarmInformationReqVO req) { - PageResult result = farmInformationService.getFarmInformationPage(req); + public CommonResult> getFarmInformation(@Valid FarmInformationPageReqVO req) { + PageResult result = farmInformationService.getFarmInformationPage(req); return CommonResult.success(result); } diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/wx/vo/FarmInformationReqVO.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/wx/vo/FarmInformationReqVO.java deleted file mode 100644 index 3c560a96..00000000 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/controller/admin/wx/vo/FarmInformationReqVO.java +++ /dev/null @@ -1,18 +0,0 @@ -package cn.iocoder.yudao.module.farm.controller.admin.wx.vo; - -import cn.iocoder.yudao.framework.common.pojo.PageParam; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @description: - * @author: binda - * @date: 2025/9/25 17:33 - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class FarmInformationReqVO extends PageParam { - private String id; -} diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/manager/equipmentproducer/conf/DeviceConf.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/manager/equipmentproducer/conf/DeviceConf.java index 3a88bc90..277e2451 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/manager/equipmentproducer/conf/DeviceConf.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/manager/equipmentproducer/conf/DeviceConf.java @@ -16,6 +16,7 @@ public class DeviceConf { private FourSituations fourSituations; private WaterAndFertilizer waterAndFertilizer; + private VideoMonitor videoMonitor; @Data public static class FourSituations { @@ -60,5 +61,12 @@ public class DeviceConf { private String url4; // 更新设备属性 POST } + @Data + public static class VideoMonitor{ + private String url1; + private String state1; + private String url2; + private String state2; + } } diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/manager/equipmentproducer/service/TokenCacheService.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/manager/equipmentproducer/service/TokenCacheService.java index 12868b8f..03e1bbdb 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/manager/equipmentproducer/service/TokenCacheService.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/manager/equipmentproducer/service/TokenCacheService.java @@ -94,7 +94,7 @@ public abstract class TokenCacheService { /** * 定期清除过期token */ - @Scheduled(fixedRate = 1000 * 60 * 60 ) // 每1小时执行一次 + @Scheduled(fixedRate = 1000 * 60 * 6 ) // 每6分钟执行一次 public void cleanupExpiredTokens() { long currentTime = System.currentTimeMillis(); diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/farminformation/FarmInformationService.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/farminformation/FarmInformationService.java index fec37b14..61ea73bf 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/farminformation/FarmInformationService.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/farminformation/FarmInformationService.java @@ -1,8 +1,8 @@ package cn.iocoder.yudao.module.farm.service.farminformation; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.farm.controller.admin.wx.vo.FarmInformationReqVO; -import cn.iocoder.yudao.module.farm.controller.admin.wx.vo.FarmInformationRespVO; +import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.farmnews.vo.FarmInformationPageReqVO; +import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.farmnews.vo.FarmInformationPageRespVO; /** * @description: @@ -10,5 +10,6 @@ import cn.iocoder.yudao.module.farm.controller.admin.wx.vo.FarmInformationRespVO * @date: 2025/9/25 17:27 */ public interface FarmInformationService { - PageResult getFarmInformationPage(FarmInformationReqVO req); + PageResult getFarmInformationPage(FarmInformationPageReqVO req); + } diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/farminformation/FarmInformationServiceImpl.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/farminformation/FarmInformationServiceImpl.java index a89460d4..470f2286 100644 --- a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/farminformation/FarmInformationServiceImpl.java +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/service/farminformation/FarmInformationServiceImpl.java @@ -1,8 +1,9 @@ package cn.iocoder.yudao.module.farm.service.farminformation; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.farm.controller.admin.wx.vo.FarmInformationReqVO; -import cn.iocoder.yudao.module.farm.controller.admin.wx.vo.FarmInformationRespVO; +import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.farmnews.vo.FarmInformationPageReqVO; +import cn.iocoder.yudao.module.farm.controller.admin.managementcenter.farmnews.vo.FarmInformationPageRespVO; +import cn.iocoder.yudao.module.farm.dal.mysql.farminformation.FarmInformationMapper; import org.springframework.stereotype.Service; /** @@ -13,10 +14,18 @@ import org.springframework.stereotype.Service; @Service public class FarmInformationServiceImpl implements FarmInformationService{ + private final FarmInformationMapper farmInformationMapper; + + public FarmInformationServiceImpl(FarmInformationMapper farmInformationMapper) { + this.farmInformationMapper = farmInformationMapper; + } + @Override - public PageResult getFarmInformationPage(FarmInformationReqVO req) { + public PageResult getFarmInformationPage(FarmInformationPageReqVO req) { return null; } + + } diff --git a/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/utils/WeatherUtil.java b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/utils/WeatherUtil.java new file mode 100644 index 00000000..5a5fc11c --- /dev/null +++ b/yudao-module-farm/src/main/java/cn/iocoder/yudao/module/farm/utils/WeatherUtil.java @@ -0,0 +1,147 @@ +package cn.iocoder.yudao.module.farm.utils; + +import cn.iocoder.yudao.module.farm.config.WeatherConf; +import cn.iocoder.yudao.module.farm.controller.admin.home.vo.GeocodeResponse; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import java.text.MessageFormat; + +/** + * @description: 高德天气 + * @date: 2025/10/13 11:34 + */ +@Slf4j +@Component +public class WeatherUtil { + + private final WeatherConf weatherConf; + private final RestTemplate restTemplate; + + public WeatherUtil(WeatherConf weatherConf, RestTemplate restTemplate) { + this.weatherConf = weatherConf; + this.restTemplate = restTemplate; + } + + private static final ObjectMapper objectMapper = new ObjectMapper(); + + /** + * 根据经纬度获取天气信息 + * @param lng 经度 + * @param lat 纬度 + * @return 天气信息JSON字符串 + */ + public String getWeatherInfo(String lng, String lat) { + try { + // 1. 逆地理编码获取adcode + String adcode = getAdcodeByLocation(lng, lat); + if (adcode == null || adcode.isEmpty()) { + log.error("根据经纬度获取adcode失败: lng={}, lat={}", lng, lat); + return buildErrorResult("获取地区编码失败"); + } + + // 2. 根据adcode获取天气信息 + return getWeatherByAdcode(adcode); + + } catch (Exception e) { + log.error("获取天气信息异常: lng={}, lat={}, error={}", lng, lat, e.getMessage(), e); + return buildErrorResult("获取天气信息异常: " + e.getMessage()); + } + } + + /** + * 根据经纬度获取地区编码(adcode) + * @param lng 经度 + * @param lat 纬度 + * @return adcode + */ + private String getAdcodeByLocation(String lng, String lat) { + String webKey = weatherConf.getWebkey(); + String url_1 = weatherConf.getUrl1(); + String url = MessageFormat.format(url_1, lng, lat, webKey); + + try { + log.info("调用逆地理编码API: {}", url.replace(webKey, "***")); + + ResponseEntity response = restTemplate.getForEntity(url, String.class); + if (response.getStatusCode().is2xxSuccessful()) { + String result = response.getBody(); + log.debug("逆地理编码响应: {}", result); + + // 解析响应数据 - 使用新的GeocodeResponse类 + GeocodeResponse geocodeResponse = objectMapper.readValue(result, GeocodeResponse.class); + if (geocodeResponse.isSuccess() && geocodeResponse.getAdcode() != null) { + return geocodeResponse.getAdcode(); + } else { + log.error("逆地理编码API返回错误: status={}, info={}", geocodeResponse.getStatus(), geocodeResponse.getInfo()); + return null; + } + } else { + log.error("逆地理编码HTTP请求失败,状态码: {}", response.getStatusCode()); + return null; + } + } catch (Exception e) { + log.error("逆地理编码查询异常: {}", e.getMessage(), e); + return null; + } + } + + /** + * 根据adcode获取天气信息 + * @param adcode 地区编码 + * @return 天气信息JSON字符串 + */ + private String getWeatherByAdcode(String adcode) { + String webKey = weatherConf.getWebkey(); + String url_2 = weatherConf.getUrl2(); + String url = MessageFormat.format(url_2, adcode, webKey); + + try { + log.info("调用天气信息API: {}", url.replace(webKey, "***")); + + ResponseEntity response = restTemplate.getForEntity(url, String.class); + if (response.getStatusCode().is2xxSuccessful()) { + String result = response.getBody(); + log.debug("天气信息响应: {}", result); + return result; + } else { + log.error("天气信息HTTP请求失败,状态码: {}", response.getStatusCode()); + return buildErrorResult("天气信息请求失败,状态码: " + response.getStatusCode()); + } + } catch (Exception e) { + log.error("天气信息查询异常: {}", e.getMessage(), e); + return buildErrorResult("天气信息查询异常: " + e.getMessage()); + } + } + + /** + * 构建错误结果 + * @param errorMsg 错误信息 + * @return JSON格式的错误结果 + */ + private static String buildErrorResult(String errorMsg) { + try { + ErrorResult errorResult = new ErrorResult(); + errorResult.setCode(1); + errorResult.setMsg(errorMsg); + return objectMapper.writeValueAsString(errorResult); + } catch (Exception e) { + return "{\"code\":1,\"msg\":\"构建错误结果异常\"}"; + } + } + + @Data + public static class ErrorResult { + @JsonProperty("code") + private Integer code = 1; + + @JsonProperty("msg") + private String msg; + } + +} diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index 1650671d..b2b76d84 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -381,5 +381,17 @@ device-manager: url-2: /prod-api/agriculture/deviceMain/list # 获取设备列表 GET url-3: /prod-api/agriculture/deviceMain/getDeviceAllPropertyAndData/{0} # 获取设备实时状态 GET {0}: deviceId url-4: /prod-api/agriculture/deviceMain/updateDeviceStatus # 更改设备属性 POST + video-monitor: + url-1: https://cmgw-vpc.lechange.com:8890/flv/LCO/BD0F028PAJD72EF/0/1/20250918155206/openhzb6d1cc3dc98646938440066260617092.flv?proto=https&source=open + state-1: 1 # 1: 开启状态; 0: 关闭状态 + url-2: https://cmgw-vpc.lechange.com:8890/flv/LCO/BD0F028PAJD72EF/1/1/20250918151221/openhz4e7ed55f0a6c42f683839719fca33c9e.flv?proto=https&source=open + state-2: 1 # 1: 开启状态; 0: 关闭状态 + +# 高德天气 +weather: + webKey: ${gaode.weather.webkey} + url-1: https://restapi.amap.com/v3/geocode/regeo?location={0},{1}&key={2} # 经纬度逆解析 GET + url-2: https://restapi.amap.com/v3/weather/weatherInfo?city={0}&key={1} # 获取天气信息 GET + diff --git a/yudao-server/src/main/resources/db.properties b/yudao-server/src/main/resources/db.properties index 66a72353..ef711002 100644 --- a/yudao-server/src/main/resources/db.properties +++ b/yudao-server/src/main/resources/db.properties @@ -16,15 +16,14 @@ wm.wx.mp.secret=92c571b9973f9078c11da47a16c4094c wm.wx.miniapp.app-id=wx508d9a9ab84f67d0 wm.wx.miniapp.secret=92c571b9973f9078c11da47a16c4094c -# ???? -wanmao.wms.hosts=https://wms.simple.gltec.cn/prod-api -# ???? -#wanmao.wms.hosts=47.111.15.9:8074/prod-api wanmao.wms.url_1=getTenantByMobile +# prod +wanmao.wms.hosts=https://wms.simple.gltec.cn/prod-api +# test +#wanmao.wms.hosts=47.111.15.9:8074/prod-api - - - +# gaode key +gaode.weather.webkey=ea0a0486aaea8dbf9f68274df1160df3 @@ -37,7 +36,7 @@ wanmao.wms.url_1=getTenantByMobile ######################### -###########??########### +###########jishui########### ######################### #mysql.url=jdbc:mysql://rm-bp10c7f0fou5efc95fo.mysql.rds.aliyuncs.com:3306/farming-platform?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true @@ -55,4 +54,6 @@ wanmao.wms.url_1=getTenantByMobile #wm.wx.miniapp.secret=a5e114df50a86c2578af255adba1c3e7 # #wms.hosts=https://wms.jslstec.cn/prod-api -#wms.url_1=getTenantByMobile \ No newline at end of file +#wms.url_1=getTenantByMobile +# +#weather.webkey=6e867624a911d74e673f5e68c52a61e7 \ No newline at end of file