<?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="jnpf.cultivate.mapper.FtbCultivatePromotionPostMapper">
    <resultMap id="promotionMap" type="jnpf.model.cultivate.vo.promotion.FtbCultivatePromotionVO">
        <id property="id" column="id" jdbcType="VARCHAR"  javaType="java.lang.String"/>
        <result property="promotion" column="promotion" jdbcType="VARCHAR"  javaType="java.lang.String"/>
        <result property="promotionBusinessId" column="promotionBusinessId" jdbcType="VARCHAR"  javaType="java.lang.String"/>
        <result property="channelIniPoId" column="channelIniPoId" jdbcType="VARCHAR"  javaType="java.lang.String"/>
        <result property="channelIniName" column="channelIniName" jdbcType="VARCHAR"  javaType="java.lang.String"/>
        <result property="lastModifyTime" column="lastModifyTime" jdbcType="DATETIMEOFFSET"  javaType="java.util.Date"/>
        <result property="creatorTime" column="creatorTime" jdbcType="DATETIMEOFFSET"  javaType="java.util.Date"/>
        <collection select="jnpf.cultivate.mapper.FtbCultivatePromotionMapper.promoPostId" property="postChannelLevel" column="id" javaType="java.util.ArrayList"/>
    </resultMap>
    <!--查询同一岗位的其他任职信息-->
    <select id="queryPromonChanOfTheSamePosition"
            resultMap="promotionMap">
        SELECT
        distinct
        pr.F_Id AS id,
        pr.F_Promotion AS promotion,
        pr.F_PromotionBusinessId AS promotionBusinessId,
        pr.F_LastModifyTime AS lastModifyTime,
        pr.F_CreatorTime AS creatorTime,
        po.F_PostId channelIniPoId,
        po.F_PostName channelIniName
        FROM
        ftb_cultivate_promotion AS pr
        LEFT JOIN ftb_cultivate_promotion_post AS po ON pr.F_Id = po.F_PromotionId AND po.F_Level =1
        <where>
            pr.F_EnableMark=0
            <if test="postId != null">
                and  po.F_PostId =#{postId}
            </if>
            <if test="promotionVOId != null">
                and  pr.F_Id not in ( #{promotionVOId} )
            </if>
        </where>
        ORDER BY
        pr.F_Promotion
    </select>
    <!--查询个人下一次晋职信息-->
    <select id="findOutAboutTheNextPromotion"  resultType="jnpf.model.cultivate.vo.promotion.FtbCultivatePromotionPostVO">
        SELECT
            p.F_Id as promotionPostId,
            p.F_PromotionId AS promotionId,
            p.F_Level as channelLevel,
            p.F_PostId as postId,
            p.F_PostName  as postName
        FROM
            ftb_cultivate_promotion_post AS p
                INNER JOIN (
                SELECT
                    po.F_Id,
                    po.F_PromotionId,
                    po.F_PostId,
                    po.F_Level,
                    po.F_PostName
                FROM
                    ftb_cultivate_promotion_post AS po
                        INNER JOIN ftb_cultivate_promotion_member AS me ON po.F_PromotionId = me.F_PromotionId
                WHERE
                    po.F_PostId = #{postId}
                  AND me.F_UserId = #{userId}
                  AND me.F_EnableStatus = 1
            ) AS a ON p.F_PromotionId = a.F_PromotionId
        WHERE
            p.F_Level = a.F_Level + 1
    </select>
</mapper>