DeviceController.java 3.47 KB
package cn.com.glsx.modules.controller;

import cn.com.glsx.modules.service.DeviceService;
import com.glsx.plat.core.web.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * @author zhouhaibao
 * @date 2021/3/4 17:05
 */
@Controller
@RequestMapping("/device")
@Api(value = "设备管理", tags = {"设备管理"})
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    /**
     * 获取用户下的设备列表
     *
     * @return R
     */
    @RequestMapping(value = "/{uid}/devices", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取用户下的设备列表")
    public R getAllDevicesByUser(@PathVariable String uid) {
        return deviceService.getAllDevicesByUser(uid);
    }

    /**
     * 获取用户下的设备列表
     *
     * @return R
     */
    @RequestMapping(value = "/devices/{device_id}", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "根据id获取设备")
    public R getDevicesById(@PathVariable String device_id) {
        return deviceService.getDevicesById(device_id);
    }


    /**
     * 获取用户下的设备列表
     *
     * @return R
     */
    @RequestMapping(value = "/devices/{device_id}/functions", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "根据id获取指令集")
    public R getFunctionsById(@PathVariable String device_id) {
        return deviceService.getFunctionsById(device_id);
    }

    /**
     * 获取用户下的设备列表
     *
     * @return R
     */
    @RequestMapping(value = "/functions/{category}", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "根据品类获取指令集")
    public R getFunctionsByCat(@PathVariable String category) {
        return deviceService.getFunctionsByCat(category);
    }

    /**
     * 根据设备下发指令
     *
     * @return R
     */
    @RequestMapping(value = "/devices/{device_id}/commands", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "根据设备下发指令")
    public R instructionIssue(@PathVariable String device_id, @RequestBody String insjson) {
        return deviceService.instructionIssue(device_id, insjson);
    }

    /**
     * 获取红外设备下的设备列表
     *
     * @return R
     */
    @RequestMapping(value = "/infrareds/{infrared_id}/remotes", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取红外设备下面绑定的遥控器列表")
    public R findRemotes(@PathVariable String infrared_id) {
        return deviceService.findRemotes(infrared_id);
    }

    /**
     * 下发红外指令
     *
     * @return R
     */
    @RequestMapping(value = "/infrareds/{infrared_id}/{remote_id}/scenes/command", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "下发红外指令")
    public R instructionInfIssue(@PathVariable String infrared_id,@PathVariable String remote_id,@RequestBody String insjson) {
        return deviceService.instructionInfIssue(infrared_id,remote_id,insjson);
    }
}