<?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.ActivityConsumReturnMapper">

	   	<insert id="saveActivityConsumReturn" parameterType="cn.pluss.platform.entity.ActivityConsumReturn">
        	insert into tb_pluss_activity_consum_return(userId,merchantCode,merchantName,storeId,storeName,name,createDt,type,comsumeMoney,returnMoney,percent,startDt,endDt,timeType,posterUrl)VALUES(#{userId},#{merchantCode},#{merchantName},#{storeId},#{storeName},#{name},now(),#{type},#{comsumeMoney},#{returnMoney},#{percent},#{startDt},#{endDt},#{timeType},#{posterUrl})
    	</insert>

	   	<insert id="saveActivityConsumReturnBatch">
        	insert into tb_pluss_activity_consum_return(userId,merchantCode,merchantName,storeId,storeName,name,createDt,type,comsumeMoney,returnMoney,percent,startDt,endDt,timeType) VALUES 
    			<foreach collection="list" item="item" index="index" separator=",">
			(#{userId},#{merchantCode},#{merchantName},#{storeId},#{storeName},#{name},#{createDt},#{type},#{comsumeMoney},#{returnMoney},#{percent},#{startDt},#{endDt},#{timeType}		)
				</foreach>
    	</insert>

		<select id="queryActivityConsumReturn" parameterType="cn.pluss.platform.entity.ActivityConsumReturn" resultType="cn.pluss.platform.entity.ActivityConsumReturn">
			SELECT * from tb_pluss_activity_consum_return 
				<where> 
					<if test="id!= null"> 
					 	and id = #{id}
					 </if> 
					<if test="userId!= null"> 
					 	and userId = #{userId}
					 </if> 
					<if test="merchantCode!= null"> 
					 	and merchantCode = #{merchantCode}
					 </if> 
					<if test="merchantName!= null"> 
					 	and merchantName = #{merchantName}
					 </if> 
					<if test="storeId!= null"> 
					 	and storeId = #{storeId}
					 </if> 
					<if test="storeName!= null"> 
					 	and storeName = #{storeName}
					 </if> 
					<if test="name!= null"> 
					 	and name = #{name}
					 </if> 
					<if test="createDt!= null"> 
					 	and createDt = #{createDt}
					 </if> 
					<if test="type!= null"> 
					 	and type = #{type}
					 </if> 
					<if test="comsumeMoney!= null"> 
					 	and comsumeMoney = #{comsumeMoney}
					 </if> 
					<if test="returnMoney!= null"> 
					 	and returnMoney = #{returnMoney}
					 </if> 
					<if test="percent!= null"> 
					 	and percent = #{percent}
					 </if> 
					<if test="startDt!= null"> 
					 	and startDt = #{startDt}
					 </if> 
					<if test="endDt!= null"> 
					 	and endDt = #{endDt}
					 </if> 
					<if test="timeType!= null"> 
					 	and timeType = #{timeType}
					 </if> 
					 <if test="posterUrl!= null"> 
					 	and posterUrl = #{posterUrl}
					 </if> 
				 </where> 
		</select>

		<select id="queryActivityConsumReturnList" parameterType="cn.pluss.platform.entity.ActivityConsumReturn" resultType="cn.pluss.platform.entity.ActivityConsumReturn">
			SELECT * from tb_pluss_activity_consum_return 
				<where> 
					<if test="id!= null"> 
					 and 	id = #{id}
					 </if> 
					<if test="userId!= null"> 
					 and 	userId = #{userId}
					 </if> 
					<if test="merchantCode!= null"> 
					 and 	merchantCode = #{merchantCode}
					 </if> 
					<if test="merchantName!= null"> 
					 and 	merchantName = #{merchantName}
					 </if> 
					<if test="storeId!= null"> 
					 and 	storeId = #{storeId}
					 </if> 
					<if test="storeName!= null"> 
					 and 	storeName = #{storeName}
					 </if> 
					<if test="name!= null"> 
					 and 	name = #{name}
					 </if> 
					<if test="createDt!= null"> 
					 and 	createDt = #{createDt}
					 </if> 
					<if test="type!= null"> 
					 and 	type = #{type}
					 </if> 
					<if test="comsumeMoney!= null"> 
					 and 	comsumeMoney = #{comsumeMoney}
					 </if> 
					<if test="returnMoney!= null"> 
					 and 	returnMoney = #{returnMoney}
					 </if> 
					<if test="percent!= null"> 
					 and 	percent = #{percent}
					 </if> 
					<if test="startDt!= null"> 
					 and 	startDt = #{startDt}
					 </if> 
					<if test="endDt!= null"> 
					 and 	endDt = #{endDt}
					 </if> 
					<if test="timeType!= null"> 
					 and 	timeType = #{timeType}
					 </if> 
					 <if test="posterUrl!= null"> 
					 and 	posterUrl = #{posterUrl}
					 </if> 
				 </where> 
		</select>

		<update id="updateActivityConsumReturn" parameterType="cn.pluss.platform.entity.ActivityConsumReturn" >
			update tb_pluss_activity_consum_return 
				  <set> 
				  startDt = #{startDt},
				  endDt = #{endDt},
					<if test="userId!= null"> 
					 	userId = #{userId},
					 </if> 
					<if test="merchantCode!= null"> 
					 	merchantCode = #{merchantCode},
					 </if> 
					<if test="merchantName!= null"> 
					 	merchantName = #{merchantName},
					 </if> 
					<if test="storeId!= null"> 
					 	storeId = #{storeId},
					 </if> 
					<if test="storeName!= null"> 
					 	storeName = #{storeName},
					 </if> 
					<if test="name!= null"> 
					 	name = #{name},
					 </if> 
					<if test="createDt!= null"> 
					 	createDt = #{createDt},
					 </if> 
					<if test="type!= null"> 
					 	type = #{type},
					 </if> 
					<if test="comsumeMoney!= null"> 
					 	comsumeMoney = #{comsumeMoney},
					 </if> 
					<if test="returnMoney!= null"> 
					 	returnMoney = #{returnMoney},
					 </if> 
					<if test="percent!= null"> 
					 	percent = #{percent},
					 </if> 
					<if test="timeType!= null"> 
					 	timeType = #{timeType},
					 </if> 
					 <if test="posterUrl!= null"> 
					  	posterUrl = #{posterUrl}
					 </if> 
				</set>
			where id=#{id} 
		</update>

		<delete id="deleteActivityConsumReturn" parameterType="cn.pluss.platform.entity.ActivityConsumReturn" >
			DELETE FROM tb_pluss_activity_consum_return where id=#{id}
		</delete>

		<select id="queryActivityConsumReturnPage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.ActivityConsumReturn">
			SELECT * from tb_pluss_activity_consum_return 
				<where> 
					<if test="id!= null"> 
					and id = #{id}
					 </if> 
					<if test="userId!= null"> 
					and userId = #{userId}
					 </if> 
					<if test="merchantCode!= null"> 
					and merchantCode = #{merchantCode}
					 </if> 
					<if test="merchantName!= null"> 
					and merchantName = #{merchantName}
					 </if> 
					<if test="storeId!= null"> 
					and storeId = #{storeId}
					 </if> 
					<if test="storeName!= null"> 
					and storeName = #{storeName}
					 </if> 
					<if test="name!= null"> 
					and name Like CONCAT("%",#{name},"%")
					 </if> 
					<if test="createDt!= null"> 
					and createDt = #{createDt}
					 </if> 
					<if test="type!= null"> 
					and type = #{type}
					 </if> 
					<if test="comsumeMoney!= null"> 
					and comsumeMoney = #{comsumeMoney}
					 </if> 
					<if test="returnMoney!= null"> 
					and returnMoney = #{returnMoney}
					 </if> 
					<if test="percent!= null"> 
					and percent = #{percent}
					 </if> 
					 
					 <if test="startDt!= null">
					   AND startDt <![CDATA[>=]]>#{startDt}
					 </if>
                <if test="endDt!= null">
                    AND endDt <![CDATA[<=]]>#{endDt}
                </if>
					 
					<!-- <if test="startDt!= null"> 
					and startDt = #{startDt}
					 </if> 
					<if test="endDt!= null"> 
					and endDt = #{endDt}
					 </if>  -->
					<if test="timeType!= null"> 
					and timeType = #{timeType}
					 </if> 
					 <if test="posterUrl!= null"> 
					 and 	posterUrl = #{posterUrl}
					 </if> 
				 </where> 
			order by id desc  limit #{pageSize}  offset  #{offset}  
		</select>

	<select id="queryActivityNoConsumReturnPage" parameterType="java.util.Map" resultType="cn.pluss.platform.entity.ActivityConsumReturn">
		SELECT * from tb_pluss_activity_consum_return
		<where>
			<if test="id!= null">
				and id = #{id}
			</if>
			<if test="userId!= null">
				and userId = #{userId}
			</if>
			<if test="merchantCode!= null">
				and merchantCode IN (SELECT merchantCode
				FROM tb_pluss_merchant_base_info
				WHERE bindingCode = (SELECT bindingCode
				FROM tb_pluss_merchant_base_info
				where merchantCode = #{merchantCode}))
			</if>
			<if test="merchantName!= null">
				and merchantName = #{merchantName}
			</if>
			<if test="storeId!= null">
				and storeId = #{storeId}
			</if>
			<if test="storeName!= null">
				and storeName = #{storeName}
			</if>
			<if test="name!= null">
				and name Like CONCAT("%",#{name},"%")
			</if>
			<if test="createDt!= null">
				and createDt = #{createDt}
			</if>
			<if test="type!= null">
				and type = #{type}
			</if>
			<if test="comsumeMoney!= null">
				and comsumeMoney = #{comsumeMoney}
			</if>
			<if test="returnMoney!= null">
				and returnMoney = #{returnMoney}
			</if>
			<if test="percent!= null">
				and percent = #{percent}
			</if>

			<if test="startDt!= null">
				AND startDt <![CDATA[>=]]>#{startDt}
			</if>
			<if test="endDt!= null">
				AND endDt <![CDATA[<=]]>#{endDt}
			</if>

			<!-- <if test="startDt!= null">
            and startDt = #{startDt}
             </if>
            <if test="endDt!= null">
            and endDt = #{endDt}
             </if>  -->
			<if test="timeType!= null">
				and timeType = #{timeType}
			</if>
			<if test="posterUrl!= null">
				and 	posterUrl = #{posterUrl}
			</if>
		</where>
		order by id desc  limit #{pageSize}  offset  #{offset}
	</select>

		<select id="queryActivityConsumReturnPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
			SELECT count(*) from tb_pluss_activity_consum_return 
					<where> 
					<if test="id!= null"> 
					 and id = #{id}
					 </if> 
					<if test="userId!= null"> 
					 and userId = #{userId}
					 </if> 
					<if test="merchantCode!= null"> 
					 and merchantCode = #{merchantCode}
					 </if> 
					<if test="merchantName!= null"> 
					 and merchantName = #{merchantName}
					 </if> 
					<if test="storeId!= null"> 
					 and storeId = #{storeId}
					 </if> 
					<if test="storeName!= null"> 
					 and storeName = #{storeName}
					 </if> 
					<if test="name!= null"> 
					 and name Like CONCAT("%",#{name},"%")
					 </if> 
					<if test="createDt!= null"> 
					 and createDt = #{createDt}
					 </if> 
					<if test="type!= null"> 
					 and type = #{type}
					 </if> 
					<if test="comsumeMoney!= null"> 
					 and comsumeMoney = #{comsumeMoney}
					 </if> 
					<if test="returnMoney!= null"> 
					 and returnMoney = #{returnMoney}
					 </if> 
					<if test="percent!= null"> 
					 and percent = #{percent}
					 </if> 
					 
					  <if test="startDt!= null">
                       AND startDt <![CDATA[>=]]>#{startDt}
                     </if>
                <if test="endDt!= null">
                    AND endDt <![CDATA[<=]]>#{endDt}
                </if>
					 
					<!-- <if test="startDt!= null"> 
					 and startDt = #{startDt}
					 </if> 
					<if test="endDt!= null"> 
					 and endDt = #{endDt}
					 </if>  -->
					<if test="timeType!= null"> 
					 and timeType = #{timeType}
					 </if> 
				</where>
		</select>

	<select id="queryActivityNoConsumReturnPageCount" parameterType="java.util.Map" resultType="java.lang.Integer">
		SELECT count(*) from tb_pluss_activity_consum_return
		<where>
			<if test="id!= null">
				and id = #{id}
			</if>
			<if test="userId!= null">
				and userId = #{userId}
			</if>
			<if test="merchantCode!= null">
				and merchantCode IN (SELECT merchantCode
				FROM tb_pluss_merchant_base_info
				WHERE bindingCode = (SELECT bindingCode
				FROM tb_pluss_merchant_base_info
				where merchantCode = #{merchantCode}))
			</if>
			<if test="merchantName!= null">
				and merchantName = #{merchantName}
			</if>
			<if test="storeId!= null">
				and storeId = #{storeId}
			</if>
			<if test="storeName!= null">
				and storeName = #{storeName}
			</if>
			<if test="name!= null">
				and name Like CONCAT("%",#{name},"%")
			</if>
			<if test="createDt!= null">
				and createDt = #{createDt}
			</if>
			<if test="type!= null">
				and type = #{type}
			</if>
			<if test="comsumeMoney!= null">
				and comsumeMoney = #{comsumeMoney}
			</if>
			<if test="returnMoney!= null">
				and returnMoney = #{returnMoney}
			</if>
			<if test="percent!= null">
				and percent = #{percent}
			</if>
			<if test="startDt!= null">
				AND startDt <![CDATA[>=]]>#{startDt}
			</if>
			<if test="endDt!= null">
				AND endDt <![CDATA[<=]]>#{endDt}
			</if>
			<!-- <if test="startDt!= null">
             and startDt = #{startDt}
             </if>
            <if test="endDt!= null">
             and endDt = #{endDt}
             </if>  -->
			<if test="timeType!= null">
				and timeType = #{timeType}
			</if>
		</where>
	</select>

</mapper>
