package com.fastbee.data.controller.devicedetail;

import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.core.domain.CommonResult;
import com.fastbee.common.model.vo.iot.QueryLogVo;
import com.fastbee.data.service.devicedetail.IDeviceDetailService;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.model.haiwei.CmdHaiWeiVo;
import com.fastbee.iot.model.haiwei.dto.CmdHaiWeiDto;
import com.fastbee.waterele.domain.MaWatereleRecord;
import com.fastbee.waterele.domain.dto.MaGuangaiRecordDto;
import com.fastbee.waterele.domain.dto.MaWatereleRecordDto;
import com.fastbee.xunjian.domain.XjInspectionRecords;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "设备详情数据")
@RestController
@RequestMapping("/device/detail")
public class DeviceDetailController  extends BaseController {


    @Autowired
    IDeviceDetailService deviceDetailService;

    /**
     * 查询设备刷卡记录
     * @param maWatereleRecordDto 传参
     * @return com.fastbee.common.core.domain.AjaxResult
     */
    @ApiOperation("查询刷卡记录")
    @GetMapping("/shuakaRecord")
    public AjaxResult shuakaRecord(MaWatereleRecordDto maWatereleRecordDto)
    {
        if (null == maWatereleRecordDto.getDeviceId() || maWatereleRecordDto.getDeviceId() == 0L) {
            return AjaxResult.error("请选择设备");
        }
        List<MaWatereleRecord> list = deviceDetailService.shuakaRecord(maWatereleRecordDto);
        return AjaxResult.success(list);
    }





    /**
     * 查询灌溉记录
     * @param maWatereleRecordDto 传参
     * @return com.fastbee.common.core.domain.AjaxResult
     */
    @ApiOperation("查询灌溉记录")
    @GetMapping("/guangaiRecord")
    public AjaxResult guangaiRecord(MaGuangaiRecordDto maWatereleRecordDto)
    {
        if (null == maWatereleRecordDto.getDeviceId() || maWatereleRecordDto.getDeviceId() == 0L) {
            return AjaxResult.error("请选择设备");
        }
        List<MaGuangaiRecordDto> list = deviceDetailService.guangaiRecord(maWatereleRecordDto);
        return AjaxResult.success(list);
    }

    /**
     * 获取绑定设备列表
     * @param ids 传参
     * @return com.fastbee.common.core.domain.AjaxResult
     */
    @ApiOperation("获取绑定设备列表")
    @GetMapping("/getBindDevices")
    public AjaxResult getBindDevices(String ids)
    {
        List<Device> list = deviceDetailService.getBindDevices(ids);
        return AjaxResult.success(list);
    }

    /**
     * 查询供电数据
     * @param queryLogVo 传参
     * @return com.fastbee.common.core.domain.AjaxResult
     */
    @ApiOperation("查询供电数据")
    @GetMapping("/gongdianChart")
    public AjaxResult gongdianChart(QueryLogVo queryLogVo)
    {
        if (null == queryLogVo.getDeviceId() || queryLogVo.getDeviceId() == 0L) {
            return AjaxResult.error("请选择设备");
        }
        //设备历史echart数据
        List<Object> list = deviceDetailService.gongdianChart(queryLogVo);
        AjaxResult ajaxResult = AjaxResult.success();
        ajaxResult.put("data", list);
        ajaxResult.put("realData", deviceDetailService.gongdianRealData(queryLogVo));
        return ajaxResult;
    }

    /**
     * 查询用水数据
     * @param queryLogVo 传参
     * @return com.fastbee.common.core.domain.AjaxResult
     */
    @ApiOperation("查询用水数据")
    @GetMapping("/yongshuiChart")
    public AjaxResult yongshuiChart(QueryLogVo queryLogVo)
    {
        if (null == queryLogVo.getDeviceId() || queryLogVo.getDeviceId() == 0L) {
            return AjaxResult.error("请选择设备");
        }
        //设备历史echart数据
        List<Object> list = deviceDetailService.yongshuiChart(queryLogVo);
        AjaxResult ajaxResult = AjaxResult.success();
        ajaxResult.put("data", list);
        ajaxResult.put("realData", deviceDetailService.yongshuiRealData(queryLogVo));
        return ajaxResult;
    }


    /**
     * 查询巡检记录
     * @param queryLogVo 传参
     * @return com.fastbee.common.core.domain.AjaxResult
     */
    @ApiOperation("查询巡检记录")
    @GetMapping("/xunjianRecord")
    public AjaxResult xunjianRecord(QueryLogVo queryLogVo)
    {
        if (null == queryLogVo.getDeviceId() || queryLogVo.getDeviceId() == 0L) {
            return AjaxResult.error("请选择设备");
        }
        List<XjInspectionRecords> list = deviceDetailService.xunjianRecord(queryLogVo);
        return AjaxResult.success(list);
    }

    /**
     * 获取安防信息
     * @param deviceId 传参
     * @return com.fastbee.common.core.domain.AjaxResult
     */
    @ApiOperation("获取安防信息")
    @GetMapping("/anfangInfo")
    public AjaxResult anfangInfo(Long deviceId)
    {
        if (null == deviceId || deviceId == 0L) {
            return AjaxResult.error("请传入设备号");
        }
        return AjaxResult.success(deviceDetailService.anfangInfo(deviceId));
    }
    @ApiOperation("箱门打开控制")
    @PostMapping("/hwcmd")
    public CommonResult<CmdHaiWeiVo> cmdDevices(@RequestBody CmdHaiWeiDto cmdHwDto) {
        return deviceDetailService.cmdDevices(cmdHwDto);
    }







}
