package com.yanzhu.manage.controller;

import com.yanzhu.common.core.utils.poi.ExcelUtil;
import com.yanzhu.common.core.web.controller.BaseController;
import com.yanzhu.common.core.web.domain.AjaxResult;
import com.yanzhu.common.core.web.page.TableDataInfo;
import com.yanzhu.common.log.annotation.Log;
import com.yanzhu.common.log.enums.BusinessType;
import com.yanzhu.common.security.annotation.RequiresPermissions;
import com.yanzhu.manage.domain.BusTrainingVideo;
import com.yanzhu.manage.service.IBusTrainingVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * 培训视频Controller
 * 
 * @author JiangYuQi
 * @date 2024-08-25
 */
@RestController
@RequestMapping("/busTrainingVideo")
public class BusTrainingVideoController extends BaseController
{
    @Autowired
    private IBusTrainingVideoService busTrainingVideoService;

    /**
     * 查询培训视频列表
     */
    @RequiresPermissions("manage:busTrainingVideo:list")
    @GetMapping("/list")
    public TableDataInfo list(BusTrainingVideo busTrainingVideo)
    {
        startPage();
        List<BusTrainingVideo> list = busTrainingVideoService.selectBusTrainingVideoList(busTrainingVideo);
        return getDataTable(list);
    }

    /**
     * 统计培训视频列表
     * @RequiresPermissions("manage:busTrainingVideo:list")
     *
     * @param busTrainingVideo 培训视频
     * @return 培训视频集合
     */
    @GetMapping("/findGroupByLevel")
    public AjaxResult findBusTrainingVideoByLevel(BusTrainingVideo busTrainingVideo){
        return success(busTrainingVideoService.findBusTrainingVideoByLevel(busTrainingVideo));
    }

    /**
     * 导出培训视频列表
     */
    @RequiresPermissions("manage:busTrainingVideo:export")
    @Log(title = "培训视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusTrainingVideo busTrainingVideo)
    {
        List<BusTrainingVideo> list = busTrainingVideoService.selectBusTrainingVideoList(busTrainingVideo);
        ExcelUtil<BusTrainingVideo> util = new ExcelUtil<BusTrainingVideo>(BusTrainingVideo.class);
        util.exportExcel(response, list, "培训视频数据");
    }

    /**
     * 获取培训视频详细信息
     */
    @RequiresPermissions("manage:busTrainingVideo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busTrainingVideoService.selectBusTrainingVideoById(id));
    }

    /**
     * 新增培训视频
     */
    @RequiresPermissions("manage:busTrainingVideo:add")
    @Log(title = "培训视频", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusTrainingVideo busTrainingVideo)
    {
        return toAjax(busTrainingVideoService.insertBusTrainingVideo(busTrainingVideo));
    }

    /**
     * 修改培训视频
     */
    @RequiresPermissions("manage:busTrainingVideo:edit")
    @Log(title = "培训视频", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusTrainingVideo busTrainingVideo)
    {
        return toAjax(busTrainingVideoService.updateBusTrainingVideo(busTrainingVideo));
    }

    /**
     * 删除培训视频
     */
    @RequiresPermissions("manage:busTrainingVideo:remove")
    @Log(title = "培训视频", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busTrainingVideoService.deleteBusTrainingVideoByIds(ids));
    }
}
