<?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.slodon.b2b2c.dao.write.live.LiveBroadWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.live.pojo.LiveBroadcast">
    <id column="roomId" property="roomId" />
    <result column="vendorId" property="vendorId" />
    <result column="name" property="name" />
    <result column="coverImg" property="coverImg" />
    <result column="coverImgPath" property="coverImgPath" />
    <result column="startTime" property="startTime" />
    <result column="endTime" property="endTime" />
    <result column="anchorName" property="anchorName" />
    <result column="anchorWechat" property="anchorWechat" />
    <result column="subAnchorWechat" property="subAnchorWechat" />
    <result column="createrWechat" property="createrWechat" />
    <result column="shareImg" property="shareImg" />
    <result column="shareImgPath" property="shareImgPath" />
    <result column="feedsImg" property="feedsImg" />
    <result column="feedsImgPath" property="feedsImgPath" />
    <result column="isFeedsPublic" property="isFeedsPublic" />
    <result column="type" property="type" />
    <result column="closeLike" property="closeLike" />
    <result column="closeGoods" property="closeGoods" />
    <result column="closeComment" property="closeComment" />
    <result column="closeReplay" property="closeReplay" />
    <result column="closeShare" property="closeShare" />
    <result column="closeKf" property="closeKf" />
  </resultMap>

  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="roomId != null">
        roomId,
      </if>
      <if test="vendorId != null">
        vendorId,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="coverImg != null">
        coverImg,
      </if>
      <if test="coverImgPath != null">
        coverImgPath,
      </if>
      <if test="startTime != null">
        startTime,
      </if>
      <if test="endTime != null">
        endTime,
      </if>
      <if test="anchorName != null">
        anchorName,
      </if>
      <if test="anchorWechat != null">
        anchorWechat,
      </if>
      <if test="subAnchorWechat != null">
        subAnchorWechat,
      </if>
      <if test="createrWechat != null">
        createrWechat,
      </if>
      <if test="shareImg != null">
        shareImg,
      </if>
      <if test="shareImgPath != null">
        shareImgPath,
      </if>
      <if test="feedsImg != null">
        feedsImg,
      </if>
      <if test="feedsImgPath != null">
        feedsImgPath,
      </if>
      <if test="isFeedsPublic != null">
        isFeedsPublic,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="closeLike != null">
        closeLike,
      </if>
      <if test="closeGoods != null">
        closeGoods,
      </if>
      <if test="closeComment != null">
        closeComment,
      </if>
      <if test="closeReplay != null">
        closeReplay,
      </if>
      <if test="closeShare != null">
        closeShare,
      </if>
      <if test="closeKf != null">
        closeKf,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE roomId = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.roomId != null">
          AND roomId = #{example.roomId}
        </if>
        <if test="example.vendorId != null">
          AND vendorId = #{example.vendorId}
        </if>
        <if test="example.name != null">
          AND name like concat('%',#{example.name},'%')
        </if>
        <if test="example.coverImg != null">
          AND coverImg = #{example.coverImg}
        </if>
        <if test="example.coverImgPath != null">
          AND coverImgPath = #{example.coverImgPath}
        </if>
        <if test="example.startTime != null">
          AND startTime = #{example.startTime}
        </if>
        <if test="example.endTime != null">
          AND endTime = #{example.endTime}
        </if>
        <if test="example.anchorName != null">
          AND anchorName = #{example.anchorName}
        </if>
        <if test="example.anchorWechat != null">
          AND anchorWechat = #{example.anchorWechat}
        </if>
        <if test="example.subAnchorWechat != null">
          AND subAnchorWechat = #{example.subAnchorWechat}
        </if>
        <if test="example.createrWechat != null">
          AND createrWechat = #{example.createrWechat}
        </if>
        <if test="example.shareImg != null">
          AND shareImg = #{example.shareImg}
        </if>
        <if test="example.shareImgPath != null">
          AND shareImgPath = #{example.shareImgPath}
        </if>
        <if test="example.feedsImg != null">
          AND feedsImg = #{example.feedsImg}
        </if>
        <if test="example.feedsImgPath != null">
          AND feedsImgPath = #{example.feedsImgPath}
        </if>
        <if test="example.isFeedsPublic != null">
          AND isFeedsPublic = #{example.isFeedsPublic}
        </if>
        <if test="example.type != null">
          AND type = #{example.type}
        </if>
        <if test="example.closeLike != null">
          AND closeLike = #{example.closeLike}
        </if>
        <if test="example.closeGoods != null">
          AND closeGoods = #{example.closeGoods}
        </if>
        <if test="example.closeComment != null">
          AND closeComment = #{example.closeComment}
        </if>
        <if test="example.closeReplay != null">
          AND closeReplay = #{example.closeReplay}
        </if>
        <if test="example.closeShare != null">
          AND closeShare = #{example.closeShare}
        </if>
        <if test="example.closeKf != null">
          AND closeKf = #{example.closeKf}
        </if>

      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY roomId DESC
  </sql>
  <sql id="orderByOther">
    order by #{example.orderBy}
  </sql>
  <!--分组条件-->
  <sql id="groupBy">
    group by #{example.groupBy}
  </sql>
  <!--分页条件-->
  <sql id="limit">
    <if test="size != null and size &gt; 0">
      limit #{startRow},#{size}
    </if>
  </sql>
  <!--查询符合条件的记录数-->
  <select id="countByExample" parameterType="com.slodon.b2b2c.live.example.LiveBroadcastExample" resultType="java.lang.Integer">
    SELECT
    COUNT(*)
    FROM live_broadcast
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
    *
    FROM live_broadcast
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
    *
    FROM live_broadcast
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(所有字段)-->
  <select id="listPageByExample" resultMap="resultMap">
    SELECT
    *
    FROM live_broadcast
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--查询符合条件的记录(指定字段)-->
  <select id="listFieldsByExample" resultMap="resultMap">
    SELECT
    #{fields}
    FROM live_broadcast
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(指定字段)-->
  <select id="listFieldsPageByExample" resultMap="resultMap">
    SELECT
    #{fields}
    FROM live_broadcast
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
    <select id="getLivesNum" resultType="java.lang.Integer">
      select count(1) from live_broadcast where roomId >= #{roomId}
    </select>
  <select id="getLiveRoomId" resultType="java.lang.Integer">
    select roomId from live_broadcast where liveStatus &lt; 103 limit 1
  </select>
  <!--根据条件删除记录，可多条删除-->
  <delete id="deleteByExample">
    DELETE FROM live_broadcast
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM live_broadcast
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="roomId" keyProperty="roomId" parameterType="com.slodon.b2b2c.live.pojo.LiveBroadcast" useGeneratedKeys="true">
    INSERT INTO live_broadcast(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="roomId != null">
        #{roomId},
      </if>
      <if test="vendorId != null">
        #{vendorId},
      </if>
      <if test="name != null">
        #{name},
      </if>
      <if test="coverImg != null">
        #{coverImg},
      </if>
      <if test="coverImgPath != null">
        #{coverImgPath},
      </if>
      <if test="startTime != null">
        #{startTime},
      </if>
      <if test="endTime != null">
        #{endTime},
      </if>
      <if test="anchorName != null">
        #{anchorName},
      </if>
      <if test="anchorWechat != null">
        #{anchorWechat},
      </if>
      <if test="subAnchorWechat != null">
        #{subAnchorWechat},
      </if>
      <if test="createrWechat != null">
        #{createrWechat},
      </if>
      <if test="shareImg != null">
        #{shareImg},
      </if>
      <if test="shareImgPath != null">
        #{shareImgPath},
      </if>
      <if test="feedsImg != null">
        #{feedsImg},
      </if>
      <if test="feedsImgPath != null">
        #{feedsImgPath},
      </if>
      <if test="isFeedsPublic != null">
        #{isFeedsPublic},
      </if>
      <if test="type != null">
        #{type},
      </if>
      <if test="closeLike != null">
        #{closeLike},
      </if>
      <if test="closeGoods != null">
        #{closeGoods},
      </if>
      <if test="closeComment != null">
        #{closeComment},
      </if>
      <if test="closeReplay != null">
        #{closeReplay},
      </if>
      <if test="closeShare != null">
        #{closeShare},
      </if>
      <if test="closeKf != null">
        #{closeKf},
      </if>

    </trim>
    )
  </insert>
  <insert id="addLiveGoodsRelation">
    insert into live_goods_relation (roomId,goodsId) values
    <foreach collection="asList" item="item" index="index" separator=",">
      (#{roomId},#{item})
    </foreach>
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE live_broadcast
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.roomId != null">
        AND roomId = #{record.roomId},
      </if>
      <if test="record.vendorId != null">
        AND vendorId = #{record.vendorId},
      </if>
      <if test="record.name != null">
        AND name = #{record.name},
      </if>
      <if test="record.coverImg != null">
        AND coverImg = #{record.coverImg},
      </if>
      <if test="record.coverImgPath != null">
        AND coverImgPath = #{record.coverImgPath},
      </if>
      <if test="record.startTime != null">
        AND startTime = #{record.startTime},
      </if>
      <if test="record.endTime != null">
        AND endTime = #{record.endTime},
      </if>
      <if test="record.anchorName != null">
        AND anchorName = #{record.anchorName},
      </if>
      <if test="record.anchorWechat != null">
        AND anchorWechat = #{record.anchorWechat},
      </if>
      <if test="record.subAnchorWechat != null">
        AND subAnchorWechat = #{record.subAnchorWechat},
      </if>
      <if test="record.createrWechat != null">
        AND createrWechat = #{record.createrWechat},
      </if>
      <if test="record.shareImg != null">
        AND shareImg = #{record.shareImg},
      </if>
      <if test="record.shareImgPath != null">
        AND shareImgPath = #{record.shareImgPath},
      </if>
      <if test="record.feedsImg != null">
        AND feedsImg = #{record.feedsImg},
      </if>
      <if test="record.feedsImgPath != null">
        AND feedsImgPath = #{record.feedsImgPath},
      </if>
      <if test="record.isFeedsPublic != null">
        AND isFeedsPublic = #{record.isFeedsPublic},
      </if>
      <if test="record.type != null">
        AND type = #{record.type},
      </if>
      <if test="record.closeLike != null">
        AND closeLike = #{record.closeLike},
      </if>
      <if test="record.closeGoods != null">
        AND closeGoods = #{record.closeGoods},
      </if>
      <if test="record.closeComment != null">
        AND closeComment = #{record.closeComment},
      </if>
      <if test="record.closeReplay != null">
        AND closeReplay = #{record.closeReplay},
      </if>
      <if test="record.closeShare != null">
        AND closeShare = #{record.closeShare},
      </if>
      <if test="record.closeKf != null">
        AND closeKf = #{record.closeKf},
      </if>

    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE live_broadcast
    <trim prefix="SET" suffixOverrides=",">
      <if test="name != null">
        name = #{name},
      </if>
      <if test="coverImg != null">
        coverImg = #{coverImg},
      </if>
      <if test="coverImgPath != null">
        coverImgPath = #{coverImgPath},
      </if>
      <if test="startTime != null">
        startTime = #{startTime},
      </if>
      <if test="endTime != null">
        endTime = #{endTime},
      </if>
      <if test="anchorName != null">
        anchorName = #{anchorName},
      </if>
      <if test="anchorWechat != null">
        anchorWechat = #{anchorWechat},
      </if>
      <if test="subAnchorWechat != null">
        subAnchorWechat = #{subAnchorWechat},
      </if>
      <if test="createrWechat != null">
        createrWechat = #{createrWechat},
      </if>
      <if test="shareImg != null">
        shareImg = #{shareImg},
      </if>
      <if test="shareImgPath != null">
        shareImgPath = #{shareImgPath},
      </if>
      <if test="feedsImg != null">
        feedsImg = #{feedsImg},
      </if>
      <if test="feedsImgPath != null">
        feedsImgPath = #{feedsImgPath},
      </if>
      <if test="isFeedsPublic != null">
        isFeedsPublic = #{isFeedsPublic},
      </if>
      <if test="type != null">
        type = #{type},
      </if>
      <if test="closeLike != null">
        closeLike = #{closeLike},
      </if>
      <if test="closeGoods != null">
        closeGoods = #{closeGoods},
      </if>
      <if test="closeComment != null">
        closeComment = #{closeComment},
      </if>
      <if test="closeReplay != null">
        closeReplay = #{closeReplay},
      </if>
      <if test="closeShare != null">
        closeShare = #{closeShare},
      </if>
      <if test="closeKf != null">
        closeKf = #{closeKf},
      </if>
    </trim>
    WHERE roomId = #{roomId}
  </update>

  <update id="updateLivesType" parameterType="list">
    <foreach collection="livesVOS" item="item" index="index">
      update live_broadcast set
      liveStatus=#{item.liveStatus}
      where roomId = #{item.roomId};
    </foreach>
  </update>
</mapper>