<?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.detach.ManagerDetachMapper">
    <resultMap id="BaseResultMap" type="com.engine.organization.entity.detach.po.ManagerDetachPO">
        <result column="id" property="id"/>
        <result column="manager_type" property="managerType"/>
        <result column="ec_manager" property="ecManager"/>
        <result column="jcl_manager" property="jclManager"/>
        <result column="ec_rolelevel" property="ecRolelevel"/>
        <result column="jcl_rolelevel" property="jclRolelevel"/>
        <result column="manage_module" property="manageModule"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
    </resultMap>


    <!-- 表字段 -->
    <sql id="baseColumns">
        t.id
        , t.manager_type
        , t.ec_manager
        , t.jcl_manager
        , t.ec_rolelevel
        , t.jcl_rolelevel
        , t.manage_module
        , t.creator
        , t.delete_type
    </sql>



    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.detach.po.ManagerDetachPO" keyProperty="id"
            keyColumn="id" useGeneratedKeys="true">
        INSERT INTO jcl_org_detach
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="managerType != null ">
                manager_type,
            </if>
            <if test="ecManager != null ">
                ec_manager,
            </if>
            <if test="jclManager != null ">
                jcl_manager,
            </if>
            <if test="ecRolelevel != null ">
                ec_rolelevel,
            </if>
            <if test="jclRolelevel != null ">
                jcl_rolelevel,
            </if>
            <if test="manageModule != null ">
                manage_module,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="managerType != null ">
                #{managerType},
            </if>
            <if test="ecManager != null ">
                #{ecManager},
            </if>
            <if test="jclManager != null ">
                #{jclManager},
            </if>
            <if test="ecRolelevel != null ">
                #{ecRolelevel},
            </if>
            <if test="jclRolelevel != null ">
                #{jclRolelevel},
            </if>
            <if test="manageModule != null ">
                #{manageModule},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>

    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.detach.po.ManagerDetachPO" databaseId="oracle">
        <selectKey  keyProperty="id" resultType="int" order="AFTER">
            select JCL_ORG_DETACH_ID.currval from dual
        </selectKey>
        INSERT INTO jcl_org_detach
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="managerType != null ">
                manager_type,
            </if>
            <if test="ecManager != null ">
                ec_manager,
            </if>
            <if test="jclManager != null ">
                jcl_manager,
            </if>
            <if test="ecRolelevel != null ">
                ec_rolelevel,
            </if>
            <if test="jclRolelevel != null ">
                jcl_rolelevel,
            </if>
            <if test="manageModule != null ">
                manage_module,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="deleteType != null">
                delete_type,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="managerType != null ">
                #{managerType},
            </if>
            <if test="ecManager != null ">
                #{ecManager},
            </if>
            <if test="jclManager != null ">
                #{jclManager},
            </if>
            <if test="ecRolelevel != null ">
                #{ecRolelevel},
            </if>
            <if test="jclRolelevel != null ">
                #{jclRolelevel},
            </if>
            <if test="manageModule != null ">
                #{manageModule},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>

    <update id="updateDetach" parameterType="com.engine.organization.entity.detach.po.ManagerDetachPO">
        update jcl_org_detach
        <set>
            ec_manager=#{ecManager},
            jcl_Manager=#{jclManager},
            ec_rolelevel=#{ecRolelevel},
            jcl_rolelevel=#{jclRolelevel}
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>


    <update id="deleteByIds">
        UPDATE jcl_org_detach
        SET delete_type = 1
        WHERE delete_type = 0
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <select id="selectByIds" resultMap="BaseResultMap">
        select
        <include refid="baseColumns"/>
        from jcl_org_detach t
        WHERE delete_type = 0
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </select>


    <select id="getDetachById" resultMap="BaseResultMap">
        select
        <include refid="baseColumns"/>
        from jcl_org_detach t
        WHERE delete_type = 0
        AND id = #{id}
    </select>
    <select id="getDetachListById" resultMap="BaseResultMap">
        select
        <include refid="baseColumns"/>
        from jcl_org_detach t
        WHERE delete_type = 0
        and ec_manager = #{ecManager}
    </select>
</mapper>