<?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.WShowsetMapper">
	<resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WShowset">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jun 13 
			11:02:19 CST 2016. -->
		<id column="ShowSetID" jdbcType="SMALLINT" property="showsetid" />
		<result column="ShowSetName" jdbcType="NVARCHAR" property="showsetname" />
		<result column="DepartmentID" jdbcType="VARCHAR" property="departmentid" />
		<result column="ShowSetDec" jdbcType="NVARCHAR" property="showsetdec" />
		<result column="FormID" jdbcType="INTEGER" property="formid" />
		<result column="ShowArea" jdbcType="TINYINT" property="showarea" />
		<result column="ShowIndex" jdbcType="TINYINT" property="showindex" />
		<result column="ShowGoodsName" jdbcType="TINYINT" property="showgoodsname" />
		<result column="ShowTag" jdbcType="TINYINT" property="showtag" />
		<result column="ShowPirce" jdbcType="TINYINT" property="showpirce" />
		<result column="ShowLabel" jdbcType="TINYINT" property="showlabel" />
		<result column="LabelPlace" jdbcType="TINYINT" property="labelplace" />
		<result column="LabelUrl" jdbcType="NVARCHAR" property="labelurl" />
		<result column="CartStyle" jdbcType="NVARCHAR" property="cartstyle" />
		<result column="ShowKind" jdbcType="TINYINT" property="showkind" />
		<result column="OrderBy" jdbcType="TINYINT" property="orderby" />
		<result column="NumOfRow" jdbcType="TINYINT" property="numofrow" />
		<result column="MouldID" jdbcType="SMALLINT" property="mouldid" />
		<result column="Creater" jdbcType="VARCHAR" property="creater" />
		<result column="Created" jdbcType="TIMESTAMP" property="created" />
		<result column="Modifier" jdbcType="VARCHAR" property="modifier" />
		<result column="Modified" jdbcType="TIMESTAMP" property="modified" />
	</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 Jun 13 
			11:02:19 CST 2016. -->
		<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 Mon Jun 13 
			11:02:19 CST 2016. -->
		ShowSetID, ShowSetName, DepartmentID, ShowSetDec, FormID, ShowArea,
		ShowIndex, ShowGoodsName,
		ShowTag, ShowPirce, ShowLabel, LabelPlace,
		LabelUrl, CartStyle, ShowKind,
		OrderBy,
		NumOfRow, MouldID, Creater,
		Created, Modifier, Modified
	</sql>
	<select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WShowsetExample"
		resultMap="BaseResultMap">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jun 13 
			11:02:19 CST 2016. -->
		select
		<if test="distinct">
			distinct
		</if>
		'false' as QUERYID,
		<include refid="Base_Column_List" />
		from W_ShowSet
		<if test="_parameter != null">
			<include refid="Example_Where_Clause" />
		</if>
		<if test="orderByClause != null">
			order by ${orderByClause}
		</if>
	</select>
	<select id="selectByPrimaryKey" parameterType="java.lang.Short"
		resultMap="BaseResultMap">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jun 13 
			11:02:19 CST 2016. -->
		select
		<include refid="Base_Column_List" />
		from W_ShowSet
		where ShowSetID = #{showsetid,jdbcType=SMALLINT}
	</select>
	<delete id="deleteByPrimaryKey" parameterType="java.lang.Short">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jun 13 
			11:02:19 CST 2016. -->
		delete from W_ShowSet
		where ShowSetID = #{showsetid,jdbcType=SMALLINT}
	</delete>
	<insert id="insert" parameterType="com.fuxi.ws.data.entity.WShowset">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jun 13 
			11:02:19 CST 2016. -->
		insert into W_ShowSet (ShowSetID, ShowSetName, DepartmentID,
		ShowSetDec, FormID, ShowArea,
		ShowIndex, ShowGoodsName, ShowTag,
		ShowPirce, ShowLabel, LabelPlace,
		LabelUrl, CartStyle, ShowKind,
		OrderBy, NumOfRow, MouldID,
		Creater, Created, Modifier,
		Modified)
		values
		(#{showsetid,jdbcType=SMALLINT}, #{showsetname,jdbcType=NVARCHAR},
		#{departmentid,jdbcType=VARCHAR},
		#{showsetdec,jdbcType=NVARCHAR},
		#{formid,jdbcType=INTEGER}, #{showarea,jdbcType=TINYINT},
		#{showindex,jdbcType=TINYINT}, #{showgoodsname,jdbcType=TINYINT},
		#{showtag,jdbcType=TINYINT},
		#{showpirce,jdbcType=TINYINT},
		#{showlabel,jdbcType=TINYINT}, #{labelplace,jdbcType=TINYINT},
		#{labelurl,jdbcType=NVARCHAR}, #{cartstyle,jdbcType=NVARCHAR},
		#{showkind,jdbcType=TINYINT},
		#{orderby,jdbcType=TINYINT},
		#{numofrow,jdbcType=TINYINT}, #{mouldid,jdbcType=SMALLINT},
		#{creater,jdbcType=VARCHAR}, #{created,jdbcType=TIMESTAMP},
		#{modifier,jdbcType=VARCHAR},
		#{modified,jdbcType=TIMESTAMP})
	</insert>
	<insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WShowset">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jun 13 
			11:02:19 CST 2016. -->
		insert into W_ShowSet
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="showsetid != null">
				ShowSetID,
			</if>
			<if test="showsetname != null">
				ShowSetName,
			</if>
			<if test="departmentid != null">
				DepartmentID,
			</if>
			<if test="showsetdec != null">
				ShowSetDec,
			</if>
			<if test="formid != null">
				FormID,
			</if>
			<if test="showarea != null">
				ShowArea,
			</if>
			<if test="showindex != null">
				ShowIndex,
			</if>
			<if test="showgoodsname != null">
				ShowGoodsName,
			</if>
			<if test="showtag != null">
				ShowTag,
			</if>
			<if test="showpirce != null">
				ShowPirce,
			</if>
			<if test="showlabel != null">
				ShowLabel,
			</if>
			<if test="labelplace != null">
				LabelPlace,
			</if>
			<if test="labelurl != null">
				LabelUrl,
			</if>
			<if test="cartstyle != null">
				CartStyle,
			</if>
			<if test="showkind != null">
				ShowKind,
			</if>
			<if test="orderby != null">
				OrderBy,
			</if>
			<if test="numofrow != null">
				NumOfRow,
			</if>
			<if test="mouldid != null">
				MouldID,
			</if>
			<if test="creater != null">
				Creater,
			</if>
			<if test="created != null">
				Created,
			</if>
			<if test="modifier != null">
				Modifier,
			</if>
			<if test="modified != null">
				Modified,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="showsetid != null">
				#{showsetid,jdbcType=SMALLINT},
			</if>
			<if test="showsetname != null">
				#{showsetname,jdbcType=NVARCHAR},
			</if>
			<if test="departmentid != null">
				#{departmentid,jdbcType=VARCHAR},
			</if>
			<if test="showsetdec != null">
				#{showsetdec,jdbcType=NVARCHAR},
			</if>
			<if test="formid != null">
				#{formid,jdbcType=INTEGER},
			</if>
			<if test="showarea != null">
				#{showarea,jdbcType=TINYINT},
			</if>
			<if test="showindex != null">
				#{showindex,jdbcType=TINYINT},
			</if>
			<if test="showgoodsname != null">
				#{showgoodsname,jdbcType=TINYINT},
			</if>
			<if test="showtag != null">
				#{showtag,jdbcType=TINYINT},
			</if>
			<if test="showpirce != null">
				#{showpirce,jdbcType=TINYINT},
			</if>
			<if test="showlabel != null">
				#{showlabel,jdbcType=TINYINT},
			</if>
			<if test="labelplace != null">
				#{labelplace,jdbcType=TINYINT},
			</if>
			<if test="labelurl != null">
				#{labelurl,jdbcType=NVARCHAR},
			</if>
			<if test="cartstyle != null">
				#{cartstyle,jdbcType=NVARCHAR},
			</if>
			<if test="showkind != null">
				#{showkind,jdbcType=TINYINT},
			</if>
			<if test="orderby != null">
				#{orderby,jdbcType=TINYINT},
			</if>
			<if test="numofrow != null">
				#{numofrow,jdbcType=TINYINT},
			</if>
			<if test="mouldid != null">
				#{mouldid,jdbcType=SMALLINT},
			</if>
			<if test="creater != null">
				#{creater,jdbcType=VARCHAR},
			</if>
			<if test="created != null">
				#{created,jdbcType=TIMESTAMP},
			</if>
			<if test="modifier != null">
				#{modifier,jdbcType=VARCHAR},
			</if>
			<if test="modified != null">
				#{modified,jdbcType=TIMESTAMP},
			</if>
		</trim>
	</insert>
	<select id="countByExample" parameterType="com.fuxi.ws.data.entity.WShowsetExample"
		resultType="java.lang.Integer">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jun 13 
			11:02:19 CST 2016. -->
		select count(*) from W_ShowSet
		<if test="_parameter != null">
			<include refid="Example_Where_Clause" />
		</if>
	</select>
	<update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WShowset">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jun 13 
			11:02:19 CST 2016. -->
		update W_ShowSet
		<set>
			<if test="showsetname != null">
				ShowSetName = #{showsetname,jdbcType=NVARCHAR},
			</if>
			<if test="departmentid != null">
				DepartmentID = #{departmentid,jdbcType=VARCHAR},
			</if>
			<if test="showsetdec != null">
				ShowSetDec = #{showsetdec,jdbcType=NVARCHAR},
			</if>
			<if test="formid != null">
				FormID = #{formid,jdbcType=INTEGER},
			</if>
			<if test="showarea != null">
				ShowArea = #{showarea,jdbcType=TINYINT},
			</if>
			<if test="showindex != null">
				ShowIndex = #{showindex,jdbcType=TINYINT},
			</if>
			<if test="showgoodsname != null">
				ShowGoodsName = #{showgoodsname,jdbcType=TINYINT},
			</if>
			<if test="showtag != null">
				ShowTag = #{showtag,jdbcType=TINYINT},
			</if>
			<if test="showpirce != null">
				ShowPirce = #{showpirce,jdbcType=TINYINT},
			</if>
			<if test="showlabel != null">
				ShowLabel = #{showlabel,jdbcType=TINYINT},
			</if>
			<if test="labelplace != null">
				LabelPlace = #{labelplace,jdbcType=TINYINT},
			</if>
			<if test="labelurl != null">
				LabelUrl = #{labelurl,jdbcType=NVARCHAR},
			</if>
			<if test="cartstyle != null">
				CartStyle = #{cartstyle,jdbcType=NVARCHAR},
			</if>
			<if test="showkind != null">
				ShowKind = #{showkind,jdbcType=TINYINT},
			</if>
			<if test="orderby != null">
				OrderBy = #{orderby,jdbcType=TINYINT},
			</if>
			<if test="numofrow != null">
				NumOfRow = #{numofrow,jdbcType=TINYINT},
			</if>
			<if test="mouldid != null">
				MouldID = #{mouldid,jdbcType=SMALLINT},
			</if>
			<if test="creater != null">
				Creater = #{creater,jdbcType=VARCHAR},
			</if>
			<if test="created != null">
				Created = #{created,jdbcType=TIMESTAMP},
			</if>
			<if test="modifier != null">
				Modifier = #{modifier,jdbcType=VARCHAR},
			</if>
			<if test="modified != null">
				Modified = #{modified,jdbcType=TIMESTAMP},
			</if>
		</set>
		where ShowSetID = #{showsetid,jdbcType=SMALLINT}
	</update>
	<update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WShowset">
		<!-- WARNING - @mbggenerated This element is automatically generated by 
			MyBatis Generator, do not modify. This element was generated on Mon Jun 13 
			11:02:19 CST 2016. -->
		update W_ShowSet
		set ShowSetName = #{showsetname,jdbcType=NVARCHAR},
		DepartmentID = #{departmentid,jdbcType=VARCHAR},
		ShowSetDec =
		#{showsetdec,jdbcType=NVARCHAR},
		FormID = #{formid,jdbcType=INTEGER},
		ShowArea = #{showarea,jdbcType=TINYINT},
		ShowIndex =
		#{showindex,jdbcType=TINYINT},
		ShowGoodsName =
		#{showgoodsname,jdbcType=TINYINT},
		ShowTag =
		#{showtag,jdbcType=TINYINT},
		ShowPirce = #{showpirce,jdbcType=TINYINT},
		ShowLabel = #{showlabel,jdbcType=TINYINT},
		LabelPlace =
		#{labelplace,jdbcType=TINYINT},
		LabelUrl =
		#{labelurl,jdbcType=NVARCHAR},
		CartStyle =
		#{cartstyle,jdbcType=NVARCHAR},
		ShowKind =
		#{showkind,jdbcType=TINYINT},
		OrderBy = #{orderby,jdbcType=TINYINT},
		NumOfRow = #{numofrow,jdbcType=TINYINT},
		MouldID =
		#{mouldid,jdbcType=SMALLINT},
		Creater = #{creater,jdbcType=VARCHAR},
		Created = #{created,jdbcType=TIMESTAMP},
		Modifier =
		#{modifier,jdbcType=VARCHAR},
		Modified = #{modified,jdbcType=TIMESTAMP}
		where ShowSetID = #{showsetid,jdbcType=SMALLINT}
	</update>
	<!-- <cache eviction="FIFO" size="1024" readOnly="true"></cache> -->

	<!-- 首页展位设置参数 -->
	<select id="showSetConfig" resultType="java.util.LinkedHashMap">
		select
		a.ShowSetID,a.ShowGoodsName,a.ShowTag,a.ShowPirce,a.ShowLabel,a.CartStyle,a.ShowKind,
		b.LineID,b.ShowStyle,a.ShowIndex,b.LineIndex
		from W_ShowSet a
		join
		W_ShowSetLine
		b on a.ShowSetID=b.ShowSetID
		where
		a.ShowArea in (1,3,4)
		order by
		a.ShowIndex,b.LineIndex
	</select>

	<!-- 首页展位 -->
	<select id="showSet" resultType="java.util.LinkedHashMap">
		select a.ShowSetID,
		a.ShowSetName,a.ShowSetDec,a.ShowGoodsName,ISNULL(a.ShowTag,0)
		ShowTag,a.ShowPirce,a.ShowLabel,
		a.LabelPlace,ISNULL(a.LabelUrl,'')
		LabelUrl,ISNULL(a.CartStyle,'') CartStyle, a.ShowKind,
		a.ShowIndex,b.LineID,b.ClumIndex,ISNULL(c.ImgPath,'')
		ImgPath,ISNULL(b.ImgPath,'') adImgPath,
		b.GoodsID,c.GoodName,ISNULL(c.InitialPrice,'')InitialPrice,c.Price,
		b.ADUrl,b.TicketID,e.Parvalue,e.MinConsumption,e.Color
		TicketStyle,b.GoodsTypeID,f.GoodsType,a.OrderBy,a.NumOfRow
		,c.PayByPoint,c.Integral,(select ItemValue from W_Config where
		ConfigID='56') ItemValue,g.GoodsType
		GoodsGrounp,c.LabelImgFlag,c.LabelImgUrl,b.FocusImg
		from W_ShowSet a
		left
		join W_ShowSetDtl b on
		a.ShowSetID=b.ShowSetID
		left join W_Goods c
		on
		b.GoodsID=c.GoodsID
		left
		join W_ShowSetLine d on
		b.LineID=d.LineID and
		b.ShowSetID=d.ShowSetID
		left join W_Ticket e on
		b.TicketID=e.TicketID
		left join W_GoodsType f on
		b.GoodsTypeID=convert(varchar(20),f.GoodsTypeID) and a.ShowKind=7
		left
		join GoodsType g on b.GoodsTypeID=g.GoodsTypeID and a.ShowKind=11
		where
		ShowArea=#{showarea}
		order by
		a.ShowIndex,a.ShowSetID,d.LineIndex,b.ClumIndex
	</select>

	<!-- 微页面 -->
	<select id="microPage" resultType="java.util.LinkedHashMap">
		select a.ShowSetID,
		a.ShowSetName,a.ShowSetDec,a.ShowGoodsName,ISNULL(a.ShowTag,0)
		ShowTag,a.ShowPirce,a.ShowLabel,
		a.LabelPlace,ISNULL(a.LabelUrl,'')
		LabelUrl,ISNULL(a.CartStyle,'') CartStyle, a.ShowKind,
		a.ShowIndex,b.LineID,b.ClumIndex,ISNULL(c.ImgPath,'')
		ImgPath,ISNULL(b.ImgPath,'') adImgPath,
		b.GoodsID,c.GoodName,ISNULL(c.InitialPrice,'')InitialPrice,c.Price,
		b.ADUrl,b.TicketID,e.Parvalue,e.MinConsumption,e.Color
		TicketStyle,b.GoodsTypeID,f.GoodsType,a.OrderBy,gm.FormTitle,a.NumOfRow
		,c.PayByPoint,c.Integral,(select ItemValue from W_Config where
		ConfigID='56') ItemValue,g.GoodsType
		GoodsGrounp,c.LabelImgFlag,c.LabelImgUrl,b.FocusImg
		from W_ShowSet a
		left
		join W_ShowSetDtl b on a.ShowSetID=b.ShowSetID
		left
		join W_Goods c
		on
		b.GoodsID=c.GoodsID
		left join W_ShowSetLine d on
		b.LineID=d.LineID and
		b.ShowSetID=d.ShowSetID
		left join W_Ticket e on
		b.TicketID=e.TicketID
		left join W_GoodsType f on
		b.GoodsTypeID=convert(varchar(20),f.GoodsTypeID) and a.ShowKind=7
		left
		join GoodsType g on b.GoodsTypeID=g.GoodsTypeID and a.ShowKind=11
		join
		W_MicroForm gm on a.FormID=gm.FormID
		where
		a.formid=#{formid}
		order by
		a.ShowIndex,d.LineIndex,b.ClumIndex
	</select>

	<!-- 展位维护列表 -->
	<select id="selectshowSetByArea" resultType="java.util.LinkedHashMap">
		select * from (
		select top 1
		f.FormID,a.ShowSetID,b.GoodsID,a.ShowKind,b.ADUrl,ISNULL(b.ImgPath,'')
		ImgPath,a.ShowSetName,a.ShowSetDec,a.LabelUrl,a.CartStyle,''
		TicketStyle,
		'店招'as ShowKindName,0 Parvalue,'' GoodsType,0 as
		AtList,isnull(m.MouldTye,0)
		MouldTye,
		0 ShowIndex,0 LineIndex,0
		ClumIndex
		from W_Microform f with(nolock) inner join
		W_Mould m
		with(nolock) on m.Mouldid=f.Mouldid and m.MouldTye=1 left join
		W_ShowSet a with(nolock) on f.Formid=a.formid and a.ShowKind = 10 left
		join
		W_ShowSetDtl b with(nolock) on a.ShowSetID=b.ShowSetID
		where
		a.ShowArea=#{showarea,jdbcType=TINYINT}
		union all
		select
		a.FormID,a.ShowSetID,b.GoodsID,a.ShowKind,b.ADUrl,isnull(g.ImgPath,ISNULL(b.ImgPath,''))
		ImgPath,a.ShowSetName,a.ShowSetDec,a.LabelUrl,a.CartStyle,b.TicketStyle,
		case a.ShowKind when 1 then '商品列表' when 2 then
		'广告图片' when 3 then '优惠券'
		when 4 then '导航图片' when 5 then '商品搜索' when 6
		then '分栏标题' when 7 then
		'商品分组' when 8 then '辅助空白' when 9 then '公告'
		when 10 then '店招' when 11
		then '商品分类' when 12 then '广告视频' end as ShowKindName,d.Parvalue,
		case a.ShowKind when 7 then
		p.GoodsType when 11 then
		isnull(r.Name,q.GoodsType)
		else '' end as
		GoodsType,case when g.AtList=0 then 0 when
		(Select SUM(Quantity) from
		W_Store with(nolock) where
		GoodsID=g.GoodsID)=0 then 0 else 1 end as
		AtList,0 as
		MouldTye,a.ShowIndex,c.LineIndex,b.ClumIndex
		from W_ShowSet
		a with(nolock) inner join
		W_ShowSetLine c with(nolock) on
		c.ShowSetID=a.ShowSetID inner join
		W_ShowSetDtl b with(nolock) on
		a.ShowSetID=b.ShowSetID and b.LineID=c.LineID left join
		W_Goods g
		with(nolock) on g.GoodsID=b.GoodsID left join
		W_Ticket d with(nolock)
		on d.TicketID=b.TicketID left join
		W_GoodsType p with(nolock) on
		convert(varchar(20),p.Goodstypeid)=b.GoodsTypeid
		and a.ShowKind=7 left
		join
		GoodsType q with(nolock) on q.Goodstypeid=b.GoodsTypeid and
		a.ShowKind=11 left
		join
		GoodsSubType r with(nolock) on
		r.GoodsSubTypeID=b.GoodsID and a.ShowKind=11
		where
		a.ShowArea=#{showarea,jdbcType=TINYINT} and a.ShowKind <![CDATA[<>]]>
		10
		) tb
		order by tb.MouldTye desc, tb.ShowIndex asc,tb.ShowSetID
		asc,tb.LineIndex asc,tb.ClumIndex asc

	</select>

	<!-- 商品展位维护页数据 -->
	<select id="selectGoodsShowById" resultType="java.util.LinkedHashMap">
		select
		a.ShowSetName,a.ShowGoodsName,ISNULL(a.ShowTag,0)
		ShowTag,a.ShowPirce,a.ShowLabel,a.NumOfRow,
		a.LabelPlace,ISNULL(a.LabelUrl,'')
		LabelUrl,ISNULL(a.CartStyle,'')
		CartStyle,d.LineIndex,
		a.ShowSetID,b.LineID,b.ShowSetDtlId,b.ClumIndex,isnull(c.ImgPath,ISNULL(b.ImgPath,''))
		ImgPath,b.GoodsID,
		c.Code,a.ShowIndex,c.GoodName,ISNULL(c.InitialPrice,'')InitialPrice,c.Price,
		case when c.AtList=0 then 0 when (Select SUM(Quantity) from W_Store
		with(nolock)
		where GoodsID=c.GoodsID)=0 then 0 else 1 end as AtList
		from W_ShowSet a with(nolock)
		inner join W_ShowSetDtl b with(nolock) on
		a.ShowSetID=b.ShowSetID
		inner join W_Goods c with(nolock)
		on
		b.GoodsID=c.GoodsID
		inner join W_ShowSetLine d with(nolock) on
		b.LineID=d.LineID and b.ShowSetID=d.ShowSetID
		where
		a.ShowSetID=#{showsetid,jdbcType=SMALLINT}
		order by
		d.LineIndex,b.ClumIndex
	</select>

	<!-- 广告展位维护页数据 -->
	<select id="selectAdShowGyId" resultType="java.util.LinkedHashMap">
		select
		a.ShowSetName,a.ShowSetID,b.LineID,b.GoodsID,b.GoodsTypeID,b.ShowSetDtlId,b.TicketID,b.ClumIndex,ISNULL(b.ImgPath,'')
		ImgPath,b.ADUrl
		from W_ShowSet a inner join
		W_ShowSetDtl b on
		a.ShowSetID=b.ShowSetID inner join
		W_ShowSetLine d on
		b.LineID=d.LineID
		and b.ShowSetID=d.ShowSetID
		where
		a.ShowSetID=#{showsetid,jdbcType=SMALLINT}
		order by
		d.LineIndex,b.ClumIndex
	</select>

	<!-- 商品分类展位维护页数据 -->
	<select id="selectGoodstypeGyId" resultType="java.util.LinkedHashMap">
		select
		a.ShowSetName,a.ShowSetID,b.GoodsTypeID,b.ShowSetDtlId
		from W_ShowSet a
		inner join
		W_ShowSetDtl b on
		a.ShowSetID=b.ShowSetID inner join
		W_ShowSetLine d on
		b.LineID=d.LineID
		and b.ShowSetID=d.ShowSetID
		where
		a.ShowSetID=#{showsetid,jdbcType=SMALLINT}
		order by
		d.LineIndex,b.ClumIndex
	</select>

	<!-- 获取展位显示索引 -->
	<select id="selectshowindex" resultType="java.lang.Byte">
		select
		isnull(max(ShowIndex)+1,1) ShowIndex
		from W_ShowSet
	</select>

	<!-- 新品数量 -->
	<select id="newGoodsCount" resultType="java.lang.Integer">
		select COUNT(*) from
		W_ShowSet a
		join W_ShowSetDtl b on
		a.ShowSetID=b.ShowSetID
		join W_Goods c
		on b.GoodsID=c.GoodsID
		where a.ShowArea='3' and a.ShowKind='1'
	</select>

	<!-- 新品分类数量 -->
	<select id="newGoodsTypeCount" resultType="java.lang.String">
		select b.GoodsTypeID
		from
		W_ShowSet a
		join w_showsetdtl b on a.showsetid=b.showsetid
		where
		a.ShowArea=3 and a.ShowKind=7
	</select>

	<!-- 热销数量 -->
	<select id="hotGoodsCount" resultType="java.lang.Integer">
		select COUNT(*) from
		W_ShowSet a
		join W_ShowSetDtl b on
		a.ShowSetID=b.ShowSetID
		join W_Goods c
		on b.GoodsID=c.GoodsID
		where a.ShowArea='4' and a.ShowKind='1'
	</select>

	<!-- 热销分类数量 -->
	<select id="hotGoodsTypeCount" resultType="java.lang.String">
		select b.GoodsTypeID
		from
		W_ShowSet a
		join w_showsetdtl b on a.showsetid=b.showsetid
		where
		a.ShowArea=4 and a.ShowKind=7
	</select>



	<!-- 获取优惠卷 -->
	<select id="getCoupons" resultType="java.util.LinkedHashMap">
		select b.ShowSetID,
		c.TicketID,c.Parvalue,c.MinConsumption,c.ParVIP,c.BeginTime,c.EndTime
		from
		W_ShowSet a
		join
		W_ShowSetDtl b on a.ShowSetID=b.ShowSetID
		join
		W_Ticket
		c on
		b.TicketID=c.TicketID
		where a.ShowKind='3' and
		a.ShowArea='1'
	</select>

	<!-- 导航图片 -->
	<select id="getBars" resultType="java.util.LinkedHashMap">
		select a.ShowSetID,
		a.ShowIndex,b.ClumIndex,ISNULL(b.ImgPath,'') adImgPath,b.ADUrl
		from
		W_ShowSet a
		left join W_ShowSetDtl b on a.ShowSetID=b.ShowSetID
		left
		join
		W_ShowSetLine d on
		b.LineID=d.LineID and b.ShowSetID=d.ShowSetID
		where
		ShowArea='1' and a.ShowKind='4'
		order by
		a.ShowIndex,d.LineIndex,b.ClumIndex
	</select>

	<!-- 首页设置:优惠卷 -->
	<select id="indexTicketSet" resultType="java.util.LinkedHashMap">
		select c.*,b.TicketStyle
		from W_ShowSet
		a
		join W_ShowSetDtl b on
		a.ShowSetID=b.ShowSetID
		join
		W_Ticket c on
		b.TicketID=c.TicketID
		where
		a.ShowArea='1' and
		a.ShowKind='3' and
		a.ShowSetID=#{ showsetid }
		order by
		a.ShowIndex,b.LineID,b.ClumIndex
	</select>

	<delete id="deleteShowsetDtl" parameterType="java.lang.Short">
		delete from
		W_ShowSet
		where ShowSetID = #{showsetid,jdbcType=SMALLINT}
		and (not
		exists(select * from W_ShowSetDtl d where d.ShowSetID =
		#{showsetid,jdbcType=SMALLINT}))
	</delete>

	<!-- 读取商品列表信息 -->
	<select id="goodsList" resultType="java.util.LinkedHashMap">
		SELECT a.GoodsID, a.ImgPath, a.Code, a.GoodName,
		a.Price,b.SupplierName
		FROM W_Goods AS a left join
		W_Supplier b on
		a.SupplierID=b.SupplierID
		<if test="conditions != null and conditions != ''">
			where
			${conditions}
		</if>
		order by a.Created desc
	</select>

	<!-- 获取为页面列表 -->
	<select id="getFormList" resultType="java.util.LinkedHashMap">
		SELECT distinct FormID,
		ShowSetName,(select top 1 Status from W_ShowSet t where
		t.FormID=W_ShowSet.FormID) Status
		FROM W_ShowSet
		order by FormID
	</select>

	<!-- 设为主页 -->
	<update id="setFormAsMain" parameterType="java.lang.Integer">
		update W_ShowSet
		set
		ShowArea = #{showarea,jdbcType=TINYINT}
		where FormID =
		#{formid,jdbcType=INTEGER}
	</update>

	<!-- 获取微页面ID -->
	<select id="getFormID" resultType="java.lang.Integer">
		SELECT isnull(max(FormID),4) +
		1 as FormID
		FROM W_ShowSet
	</select>

	<!-- 删除微页面 -->
	<delete id="deleteFrom" parameterType="java.lang.Integer">
		delete from W_ShowSet
		where FormID = #{formid,jdbcType=INTEGER}
	</delete>
</mapper>