package com.fastbee.data.controller.aaScreenAgricultural.deviceHistoryData;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.deviceData.domain.*;
import com.fastbee.deviceData.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author mijiupro
 */
@RestController
@RequestMapping("/device/history/data")
public class DeviceHistoryDataController extends BaseController {

    @Autowired
    private DeviceRealtimedataWormsMapper deviceRealtimedataWormsMapper;

    @Autowired
    private DeviceRealtimedataMoistureMapper deviceRealtimedataMoistureMapper;

    @Autowired
    private DeviceRealtimedataMiaoqingMapper deviceRealtimedataMiaoqingMapper;

    @Autowired
    private DeviceRealtimedataMeteorologyMapper deviceRealtimedataMeteorologyMapper;


    /**
     * 获取虫情设备历史数据
     */
    @GetMapping("/worms")
    public TableDataInfo getWormsHistoryData(DeviceRealtimedataWorms deviceRealtimedataWorms){
        startPage();
        //虫害图片
        List<DeviceRealtimedataWorms> list = new LambdaQueryChainWrapper<>(deviceRealtimedataWormsMapper)
                .eq(DeviceRealtimedataWorms::getDeviceAddr,deviceRealtimedataWorms.getDeviceAddr()).list();
        //虫害列表
        return getDataTable(list);
    }

    /**
     * 获取气象设备历史数据
     */
    @GetMapping("/meteorology")
    public TableDataInfo getMeteorologyHistoryData(DeviceRealtimedataMeteorology deviceRealtimedataMeteorology){
        startPage();
        List<DeviceRealtimedataMeteorology> list = new LambdaQueryChainWrapper<>(deviceRealtimedataMeteorologyMapper)
                .eq(DeviceRealtimedataMeteorology::getDeviceId,deviceRealtimedataMeteorology.getDeviceId())
                .orderByDesc(DeviceRealtimedataMeteorology::getRealTime)
                .list();
        return getDataTable(list);
    }
    /**
     * 获取墒情设备历史数据
     */
    @GetMapping("/moisture")
    public TableDataInfo getMoistureHistoryData(DeviceRealtimedataMoisture deviceRealtimedataMoisture){
        startPage();
        List<DeviceRealtimedataMoisture> list = new LambdaQueryChainWrapper<>(deviceRealtimedataMoistureMapper)
                .eq(DeviceRealtimedataMoisture::getDeviceId,deviceRealtimedataMoisture.getDeviceId())
                .orderByDesc(DeviceRealtimedataMoisture::getRealTime)
                .list();
        return getDataTable(list);
    }
    /**
     * 获取苗青实时数据
     */
    @GetMapping("/miaoqing")
    public TableDataInfo getMiaoqingHistoryData(DeviceRealtimedataMiaoqing deviceRealtimedataMiaoqing){
        startPage();
        List<DeviceRealtimedataMiaoqing> list = new LambdaQueryChainWrapper<>(deviceRealtimedataMiaoqingMapper)
                .eq(DeviceRealtimedataMiaoqing::getDeviceId,deviceRealtimedataMiaoqing.getDeviceId()).list();
        return getDataTable(list);
    }





}
