SalesDao.xml 2.4 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.SalesDao">
	<select id="getSalesList" resultType="com.w1hd.zzhnc.vo.Sales_Vo">
		select a.*,b.name as projectname from sales a
		LEFT JOIN projects b on
		a.projectId=b.id
		where a.deleted=0
		<if test="projectid != null and projectid>0">
			and a.projectid=#{projectid}
		</if>
		<if test="isvanker != null">
			and a.isvanker=#{isvanker}
		</if>
		<if test="keyword !=null and keyword!='' ">
			and (a.name like CONCAT(CONCAT('%',#{keyword}),'%')
			or
			a.phone like CONCAT(CONCAT('%',#{keyword}),'%')
			or b.name like
			CONCAT(CONCAT('%',#{keyword}),'%'))
		</if>
		order by a.updatedtime desc
		limit #{0},#{1}
	</select>
	<select id="getSalesCount" resultType="java.lang.Integer">
		select count(a.id) from sales a
		LEFT JOIN projects b on
		a.projectId=b.id
		where a.deleted=0
		<if test="projectid != null and projectid>0">
			and a.projectid=#{projectid}
		</if>
		<if test="isvanker != null">
			and a.isvanker=#{isvanker}
		</if>
		<if test="keyword !=null and keyword!='' ">
			and (a.name like CONCAT(CONCAT('%',#{keyword}),'%')
			or
			a.phone like CONCAT(CONCAT('%',#{keyword}),'%')
			or b.name like
			CONCAT(CONCAT('%',#{keyword}),'%'))
		</if>
	</select>
	<select id="getSalesReportList" resultType="com.w1hd.zzhnc.vo.SalesReport_Vo">
		select a.id,a.name,e.name as projectname,
		IFNULL(b.fanscount,0) as fanscount,
		IFNULL(c.callcount,0)as callcount,
		IFNULL(d.chatcount,0)as chatcount 
		from sales a
		left join(
		  select count(id) as fanscount,salesid from fans group by salesId
		) as b on a.id=b.salesid
		left JOIN(
		  select count(id) callcount,salesid from calllog GROUP BY salesid
		)as c on a.id=c.salesid
		left join(
		  select count(id) chatcount,salesid from chatlog GROUP BY salesid
		)as d on a.id=d.salesid
		left join projects as e on a.projectId=e.id
		where a.deleted=0
		<if test="keyword !=null and keyword!='' ">
			and (a.name like CONCAT(CONCAT('%',#{keyword}),'%'))
		</if>
		ORDER BY d.chatcount desc,b.fanscount desc
		limit #{0},#{1}	
	</select>
	
	<select id="getSalesReportCount" resultType="java.lang.Integer">
	  select count(a.id) from sales  a
	  where a.deleted=0
	  <if test="keyword !=null and keyword!='' ">
			and (a.name like CONCAT(CONCAT('%',#{keyword}),'%'))
	  </if>
    </select>
</mapper>