<?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="cn.pluss.platform.mapper.DeviceMerchantBuyDetailMapper">

	   	<insert id="saveDeviceMerchantBuyDetail" parameterType="cn.pluss.platform.entity.DeviceMerchantBuyDetail">
        	insert into tb_pluss_device_merchant_buy_detail(orderNo,soleCode)VALUES(#{orderNo},#{soleCode})
    	</insert>

	   	<insert id="saveDeviceMerchantBuyDetailBatch">
        	insert into tb_pluss_device_merchant_buy_detail(orderNo,soleCode) VALUES 
    			<foreach collection="list" item="item" index="index" separator=",">
			(#{orderNo},#{soleCode}		)
				</foreach>
    	</insert>

		<select id="queryDeviceMerchantBuyDetail" parameterType="cn.pluss.platform.entity.DeviceMerchantBuyDetail" resultType="cn.pluss.platform.entity.DeviceMerchantBuyDetail">
			SELECT * from tb_pluss_device_merchant_buy_detail 
				<where> 
					<if test="id!= null"> 
					 	and id = #{id}
					 </if> 
					<if test="orderNo!= null"> 
					 	and orderNo = #{orderNo}
					 </if> 
					<if test="soleCode!= null"> 
					 	and soleCode = #{soleCode}
					 </if> 
				 </where> 
		</select>

		<select id="queryDeviceMerchantBuyDetailList" parameterType="cn.pluss.platform.entity.DeviceMerchantBuyDetail" resultType="cn.pluss.platform.entity.DeviceMerchantBuyDetail">
			SELECT * from tb_pluss_device_merchant_buy_detail 
				<where> 
					<if test="id!= null"> 
					 and 	id = #{id}
					 </if> 
					<if test="orderNo!= null"> 
					 and 	orderNo = #{orderNo}
					 </if> 
					<if test="soleCode!= null"> 
					 and 	soleCode = #{soleCode}
					 </if> 
				 </where> 
		</select>

		<update id="updateDeviceMerchantBuyDetail" parameterType="cn.pluss.platform.entity.DeviceMerchantBuyDetail" >
			update tb_pluss_device_merchant_buy_detail 
				  <set> 
					<if test="orderNo!= null"> 
					 	orderNo = #{orderNo},
					 </if> 
					<if test="soleCode!= null"> 
					 	soleCode = #{soleCode}
					 </if> 
				</set>
			where id=#{id} 
		</update>

		<delete id="deleteDeviceMerchantBuyDetail" parameterType="cn.pluss.platform.entity.DeviceMerchantBuyDetail" >
			DELETE FROM tb_pluss_device_merchant_buy_detail where id=#{id}
		</delete>

		<select id="queryDeviceMerchantBuyDetailPage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.DeviceMerchantBuyDetail">
			SELECT * from tb_pluss_device_merchant_buy_detail 
				<where> 
					<if test="id!= null"> 
					and id = #{id}
					 </if> 
					<if test="orderNo!= null"> 
					and orderNo = #{orderNo}
					 </if> 
					<if test="soleCode!= null"> 
					and soleCode = #{soleCode}
					 </if> 
				 </where> 
			order by id desc  limit #{pageSize}  offset  #{offset}  
		</select>

		<select id="queryDeviceMerchantBuyDetailPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
			SELECT count(*) from tb_pluss_device_merchant_buy_detail 
					<where> 
					<if test="id!= null"> 
					 and id = #{id}
					 </if> 
					<if test="orderNo!= null"> 
					 and orderNo = #{orderNo}
					 </if> 
					<if test="soleCode!= null"> 
					 and soleCode = #{soleCode}
					 </if> 
				</where>
		</select>
		
		<select id="queryDeviceMerchantBuyDetailVO" resultType="cn.pluss.platform.vo.DeviceMerchantBuyDetailVO">
		  select mbd.orderNo as orderNo,mbd.soleCode as soleCode,IFNULL(dsu.status,0) as status from tb_pluss_device_merchant_buy_detail mbd 
		  LEFT JOIN tb_pluss_device_sign_unbind dsu  ON mbd.orderNo=dsu.orderNo and mbd.soleCode=dsu.soleCode
		  where mbd.orderNo=#{orderNo}
		</select>

</mapper>
