package com.fs.watch.controller;

import com.fs.common.core.domain.AjaxResult;
import com.fs.watch.domain.WatchBloodGlucoseData;
import com.fs.watch.service.WatchBloodGlucoseDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 血糖
 */
@RestController
@RequestMapping("/watch/blood/glucose")
public class WatchBloodGlucoseDataController {

    @Autowired
    private WatchBloodGlucoseDataService watchBloodGlucoseDataService;

    @PostMapping("/insert")
    public AjaxResult insertBloodGlucoseData(@RequestBody WatchBloodGlucoseData data){
        return AjaxResult.success(watchBloodGlucoseDataService.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.watchBloodGlucoseDataService.queryByDateAndDeviceId(date,deviceId));
    }

    /**
     * 查询某个时间段血糖数据
     *
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @param deviceId  设备编号
     * @return 查询某个时间段数据
     */
    @GetMapping("/list")
    public AjaxResult queryBgByDate(@RequestParam(value = "startTime") Date startTime,
                                    @RequestParam(value = "endTime") Date endTime,
                                    @RequestParam(value = "deviceId") String deviceId,
                                    @RequestParam(value = "status", required = false) Integer status) {
        return AjaxResult.success(this.watchBloodGlucoseDataService.queryBgByDate(startTime, endTime, deviceId, status));
    }
}
