package com.fs.course.mapper;

import com.fs.course.domain.FsCourseSop;
import com.fs.course.param.FsCourseSopParam;
import com.fs.course.vo.FsCourseSopAiListVO;
import com.fs.course.vo.FsCourseSopListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 看课sopMapper接口
 *
 * @author fs
 * @date 2024-09-04
 */
public interface FsCourseSopMapper
{
    /**
     * 查询看课sop
     *
     * @param id 看课sop主键
     * @return 看课sop
     */
    public FsCourseSop selectFsCourseSopById(Long id);

    /**
     * 查询看课sop列表
     *
     * @param fsSop 看课sop
     * @return 看课sop集合
     */
    public List<FsCourseSop> selectFsCourseSopList(FsCourseSop fsSop);


    @Select("<script> " +
            "select fs.*," +
            "case when fs.sop_type= 1 then cv.title " +
            "else null " +
            "end as courseTitle  from fs_course_sop fs " +
            "left join fs_user_course_video cv on fs.business_id = cv.video_id AND fs.sop_type= 1 " +
            "</script>")
    public List<FsCourseSopListVO> selectFsCourseSopVOList(FsCourseSop fsSop);

    /**
     * 新增看课sop
     *
     * @param fsSop 看课sop
     * @return 结果
     */
    public int insertFsCourseSop(FsCourseSop fsSop);

    /**
     * 修改看课sop
     *
     * @param fsSop 看课sop
     * @return 结果
     */
    public int updateFsCourseSop(FsCourseSop fsSop);

    /**
     * 删除看课sop
     *
     * @param id 看课sop主键
     * @return 结果
     */
    public int deleteFsCourseSopById(Long id);

    /**
     * 批量删除看课sop
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsCourseSopByIds(Long[] ids);

    /**
     * AI-chat课程 获取员工SOP规则列表
     */

    @Select("<script> " +
            "SELECT DISTINCT( cs.business_id ), cs.id, cs.NAME, qu.id as qwUserIds, cs.company_id, cs.create_time " +
            "FROM " +
            " fs_course_sop cs " +
            " LEFT JOIN fs_course_sop_logs csl ON cs.id = csl.sop_id " +
            " LEFT JOIN qw_user qu on qu.qw_user_id=csl.qw_userid " +
            "WHERE " +
            "csl.qw_userid = #{map.qwQwUserID} " +
            "AND csl.company_id = #{map.companyId} " +
            "AND cs.is_audit = '1' " +
            "AND cs.`status` = '1' " +
            "</script>")
    List<FsCourseSopAiListVO> selectSopListVO(@Param("map") FsCourseSopParam param);


}
