<?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.skill.dao.impl.PcloudGroupActivityDaoImpl" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.skill.entity.PcloudGroupActivity" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="description" property="desc" jdbcType="VARCHAR" />
    <result column="join_type" property="joinType" jdbcType="INTEGER" />
    <result column="group_pic" property="groupPic" jdbcType="VARCHAR" />
    <result column="pro_label_id" property="proLabelId" jdbcType="INTEGER" />
    <result column="dep_label_id" property="depLabelId" jdbcType="INTEGER" />
    <result column="pur_label_id" property="purLabelId" jdbcType="INTEGER" />
    <result column="book_group_qrcode_id" property="bookGroupQrcodeId" jdbcType="INTEGER" />
    <result column="group_name" property="groupName" jdbcType="VARCHAR" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="create_user" property="createUser" jdbcType="INTEGER" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="update_user" property="updateUser" jdbcType="INTEGER" />
    <result column="is_delete" property="isDelete" jdbcType="BIT" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, name, description, join_type, group_pic, pro_label_id, dep_label_id,
    pur_label_id, book_group_qrcode_id,
    create_time, create_user, update_time, update_user, is_delete
  </sql>

  <update id="deleteById" parameterType="long">
    update pcloud_group_activity set is_delete = 1 where id = #{id}
  </update>

  <select id="queryGroupActivity" resultType="com.pcloud.book.skill.facade.response.QueryGroupActivityResponseVO" parameterType="map" >
    SELECT
      a.id,
      a.`name`,
      a.description as `desc`,
      a.join_type AS joinType,
      a.group_pic AS groupPic,
      a.book_group_qrcode_id AS bookGroupQrcodeId,
      a.pro_label_id AS proLabelId,
      a.dep_label_id AS depLabelId,
      a.pur_label_id AS purLabelId,
      b.group_name AS groupName
    FROM
        pcloud_group_activity a left join book_group_qrcode b on a.book_group_qrcode_id = b.id
    WHERE
        a.is_delete = 0
        <if test="proLabelId != null">
          and a.pro_label_id = #{proLabelId}
        </if>
        <if test="depLabelId != null">
          and a.dep_label_id = #{depLabelId}
        </if>
        <if test="purLabelId != null">
          and a.pur_label_id = #{purLabelId}
        </if>
        <if test="name != null">
          and a.name like CONCAT('%', #{name},'%')
        </if>
  </select>

  <select id="getById" resultMap="BaseResultMap" parameterType="long" >
    select 
      a.id, a.name, a.description, a.join_type, a.group_pic, a.pro_label_id, a.dep_label_id,
      a.pur_label_id, a.book_group_qrcode_id,
      a.create_time, a.create_user, a.update_time, a.update_user, a.is_delete, b.group_name
    from pcloud_group_activity a left join book_group_qrcode b on a.book_group_qrcode_id = b.id
    where a.id = #{id,jdbcType=INTEGER}
  </select>
  <insert id="insert" parameterType="com.pcloud.book.skill.entity.PcloudGroupActivity" >
    insert into pcloud_group_activity (id, name,
      description, join_type, group_pic, pro_label_id, dep_label_id,
      pur_label_id, book_group_qrcode_id, create_time, 
      create_user, update_time, update_user, 
      is_delete)
    values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},
      #{desc,jdbcType=VARCHAR}, #{joinType,jdbcType=INTEGER}, #{groupPic,jdbcType=VARCHAR}, #{proLabelId,jdbcType=INTEGER}, #{depLabelId,jdbcType=INTEGER},
      #{purLabelId,jdbcType=INTEGER}, #{bookGroupQrcodeId,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, 
      #{createUser,jdbcType=INTEGER}, #{updateTime,jdbcType=TIMESTAMP}, #{updateUser,jdbcType=INTEGER}, 
      #{isDelete,jdbcType=BIT})
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.skill.entity.PcloudGroupActivity" >
    update pcloud_group_activity
    <set >
      <if test="name != null" >
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="desc != null" >
        description = #{desc,jdbcType=VARCHAR},
      </if>
      <if test="joinType != null" >
        join_type = #{joinType,jdbcType=INTEGER},
      </if>
      <if test="groupPic != null" >
        group_pic = #{groupPic,jdbcType=VARCHAR},
      </if>
      <if test="proLabelId != null" >
        pro_label_id = #{proLabelId,jdbcType=INTEGER},
      </if>
      <if test="depLabelId != null" >
        dep_label_id = #{depLabelId,jdbcType=INTEGER},
      </if>
      <if test="purLabelId != null" >
        pur_label_id = #{purLabelId,jdbcType=INTEGER},
      </if>
      <if test="bookGroupQrcodeId != null" >
        book_group_qrcode_id = #{bookGroupQrcodeId,jdbcType=INTEGER},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUser != null" >
        create_user = #{createUser,jdbcType=INTEGER},
      </if>
      <if test="updateTime != null" >
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUser != null" >
        update_user = #{updateUser,jdbcType=INTEGER},
      </if>
      <if test="isDelete != null" >
        is_delete = #{isDelete,jdbcType=BIT},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="update" parameterType="com.pcloud.book.skill.entity.PcloudGroupActivity" >
    update pcloud_group_activity
    set name = #{name,jdbcType=VARCHAR},
      description = #{desc,jdbcType=VARCHAR},
      join_type = #{joinType,jdbcType=INTEGER},
      group_pic = #{groupPic,jdbcType=VARCHAR},
      pro_label_id = #{proLabelId,jdbcType=INTEGER},
      dep_label_id = #{depLabelId,jdbcType=INTEGER},
      pur_label_id = #{purLabelId,jdbcType=INTEGER},
      book_group_qrcode_id = #{bookGroupQrcodeId,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_user = #{createUser,jdbcType=INTEGER},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      update_user = #{updateUser,jdbcType=INTEGER},
      is_delete = #{isDelete,jdbcType=BIT}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="mayByIds" parameterType="long" resultMap="BaseResultMap">
    select <include refid="Base_Column_List"/>
    from pcloud_group_activity
    where id in
    <foreach collection="list" index="i" item="item" open="(" separator="," close=")">
      ${item}
    </foreach>
  </select>
</mapper>