<?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.FtbPersonnelsTransferManageMapper">

  <select id="transferManageList" resultType="jnpf.model.personnels.vo.transfer.FtbHandleTransferPageVO">
    SELECT
      a.F_Id as id,
      a.F_UserId as userId,
      b.F_Name as userName,
      b.F_SystemWokerId as userCustomId,
      a.F_BeforeOrgId as oldOrganizeId,
      a.F_BeforeOrgName as oldOrganizeName,
      a.F_BeforePostId as oldPostId,
      a.F_BeforePostName as oldPostName,
      a.F_BeforeRankId as oldRankId,
      a.F_BeforeRankName as oldRankName,
      a.F_AfterOrgId as newOrganizeId,
      a.F_AfterOrgName as newOrganizeName,
      a.F_AfterPostId as newPostId,
      a.F_AfterPostName as newPostName,
      a.F_AfterRankId as newRankId,
      a.F_AfterRankName as newRankName,
      a.F_State as transferType,
      a.F_EffectiveDate as effectDate,
      a.F_ProcessingStatus as state,
      a.F_TaskInfoId as taskInfoId,
      b.F_WorkerStatus as workingCondition,
      a.F_Source as source,
      b.F_JoinNum as joinNum
    FROM ftb_personnels_transfer_manage a JOIN ftb_personnels_staff_roster b ON a.F_UserId = b.F_UserId
    <where>
      a.F_EnableMark = 0
      <if test="params.userName != null and params.userName != ''">
        AND b.F_Name LIKE concat('%',#{params.userName},'%')
      </if>
      <if test="params.organizeId != null and params.organizeId != ''">
        AND locate(a.F_AfterOrgId,#{params.organizeId}) > 0
      </if>
      <if test="params.postId != null and params.postId != ''">
        AND a.F_AfterPostId = #{params.postId}
      </if>
      <if test="params.state != null">
        AND a.F_ProcessingStatus = #{params.state}
      </if>
      <if test="params.transferType != null">
        AND a.F_State = #{params.transferType}
      </if>
      <if test="params.startDate != null and params.startDate != '' and params.endDate != null and params.endDate != ''">
        AND DATE_FORMAT(a.F_EffectiveDate, '%Y-%m-%d') BETWEEN #{params.startDate} AND #{params.endDate}
      </if>
    </where>
    order by a.F_Id desc
  </select>

  <select id="transferListApp" resultType="jnpf.model.personnels.vo.transfer.FtbHandleTransferPageVO">
    SELECT
    a.F_Id as id,
    a.F_UserId as userId,
    b.F_Name as userName,
    b.F_SystemWokerId as userCustomId,
    a.F_BeforeOrgId as oldOrganizeId,
    a.F_BeforeOrgName as oldOrganizeName,
    a.F_BeforePostId as oldPostId,
    a.F_BeforePostName as oldPostName,
    a.F_BeforeRankId as oldRankId,
    a.F_BeforeRankName as oldRankName,
    a.F_AfterOrgId as newOrganizeId,
    a.F_AfterOrgName as newOrganizeName,
    a.F_AfterPostId as newPostId,
    a.F_AfterPostName as newPostName,
    a.F_AfterRankId as newRankId,
    a.F_AfterRankName as newRankName,
    a.F_State as transferType,
    a.F_EffectiveDate as effectDate,
    a.F_ProcessingStatus as state,
    a.F_TaskInfoId as taskInfoId,
    a.F_AfterTeamId as afterTeamId,
    a.F_AfterTeamName as afterTeamName,
    b.F_WorkerStatus as workingCondition,
    a.F_Source as source,
    b.F_JoinNum as joinNum
    FROM ftb_personnels_transfer_manage a JOIN ftb_personnels_staff_roster b ON a.F_UserId = b.F_UserId
    <where>
      a.F_EnableMark = 0
      <if test="userIds != null and userIds.size() != 0">
        and a.F_UserId in
        <foreach collection="userIds" separator="," open="(" close=")" item="userId">
          #{userId}
       </foreach>
      </if>
      <if test="keyWord != null and keyWord != ''">
        AND b.F_Name LIKE concat('%',#{keyWord},'%')
      </if>
    </where>
    order by a.F_Id desc
    </select>

  <select id="transferDetails" resultType="jnpf.model.personnels.vo.transfer.FtbHandleTransferDetailsVO">
    SELECT
    a.F_Id as mobilizeId,
    a.F_UserId as userId,
    b.F_Name as userName,
    b.F_SystemWokerId as userCustomId,
    a.F_BeforeOrgId as oldOrganizeId,
    a.F_BeforeOrgName as oldOrganizeName,
    a.F_BeforePostId as oldPostId,
    a.F_BeforePostName as oldPostName,
    a.F_BeforeRankId as oldRankId,
    a.F_BeforeRankName as oldRankName,
    a.F_AfterOrgId as newOrganizeId,
    a.F_AfterOrgName as newOrganizeName,
    a.F_AfterPostId as newPostId,
    a.F_AfterPostName as newPostName,
    a.F_AfterRankId as newRankId,
    a.F_AfterRankName as newRankName,
    a.F_State as transferType,
    a.F_EffectiveDate as effectDate,
    a.F_ProcessingStatus as state,
    a.F_TaskInfoId as taskInfoId
    FROM ftb_personnels_transfer_manage a JOIN ftb_personnels_staff_roster b ON a.F_UserId = b.F_UserId
    where
      a.F_EnableMark = 0 and a.F_Id = #{id}
  </select>

  <update id="updateTransferManage">
    UPDATE ftb_personnels_transfer_manage a SET a.F_ImplementType = 1 WHERE
    a.F_EnableMark = 0 and a.F_ProcessingStatus in (2,6) and a.F_ImplementType = 0
    and DATE_FORMAT(a.F_EffectiveDate, '%Y-%m-%d') &lt;= DATE_FORMAT(now(), '%Y-%m-%d')
  </update>

</mapper>