<?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.engine.organization.mapper.jclimport.JclImportHistoryDetailMapper">
    <resultMap id="BaseResultMap" type="com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO">
        <result column="id" property="id"/>
        <result column="pid" property="pid"/>
        <result column="row_nums" property="rowNums"/>
        <result column="status" property="status"/>
        <result column="operate_detail" property="operateDetail"/>
        <result column="related_name" property="relatedName"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        id
        , t.pid
        , t.row_nums
        , t.status
        , t.operate_detail
        , t.related_name
    </sql>
    <insert id="insertHistoryDetail"
            parameterType="com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO" keyProperty="id"
            keyColumn="id" useGeneratedKeys="true">
        INSERT INTO jcl_import_history_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pid != null">
                pid,
            </if>
            <if test="rowNums != null">
                row_nums,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="operateDetail != null">
                operate_detail,
            </if>
            <if test="relatedName != null ">
                related_name,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="pid != null">
                #{pid},
            </if>
            <if test="rowNums != null">
                #{rowNums},
            </if>
            <if test="status != null">
                #{status},
            </if>
            <if test="operateDetail != null">
                #{operateDetail},
            </if>
            <if test="relatedName != null ">
                #{relatedName},
            </if>
        </trim>
    </insert>

    <insert id="insertHistoryDetail"  parameterType="com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO" databaseId="oracle">
        <selectKey  keyProperty="id" resultType="long" order="AFTER">
            select JCL_IMPORT_DETAIL_ID.currval from dual
        </selectKey>
        INSERT INTO jcl_import_history_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="pid != null">
                pid,
            </if>
            <if test="rowNums != null">
                row_nums,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="operateDetail != null">
                operate_detail,
            </if>
            <if test="relatedName != null ">
                related_name,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="pid != null">
                #{pid},
            </if>
            <if test="rowNums != null">
                #{rowNums},
            </if>
            <if test="status != null">
                #{status},
            </if>
            <if test="operateDetail != null">
                #{operateDetail},
            </if>
            <if test="relatedName != null ">
                #{relatedName},
            </if>
        </trim>
    </insert>

    <select id="countRows" resultType="java.lang.Integer">
        select count(1)
        from jcl_import_history_detail
        where status = #{status}
          and pid = #{pId}
    </select>
</mapper>