package thyyxxk.webserver.dao.his.medicaladvice.nursing;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.datamodify.YzTemperature;
import thyyxxk.webserver.entity.medicaladvice.medicamanage.YzTemperatureVO;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @Author:lihong
 * @Date: 2023/4/27
 */
@Mapper
public interface YzTemperatureMapper extends BaseMapper<YzTemperature> {
    @Select("select  *, "+
            " GLU glu,CONVERT(char(8), rec_time, 108) toStringRecTime," +
            " MAP map," +
            " CVP cvp," +
            " ETCHO2 etcho2," +
            " GCS gcs," +
            " RASS rass," +
            " temperature_1_str=case isnull(temperature_1,0) when 0 then '' else cast(temperature_1 as varchar(10)) + isnull(temperature_1_type,'') end" +
            " FROM yz_temperature" +
            " WHERE ( inpatient_no = #{inpatientNo} ) AND" +
            "    ( admiss_times = #{admissTimes} ) and (${dateTimeCondition})" +
            "      and  isnull(scd_flag,'0')<>'1' order by rec_date ,rec_time ")
   List<YzTemperature> listYzTemperature(YzTemperatureVO yzTemperature);
    @Select(" select   detail_no from yz_temperature where isnull(scd_flag,'0')<>'1' and inpatient_no =#{inpatientNo} and admiss_times =#{admissTimes} and convert(char(11),rec_date,121) = #{toStringRecDate} and  CONVERT(char(8), rec_time, 108)=#{toStringRecTime}  ")
    List<Integer> exists(YzTemperatureVO query);
    @Select( " select sum ( col_1_am ) col_1_am from yz_temperature  where inpatient_no=#{inpatientNo} and  admiss_times =#{admissTimes}    and isnull(scd_flag, '') = '0' and isnull ( intake_flag , '' ) <> '1'  and (${dateTimeCondition})" )
    YzTemperature queryInputSum(YzTemperatureVO query);
    @Select(" select sum(col_2_am) col_2_am," +
            "       sum(urine_quan_am) urine_quan_am," +
            "       sum(output_dblood) output_dblood," +
            "       sum(output_other) output_other," +
            "       sum(shit) shit," +
            "       sum(gastric) gastric" +
            " from yz_temperature  where inpatient_no=#{inpatientNo} and  admiss_times =#{admissTimes} and    isnull(scd_flag, '') = '0' and isnull ( outtake_flag , '' ) <> '1' and (${dateTimeCondition})   ")
    YzTemperature queryOutSum(YzTemperatureVO query);
    @Select(" select min(rec_date) rec_start_date,max(rec_date) rec_end_date from  yz_temperature where scd_flag =1 and inpatient_no=#{inpatientNo} and admiss_times =#{admissTimes} ")
    Map<String,Object> getStartAndEndTime(YzTemperatureVO query);
    @Update(" update yz_temperature  set rec_time = #{newRecTime} where isnull(scd_flag,'0')<>'1' and inpatient_no =#{query.inpatientNo} and admiss_times =#{query.admissTimes} and convert(char(11),rec_date,121) = #{query.toStringRecDate} and  CONVERT(char(8), rec_time, 108)=#{query.toStringRecTime}")
    void updateRecTime(@Param("query") YzTemperatureVO query, @Param("newRecTime") String newRecTime);
}
