CustomerManageMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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.customer.mapper.CustomerManageMapper">
  6. <resultMap type="CustomerManage" id="CustomerManageResult">
  7. <result property="id" column="id" />
  8. <result property="memberId" column="member_id" />
  9. <result property="customerName" column="customer_name" />
  10. <result property="commendMan" column="commend_man" />
  11. <result property="phoneNumber" column="phone_number" />
  12. <result property="carNumber" column="car_number" />
  13. <result property="balance" column="balance" />
  14. <result property="integral" column="integral" />
  15. <result property="specialCarType" column="special_car_type" />
  16. <result property="regtime" column="regtime" />
  17. <result property="stationId" column="station_id" />
  18. <result property="stationName" column="station_name" />
  19. <result property="cyAmt" column="cy_amt" />
  20. <result property="qyAmt" column="qy_amt" />
  21. <result property="minaUserId" column="mina_user_id" />
  22. <result property="oilName" column="oil_name" />
  23. <result property="grade" column="grade" />
  24. <result property="liters" column="liters" />
  25. <result property="amt" column="amt" />
  26. <result property="unionId" column="union_id" />
  27. <result property="payDate" column="pay_date" />
  28. <result property="fyAmt" column="fy_amt" />
  29. <result property="lngAmt" column="lng_amt" />
  30. <result property="cngAmt" column="cng_amt" />
  31. </resultMap>
  32. <sql id="selectCustomerManageVo">
  33. select m.id, m.member_id, m.customer_name, m.commend_man, m.phone_number, m.car_number, m.balance,
  34. m.integral, m.special_car_type, m.regtime, m.station_id, m.mina_user_id, m.oil_name, m.grade,
  35. m.liters, m.amt, m.union_id ,d.dept_name as station_name
  36. from customer_manage m join sys_dept d on m.station_id = d.dept_id
  37. </sql>
  38. <select id="selectCustomerManageList" parameterType="CustomerManage" resultMap="CustomerManageResult">
  39. <include refid="selectCustomerManageVo"/>
  40. <where>
  41. <if test="memberId != null and memberId != ''"> and member_id = #{memberId}</if>
  42. <if test="customerName != null and customerName != ''"> and customer_name like concat('%', #{customerName}, '%')</if>
  43. <if test="commendMan != null and commendMan != ''"> and commend_man = #{commendMan}</if>
  44. <if test="phoneNumber != null and phoneNumber != ''"> and phone_number like concat('%', #{phoneNumber}, '%')</if>
  45. <if test="carNumber != null and carNumber != ''"> and car_number = #{carNumber}</if>
  46. <if test="balance != null "> and m.balance = #{balance}</if>
  47. <if test="integral != null "> and integral = #{integral}</if>
  48. <if test="specialCarType != null and specialCarType != ''"> and special_car_type = #{specialCarType}</if>
  49. <if test="regtime != null "> and regtime = #{regtime}</if>
  50. <if test="stationId != null "> and station_id = #{stationId}</if>
  51. <if test="minaUserId != null "> and mina_user_id = #{minaUserId}</if>
  52. <if test="oilName != null and oilName != ''"> and oil_name like concat('%', #{oilName}, '%')</if>
  53. <if test="grade != null and grade != ''"> and grade like concat('%', #{grade},'%')</if>
  54. <if test="liters != null "> and liters = #{liters}</if>
  55. <if test="amt != null "> and amt = #{amt}</if>
  56. <if test="unionId != null and unionId != ''"> and union_id = #{unionId}</if>
  57. <if test="stationIdList != null ">
  58. and station_id in
  59. <foreach item="item" index="index" collection="stationIdList"
  60. open="(" separator="," close=")">
  61. #{item}
  62. </foreach>
  63. </if>
  64. <if test="stationId != null ">
  65. and station_id = #{stationId}
  66. </if>
  67. </where>
  68. order by id desc
  69. </select>
  70. <select id="selectCustomerManageById" parameterType="Long" resultMap="CustomerManageResult">
  71. <include refid="selectCustomerManageVo"/>
  72. where id = #{id}
  73. </select>
  74. <insert id="insertCustomerManage" parameterType="CustomerManage" useGeneratedKeys="true" keyProperty="id">
  75. insert into customer_manage
  76. <trim prefix="(" suffix=")" suffixOverrides=",">
  77. <if test="memberId != null">member_id,</if>
  78. <if test="customerName != null">customer_name,</if>
  79. <if test="commendMan != null">commend_man,</if>
  80. <if test="phoneNumber != null">phone_number,</if>
  81. <if test="carNumber != null">car_number,</if>
  82. <if test="balance != null">balance,</if>
  83. <if test="integral != null">integral,</if>
  84. <if test="specialCarType != null">special_car_type,</if>
  85. <if test="regtime != null">regtime,</if>
  86. <if test="stationId != null">station_id,</if>
  87. <if test="minaUserId != null">mina_user_id,</if>
  88. <if test="oilName != null">oil_name,</if>
  89. <if test="grade != null">grade,</if>
  90. <if test="liters != null">liters,</if>
  91. <if test="amt != null">amt,</if>
  92. <if test="unionId != null">union_id,</if>
  93. </trim>
  94. <trim prefix="values (" suffix=")" suffixOverrides=",">
  95. <if test="memberId != null">#{memberId},</if>
  96. <if test="customerName != null">#{customerName},</if>
  97. <if test="commendMan != null">#{commendMan},</if>
  98. <if test="phoneNumber != null">#{phoneNumber},</if>
  99. <if test="carNumber != null">#{carNumber},</if>
  100. <if test="balance != null">#{balance},</if>
  101. <if test="integral != null">#{integral},</if>
  102. <if test="specialCarType != null">#{specialCarType},</if>
  103. <if test="regtime != null">#{regtime},</if>
  104. <if test="stationId != null">#{stationId},</if>
  105. <if test="blogUserId != null">#{blogUserId},</if>
  106. <if test="minaUserId != null">#{minaUserId},</if>
  107. <if test="oilName != null">#{oilName},</if>
  108. <if test="grade != null">#{grade},</if>
  109. <if test="liters != null">#{liters},</if>
  110. <if test="amt != null">#{amt},</if>
  111. <if test="unionId != null">#{unionId},</if>
  112. </trim>
  113. </insert>
  114. <update id="updateCustomerManage" parameterType="CustomerManage">
  115. update customer_manage
  116. <trim prefix="SET" suffixOverrides=",">
  117. <if test="memberId != null">member_id = #{memberId},</if>
  118. <if test="customerName != null">customer_name = #{customerName},</if>
  119. <if test="commendMan != null">commend_man = #{commendMan},</if>
  120. <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
  121. <if test="carNumber != null">car_number = #{carNumber},</if>
  122. <if test="balance != null">balance = #{balance},</if>
  123. <if test="integral != null">integral = #{integral},</if>
  124. <if test="specialCarType != null">special_car_type = #{specialCarType},</if>
  125. <if test="regtime != null">regtime = #{regtime},</if>
  126. <if test="stationId != null">station_id = #{stationId},</if>
  127. <if test="minaUserId != null">mina_user_id = #{minaUserId},</if>
  128. <if test="oilName != null">oil_name = #{oilName},</if>
  129. <if test="grade != null">grade = #{grade},</if>
  130. <if test="liters != null">liters = #{liters},</if>
  131. <if test="amt != null">amt = #{amt},</if>
  132. <if test="unionId != null">union_id = #{unionId},</if>
  133. </trim>
  134. where id = #{id}
  135. </update>
  136. <delete id="deleteCustomerManageById" parameterType="Long">
  137. delete from customer_manage where id = #{id}
  138. </delete>
  139. <delete id="deleteCustomerManageByIds" parameterType="String">
  140. delete from customer_manage where id in
  141. <foreach item="id" collection="array" open="(" separator="," close=")">
  142. #{id}
  143. </foreach>
  144. </delete>
  145. <select id="selectCustomerManage" parameterType="CustomerManage" resultMap="CustomerManageResult">
  146. SELECT b.union_id,b.station_id,a.qy_amt,a.cy_amt,a.fy_amt,a.lng_amt, a.cng_amt,b.member_id, b.customer_name,
  147. b.phone_number, b.car_number,b.mina_user_id,b.oil_name,b.grade,c.points AS integral,d.dept_name as station_name
  148. from (SELECT member_id,customer_name,phone_number,car_number, mina_user_id,station_id,
  149. union_id,GROUP_CONCAT(DISTINCT ( oil_name )) oil_name,GROUP_CONCAT(DISTINCT ( grade )) AS grade,created_date
  150. FROM (
  151. SELECT max( created_date ) created_date, po.consumer_id FROM pay_order po
  152. <where>
  153. <if test="stationIdList != null ">
  154. and po.station_id in
  155. <foreach item="item" index="index" collection="stationIdList"
  156. open="(" separator="," close=")">
  157. #{item}
  158. </foreach>
  159. </if>
  160. <if test="stationId != null ">
  161. and po.station_id = #{stationId}
  162. </if>
  163. <if test="oilName != null and oilName != ''"> and po.oil_name like concat('%', #{oilName}, '%')</if>
  164. and status ="1"
  165. </where>
  166. GROUP BY po.consumer_id order by created_date desc ) p
  167. INNER JOIN customer_manage m ON m.mina_user_id = p.consumer_id
  168. <where>
  169. <if test="stationIdList != null ">
  170. and m.station_id in
  171. <foreach item="item" index="index" collection="stationIdList"
  172. open="(" separator="," close=")">
  173. #{item}
  174. </foreach>
  175. </if>
  176. <if test="stationId != null ">
  177. and m.station_id = #{stationId}
  178. </if>
  179. <if test="customerName != null and customerName != ''">
  180. and m.customer_name like concat('%', #{customerName}, '%')
  181. </if>
  182. <if test="commendMan != null and commendMan != ''">
  183. and m.commend_man = #{commendMan}
  184. </if>
  185. <if test="phoneNumber != null and phoneNumber != ''">
  186. and m.phone_number like concat('%', #{phoneNumber}, '%')
  187. </if>
  188. <if test="oilName != null and oilName != ''"> and m.oil_name like concat('%', #{oilName}, '%')</if>
  189. </where>
  190. GROUP BY member_id,customer_name, phone_number,car_number, mina_user_id, station_id, union_id,created_date
  191. order by max( created_date ) desc
  192. limit #{pageNumLimit},#{pageSizeLimit}
  193. ) b
  194. LEFT JOIN
  195. (SELECT union_id, customer_name, station_id,
  196. sum( CASE card_oils_type WHEN '1' THEN amt ELSE 0 END ) qy_amt,
  197. sum( CASE card_oils_type WHEN '2' THEN amt ELSE 0 END ) cy_amt,
  198. sum( CASE card_oils_type WHEN '3' THEN amt ELSE 0 END ) fy_amt,
  199. sum( CASE card_oils_type WHEN '4' THEN amt ELSE 0 END ) lng_amt,
  200. sum( CASE card_oils_type WHEN '5' THEN amt ELSE 0 END ) cng_amt
  201. FROM customer_electronic_card
  202. <where>
  203. <if test="stationIdList != null ">
  204. and station_id in
  205. <foreach item="item" index="index" collection="stationIdList"
  206. open="(" separator="," close=")">
  207. #{item}
  208. </foreach>
  209. </if>
  210. <if test="stationId != null ">
  211. and station_id = #{stationId}
  212. </if>
  213. </where>
  214. GROUP BY union_id, customer_name, station_id) a
  215. ON a.union_id = b.union_id AND a.station_id = b.station_id
  216. LEFT JOIN customer_points c ON b.union_id = c.union_id AND b.station_id = c.station_id
  217. <if test="stationIdList != null ">
  218. and c.station_id in
  219. <foreach item="item" index="index" collection="stationIdList"
  220. open="(" separator="," close=")">
  221. #{item}
  222. </foreach>
  223. </if>
  224. <if test="stationId != null ">
  225. and c.station_id = #{stationId}
  226. </if>
  227. LEFT JOIN sys_dept d ON b.station_id = d.dept_id
  228. ORDER BY created_date desc
  229. </select>
  230. <select id="selectCustomerManagePage" parameterType="CustomerManage" resultMap="CustomerManageResult">
  231. SELECT customer_name,mina_user_id
  232. FROM (SELECT max( created_date ) created_date, po.consumer_id FROM pay_order po
  233. <where>
  234. <if test="stationIdList != null ">
  235. and po.station_id in
  236. <foreach item="item" index="index" collection="stationIdList"
  237. open="(" separator="," close=")">
  238. #{item}
  239. </foreach>
  240. </if>
  241. <if test="stationId != null ">
  242. and po.station_id = #{stationId}
  243. </if>
  244. <if test="oilName != null and oilName != ''"> and po.oil_name like concat('%', #{oilName}, '%')</if>
  245. and status ="1"
  246. </where>
  247. GROUP BY po.consumer_id order by created_date desc ) p
  248. INNER JOIN customer_manage m ON m.mina_user_id = p.consumer_id
  249. <where>
  250. <if test="stationIdList != null ">
  251. and m.station_id in
  252. <foreach item="item" index="index" collection="stationIdList"
  253. open="(" separator="," close=")">
  254. #{item}
  255. </foreach>
  256. </if>
  257. <if test="stationId != null ">
  258. and m.station_id = #{stationId}
  259. </if>
  260. <if test="customerName != null and customerName != ''">
  261. and m.customer_name like concat('%', #{customerName}, '%')
  262. </if>
  263. <if test="commendMan != null and commendMan != ''">
  264. and m.commend_man = #{commendMan}
  265. </if>
  266. <if test="phoneNumber != null and phoneNumber != ''">
  267. and m.phone_number like concat('%', #{phoneNumber}, '%')
  268. </if>
  269. <if test="oilName != null and oilName != ''"> and m.oil_name like concat('%', #{oilName}, '%')</if>
  270. </where>
  271. GROUP BY customer_name, mina_user_id, phone_number, member_id
  272. </select>
  273. </mapper>