package com.zd.laboratory.controller;

import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.utils.poi.ExcelUtil;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.ResultData;
import com.zd.common.core.web.page.TableDataInfo;
import com.zd.common.log.annotation.Log;
import com.zd.common.log.enums.BusinessType;
import com.zd.common.security.annotation.PreAuthorize;
import com.zd.laboratory.domain.LabSparseHardware;
import com.zd.laboratory.service.ILabSparseHardwareService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 疏散硬件Controller
 *
 * @author liubo
 * @date 2022-01-25
 */
@RestController
@Api(tags = "【疏散硬件】")
@RequestMapping("/sparseHardware")
public class LabSparseHardwareController extends BaseController {
    @Autowired
    private ILabSparseHardwareService labSparseHardwareService;

    /**
     * 查询疏散硬件列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SPARSEHARDWARE + PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询疏散硬件列表")
    public TableDataInfo<LabSparseHardware> list(LabSparseHardware labSparseHardware) {
        startPage();
        List<LabSparseHardware> list = labSparseHardwareService.selectLabSparseHardwareList(labSparseHardware);
        return getDataTable(list);
    }

    /**
     * 导出疏散硬件列表
     */
    @ApiOperation(value = "导出疏散硬件列表")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SPARSEHARDWARE + PerFun.EXPORT)
    @Log(title = "疏散硬件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabSparseHardware labSparseHardware) throws IOException {
        List<LabSparseHardware> list = labSparseHardwareService.selectLabSparseHardwareList(labSparseHardware);
        ExcelUtil<LabSparseHardware> util = new ExcelUtil<LabSparseHardware>(LabSparseHardware.class);
        util.exportExcel(response, list, "疏散硬件数据");
    }

    /**
     * 获取疏散硬件详细信息
     */
    @ApiOperation(value = "获取疏散硬件详细信息")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SPARSEHARDWARE + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public ResultData<LabSparseHardware> getInfo(@PathVariable("id") Long id) {
        return ResultData.success(labSparseHardwareService.selectLabSparseHardwareById(id));
    }

    /**
     * 根据楼层获取摄像头列表
     */
    @ApiOperation(value = "根据楼层获取摄像头列表")
    @RequestMapping(value = "getCameraByFloor")
    public ResultData<List<String>> getCameraByFloor(Long floorId) {
        return ResultData.success(labSparseHardwareService.selectCameraByFloorId(floorId));
    }


    /**
     * 根据楼层获取摄像头列表
     */
    @ApiOperation(value = "根据楼层获取喇叭列表")
    @RequestMapping(value = "getSpeakerByFloor/{floorId}")
    public ResultData<List<Map<String,Object>>> getSpeakerByFloor(@PathVariable("floorId") Long floorId) {
        return ResultData.success(labSparseHardwareService.selectSpeakerByFloorId(floorId, null));
    }

    /**
     * 根据楼层获取摄像头列表
     */
    @ApiOperation(value = "根据楼层获取喇叭列表")
    @RequestMapping(value = "/getSpeaker/{floorId}/{subId}")
    public ResultData<List<Map<String,Object>>> getSpeakerBySub(
            @PathVariable("floorId") Long floorId, @PathVariable("subId") Long subId) {

        return ResultData.success(labSparseHardwareService.selectSpeakerByFloorId(floorId, subId));
    }


    /**
     * 新增疏散硬件
     */
    @ApiOperation(value = "新增疏散硬件")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SPARSEHARDWARE + PerFun.ADD)
    @Log(title = "疏散硬件", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody LabSparseHardware labSparseHardware) {
        return ResultData.result(labSparseHardwareService.insertLabSparseHardware(labSparseHardware));
    }

    /**
     * 修改疏散硬件
     */
    @ApiOperation(value = "修改疏散硬件")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SPARSEHARDWARE + PerFun.EDIT)
    @Log(title = "疏散硬件", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody LabSparseHardware labSparseHardware) {
        return ResultData.result(labSparseHardwareService.updateLabSparseHardware(labSparseHardware));
    }

    /**
     * 删除疏散硬件
     */
    @ApiOperation(value = "删除疏散硬件")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_SPARSEHARDWARE + PerFun.REMOVE)
    @Log(title = "疏散硬件", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids) {
        return ResultData.result(labSparseHardwareService.deleteLabSparseHardwareByIds(ids));
    }
}
