package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ClewVideo;
import com.ruoyi.system.service.IClewVideoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 线索视频Controller
 *
 * @author ruoyi
 * @date 2023-11-06
 */
@Controller
@RequestMapping("/system/video")
public class ClewVideoController extends BaseController
{
    private String prefix = "system/video";

    @Autowired
    private IClewVideoService clewVideoService;

    @RequiresPermissions("system:video:view")
    @GetMapping()
    public String video()
    {
        return prefix + "/video";
    }

    /**
     * 查询线索视频列表
     */
    @RequiresPermissions("system:video:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClewVideo clewVideo)
    {
        startPage();
        List<ClewVideo> list = clewVideoService.selectClewVideoList(clewVideo);
        return getDataTable(list);
    }

    @GetMapping("/app/list")
    @ResponseBody
    public AjaxResult getAppList(@RequestParam(value = "sourceApp", required = false) Long sourceApp)
    {
        if(sourceApp == null){
            sourceApp = 1L;
        }
        ClewVideo param = new ClewVideo();
        param.setSourceApp(sourceApp);
        List<ClewVideo> list = clewVideoService.selectClewVideoList(param);
        return AjaxResult.success(list);
    }

    /**
     * 导出线索视频列表
     */
    @RequiresPermissions("system:video:export")
    @Log(title = "线索视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClewVideo clewVideo)
    {
        List<ClewVideo> list = clewVideoService.selectClewVideoList(clewVideo);
        ExcelUtil<ClewVideo> util = new ExcelUtil<ClewVideo>(ClewVideo.class);
        return util.exportExcel(list, "线索视频数据");
    }

    /**
     * 新增线索视频
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存线索视频
     */
    @RequiresPermissions("system:video:add")
    @Log(title = "线索视频", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClewVideo clewVideo)
    {
        return toAjax(clewVideoService.insertClewVideo(clewVideo));
    }

    /**
     * 修改线索视频
     */
    @RequiresPermissions("system:video:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ClewVideo clewVideo = clewVideoService.selectClewVideoById(id);
        mmap.put("clewVideo", clewVideo);
        return prefix + "/edit";
    }

    /**
     * 修改保存线索视频
     */
    @RequiresPermissions("system:video:edit")
    @Log(title = "线索视频", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClewVideo clewVideo)
    {
        return toAjax(clewVideoService.updateClewVideo(clewVideo));
    }

    /**
     * 删除线索视频
     */
    @RequiresPermissions("system:video:remove")
    @Log(title = "线索视频", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clewVideoService.deleteClewVideoByIds(ids));
    }
}
