package com.fs.his.mapper;

import java.util.List;
import com.fs.his.domain.FsHealthLife;
import com.fs.his.param.FsHealthLifeParam;
import com.fs.his.param.FsHealthLifeUParam;
import com.fs.his.vo.FsHealthLifeListUVO;
import com.fs.his.vo.FsHealthLifeListVO;
import org.apache.ibatis.annotations.Select;

/**
 * 健康生活Mapper接口
 *
 * @author fs
 * @date 2024-09-02
 */
public interface FsHealthLifeMapper
{
    /**
     * 查询健康生活
     *
     * @param id 健康生活主键
     * @return 健康生活
     */
    public FsHealthLife selectFsHealthLifeById(Long id);

    /**
     * 查询健康生活列表
     *
     * @param fsHealthLife 健康生活
     * @return 健康生活集合
     */
    public List<FsHealthLife> selectFsHealthLifeList(FsHealthLife fsHealthLife);

    /**
     * 新增健康生活
     *
     * @param fsHealthLife 健康生活
     * @return 结果
     */
    public int insertFsHealthLife(FsHealthLife fsHealthLife);

    /**
     * 修改健康生活
     *
     * @param fsHealthLife 健康生活
     * @return 结果
     */
    public int updateFsHealthLife(FsHealthLife fsHealthLife);

    /**
     * 删除健康生活
     *
     * @param id 健康生活主键
     * @return 结果
     */
    public int deleteFsHealthLifeById(Long id);

    /**
     * 批量删除健康生活
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsHealthLifeByIds(Long[] ids);

    @Select("select * from fs_health_life where user_id=#{userId} and type=#{type} ")
    List<FsHealthLifeListUVO> selectFsHealthLifeListUVO(FsHealthLifeUParam param);
    @Select({"<script> " +
            "select h.*,u.nick_name, CONCAT(LEFT(u.phone, 3), '****', RIGHT(u.phone, 4)) AS phone  from fs_health_life h left join fs_user u on h.user_id=u.user_id  "+
            "<where>" +
            "  <if test=\"userId != null \"> and h.user_id = #{userId}</if>\n" +
            "  <if test=\"type != null \"> and h.type = #{type}</if>\n" +
            "  <if test=\"phone != null  and phone != ''\"> and u.phone like concat( #{phone}, '%')</if>\n" +
            "</where> order by h.id desc "+
            "</script>"})
    List<FsHealthLifeListVO> selectFsHealthLifeListVO(FsHealthLifeParam fsHealthLife);
    @Select("select * from fs_health_life where user_id=#{userId} and type=#{type} order by id desc limit 1")
    FsHealthLifeListUVO selectFsHealthLifeDayByUserId(FsHealthLifeUParam param);
}
