package com.nursinghome.mapper;

import com.nursinghome.entity.CareRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CareRecordMapper {
    @Insert("INSERT INTO care_record(elder_id, nurse_id, content, attachment_url, record_time, created_at) VALUES(#{elderId}, #{nurseId}, #{content}, #{attachmentUrl}, #{recordTime}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(CareRecord record);

    @Select("SELECT * FROM care_record WHERE elder_id = #{elderId} ORDER BY record_time DESC")
    List<CareRecord> listByElderId(Long elderId);

    @Select("<script>SELECT * FROM care_record WHERE elder_id IN <foreach collection='elderIds' item='id' open='(' separator=',' close=')'>#{id}</foreach> ORDER BY record_time DESC</script>")
    List<CareRecord> listByElderIds(@Param("elderIds") List<Long> elderIds);
}
