CustomerLabelDemoMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.yijia.label.mapper.CustomerLabelDemoMapper">
  6. <resultMap type="CustomerLabelDemo" id="CustomerLabelDemoResult">
  7. <result property="id" column="id" />
  8. <result property="phone" column="phone" />
  9. <result property="stationId" column="station_id" />
  10. <result property="customerName" column="customer_name" />
  11. <result property="labelName" column="label_name" />
  12. <result property="labelId" column="label_id" />
  13. <result property="createDate" column="create_date" />
  14. </resultMap>
  15. <select id="selectCustomerLabelDemoList" parameterType="CustomerLabelDemo" resultMap="CustomerLabelDemoResult">
  16. SELECT zq.*,r.label_name,r.id as label_id from (
  17. 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,
  18. a.mobile_phone as phone,blog_nick_name as customer_name
  19. from pay_order p
  20. join app_user_info a on a.user_id = p.consumer_id
  21. where p.status ="1"
  22. <if test="stationId != null "> and p.station_id = #{stationId}</if>
  23. <if test="oilName != null "> and oil_name = #{oilName} </if>
  24. <if test="beginDate != null and beginDate != ''"><!-- 开始时间检索 -->
  25. AND date_format(created_date,'%Y-%m-%d %H:%i:%s') &gt;= date_format(#{beginDate},'%Y-%m-%d %H:%i:%s')
  26. </if>
  27. <if test="endDate != null and endDate != ''"><!-- 结束时间检索 -->
  28. AND date_format(created_date,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{endDate},'%Y-%m-%d %H:%i:%s')
  29. </if>
  30. group by consumer_id,p.station_id,a.mobile_phone,blog_nick_name
  31. ORDER BY create_date desc) zq
  32. left join customer_label l on zq.station_id = l.station_id and zq.phone = l.phone and l.del_flag ="0"
  33. left join label_rule r on r.id = l.label_id and r.del_flag ="0"
  34. <where>
  35. <if test="labelId != null "> and l.label_id >= #{labelId}</if>
  36. <if test="startCountNum != null "> and zq.count_num >= #{startCountNum}</if>
  37. <if test="endCountNum != null "> and zq.count_num &lt; #{endCountNum}</if>
  38. <if test="amtFlag != null and amtFlag=='2'.toString()">
  39. <choose>
  40. <when test="startAmt != null and endAmt != null">
  41. and ( zq.amt >= #{startAmt} and zq.amt &lt; #{endAmt})
  42. </when>
  43. <when test="startAmt != null and endAmt == null">
  44. and zq.amt >= #{startAmt}
  45. </when>
  46. <when test="endAmt != null and startAmt == null">
  47. and zq.amt &lt; #{endAmt}
  48. </when>
  49. <otherwise>
  50. </otherwise>
  51. </choose>
  52. </if>
  53. <if test="amtFlag != null and amtFlag=='1'.toString() ">
  54. <choose>
  55. <when test="startAmt != null and endAmt != null">
  56. or ( zq.amt >= #{startAmt} and zq.amt &lt; #{endAmt})
  57. </when>
  58. <when test="startAmt != null and endAmt == null">
  59. or zq.amt >= #{startAmt}
  60. </when>
  61. <when test="endAmt != null and startAmt == null">
  62. or zq.amt &lt; #{endAmt}
  63. </when>
  64. <otherwise>
  65. </otherwise>
  66. </choose>
  67. </if>
  68. <if test="litersFlag != null and litersFlag=='2'.toString() ">
  69. <choose>
  70. <when test="startLiters != null and endLiters != null">
  71. and ( zq.order_liters >= #{startLiters} and zq.order_liters &lt; #{endLiters})
  72. </when>
  73. <when test="startLiters != null and endLiters == null">
  74. and zq.order_liters >= #{startLiters}
  75. </when>
  76. <when test="endLiters != null and startLiters == null">
  77. and zq.order_liters &lt; #{endLiters}
  78. </when>
  79. <otherwise>
  80. </otherwise>
  81. </choose>
  82. </if>
  83. <if test="litersFlag != null and litersFlag=='1'.toString() ">
  84. <choose>
  85. <when test="startLiters != null and endLiters != null">
  86. or ( zq.order_liters >= #{startLiters} and zq.order_liters &lt; #{endLiters})
  87. </when>
  88. <when test="startLiters != null and endLiters == null">
  89. or zq.order_liters >= #{startLiters}
  90. </when>
  91. <when test="endLiters != null and startLiters == null">
  92. or zq.order_liters &lt; #{endLiters}
  93. </when>
  94. <otherwise>
  95. </otherwise>
  96. </choose>
  97. </if>
  98. </where>
  99. </select>
  100. <select id="selectPhoneCustomerLabelList" parameterType="CustomerLabelDemo" resultMap="CustomerLabelDemoResult">
  101. SELECT id,phone,label_id,station_id from customer_label
  102. <where>
  103. <if test="stationId != null "> and station_id = #{stationId}</if>
  104. <if test="labelId != null "> and label_id = #{labelId}</if>
  105. <if test="delFlag != null "> and del_flag = #{delFlag}</if>
  106. <if test="phone != null and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
  107. <if test="phoneList != null ">
  108. and phone in
  109. <foreach item="item" index="index" collection="phoneList"
  110. open="(" separator="," close=")">
  111. #{item}
  112. </foreach>
  113. </if>
  114. </where>
  115. </select>
  116. <select id="secondCustomerLabelDemoList" parameterType="CustomerLabelDemo" resultMap="CustomerLabelDemoResult">
  117. SELECT zh.*,r.label_name,r.id as label_id from (select * from (
  118. 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,
  119. a.mobile_phone as phone,blog_nick_name as customer_name
  120. from pay_order p
  121. join app_user_info a on a.user_id = p.consumer_id
  122. where `status` = "1"
  123. <if test="stationId != null "> and p.station_id = #{stationId}</if>
  124. <if test="oilName != null "> and oil_name = #{oilName} </if>
  125. <if test="secondEndCountNum != 0 and secondEndAmt!=0 and secondEndLiters!=0 ">
  126. <if test="secondBeginDate != null and secondBeginDate != ''"><!-- 开始时间检索 -->
  127. and date_format(created_date,'%Y-%m-%d %H:%i:%s') &gt;= date_format(#{secondBeginDate},'%Y-%m-%d %H:%i:%s')
  128. </if>
  129. <if test="secondEndDate != null and secondEndDate != ''"><!-- 结束时间检索 -->
  130. AND date_format(created_date,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{secondEndDate},'%Y-%m-%d %H:%i:%s')
  131. </if>
  132. </if>
  133. group by consumer_id,p.station_id,a.mobile_phone,blog_nick_name ) ff where 1=1
  134. <if test="secondEndCountNum == 0 and (secondStartCountNum=='' or secondStartCountNum==null ) and secondEndAmt !=0 and secondEndLiters!=0">
  135. <if test="secondBeginDate != null and secondEndDate!=null "><!-- 开始时间检索 -->
  136. and (date_format(create_date,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{secondBeginDate},'%Y-%m-%d %H:%i:%s')
  137. or date_format(create_date,'%Y-%m-%d %H:%i:%s') >= date_format(#{secondEndDate},'%Y-%m-%d %H:%i:%s'))
  138. </if>
  139. </if>
  140. <if test="secondEndAmt==0 and (secondStartAmt==null or secondStartAmt=='') and secondEndCountNum != 0 and secondEndLiters!=0">
  141. <if test="secondBeginDate != null and secondEndDate!=null "><!-- 开始时间检索 -->
  142. and (date_format(create_date,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{secondBeginDate},'%Y-%m-%d %H:%i:%s')
  143. or date_format(create_date,'%Y-%m-%d %H:%i:%s') >= date_format(#{secondEndDate},'%Y-%m-%d %H:%i:%s'))
  144. </if>
  145. </if>
  146. <if test="secondEndLiters==0 and (secondStartLiters==null or secondStartLiters=='') and secondEndAmt!=0 and secondEndCountNum != 0 ">
  147. <if test="secondBeginDate != null and secondEndDate!=null "><!-- 开始时间检索 -->
  148. and (ff.date_format(create_date,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{secondBeginDate},'%Y-%m-%d %H:%i:%s')
  149. or date_format(create_date,'%Y-%m-%d %H:%i:%s') >= date_format(#{secondEndDate},'%Y-%m-%d %H:%i:%s'))
  150. </if>
  151. </if>
  152. ORDER BY create_date desc) zh
  153. left join customer_label l on zh.station_id = l.station_id and zh.phone = l.phone and l.del_flag ="0"
  154. left join label_rule r on r.id = l.label_id
  155. where 1=1
  156. <if test="labelId != null "> and l.label_id = #{labelId}</if>
  157. <if test="stationId != null "> and zh.station_id = #{stationId}</if>
  158. <if test="secondStartCountNum != null "> and zh.count_num > #{secondStartCountNum}</if>
  159. <if test="secondEndCountNum != null and secondEndCountNum !=0"> and zh.count_num &lt;=#{secondEndCountNum} </if>
  160. <if test="!(secondEndAmt==0 and (secondStartAmt==null or secondStartAmt=='') ) ">
  161. <if test="secondAmtFlag != null and secondAmtFlag=='2'.toString() ">
  162. <choose>
  163. <when test="secondStartAmt != null and secondEndAmt != null">
  164. and ( zh.amt > #{secondStartAmt} and zh.amt &lt;= #{secondEndAmt})
  165. </when>
  166. <when test="secondStartAmt != null and secondEndAmt == null">
  167. and zh.amt > #{secondStartAmt}
  168. </when>
  169. <when test="secondEndAmt != null and secondStartAmt == null">
  170. and zh.amt &lt;= #{secondEndAmt}
  171. </when>
  172. <otherwise>
  173. </otherwise>
  174. </choose>
  175. </if>
  176. <if test="secondAmtFlag != null and secondAmtFlag=='1'.toString() ">
  177. <choose>
  178. <when test="secondStartAmt != null and secondEndAmt != null">
  179. or ( zh.amt > #{secondStartAmt} and zh.amt &lt;=#{secondEndAmt})
  180. </when>
  181. <when test="secondStartAmt != null and secondEndAmt == null">
  182. or zh.amt > #{secondStartAmt}
  183. </when>
  184. <when test="secondEndAmt != null and startAmt == null">
  185. or zh.amt &lt;= #{secondEndAmt}
  186. </when>
  187. <otherwise>
  188. </otherwise>
  189. </choose>
  190. </if>
  191. </if>
  192. <if test="!(secondEndLiters==0 and (secondStartLiters==null or secondStartLiters=='') ) ">
  193. <if test="secondLitersFlag != null and secondLitersFlag=='2'.toString() ">
  194. <choose>
  195. <when test="secondStartLiters != null and secondEndLiters != null">
  196. and ( zh.order_liters > #{secondStartLiters} and zh.order_liters &lt;= #{secondEndLiters})
  197. </when>
  198. <when test="secondStartLiters != null and secondEndLiters == null">
  199. and zh.order_liters > #{secondStartLiters}
  200. </when>
  201. <when test="secondEndLiters != null and secondStartLiters == null">
  202. and zh.order_liters &lt;= #{secondEndLiters}
  203. </when>
  204. <otherwise>
  205. </otherwise>
  206. </choose>
  207. </if>
  208. <if test="secondLitersFlag != null and secondLitersFlag=='1'.toString() ">
  209. <choose>
  210. <when test="secondStartLiters != null and secondEndLiters != null">
  211. or ( zh.order_liters > #{secondStartLiters} and zq.order_liters &lt;= #{secondEndLiters})
  212. </when>
  213. <when test="secondStartLiters != null and secondEndLiters == null">
  214. or zh.order_liters > #{secondStartLiters}
  215. </when>
  216. <when test="secondEndLiters != null and secondStartLiters == null">
  217. or zh.order_liters &lt;= #{secondEndLiters}
  218. </when>
  219. <otherwise>
  220. </otherwise>
  221. </choose>
  222. </if>
  223. </if>
  224. and zh.phone in (
  225. SELECT zq.phone from (select * from (
  226. SELECT consumer_id,sum(order_liters) order_liters,count(1) count_num,sum(amt) as amt,p.station_id,max(created_date) created_date,
  227. a.mobile_phone as phone,blog_nick_name as customer_name
  228. from pay_order p
  229. join app_user_info a on a.user_id = p.consumer_id
  230. where p.status ="1"
  231. <if test="stationId != null "> and p.station_id = #{stationId}</if>
  232. <if test="oilName != null "> and oil_name = #{oilName} </if>
  233. <if test="beginDate != null and beginDate != ''"><!-- 开始时间检索 -->
  234. and date_format(created_date,'%Y-%m-%d %H:%i:%s') &gt;= date_format(#{beginDate},'%Y-%m-%d %H:%i:%s')
  235. </if>
  236. <if test="endDate != null and endDate != ''"><!-- 结束时间检索 -->
  237. AND date_format(created_date,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{endDate},'%Y-%m-%d %H:%i:%s')
  238. </if>
  239. group by consumer_id,p.station_id,a.mobile_phone,blog_nick_name) ffmm
  240. ORDER BY created_date desc) zq
  241. left join customer_label l on zq.station_id = l.station_id and zq.phone = l.phone and l.del_flag ="0"
  242. left join label_rule r on r.id = l.label_id
  243. <where>
  244. <if test="labelId != null "> and l.label_id = #{labelId}</if>
  245. <if test="stationId != null "> and zq.station_id = #{stationId}</if>
  246. <if test="startCountNum != null "> and zq.count_num >= #{startCountNum}</if>
  247. <if test="endCountNum != null "> and zq.count_num &lt; #{endCountNum}</if>
  248. <if test="amtFlag != null and amtFlag=='2'.toString() ">
  249. <choose>
  250. <when test="startAmt != null and endAmt != null">
  251. and ( zq.amt >= #{startAmt} and zq.amt &lt; #{endAmt})
  252. </when>
  253. <when test="startAmt != null and endAmt == null">
  254. and zq.amt >= #{startAmt}
  255. </when>
  256. <when test="endAmt != null and startAmt == null">
  257. and zq.amt &lt; #{endAmt}
  258. </when>
  259. <otherwise>
  260. </otherwise>
  261. </choose>
  262. </if>
  263. <if test="amtFlag != null and amtFlag=='1'.toString() ">
  264. <choose>
  265. <when test="startAmt != null and endAmt != null">
  266. or ( zq.amt >= #{startAmt} and zq.amt &lt; #{endAmt})
  267. </when>
  268. <when test="startAmt != null and endAmt == null">
  269. or zq.amt >= #{startAmt}
  270. </when>
  271. <when test="endAmt != null and startAmt == null">
  272. or zq.amt &lt; #{endAmt}
  273. </when>
  274. <otherwise>
  275. </otherwise>
  276. </choose>
  277. </if>
  278. <if test="litersFlag != null and litersFlag=='2'.toString() ">
  279. <choose>
  280. <when test="startLiters != null and endLiters != null">
  281. and ( zq.order_liters >= #{startLiters} and zq.order_liters &lt; #{endLiters})
  282. </when>
  283. <when test="startLiters != null and endLiters == null">
  284. and zq.order_liters >= #{startLiters}
  285. </when>
  286. <when test="endLiters != null and startLiters == null">
  287. and zq.order_liters &lt; #{endLiters}
  288. </when>
  289. <otherwise>
  290. </otherwise>
  291. </choose>
  292. </if>
  293. <if test="litersFlag != null and litersFlag=='1'.toString() ">
  294. <choose>
  295. <when test="startLiters != null and endLiters != null">
  296. or ( zq.order_liters >= #{startLiters} and zq.order_liters &lt; #{endLiters})
  297. </when>
  298. <when test="startLiters != null and endLiters == null">
  299. or zq.order_liters >= #{startLiters}
  300. </when>
  301. <when test="endLiters != null and startLiters == null">
  302. or zq.order_liters &lt; #{endLiters}
  303. </when>
  304. <otherwise>
  305. </otherwise>
  306. </choose>
  307. </if>
  308. </where> )
  309. </select>
  310. </mapper>