<?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.aucma.report.mapper.BasePdaRecordMapper">

    <resultMap type="BasePdaRecord" id="BasePdaRecordResult">
        <result property="objId" column="obj_id"/>
        <result property="pdaName" column="pda_name"/>
        <result property="serialCode" column="serial_code"/>
        <result property="remark" column="remark"/>
        <result property="procedureCode" column="procedure_code"/>
        <result property="isFlag" column="is_flag"/>
        <result property="createdBy" column="created_by"/>
        <result property="createdTime" column="created_time"/>
        <result property="updatedBy" column="updated_by"/>
        <result property="updatedTime" column="updated_time"/>
    </resultMap>

    <sql id="selectBasePdaRecordVo">
        select obj_id,
               pda_name,
               serial_code,
               remark,
               procedure_code,
               is_flag,
               created_by,
               created_time,
               updated_by,
               updated_time
        from base_pda_record
    </sql>

    <select id="selectBasePdaRecordList" parameterType="BasePdaRecord" resultMap="BasePdaRecordResult">
        <include refid="selectBasePdaRecordVo"/>
        <where>
            <if test="pdaName != null  and pdaName != ''">and pda_name like concat(concat('%', #{pdaName}), '%')</if>
            <if test="serialCode != null  and serialCode != ''">and serial_code = #{serialCode}</if>
            <if test="procedureCode != null ">and procedure_code = #{procedureCode}</if>
            <if test="isFlag != null ">and is_flag = #{isFlag}</if>
            <if test="createdBy != null  and createdBy != ''">and created_by = #{createdBy}</if>
            <if test="createdTime != null ">and created_time = #{createdTime}</if>
            <if test="updatedBy != null  and updatedBy != ''">and updated_by = #{updatedBy}</if>
            <if test="updatedTime != null ">and updated_time = #{updatedTime}</if>
        </where>
        order by pda_name
    </select>

    <select id="selectBasePdaRecordByObjId" parameterType="Long" resultMap="BasePdaRecordResult">
        <include refid="selectBasePdaRecordVo"/>
        where obj_id = #{objId}
    </select>

    <insert id="insertBasePdaRecord" parameterType="BasePdaRecord">
        <selectKey keyProperty="objId" resultType="long" order="BEFORE">
            SELECT seq_base_pda_record.NEXTVAL as objId FROM DUAL
        </selectKey>
        insert into base_pda_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objId != null">obj_id,</if>
            <if test="pdaName != null">pda_name,</if>
            <if test="serialCode != null">serial_code,</if>
            <if test="remark != null">remark,</if>
            <if test="procedureCode != null">procedure_code,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="createdBy != null">created_by,</if>
            <if test="createdTime != null">created_time,</if>
            <if test="updatedBy != null">updated_by,</if>
            <if test="updatedTime != null">updated_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objId != null">#{objId},</if>
            <if test="pdaName != null">#{pdaName},</if>
            <if test="serialCode != null">#{serialCode},</if>
            <if test="remark != null">#{remark},</if>
            <if test="procedureCode != null">#{procedureCode},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="createdBy != null">#{createdBy},</if>
            <if test="createdTime != null">#{createdTime},</if>
            <if test="updatedBy != null">#{updatedBy},</if>
            <if test="updatedTime != null">#{updatedTime},</if>
        </trim>
    </insert>

    <update id="updateBasePdaRecord" parameterType="BasePdaRecord">
        update base_pda_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="pdaName != null">pda_name = #{pdaName},</if>
            <if test="serialCode != null">serial_code = #{serialCode},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="procedureCode != null">procedure_code = #{procedureCode},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="createdBy != null">created_by = #{createdBy},</if>
            <if test="createdTime != null">created_time = #{createdTime},</if>
            <if test="updatedBy != null">updated_by = #{updatedBy},</if>
            <if test="updatedTime != null">updated_time = #{updatedTime},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteBasePdaRecordByObjId" parameterType="Long">
        delete
        from base_pda_record
        where obj_id = #{objId}
    </delete>

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