123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- <?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.yijia.label.mapper.CustomerLabelDemoMapper">
- <resultMap type="CustomerLabelDemo" id="CustomerLabelDemoResult">
- <result property="id" column="id" />
- <result property="phone" column="phone" />
- <result property="stationId" column="station_id" />
- <result property="customerName" column="customer_name" />
- <result property="labelName" column="label_name" />
- <result property="labelId" column="label_id" />
- <result property="createDate" column="create_date" />
- </resultMap>
- <select id="selectCustomerLabelDemoList" parameterType="CustomerLabelDemo" resultMap="CustomerLabelDemoResult">
- SELECT zq.*,r.label_name,r.id as label_id from (
- SELECT consumer_id,sum(order_liters) order_liters,sum(amt) as amt,count(1) count_num,p.station_id,max(created_date) as create_date,
- a.mobile_phone as phone,blog_nick_name as customer_name
- from pay_order p
- join app_user_info a on a.user_id = p.consumer_id
- where p.status ="1"
- <if test="stationId != null "> and p.station_id = #{stationId}</if>
- <if test="oilName != null "> and oil_name = #{oilName} </if>
- <if test="beginDate != null and beginDate != ''"><!-- 开始时间检索 -->
- AND date_format(created_date,'%Y-%m-%d %H:%i:%s') >= date_format(#{beginDate},'%Y-%m-%d %H:%i:%s')
- </if>
- <if test="endDate != null and endDate != ''"><!-- 结束时间检索 -->
- AND date_format(created_date,'%Y-%m-%d %H:%i:%s') <= date_format(#{endDate},'%Y-%m-%d %H:%i:%s')
- </if>
- group by consumer_id,p.station_id,a.mobile_phone,blog_nick_name
- ORDER BY create_date desc) zq
- left join customer_label l on zq.station_id = l.station_id and zq.phone = l.phone and l.del_flag ="0"
- left join label_rule r on r.id = l.label_id and r.del_flag ="0"
- <where>
- <if test="labelId != null "> and l.label_id >= #{labelId}</if>
- <if test="startCountNum != null "> and zq.count_num >= #{startCountNum}</if>
- <if test="endCountNum != null "> and zq.count_num < #{endCountNum}</if>
- <if test="amtFlag != null and amtFlag=='2'.toString()">
- <choose>
- <when test="startAmt != null and endAmt != null">
- and ( zq.amt >= #{startAmt} and zq.amt < #{endAmt})
- </when>
- <when test="startAmt != null and endAmt == null">
- and zq.amt >= #{startAmt}
- </when>
- <when test="endAmt != null and startAmt == null">
- and zq.amt < #{endAmt}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </if>
- <if test="amtFlag != null and amtFlag=='1'.toString() ">
- <choose>
- <when test="startAmt != null and endAmt != null">
- or ( zq.amt >= #{startAmt} and zq.amt < #{endAmt})
- </when>
- <when test="startAmt != null and endAmt == null">
- or zq.amt >= #{startAmt}
- </when>
- <when test="endAmt != null and startAmt == null">
- or zq.amt < #{endAmt}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </if>
- <if test="litersFlag != null and litersFlag=='2'.toString() ">
- <choose>
- <when test="startLiters != null and endLiters != null">
- and ( zq.order_liters >= #{startLiters} and zq.order_liters < #{endLiters})
- </when>
- <when test="startLiters != null and endLiters == null">
- and zq.order_liters >= #{startLiters}
- </when>
- <when test="endLiters != null and startLiters == null">
- and zq.order_liters < #{endLiters}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </if>
- <if test="litersFlag != null and litersFlag=='1'.toString() ">
- <choose>
- <when test="startLiters != null and endLiters != null">
- or ( zq.order_liters >= #{startLiters} and zq.order_liters < #{endLiters})
- </when>
- <when test="startLiters != null and endLiters == null">
- or zq.order_liters >= #{startLiters}
- </when>
- <when test="endLiters != null and startLiters == null">
- or zq.order_liters < #{endLiters}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </if>
- </where>
- </select>
- <select id="selectPhoneCustomerLabelList" parameterType="CustomerLabelDemo" resultMap="CustomerLabelDemoResult">
- SELECT id,phone,label_id,station_id from customer_label
- <where>
- <if test="stationId != null "> and station_id = #{stationId}</if>
- <if test="labelId != null "> and label_id = #{labelId}</if>
- <if test="delFlag != null "> and del_flag = #{delFlag}</if>
- <if test="phone != null and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
- <if test="phoneList != null ">
- and phone in
- <foreach item="item" index="index" collection="phoneList"
- open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- </where>
- </select>
- <select id="secondCustomerLabelDemoList" parameterType="CustomerLabelDemo" resultMap="CustomerLabelDemoResult">
- SELECT zh.*,r.label_name,r.id as label_id from (select * from (
- SELECT consumer_id,sum(order_liters) order_liters,sum(amt) as amt,count(1) count_num,p.station_id,max(created_date) as create_date,
- a.mobile_phone as phone,blog_nick_name as customer_name
- from pay_order p
- join app_user_info a on a.user_id = p.consumer_id
- where `status` = "1"
- <if test="stationId != null "> and p.station_id = #{stationId}</if>
- <if test="oilName != null "> and oil_name = #{oilName} </if>
- <if test="secondEndCountNum != 0 and secondEndAmt!=0 and secondEndLiters!=0 ">
- <if test="secondBeginDate != null and secondBeginDate != ''"><!-- 开始时间检索 -->
- and date_format(created_date,'%Y-%m-%d %H:%i:%s') >= date_format(#{secondBeginDate},'%Y-%m-%d %H:%i:%s')
- </if>
- <if test="secondEndDate != null and secondEndDate != ''"><!-- 结束时间检索 -->
- AND date_format(created_date,'%Y-%m-%d %H:%i:%s') <= date_format(#{secondEndDate},'%Y-%m-%d %H:%i:%s')
- </if>
- </if>
- group by consumer_id,p.station_id,a.mobile_phone,blog_nick_name ) ff where 1=1
- <if test="secondEndCountNum == 0 and (secondStartCountNum=='' or secondStartCountNum==null ) and secondEndAmt !=0 and secondEndLiters!=0">
- <if test="secondBeginDate != null and secondEndDate!=null "><!-- 开始时间检索 -->
- and (date_format(create_date,'%Y-%m-%d %H:%i:%s') <= date_format(#{secondBeginDate},'%Y-%m-%d %H:%i:%s')
- or date_format(create_date,'%Y-%m-%d %H:%i:%s') >= date_format(#{secondEndDate},'%Y-%m-%d %H:%i:%s'))
- </if>
- </if>
- <if test="secondEndAmt==0 and (secondStartAmt==null or secondStartAmt=='') and secondEndCountNum != 0 and secondEndLiters!=0">
- <if test="secondBeginDate != null and secondEndDate!=null "><!-- 开始时间检索 -->
- and (date_format(create_date,'%Y-%m-%d %H:%i:%s') <= date_format(#{secondBeginDate},'%Y-%m-%d %H:%i:%s')
- or date_format(create_date,'%Y-%m-%d %H:%i:%s') >= date_format(#{secondEndDate},'%Y-%m-%d %H:%i:%s'))
- </if>
- </if>
- <if test="secondEndLiters==0 and (secondStartLiters==null or secondStartLiters=='') and secondEndAmt!=0 and secondEndCountNum != 0 ">
- <if test="secondBeginDate != null and secondEndDate!=null "><!-- 开始时间检索 -->
- and (ff.date_format(create_date,'%Y-%m-%d %H:%i:%s') <= date_format(#{secondBeginDate},'%Y-%m-%d %H:%i:%s')
- or date_format(create_date,'%Y-%m-%d %H:%i:%s') >= date_format(#{secondEndDate},'%Y-%m-%d %H:%i:%s'))
- </if>
- </if>
- ORDER BY create_date desc) zh
- left join customer_label l on zh.station_id = l.station_id and zh.phone = l.phone and l.del_flag ="0"
- left join label_rule r on r.id = l.label_id
- where 1=1
- <if test="labelId != null "> and l.label_id = #{labelId}</if>
- <if test="stationId != null "> and zh.station_id = #{stationId}</if>
- <if test="secondStartCountNum != null "> and zh.count_num > #{secondStartCountNum}</if>
- <if test="secondEndCountNum != null and secondEndCountNum !=0"> and zh.count_num <=#{secondEndCountNum} </if>
- <if test="!(secondEndAmt==0 and (secondStartAmt==null or secondStartAmt=='') ) ">
- <if test="secondAmtFlag != null and secondAmtFlag=='2'.toString() ">
- <choose>
- <when test="secondStartAmt != null and secondEndAmt != null">
- and ( zh.amt > #{secondStartAmt} and zh.amt <= #{secondEndAmt})
- </when>
- <when test="secondStartAmt != null and secondEndAmt == null">
- and zh.amt > #{secondStartAmt}
- </when>
- <when test="secondEndAmt != null and secondStartAmt == null">
- and zh.amt <= #{secondEndAmt}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </if>
- <if test="secondAmtFlag != null and secondAmtFlag=='1'.toString() ">
- <choose>
- <when test="secondStartAmt != null and secondEndAmt != null">
- or ( zh.amt > #{secondStartAmt} and zh.amt <=#{secondEndAmt})
- </when>
- <when test="secondStartAmt != null and secondEndAmt == null">
- or zh.amt > #{secondStartAmt}
- </when>
- <when test="secondEndAmt != null and startAmt == null">
- or zh.amt <= #{secondEndAmt}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </if>
- </if>
- <if test="!(secondEndLiters==0 and (secondStartLiters==null or secondStartLiters=='') ) ">
- <if test="secondLitersFlag != null and secondLitersFlag=='2'.toString() ">
- <choose>
- <when test="secondStartLiters != null and secondEndLiters != null">
- and ( zh.order_liters > #{secondStartLiters} and zh.order_liters <= #{secondEndLiters})
- </when>
- <when test="secondStartLiters != null and secondEndLiters == null">
- and zh.order_liters > #{secondStartLiters}
- </when>
- <when test="secondEndLiters != null and secondStartLiters == null">
- and zh.order_liters <= #{secondEndLiters}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </if>
- <if test="secondLitersFlag != null and secondLitersFlag=='1'.toString() ">
- <choose>
- <when test="secondStartLiters != null and secondEndLiters != null">
- or ( zh.order_liters > #{secondStartLiters} and zq.order_liters <= #{secondEndLiters})
- </when>
- <when test="secondStartLiters != null and secondEndLiters == null">
- or zh.order_liters > #{secondStartLiters}
- </when>
- <when test="secondEndLiters != null and secondStartLiters == null">
- or zh.order_liters <= #{secondEndLiters}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </if>
- </if>
- and zh.phone in (
- SELECT zq.phone from (select * from (
- SELECT consumer_id,sum(order_liters) order_liters,count(1) count_num,sum(amt) as amt,p.station_id,max(created_date) created_date,
- a.mobile_phone as phone,blog_nick_name as customer_name
- from pay_order p
- join app_user_info a on a.user_id = p.consumer_id
- where p.status ="1"
- <if test="stationId != null "> and p.station_id = #{stationId}</if>
- <if test="oilName != null "> and oil_name = #{oilName} </if>
- <if test="beginDate != null and beginDate != ''"><!-- 开始时间检索 -->
- and date_format(created_date,'%Y-%m-%d %H:%i:%s') >= date_format(#{beginDate},'%Y-%m-%d %H:%i:%s')
- </if>
- <if test="endDate != null and endDate != ''"><!-- 结束时间检索 -->
- AND date_format(created_date,'%Y-%m-%d %H:%i:%s') <= date_format(#{endDate},'%Y-%m-%d %H:%i:%s')
- </if>
- group by consumer_id,p.station_id,a.mobile_phone,blog_nick_name) ffmm
- ORDER BY created_date desc) zq
- left join customer_label l on zq.station_id = l.station_id and zq.phone = l.phone and l.del_flag ="0"
- left join label_rule r on r.id = l.label_id
- <where>
- <if test="labelId != null "> and l.label_id = #{labelId}</if>
- <if test="stationId != null "> and zq.station_id = #{stationId}</if>
- <if test="startCountNum != null "> and zq.count_num >= #{startCountNum}</if>
- <if test="endCountNum != null "> and zq.count_num < #{endCountNum}</if>
- <if test="amtFlag != null and amtFlag=='2'.toString() ">
- <choose>
- <when test="startAmt != null and endAmt != null">
- and ( zq.amt >= #{startAmt} and zq.amt < #{endAmt})
- </when>
- <when test="startAmt != null and endAmt == null">
- and zq.amt >= #{startAmt}
- </when>
- <when test="endAmt != null and startAmt == null">
- and zq.amt < #{endAmt}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </if>
- <if test="amtFlag != null and amtFlag=='1'.toString() ">
- <choose>
- <when test="startAmt != null and endAmt != null">
- or ( zq.amt >= #{startAmt} and zq.amt < #{endAmt})
- </when>
- <when test="startAmt != null and endAmt == null">
- or zq.amt >= #{startAmt}
- </when>
- <when test="endAmt != null and startAmt == null">
- or zq.amt < #{endAmt}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </if>
- <if test="litersFlag != null and litersFlag=='2'.toString() ">
- <choose>
- <when test="startLiters != null and endLiters != null">
- and ( zq.order_liters >= #{startLiters} and zq.order_liters < #{endLiters})
- </when>
- <when test="startLiters != null and endLiters == null">
- and zq.order_liters >= #{startLiters}
- </when>
- <when test="endLiters != null and startLiters == null">
- and zq.order_liters < #{endLiters}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </if>
- <if test="litersFlag != null and litersFlag=='1'.toString() ">
- <choose>
- <when test="startLiters != null and endLiters != null">
- or ( zq.order_liters >= #{startLiters} and zq.order_liters < #{endLiters})
- </when>
- <when test="startLiters != null and endLiters == null">
- or zq.order_liters >= #{startLiters}
- </when>
- <when test="endLiters != null and startLiters == null">
- or zq.order_liters < #{endLiters}
- </when>
- <otherwise>
- </otherwise>
- </choose>
- </if>
- </where> )
- </select>
- </mapper>
|