package com.fs.hospital.mapper;

import java.util.List;
import com.fs.hospital.domain.HospitalMemberLevel;
import com.fs.hospital.vo.HospitalMemberLevelHVO;
import org.apache.ibatis.annotations.Select;

/**
 * 会员等级Mapper接口
 *
 * @author fs
 * @date 2024-03-04
 */
public interface HospitalMemberLevelMapper
{
    /**
     * 查询会员等级
     *
     * @param levelId 会员等级主键
     * @return 会员等级
     */
    public HospitalMemberLevel selectHospitalMemberLevelByLevelId(Long levelId);

    /**
     * 查询会员等级列表
     *
     * @param hospitalMemberLevel 会员等级
     * @return 会员等级集合
     */
    public List<HospitalMemberLevel> selectHospitalMemberLevelList(HospitalMemberLevel hospitalMemberLevel);

    /**
     * 新增会员等级
     *
     * @param hospitalMemberLevel 会员等级
     * @return 结果
     */
    public int insertHospitalMemberLevel(HospitalMemberLevel hospitalMemberLevel);

    /**
     * 修改会员等级
     *
     * @param hospitalMemberLevel 会员等级
     * @return 结果
     */
    public int updateHospitalMemberLevel(HospitalMemberLevel hospitalMemberLevel);

    /**
     * 删除会员等级
     *
     * @param levelId 会员等级主键
     * @return 结果
     */
    public int deleteHospitalMemberLevelByLevelId(Long levelId);

    /**
     * 批量删除会员等级
     *
     * @param levelIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteHospitalMemberLevelByLevelIds(Long[] levelIds);

    @Select("select * from hospital_member_level where hospital_id = #{hospitalId}")
    List<HospitalMemberLevel> selectAllLevel(Long hospitalId);

    @Select({"<script> " +
            "SELECT hml.*, COUNT(hm.level_value) AS member_count\n" +
            "FROM hospital_member_level hml\n" +
            "LEFT JOIN hospital_member hm ON hml.level_value = hm.level_value\n" +
            "where 1 =1 " +
            " <if test=\"levelName != null  and levelName != ''\"> and hml.level_name like concat('%', #{levelName}, '%')</if>\n" +
            "            <if test=\"level != null \"> and hml.level = #{level}</if>\n" +
            "            <if test=\"levelValue != null \"> and hml.level_value = #{levelValue}</if>\n" +
            "            <if test=\"totalIntegral != null \"> and total_integral = #{totalIntegral}</if>\n" +
            "            <if test=\"hospitalId != null \"> and hml.hospital_id = #{hospitalId}</if>\n" +
            "            <if test=\"configJson != null  and hml.configJson != ''\"> and config_json = #{configJson}</if>" +

            " GROUP BY hml.level_value " +
            "</script>"})
    List<HospitalMemberLevelHVO> selectHospitalMemberLevelListPVO(HospitalMemberLevel hospitalMemberLevel);
}
