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

import com.yuchen.saas.park.api.vo.park.devicepro.DeviceBasePro;
import com.yuchen.saas.park.service.service.PmgBatParkPerceiveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.nest.springwrap.core.tool.api.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 肖润飞
 * @CreateTime: 2022/09/07 10:47
 * @Description: 智慧物联网感知数据控制类
 * @Version: 1.0
 */
@Api(tags = "智慧物联网感知数据")
@RestController
@RequestMapping("/parking/perceive")
public class PmgBatParkPerceiveController {

    @Resource
    private PmgBatParkPerceiveService pmgBatParkPerceiveService;


    @GetMapping("/getDeviceListByType/{type}")
    @ApiOperation(value = "获取设备数据列表")
    @ApiImplicitParam(required = true, name = "type", value = "分类", defaultValue = "enum", dataType = "String")
    public R getDeviceList(@PathVariable("type") String type, String parkId) {
        List<DeviceBasePro> res = pmgBatParkPerceiveService.getDeviceList(type, parkId);
        return R.data(res);
    }

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

    @GetMapping("/getDeviceList")
    @ApiOperation(value = "根据设备的列表展示")
    @ApiImplicitParam(required = true, name = "parkId", value = "园区id", dataType = "String")
    public R getDeviceList(@RequestParam String parkId) {
        HashMap<String, Object> res = pmgBatParkPerceiveService.getDeviceList(parkId);
        return R.data(res);
    }

    @GetMapping("/upOrDownDeviceFeign")
    @ApiOperation(value = "对指定设备缓存进行上线/下线设置")
    @ApiImplicitParam(required = true, name = "parkId", value = "园区id", dataType = "String")
    public R upOrDownDeviceFeign(@RequestParam String upOrDown, @RequestParam String productKey,@RequestParam String deviceName,@RequestParam String parkId) {
        return pmgBatParkPerceiveService.upOrDownDevice(upOrDown,productKey,deviceName,Long.parseLong(parkId));
    }

    @GetMapping("/getDeviceListByProductKeys")
    @ApiOperation(value = "根据设备的列表展示")
    @ApiImplicitParam(required = true, name = "parkId", value = "园区id", dataType = "String")
    public R getDeviceListByProductKey(@RequestParam String parkId) {
        Map<String, Object> res = pmgBatParkPerceiveService.getDeviceListByProductKeys(parkId);
        return R.data(res);
    }

}