<?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.staff.StaffPlanMapper">
    <resultMap id="BaseResultMap" type="com.engine.organization.entity.staff.po.StaffPlanPO">
        <result column="id" property="id"/>
        <result column="plan_no" property="planNo"/>
        <result column="plan_name" property="planName"/>
        <result column="plan_year" property="planYear"/>
        <result column="time_start" property="timeStart"/>
        <result column="time_end" property="timeEnd"/>
        <result column="company_id" property="companyId"/>
        <result column="ec_company" property="ecCompany"/>
        <result column="control_dimension" property="controlDimension"/>
        <result column="description" property="description"/>
        <result column="forbidden_tag" property="forbiddenTag"/>
        <result column="creator" property="creator"/>
        <result column="delete_type" property="deleteType"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <!-- 表字段 -->
    <sql id="baseColumns">
        t
        .
        id
        , t.plan_no
        , t.plan_name
        , t.plan_year
        , t.time_start
        , t.time_end
        , t.company_id
        , t.ec_company
        , t.control_dimension
        , t.description
        , t.forbidden_tag
        , t.creator
        , t.delete_type
        , t.create_time
        , t.update_time
    </sql>
    <select id="getStaffPlanByID" parameterType="com.engine.organization.entity.staff.po.StaffPlanPO"
            resultMap="BaseResultMap">
        select
        <include refid="baseColumns"/>
        from jcl_org_staffplan t where id = #{id} AND delete_type = 0
    </select>

    <select id="listByNo" parameterType="com.engine.organization.entity.staff.po.StaffPlanPO"
            resultMap="BaseResultMap">
        select
        <include refid="baseColumns"/>
        from jcl_org_staffplan t where plan_no = #{planNo} AND delete_type = 0
    </select>
    <select id="listPlansByIds" resultType="java.util.Map">
        select
        id as "id",
        plan_name as "name"
        from jcl_org_staffplan t
        WHERE delete_type = 0
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </select>
    <select id="listUsedId" resultType="java.lang.String">
        select plan_id
        from JCL_ORG_STAFF
        where delete_type = 0
    </select>
    <select id="getStaffPlansByIds" resultMap="BaseResultMap">
        select
        <include refid="baseColumns"/>
        from jcl_org_staffplan t
        WHERE delete_type = 0
        AND id IN
        <foreach collection="ids" open="(" item="id" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <update id="updateStaffPlan" parameterType="com.engine.organization.entity.staff.po.StaffPlanPO">
        update jcl_org_staffplan
        <set>
            creator=#{creator},
            update_time=#{updateTime},
            plan_no=#{planNo},
            plan_name=#{planName},
            plan_year=#{planYear},
            time_start=#{timeStart},
            time_end=#{timeEnd},
            company_id=#{companyId},
            ec_company=#{ecCompany},
            control_dimension=#{controlDimension},
            description=#{description},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>

    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.staff.po.StaffPlanPO" keyProperty="id"
            keyColumn="id" useGeneratedKeys="true">
        INSERT INTO jcl_org_staffplan
        <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="planNo != null ">
                plan_no,
            </if>
            <if test="planName != null ">
                plan_name,
            </if>
            <if test="planYear != null ">
                plan_year,
            </if>
            <if test="timeStart != null ">
                time_start,
            </if>
            <if test="timeEnd != null ">
                time_end,
            </if>
            <if test="companyId != null ">
                company_id,
            </if>
            <if test="ecCompany != null ">
                ec_company,
            </if>
            <if test="controlDimension != null ">
                control_dimension,
            </if>
            <if test="description != null ">
                description,
            </if>
            forbidden_tag,
        </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="planNo != null ">
                #{planNo},
            </if>
            <if test="planName != null ">
                #{planName},
            </if>
            <if test="planYear != null ">
                #{planYear},
            </if>
            <if test="timeStart != null ">
                #{timeStart},
            </if>
            <if test="timeEnd != null ">
                #{timeEnd},
            </if>
            <if test="companyId != null ">
                #{companyId},
            </if>
            <if test="ecCompany != null ">
                #{ecCompany},
            </if>
            <if test="controlDimension != null ">
                #{controlDimension},
            </if>
            <if test="description != null ">
                #{description},
            </if>
            0,
        </trim>
    </insert>

    <insert id="insertIgnoreNull" parameterType="com.engine.organization.entity.staff.po.StaffPlanPO"
            databaseId="oracle">
        <selectKey keyProperty="id" resultType="long" order="AFTER">
            select JCL_ORG_STAFFPLAN_ID.currval from dual
        </selectKey>
        INSERT INTO jcl_org_staffplan
        <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="planNo != null ">
                plan_no,
            </if>
            <if test="planName != null ">
                plan_name,
            </if>
            <if test="planYear != null ">
                plan_year,
            </if>
            <if test="timeStart != null ">
                time_start,
            </if>
            <if test="timeEnd != null ">
                time_end,
            </if>
            <if test="companyId != null ">
                company_id,
            </if>
            <if test="ecCompany != null ">
                ec_company,
            </if>
            <if test="controlDimension != null ">
                control_dimension,
            </if>
            <if test="description != null ">
                description,
            </if>
            forbidden_tag,
        </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="planNo != null ">
                #{planNo},
            </if>
            <if test="planName != null ">
                #{planName},
            </if>
            <if test="planYear != null ">
                #{planYear},
            </if>
            <if test="timeStart != null ">
                #{timeStart},
            </if>
            <if test="timeEnd != null ">
                #{timeEnd},
            </if>
            <if test="companyId != null ">
                #{companyId},
            </if>
            <if test="ecCompany != null ">
                #{ecCompany},
            </if>
            <if test="controlDimension != null ">
                #{controlDimension},
            </if>
            <if test="description != null ">
                #{description},
            </if>
            0,
        </trim>
    </insert>

    <update id="updateForbiddenTagById" parameterType="com.engine.organization.entity.staff.po.StaffPlanPO">
        update jcl_org_staffplan
        <set>
            forbidden_tag=#{forbiddenTag},
        </set>
        WHERE id = #{id} AND delete_type = 0
    </update>

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

</mapper>