<?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.WSupportingMapper">
	<resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WSupporting">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jan 26 
			11:10:54 CST 2015. -->
		<id column="GoodsID" property="goodsid" jdbcType="VARCHAR" />
		<id column="SupportingID" property="supportingid" jdbcType="VARCHAR" />
		<result column="ListIndex" property="listindex" jdbcType="TINYINT" />
	</resultMap>
	<sql id="Example_Where_Clause">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jan 26 
			11:10:54 CST 2015. -->
		<where>
			<foreach collection="oredCriteria" item="criteria" separator="or">
				<if test="criteria.valid">
					<trim prefix="(" suffix=")" prefixOverrides="and">
						<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 collection="criterion.value" item="listItem"
										open="(" close=")" 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 Mon Jan 26 
			11:10:54 CST 2015. -->
		GoodsID, SupportingID, ListIndex
	</sql>
	<select id="selectByExample" resultMap="BaseResultMap"
		parameterType="com.fuxi.ws.data.entity.WSupportingExample">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jan 26 
			11:10:54 CST 2015. -->
		select
		<if test="distinct">
			distinct
		</if>
		'false' as QUERYID,
		<include refid="Base_Column_List" />
		from W_Supporting
		<if test="_parameter != null">
			<include refid="Example_Where_Clause" />
		</if>
		<if test="orderByClause != null">
			order by ${orderByClause}
		</if>
	</select>
	<select id="selectByPrimaryKey" resultMap="BaseResultMap"
		parameterType="com.fuxi.ws.data.entity.WSupportingKey">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jan 26 
			11:10:54 CST 2015. -->
		select
		<include refid="Base_Column_List" />
		from W_Supporting
		where GoodsID = #{goodsid,jdbcType=VARCHAR}
		and
		SupportingID = #{supportingid,jdbcType=VARCHAR}
	</select>
	<delete id="deleteByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WSupportingKey">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jan 26 
			11:10:54 CST 2015. -->
		delete from W_Supporting
		where GoodsID = #{goodsid,jdbcType=VARCHAR}
		and SupportingID = #{supportingid,jdbcType=VARCHAR}
	</delete>
	<insert id="insert" parameterType="com.fuxi.ws.data.entity.WSupporting">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jan 26 
			11:10:54 CST 2015. -->
		insert into W_Supporting (GoodsID, SupportingID, ListIndex
		)
		values
		(#{goodsid,jdbcType=VARCHAR}, #{supportingid,jdbcType=VARCHAR},
		#{listindex,jdbcType=TINYINT}
		)
	</insert>
	<insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WSupporting">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jan 26 
			11:10:54 CST 2015. -->
		insert into W_Supporting
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="goodsid != null">
				GoodsID,
			</if>
			<if test="supportingid != null">
				SupportingID,
			</if>
			<if test="listindex != null">
				ListIndex,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="goodsid != null">
				#{goodsid,jdbcType=VARCHAR},
			</if>
			<if test="supportingid != null">
				#{supportingid,jdbcType=VARCHAR},
			</if>
			<if test="listindex != null">
				#{listindex,jdbcType=TINYINT},
			</if>
		</trim>
	</insert>
	<select id="countByExample" parameterType="com.fuxi.ws.data.entity.WSupportingExample"
		resultType="java.lang.Integer">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jan 26 
			11:10:54 CST 2015. -->
		select count(*) from W_Supporting
		<if test="_parameter != null">
			<include refid="Example_Where_Clause" />
		</if>
	</select>
	<update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WSupporting">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jan 26 
			11:10:54 CST 2015. -->
		update W_Supporting
		<set>
			<if test="listindex != null">
				ListIndex = #{listindex,jdbcType=TINYINT},
			</if>
		</set>
		where GoodsID = #{goodsid,jdbcType=VARCHAR}
		and SupportingID =
		#{supportingid,jdbcType=VARCHAR}
	</update>
	<update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WSupporting">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jan 26 
			11:10:54 CST 2015. -->
		update W_Supporting
		set ListIndex = #{listindex,jdbcType=TINYINT}
		where
		GoodsID = #{goodsid,jdbcType=VARCHAR}
		and SupportingID =
		#{supportingid,jdbcType=VARCHAR}
	</update>

	<!-- 相关搭配列表 -->
	<select id="supportList" resultType="java.util.LinkedHashMap">
		select
		a.SupportingID,b.GoodName,b.Price,b.ImgPath from W_Supporting
		a
		join W_Goods b on
		a.SupportingID=b.GoodsID
		where b.AtList='1' and
		a.GoodsID=#{goodsid}
		order by
		a.ListIndex
	</select>
	
	<select id="selectSupportByGoodId" resultType="java.util.LinkedHashMap">
		select a.goodsid,a.supportingid,a.listindex,c.code,c.imgpath,c.price,
		case when s.SupplierName='' or s.SupplierName is null then c.goodname else c.goodname + '（' + s.SupplierName + '）' end as goodname
		from W_Supporting a inner join
		W_Goods c on c.GoodsID=a.supportingid left join
		W_Supplier s on s.SupplierID=c.SupplierID
		where a.goodsID=#{goodsid,jdbcType=VARCHAR}
		order by
		a.ListIndex
	</select>
</mapper>