package com.rehome.mqttclienttemperature.controller;


import com.rehome.mqttclienttemperature.dto.RequestNowTemperatureDto;
import com.rehome.mqttclienttemperature.dto.RequestTemperatureDto;
import com.rehome.mqttclienttemperature.entity.Temperature;
import com.rehome.mqttclienttemperature.response.Result;
import com.rehome.mqttclienttemperature.service.TemperatureService;
import jakarta.annotation.Resource;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import java.util.List;

/**
 * @author HuangWenfei
 * App自动更新
 * 2024-10-16 11:11
 */
@RestController
@CrossOrigin
@RequestMapping("/web/temperature")
public class TemperatureController {
    @Resource
    private TemperatureService temperatureService;

    /**
     * APP更新版本号
     */
    @PostMapping("/getHistoryTemperatureByTen")
    private List<Temperature> getHistoryTemperatureByTen(@RequestBody @Validated RequestTemperatureDto dto) {
        return temperatureService.findFirst10ByDataDateAndLocationDesc(dto.getDataDate(),dto.getLocationDesc());
    }

    /**
     * APP更新版本号
     */
    @PostMapping("/getRealTemperatureByTen")
    private List<Temperature> getRealTemperatureByTen(@RequestBody @Validated RequestNowTemperatureDto dto) {
        return temperatureService.findFirst10ByLocationDesc(dto.getLocationDesc());
    }

    /**
     *
     */
    @PostMapping("/findFirstByOrderByLocationDescAsc")
    private Temperature findFirstByOrderByLocationDescAsc(@RequestBody @Validated RequestNowTemperatureDto dto) {
        return temperatureService.findFirstByOrderByLocationDescAsc(dto.getLocationDesc());
    }

    /**
     * APP更新版本号
     */
    @PostMapping("/queryFirst10ByDataDateAndLocationDesc")
    private List<Temperature> queryFirst10ByDataDateAndLocationDesc(@RequestBody @Validated RequestTemperatureDto dto) {
        return temperatureService.queryFirst10ByDataDateAndLocationDesc(dto.getDataDate(),dto.getLocationDesc());
    }


}
