package com.fs.watch.controller;

import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.watch.domain.WatchTemperatureData;
import com.fs.watch.param.WatchDataQueryParam;
import com.fs.watch.service.WatchTemperatureDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/watch/temperature")
public class WatchTemperatureDataController extends BaseController {

    @Autowired
    private WatchTemperatureDataService watchTemperatureDataService;

    @PostMapping("/insert")
    public AjaxResult insertTemperatureData(@RequestBody WatchTemperatureData data){
        return AjaxResult.success(watchTemperatureDataService.insert(data));
    }

    /**
     * 查询某天的数据
     * @param  date 日期
     * @param  deviceId 主键
     * @return 查询某天的数据
     */
    @GetMapping("/queryByDateAndDeviceId")
    public AjaxResult queryByDateAndDeviceId(@RequestParam(value = "date",required = false) String date,
                                             @RequestParam(value = "deviceId") String deviceId) {
        return AjaxResult.success(this.watchTemperatureDataService.queryByDateAndDeviceId(date,deviceId));
    }

    /**
     * 查询某天的数据 分页
     * @param  param 查询参数
     * @return 查询某天的数据
     */
    @GetMapping("/page")
    public TableDataInfo page(WatchDataQueryParam param) {
        startPage();
        List<WatchTemperatureData> list =  this.watchTemperatureDataService.page(param);
        return getDataTable(list);
    }
}
