<?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.UserNamesMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.UserNames">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jul 05 11:40:49 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="name" jdbcType="VARCHAR" property="name" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  </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 Mon Jul 05 11:40:49 CST 2021.
    -->
    id, `uid`, aid, `name`, create_time
  </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 Mon Jul 05 11:40:49 CST 2021.
    -->
    select 
    <include refid="Base_Column_List" />
    from user_names
    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 Mon Jul 05 11:40:49 CST 2021.
    -->
    delete from user_names
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.UserNames">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jul 05 11:40:49 CST 2021.
    -->
    insert into user_names (id, `uid`, aid, 
      `name`, create_time)
    values (#{id,jdbcType=INTEGER}, #{uid,jdbcType=VARCHAR}, #{aid,jdbcType=VARCHAR}, 
      #{name,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.UserNames">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jul 05 11:40:49 CST 2021.
    -->
    insert into user_names
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="uid != null">
        `uid`,
      </if>
      <if test="aid != null">
        aid,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="createTime != null">
        create_time,
      </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="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.UserNames">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jul 05 11:40:49 CST 2021.
    -->
    update user_names
    <set>
      <if test="uid != null">
        `uid` = #{uid,jdbcType=VARCHAR},
      </if>
      <if test="aid != null">
        aid = #{aid,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.UserNames">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jul 05 11:40:49 CST 2021.
    -->
    update user_names
    set `uid` = #{uid,jdbcType=VARCHAR},
      aid = #{aid,jdbcType=VARCHAR},
      `name` = #{name,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateAddUserName">
  update `user`  set nickname=concat(#{userName},'[',username ,']'),username = #{userName}
	where id= #{uid};
  </update>
  <select id="getUserList" resultType="com.goafanti.customer.bo.UserNamesListBo">
	  select a.id,a.uid,a.aid,a.name ,date_format(a.create_time,'%Y-%m-%d %H:%i:%S') createTimes ,b.name  adminName
	from user_names a left join admin b on a.aid =b.id 
	where a.uid = #{uid}
	order by a.create_time 
  </select>
  <select id="checkUserName" resultType="java.lang.Integer">
  select count(*) from user_names where name= #{userName}
  </select>
  
  <insert id="insertBatch" parameterType="com.goafanti.user.bo.InputUserChannel">
	INSERT INTO `user_names` (uid,name)VALUES
	<foreach item="item" index="index" collection="list"
		separator=",">
		(#{item.uid,jdbcType=VARCHAR},#{item.userName})
    </foreach>
  </insert>
</mapper>