<?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.signpatientpackage.SignPatientPackageMapper">

    <resultMap type="SignPatientPackage" id="SignPatientPackageResult">
            <result property="id" column="id"/>
            <result property="patientId" column="patient_id"/>
	        <result property="signPatientRecordId" column="sign_patient_record_id"/>
            <result property="servicePackageId" column="service_package_id"/>
            <result property="packageName" column="package_name"/>
            <result property="packagePaymentStatus" column="package_payment_status"/>
            <result property="packagePrice" column="package_price"/>
            <result property="serviceStartTime" column="service_start_time"/>
            <result property="serviceEndTime" column="service_end_time"/>
            <result property="packageTerm" column="package_term"/>
	        <result property="packageTermUnit" column="package_term_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="selectSignPatientPackageVo">
        select id, patient_id, sign_patient_record_id, service_package_id, package_name, package_payment_status, package_price,
               service_start_time, service_end_time, package_term, package_term_unit, create_by, create_time, update_by, update_time from sign_patient_package
    </sql>

    <select id="selectSignPatientPackageList" parameterType="SignPatientPackage" resultMap="SignPatientPackageResult">
        <include refid="selectSignPatientPackageVo"/>
        <where>
	        <if test="patientId != null ">
	            and patient_id = #{patientId}
	        </if>
	        <if test="signPatientRecordId != null ">
		        and sign_patient_record_id = #{signPatientRecordId}
	        </if>
	        <if test="servicePackageId != null ">
	            and service_package_id = #{servicePackageId}
	        </if>
	        <if test="packageName != null  and packageName != ''">
	            and package_name like concat('%', #{packageName}, '%')
	        </if>
	        <if test="packagePaymentStatus != null  and packagePaymentStatus != ''">
	            and package_payment_status = #{packagePaymentStatus}
	        </if>
	        <if test="packagePrice != null ">
	            and package_price = #{packagePrice}
	        </if>
	        <if test="serviceStartTime != null ">
	            and service_start_time = #{serviceStartTime}
	        </if>
	        <if test="serviceEndTime != null ">
	            and service_end_time = #{serviceEndTime}
	        </if>
	        <if test="packageTerm != null ">
		        and package_term = #{packageTerm}
	        </if>
	        <if test="packageTermUnit != null ">
		        and package_term_unit = #{packageTermUnit}
	        </if>
        </where>
    </select>

    <select id="selectSignPatientPackageById" parameterType="Long" resultMap="SignPatientPackageResult">
        <include refid="selectSignPatientPackageVo"/>
        where id = #{id}
    </select>

    <insert id="insertSignPatientPackage" parameterType="SignPatientPackage" useGeneratedKeys="true"
            keyProperty="id">
        insert into sign_patient_package
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="patientId != null">patient_id,
                    </if>
			        <if test="signPatientRecordId != null ">
				        sign_patient_record_id,
			        </if>
                    <if test="servicePackageId != null">service_package_id,
                    </if>
                    <if test="packageName != null">package_name,
                    </if>
                    <if test="packagePaymentStatus != null">package_payment_status,
                    </if>
                    <if test="packagePrice != null">package_price,
                    </if>
                    <if test="serviceStartTime != null">service_start_time,
                    </if>
                    <if test="serviceEndTime != null">service_end_time,
                    </if>
                    <if test="packageTerm != null">package_term,
                    </if>
			        <if test="packageTermUnit != null">package_term_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="signPatientRecordId != null ">
		        #{signPatientRecordId},
	        </if>
            <if test="servicePackageId != null">#{servicePackageId},
            </if>
            <if test="packageName != null">#{packageName},
            </if>
            <if test="packagePaymentStatus != null">#{packagePaymentStatus},
            </if>
            <if test="packagePrice != null">#{packagePrice},
            </if>
            <if test="serviceStartTime != null">#{serviceStartTime},
            </if>
            <if test="serviceEndTime != null">#{serviceEndTime},
            </if>
            <if test="packageTerm != null">#{packageTerm},
            </if>
	        <if test="packageTermUnit != null">#{packageTermUnit},
	        </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="updateSignPatientPackage" parameterType="SignPatientPackage">
        update sign_patient_package
        <trim prefix="SET" suffixOverrides=",">
            <if test="patientId != null">patient_id =
                #{patientId},
            </if>
	        <if test="signPatientRecordId != null">sign_patient_record_id =
		        #{signPatientRecordId},
	        </if>
            <if test="servicePackageId != null">service_package_id =
                #{servicePackageId},
            </if>
            <if test="packageName != null">package_name =
                #{packageName},
            </if>
            <if test="packagePaymentStatus != null">package_payment_status =
                #{packagePaymentStatus},
            </if>
            <if test="packagePrice != null">package_price =
                #{packagePrice},
            </if>
            <if test="serviceStartTime != null">service_start_time =
                #{serviceStartTime},
            </if>
            <if test="serviceEndTime != null">service_end_time =
                #{serviceEndTime},
            </if>
            <if test="packageTerm != null">package_term =
                #{packageTerm},
            </if>
	        <if test="packageTermUnit != null">package_term_unit =
		        #{packageTermUnit},
	        </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="deleteSignPatientPackageById" parameterType="Long">
        delete from sign_patient_package where id = #{id}
    </delete>

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