<?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.WFittingMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WFitting">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu May 19 17:10:23 CST 2016.
    -->
    <id column="Fitting" jdbcType="BIGINT" property="fitting" />
    <result column="FittingNo" jdbcType="VARCHAR" property="fittingno" />
    
    <result column="VIPID" jdbcType="VARCHAR" property="vipid" />
    <result column="DepartmentID" jdbcType="VARCHAR" property="departmentid" />
    <result column="EmployeeID" jdbcType="VARCHAR" property="employeeid" />
    <result column="ReserveDate" jdbcType="TIMESTAMP" property="reservedate" />
    <result column="Reservetime" jdbcType="VARCHAR" property="reservetime" />
    <result column="Visit" jdbcType="TINYINT" property="visit" />
    <result column="Provinces" jdbcType="VARCHAR" property="provinces" />
    <result column="City" jdbcType="VARCHAR" property="city" />
    <result column="County" jdbcType="VARCHAR" property="county" />
    <result column="Addr" jdbcType="VARCHAR" property="addr" />
    <result column="ReceiverName" jdbcType="NVARCHAR" property="receivername" />
    <result column="Mobile" jdbcType="VARCHAR" property="mobile" />
    <result column="Appointmented" jdbcType="TINYINT" property="appointmented" />
    <result column="AppointmentDate" jdbcType="TIMESTAMP" property="appointmentdate" />
    <result column="Memo" jdbcType="NVARCHAR" property="memo" />
    <result column="Finished" jdbcType="TINYINT" property="finished" />
    <result column="Created" jdbcType="TIMESTAMP" property="created" />
    <result column="FinishDate" jdbcType="TIMESTAMP" property="finishdate" />
  </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 May 19 17:10:23 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 Thu May 19 17:10:23 CST 2016.
    -->
    Fitting, FittingNo, VIPID, DepartmentID, EmployeeID, ReserveDate, Reservetime, Visit, 
    Provinces, City, County, Addr, ReceiverName, Mobile, Appointmented, AppointmentDate, 
    Memo, Finished, Created, FinishDate
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WFittingExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu May 19 17:10:23 CST 2016.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_Fitting
    <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.Long" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu May 19 17:10:23 CST 2016.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_Fitting
    where Fitting = #{fitting,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu May 19 17:10:23 CST 2016.
    -->
    delete from W_Fitting
    where Fitting = #{fitting,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WFitting">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu May 19 17:10:23 CST 2016.
    -->
    insert into W_Fitting (Fitting, FittingNo, VIPID, 
      DepartmentID, EmployeeID, ReserveDate, 
      Reservetime, Visit, Provinces, 
      City, County, Addr, 
      ReceiverName, Mobile, Appointmented, 
      AppointmentDate, Memo, Finished, 
      Created, FinishDate)
    values (#{fitting,jdbcType=BIGINT}, #{fittingno,jdbcType=VARCHAR}, #{vipid,jdbcType=VARCHAR}, 
      #{departmentid,jdbcType=VARCHAR}, #{employeeid,jdbcType=VARCHAR}, #{reservedate,jdbcType=TIMESTAMP}, 
      #{reservetime,jdbcType=VARCHAR}, #{visit,jdbcType=TINYINT}, #{provinces,jdbcType=VARCHAR}, 
      #{city,jdbcType=VARCHAR}, #{county,jdbcType=VARCHAR}, #{addr,jdbcType=VARCHAR}, 
      #{receivername,jdbcType=NVARCHAR}, #{mobile,jdbcType=VARCHAR}, #{appointmented,jdbcType=TINYINT}, 
      #{appointmentdate,jdbcType=TIMESTAMP}, #{memo,jdbcType=NVARCHAR}, #{finished,jdbcType=TINYINT}, 
      #{created,jdbcType=TIMESTAMP}, #{finishdate,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WFitting">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu May 19 17:10:23 CST 2016.
    -->
    insert into W_Fitting
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="fitting != null">
        Fitting,
      </if>
      <if test="fittingno != null">
        FittingNo,
      </if>
      <if test="vipid != null">
        VIPID,
      </if>
      <if test="departmentid != null">
        DepartmentID,
      </if>
      <if test="employeeid != null">
        EmployeeID,
      </if>
      <if test="reservedate != null">
        ReserveDate,
      </if>
      <if test="reservetime != null">
        Reservetime,
      </if>
      <if test="visit != null">
        Visit,
      </if>
      <if test="provinces != null">
        Provinces,
      </if>
      <if test="city != null">
        City,
      </if>
      <if test="county != null">
        County,
      </if>
      <if test="addr != null">
        Addr,
      </if>
      <if test="receivername != null">
        ReceiverName,
      </if>
      <if test="mobile != null">
        Mobile,
      </if>
      <if test="appointmented != null">
        Appointmented,
      </if>
      <if test="appointmentdate != null">
        AppointmentDate,
      </if>
      <if test="memo != null">
        Memo,
      </if>
      <if test="finished != null">
        Finished,
      </if>
      <if test="created != null">
        Created,
      </if>
      <if test="finishdate != null">
        FinishDate,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="fitting != null">
        #{fitting,jdbcType=BIGINT},
      </if>
      <if test="fittingno != null">
        #{fittingno,jdbcType=VARCHAR},
      </if>
      <if test="vipid != null">
        #{vipid,jdbcType=VARCHAR},
      </if>
      <if test="departmentid != null">
        #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="employeeid != null">
        #{employeeid,jdbcType=VARCHAR},
      </if>
      <if test="reservedate != null">
        #{reservedate,jdbcType=TIMESTAMP},
      </if>
      <if test="reservetime != null">
        #{reservetime,jdbcType=VARCHAR},
      </if>
      <if test="visit != null">
        #{visit,jdbcType=TINYINT},
      </if>
      <if test="provinces != null">
        #{provinces,jdbcType=VARCHAR},
      </if>
      <if test="city != null">
        #{city,jdbcType=VARCHAR},
      </if>
      <if test="county != null">
        #{county,jdbcType=VARCHAR},
      </if>
      <if test="addr != null">
        #{addr,jdbcType=VARCHAR},
      </if>
      <if test="receivername != null">
        #{receivername,jdbcType=NVARCHAR},
      </if>
      <if test="mobile != null">
        #{mobile,jdbcType=VARCHAR},
      </if>
      <if test="appointmented != null">
        #{appointmented,jdbcType=TINYINT},
      </if>
      <if test="appointmentdate != null">
        #{appointmentdate,jdbcType=TIMESTAMP},
      </if>
      <if test="memo != null">
        #{memo,jdbcType=NVARCHAR},
      </if>
      <if test="finished != null">
        #{finished,jdbcType=TINYINT},
      </if>
      <if test="created != null">
        #{created,jdbcType=TIMESTAMP},
      </if>
      <if test="finishdate != null">
        #{finishdate,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WFittingExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu May 19 17:10:23 CST 2016.
    -->
    select count(*) from W_Fitting
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WFitting">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu May 19 17:10:23 CST 2016.
    -->
    update W_Fitting
    <set>
      <if test="fittingno != null">
        FittingNo = #{fittingno,jdbcType=VARCHAR},
      </if>
      <if test="vipid != null">
        VIPID = #{vipid,jdbcType=VARCHAR},
      </if>
      <if test="departmentid != null">
        DepartmentID = #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="employeeid != null">
        EmployeeID = #{employeeid,jdbcType=VARCHAR},
      </if>
      <if test="reservedate != null">
        ReserveDate = #{reservedate,jdbcType=TIMESTAMP},
      </if>
      <if test="reservetime != null">
        Reservetime = #{reservetime,jdbcType=VARCHAR},
      </if>
      <if test="visit != null">
        Visit = #{visit,jdbcType=TINYINT},
      </if>
      <if test="provinces != null">
        Provinces = #{provinces,jdbcType=VARCHAR},
      </if>
      <if test="city != null">
        City = #{city,jdbcType=VARCHAR},
      </if>
      <if test="county != null">
        County = #{county,jdbcType=VARCHAR},
      </if>
      <if test="addr != null">
        Addr = #{addr,jdbcType=VARCHAR},
      </if>
      <if test="receivername != null">
        ReceiverName = #{receivername,jdbcType=NVARCHAR},
      </if>
      <if test="mobile != null">
        Mobile = #{mobile,jdbcType=VARCHAR},
      </if>
      <if test="appointmented != null">
        Appointmented = #{appointmented,jdbcType=TINYINT},
      </if>
      <if test="appointmentdate != null">
        AppointmentDate = #{appointmentdate,jdbcType=TIMESTAMP},
      </if>
      <if test="memo != null">
        Memo = #{memo,jdbcType=NVARCHAR},
      </if>
      <if test="finished != null">
        Finished = #{finished,jdbcType=TINYINT},
      </if>
      <if test="created != null">
        Created = #{created,jdbcType=TIMESTAMP},
      </if>
      <if test="finishdate != null">
        FinishDate = #{finishdate,jdbcType=TIMESTAMP},
      </if>
    </set>
    where Fitting = #{fitting,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WFitting">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu May 19 17:10:23 CST 2016.
    -->
    update W_Fitting
    set FittingNo = #{fittingno,jdbcType=VARCHAR},
      VIPID = #{vipid,jdbcType=VARCHAR},
      DepartmentID = #{departmentid,jdbcType=VARCHAR},
      EmployeeID = #{employeeid,jdbcType=VARCHAR},
      ReserveDate = #{reservedate,jdbcType=TIMESTAMP},
      Reservetime = #{reservetime,jdbcType=VARCHAR},
      Visit = #{visit,jdbcType=TINYINT},
      Provinces = #{provinces,jdbcType=VARCHAR},
      City = #{city,jdbcType=VARCHAR},
      County = #{county,jdbcType=VARCHAR},
      Addr = #{addr,jdbcType=VARCHAR},
      ReceiverName = #{receivername,jdbcType=NVARCHAR},
      Mobile = #{mobile,jdbcType=VARCHAR},
      Appointmented = #{appointmented,jdbcType=TINYINT},
      AppointmentDate = #{appointmentdate,jdbcType=TIMESTAMP},
      Memo = #{memo,jdbcType=NVARCHAR},
      Finished = #{finished,jdbcType=TINYINT},
      Created = #{created,jdbcType=TIMESTAMP},
      FinishDate = #{finishdate,jdbcType=TIMESTAMP}
    where Fitting = #{fitting,jdbcType=BIGINT}
  </update>
  
  <!-- 预约单列表 -->
	<select id="fittinglist" resultType="java.util.LinkedHashMap">
select f.Fitting,f.FittingNo,d.Department,e.Name+'<![CDATA[<br/>]]>'+e.MobilPhone AS Employee,
		CONVERT(varchar(10),f.Created, 121) +'<![CDATA[<br/>]]>'+
		CONVERT(varchar(10),f.Created, 108) AS CreateDate,	
		CONVERT(varchar(10),f.ReserveDate, 121) +'<![CDATA[<br/>]]>'+
		f.Reservetime AS Reserve,f.ReserveDate as ReserveDate,
		isnull(v.VIP,'')  + '<![CDATA[<br/>]]>'
		+ isnull(v.MobilePhone,'') as vip,v.MobilePhone as VMobilePhone,e.MobilPhone as EMobilePhone,
		case
		f.Appointmented when 0 then '待确认' when 1 then '已完成' when 2 then '取消' when 3
		then '已过期' when 4 then case when f.Visit=0 then '待到店' when f.Visit=1 then '待上门'  when f.Visit=2 then '待快递' END 
		end as
		Status
		,case f.Visit when 0 then '到店' when 1 then '上门' when 2 then '快递' END as type
		from W_Fitting as f 
		inner join VIP as v on
		f.Vipid=v.VIPID
		left join Department as d on
		f.DepartmentID=d.DepartmentID
		inner join Employee as e on
		e.EmployeeID=f.EmployeeID
		<if test="conditions != null and conditions != ''">
			where
			${conditions}
		</if>
		order by f.Created desc
	</select>
  <!-- 获单个预约单信息 -->
	<select id="selectFitting" parameterType="java.lang.String" resultType="java.util.LinkedHashMap">
		SELECT a.Fitting,a.FittingNo,a.VIPID,a.DepartmentID,a.EmployeeID,convert(varchar(10),a.ReserveDate,121)  
		+ (case when a.Reservetime IS null then '' else ' ' + a.Reservetime end) ReserveDate,
		a.Visit,a.Provinces,a.City,a.County,a.Addr,case when a.ReserveDate<![CDATA[<]]>getdate() then 1 else 0 end as OverTime,
		a.Appointmented,a.AppointmentDate,a.Memo,a.Finished,a.Created,a.FinishDate,c.Department,d.Name,d.MobilPhone,a.ReceiverName,a.Mobile,
		isnull(c.Province,'') + isnull(c.City,'') + isnull(c.County,'') + isnull(c.Addr,'') Addr
		FROM W_Fitting AS a left JOIN
		Department AS c ON a.DepartmentID =	c.DepartmentID left JOIN
		Employee AS d ON a.EmployeeID = d.EmployeeID
		where  a.Fitting = #{fitting}
	</select>

	<!-- 获取我的试穿预约单信息 -->
	<select id="selectFittingList" parameterType="java.lang.String" resultType="java.util.LinkedHashMap">
		SELECT a.Fitting,a.FittingNo,a.VIPID,a.DepartmentID,a.EmployeeID,convert(varchar(10),a.ReserveDate,121) 
		+ (case when a.Reservetime IS null then '' else ' ' + a.Reservetime end) ReserveDate,
		a.Visit,a.Provinces,a.City,a.County,a.Addr,case when a.ReserveDate<![CDATA[<]]>getdate() then 1 else 0 end as OverTime,
		a.Appointmented,a.AppointmentDate,a.Memo,a.Finished,a.Created,a.FinishDate,c.Department,d.Name,d.MobilPhone,a.ReceiverName,a.Mobile
		FROM W_Fitting AS a left JOIN
		Department AS c ON a.DepartmentID =
		c.DepartmentID left JOIN
		Employee AS d ON a.EmployeeID = d.EmployeeID
		where  a.VIPID = #{vipid,jdbcType=VARCHAR}
		<if test="status != null and status != -1">
	    	and a.Appointmented = #{status}
	    </if>
	    <if test="visit != null and visit != -1">
	    	and a.Visit = #{visit}
	    </if>
		order by a.Fitting desc
	</select>
	
	<!-- 获取导购员的试穿预约单信息 -->
	<select id="selectGuideFitting" parameterType="java.lang.String" resultType="java.util.LinkedHashMap">
		SELECT
		a.Fitting,a.FittingNo,a.VIPID,a.DepartmentID,a.EmployeeID,convert(varchar(10),a.ReserveDate,121)  
		+ (case when a.Reservetime IS null then '' else ' ' + a.Reservetime end) ReserveDate,
		a.Visit,a.Provinces,a.City,a.County,a.Addr,	case when a.ReserveDate<![CDATA[<]]>getdate() then 1 else 0 end as OverTime,
		a.Appointmented,a.AppointmentDate,a.Memo,a.Finished,a.Created,a.FinishDate,c.Department,d.Name,d.MobilPhone,a.ReceiverName,a.Mobile
		FROM W_Fitting AS a inner JOIN
		Employee AS d ON a.EmployeeID = d.EmployeeID left JOIN
		Department AS c ON a.DepartmentID =	c.DepartmentID 
		where a.EmployeeID = #{empid,jdbcType=VARCHAR}
		<if test="status != null and status != -1">
	    	and a.Appointmented = #{status}
	    </if>
	    <if test="visit != null and visit != -1">
	    	and a.Visit = #{visit}
	    </if>
		order by a.Fitting desc
	</select>

	<!-- 获取我的试穿预约单明细信息 -->
	<select id="selectFittingDtlList" resultType="java.util.LinkedHashMap">
		SELECT
		a.Fitting,e.GoodName,isnull((select top 1 p.DiscountRate 
			from VIP v with(nolock) inner join 
			VIPType p with(nolock) on v.VIPTypeID=p.VIPTypeID
			where t.Fitting=a.Fitting and t.VIPID=v.VIPID),10)/10.0 * isnull(
				(select s1.Price from W_Store s1 with(nolock) where s1.GoodsID=a.GoodsID and s1.SizeID=a.SizeID and s1.ColorID=a.ColorID
					and s1.DepartmentID=t.DepartmentID),isnull(
				(select s.Price from W_Store s with(nolock) where s.GoodsID=a.GoodsID and s.SizeID=a.SizeID and s.ColorID=a.ColorID
					and s.DepartmentID=''),e.Price)) as Price,e.ImgPath,g.Color,h.Size
		FROM W_FittingDtl a with(nolock) inner join
		W_Fitting t with(nolock) on t.Fitting=a.Fitting INNER JOIN
		W_Goods AS e with(nolock) ON a.GoodsID = e.GoodsID left JOIN
		Color AS g with(nolock) 
		ON a.ColorID = g.ColorID left JOIN
		Size AS h with(nolock) ON a.SizeID = h.SizeID 
		where a.Fitting in (${fittings})
	</select>

	<!-- 门店试衣:获取相同的货品 -->
	<select id="getSameGoods" resultType="java.util.LinkedHashMap">
		select * from W_Fitting a
		join W_FittingDtl b on
		a.Fitting=b.Fitting
		where a.Visit=#{visit} and
		b.GoodsID=#{goodsid} and
		b.ColorID=#{colorid} and b.SizeID=#{sizeid}
	</select>

	<!-- -->
	<select id="getFittingDtl" resultType="java.util.LinkedHashMap">
		select	a.VIPID,b.GoodsID,b.ColorID,b.SizeID,c.GoodName,e.Size,d.Color,isnull(
				(select s1.Price from W_Store s1 with(nolock) where s1.GoodsID=b.GoodsID and s1.SizeID=b.SizeID and s1.ColorID=b.ColorID
					and s1.DepartmentID=a.DepartmentID),isnull(
				(select s.Price from W_Store s with(nolock) where s.GoodsID=b.GoodsID and s.SizeID=b.SizeID and s.ColorID=b.ColorID
					and s.DepartmentID=''),c.Price)) as Price,c.ImgPath
		from W_Fitting a with(nolock)
		join W_FittingDtl b with(nolock) on a.Fitting=b.Fitting
		join W_Goods
		c with(nolock) on b.GoodsID=c.GoodsID
		join Color d with(nolock) on b.ColorID=d.ColorID
		join Size e with(nolock)
		on b.SizeID=e.SizeID
		where a.Fitting=#{fitting}
	</select>
	
	<!-- 获取导购员当日业绩数据 -->
	<select id="getFittingGain" resultType="java.util.LinkedHashMap">
		select isnull(SUM(salesnum),0) as salesnum,isnull(SUM(returnnum),0) as returnnum,(select COUNT(*) from 
			W_Fitting 
			where  Created between CONVERT(datetime,CONVERT(varchar(10),getdate(),121)) and CONVERT(datetime,CONVERT(varchar(10),DATEADD(d,1,getdate()),121))
			and EmployeeID=#{employeeid}) as fittingnum 
		from (
			select distinct a.SourceOrderID, case when a.AllotSales>=0 then 1 else 0 end as salesnum,case when a.AllotSales<![CDATA[<]]>0 then 1 else 0 end as returnnum
			from WD_Orders a inner join 
			WD_Ordersdtl b on a.OrderID=b.OrderID
			where  a.pay_time between CONVERT(datetime,CONVERT(varchar(10),getdate(),121)) and CONVERT(datetime,CONVERT(varchar(10),DATEADD(d,1,getdate()),121))
			and b.EmployeeID=#{employeeid}  and a.Source =1
		) t
	</select>

	<select id="fittingdtllist" resultType="java.util.LinkedHashMap">

select	a.FittingNo,a.Fitting,a.VIPID,b.GoodsID,v.VIP,de.Department,de.Tel,v.MobilePhone,b.ColorID,a.Created,a.ReserveDate,a.Reservetime,b.SizeID,a.Memo,
c.GoodName,e.Size,f.Name as EmployeeName,d.Color,
isnull(
				(select s1.Price from W_Store s1 with(nolock) where s1.GoodsID=b.GoodsID and s1.SizeID=b.SizeID and s1.ColorID=b.ColorID
					and s1.DepartmentID=a.DepartmentID),isnull(
				(select s.Price from W_Store s with(nolock) where s.GoodsID=b.GoodsID and s.SizeID=b.SizeID and s.ColorID=b.ColorID
					and s.DepartmentID=''),c.Price)) as Price,case
		a.Appointmented when 0 then '待确认' when 1 then '已完成' when 2 then '取消' when 3
		then '已过期' when 4 then case when a.Visit=0 then '待到店' when a.Visit=1 then '待上门'  when a.Visit=2 then '待快递' END 
		end as
		Status,a.Provinces+a.City+a.County+a.Addr as adr,
		case a.Visit when 0 then '到店' when 1 then '上门' when 2 then '快递' END as type
		from W_Fitting a with(nolock)
		join W_FittingDtl b with(nolock) on a.Fitting=b.Fitting
		join W_Goods
		c with(nolock) on b.GoodsID=c.GoodsID
		join Color d with(nolock) on b.ColorID=d.ColorID
		join Size e with(nolock)
		on b.SizeID=e.SizeID
		join Vip v ON v.VipID=a.VipID
		inner join Employee as f on
		f.EmployeeID=a.EmployeeID
		join Department as de on de.DepartmentID = a.DepartmentID
	where
	a.Fitting=#{fitting}
	</select>
	
	<select id="fittinggoodsdtl" resultType="java.util.LinkedHashMap">
	select a.Fitting,
	(select top
	1 Code from W_Goods g where g.GoodsID=b.GoodsID) as Code,
	b.GoodsID,c.ImgPath,c.GoodName,c.code
	as GoodCode,d.Color,s.Size,c.Price
	from W_Fitting a
	inner join W_FittingDtl b
	on b.Fitting=a.Fitting
	inner join W_Goods c on
	c.GoodsID=b.GoodsID
	inner join Color d on d.ColorID=b.ColorID
	inner join
	Size s on s.SizeID=b.SizeID
	where a.Fitting=#{fitting}
	</select>
</mapper>