<?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.hrmresource.ResourceBasicInfoMapper">

    <resultMap id="ItemResultMap" type="com.engine.organization.entity.hrmresource.po.ResourceItemPO">
        <result column="fid" property="fid"/>
        <result column="fclassid" property="fclassid"/>
        <result column="fno" property="fno"/>
        <result column="fname" property="fname"/>
        <result column="fmemo" property="fmemo"/>
        <result column="fdelete" property="fdelete"/>
    </resultMap>
    <resultMap id="ItemClassResultMap" type="com.engine.organization.entity.hrmresource.po.ResourceItemClassPO">
        <result column="fid" property="fid"/>
        <result column="fno" property="fno"/>
        <result column="fname" property="fname"/>
        <result column="fmemo" property="fmemo"/>
    </resultMap>

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

    <select id="getTreeData" resultMap="TreeResultMap">
        select fid, fname
        from jcl_org_itemclass
    </select>

    <select id="browserDatas" resultType="java.util.Map">
        select
        fid as id,
        fname as name
        from jcl_org_itemclass
        where fid IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </select>


    <select id="getResourceItemByFid" resultType="com.engine.organization.entity.hrmresource.po.ResourceItemPO">
        select fid,
               fclassid,
               fno,
               fname,
               fmemo,
               fdelete,
               creator,
               create_time,
               update_time
        from jcl_org_item
        where fdelete = 0
          and fid = #{fid}
    </select>


    <select id="selectItemByIds" resultMap="ItemResultMap">
        select fid,fclassid,fno,fname,fmemo,fdelete,creator,create_time,update_time
        from jcl_org_item
        where fdelete = 0
        AND fid IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </select>


    <select id="selectItemByFNo" resultMap="ItemResultMap">
        select fid,
               fclassid,
               fno,
               fname,
               fmemo,
               fdelete,
               creator,
               create_time,
               update_time
        from jcl_org_item
        where fno = #{fno}
          and fclassid = #{fclassid}
    </select>

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


    <update id="recoverByIds">
        UPDATE jcl_org_item
        SET fdelete = 0
        WHERE fdelete = 1
        AND fid IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </update>


    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.hrmresource.po.ResourceItemPO"
            keyProperty="fid"
            keyColumn="fid" useGeneratedKeys="true">
        INSERT INTO jcl_org_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fclassid != null">
                fclassid,
            </if>
            <if test="fno != null">
                fno,
            </if>
            <if test="fname != null">
                fname,
            </if>
            <if test="fmemo != null">
                fmemo,
            </if>
            <if test="fdelete != null">
                fdelete,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="fclassid != null">
                #{fclassid},
            </if>
            <if test="fno != null">
                #{fno},
            </if>
            <if test="fname != null">
                #{fname},
            </if>
            <if test="fmemo != null">
                #{fmemo},
            </if>
            <if test="fdelete != null">
                #{fdelete},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>

    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.hrmresource.po.ResourceItemPO" databaseId="oracle">
        <selectKey keyProperty="fid" resultType="int" order="AFTER">
            select JCL_ORG_ITEM_ID.currval from dual
        </selectKey>
        INSERT INTO jcl_org_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fclassid != null">
                fclassid,
            </if>
            <if test="fno != null">
                fno,
            </if>
            <if test="fname != null">
                fname,
            </if>
            <if test="fmemo != null">
                fmemo,
            </if>
            <if test="fdelete != null">
                fdelete,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="fclassid != null">
                #{fclassid},
            </if>
            <if test="fno != null">
                #{fno},
            </if>
            <if test="fname != null">
                #{fname},
            </if>
            <if test="fmemo != null">
                #{fmemo},
            </if>
            <if test="fdelete != null">
                #{fdelete},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>


    <!--oracle未处理-->
    <!--<insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.hrmresource.po.ResourceItemPO"-->
    <!--databaseId="oracle">-->
    <!--</insert>-->

    <update id="update" parameterType="com.engine.organization.entity.hrmresource.po.ResourceItemPO">
        update jcl_org_item
        <set>
            fname=#{fname},
            fmemo=#{fmemo},
            update_time=#{updateTime},
        </set>
        WHERE fid = #{fid} AND fdelete = 0
    </update>

    <select id="getResourceItemClassByFid" resultMap="ItemClassResultMap">
        select fid,
               fno,
               fname,
               fmemo,
               creator,
               create_time,
               update_time
        from jcl_org_itemclass
        where fid = #{fid}
    </select>


    <insert id="saveResourceItemClass">
        INSERT INTO jcl_org_itemclass
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fno != null">
                fno,
            </if>
            <if test="fname != null">
                fname,
            </if>
            <if test="fmemo != null">
                fmemo,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="fno != null">
                #{fno},
            </if>
            <if test="fname != null">
                #{fname},
            </if>
            <if test="fmemo != null">
                #{fmemo},
            </if>
            <if test="creator != null">
                #{creator},
            </if>
            <if test="createTime != null">
                #{createTime},
            </if>
            <if test="updateTime != null">
                #{updateTime},
            </if>
        </trim>
    </insert>

    <select id="selectItemClassByFNo" resultMap="ItemClassResultMap">
        select fid,
        fno,
        fname,
        fmemo,
        creator,
        create_time,
        update_time
        from jcl_org_itemclass
        where fno = #{fno}
        <if test=" fid !=null ">
            and fid != #{fid}
        </if>
    </select>
    <select id="getItemByClassId" resultMap="ItemResultMap">
        select fid,
        fclassid,
        fno,
        fname,
        fmemo,
        fdelete,
        creator,
        create_time,
        update_time
        from jcl_org_item
        where fclassid = #{fclassid}
        <if test="fdelete!=null">
            and fdelete = #{fdelete}
        </if>
    </select>

    <update id="updateResourceItemClass">
        update jcl_org_itemclass
        <set>
            fname=#{fname},
            fmemo=#{fmemo},
            update_time=#{updateTime},
        </set>
        WHERE fid = #{fid}
    </update>

    <delete id="deleteResourceItemClass">
        delete
        from jcl_org_itemclass
        where fid = #{fid}
    </delete>
    <delete id="deleteItemByIds">
        delete
        from jcl_org_item
        where fid IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>