<?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.post.PostMapper">
    <resultMap id="BaseResultMap" type="com.engine.organization.entity.postion.po.PostPO">
        <result column="id" property="id"/>
        <result column="post_name" property="postName"/>
        <result column="description" property="description"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <resultMap id="TreeResultMap" type="com.engine.organization.entity.TreeData">
        <result column="id" property="key"/>
        <result column="post_name" property="title"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        id
        , t.post_name
        , t.description
        , t.creator
        , t.delete_type
        , t.create_time
        , t.update_time
    </sql>
    <select id="getPostByID" parameterType="com.engine.organization.entity.postion.po.PostPO"
            resultMap="BaseResultMap">
        select
        <include refid="baseColumns"/>
        from jcl_org_post t where id = #{id} AND delete_type = 0
    </select>

    <!-- 浏览按钮赋值、展示用 -->
    <select id="listPostsByIds" resultType="java.util.Map">
        select
        id as "id",
        post_name as "name"
        from jcl_org_post t
        WHERE delete_type = 0
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <select id="getTreeData" resultMap="TreeResultMap">
        select id, post_name
        from jcl_org_post
        where delete_type = '0'
    </select>

    <select id="getPostByName" resultMap="BaseResultMap">
        select
        <include refid="baseColumns"/>
        from jcl_org_post t where post_name = #{postName} AND delete_type = 0
    </select>

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

    <update id="updatePost" parameterType="com.engine.organization.entity.postion.po.PostPO">
        update jcl_org_post
        <set>
            creator=#{creator},
            update_time=#{updateTime},
            post_name=#{postName},
            description=#{description},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>

    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.postion.po.PostPO" keyProperty="id"
            keyColumn="id" useGeneratedKeys="true">
        INSERT INTO jcl_org_post
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <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>
            <if test="postName != null ">
                post_name,
            </if>
            <if test="description != null ">
                description,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="postName != null ">
                #{postName},
            </if>
            <if test="description != null ">
                #{description},
            </if>
        </trim>
    </insert>

    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.postion.po.PostPO" databaseId="oracle">
        <selectKey  keyProperty="id" resultType="long" order="AFTER">
            select JCL_ORG_POST_ID.currval from dual
        </selectKey>
        INSERT INTO jcl_org_post
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <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>
            <if test="postName != null ">
                post_name,
            </if>
            <if test="description != null ">
                description,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="creator != null">
                #{creator},
            </if>
            <if test="deleteType != null">
                #{deleteType},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
            <if test="postName != null ">
                #{postName},
            </if>
            <if test="description != null ">
                #{description},
            </if>
        </trim>
    </insert>

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

</mapper>