package com.securitycontrol.background.controller;

import com.securitycontrol.background.service.DeviceService;
import com.securitycontrol.common.core.domain.Result;
import com.securitycontrol.common.core.web.controller.BaseController;
import com.securitycontrol.common.core.web.page.TableDataInfo;
import com.securitycontrol.common.log.annotation.Log;
import com.securitycontrol.common.log.enums.OperationType;
import com.securitycontrol.entity.background.dto.DeviceBdDto;
import com.securitycontrol.entity.background.dto.DeviceDto;
import com.securitycontrol.entity.background.vo.DeviceBdVo;
import com.securitycontrol.entity.background.vo.DeviceVo;
import com.securitycontrol.entity.system.vo.DictVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**‘
 * 设备管理
 * @author 黑子
 */

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


    @Autowired
    private DeviceService service;

    @ApiOperation(value = "获取设备列表")
    @GetMapping("getDeviceList")
    @Log(title = "设备管理", menu = "设备管理->设备管理", grade = OperationType.QUERY_BUSINESS, details = "查询设备列表", type = "业务日志")
    public TableDataInfo getDeviceList(DeviceDto dto) {
        try{
            startPage();
            List<DeviceVo> list = service.getDeviceList(dto);
            return getDataTable(list);
        }catch (Exception e){
            log.error(e.toString(),e);
            return getDataTableBad(new ArrayList<>(),"请求出错了");
        }
    }

    /**
     * 新增设备
     *
     * @param dto
     * @return
     */
    @PostMapping("addDevice")
    @Log(title = "设备管理", menu = "设备管理->新增设备", grade = OperationType.ADD_BUSINESS, details = "查询设备列表", type = "业务日志")
    public Result<String> addDevice(@RequestBody @Valid DeviceVo dto) {
        return service.addDevice(dto);
    }


    /**
     * 新增设备
     *
     * @param dto
     * @return
     */
    @PostMapping("updateDevice")
    @Log(title = "设备管理", menu = "设备管理->修改设备", grade = OperationType.UPDATE_BUSINESS, details = "查询设备列表", type = "业务日志")
    public Result<String> updateDevice(@RequestBody @Valid DeviceVo dto) {
        return service.updateDevice(dto);
    }

    /**
     * 新增设备
     *
     * @param dto
     * @return
     */
    @PostMapping("deleteDevice")
    @Log(title = "设备管理", menu = "设备管理->注销设备", grade = OperationType.DELETE_BUSINESS, details = "查询设备列表", type = "业务日志")
    public Result<String> deleteDevice(@RequestBody @Valid DeviceVo dto) {
        return service.deleteDevice(dto);
    }
    /**
     * 新增设备
     *
     * @param dto
     * @return
     */
    @PostMapping("getDeviceDetail")
    public Result<DeviceVo> getDeviceDetail(@RequestBody @Valid DeviceDto dto) {
        return service.getDeviceDetail(dto);
    }


    /**
     * 查询安全帽的集合
     * @param dto
     * @return
     */
    @GetMapping("getDeviceListByType")
    public Result<List<DeviceVo>> getDeviceListByType(DeviceDto dto) {
        return service.getDeviceListByType(dto);
    }
}
