CustomerManageMapper.xml 16 KB

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