package com.fs.company.mapper;

import com.fs.company.domain.CompanyConfig;
import com.fs.company.vo.CompanyMiniAppVO;
import com.fs.system.domain.SysConfig;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 参数配置Mapper接口
 *
 * @author fs
 * @date 2021-05-25
 */
public interface CompanyConfigMapper
{
    /**
     * 查询参数配置
     *
     * @param configId 参数配置ID
     * @return 参数配置
     */
    public CompanyConfig selectCompanyConfigById(Integer configId);

    /**
     * 查询参数配置列表
     *
     * @param companyConfig 参数配置
     * @return 参数配置集合
     */
    public List<CompanyConfig> selectCompanyConfigList(CompanyConfig companyConfig);

    /**
     * 新增参数配置
     *
     * @param companyConfig 参数配置
     * @return 结果
     */
    public int insertCompanyConfig(CompanyConfig companyConfig);

    /**
     * 修改参数配置
     *
     * @param companyConfig 参数配置
     * @return 结果
     */
    public int updateCompanyConfig(CompanyConfig companyConfig);

    /**
     * 删除参数配置
     *
     * @param configId 参数配置ID
     * @return 结果
     */
    public int deleteCompanyConfigById(Integer configId);

    /**
     * 批量删除参数配置
     *
     * @param configIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteCompanyConfigByIds(Integer[] configIds);
    @Select("select * from company_config where company_id=#{companyId} and config_key=#{key} ")
    CompanyConfig selectCompanyConfigByKey(@Param("companyId") Long companyId, @Param("key")String key);
    @Select("select * from company_config where config_key=#{key} ")
    String selectConfigByKey(String key);
    @Select("select * from company_config where config_key=#{key} limit 1")
    SysConfig selectConfig(String key);

    @Select("select * from company_config where config_key=#{key} ")
    CompanyConfig selectCompanyConfigByServerKey(@Param("key")String key);

    @Select("select config_value from company_config where company_id=#{companyId} and config_key='redPacket:config' ")
    String selectRedPacketConfigByKey(Long companyId);

/*    @Select("select \n" +
            "id,\n" +
            "name,\n" +
            "appid\n" +
            "from\n" +
            "fs_course_play_source_config\n" +
            "where \n" +
            "is_del = 0\n" +
            "and FIND_IN_SET(#{companyId},set_company_ids)")*/

    @Select("SELECT cm.id,cm.company_id,cs.`name`,cm.app_id FROM  company_miniapp  cm\n" +
            "LEFT JOIN fs_course_play_source_config   cs ON cm.app_id=cs.appid\n" +
            "\n" +
            "WHERE cm.`company_id` = #{companyId}\n" +
            "  AND (cs.status IS NULL OR cs.status <> 2)")
    List<CompanyMiniAppVO> getCompanyMiniAppList(@Param("companyId") Long companyId);

    @Select("SELECT fcpsc.id,\n" +
            "       fcpsc.company_id,\n" +
            "       fcpsc.`name`,\n" +
            "       fcpsc.appid\n" +
            "FROM fs_course_play_source_config fcpsc\n" +
            "WHERE fcpsc.is_del = 0\n" +
            "  AND (fcpsc.status IS NULL OR fcpsc.status <> 2)\n" +
            "  AND (\n" +
            "        fcpsc.company_id = #{companyId}\n" +
            "        OR (fcpsc.company_ids IS NOT NULL AND fcpsc.company_ids != '' AND FIND_IN_SET(#{companyId}, fcpsc.company_ids))\n" +
            "      )")
    List<CompanyMiniAppVO> getCompanyMiniAppListByCompany(@Param("companyId") Long companyId);
}
