package com.fs.his.mapper;

import java.util.List;
import com.fs.his.domain.FsPackage;
import com.fs.his.param.FsPackageListUParam;
import com.fs.his.param.FsPackageParam;
import com.fs.his.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

/**
 * 套餐包Mapper接口
 *
 * @author fs
 * @date 2023-08-25
 */
public interface FsPackageMapper
{
    /**
     * 查询套餐包
     *
     * @param packageId 套餐包主键
     * @return 套餐包
     */
    public FsPackage selectFsPackageByPackageId(Long packageId);

    /**
     * 查询套餐包列表
     *
     * @param fsPackage 套餐包
     * @return 套餐包集合
     */
    public List<FsPackage> selectFsPackageList(FsPackage fsPackage);

    /**
     * 新增套餐包
     *
     * @param fsPackage 套餐包
     * @return 结果
     */
    public int insertFsPackage(FsPackage fsPackage);

    /**
     * 修改套餐包
     *
     * @param fsPackage 套餐包
     * @return 结果
     */
    public int updateFsPackage(FsPackage fsPackage);

    /**
     * 删除套餐包
     *
     * @param packageId 套餐包主键
     * @return 结果
     */
    public int deleteFsPackageByPackageId(Long packageId);

    /**
     * 批量删除套餐包
     *
     * @param packageIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsPackageByPackageIds(Long[] packageIds);

    @Select("select package_id dictValue,package_name dictLabel from fs_package where package_sub_type != 3 order by sort")
    List<OptionsVO> selectAllPackageList();
    @Select({"<script> " +
            "select * from fs_package "+
            "where 1=1 "+
            "            <if test=\"maps.packageName != null  and maps.packageName != ''\"> and package_name like concat('%', #{maps.packageName}, '%')</if>\n" +
//            "            <if test=\"maps.sort != null \"> and sort = #{maps.sort}</if>\n" +
            "            <if test=\"maps.secondName != null  and maps.secondName != ''\"> and second_name like concat('%', #{maps.secondName}, '%')</if>\n" +
            "            <if test=\"maps.status != null \"> and status = #{maps.status}</if>\n" +
            "            <if test=\"maps.packageId != null \"> and package_id = #{maps.packageId}</if>\n" +
            "            <if test=\"maps.packageType != null \"> and package_type = #{maps.packageType}</if>\n" +
            "            <if test=\"maps.isDel != null \"> and is_del = #{maps.isDel}</if>\n" +
            "            <if test=\"maps.packageSubType != null \"> and package_sub_type = #{maps.packageSubType}</if>\n" +
            "            <if test=\"maps.privateType != null \"> and private_type = #{maps.privateType}</if>\n" +
            "            <if test=\"maps.diseaseType != null \"> and disease_type = #{maps.diseaseType}</if>\n" +
            "            <if test=\"maps.isShow != null \"> and is_show = #{maps.isShow}</if>\n" +
            "        order by sort,package_id desc"+
            "</script>"})

    List<FsPackageListVO> selectFsPackageListVO(@Param("maps") FsPackageParam fsPackage);

    @Select("select *, (select GROUP_CONCAT(doctor_name SEPARATOR ',') AS doctors FROM fs_doctor WHERE  FIND_IN_SET(#{packageId}, package_ids) > 0)as doctors from fs_package where package_id=#{packageId}")
    FsPackageVO selectFsPackageByPackageIdVO(Long packageId);
    @Select("select GROUP_CONCAT(doctor_name SEPARATOR ',') AS doctors FROM fs_doctor WHERE  FIND_IN_SET(#{packageId}, package_ids) > 0")
    String selectFsDoctorNamesByPackageId(Long packageId);

    @Select({"<script> " +
            "select * from fs_package "+
            "where 1=1 "+
            "            <if test=\"maps.packageName != null  and maps.packageName != ''\"> and package_name like concat('%', #{maps.packageName}, '%')</if>\n" +
//            "            <if test=\"maps.sort != null \"> and sort = #{maps.sort}</if>\n" +
            "            <if test=\"maps.secondName != null  and maps.secondName != ''\"> and second_name like concat('%', #{maps.secondName}, '%')</if>\n" +
            "            <if test=\"maps.status != null \"> and status = #{maps.status}</if>\n" +
            "            <if test=\"maps.packageType != null \"> and package_type = #{maps.packageType}</if>\n" +
            "            <if test=\"maps.isDel != null \"> and is_del = #{maps.isDel}</if>\n" +
            "            <if test=\"maps.packageSubType != null \"> and package_sub_type = #{maps.packageSubType}</if>\n" +
            "            <if test=\"maps.privateType != null \"> and private_type = #{maps.privateType}</if>\n" +
            "            <if test=\"maps.diseaseType != null \"> and disease_type = #{maps.diseaseType}</if>\n" +

            "        order by sort,package_id desc"+
            "</script>"})
    List<FsPackageExcelVO> selectFsPackageListExcelVO(@Param("maps") FsPackage fsPackage);
    @Select({"<script> " +
            "select p.*  from fs_package p    " +
            "where p.status=1 and p.is_del=0   " +
            "<if test = 'maps.keyword != null     '> " +
            "and ( p.package_name like CONCAT('%',#{maps.keyword},'%') or p.second_name like CONCAT('%',#{maps.keyword},'%')) " +
            "</if>" +
            "<if test = 'maps.diseaseType != null and maps.diseaseType !=0    '> " +
            "and p.disease_type = #{maps.diseaseType} " +
            "</if>" +
            "<if test = 'maps.privateType != null and maps.privateType !=0    '> " +
            "and p.private_type = #{maps.privateType} " +
            "</if>" +
            "<if test = 'maps.isShow != null '> " +
            "and p.is_show = #{maps.isShow} " +
            "</if>" +
            " order by p.sort desc,package_id  "+
            "</script>"})
    List<FsPackageListUVO> selectFsPackageListUVO(@Param("maps") FsPackageListUParam param);
    @Select("select count(order_id) from fs_package_order WHERE user_id=#{userId} AND package_id=#{packageId} AND `status`>=0")
    int selectFsPackageListByUser(@Param("userId")Long userId,@Param("packageId")Long packageId);

    @Select("select * from fs_package where is_show=0 and `status`=1 and is_del=0 and  package_name like concat('%', #{packageName}, '%') or second_name like concat('%', #{packageName}, '%') limit 10")
    List<FsPackageListVO> selectFsPackageListVByName(String packageName);

    @Update({"<script> " +
            "UPDATE fs_package SET status = #{status} where package_id in "+
            "<foreach item='packageId' collection='packageIds' open='(' separator=',' close=')'> " +
            "            #{packageId} " +
            "</foreach>"+
            "</script>"})
    int updatePackagesStatus(@Param("packageIds")Long[] packageIds,@Param("status")Long status);
}
