package com.zd.laboratory.controller;

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

import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.zd.common.core.domain.per.PerFun;
import com.zd.common.core.domain.per.PerPrefix;
import com.zd.common.core.web.domain.ResultData;
import com.zd.laboratory.domain.vo.LabExitLineJoinVO;
import com.zd.laboratory.domain.vo.LabExitLineVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RestController;
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.LabExitLine;
import com.zd.laboratory.service.ILabExitLineService;
import com.zd.common.core.web.controller.BaseController;
import com.zd.common.core.web.domain.AjaxResult;
import com.zd.common.core.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.zd.common.swagger.config.Knife4jConfiguration;

import com.zd.common.core.web.page.TableDataInfo;

/**
 * 逃生线路主Controller
 *
 * @author zd
 * @date 2022-01-25
 */
@RestController
@Api(tags = "【逃生线路主】")
//作者手动加入 ，在接口上加作者@ApiOperationSupport(author = "XXX")
@ApiSupport(author = Knife4jConfiguration.Author.CYL)
@RequestMapping("/line")
public class LabExitLineController extends BaseController {
    @Autowired
    private ILabExitLineService labExitLineService;

    /**
     * 查询逃生线路主列表
     */
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_LINE + PerFun.LIST)
    @GetMapping("/list")
    @ApiOperation(value = "查询逃生线路主列表")
    public TableDataInfo<LabExitLineVO> list(LabExitLine labExitLine) {
        startPage();
        List<LabExitLineVO> list = labExitLineService.selectLabExitLineList(labExitLine);
        return getDataTable(list);
    }

    /**
     * 导出逃生线路主列表
     */
    @ApiOperation(value = "导出逃生线路主列表")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_LINE + PerFun.EXPORT)
    @Log(title = "逃生线路主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LabExitLine labExitLine) throws IOException {
        List<LabExitLineVO> list = labExitLineService.selectLabExitLineList(labExitLine);
        ExcelUtil<LabExitLineVO> util = new ExcelUtil<LabExitLineVO>(LabExitLineVO.class);
        util.exportExcel(response, list, "逃生线路主数据");
    }

    /**
     * 获取逃生线路主详细信息
     */
    @ApiOperation(value = "获取逃生线路主详细信息")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_LINE + PerFun.QUERY)
    @GetMapping(value = "/{id}")
    public ResultData<LabExitLineVO> getInfo(@PathVariable("id") Long id) {
        return ResultData.success(labExitLineService.selectLabExitLineById(id));
    }


    /**
     * 获取逃生线路主详细信息
     */
    @ApiOperation(value = "获取逃生线路主详细信息")
    @GetMapping(value = "/IntelligentGuidance/{subId}/{dire}")
    public ResultData getGuidance(@PathVariable("subId") Long subId, @PathVariable("dire") Integer dire) {
        return ResultData.success(labExitLineService.selectLabExitLineIntelligentGuidance(subId, dire));
    }

    /**
     * 新增逃生线路主
     */
    @ApiOperation(value = "新增逃生线路主")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_LINE + PerFun.ADD)
    @Log(title = "逃生线路主", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultData add(@RequestBody LabExitLine labExitLine) {
        return ResultData.result(labExitLineService.insertLabExitLine(labExitLine));
    }

    /**
     * 新增逃生线路相关数据
     */
    @ApiOperation(value = "新增逃生线路相关数据")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_LINE + PerFun.ADD)
    @Log(title = "逃生线路主", businessType = BusinessType.INSERT)
    @PostMapping("/addExitJoin")
    public ResultData addExitJoin(@RequestBody LabExitLineVO labExitLineVO) {
        return ResultData.result(labExitLineService.addExitJoin(labExitLineVO));
    }

    /**
     * 修改逃生线路主
     */
    @ApiOperation(value = "修改逃生线路主")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_LINE + PerFun.EDIT)
    @Log(title = "逃生线路主", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultData edit(@RequestBody LabExitLine labExitLine) {
        return ResultData.result(labExitLineService.updateLabExitLine(labExitLine));
    }

    /**
     * 删除逃生线路主
     */
    @ApiOperation(value = "删除逃生线路主")
    @PreAuthorize(hasPermi = PerPrefix.LABORATORY_LINE + PerFun.REMOVE)
    @Log(title = "逃生线路主", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public ResultData remove(@PathVariable Long[] ids) {
        return ResultData.result(labExitLineService.deleteLabExitLineByIds(ids));
    }

    /**
     * 实验室执行应急疏散
     */
    @ApiOperation(value = "实验室执行应急疏散")
    @GetMapping(value = "/evacuate/{subId}")
    public ResultData doEvacuate(@PathVariable("subId") Long subId) {
        return ResultData.success(labExitLineService.doEvacuate(subId));
    }

    /**
     * 实验室结束应急疏散
     */
    @ApiOperation(value = "实验室结束应急疏散")
    @GetMapping(value = "/closure/{subId}")
    public ResultData doClosure(@PathVariable("subId") Long subId) {
        labExitLineService.doClosure(subId);
        return ResultData.success();
    }

    /**
     * 实验室切换应急疏散线路
     *
     * @param type 1是向左疏散，2是向右疏散，0是两侧疏散
     */
    @ApiOperation(value = "实验室切换应急疏散线路")
    @GetMapping(value = "/change/{subId}/{type}")
    public ResultData doChange(@PathVariable("subId") Long subId, @PathVariable("type") Integer type) {
        return ResultData.success(labExitLineService.doChange(subId, type));
    }

    /**
     * 获取逃生线路缓存数据
     */
    @ApiOperation(value = "获取逃生线路缓存数据")
    @GetMapping(value = "/getRedis")
    public ResultData getRedis() {
        return ResultData.success(labExitLineService.getRedis());
    }


    /**
     * 实验室查询切换线路
     * @param subId 实验室ID
     * @param type 1是向左疏散，2是向右疏散，0是两侧疏散， 否则-1
     */
    @ApiOperation(value = "实验室切换应急疏散线路")
    @GetMapping(value = "/getRoute/{subId}/{type}")
    public ResultData getRoute(@PathVariable("subId") Long subId, @PathVariable("type") Integer type) {
        return ResultData.success(labExitLineService.getRoute(subId, type));
    }

}
