CustomerLabelDemoMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 (
  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="secondBeginDate != null and beginDate != ''"><!-- 开始时间检索 -->
  126. AND date_format(created_date,'%Y-%m-%d %H:%i:%s') &gt;= date_format(#{secondBeginDate},'%Y-%m-%d %H:%i:%s')
  127. </if>
  128. <if test="secondEndDate != null and secondEndDate != ''"><!-- 结束时间检索 -->
  129. AND date_format(created_date,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{secondEndDate},'%Y-%m-%d %H:%i:%s')
  130. </if>
  131. group by consumer_id,p.station_id,a.mobile_phone,blog_nick_name
  132. ORDER BY create_date desc) zh
  133. left join customer_label l on zh.station_id = l.station_id and zh.phone = l.phone and l.del_flag ="0"
  134. left join label_rule r on r.id = l.label_id
  135. where 1=1
  136. <if test="labelId != null "> and l.label_id = #{labelId}</if>
  137. <if test="stationId != null "> and zh.station_id = #{stationId}</if>
  138. <if test="secondStartCountNum != null "> and zh.count_num > #{secondStartCountNum}</if>
  139. <if test="secondEndCountNum != null "> and zh.count_num &lt;=#{secondEndCountNum} </if>
  140. <if test="secondAmtFlag != null and secondAmtFlag=='2'.toString() ">
  141. <choose>
  142. <when test="secondStartAmt != null and secondEndAmt != null">
  143. and ( zh.amt > #{secondStartAmt} and zh.amt &lt;= #{secondEndAmt})
  144. </when>
  145. <when test="secondStartAmt != null and secondEndAmt == null">
  146. and zh.amt > #{secondStartAmt}
  147. </when>
  148. <when test="secondEndAmt != null and secondStartAmt == null">
  149. and zh.amt &lt;= #{secondEndAmt}
  150. </when>
  151. <otherwise>
  152. </otherwise>
  153. </choose>
  154. </if>
  155. <if test="secondAmtFlag != null and secondAmtFlag=='1'.toString() ">
  156. <choose>
  157. <when test="secondStartAmt != null and secondEndAmt != null">
  158. or ( zh.amt > #{secondStartAmt} and zh.amt &lt;=#{secondEndAmt})
  159. </when>
  160. <when test="secondStartAmt != null and secondEndAmt == null">
  161. or zh.amt > #{secondStartAmt}
  162. </when>
  163. <when test="secondEndAmt != null and startAmt == null">
  164. or zh.amt &lt;= #{secondEndAmt}
  165. </when>
  166. <otherwise>
  167. </otherwise>
  168. </choose>
  169. </if>
  170. <if test="secondLitersFlag != null and secondLitersFlag=='2'.toString() ">
  171. <choose>
  172. <when test="secondStartLiters != null and secondEndLiters != null">
  173. and ( zh.order_liters > #{secondStartLiters} and zh.order_liters &lt;= #{secondEndLiters})
  174. </when>
  175. <when test="secondStartLiters != null and secondEndLiters == null">
  176. and zh.order_liters > #{secondStartLiters}
  177. </when>
  178. <when test="secondEndLiters != null and secondStartLiters == null">
  179. and zh.order_liters &lt;= #{secondEndLiters}
  180. </when>
  181. <otherwise>
  182. </otherwise>
  183. </choose>
  184. </if>
  185. <if test="secondLitersFlag != null and secondLitersFlag=='1'.toString() ">
  186. <choose>
  187. <when test="secondStartLiters != null and secondEndLiters != null">
  188. or ( zh.order_liters > #{secondStartLiters} and zq.order_liters &lt;= #{secondEndLiters})
  189. </when>
  190. <when test="secondStartLiters != null and secondEndLiters == null">
  191. or zh.order_liters > #{secondStartLiters}
  192. </when>
  193. <when test="secondEndLiters != null and secondStartLiters == null">
  194. or zh.order_liters &lt;= #{secondEndLiters}
  195. </when>
  196. <otherwise>
  197. </otherwise>
  198. </choose>
  199. </if>
  200. and zh.phone in (
  201. SELECT zq.phone from (
  202. SELECT consumer_id,sum(order_liters) order_liters,count(1) count_num,sum(amt) as amt,p.station_id,max(created_date) created_date,
  203. a.mobile_phone as phone,blog_nick_name as customer_name
  204. from pay_order p
  205. join app_user_info a on a.user_id = p.consumer_id
  206. where p.status ="1"
  207. <if test="stationId != null "> and p.station_id = #{stationId}</if>
  208. <if test="oilName != null "> and oil_name = #{oilName} </if>
  209. <if test="beginDate != null and beginDate != ''"><!-- 开始时间检索 -->
  210. AND date_format(created_date,'%Y-%m-%d %H:%i:%s') &gt;= date_format(#{beginDate},'%Y-%m-%d %H:%i:%s')
  211. </if>
  212. <if test="endDate != null and endDate != ''"><!-- 结束时间检索 -->
  213. AND date_format(created_date,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{endDate},'%Y-%m-%d %H:%i:%s')
  214. </if>
  215. group by consumer_id,p.station_id,a.mobile_phone,blog_nick_name
  216. ORDER BY created_date desc) zq
  217. left join customer_label l on zq.station_id = l.station_id and zq.phone = l.phone and l.del_flag ="0"
  218. left join label_rule r on r.id = l.label_id
  219. <where>
  220. <if test="labelId != null "> and l.label_id = #{labelId}</if>
  221. <if test="stationId != null "> and zq.station_id = #{stationId}</if>
  222. <if test="startCountNum != null "> and zq.count_num >= #{startCountNum}</if>
  223. <if test="endCountNum != null "> and zq.count_num &lt; #{endCountNum}</if>
  224. <if test="amtFlag != null and amtFlag=='2'.toString() ">
  225. <choose>
  226. <when test="startAmt != null and endAmt != null">
  227. and ( zq.amt >= #{startAmt} and zq.amt &lt; #{endAmt})
  228. </when>
  229. <when test="startAmt != null and endAmt == null">
  230. and zq.amt >= #{startAmt}
  231. </when>
  232. <when test="endAmt != null and startAmt == null">
  233. and zq.amt &lt; #{endAmt}
  234. </when>
  235. <otherwise>
  236. </otherwise>
  237. </choose>
  238. </if>
  239. <if test="amtFlag != null and amtFlag=='1'.toString() ">
  240. <choose>
  241. <when test="startAmt != null and endAmt != null">
  242. or ( zq.amt >= #{startAmt} and zq.amt &lt; #{endAmt})
  243. </when>
  244. <when test="startAmt != null and endAmt == null">
  245. or zq.amt >= #{startAmt}
  246. </when>
  247. <when test="endAmt != null and startAmt == null">
  248. or zq.amt &lt; #{endAmt}
  249. </when>
  250. <otherwise>
  251. </otherwise>
  252. </choose>
  253. </if>
  254. <if test="litersFlag != null and litersFlag=='2'.toString() ">
  255. <choose>
  256. <when test="startLiters != null and endLiters != null">
  257. and ( zq.order_liters >= #{startLiters} and zq.order_liters &lt; #{endLiters})
  258. </when>
  259. <when test="startLiters != null and endLiters == null">
  260. and zq.order_liters >= #{startLiters}
  261. </when>
  262. <when test="endLiters != null and startLiters == null">
  263. and zq.order_liters &lt; #{endLiters}
  264. </when>
  265. <otherwise>
  266. </otherwise>
  267. </choose>
  268. </if>
  269. <if test="litersFlag != null and litersFlag=='1'.toString() ">
  270. <choose>
  271. <when test="startLiters != null and endLiters != null">
  272. or ( zq.order_liters >= #{startLiters} and zq.order_liters &lt; #{endLiters})
  273. </when>
  274. <when test="startLiters != null and endLiters == null">
  275. or zq.order_liters >= #{startLiters}
  276. </when>
  277. <when test="endLiters != null and startLiters == null">
  278. or zq.order_liters &lt; #{endLiters}
  279. </when>
  280. <otherwise>
  281. </otherwise>
  282. </choose>
  283. </if>
  284. </where> )
  285. </select>
  286. </mapper>