<?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.patientvisitoperation.PatientVisitOperationMapper">

    <resultMap type="PatientVisitOperation" id="PatientVisitOperationResult">
            <result property="id" column="id"/>
            <result property="patientVisitRecordId" column="patient_visit_record_id"/>
            <result property="operationName" column="operation_name"/>
            <result property="operationDate" column="operation_date"/>
            <result property="operationAnesthesiaWay" column="operation_anesthesia_way"/>
            <result property="operationApproach" column="operation_approach"/>
            <result property="operationWay" column="operation_way"/>
            <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="selectPatientVisitOperationVo">
        select id, patient_visit_record_id, operation_name, operation_date, operation_anesthesia_way, operation_approach, operation_way, create_by, create_time, update_by, update_time from patient_visit_operation
    </sql>

    <select id="selectPatientVisitOperationList" parameterType="PatientVisitOperation" resultMap="PatientVisitOperationResult">
        <include refid="selectPatientVisitOperationVo"/>
        <where>
                        <if test="patientVisitRecordId != null ">
                            and patient_visit_record_id = #{patientVisitRecordId}
                        </if>
                        <if test="operationName != null  and operationName != ''">
                            and operation_name like concat('%', #{operationName}, '%')
                        </if>
                        <if test="operationDate != null ">
                            and operation_date = #{operationDate}
                        </if>
                        <if test="operationAnesthesiaWay != null  and operationAnesthesiaWay != ''">
                            and operation_anesthesia_way = #{operationAnesthesiaWay}
                        </if>
                        <if test="operationApproach != null  and operationApproach != ''">
                            and operation_approach = #{operationApproach}
                        </if>
                        <if test="operationWay != null  and operationWay != ''">
                            and operation_way = #{operationWay}
                        </if>
        </where>
    </select>

    <select id="selectPatientVisitOperationById" parameterType="Long"
            resultMap="PatientVisitOperationResult">
            <include refid="selectPatientVisitOperationVo"/>
            where id = #{id}
    </select>

    <insert id="insertPatientVisitOperation" parameterType="PatientVisitOperation" useGeneratedKeys="true"
            keyProperty="id">
        insert into patient_visit_operation
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="patientVisitRecordId != null">patient_visit_record_id,
                    </if>
                    <if test="operationName != null">operation_name,
                    </if>
                    <if test="operationDate != null">operation_date,
                    </if>
                    <if test="operationAnesthesiaWay != null">operation_anesthesia_way,
                    </if>
                    <if test="operationApproach != null">operation_approach,
                    </if>
                    <if test="operationWay != null">operation_way,
                    </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="patientVisitRecordId != null">#{patientVisitRecordId},
                    </if>
                    <if test="operationName != null">#{operationName},
                    </if>
                    <if test="operationDate != null">#{operationDate},
                    </if>
                    <if test="operationAnesthesiaWay != null">#{operationAnesthesiaWay},
                    </if>
                    <if test="operationApproach != null">#{operationApproach},
                    </if>
                    <if test="operationWay != null">#{operationWay},
                    </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="updatePatientVisitOperation" parameterType="PatientVisitOperation">
        update patient_visit_operation
        <trim prefix="SET" suffixOverrides=",">
                    <if test="patientVisitRecordId != null">patient_visit_record_id =
                        #{patientVisitRecordId},
                    </if>
                    <if test="operationName != null">operation_name =
                        #{operationName},
                    </if>
                    <if test="operationDate != null">operation_date =
                        #{operationDate},
                    </if>
                    <if test="operationAnesthesiaWay != null">operation_anesthesia_way =
                        #{operationAnesthesiaWay},
                    </if>
                    <if test="operationApproach != null">operation_approach =
                        #{operationApproach},
                    </if>
                    <if test="operationWay != null">operation_way =
                        #{operationWay},
                    </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="deletePatientVisitOperationById" parameterType="Long">
        delete from patient_visit_operation where id = #{id}
    </delete>

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