<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xinelu.manage.mapper.projectresult.ProjectResultMapper">

	<resultMap type="ProjectResult" id="ProjectResultResult">
		<result property="id" column="id"/>
		<result property="patientId" column="patient_id"/>
		<result property="patientName" column="patient_name"/>
		<result property="cardNo" column="card_no"/>
		<result property="batchId" column="batch_id"/>
		<result property="batchName" column="batch_name"/>
		<result property="groupId" column="group_id"/>
		<result property="groupName" column="group_name"/>
		<result property="projectId" column="project_id"/>
		<result property="projectName" column="project_name"/>
		<result property="deviceId" column="device_id"/>
		<result property="deviceName" column="device_name"/>
		<result property="projectAlias" column="project_alias"/>
		<result property="judgeMode" column="judge_mode"/>
		<result property="measureResult" column="measure_result"/>
		<result property="maxValue" column="max_value"/>
		<result property="minValue" column="min_value"/>
		<result property="defaultValue" column="default_value"/>
		<result property="lisCompare" column="lis_compare"/>
		<result property="measureTime" column="measure_time"/>
		<result property="measureName" column="measure_name"/>
		<result property="recordRemark" column="record_remark"/>
		<result property="qualifiedSign" column="qualified_sign"/>
		<result property="measureResultPath" column="measure_result_path"/>
		<result property="projectUnit" column="project_unit"/>
		<result property="createBy" column="create_by"/>
		<result property="createTime" column="create_time"/>
		<result property="updateBy" column="update_by"/>
		<result property="updateTime" column="update_time"/>
	</resultMap>

	<sql id="selectProjectResultVo">
		select id, patient_id, patient_name, card_no, batch_id, batch_name, group_id, group_name, project_id, project_name, device_id, device_name, project_alias, judge_mode, measure_result, max_value, min_value, default_value, lis_compare, measure_time, measure_name, record_remark, qualified_sign, measure_result_path, project_unit, create_by, create_time, update_by, update_time from project_result
	</sql>

	<select id="selectProjectResultList" parameterType="ProjectResult" resultMap="ProjectResultResult">
		<include refid="selectProjectResultVo"/>
		<where>
			<if test="patientId != null ">
				and patient_id = #{patientId}
			</if>
			<if test="patientName != null  and patientName != ''">
				and patient_name like concat('%', #{patientName}, '%')
			</if>
			<if test="cardNo != null  and cardNo != ''">
				and card_no = #{cardNo}
			</if>
			<if test="batchId != null ">
				and batch_id = #{batchId}
			</if>
			<if test="batchName != null  and batchName != ''">
				and batch_name like concat('%', #{batchName}, '%')
			</if>
			<if test="groupId != null ">
				and group_id = #{groupId}
			</if>
			<if test="groupName != null  and groupName != ''">
				and group_name like concat('%', #{groupName}, '%')
			</if>
			<if test="projectId != null ">
				and project_id = #{projectId}
			</if>
			<if test="projectName != null  and projectName != ''">
				and project_name like concat('%', #{projectName}, '%')
			</if>
			<if test="deviceId != null ">
				and device_id = #{deviceId}
			</if>
			<if test="deviceName != null  and deviceName != ''">
				and device_name like concat('%', #{deviceName}, '%')
			</if>
			<if test="projectAlias != null  and projectAlias != ''">
				and project_alias = #{projectAlias}
			</if>
			<if test="judgeMode != null  and judgeMode != ''">
				and judge_mode = #{judgeMode}
			</if>
			<if test="measureResult != null  and measureResult != ''">
				and measure_result = #{measureResult}
			</if>
			<if test="maxValue != null ">
				and max_value = #{maxValue}
			</if>
			<if test="minValue != null ">
				and min_value = #{minValue}
			</if>
			<if test="defaultValue != null  and defaultValue != ''">
				and default_value = #{defaultValue}
			</if>
			<if test="lisCompare != null  and lisCompare != ''">
				and lis_compare = #{lisCompare}
			</if>
			<if test="measureTime != null ">
				and measure_time = #{measureTime}
			</if>
			<if test="measureName != null  and measureName != ''">
				and measure_name like concat('%', #{measureName}, '%')
			</if>
			<if test="recordRemark != null  and recordRemark != ''">
				and record_remark = #{recordRemark}
			</if>
			<if test="qualifiedSign != null  and qualifiedSign != ''">
				and qualified_sign = #{qualifiedSign}
			</if>
			<if test="measureResultPath != null  and measureResultPath != ''">
				and measure_result_path = #{measureResultPath}
			</if>
			<if test="projectUnit != null  and projectUnit != ''">
				and project_unit = #{projectUnit}
			</if>
		</where>
	</select>

	<select id="selectProjectResultById" parameterType="Long"
		resultMap="ProjectResultResult">
		<include refid="selectProjectResultVo"/>
		where id = #{id}
	</select>

	<insert id="insertProjectResult" parameterType="ProjectResult" useGeneratedKeys="true"
		keyProperty="id">
		insert into project_result
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="patientId != null">patient_id,
			</if>
			<if test="patientName != null">patient_name,
			</if>
			<if test="cardNo != null">card_no,
			</if>
			<if test="batchId != null">batch_id,
			</if>
			<if test="batchName != null">batch_name,
			</if>
			<if test="groupId != null">group_id,
			</if>
			<if test="groupName != null">group_name,
			</if>
			<if test="projectId != null">project_id,
			</if>
			<if test="projectName != null">project_name,
			</if>
			<if test="deviceId != null">device_id,
			</if>
			<if test="deviceName != null">device_name,
			</if>
			<if test="projectAlias != null">project_alias,
			</if>
			<if test="judgeMode != null">judge_mode,
			</if>
			<if test="measureResult != null">measure_result,
			</if>
			<if test="maxValue != null">max_value,
			</if>
			<if test="minValue != null">min_value,
			</if>
			<if test="defaultValue != null">default_value,
			</if>
			<if test="lisCompare != null">lis_compare,
			</if>
			<if test="measureTime != null">measure_time,
			</if>
			<if test="measureName != null">measure_name,
			</if>
			<if test="recordRemark != null">record_remark,
			</if>
			<if test="qualifiedSign != null">qualified_sign,
			</if>
			<if test="measureResultPath != null">measure_result_path,
			</if>
			<if test="projectUnit != null">project_unit,
			</if>
			<if test="createBy != null">create_by,
			</if>
			<if test="createTime != null">create_time,
			</if>
			<if test="updateBy != null">update_by,
			</if>
			<if test="updateTime != null">update_time,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="patientId != null">#{patientId},
			</if>
			<if test="patientName != null">#{patientName},
			</if>
			<if test="cardNo != null">#{cardNo},
			</if>
			<if test="batchId != null">#{batchId},
			</if>
			<if test="batchName != null">#{batchName},
			</if>
			<if test="groupId != null">#{groupId},
			</if>
			<if test="groupName != null">#{groupName},
			</if>
			<if test="projectId != null">#{projectId},
			</if>
			<if test="projectName != null">#{projectName},
			</if>
			<if test="deviceId != null">#{deviceId},
			</if>
			<if test="deviceName != null">#{deviceName},
			</if>
			<if test="projectAlias != null">#{projectAlias},
			</if>
			<if test="judgeMode != null">#{judgeMode},
			</if>
			<if test="measureResult != null">#{measureResult},
			</if>
			<if test="maxValue != null">#{maxValue},
			</if>
			<if test="minValue != null">#{minValue},
			</if>
			<if test="defaultValue != null">#{defaultValue},
			</if>
			<if test="lisCompare != null">#{lisCompare},
			</if>
			<if test="measureTime != null">#{measureTime},
			</if>
			<if test="measureName != null">#{measureName},
			</if>
			<if test="recordRemark != null">#{recordRemark},
			</if>
			<if test="qualifiedSign != null">#{qualifiedSign},
			</if>
			<if test="measureResultPath != null">#{measureResultPath},
			</if>
			<if test="projectUnit != null">#{projectUnit},
			</if>
			<if test="createBy != null">#{createBy},
			</if>
			<if test="createTime != null">#{createTime},
			</if>
			<if test="updateBy != null">#{updateBy},
			</if>
			<if test="updateTime != null">#{updateTime},
			</if>
		</trim>
	</insert>

	<update id="updateProjectResult" parameterType="ProjectResult">
		update project_result
		<trim prefix="SET" suffixOverrides=",">
			<if test="patientId != null">patient_id =
				#{patientId},
			</if>
			<if test="patientName != null">patient_name =
				#{patientName},
			</if>
			<if test="cardNo != null">card_no =
				#{cardNo},
			</if>
			<if test="batchId != null">batch_id =
				#{batchId},
			</if>
			<if test="batchName != null">batch_name =
				#{batchName},
			</if>
			<if test="groupId != null">group_id =
				#{groupId},
			</if>
			<if test="groupName != null">group_name =
				#{groupName},
			</if>
			<if test="projectId != null">project_id =
				#{projectId},
			</if>
			<if test="projectName != null">project_name =
				#{projectName},
			</if>
			<if test="deviceId != null">device_id =
				#{deviceId},
			</if>
			<if test="deviceName != null">device_name =
				#{deviceName},
			</if>
			<if test="projectAlias != null">project_alias =
				#{projectAlias},
			</if>
			<if test="judgeMode != null">judge_mode =
				#{judgeMode},
			</if>
			<if test="measureResult != null">measure_result =
				#{measureResult},
			</if>
			<if test="maxValue != null">max_value =
				#{maxValue},
			</if>
			<if test="minValue != null">min_value =
				#{minValue},
			</if>
			<if test="defaultValue != null">default_value =
				#{defaultValue},
			</if>
			<if test="lisCompare != null">lis_compare =
				#{lisCompare},
			</if>
			<if test="measureTime != null">measure_time =
				#{measureTime},
			</if>
			<if test="measureName != null">measure_name =
				#{measureName},
			</if>
			<if test="recordRemark != null">record_remark =
				#{recordRemark},
			</if>
			<if test="qualifiedSign != null">qualified_sign =
				#{qualifiedSign},
			</if>
			<if test="measureResultPath != null">measure_result_path =
				#{measureResultPath},
			</if>
			<if test="projectUnit != null">project_unit =
				#{projectUnit},
			</if>
			<if test="createBy != null">create_by =
				#{createBy},
			</if>
			<if test="createTime != null">create_time =
				#{createTime},
			</if>
			<if test="updateBy != null">update_by =
				#{updateBy},
			</if>
			<if test="updateTime != null">update_time =
				#{updateTime},
			</if>
		</trim>
		where id = #{id}
	</update>

	<delete id="deleteProjectResultById" parameterType="Long">
		delete from project_result where id = #{id}
	</delete>

	<delete id="deleteProjectResultByIds" parameterType="String">
		delete from project_result where id in
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

	<select id="selectList" parameterType="com.xinelu.manage.dto.projectresult.ProjectResultStatisticDto" resultType="com.xinelu.manage.vo.projectresult.ProjectResultVo">
		select group_name,project_name,measure_result, date_format(measure_time,'%Y-%m-%d')as measureTimeStr
		from project_result
		<where>
			<if test="patientId != null">
				and patient_id = #{patientId,jdbcType=BIGINT}
			</if>
			<if test="groupId != null">
				and group_id = #{groupId,jdbcType=BIGINT}
			</if>
			<if test="projectId != null">
				and project_id = #{projectId,jdbcType=BIGINT}
			</if>
			<if test="measureTimeStart != null">
				and date_format(measure_time,'%y%m%d') >= date_format(#{measureTimeStart}, '%y%m%d')
			</if>
			<if test="measureTimeEnd != null">
				and date_format(measure_time,'%y%m%d') &lt;= date_format(#{measureTimeEnd}, '%y%m%d')
			</if>
		</where>
	</select>
</mapper>
