package com.fs.qw;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.core.security.LoginUser;
import com.fs.core.web.service.TokenService;
import com.fs.qw.domain.QwUserVideo;
import com.fs.qw.param.QwUserVideoParam;
import com.fs.qw.service.IQwUserVideoService;
import com.fs.qw.vo.QwUserVideoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业微信的视频号Controller
 *
 * @author fs
 * @date 2025-01-14
 */
@RestController
@RequestMapping("/qw/userVideo")
public class QwUserVideoController extends BaseController
{
    @Autowired
    private IQwUserVideoService qwUserVideoService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询企业微信的视频号列表
     */
//    @PreAuthorize("@ss.hasPermi('qw:userVideo:list')")
    @GetMapping("/list")
    public TableDataInfo list(QwUserVideoParam param)
    {
        startPage();

        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.setCompanyId(loginUser.getCompany().getCompanyId());

        List<QwUserVideoVO> list = qwUserVideoService.selectQwUserVideoListVO(param);
        return getDataTable(list);
    }

    /**
     * 导出企业微信的视频号列表
     */
//    @PreAuthorize("@ss.hasPermi('qw:userVideo:export')")
    @Log(title = "企业微信的视频号", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QwUserVideoParam param)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        param.setCompanyId(loginUser.getCompany().getCompanyId());

        List<QwUserVideoVO> list = qwUserVideoService.selectQwUserVideoListVO(param);
        ExcelUtil<QwUserVideoVO> util = new ExcelUtil<QwUserVideoVO>(QwUserVideoVO.class);
        return util.exportExcel(list, "企业微信的视频号数据");
    }

    /**
     * 获取企业微信的视频号详细信息
     */
//    @PreAuthorize("@ss.hasPermi('qw:userVideo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(qwUserVideoService.selectQwUserVideoById(id));
    }

    /**
     * 新增企业微信的视频号
     */
//    @PreAuthorize("@ss.hasPermi('qw:userVideo:add')")
    @Log(title = "企业微信的视频号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QwUserVideo qwUserVideo)
    {
        return toAjax(qwUserVideoService.insertQwUserVideo(qwUserVideo));
    }

    /**
     * 修改企业微信的视频号
     */
//    @PreAuthorize("@ss.hasPermi('qw:userVideo:edit')")
    @Log(title = "企业微信的视频号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QwUserVideo qwUserVideo)
    {
        return toAjax(qwUserVideoService.updateQwUserVideo(qwUserVideo));
    }

    /**
     * 删除企业微信的视频号
     */
//    @PreAuthorize("@ss.hasPermi('qw:userVideo:remove')")
    @Log(title = "企业微信的视频号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(qwUserVideoService.deleteQwUserVideoByIds(ids));
    }
}
