<?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">
<!-- 命名，每一个映射对象不一样
	namespace:必须与对应的接口全类名一致
 -->
 <mapper namespace="com.iamberry.wechat.service.mapper.PlaceOrderMapper">
 
  <sql id="orderAllField">
	t.PLACE_ORDERID id ,
	t.PLACE_INFO_ID placeInfoId ,
	t.PLACE_PRODUCT_ID productId,
	t.PLACE_PRODUCT_NUMBER productNumber,
	t.PLACE_OPENID  openid,
	t.PLACE_YET_AMOUNT  yetAmount,
	t.PLACE_AMOUNT amount,
	t.PLACE_POST_NUM  postNum,
	t.PLACE_POST_FIRM postFirm ,
	t.PLACE_STATUS  status,
	t.PLACE_SEND_DATE  sendDate,
	t.PLACE_ADDRESS_INFO address,
	t.PLACE_POSTCODE postCode,
	t.PLACE_CONTACT_TEL  tel,
	t.PLACE_CONTACT_NAME contactName,
	t.PLACE_CREATE_DATE  createDate,
	t.PLACE_ADMIN_REMARK  remark
  </sql>
 
  <select id="getOnePlaceOrder" parameterType="string" resultType="PlaceOrder">
	SELECT 
	<include refid="orderAllField"/>,p.product_name productName
       FROM tb_iamberry_place_order t
       left join tb_iamberry_product_info p
          on t.place_product_id=p.product_id
        WHERE t.PLACE_ORDERID = #{appid}
   </select>
   
    <select id="selectAll" resultType="PlaceOrder" parameterType="PlaceOrder">
		  select 
		<include refid="orderAllField"/>
          from tb_iamberry_place_order t
		<where>
			<if test="productId!=null and productId!=''" >
			   t.PLACE_PRODUCT_ID=#{productId}
			</if>
			<if test="id!=null and id!=''" >
			 and  t.PLACE_ORDERID=#{id}
			</if>
			<if test="status!=null and status!=''" >
			 and  t.PLACE_STATUS=#{status}
			</if>
			<if test="openid!=null and openid!=''" >
			 and  t.PLACE_OPENID=#{openid}
			</if>
			<if test="placeInfoId!=null and placeInfoId!=''" >
			 and  t.PLACE_INFO_ID=#{placeInfoId}
			</if>
			<if test="beginDate!=null and beginDate!=''">
			  and t.PLACE_CREATE_DATE &gt; #{beginDate}
			</if>
			<if test="endDate!=null and endDate!=''">
			  and t.PLACE_CREATE_DATE &lt; #{endDate}
			</if>  
	    </where>
	    order by PLACE_CREATE_DATE DESC 
	    <if test="page!=null and page.recordBegin>0 and page.pageSize>0 ">
	     limit ${page.recordBegin},${page.pageSize}
	    </if>
	     <if test="page!=null and page.recordBegin==0 and page.pageSize>0 ">
	     limit ${page.pageSize}
	    </if>  
	</select>
	
	<select id="selectAllMore" resultType="PlaceOrder" parameterType="PlaceOrder">
		  select 
		<include refid="orderAllField"/>,p.product_name productName ,m.place_name drpName
          from TB_IAMBERRY_PLACE_ORDER t left join tb_iamberry_product_info p
          on t.place_product_id=p.product_id 
          left join  TB_IAMBERRY_PLACE_INFO  m on t.place_openid=m.place_openid
		<where>
			<if test="productId!=null and productId!=''" >
			   t.PLACE_PRODUCT_ID=#{productId}
			</if>
			<if test="id!=null and id!=''" >
			 and  t.PLACE_ORDERID=#{id}
			</if>
			<if test="status!=null and status!=''" >
			 and  t.PLACE_STATUS=#{status}
			</if>
			<if test="openid!=null and openid!=''" >
			 and  t.PLACE_OPENID=#{openid}
			</if>
			<if test="placeInfoId!=null and placeInfoId!=''" >
			 and  t.PLACE_INFO_ID=#{placeInfoId}
			</if>
			<if test="beginDate!=null and beginDate!=''">
			  and t.PLACE_CREATE_DATE &gt; #{beginDate}
			</if>
			<if test="endDate!=null and endDate!=''">
			  and t.PLACE_CREATE_DATE &lt; #{endDate}
			</if>  
	    </where>
	    order by t.PLACE_CREATE_DATE DESC 
	    <if test="page!=null and page.recordBegin>0 and page.pageSize>0 ">
	     limit ${page.recordBegin},${page.pageSize}
	    </if>
	     <if test="page!=null and page.recordBegin==0 and page.pageSize>0 ">
	     limit ${page.pageSize}
	    </if>  
	</select>
	
	<select id="getAllCount" resultType="integer">
	 select count(PLACE_ORDERID) from tb_iamberry_place_order
		<where>
			<if test="productId!=null and productId!=''" >
			   PLACE_PRODUCT_ID=#{productId}
			</if>
			<if test="id!=null and id!=''" >
			 and  PLACE_ORDERID=#{id}
			</if>
			<if test="status!=null and status!=''" >
			 and  PLACE_STATUS=${status}
			</if>
			<if test="openid!=null and openid!=''" >
			  and PLACE_OPENID=#{openid}
			</if>
			<if test="placeInfoId!=null and placeInfoId!=''" >
			 and  t.PLACE_INFO_ID=#{placeInfoId}
			</if>
			<if test="beginDate!=null and beginDate!=''">
			  and PLACE_CREATE_DATE &gt; #{beginDate}
			</if>
			<if test="endDate!=null and endDate!=''">
			  and PLACE_CREATE_DATE &lt; #{endDate}
			</if>  
	    </where>
	 </select>
 
   <insert id="insert">
 	  insert into 
 	  tb_iamberry_place_order(
 	    PLACE_ORDERID ,
 	    PLACE_INFO_ID ,
 	    PLACE_PRODUCT_ID ,
		PLACE_PRODUCT_NUMBER ,
		PLACE_OPENID ,
		PLACE_YET_AMOUNT ,
		PLACE_AMOUNT ,
		PLACE_POST_NUM  ,
		PLACE_POST_FIRM ,
		PLACE_STATUS ,
		PLACE_SEND_DATE ,
		PLACE_ADDRESS_INFO ,
		PLACE_POSTCODE ,
		PLACE_CONTACT_TEL ,
		PLACE_CONTACT_NAME ,
		PLACE_CREATE_DATE ,
		PLACE_ADMIN_REMARK
 	   ) 
      values(
       #{id},
       #{placeInfoId},
	   #{productId},
	   #{productNumber},
	   #{openid},
	   #{yetAmount},
	   #{amount},
	   #{postNum},
	   #{postFirm},
	   #{status},
	   #{sendDate},
	   #{address},
	   #{postCode},
	   #{tel},
	   #{contactName},
	   #{createDate},
	   #{remark}
	  )
 	</insert>
 
    <update id="update" >
	     update tb_iamberry_place_order 
	     <set>
	     	<if test="productId!=null and productId!=''">
	          PLACE_PRODUCT_ID =#{productId},
	        </if>
	        <if test="productNumber!=null and productNumber!=''">
	          PLACE_PRODUCT_NUMBER =#{productNumber},
	        </if>
	        <if test="openid!=null and openid!=''">
	          PLACE_OPENID =#{openid},
	        </if>
	        <if test="placeInfoId!=null and placeInfoId!=''" >
			 and  t.PLACE_INFO_ID=${placeInfoId}
			</if>
	        <if test="yetAmount!=null and yetAmount!=''">
	          PLACE_YET_AMOUNT =#{yetAmount},
	        </if>
	        <if test="amount!=null and amount!=''">
	          PLACE_AMOUNT =#{amount},
	        </if>
	        <if test="postNum!=null and postNum!=''">
	          PLACE_POST_NUM =#{postNum},
	        </if>
	        <if test="postFirm!=null and postFirm!=''">
	          PLACE_POST_FIRM =#{postFirm},
	        </if>
	        <if test="status!=null and status!=''">
	          PLACE_STATUS =#{status},
	        </if>
	        <if test="sendDate!=null and sendDate!=''">
	          PLACE_SEND_DATE =#{sendDate},
	        </if>
	        <if test="postCode!=null and postCode!=''">
	          PLACE_POSTCODE =#{postCode},
	        </if>
	        <if test="tel!=null and tel!=''">
	          PLACE_CONTACT_TEL =#{tel},
	        </if>
	        <if test="contactName!=null and contactName!=''">
	          PLACE_CONTACT_NAME =#{contactName},
	        </if>
	        <if test="remark!=null and remark!=''">
	          PLACE_ADMIN_REMARK =#{remark},
	        </if>
	     </set> 
	     where PLACE_ORDERID = #{id}
     </update>
 
 
      <delete id="delete" parameterType="string">
	      delete from tb_iamberry_place_order  
	      where WHERE PLACE_ORDERID = #{appid}
      </delete>
   
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 </mapper>