<?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="lingtao.net.dao.CustomerDataMapper">
	<!-- 获取操作的数据根据店铺 -->
	<select id="getCustomerDatas" parameterType="CustomerData" resultType="CustomerData">
		select * from tbl_customer_data
		<where>
			<if test="realname != null and realname != ''">
  				and realname like '%${realname}%'
  			</if>
			<if test="wangwang != null and wangwang != ''">
				and wangwang like '%${wangwang}%'
			</if>
			<if test="isBuy != null and isBuy != ''">
				and isBuy = #{isBuy}
			</if>
			<if test="roleSearch != null and roleSearch != ''">
  				and role = #{roleSearch}
  			</if>
  			<if test = "roleArr != null and roleArr != '' " > 
				and	role in
				<foreach collection="roleArr" item="item" open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
			<if test="createDateBegin !=null and createDateBegin != '' ">
				<![CDATA[and createDate >= #{createDateBegin} ]]>
			</if>
			<if test="createDateEnd !=null and createDateEnd != '' ">
				 <![CDATA[and createDate <= #{createDateEnd} ]]>
			</if>
		</where>
		 ORDER BY createDate DESC
	</select>

	<insert id="addCustomerData" useGeneratedKeys="true" keyProperty="id" parameterType="CustomerData">
		insert into tbl_customer_data
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="username != null">
				username,
			</if>
			<if test="realname != null">
				realname,
			</if>
			<if test="role != null">
				role,
			</if>
			<if test="price != null">
				price,
			</if>
			<if test="productExplain != null">
				productExplain,
			</if>
			<if test="wangwang != null">
				wangwang,
			</if>
			<if test="isBuy != null">
				isBuy,
			</if>
			<if test="commentSelf != null">
				commentSelf,
			</if>
			<if test="createBy != null">
				createBy,
			</if>
			createDate,
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="username != null">
				#{username,jdbcType=VARCHAR},
			</if>
			<if test="realname != null">
				#{realname,jdbcType=VARCHAR},
			</if>
			<if test="role != null">
				#{role,jdbcType=VARCHAR},
			</if>
			<if test="price != null">
				#{price,jdbcType=DOUBLE},
			</if>
			<if test="productExplain != null">
				#{productExplain,jdbcType=VARCHAR},
			</if>
			<if test="wangwang != null">
				#{wangwang,jdbcType=VARCHAR},
			</if>
			<if test="isBuy != null">
				#{isBuy,jdbcType=VARCHAR},
			</if>
			<if test="commentSelf != null">
				#{commentSelf,jdbcType=VARCHAR},
			</if>
			<if test="createBy != null">
				#{createBy,jdbcType=VARCHAR},
			</if>
			now(),
		</trim>
	</insert>

	<update id="updateCustomerDataById" parameterType="CustomerData">
		update tbl_customer_data
		<set>
			<if test="role != null">
				role = #{role,jdbcType=VARCHAR},
			</if>
			<if test="price != null">
				price = #{price,jdbcType=DOUBLE},
			</if>
			<if test="productExplain != null">
				productExplain = #{productExplain,jdbcType=VARCHAR},
			</if>
			<if test="wangwang != null">
				wangwang = #{wangwang,jdbcType=VARCHAR},
			</if>
			<if test="commentSelf != null">
				commentSelf = #{commentSelf,jdbcType=VARCHAR},
			</if>
			<if test="updateBy != null">
				updateBy = #{updateBy,jdbcType=VARCHAR},
			</if>
			updateDate = now(),
		</set>
		where id = #{id,jdbcType=INTEGER}
	</update>
	
	<!-- 修改店长评语 -->
	<update id="updateCommentManager" parameterType="CustomerData">
		UPDATE 
		  	tbl_customer_data 
		SET
		  	commentManager = #{commentManager}, commentDate = now()
		WHERE 
		  	id = #{id} 
	</update>
	
	<delete id="deleteCustomerDataById" parameterType="java.lang.Integer">
		delete from tbl_customer_data
		where id = #{id,jdbcType=INTEGER}
	</delete>
	
	<!-- 查询7天内的数据 -->
	<select id="getProductExplain" parameterType="String" resultType="String">
	 	SELECT 
		  	remark
		FROM
		  	tbl_quote_data 
		WHERE 
			<![CDATA[ DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= DATE(quoteTime) ]]>
		AND 
			username = #{username}	
		AND 
			remark LIKE '%${productExplain}%' 
		ORDER BY id DESC 
  	</select>
</mapper>