审计记录

WebContent/WEB-INF/classes/mapper/ChatlogDao.xml 5.2 KB
zxt@theyeasy.com committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
<?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>