<?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.pcloud.book.applet.dao.impl.AppletBusinessCardDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.applet.entity.AppletBusinessCard" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="title" property="title" jdbcType="VARCHAR" />
    <result column="qrcode" property="qrcode" jdbcType="VARCHAR" />
    <result column="head_photo" property="headPhoto" jdbcType="VARCHAR" />
    <result column="wechat_num" property="wechatNum" jdbcType="VARCHAR" />
    <result column="phone" property="phone" jdbcType="VARCHAR" />
    <result column="creator" property="creator" jdbcType="BIGINT"/>
    <result column="updator" property="updator" jdbcType="BIGINT"/>
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
  </resultMap>

  <sql id="Base_Column_List" >
    id, name, title, qrcode, head_photo, wechat_num, phone ,creator,updator,create_time,update_time
  </sql>

  <insert id="insert" parameterType="com.pcloud.book.applet.entity.AppletBusinessCard" useGeneratedKeys="true" keyProperty="id">
    insert into applet_businessCard(
     `name`, title, qrcode, head_photo, wechat_num, phone,create_time,update_time,creator,updator)
    values (
      #{name}, #{title}, #{qrcode}, #{headPhoto}, #{wechatNum}, #{phone},NOW(),NOW(), #{creator, jdbcType=BIGINT},#{updator, jdbcType=BIGINT}
      )
  </insert>

  <delete id="deleteById" parameterType="long">
    delete from applet_businessCard
    where id=#{id}
  </delete>

  <update id="update" parameterType="com.pcloud.book.applet.entity.AppletBusinessCard">
    update applet_businessCard
    <set>
      name = #{name},
      title = #{title},
      qrcode = #{qrcode},
      head_photo = #{headPhoto},
      wechat_num = #{wechatNum},
      phone = #{phone},
      update_time=NOW(),
      updator =#{updator},
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>

  <select id="getList" resultMap="BaseResultMap">
    SELECT
    <include refid="Base_Column_List"/>
    FROM
    applet_businessCard
    WHERE 1=1
    <if test="keyword!=null">
      AND (name like concat('%', #{keyword}, '%') OR wechat_num like concat('%', #{keyword}, '%') OR phone like concat('%', #{keyword}, '%'))
    </if>
    ORDER BY update_time DESC
  </select>

  <select id="getCountByName" resultType="Integer" parameterType="String">
        select
           count(1) groupCount
        from
            applet_businessCard
        where
            name = #{name}

    </select>


  <!--根据id查询-->
  <select id="getById" parameterType="Long" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/> from applet_businessCard where id=#{id}
  </select>

</mapper>
