package com.dy.pipIrrWechat.mqtt; 
 | 
  
 | 
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") 
 | 
    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") 
 | 
    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") 
 | 
    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()) ; 
 | 
        } 
 | 
    } 
 | 
  
 | 
} 
 |