<?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.LiveGoodsWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.live.pojo.LiveGoods">
    <id column="goodsId" property="goodsId" />
    <result column="coverImgUrl" property="coverImgUrl" />
    <result column="name" property="name" />
    <result column="priceType" property="priceType" />
    <result column="price" property="price" />
    <result column="price2" property="price2" />
    <result column="url" property="url" />
    <result column="thirdPartyAppid" property="thirdPartyAppid" />
    <result column="vendorId" property="vendorId" />
    <result column="localGoodsId" property="localGoodsId" />
    <result column="auditStatus" property="auditStatus" />
    <result column="auditId" property="auditId" />
  </resultMap>

  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="goodsId != null">
        goodsId,
      </if>
      <if test="vendorId != null">
        vendorId,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="coverImgUrl != null">
        coverImgUrl,
      </if>
      <if test="priceType != null">
        priceType,
      </if>
      <if test="price != null">
        price,
      </if>
      <if test="price2 != null">
        price2,
      </if>
      <if test="url != null">
        url,
      </if>
      <if test="thirdPartyAppid != null">
        thirdPartyAppid,
      </if>
      <if test="localGoodsId != null">
        localGoodsId,
      </if>
      <if test="auditStatus != null">
        auditStatus,
      </if>
      <if test="auditId != null">
        auditId,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE goodsId = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.coverImgUrl != null">
          AND coverImgUrl = #{example.coverImgUrl}
        </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.priceType != null">
          AND priceType = #{example.priceType}
        </if>
        <if test="example.price != null">
          AND price = #{example.price}
        </if>
        <if test="example.price2 != null">
          AND price2 = #{example.price2}
        </if>
        <if test="example.url != null">
          AND url = #{example.url}
        </if>
        <if test="example.thirdPartyAppid != null">
          AND thirdPartyAppid = #{example.thirdPartyAppid}
        </if>
        <if test="example.localGoodsId != null">
          AND localGoodsId = #{example.localGoodsId}
        </if>
        <if test="example.auditStatus != null">
          AND auditStatus = #{example.auditStatus}
        </if>
        <if test="example.goodsId != null">
          AND goodsId = #{example.goodsId}
        </if>
        <if test="example.auditId != null">
          AND auditId = #{example.auditId}
        </if>

      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY goodsId 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.LiveGoodsExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM live_goods
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM live_goods
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM live_goods
    <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_goods
    <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_goods
    <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_goods
    <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>
  <!--根据条件删除记录，可多条删除-->
  <delete id="deleteByExample">
    DELETE FROM live_goods
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM live_goods
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="roomId" keyProperty="roomId" parameterType="com.slodon.b2b2c.live.pojo.LiveGoods" useGeneratedKeys="true">
    INSERT INTO live_goods(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="goodsId != null">
        #{goodsId},
      </if>
      <if test="vendorId != null">
        #{vendorId},
      </if>
      <if test="name != null">
        #{name},
      </if>
      <if test="coverImgUrl != null">
        #{coverImgUrl},
      </if>
      <if test="priceType != null">
        #{priceType},
      </if>
      <if test="price != null">
        #{price},
      </if>
      <if test="price2 != null">
        #{price2},
      </if>
      <if test="url != null">
        #{url},
      </if>
      <if test="thirdPartyAppid != null">
        #{thirdPartyAppid},
      </if>
      <if test="localGoodsId != null">
        #{localGoodsId},
      </if>
      <if test="auditStatus != null">
        #{auditStatus},
      </if>
      <if test="auditId != null">
        #{auditId},
      </if>

    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE live_goods
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.goodsId != null">
        AND goodsId = #{record.goodsId},
      </if>
      <if test="record.vendorId != null">
        AND vendorId = #{record.vendorId},
      </if>
      <if test="record.name != null">
        AND name = #{record.name},
      </if>
      <if test="record.coverImgUrl != null">
        AND coverImgUrl = #{record.coverImgUrl},
      </if>
      <if test="record.priceType != null">
        AND priceType = #{record.priceType},
      </if>
      <if test="record.price != null">
        AND price = #{record.price},
      </if>
      <if test="record.price2 != null">
        AND price2 = #{record.price2},
      </if>
      <if test="record.url != null">
        AND url = #{record.url},
      </if>
      <if test="record.thirdPartyAppid != null">
        AND thirdPartyAppid = #{record.thirdPartyAppid},
      </if>
      <if test="record.localGoodsId != null">
        AND localGoodsId = #{record.localGoodsId},
      </if>
      <if test="record.auditStatus != null">
        AND auditStatus = #{record.auditStatus},
      </if>
      <if test="record.auditId != null">
        AND auditId = #{record.auditId},
      </if>

    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE live_goods
    <trim prefix="SET" suffixOverrides=",">
      <if test="vendorId != null">
        AND vendorId = #{vendorId},
      </if>
      <if test="name != null">
        AND name = #{name},
      </if>
      <if test="coverImgUrl != null">
        AND coverImgUrl = #{coverImgUrl},
      </if>
      <if test="priceType != null">
        AND priceType = #{priceType},
      </if>
      <if test="price != null">
        AND price = #{price},
      </if>
      <if test="price2 != null">
        AND price2 = #{price2},
      </if>
      <if test="url != null">
        AND url = #{url},
      </if>
      <if test="thirdPartyAppid != null">
        AND thirdPartyAppid = #{thirdPartyAppid},
      </if>
      <if test="localGoodsId != null">
        AND localGoodsId = #{localGoodsId},
      </if>
      <if test="auditStatus != null">
        AND auditStatus = #{auditStatus},
      </if>
      <if test="auditId != null">
        AND auditId = #{auditId},
      </if>
    </trim>
    WHERE goodsId = #{goodsId}
  </update>
</mapper>