<?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.goafanti.common.dao.UserTransferLogMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.UserTransferLog">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Apr 23 09:38:20 CST 2021.
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="uid" jdbcType="VARCHAR" property="uid" />
    <result column="aid" jdbcType="VARCHAR" property="aid" />
    <result column="pid" jdbcType="VARCHAR" property="pid" />
    <result column="take_aid" jdbcType="VARCHAR" property="takeAid" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Apr 23 09:38:20 CST 2021.
    -->
    id, `uid`, aid, pid, take_aid, `type`, create_time, remarks
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Apr 23 09:38:20 CST 2021.
    -->
    select 
    <include refid="Base_Column_List" />
    from user_transfer_log
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Apr 23 09:38:20 CST 2021.
    -->
    delete from user_transfer_log
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.UserTransferLog">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Apr 23 09:38:20 CST 2021.
    -->
    insert into user_transfer_log (id, `uid`, aid, 
      pid, take_aid, `type`, 
      create_time, remarks)
    values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=VARCHAR}, #{aid,jdbcType=VARCHAR}, 
      #{pid,jdbcType=VARCHAR}, #{takeAid,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, 
      #{createTime,jdbcType=TIMESTAMP}, #{remarks,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.UserTransferLog">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Apr 23 09:38:20 CST 2021.
    -->
    insert into user_transfer_log
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="uid != null">
        `uid`,
      </if>
      <if test="aid != null">
        aid,
      </if>
      <if test="pid != null">
        pid,
      </if>
      <if test="takeAid != null">
        take_aid,
      </if>
      <if test="type != null">
        `type`,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="uid != null">
        #{uid,jdbcType=VARCHAR},
      </if>
      <if test="aid != null">
        #{aid,jdbcType=VARCHAR},
      </if>
      <if test="pid != null">
        #{pid,jdbcType=VARCHAR},
      </if>
      <if test="takeAid != null">
        #{takeAid,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.UserTransferLog">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Apr 23 09:38:20 CST 2021.
    -->
    update user_transfer_log
    <set>
      <if test="uid != null">
        `uid` = #{uid,jdbcType=VARCHAR},
      </if>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="pid != null">
        pid = #{pid,jdbcType=VARCHAR},
      </if>
      <if test="takeAid != null">
        take_aid = #{takeAid,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        `type` = #{type,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remarks != null">
        remarks = #{remarks,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.UserTransferLog">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Apr 23 09:38:20 CST 2021.
    -->
    update user_transfer_log
    set `uid` = #{uid,jdbcType=VARCHAR},
      aid = #{aid,jdbcType=VARCHAR},
      pid = #{pid,jdbcType=VARCHAR},
      take_aid = #{takeAid,jdbcType=VARCHAR},
      `type` = #{type,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      remarks = #{remarks,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <select id="selectByUidGetList" resultType="com.goafanti.customer.bo.transferListBo">
	select a.id,a.type,b.nickname userName,c.name usedAName,d.name newAName,e.bname Pname, 
  	date_format(a.create_time,'%Y-%m-%d %H:%i:%S') as createDate,remarks
  	from user_transfer_log a left join user b on a.uid=b.id
	left join admin c on a.aid=c.id left join admin d on a.take_aid=d.id
	left join business_project e on a.pid=e.id 
	where uid= #{uid}
	order by a.id
  </select>
  
   <insert id="insertList">
    insert into user_transfer_log ( uid, aid, 
      pid, take_aid, type, remarks,
      create_time)
    values 
    <foreach collection="list" index="" item="item" separator=",">
    ( #{item.uid,jdbcType=VARCHAR}, #{item.aid,jdbcType=VARCHAR}, 
      #{item.pid,jdbcType=VARCHAR}, #{item.takeAid,jdbcType=VARCHAR}, #{item.type,jdbcType=INTEGER}, 
      #{item.remarks},#{item.createTime,jdbcType=TIMESTAMP})
     </foreach>
  </insert>
  
     <insert id="insertBatch">
    insert into user_transfer_log ( uid, aid, 
      type, 
      create_time)
    values 
    <foreach collection="list" index="" item="item" separator=",">
    ( #{item.uid,jdbcType=VARCHAR}, #{item.aid,jdbcType=VARCHAR}, 
     8, 
      #{item.createTime,jdbcType=TIMESTAMP})
     </foreach>
  </insert>
  <insert id="insertUserLog">
   	INSERT INTO user_transfer_log (uid, aid, take_aid, `type`, create_time)
select id,aid, #{transferId},13,#{date} from user where share_type =0 and aid = #{aid}
  </insert>
  <insert id="insertUserLockLog">
	INSERT INTO user_transfer_log (uid, aid, take_aid,pid, `type`,create_time)
	select a.id,a.aid,#{transferId},b.business_project_id ,14,#{date} from `user` a 
	left join user_lock_release b on a.id=b.uid
	where a.share_type =2 and a.aid= #{aid} and b.`type` =1
  </insert>
  
</mapper>