package me.zhengjie.modules.front.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.annotation.Log;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.system.domain.BusDevice;
import me.zhengjie.modules.system.service.BusDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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;


@Slf4j
@RestController("DeviceController")
@RequestMapping("api/front/device")
@Api(tags = "微信：设备管理")
public class BusDeviceController {

    @Autowired private BusDeviceService busDeviceService;

    @Log("获取设备")
    @ApiOperation(value = "获取设备")
    @GetMapping(value = "/get")
    public ResponseEntity<BusDevice> get(@RequestParam String deviceCode) {
        BusDevice device = busDeviceService.getByDeviceCode(deviceCode);
        if (null == device) { throw new BadRequestException("未查询到设备"); }
        return new ResponseEntity<>(device, HttpStatus.OK);
    }

    @Log("绑定设备")
    @ApiOperation(value = "绑定设备")
    @GetMapping(value = "/bindingDevice")
    public ResponseEntity<Object> bindingDevice(@RequestParam String deviceCode) {
        busDeviceService.bindingDevice(deviceCode);
        return new ResponseEntity<>("绑定成功", HttpStatus.OK);
    }

}



