package com.fs.his.mapper;

import java.util.List;
import com.fs.his.domain.FsHealthRecord;
import com.fs.his.param.FsHealthRecordListParam;
import com.fs.his.vo.FsHealthRecordListPVO;
import org.apache.ibatis.annotations.Select;

/**
 * 健康档案Mapper接口
 *
 * @author fs
 * @date 2024-09-02
 */
public interface FsHealthRecordMapper
{
    /**
     * 查询健康档案
     *
     * @param id 健康档案主键
     * @return 健康档案
     */
    public FsHealthRecord selectFsHealthRecordById(Long id);

    /**
     * 查询健康档案列表
     *
     * @param fsHealthRecord 健康档案
     * @return 健康档案集合
     */
    public List<FsHealthRecord> selectFsHealthRecordList(FsHealthRecord fsHealthRecord);

    /**
     * 新增健康档案
     *
     * @param fsHealthRecord 健康档案
     * @return 结果
     */
    public int insertFsHealthRecord(FsHealthRecord fsHealthRecord);

    /**
     * 修改健康档案
     *
     * @param fsHealthRecord 健康档案
     * @return 结果
     */
    public int updateFsHealthRecord(FsHealthRecord fsHealthRecord);

    /**
     * 删除健康档案
     *
     * @param id 健康档案主键
     * @return 结果
     */
    public int deleteFsHealthRecordById(Long id);

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

    @Select("select * from fs_health_record where user_id=#{userId} limit 1")
    FsHealthRecord selectFsHealthRecordByUserId(Long userId);

    @Select({"<script> " +
            "select hr.*,u.nick_name,CONCAT(LEFT(u.phone, 3), '****', RIGHT(u.phone, 4)) AS phone from fs_health_record hr left join fs_user u on hr.user_id=u.user_id "+
            "<where>" +
            "  <if test=\"userId != null \"> and hr.user_id = #{userId}</if>\n" +
            "  <if test=\"name != null  and name != ''\"> and hr.name like concat( #{name}, '%')</if>\n" +
            "  <if test=\"phone != null  and phone != ''\"> and u.phone like concat( #{phone}, '%')</if>\n" +
            "</where> order by hr.id desc"+
            "</script>"})
    List<FsHealthRecordListPVO> selectFsHealthRecordListVO(FsHealthRecordListParam fsHealthRecord);
    @Select({"<script> " +
            "select distinct hr.*,u.nick_name,CONCAT(LEFT(u.phone, 3), '****', RIGHT(u.phone, 4)) AS phone from fs_health_record hr left join fs_user u on hr.user_id=u.user_id LEFT JOIN company_user_user cuu on hr.user_id=cuu.user_id  "+
            "<where>" +
            " <if test=\"companyUserId != null \"> and cuu.company_user_id=#{companyUserId}</if>\n" +
            "  <if test=\"companyId != null \"> and cuu.company_id=#{companyId}</if>\n" +
            "  <if test=\"userId != null \"> and hr.user_id = #{userId}</if>\n" +
            "  <if test=\"name != null  and name != ''\"> and hr.name like concat( #{name}, '%')</if>\n" +
            "  <if test=\"phone != null  and phone != ''\"> and u.phone like concat( #{phone}, '%')</if>\n" +
            "</where> order by hr.id desc"+
            "</script>"})
    List<FsHealthRecordListPVO> selectFsHealthRecordCompanyListVO(FsHealthRecordListParam fsHealthRecord);

}
