From 989f463760203b62e9e5343e9a5ed1129c7e02d3 Mon Sep 17 00:00:00 2001
From: liurunyu <lry9898@163.com>
Date: 星期四, 14 八月 2025 10:21:45 +0800
Subject: [PATCH] 有wechat模块中增加查询水肥机、墒情站、气象站最新数据与在线情况
---
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttMonitorSv.java | 77 +++++++++++
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttLastSv.java | 59 ++++++++
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoWeatherLast.java | 42 ++++++
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoSoilLast.java | 37 +++++
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttLastCtrl.java | 111 +++++++++++++++
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttSv.java | 25 +++
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoManureLast.java | 40 +++++
7 files changed, 391 insertions(+), 0 deletions(-)
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttLastCtrl.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttLastCtrl.java
new file mode 100644
index 0000000..93a8ed6
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttLastCtrl.java
@@ -0,0 +1,111 @@
+package com.dy.pipIrrWechat.mqtt;
+
+import com.dy.common.aop.SsoAop;
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.common.webUtil.BaseResponseUtils;
+import com.dy.pipIrrGlobal.voRm.VoManure;
+import com.dy.pipIrrGlobal.voRm.VoSoil;
+import com.dy.pipIrrGlobal.voRm.VoWeather;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2025/8/14 8:32
+ * @Description
+ */
+@Slf4j
+@Tag(name = "姘磋偉銆佹皵璞°�佸鎯呮渶鏂版暟鎹煡璇�", description = "姘磋偉銆佹皵璞°�佸鎯呮渶鏂版暟鎹煡璇�")
+@RestController
+@RequestMapping(path = "mqttLast")
+public class MqttLastCtrl {
+
+ private MqttLastSv sv ;
+ private MqttMonitorSv mmsv;
+ private MqttSv msv;
+
+ @Autowired
+ public void setSv(MqttLastSv sv, MqttMonitorSv mmsv, MqttSv msv) {
+ this.sv = sv;
+ this.mmsv = mmsv;
+ this.msv = msv;
+ }
+
+ /**
+ * 鏍规嵁鎸囧畾鏉′欢鏌ヨ鏈�鏂拌褰�
+ * @param manureId
+ * @return
+ */
+ @GetMapping(path = "oneManureLast")
+ @SsoAop()
+ public BaseResponse<VoManureLast> oneManureLast(Long manureId){
+ try {
+ if(manureId == null){
+ return BaseResponseUtils.buildFail("姘磋偉鏈篿d涓嶈兘涓虹┖") ;
+ }
+ VoManure vo = sv.oneManureLast(manureId) ;
+ String fboxId = msv.oneManureFBoxId(manureId);
+ Boolean onLine = mmsv.isOnLine4Mqtt(fboxId);
+ VoManureLast voLast = new VoManureLast() ;
+ voLast.fromVo(vo);
+ voLast.setOnLine(onLine);
+ return BaseResponseUtils.buildSuccess(voLast);
+ } catch (Exception e) {
+ return BaseResponseUtils.buildException(e.getMessage()) ;
+ }
+ }
+
+
+ /**
+ * 鏍规嵁鎸囧畾鏉′欢鏌ヨ鏈�鏂拌褰�
+ * @param soilId
+ * @return
+ */
+ @GetMapping(path = "oneSoilLast")
+ @SsoAop()
+ public BaseResponse<VoSoil> oneSoilLast(Long soilId){
+ try {
+ if(soilId == null){
+ return BaseResponseUtils.buildFail("澧掓儏绔檌d涓嶈兘涓虹┖") ;
+ }
+ VoSoil vo = sv.oneSoilLast(soilId) ;
+ String fboxId = msv.oneSoilFBoxId(soilId);
+ Boolean onLine = mmsv.isOnLine4Mqtt(fboxId);
+ VoSoilLast voLast = new VoSoilLast() ;
+ voLast.fromVo(vo);
+ voLast.setOnLine(onLine);
+ return BaseResponseUtils.buildSuccess(voLast);
+ } catch (Exception e) {
+ return BaseResponseUtils.buildException(e.getMessage()) ;
+ }
+ }
+
+ /**
+ * 鏍规嵁鎸囧畾鏉′欢鏌ヨ鏈�鏂拌褰�
+ * @param weatherId
+ * @return
+ */
+ @GetMapping(path = "oneWeatherLast")
+ @SsoAop()
+ public BaseResponse<VoWeather> oneWeatherLast(Long weatherId){
+ try {
+ if(weatherId == null){
+ return BaseResponseUtils.buildFail("姘旇薄绔檌d涓嶈兘涓虹┖") ;
+ }
+ VoWeather vo = sv.oneWeatherLast(weatherId);
+ String fboxId = msv.oneWeatherFBoxId(weatherId);
+ Boolean onLine = mmsv.isOnLine4Mqtt(fboxId);
+ VoWeatherLast voLast = new VoWeatherLast() ;
+ voLast.fromVo(vo);
+ voLast.setOnLine(onLine);
+ return BaseResponseUtils.buildSuccess(voLast);
+ } catch (Exception e) {
+ return BaseResponseUtils.buildException(e.getMessage()) ;
+ }
+ }
+
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttLastSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttLastSv.java
new file mode 100644
index 0000000..091c4c4
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttLastSv.java
@@ -0,0 +1,59 @@
+package com.dy.pipIrrWechat.mqtt;
+
+import com.dy.pipIrrGlobal.daoRm.RmManureLastMapper;
+import com.dy.pipIrrGlobal.daoRm.RmSoilLastMapper;
+import com.dy.pipIrrGlobal.daoRm.RmWeatherLastMapper;
+import com.dy.pipIrrGlobal.voRm.VoManure;
+import com.dy.pipIrrGlobal.voRm.VoSoil;
+import com.dy.pipIrrGlobal.voRm.VoSoilDay;
+import com.dy.pipIrrGlobal.voRm.VoWeather;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2025/8/14 8:32
+ * @Description
+ */
+@Slf4j
+@Service
+public class MqttLastSv {
+ @Autowired
+ private RmManureLastMapper rmManureLastDao ;
+
+ @Autowired
+ private RmSoilLastMapper rmSoilLastDao ;
+
+ @Autowired
+ private RmWeatherLastMapper rmWeatherLastDao ;
+
+ public VoManure oneManureLast(Long manureId) {
+ List<VoManure> list = this.rmManureLastDao.selectSomeByManureId(manureId) ;
+ if(list != null && list.size() > 0) {
+ return list.get(0) ;
+ }
+ return null ;
+ }
+
+
+ public VoSoil oneSoilLast(Long soilId) {
+ List<VoSoil> list = this.rmSoilLastDao.selectSomeBySoilId(soilId) ;
+ if(list != null && list.size() > 0) {
+ return list.get(0) ;
+ }
+ return null ;
+ }
+
+
+ public VoWeather oneWeatherLast(Long weatherId) {
+ List<VoWeather> list = this.rmWeatherLastDao.selectSomeByWeatherId(weatherId) ;
+ if(list != null && list.size() > 0) {
+ return list.get(0) ;
+ }
+ return null ;
+ }
+
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttMonitorSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttMonitorSv.java
new file mode 100644
index 0000000..80dcb3c
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttMonitorSv.java
@@ -0,0 +1,77 @@
+package com.dy.pipIrrWechat.mqtt;
+
+import com.alibaba.fastjson2.JSON;
+import com.dy.common.mw.protocol.Command;
+import com.dy.common.mw.protocol.CommandBackParam;
+import com.dy.common.webUtil.BaseResponse;
+import com.dy.pipIrrGlobal.rtuMw.CodeLocal;
+import com.dy.pipIrrGlobal.rtuMw.Web2RtuMw;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.HashMap;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2025/8/14 8:44
+ * @Description
+ */
+@Slf4j
+@Service
+public class MqttMonitorSv extends Web2RtuMw {
+
+ @Autowired
+ private Environment env;
+
+ @Autowired
+ private RestTemplate restTemplate;
+
+
+ /**
+ * 鏌ヨ璁惧鏄惁鍦ㄧ嚎
+ *
+ * @return
+ */
+ public Boolean isOnLine4Mqtt(String fboxId) {
+ return selectOnOrOffLine4Mqtt(fboxId) ;
+ }
+
+ /**
+ * 鏌ヨMQTT鍦ㄧ嚎鎴栫绾跨姸鎬�
+ * @param fboxId
+ * @return
+ */
+ private Boolean selectOnOrOffLine4Mqtt(String fboxId) {
+ //鍚戦�氫俊涓棿浠跺彂鍏冲懡浠わ紝鏌ヨ閮ㄥ垎RTU鍦ㄧ嚎鎯呭喌
+ Command com = this.createInnerCommand(CodeLocal.onPartLineMqtt);
+ com.setParam(fboxId) ;
+ String rqUrl = this.get2MwRequestUrl(this.env, ContextComSend) ;
+ BaseResponse res = sendPostRequest2Mw(restTemplate, rqUrl, com) ;
+ if(res != null){
+ if(res.isSuccess()){
+ Command reCom = JSON.parseObject(res.getContent() == null ? null : JSON.toJSONString(res.getContent()), Command.class) ;
+ CommandBackParam bakParam = JSON.parseObject((reCom== null || reCom.param == null) ? null : JSON.toJSONString(reCom.param), CommandBackParam.class) ;
+ if(bakParam != null){
+ if(bakParam.getSuccess().booleanValue()){
+ //閫氫俊涓棿浠舵垚鍔熻繑鍥炲懡浠ょ粨鏋�
+ HashMap<String, Boolean> onLineMap = JSON.parseObject(JSON.toJSONString(reCom.getAttachment()), HashMap.class);
+ Boolean flag = onLineMap.get(fboxId);
+ if(flag != null){
+ return flag ;
+ }
+ }
+ }else{
+ log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ょ粨鏋滀腑涓嶅寘鍚獵ommandBackParam绫诲瀷鍙傛暟");
+ }
+ }else{
+ log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ゆ墽琛屽け璐�" + (res.getMsg() == null? "" : ("锛�" + res.getMsg()))) ;
+ }
+ }else{
+ log.error("閫氫俊涓棿浠惰繑鍥炲唴閮ㄥ懡浠ょ粨鏋滀负null");
+ }
+ return null ;
+ }
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttSv.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttSv.java
index 9813b61..e08513e 100644
--- a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttSv.java
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttSv.java
@@ -3,7 +3,10 @@
import com.dy.pipIrrGlobal.daoPr.PrStManureMapper;
import com.dy.pipIrrGlobal.daoPr.PrStSoilMapper;
import com.dy.pipIrrGlobal.daoPr.PrStWeatherMapper;
+import com.dy.pipIrrGlobal.voPr.VoManure;
import com.dy.pipIrrGlobal.voPr.VoMqttSimple;
+import com.dy.pipIrrGlobal.voPr.VoSoil;
+import com.dy.pipIrrGlobal.voPr.VoWeather;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -38,4 +41,26 @@
return this.weatherDao.selectAllSimple() ;
}
+ public String oneManureFBoxId(Long id){
+ VoManure vo = manureDao.selectOne(id);
+ if(vo != null){
+ return vo.fboxId ;
+ }
+ return null ;
+ }
+ public String oneSoilFBoxId(Long id){
+ VoSoil vo = soilDao.selectOne(id);
+ if(vo != null){
+ return vo.fboxId ;
+ }
+ return null ;
+ }
+ public String oneWeatherFBoxId(Long id){
+ VoWeather vo = weatherDao.selectOne(id);
+ if(vo != null){
+ return vo.fboxId ;
+ }
+ return null ;
+ }
+
}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoManureLast.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoManureLast.java
new file mode 100644
index 0000000..7bea275
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoManureLast.java
@@ -0,0 +1,40 @@
+package com.dy.pipIrrWechat.mqtt;
+
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import lombok.Data;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2025/8/14 10:02
+ * @Description
+ */
+@Data
+@JsonPropertyOrder({
+ "id", "manureId", "manureName", "dt", "alarm",
+ "stirRunning1", "stirRunning2", "stirRunning3", "stirRunning4",
+ "injectRunning", "irrRunning",
+ "manureFlow", "manureTime", "stirTime",
+ "stirDuration", "injectDuration", "onLine"
+})
+public class VoManureLast extends com.dy.pipIrrGlobal.voRm.VoManure{
+ public Boolean onLine ;
+
+ public void fromVo(com.dy.pipIrrGlobal.voRm.VoManure vo){
+ this.id = vo.id ;
+ this.manureId = vo.manureId ;
+ this.manureName = vo.manureName ;
+ this.dt = vo.dt ;
+ this.alarm = vo.alarm ;
+ this.stirRunning1 = vo.stirRunning1 ;
+ this.stirRunning2 = vo.stirRunning2 ;
+ this.stirRunning3 = vo.stirRunning3 ;
+ this.stirRunning4 = vo.stirRunning4 ;
+ this.injectRunning = vo.injectRunning ;
+ this.irrRunning = vo.irrRunning ;
+ this.manureFlow = vo.manureFlow ;
+ this.manureTime = vo.manureTime ;
+ this.stirTime = vo.stirTime ;
+ this.stirDuration = vo.stirDuration ;
+ this.injectDuration = vo.injectDuration ;
+ }
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoSoilLast.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoSoilLast.java
new file mode 100644
index 0000000..7c2244b
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoSoilLast.java
@@ -0,0 +1,37 @@
+package com.dy.pipIrrWechat.mqtt;
+
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import lombok.Data;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2025/8/14 10:04
+ * @Description
+ */
+@Data
+@JsonPropertyOrder({
+ "id", "soilId", "soilName", "dt",
+ "soilHumidity1", "soilHumidity2", "soilHumidity3", "soilHumidity4", "soilHumidity5",
+ "soilTemperature1", "soilTemperature2", "soilTemperature3", "soilTemperature4", "soilTemperature5",
+ "onLine"
+})
+public class VoSoilLast extends com.dy.pipIrrGlobal.voRm.VoSoil{
+ public Boolean onLine ;
+
+ public void fromVo(com.dy.pipIrrGlobal.voRm.VoSoil vo){
+ this.id = vo.id ;
+ this.soilId = vo.soilId ;
+ this.soilName = vo.soilName ;
+ this.dt = vo.dt ;
+ this.soilHumidity1 = vo.soilHumidity1 ;
+ this.soilHumidity2 = vo.soilHumidity2 ;
+ this.soilHumidity3 = vo.soilHumidity3 ;
+ this.soilHumidity4 = vo.soilHumidity4 ;
+ this.soilHumidity5 = vo.soilHumidity5 ;
+ this.soilTemperature1 = vo.soilTemperature1 ;
+ this.soilTemperature2 = vo.soilTemperature2 ;
+ this.soilTemperature3 = vo.soilTemperature3 ;
+ this.soilTemperature4 = vo.soilTemperature4 ;
+ this.soilTemperature5 = vo.soilTemperature5 ;
+ }
+}
diff --git a/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoWeatherLast.java b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoWeatherLast.java
new file mode 100644
index 0000000..de50251
--- /dev/null
+++ b/pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoWeatherLast.java
@@ -0,0 +1,42 @@
+package com.dy.pipIrrWechat.mqtt;
+
+import com.alibaba.fastjson2.annotation.JSONField;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import lombok.Data;
+
+/**
+ * @Author: liurunyu
+ * @Date: 2025/8/14 10:06
+ * @Description
+ */
+@Data
+@JsonPropertyOrder({
+ "id", "weatherId", "weatherName", "dt",
+ "airTemperature", "airHumidity",
+ "ultraviolet", "lightIntensity",
+ "rainfall", "windSpeed",
+ "windDirection", "windDirectionStr",
+ "onLine"
+})
+public class VoWeatherLast extends com.dy.pipIrrGlobal.voRm.VoWeather{
+ public Boolean onLine ;
+
+ public void fromVo(com.dy.pipIrrGlobal.voRm.VoWeather vo){
+ this.id = vo.id ;
+ this.weatherId = vo.weatherId ;
+ this.weatherName = vo.weatherName ;
+ this.dt = vo.dt ;
+ this.airTemperature = vo.airTemperature ;
+ this.airHumidity = vo.airHumidity ;
+ this.ultraviolet = vo.ultraviolet ;
+ this.lightIntensity = vo.lightIntensity ;
+ this.rainfall = vo.rainfall ;
+ this.windSpeed = vo.windSpeed ;
+ this.windDirection = vo.windDirection ;
+ }
+ @JSONField(name = "windDirectionStr") // 鎸囧畾 JSON 涓殑瀛楁鍚�
+ public String getWindDirectionStr() {
+ return super.getWindDirectionStr() ;
+ }
+
+}
--
Gitblit v1.8.0