liurunyu
2025-08-14 989f463760203b62e9e5343e9a5ed1129c7e02d3
有wechat模块中增加查询水肥机、墒情站、气象站最新数据与在线情况
1个文件已修改
6个文件已添加
391 ■■■■■ 已修改文件
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttLastCtrl.java 111 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttLastSv.java 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttMonitorSv.java 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttSv.java 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoManureLast.java 40 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoSoilLast.java 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoWeatherLast.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttLastCtrl.java
New file
@@ -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("水肥机id不能为空") ;
            }
            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("墒情站id不能为空") ;
            }
            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("气象站id不能为空") ;
            }
            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()) ;
        }
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttLastSv.java
New file
@@ -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 ;
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/MqttMonitorSv.java
New file
@@ -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("通信中间件返回内部命令结果中不包含CommandBackParam类型参数");
                }
            }else{
                log.error("通信中间件返回内部命令执行失败" + (res.getMsg() == null? "" : ("," + res.getMsg()))) ;
            }
        }else{
            log.error("通信中间件返回内部命令结果为null");
        }
        return null ;
    }
}
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 ;
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoManureLast.java
New file
@@ -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 ;
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoSoilLast.java
New file
@@ -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 ;
    }
}
pipIrr-platform/pipIrr-web/pipIrr-web-wechat/src/main/java/com/dy/pipIrrWechat/mqtt/VoWeatherLast.java
New file
@@ -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() ;
    }
}