<?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.fuxi.ws.data.dao.WCartMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WCart">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Sep 14 15:22:01 CST 2017.
    -->
    <id column="Vipid" jdbcType="VARCHAR" property="vipid" />
    <id column="GoodsID" jdbcType="VARCHAR" property="goodsid" />
    <id column="ColorID" jdbcType="VARCHAR" property="colorid" />
    <id column="SizeID" jdbcType="VARCHAR" property="sizeid" />
    <id column="BuyKind" jdbcType="TINYINT" property="buykind" />
    <result column="Quantity" jdbcType="INTEGER" property="quantity" />
    <result column="Dec" jdbcType="NVARCHAR" property="dec" />
    <result column="DepartmentID" jdbcType="VARCHAR" property="departmentid" />
    <result column="BarCode" jdbcType="VARCHAR" property="barcode" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Sep 14 15:22:01 CST 2017.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Sep 14 15:22:01 CST 2017.
    -->
    Vipid, GoodsID, ColorID, SizeID, BuyKind, Quantity, Dec, DepartmentID, BarCode
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WCartExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Sep 14 15:22:01 CST 2017.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_Cart
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WCartKey" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Sep 14 15:22:01 CST 2017.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_Cart
    where Vipid = #{vipid,jdbcType=VARCHAR}
      and GoodsID = #{goodsid,jdbcType=VARCHAR}
      and ColorID = #{colorid,jdbcType=VARCHAR}
      and SizeID = #{sizeid,jdbcType=VARCHAR}
      and BuyKind = #{buykind,jdbcType=TINYINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WCartKey">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Sep 14 15:22:01 CST 2017.
    -->
    delete from W_Cart
    where Vipid = #{vipid,jdbcType=VARCHAR}
      and GoodsID = #{goodsid,jdbcType=VARCHAR}
      and ColorID = #{colorid,jdbcType=VARCHAR}
      and SizeID = #{sizeid,jdbcType=VARCHAR}
      and BuyKind = #{buykind,jdbcType=TINYINT}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WCart">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Sep 14 15:22:01 CST 2017.
    -->
    insert into W_Cart (Vipid, GoodsID, ColorID, 
      SizeID, BuyKind, Quantity, 
      Dec, DepartmentID, BarCode
      )
    values (#{vipid,jdbcType=VARCHAR}, #{goodsid,jdbcType=VARCHAR}, #{colorid,jdbcType=VARCHAR}, 
      #{sizeid,jdbcType=VARCHAR}, #{buykind,jdbcType=TINYINT}, #{quantity,jdbcType=INTEGER}, 
      #{dec,jdbcType=NVARCHAR}, #{departmentid,jdbcType=VARCHAR}, #{barcode,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WCart">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Sep 14 15:22:01 CST 2017.
    -->
    insert into W_Cart
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="vipid != null">
        Vipid,
      </if>
      <if test="goodsid != null">
        GoodsID,
      </if>
      <if test="colorid != null">
        ColorID,
      </if>
      <if test="sizeid != null">
        SizeID,
      </if>
      <if test="buykind != null">
        BuyKind,
      </if>
      <if test="quantity != null">
        Quantity,
      </if>
      <if test="dec != null">
        Dec,
      </if>
      <if test="departmentid != null">
        DepartmentID,
      </if>
      <if test="barcode != null">
        BarCode,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="vipid != null">
        #{vipid,jdbcType=VARCHAR},
      </if>
      <if test="goodsid != null">
        #{goodsid,jdbcType=VARCHAR},
      </if>
      <if test="colorid != null">
        #{colorid,jdbcType=VARCHAR},
      </if>
      <if test="sizeid != null">
        #{sizeid,jdbcType=VARCHAR},
      </if>
      <if test="buykind != null">
        #{buykind,jdbcType=TINYINT},
      </if>
      <if test="quantity != null">
        #{quantity,jdbcType=INTEGER},
      </if>
      <if test="dec != null">
        #{dec,jdbcType=NVARCHAR},
      </if>
      <if test="departmentid != null">
        #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="barcode != null">
        #{barcode,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WCartExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Sep 14 15:22:01 CST 2017.
    -->
    select count(*) from W_Cart
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WCart">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Sep 14 15:22:01 CST 2017.
    -->
    update W_Cart
    <set>
      <if test="quantity != null">
        Quantity = #{quantity,jdbcType=INTEGER},
      </if>
      <if test="dec != null">
        Dec = #{dec,jdbcType=NVARCHAR},
      </if>
      <if test="departmentid != null">
        DepartmentID = #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="barcode != null">
        BarCode = #{barcode,jdbcType=VARCHAR},
      </if>
    </set>
    where Vipid = #{vipid,jdbcType=VARCHAR}
      and GoodsID = #{goodsid,jdbcType=VARCHAR}
      and ColorID = #{colorid,jdbcType=VARCHAR}
      and SizeID = #{sizeid,jdbcType=VARCHAR}
      and BuyKind = #{buykind,jdbcType=TINYINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WCart">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Sep 14 15:22:01 CST 2017.
    -->
    update W_Cart
    set Quantity = #{quantity,jdbcType=INTEGER},
      Dec = #{dec,jdbcType=NVARCHAR},
      DepartmentID = #{departmentid,jdbcType=VARCHAR},
      BarCode = #{barcode,jdbcType=VARCHAR}
    where Vipid = #{vipid,jdbcType=VARCHAR}
      and GoodsID = #{goodsid,jdbcType=VARCHAR}
      and ColorID = #{colorid,jdbcType=VARCHAR}
      and SizeID = #{sizeid,jdbcType=VARCHAR}
      and BuyKind = #{buykind,jdbcType=TINYINT}
  </update>

	<!-- <select id="getCartByVip" resultType="java.util.LinkedHashMap"> select 
		a.Vipid,a.Quantity,a.BuyKind,b.GoodsID,b.GoodName,b.Price,b.ImgPath,b.AtList,b.Postage,b.PayByPoint,b.PromotionsID,c.ColorID,c.Color,d.SizeID,d.Size,b.ViewColor,b.ViewSize,e.Price 
		Price2,f.PromotPrice, b.AtList,e.Quantity InvQty,b.NoDiscount from W_Cart 
		a with(nolock) join W_Goods b with(nolock) on a.GoodsID=b.GoodsID join Color 
		c with(nolock) on a.ColorID=c.ColorID join Size d with(nolock) on a.SizeID=d.SizeID 
		left join w_store e with(nolock) on a.GoodsID=e.GoodsID and a.ColorID=e.ColorID 
		and a.SizeID=e.SizeID left join W_PromotionsStore f with(nolock) on a.GoodsID=f.GoodsID 
		and a.ColorID=f.ColorID and a.SizeID=f.SizeID where a.Vipid=#{ vipid } </select> -->

	<select id="getseckillCartByVip" resultType="java.util.LinkedHashMap">
		select
		a.Vipid,a.Quantity,a.BuyKind,b.GoodsID,b.GoodName,b.Price,b.ImgPath,b.AtList,b.Postage,b.PayByPoint,c.ColorID,c.Color,d.SizeID,d.Size,b.ViewColor,b.ViewSize,e.Price
		Price2,f.PromotPrice
		from W_Cart a with(nolock)
		join W_Goods b
		with(nolock) on a.GoodsID=b.GoodsID
		join Color c
		with(nolock)
		on
		a.ColorID=c.ColorID
		join Size d with(nolock) on a.SizeID=d.SizeID
		join
		w_store e with(nolock) on
		a.GoodsID=e.GoodsID and a.ColorID=e.ColorID
		and
		a.SizeID=e.SizeID
		left join W_PromotionsStore f with(nolock) on
		a.GoodsID=f.GoodsID
		and
		a.ColorID=f.ColorID and a.SizeID=f.SizeID
		where
		a.Vipid=#{
		vipid }
		and a.BuyKind=2
	</select>

	<!-- 删除全部商品 -->
	<delete id="allDelete">
		delete from W_Cart
		where Vipid = #{vipid}
	</delete>

	<select id="cartInv" resultType="java.util.LinkedHashMap">
		select a.GoodsID,b.ColorID,b.SizeID,b.Quantity,
		b.TotalQty,b.TotalSell,a.Price,c.Color,d.Size,b.Price
		Price2,ISNULL(a.Integral,0)Integral,ISNULL(a.PackageNum,1) PackageNum
		from
		W_Goods a with(nolock)
		left join
		W_Store b with(nolock) on
		a.GoodsID=b.GoodsID
		join
		Color c
		with(nolock) on
		c.ColorID=b.ColorID
		join
		Size d with(nolock) on
		d.SizeID=b.SizeID
		<if test="list.size() &gt;0">
			where
			a.GoodsID in
			<foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
				#{item}
			</foreach>
		</if>
	</select>

	<select id="cartInv2" resultType="java.util.LinkedHashMap">
		select a.GoodsID,b.ColorID,b.SizeID,
		b.PromotQty
		Quantity,a.Price,c.Color,d.Size,b.PromotPrice Price2,ISNULL(a.PackageNum,1) PackageNum
		from W_Goods a
		with(nolock)
		left join W_PromotionsStore b with(nolock) on
		a.GoodsID=b.GoodsID
		join
		Color c with(nolock) on
		c.ColorID=b.ColorID
		join
		Size d with(nolock) on
		d.SizeID=b.SizeID
		<if test="list.size() &gt;0">
			where
			a.GoodsID in
			<foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
				#{item}
			</foreach>
		</if>
	</select>

	<update id="updateCart">
		update W_Cart set ColorID=#{ colorid },SizeID=#{
		sizeid },Quantity=#{ quantity },BarCode=#{ barcode }
		where Vipid=#{ vipid } and GoodsID=#{
		goodsid } and ColorID=#{ oldcolorid } and SizeID=#{ oldsizeid } and
		BuyKind=#{ buykind }
	</update>
</mapper>