package thyyxxk.webserver.dao.his.medicalinsurance;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.medicalinsurance.log.FetchLog;
import thyyxxk.webserver.entity.medicalinsurance.log.SiLog;

@Mapper
public interface SiLogDao extends BaseMapper<SiLog> {

    @Select("<script>" +
            "select msgid,infno,insuplc_admdvs,opter,psn_no, " +
            "create_datetime,pat_no,times,infcode from t_si_log " +
            "where log_type=#{ftclg.logType} " +
            "<if test=\"ftclg.infno!=null and ftclg.infno!=''\">" +
            "and infno=#{ftclg.infno} " +
            "</if>" +
            "<if test=\"ftclg.begntime!=null and ftclg.endtime!=null\">" +
            "and create_datetime&gt;=#{ftclg.begntime} and create_datetime&lt;=#{ftclg.endtime} " +
            "</if>" +
            "<if test=\"ftclg.patNo!=null and ftclg.patNo!=''\">" +
            "and pat_no=#{ftclg.patNo} " +
            "</if> " +
            "<if test=\"ftclg.times!=null\">" +
            "and times=#{ftclg.times} " +
            "</if> " +
            "order by create_datetime" +
            "</script>")
    IPage<SiLog> selectSiLogs(IPage<SiLog> iPage,
                              @Param("ftclg") FetchLog ftclg);

    @Select("<script>" +
            "select count(1) from t_si_log " +
            "where log_type=#{ftclg.logType} and infcode=0 " +
            "<if test=\"ftclg.infno!=null and ftclg.infno!=''\">" +
            "and infno=#{ftclg.infno} " +
            "</if>" +
            "<if test=\"ftclg.begntime!=null and ftclg.endtime!=null\">" +
            "and create_datetime&gt;=#{ftclg.begntime} and create_datetime&lt;=#{ftclg.endtime} " +
            "</if>" +
            "<if test=\"ftclg.patNo!=null and ftclg.patNo!=''\">" +
            "and pat_no=#{ftclg.patNo} " +
            "</if>" +
            "<if test=\"ftclg.times!=null\">" +
            "and times=#{ftclg.times} " +
            "</if> " +
            "</script>")
    Integer selectSuccessSiLogCount(@Param("ftclg") FetchLog ftclg);
}
