package com.bonus.bracelet.controller;

import com.bonus.bracelet.service.IDeviceService;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.entity.bracelet.vo.*;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.RequiresPermissions;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * DeviceController
 */
@RestController
@RequestMapping("/device/")
@Slf4j
public class DeviceController extends BaseController {

    @Resource(name = "IDeviceService")
    private IDeviceService deviceservice;


    /**
     * 展示设备列表
     * @param data
     * @return
     */
    @GetMapping("list")
    @SysLog(title = "设备管理", businessType = OperaType.QUERY,  module = "基础管理->设备管理", details = "查询设备列表")
    public TableDataInfo list(DeviceVo data) {
        startPage();
        List<DeviceVo> list = deviceservice.getDeviceLists(data);
        return getDataTable(list);
    }

    /**
     * 根据设备id获取详细信息
     */
    @RequiresPermissions("bracelet:device:query")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable Integer deviceId) {
        return deviceservice.selectDeviceById(deviceId);
    }

    /**
     * 新增边带信息
     * @param vo
     * @return
     */
    @PostMapping("addDevice")
    @SysLog(title = "设备管理", businessType = OperaType.INSERT,  module = "基础管理->设备管理", details = "新增设备")
    public AjaxResult addDevice(@Validated @RequestBody DeviceVo vo) {
        return deviceservice.addDevice(vo);
    }

    /**
     * 修改设备信息
     * @param vo
     * @return
     */
    @PostMapping("editDevice")
    @SysLog(title = "设备管理", businessType = OperaType.UPDATE, module = "基础管理->设备管理", details = "修改设备")
    public AjaxResult editDevice(@Validated @RequestBody DeviceVo vo) {
        return deviceservice.editDevice(vo);
    }
    /**
     * 删除设备
     */

    @PostMapping("delDevice")
    @SysLog(title = "设备管理", businessType = OperaType.UPDATE,module = "基础管理->设备管理",details = "删除设备")
    public AjaxResult delDevice(@RequestBody DeviceVo vo) {
            return deviceservice.deleteDeviceById(vo.getDeviceId());

    }

}
