package com.fs.course.controller;

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.course.domain.FsCourseSop;
import com.fs.course.service.IFsCourseSopService;
import com.fs.course.vo.FsCourseSopListVO;
import com.fs.common.annotation.Log;
import com.fs.core.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 看课sopController
 *
 * @author fs
 * @date 2024-09-04
 */
@RestController
@RequestMapping("/course/sop")
public class FsCourseSopController extends BaseController
{
    @Autowired
    private IFsCourseSopService fsSopService;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询看课sop列表
     */
    @PreAuthorize("@ss.hasPermi('course:sop:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsCourseSop fsSop)
    {
        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fsSop.setCompanyId( loginUser.getCompany().getCompanyId());
        List<FsCourseSopListVO> list = fsSopService.selectFsCourseSopVOList(fsSop);
        return getDataTable(list);
    }

    /**
     * 导出看课sop列表
     */
    @PreAuthorize("@ss.hasPermi('course:sop:export')")
    @Log(title = "看课sop", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsCourseSop fsSop)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fsSop.setCompanyId( loginUser.getCompany().getCompanyId());
        List<FsCourseSop> list = fsSopService.selectFsCourseSopList(fsSop);
        ExcelUtil<FsCourseSop> util = new ExcelUtil<FsCourseSop>(FsCourseSop.class);
        return util.exportExcel(list, "看课sop数据");
    }

    /**
     * 获取看课sop详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:sop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fsSopService.selectFsCourseSopById(id));
    }

    /**
     * 新增看课sop
     */
    @PreAuthorize("@ss.hasPermi('course:sop:add')")
    @Log(title = "看课sop", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsCourseSop fsSop)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        fsSop.setCompanyId( loginUser.getCompany().getCompanyId());
        fsSop.setCreateTime(new Date());
        fsSop.setCreateBy(loginUser.getUser().getNickName());
        return toAjax(fsSopService.insertFsCourseSop(fsSop));
    }

    /**
     * 修改看课sop
     */
    @PreAuthorize("@ss.hasPermi('course:sop:edit')")
    @Log(title = "看课sop", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsCourseSop fsSop)
    {
        return toAjax(fsSopService.updateFsCourseSop(fsSop));
    }

    /**
     * 删除看课sop
     */
    @PreAuthorize("@ss.hasPermi('course:sop:remove')")
    @Log(title = "看课sop", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fsSopService.deleteFsCourseSopByIds(ids));
    }
}
