<?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.pcloudkeyword.dao.impl.PcloudRobotClassifyDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.pcloudkeyword.entity.PcloudRobotClassify" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="classify_name" property="classifyName" jdbcType="VARCHAR" />
    <result column="is_delete" property="isDelete" jdbcType="INTEGER" />
    <result column="link_url" property="linkUrl" jdbcType="VARCHAR"/>
    <result column="qrcode_url" property="qrcodeUrl" jdbcType="VARCHAR" />
    <result column="keyword_classify_id" property="keywordClassifyId" jdbcType="VARCHAR" />
      <result column="welcome_duration" property="welcomeDuration" jdbcType="INTEGER" />
      <result column="is_open_push_h5url" property="isOpenPushH5url" jdbcType="INTEGER" />
      <result column="seq_num" property="seqNum" jdbcType="INTEGER"/>
      <result column="mimi_app_qr" property="miniAppQr" jdbcType="VARCHAR"/>
  </resultMap>

    <resultMap id="pageResultMap" type="com.pcloud.book.pcloudkeyword.facade.response.PcloudRobotClassifyResponseVO" >
        <id column="id" property="id" jdbcType="INTEGER" />
        <result column="classify_name" property="classifyName" jdbcType="VARCHAR" />
        <result column="qrcode_url" property="qrcodeUrl" jdbcType="VARCHAR" />
        <result column="seq_num" property="seqNum" jdbcType="INTEGER"/>
        <association property="robotCount" column="id" fetchType="eager"
                     select="com.pcloud.book.pcloudkeyword.dao.impl.PcloudRobotDaoImpl.getRobotCountByClassifyId" />
    </resultMap>
  <sql id="Base_Column_List" >
    id, classify_name, link_url, qrcode_url,keyword_classify_id, is_delete, welcome_duration,is_open_push_h5url, seq_num, mimi_app_qr
  </sql>

  <insert id="insert" parameterType="com.pcloud.book.pcloudkeyword.entity.PcloudRobotClassify" useGeneratedKeys="true" keyProperty="id">
    insert into pcloud_robot_classify (
        classify_name,
        is_delete
      )
    values (
      #{classifyName,jdbcType=VARCHAR},
      #{isDelete,jdbcType=INTEGER}
      )
  </insert>

    <update id="update" parameterType="com.pcloud.book.pcloudkeyword.entity.PcloudRobotClassify">
        update pcloud_robot_classify
        <set>
            <if test="classifyName != null">
                classify_name = #{classifyName},
            </if>
            <if test="linkUrl != null">
                link_url = #{linkUrl},
            </if>
            <if test="qrcodeUrl != null">
                qrcode_url = #{qrcodeUrl},
            </if>
            <if test="isDelete != null">
                is_delete = #{isDelete},
            </if>
            <if test="welcomeDuration != null">
                welcome_duration = #{welcomeDuration},
            </if>
            <if test="seqNum != null">
                seq_num = #{seqNum},
            </if>
        </set>
        where id=#{id}
    </update>

    <select id="listAllRobotClassify" resultType="com.pcloud.book.pcloudkeyword.facade.response.PcloudRobotClassifyResponseVO">
        select
        id, classify_name as classifyName
        from pcloud_robot_classify where is_delete = 0
        order by seq_num
    </select>

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

    <select id="listClassifyByPage" resultMap="pageResultMap">
        select
        id, classify_name, qrcode_url, seq_num, mimi_app_qr miniAppQr
        from pcloud_robot_classify
        where is_delete = 0
        order by seq_num
    </select>

    <update id="updateRobotClassifyKeywordClassify" parameterType="map">
        update pcloud_robot_classify
        set keyword_classify_id=#{keywordClassifyId}
        where id=#{id}
    </update>

    <update id="updateWelcomeDuration" parameterType="map">
        update pcloud_robot_classify
        set welcome_duration = #{welcomeDuration},
        is_open_push_h5url=#{isOpenPushH5url}
        where id=#{id}
    </update>

    <update id="updateSeqNum4RobotClassify" parameterType="com.pcloud.book.pcloudkeyword.vo.ClassifySeqNumUpdateVO">
        update pcloud_robot_classify
        set seq_num = #{seqNum} where id = #{id}
    </update>

    <update id="updateMiniAppQr" parameterType="map">
        update pcloud_robot_classify set mimi_app_qr = #{url} where id = id
    </update>
</mapper>