package com.yanzhu.jh.video.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.SysRoleEnum;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysDeptService;
import com.yanzhu.jh.video.domain.SurProjectVideoConfig;
import com.yanzhu.jh.video.domain.SurProjectVideoPassage;
import com.yanzhu.jh.video.service.ISurProjectVideoConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 视频配置Controller
 * 
 * @author JiangYuQi
 * @date 2023-08-25
 */
@RestController
@RequestMapping("/video/videoConfig")
public class SurProjectVideoConfigController extends BaseController
{
    @Autowired
    private ISysDeptService sysDeptService;

    @Autowired
    private ISurProjectVideoConfigService surProjectVideoConfigService;

    /**
     * 查询视频配置列表
     */
    @PreAuthorize("@ss.hasPermi('video:videoConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(SurProjectVideoConfig surProjectVideoConfig)
    {
        startPage();
        surProjectVideoConfig.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(surProjectVideoConfig.getNowRole())){
            surProjectVideoConfig.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            surProjectVideoConfig.setNowDept(Convert.toStr(getDeptId()));
        }
        surProjectVideoConfig.setNowUser(Convert.toStr(getUserId()));
        List<SurProjectVideoConfig> list = surProjectVideoConfigService.selectSurProjectVideoConfigList(surProjectVideoConfig);
        return getDataTable(list);
    }

    /**
     * 查询视频配置列表
     */
    @PreAuthorize("@ss.hasPermi('video:videoConfig:list')")
    @GetMapping("/listView")
    public AjaxResult listView(SurProjectVideoConfig surProjectVideoConfig)
    {
        surProjectVideoConfig.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(surProjectVideoConfig.getNowRole())){
            surProjectVideoConfig.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            surProjectVideoConfig.setNowDept(Convert.toStr(getDeptId()));
        }
        surProjectVideoConfig.setNowUser(Convert.toStr(getUserId()));
        List<SurProjectVideoConfig> list = surProjectVideoConfigService.selectSurProjectVideoConfigList(surProjectVideoConfig);
        return success(list);
    }

    /**
     * 导出视频配置列表
     */
    @PreAuthorize("@ss.hasPermi('video:videoConfig:export')")
    @Log(title = "视频配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SurProjectVideoConfig surProjectVideoConfig)
    {
        surProjectVideoConfig.setNowRole(Convert.toStr(getUserFirstRole()));
        if(SysRoleEnum.ZGS.getCode().equals(surProjectVideoConfig.getNowRole())){
            surProjectVideoConfig.setNowDept(Convert.toStr(sysDeptService.getZGSDeptId(getDeptId())));
        }else{
            surProjectVideoConfig.setNowDept(Convert.toStr(getDeptId()));
        }
        surProjectVideoConfig.setNowUser(Convert.toStr(getUserId()));
        List<SurProjectVideoConfig> list = surProjectVideoConfigService.selectSurProjectVideoConfigList(surProjectVideoConfig);
        ExcelUtil<SurProjectVideoConfig> util = new ExcelUtil<SurProjectVideoConfig>(SurProjectVideoConfig.class);
        util.exportExcel(response, list, "视频配置数据");
    }

    /**
     * 获取视频配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('video:videoConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(surProjectVideoConfigService.selectSurProjectVideoConfigById(id));
    }

    /**
     * 新增视频配置
     */
    @PreAuthorize("@ss.hasPermi('video:videoConfig:add')")
    @Log(title = "视频配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SurProjectVideoConfig surProjectVideoConfig)
    {
        return toAjax(surProjectVideoConfigService.insertSurProjectVideoConfig(surProjectVideoConfig));
    }

    /**
     * 修改视频配置
     */
    @PreAuthorize("@ss.hasPermi('video:videoConfig:edit')")
    @Log(title = "视频配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SurProjectVideoConfig surProjectVideoConfig)
    {
        return toAjax(surProjectVideoConfigService.updateSurProjectVideoConfig(surProjectVideoConfig));
    }

    /**
     * 修改视频配置
     */
    @PreAuthorize("@ss.hasPermi('video:videoConfig:edit')")
    @Log(title = "视频配置排序", businessType = BusinessType.UPDATE)
    @PostMapping("/updateVideoConfigSort")
    public AjaxResult updateVideoConfigSort(@RequestBody SurProjectVideoConfig surProjectVideoConfig)
    {
        return toAjax(surProjectVideoConfigService.updateVideoConfig(surProjectVideoConfig));
    }

    /**
     * 删除视频配置
     */
    @PreAuthorize("@ss.hasPermi('video:videoConfig:remove')")
    @Log(title = "视频配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(surProjectVideoConfigService.deleteSurProjectVideoConfigByIds(ids));
    }

    /**
     * 修改视频通道状态
     */
    @PreAuthorize("@ss.hasPermi('video:videoConfig:query')")
    @PostMapping("/editPassageState")
    public AjaxResult editPassageState(@RequestBody SurProjectVideoPassage surProjectVideoPassage)
    {
        surProjectVideoConfigService.editPassageState(surProjectVideoPassage);

        return success(surProjectVideoConfigService.updateSurProjectVideoConfigSignalState(surProjectVideoPassage.getVideoDvrNumber()));
    }

    /**
     * 获取视频配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('video:videoConfig:query')")
    @GetMapping(value = "/getVideoPassage/{videoDvrNumberd}")
    public AjaxResult getVideoPassage(@PathVariable("videoDvrNumberd") String videoDvrNumberd)
    {
        return success(surProjectVideoConfigService.getVideoPassage(videoDvrNumberd));
    }
}
