package org.jk.rag.mapper;


import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jk.rag.domain.entity.AppNumList;
import org.jk.rag.domain.entity.JkApplication;
import org.jk.rag.domain.entity.JkApplicationResult;
import org.jk.rag.domain.entity.VipApplication;

import java.util.List;

/**
 * 高井 应用列表
 *
 * @author takai
 */
public interface JkApplicationMapper
{
    /**
     * 根据条件分页查询应用信息
     *
     * @param mData 应用信息
     * @return 应用信息
     */
    public List<JkApplicationResult> selectApplicationList(JkApplication mData);


    /**
     * 查询唯一应用信息
     * @param mData
     * @return
     */
    @InterceptorIgnore(dataPermission = "true", tenantLine = "true")
    public JkApplication selectTargetApplication(JkApplication mData);


    /**
     * 新增应用信息
     *
     * @param mData 应用信息
     * @return 结果
     */
    public int insertApplication(JkApplication mData);

    public int insertVipApp(VipApplication mData);

    public int deleteVipByAppId(String appId);

    /**
     * 更新应用信息
     *
     * @param mData 应用信息
     * @return 结果
     */
    public int updateApplication(JkApplication mData);

    int delApplication(String appId);

    public List<JkApplicationResult> selectApplicationLists(JkApplication mData);

    public List<JkApplication> selectAppListByApprover(JkApplication mData);

    public Page<JkApplication> selectAppPageListByApprover(@Param("ew")JkApplication mData,@Param("page")Page page);

    public Page<JkApplication> selectAppHistoryPageListByApprover(@Param("ew")JkApplication mData,@Param("page")Page page);

    List<JkApplicationResult> selectAppByUserId(String userId);

    public List<JkApplicationResult> selectApplicationListByProjectType(String appId);

    List<JkApplicationResult> selectRoleApp();

    @InterceptorIgnore(tenantLine = "true", dataPermission = "false")
    Page<JkApplicationResult> selectApplicationPageList(@Param("ew")JkApplication mData, @Param("page")Page page);

    Page<JkApplicationResult> selectMyApplicationPageList(@Param("ew")JkApplication mData, @Param("page")Page page);

    @Select("<script>" +
        "select slice.document_id documentId" +
        ",slice.knowledge_id knowledgeId " +
        ",slice.slice_id sliceId " +
        ",app.appId  " +
        " from bm_application app " +
        " left join bm_knowledge knowledge on FIND_IN_SET(knowledge.knowledge_id,app.knowledge_ids) > 0  " +
        " left join bm_document document on document.knowledge_id = knowledge.knowledge_id" +
        " left join slice_info slice on document.document_id = slice.document_id " +
        " where app.appId = #{appId} and slice.del_flag = 0  " +
        "</script>")
    List<AppNumList> selectSizeNumByApplicationId(@Param("appId")String appId);

    @Select("<script>" +
        "select count(*)" +
        " from bm_application app " +
        " where FIND_IN_SET(#{knowledgeId},app.knowledge_ids) > 0  " +
        "</script>")
    int selectAppByKnowledgeId(@Param("knowledgeId")String knowledgeId);

    @InterceptorIgnore(dataPermission = "true", tenantLine = "true")
    public JkApplication selectOpenApplication(JkApplication mData);
}
