package com.yuchen.saas.park.service.controller.screen;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yuchen.saas.park.service.service.EnergyConsumptionService;
import com.yuchen.saas.park.service.service.FireControlService;
import com.yuchen.saas.park.service.service.IrrigationService;
import com.yuchen.saas.park.service.service.PmgBatSmartEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.nest.springwrap.core.tool.api.R;
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 javax.annotation.Resource;
import java.util.Map;

/**
 * @ClassName TorchScreenController
 * @Description 火炬广场可视化接口
 * @Author 张逸飞
 * @Date 2022/9/15 15:38
 */
@RestController
@AllArgsConstructor
@RequestMapping("/torchScreen")
@Api(value = "火炬广场可视化接口", tags = "火炬广场可视化接口")
public class TorchScreenController {

    /**
     * 注入能耗统计相关接口
     */
    @Resource
    private EnergyConsumptionService energyConsumptionService;

    /**
     * 注入灌溉相关接口
     */
    @Resource
    private IrrigationService irrigationService;

    /**
     * 注入园区设备相关接口
     */
    @Resource
    private PmgBatSmartEquipmentService smartEquipmentService;

    /**
     * 注入消防相关接口
     */
    @Resource
    private FireControlService fireControlService;

    /**
     * 可视化-》能耗管理-》统计、趋势、排名
     * @param parkId 园区ID
     * @return
     */
    @GetMapping("/energyConsumption/getDeviceCount")
    @ApiOperation(value = "能耗管理可视化")
    public R getEnergyConsumptionCount(@RequestParam Long parkId) {
        Map<String, Object> res = energyConsumptionService.getDeviceCount(parkId);
        return R.data(res);
    }


    /**
     * 可视化-》能耗管理-》点击下边的水电数据排名,显示统计数据
     * @param parkId 园区ID
     * @param productKey 设备key
     * @param deviceName 设备ID
     * @return
     */
    @GetMapping("/energyConsumption/singleDevice")
    @ApiOperation(value = "能耗管理可视化")
    public R singleDevice(@RequestParam Long parkId,String productKey,String deviceName) {
        Map<String, Object> res = energyConsumptionService.singleDevice(parkId,productKey,deviceName);
        return R.data(res);
    }

    @GetMapping("/energyConsumption/deviceNumber")
    @ApiOperation(value = "园区设备数量查询")
    public R deviceNumber(@RequestParam(required = false) String[] productKey, @RequestParam String parkId) {
        Map<String, Object> res = energyConsumptionService.deviceNumber(productKey, parkId);
        return R.data(res);
    }

    /**
     * 可视化-》智慧浇灌-》统计、设备列表
     * @param parkId 园区ID
     * @return
     */
    @GetMapping("/irrigation/getDeviceCount")
    @ApiOperation(value = "智慧浇灌可视化")
    public R getIrrigationCount(@RequestParam Long parkId) {
        Map<String, Object> res = irrigationService.getDeviceCount(parkId);
        return R.data(res);
    }

    /**
     * 获得灌溉湿度界限值
     * @param parkId 园区ID
     * @return
     */
    @GetMapping("/irrigation/getBoundaryValue")
    @ApiOperation(value = "智慧浇灌可视化")
    public R getBoundaryValue(@RequestParam Long parkId) {
        return R.data(irrigationService.getBoundaryValue(parkId));
    }

    /**
     * 设置灌溉湿度界限值
     * @param parkId 园区ID
     * @param lowValue 界限低值
     * @param highValue 界限高值
     * @return
     */
    @GetMapping("/irrigation/setBoundaryValue")
    @ApiOperation(value = "智慧浇灌可视化")
    public R setBoundaryValue(@RequestParam Long parkId, @RequestParam Float lowValue, @RequestParam Float highValue) {
        return R.status(irrigationService.setBoundaryValue(parkId,lowValue,highValue));
    }

    /**
     * 可视化-》智慧浇灌-》灌溉控制
     * @param productKey 设备的productKey
     * @param deviceName 设备的deviceName
     * @param status 要控制的状态
     * @return
     */
    @GetMapping("/irrigation/irrigationControl")
    @ApiOperation(value = "灌溉控制")
    public R irrigationControl(@RequestParam String productKey, @RequestParam String deviceName, Boolean status) {
        return R.status(irrigationService.irrigationControl(productKey,deviceName,status));
    }

    /**
     * 可视化-》智慧消防-》概况、设备列表、告警事件、巡检统计
     * @param parkId 园区ID
     * @param productKeys 设备 productKey 逗号分割
     * @return
     */
    @GetMapping("/fireControl/getDeviceCount")
    @ApiOperation(value = "智慧消防可视化")
    public R getFireControlCount(@RequestParam Long parkId, @RequestParam String productKeys) {
        Map<String, Object> res = fireControlService.getDeviceCount(parkId, productKeys);
        return R.data(res);
    }

    /**
     * 根据分类分页查询设备数据
     * @param parkId 园区ID
     * @param name 设备名称
     * @param categoryName 设备分类
     * @param isOnline 设备是否在线(1:在线，0:离线)
     * @param current 当前页码
     * @param size 每页数量
     * @return
     */
    @GetMapping("/smartEquipment/getByCode")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "根据分类分页查询设备数据", notes = "根据分类分页查询设备数据")
    public R getDeviceByCode(@RequestParam Long parkId,
                       @RequestParam String name,
                       @RequestParam String categoryName,
                       @RequestParam Integer isOnline,
                       @RequestParam Integer current,
                       @RequestParam Integer size){
        return R.data(smartEquipmentService.getDeviceByCode(parkId,name,categoryName,isOnline,current,size));
    }

    /**
     * 根据分类查询设备分类统计数据
     * @param parkId 园区ID
     * @return
     */
    @GetMapping("/smartEquipment/getDeviceCountByCode")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "根据分类查询设备分类统计数据", notes = "根据分类查询设备分类统计数据")
    public R getDeviceCountByCode(@RequestParam Long parkId){
        return R.data(smartEquipmentService.getDeviceCountByCode(parkId));
    }

    /**
     * 根据 productKey 分页查询设备数据
     * @param parkId 园区ID
     * @param name 设备名称
     * @param categoryName 设备分类
     * @param productKeys 设备 productKey 逗号分割
     * @param isOnline 设备是否在线(1:在线，0:离线)
     * @param current 当前页码
     * @param size 每页数量
     * @return
     */
    @GetMapping("/smartEquipment/getDeviceByProductKey")
    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "根据 productKey 分页查询设备数据", notes = "根据 productKey 分页查询设备数据")
    public R getDeviceByProductKey(@RequestParam Long parkId,
                                   @RequestParam String name,
                                   @RequestParam String categoryName,
                                   @RequestParam String productKeys,
                                   @RequestParam Integer isOnline,
                                   @RequestParam Integer current,
                                   @RequestParam Integer size){
        return R.data(smartEquipmentService.getDeviceByProductKey(parkId,name,categoryName,productKeys,isOnline,current,size));
    }
}
