ChatlogDao.xml 5.2 KB
<?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.w1hd.zzhnc.dao.ChatlogDao">
	<select id="getChatlogList" resultType="com.w1hd.zzhnc.vo.Chatlog_Vo">
		select a.*,b.nickName,b.logo,c.name as salename,c.isvanker from
		chatlog a
		left join fans b on a.fansid=b.id
		left join sales c on
		a.salesid=c.id
		<where>
			<if test="replytype != null and replytype>0">
				and a.replytype=#{replytype}
			</if>
			<if test="keyword !=null and keyword!='' ">
				and (a.ask like CONCAT(CONCAT('%',#{keyword}),'%')
				or
				a.reply like CONCAT(CONCAT('%',#{keyword}),'%')
				or b.nickname like
				CONCAT(CONCAT('%',#{keyword}),'%')
				or c.name like
				CONCAT(CONCAT('%',#{keyword}),'%'))
			</if>
			<if test="date1 != null and date1!=''">
				and a.askTime <![CDATA[ >=  ]]>
				#{date1}
			</if>
			<if test="date2 != null and date2!=''">
				and a.askTime <![CDATA[ <=  ]]>
				#{date2}
			</if>
		</where>
		order by a.askTime desc
		limit #{0},#{1}
	</select>

	<select id="getChatlogCount" resultType="java.lang.Integer">
		select count(a.id) from
		chatlog a
		left join fans b on a.fansid=b.id
		left
		join sales c on a.salesid=c.id
		<where>
			<if test="replytype != null and replytype>0">
				and a.replytype=#{replytype}
			</if>
			<if test="keyword !=null and keyword!='' ">
				and (a.ask like CONCAT(CONCAT('%',#{keyword}),'%')
				or
				a.reply like CONCAT(CONCAT('%',#{keyword}),'%')
				or b.nickname like
				CONCAT(CONCAT('%',#{keyword}),'%')
				or c.name like
				CONCAT(CONCAT('%',#{keyword}),'%'))
			</if>
			<if test="date1 != null and date1!=''">
				and a.askTime <![CDATA[ >=  ]]>
				#{date1}
			</if>
			<if test="date2 != null and date2!=''">
				and a.askTime <![CDATA[ <=  ]]>
				#{date2}
			</if>
		</where>
	</select>

	<select id="getChatLogListBySalesId" resultType="com.w1hd.zzhnc.vo.Chatlog_Vo">
		<!-- select a.*,b.nickName,b.logo,c.name as salename,c.isvanker from
		chatlog a
		left join fans b on a.fansid=b.id
		left join sales c on
		a.salesid=c.id -->
		select a.* FROM chatlog a 
		<where>
			1=1
			<if test="ids != null">
				and a.salesid in
				<foreach item="item" collection="ids" separator="," open="("
					close=")" index="">
					#{item, jdbcType=NUMERIC}
				</foreach>
			</if>
			<if test="fansid != null ">
				and a.fansid = #{fansid}

			</if>
		</where>
		ORDER BY a.id desc
		limit #{0},#{1}
	</select>

	<select id="getChatlogCountBySalesId" resultType="java.lang.Integer">
		select count(a.id) from
		chatlog a
		<where>
			1=1
			<if test="salesid != null">
				and salesid = #{salesid}
			</if>
			<if test="fansid != null and fansid>0">
				and a.fansid=#{fansid}
			</if>
			and a.readed = 1
		</where>
	</select>

	<select id="getChatFansIdBySalesId" resultType="java.lang.Integer">

		SELECT DISTINCT fansid FROM chatlog
		<where>
			1=1
			<if test="salesid != null">
				and salesid = #{salesid}
			</if>
		</where>
	</select>

	<select id="getChatListDistinctFansIdIn" resultType="com.w1hd.zzhnc.vo.ChatLog_DistinctFansIdVO">
		select
		a.fansid,b.nickname,b.logo,b.salesId,c.num,d.askTime,e.ask,e.reply,e.replyType
		from

		(select distinct fansid from chatlog where salesid IN
		<foreach item="item" collection="ids" separator="," open="("
			close=")" index="">
			#{item, jdbcType=NUMERIC}
		</foreach>
		and ask not like '%进入会话:%' ) a
		left join fans b on a.fansid=b.id
		left join
		(select fansid,count(*) num from chatlog
		where salesid IN
		<foreach item="item" collection="ids" separator="," open="("
			close=")" index="">
			#{item, jdbcType=NUMERIC}
		</foreach>
		and readed=0 group by fansid ) c on
		a.fansid=c.fansid
		left join
		( select fansid,substring_index(group_concat(asktime order by asktime
		desc),",",1) as asktime from chatlog group by fansid) d on
		a.fansid=d.fansid
		left join chatlog e on d.fansid=e.fansid and d.askTime=e.askTime
		order by d.askTime desc
	</select>

	<select id="getFansListForSale" resultType="com.w1hd.zzhnc.vo.ChatLog_DistinctFansIdVO">
		 select a.fansid,b.nickname,b.logo,b.salesId,c.num,a.askTime,d.ask,d.reply,d.replyType
			from
	        (select fansid,max(askTime) as askTime  from chatlog where salesid =#{salesid} and replyType > 0 group by fansid) a
	        left join fans b on a.fansid=b.id
	        left join (select fansid,count(*) num from chatlog where salesid =#{salesid} and readed=0 and replyType>0 group by fansid) c on a.fansid=c.fansid
			left join chatlog d on a.fansid=d.fansid and a.askTime=d.askTime and d.replyType > 0
		order by d.askTime desc;
	</select>
	
	<select id="getFansListForVanker" resultType="com.w1hd.zzhnc.vo.ChatLog_DistinctFansIdVO">
		 select a.fansid,b.nickname,b.logo,b.salesId,c.num,a.askTime,d.ask,d.reply,d.replyType
			from
	        (select fansid,max(askTime) as askTime  from chatlog where salesid in (#{salesid},0) and replyType > 0 group by fansid) a
	        left join fans b on a.fansid=b.id
	        left join (select fansid,count(*) num from chatlog where salesid in (#{salesid},0) and readed=0 and replyType>0 group by fansid) c on a.fansid=c.fansid
			left join chatlog d on a.fansid=d.fansid and a.askTime=d.askTime and d.replyType > 0
		order by d.askTime desc;
	</select>
</mapper>