<?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.patientintegralchange.PatientIntegralChangeMapper">

    <resultMap type="PatientIntegralChange" id="PatientIntegralChangeResult">
        <result property="id" column="id"/>
        <result property="patientId" column="patient_id"/>
        <result property="originalIntegral" column="original_integral"/>
        <result property="changeIntegral" column="change_integral"/>
        <result property="changeTime" column="change_time"/>
        <result property="changeType" column="change_type"/>
        <result property="changeRemark" column="change_remark"/>
        <result property="changeIntegralChannel" column="change_integral_channel"/>
        <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="selectPatientIntegralChangeVo">
        select id, patient_id, original_integral, change_integral, change_time, change_type, change_remark,change_integral_channel, create_by, create_time, update_by, update_time from patient_integral_change
    </sql>

    <select id="selectPatientIntegralChangeList" parameterType="PatientIntegralChange"
            resultMap="PatientIntegralChangeResult">
        <include refid="selectPatientIntegralChangeVo"/>
        <where>
            <if test="patientId != null ">
                and patient_id = #{patientId}
            </if>
            <if test="originalIntegral != null ">
                and original_integral = #{originalIntegral}
            </if>
            <if test="changeIntegral != null ">
                and change_integral = #{changeIntegral}
            </if>
            <if test="changeTime != null ">
                and change_time = #{changeTime}
            </if>
            <if test="changeType != null  and changeType != ''">
                and change_type = #{changeType}
            </if>
            <if test="changeRemark != null  and changeRemark != ''">
                and change_remark = #{changeRemark}
            </if>
        </where>
    </select>

    <select id="selectPatientIntegralChangeById" parameterType="Long"
            resultMap="PatientIntegralChangeResult">
        <include refid="selectPatientIntegralChangeVo"/>
        where id = #{id}
    </select>

    <insert id="insertPatientIntegralChange" parameterType="PatientIntegralChange" useGeneratedKeys="true"
            keyProperty="id">
        insert into patient_integral_change
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="patientId != null">patient_id,
            </if>
            <if test="originalIntegral != null">original_integral,
            </if>
            <if test="changeIntegral != null">change_integral,
            </if>
            <if test="changeTime != null">change_time,
            </if>
            <if test="changeType != null">change_type,
            </if>
            <if test="changeRemark != null">change_remark,
            </if>
            <if test="changeIntegralChannel != null">change_integral_channel,
            </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="originalIntegral != null">#{originalIntegral},
            </if>
            <if test="changeIntegral != null">#{changeIntegral},
            </if>
            <if test="changeTime != null">#{changeTime},
            </if>
            <if test="changeType != null">#{changeType},
            </if>
            <if test="changeRemark != null">#{changeRemark},
            </if>
            <if test="changeIntegralChannel != null">#{changeIntegralChannel},
            </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="updatePatientIntegralChange" parameterType="PatientIntegralChange">
        update patient_integral_change
        <trim prefix="SET" suffixOverrides=",">
            <if test="patientId != null">patient_id =
                #{patientId},
            </if>
            <if test="originalIntegral != null">original_integral =
                #{originalIntegral},
            </if>
            <if test="changeIntegral != null">change_integral =
                #{changeIntegral},
            </if>
            <if test="changeTime != null">change_time =
                #{changeTime},
            </if>
            <if test="changeType != null">change_type =
                #{changeType},
            </if>
            <if test="changeRemark != null">change_remark =
                #{changeRemark},
            </if>
            <if test="changeIntegralChannel != null">change_integral_channel =
                #{changeIntegralChannel},
            </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="deletePatientIntegralChangeById" parameterType="Long">
        delete from patient_integral_change where id = #{id}
    </delete>

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