package com.fastbee.data.controller.aaScreenAgricultural;

import com.alibaba.druid.sql.ast.statement.SQLForeignKeyImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.deviceInfo.domain.*;
import com.fastbee.deviceInfo.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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/device/info")
public class DeviceInfoController extends BaseController {

    @Autowired
    private DeviceInformationWormsMapper deviceInformationWormsMapper;

    @Autowired
    private DeviceInformationMeteorologyMapper deviceInformationMeteorologyMapper;

    @Autowired
    private DeviceInformationMoistureMapper deviceInformationMoistureMapper;

    @Autowired
    private DeviceInformationTargetpestsMapper deviceInformationTargetpestsMapper;

    @Autowired
    private DeviceInformationMiaoqingMapper deviceInformationMiaoqingMapper;

    @Autowired
    private DeviceInformationMonitorMapper deviceInformationMonitorMapper;


    /**
     * 查询全部设备立杆列表
     */
    @GetMapping("/allList")
    public AjaxResult getAllList() {
        List<Map<String, Object>> result =new ArrayList<>();
        //气象
        LambdaQueryWrapper<DeviceInformationMeteorology> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.select(DeviceInformationMeteorology::getId,DeviceInformationMeteorology::getName,
                DeviceInformationMeteorology::getLongitude,DeviceInformationMeteorology::getLatitude,
                DeviceInformationMeteorology::getDeviceEncoding);
        List<DeviceInformationMeteorology> deviceInformationMeteorologies = deviceInformationMeteorologyMapper.selectList(queryWrapper1);
        Map<String,Object> obj1=new HashMap<>();
        obj1.put("type","气象");
        obj1.put("data",deviceInformationMeteorologies);
        result.add(obj1);
        //虫情
        LambdaQueryWrapper<DeviceInformationWorms> queryWrapper2 = new LambdaQueryWrapper<>();
        queryWrapper2.select(DeviceInformationWorms::getId,DeviceInformationWorms::getName,
                DeviceInformationWorms::getLongitude,DeviceInformationWorms::getLatitude,
                DeviceInformationWorms::getDeviceEncoding);
        List<DeviceInformationWorms> deviceInformationWorms = deviceInformationWormsMapper.selectList(queryWrapper2);
        Map<String,Object> obj2=new HashMap<>();
        obj2.put("type","虫情");
        obj2.put("data",deviceInformationWorms);
        result.add(obj2);

        //墒情
        LambdaQueryWrapper<DeviceInformationMoisture> queryWrapper3 = new LambdaQueryWrapper<>();
        queryWrapper3.select(DeviceInformationMoisture::getId,DeviceInformationMoisture::getName,
                DeviceInformationMoisture::getLongitude,DeviceInformationMoisture::getLatitude,
                DeviceInformationMoisture::getDeviceEncoding);
        List<DeviceInformationMoisture> deviceInformationMoistures = deviceInformationMoistureMapper.selectList(queryWrapper3);
        Map<String,Object> obj3=new HashMap<>();
        obj3.put("type","墒情");
        obj3.put("data",deviceInformationMoistures);
        result.add(obj3);

        //杀虫灯
        LambdaQueryWrapper<DeviceInformationTargetpests> queryWrapper4 = new LambdaQueryWrapper<>();
        queryWrapper4.select(DeviceInformationTargetpests::getId,DeviceInformationTargetpests::getName,
                DeviceInformationTargetpests::getLongitude,DeviceInformationTargetpests::getLatitude,
                DeviceInformationTargetpests::getDeviceEncoding);
        List<DeviceInformationTargetpests> deviceInformationTargetpests = deviceInformationTargetpestsMapper.selectList(queryWrapper4);
        Map<String,Object> obj4=new HashMap<>();
        obj4.put("type","杀虫灯");
        obj4.put("data",deviceInformationTargetpests);
        result.add(obj4);

        //苗情
        LambdaQueryWrapper<DeviceInformationMiaoqing> queryWrapper5 = new LambdaQueryWrapper<>();
        queryWrapper5.select(DeviceInformationMiaoqing::getId,DeviceInformationMiaoqing::getName,
                DeviceInformationMiaoqing::getLongitude,DeviceInformationMiaoqing::getLatitude,
                DeviceInformationMiaoqing::getDeviceEncoding);
        List<DeviceInformationMiaoqing> deviceInformationMiaoqings = deviceInformationMiaoqingMapper.selectList(queryWrapper5);
        Map<String,Object> obj5=new HashMap<>();
        obj5.put("type","苗情");
        obj5.put("data",deviceInformationMiaoqings);
        result.add(obj5);

        //监控
        LambdaQueryWrapper<DeviceInformationMonitor> queryWrapper6 = new LambdaQueryWrapper<>();
        queryWrapper6.select(DeviceInformationMonitor::getId,DeviceInformationMonitor::getName,
                DeviceInformationMonitor::getLongitude,DeviceInformationMonitor::getLatitude,
                DeviceInformationMonitor::getDeviceEncoding);
        List<DeviceInformationMonitor> deviceInformationMonitors = deviceInformationMonitorMapper.selectList(queryWrapper6);
        Map<String,Object> obj6=new HashMap<>();
        obj6.put("type","监控");
        obj6.put("data",deviceInformationMonitors);
        result.add(obj6);
        return success(result);

    }

    /**
     * 查询气象设备列表
     */
    @GetMapping("/weatherList")
    public AjaxResult getDeviceList() {
        LambdaQueryWrapper<DeviceInformationMeteorology> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(DeviceInformationMeteorology::getId,DeviceInformationMeteorology::getName,
                DeviceInformationMeteorology::getLongitude,DeviceInformationMeteorology::getLatitude);
        return success(deviceInformationMeteorologyMapper.selectList(queryWrapper));
    }


    /**
     * 查询虫情设备列表
     */
    @GetMapping("/wormList")
    public AjaxResult getWeatherList() {
        LambdaQueryWrapper<DeviceInformationWorms> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(DeviceInformationWorms::getId,DeviceInformationWorms::getName,
                DeviceInformationWorms::getLongitude,DeviceInformationWorms::getLatitude);
        return success(deviceInformationWormsMapper.selectList(queryWrapper));
    }

    /**
     * 查询墒情设备列表
     */
    @GetMapping("/soilList")
    public AjaxResult getSoilList() {
        LambdaQueryWrapper<DeviceInformationMoisture> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(DeviceInformationMoisture::getId,DeviceInformationMoisture::getName,
                DeviceInformationMoisture::getLongitude,DeviceInformationMoisture::getLatitude);
        return success(deviceInformationMoistureMapper.selectList(queryWrapper));
    }
    /**
     * 查询杀虫灯设备列表
     */
    @GetMapping("/lightList")
    public AjaxResult getLightList() {
        LambdaQueryWrapper<DeviceInformationTargetpests> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(DeviceInformationTargetpests::getId,DeviceInformationTargetpests::getName,
                DeviceInformationTargetpests::getLongitude,DeviceInformationTargetpests::getLatitude);
        return success(deviceInformationTargetpestsMapper.selectList(queryWrapper));
    }
    /**
     * 查询苗情设备列表
     */
    @GetMapping("/miaoList")
    public AjaxResult getmiaoList() {
        LambdaQueryWrapper<DeviceInformationMiaoqing> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(DeviceInformationMiaoqing::getId,DeviceInformationMiaoqing::getName,
                DeviceInformationMiaoqing::getLongitude,DeviceInformationMiaoqing::getLatitude);
        return success(deviceInformationMiaoqingMapper.selectList(queryWrapper));
    }
    /**
     * 查询监控站设备列表
     */
    @GetMapping("/monitorList")
    public AjaxResult getmonitorList() {
        LambdaQueryWrapper<DeviceInformationMonitor> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(DeviceInformationMonitor::getId,DeviceInformationMonitor::getName,
                DeviceInformationMonitor::getLongitude,DeviceInformationMonitor::getLatitude);
        return success(deviceInformationMonitorMapper.selectList(queryWrapper));
    }
}
