<?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.push.dao.impl.PersonalAppletsDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.push.entity.PersonalApplets" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="applets_id" property="appletsId" jdbcType="VARCHAR" />
    <result column="slogan" property="slogan" jdbcType="VARCHAR" />
    <result column="slogan_img_url" property="sloganImgUrl" jdbcType="VARCHAR" />
    <result column="applets_url" property="appletsUrl" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="remark" property="remark" jdbcType="VARCHAR" />
  </resultMap>

  <sql id="Base_Column_List" >
    id, applets_id, slogan, slogan_img_url, applets_url, create_time, update_time, remark
  </sql>

  <insert id="insert" parameterType="com.pcloud.book.push.entity.PersonalApplets" useGeneratedKeys="true" keyProperty="id">
    insert into personal_applets ( applets_id,
    slogan, slogan_img_url, applets_url,
    create_time, update_time, remark
    )
    values (#{appletsId,jdbcType=VARCHAR}, #{slogan,jdbcType=VARCHAR},
    #{sloganImgUrl,jdbcType=VARCHAR}, #{appletsUrl,jdbcType=VARCHAR},
    now(),  now(), #{remark}
    )
  </insert>

  <select id="getById" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/>
    from personal_applets where id=#{id}
  </select>

  <select id="getAllApplets" parameterType="map" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/>
    from personal_applets
    where 1=1
    <if test="appletsId!=null">
       and applets_id=#{appletsId}
    </if>
    <if test="content!=null">
      and (applets_id LIKE concat('%',#{content},'%') OR remark LIKE concat('%',#{content},'%'))
    </if>
    order by create_time desc
  </select>

  <select id="mapByIds" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/>
    from personal_applets
    where id IN
    <foreach collection="list" item="item" separator="," open="(" close=")">
      ${item}
    </foreach>
  </select>

  <update id="update" parameterType="com.pcloud.book.push.entity.PersonalApplets">
    update personal_applets
    <set>
      <if test="appletsId != null">
        applets_id = #{appletsId,jdbcType=VARCHAR},
      </if>
      <if test="slogan != null">
        slogan = #{slogan,jdbcType=VARCHAR},
      </if>
      <if test="sloganImgUrl != null">
        slogan_img_url = #{sloganImgUrl,jdbcType=VARCHAR},
      </if>
      <if test="appletsUrl != null">
        applets_url = #{appletsUrl,jdbcType=VARCHAR},
      </if>
      <if test="remark != null">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
      update_time = NOW(),
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>

  <delete id="deleteById">
    delete from personal_applets where id=#{id}
  </delete>






</mapper>
