<?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.personnels.mapper.FtbPersonnelChangesMapper">

    <select id="numberOfPeopleAdjustingTheStore" resultType="java.math.BigDecimal">
        SELECT COUNT(distinct a.F_UserId) FROM ftb_personnels_transfer_manage a WHERE
        a.F_EnableMark = 0 and a.F_ProcessingStatus in (2,6) and a.F_State = #{state}
        <if test="userIds != null and userIds.size() != 0">
            and a.F_UserId IN
            <foreach collection="userIds" open="(" close=")" separator="," item="userId">
                #{userId}
            </foreach>
        </if>
        AND DATE_FORMAT(a.F_EffectiveDate, '%Y-%m') = #{startMonth}
<!--        AND (DATE_FORMAT(a.F_EffectiveDate, '%Y-%m') &gt;= #{startMonth} and DATE_FORMAT(a.F_EffectiveDate, '%Y-%m') &lt;= #{endMonth})-->
    </select>

    <select id="departmentHeadcountRatio" resultType="java.lang.String">
        SELECT distinct a.F_UserId
        FROM ftb_personnels_transfer_manage a
        WHERE a.F_EnableMark = 0 and a.F_ProcessingStatus in (2,6) and a.F_State = #{state}
        <if test="userIds != null and userIds.size() != 0">
            and a.F_UserId IN
            <foreach collection="userIds" open="(" close=")" separator="," item="userId">
                #{userId}
            </foreach>
        </if>
        AND DATE_FORMAT(a.F_EffectiveDate, '%Y-%m') = #{startMonth}
<!--        AND (DATE_FORMAT(a.F_EffectiveDate, '%Y-%m') &gt;= #{startMonth} and DATE_FORMAT(a.F_EffectiveDate, '%Y-%m') &lt;= #{endMonth})-->
    </select>

    <select id="numberOfPeopleAdjustingTheStoreList"
            resultType="jnpf.model.personnels.vo.analysis.FtbPersonnelsShopAdjustmentDetailsVO">
        SELECT
        a.F_UserId AS userId,
        a.F_BeforeOrgName as beforeOrganization,
        a.F_BeforePostName as beforePosition,
        a.F_BeforeRankName as beforeRank,
        DATE_FORMAT(a.F_EffectiveDate, '%Y-%m-%d') as adjustDate,
        a.F_AfterOrgName AS aFOrganization,
        a.F_AfterPostName AS aFPosition,
        a.F_AfterRankName AS aFRank
        FROM ftb_personnels_transfer_manage a
        WHERE a.F_EnableMark = 0 and a.F_ProcessingStatus in (2,6) and a.F_State = #{state}
        <if test="userIds != null and userIds.size() != 0">
            and a.F_UserId IN
            <foreach collection="userIds" open="(" close=")" separator="," item="userId">
                #{userId}
            </foreach>
        </if>
        AND DATE_FORMAT(a.F_EffectiveDate, '%Y-%m') = #{startMonth}
    </select>
    
    <select id="numberOfPeopleAdjustingThePostList"
            resultType="jnpf.model.personnels.vo.analysis.FtbPersonnelsPostAdjustmentDetailsVO">
        SELECT
        a.F_UserId AS userId,
        a.F_BeforeOrgName as beforeOrganization,
        a.F_BeforePostName as beforePosition,
        a.F_BeforeRankName as beforeRank,
        DATE_FORMAT(a.F_EffectiveDate, '%Y-%m-%d') as adjustDate,
        a.F_AfterOrgName AS organization,
        a.F_AfterPostName AS position,
        a.F_AfterRankName AS `rank`
        FROM ftb_personnels_transfer_manage a
        WHERE a.F_EnableMark = 0 and a.F_ProcessingStatus in (2,6) and a.F_State = #{state}
        <if test="userIds != null and userIds.size() != 0">
            and a.F_UserId IN
            <foreach collection="userIds" open="(" close=")" separator="," item="userId">
                #{userId}
            </foreach>
        </if>
        AND DATE_FORMAT(a.F_EffectiveDate, '%Y-%m') = #{startMonth}
    </select>
</mapper>