package net.vtstar.zhongtong.avi.equipment.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.utils.domain.Return;
import net.vtstar.zhongtong.avi.equipment.domain.EquipInfo;
import net.vtstar.zhongtong.avi.equipment.service.DryingRoomTempService;
import net.vtstar.zhongtong.avi.gateway.painting.domain.DryingRoomTempMachine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Author: xiadongwei
 * @Date: 2019/11/15 9:54
 */
@Slf4j
@Api(description = "烘干室温度模块")
@RequestMapping("/api/dryingRoom")
@RestController
public class DryingRoomTempController {

    @Autowired
    private DryingRoomTempService service;

    @ApiOperation(value = "查询温度状态列表", response = EquipInfo.class, responseContainer = "List", notes =
            "入参：\n{\n" +
            "  \"equipCode\": \"设备编号，字符串类型, 可以为空\",\n" +
            "  \"beginTime\": \"指定日期，Data类型, (yyyy-MM-dd), 可以为空, 默认当天\",\n" +
            "}")
    @GetMapping("/equipPage")
    public Return getDryingRoomState(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize,
                                     @RequestParam(value = "equipCode", required = false) String equipCode,
                                     @RequestParam(value = "beginTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date beginTime){
        return Return.success(new PageInfo<>(service.findPageEquip(pageNum, pageSize, equipCode, beginTime)));
    }

    @ApiOperation(value = "获取指定时间内的温度表", response = DryingRoomTempMachine.class, responseContainer = "List", notes =
            "入参：\n{\n" +
                    "  \"beginTime\": \"开始时间，String类型, (yyyy-MM-dd HH:mm:ss)\",\n" +
                    "  \"endTime\": \"结束时间，String类型, (yyyy-MM-dd HH:mm:ss)\"\n" +
                    "}")
    @GetMapping("/temp")
    public Return getTempByStateId(@RequestParam(value = "equipCode") String equipCode,
                                   @RequestParam(value = "beginTime")String beginTime,
                                   @RequestParam(value = "endTime") String endTime){
        return Return.success(service.getTempByStateId(equipCode, beginTime, endTime));
    }
}
