CustomerCardUseRecordMapper.xml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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.CustomerCardUseRecordMapper">
  6. <resultMap type="CustomerCardUseRecord" id="CustomerCardUseRecordResult">
  7. <result property="id" column="id" />
  8. <result property="orderNo" column="order_no" />
  9. <result property="unionId" column="union_id" />
  10. <result property="customerNo" column="customer_no" />
  11. <result property="customerName" column="customer_name" />
  12. <result property="usageType" column="usage_type" />
  13. <result property="payType" column="pay_type" />
  14. <result property="cardOilsType" column="card_oils_type" />
  15. <result property="amt" column="amt" />
  16. <result property="presentAmt" column="present_amt" />
  17. <result property="balance" column="balance" />
  18. <result property="createTime" column="create_time" />
  19. <result property="stationId" column="station_id" />
  20. <result property="stationName" column="station_name" />
  21. <result property="status" column="status" />
  22. <result property="xfAmt" column="xf_amt" />
  23. <result property="czAmt" column="cz_amt" />
  24. </resultMap>
  25. <sql id="selectCustomerCardUseRecordVo">
  26. select c.id, c.order_no, c.union_id, c.customer_no, c.customer_name, c.usage_type, c.pay_type,
  27. c.card_oils_type, c.amt, c.present_amt, c.balance, c.create_time, c.station_id,d.dept_name as station_name,
  28. c.status from customer_card_use_record c join sys_dept d on c.station_id = d.dept_id
  29. </sql>
  30. <select id="selectCustomerCardUseRecordList" parameterType="CustomerCardUseRecord" resultMap="CustomerCardUseRecordResult">
  31. <include refid="selectCustomerCardUseRecordVo"/>
  32. <where>
  33. <if test="orderNo != null and orderNo != ''"> and c.order_no = #{orderNo}</if>
  34. <if test="unionId != null and unionId != ''"> and c.union_id = #{unionId}</if>
  35. <if test="customerNo != null and customerNo != ''"> and c.customer_no = #{customerNo}</if>
  36. <if test="customerName != null and customerName != ''"> and c.customer_name like concat('%', #{customerName}, '%')</if>
  37. <if test="usageType != null and usageType != ''"> and c.usage_type = #{usageType}</if>
  38. <if test="payType != null and payType != ''"> and c.pay_type = #{payType}</if>
  39. <if test="cardOilsType != null and cardOilsType != ''"> and c.card_oils_type = #{cardOilsType}</if>
  40. <if test="amt != null "> and c.amt = #{amt}</if>
  41. <if test="presentAmt != null "> and c.present_amt = #{presentAmt}</if>
  42. <if test="balance != null "> and c.balance = #{balance}</if>
  43. <if test="stationId != null "> and c.station_id = #{stationId}</if>
  44. <if test="stationIdList != null ">
  45. and c.station_id in
  46. <foreach item="item" index="index" collection="stationIdList"
  47. open="(" separator="," close=")">
  48. #{item}
  49. </foreach>
  50. </if>
  51. <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
  52. AND date_format(c.create_time,'%y-%m-%d %H:%i:%s') &gt;= date_format(#{beginTime},'%y-%m-%d %H:%i:%s')
  53. </if>
  54. <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
  55. AND date_format(c.create_time,'%y-%m-%d %H:%i:%s') &lt;= date_format(#{endTime},'%y-%m-%d %H:%i:%s')
  56. </if>
  57. <if test="status != null and status != ''"> and c.status = #{status}</if>
  58. </where>
  59. order by id desc
  60. </select>
  61. <select id="selectCustomerCardUseRecordById" parameterType="Long" resultMap="CustomerCardUseRecordResult">
  62. <include refid="selectCustomerCardUseRecordVo"/>
  63. where id = #{id}
  64. </select>
  65. <select id="listCZXFData" parameterType="CustomerCardUseRecord" resultMap="CustomerCardUseRecordResult">
  66. select sum(CASE usage_type WHEN '+' THEN amt ELSE 0 END ) cz_amt,
  67. sum(CASE usage_type WHEN '-' THEN amt ELSE 0 END ) xf_amt
  68. from customer_card_use_record c
  69. <where>
  70. <if test="orderNo != null and orderNo != ''"> and c.order_no = #{orderNo}</if>
  71. <if test="unionId != null and unionId != ''"> and c.union_id = #{unionId}</if>
  72. <if test="customerNo != null and customerNo != ''"> and c.customer_no = #{customerNo}</if>
  73. <if test="customerName != null and customerName != ''"> and c.customer_name like concat('%', #{customerName}, '%')</if>
  74. <if test="usageType != null and usageType != ''"> and c.usage_type = #{usageType}</if>
  75. <if test="payType != null and payType != ''"> and c.pay_type = #{payType}</if>
  76. <if test="cardOilsType != null and cardOilsType != ''"> and c.card_oils_type = #{cardOilsType}</if>
  77. <if test="amt != null "> and c.amt = #{amt}</if>
  78. <if test="presentAmt != null "> and c.present_amt = #{presentAmt}</if>
  79. <if test="balance != null "> and c.balance = #{balance}</if>
  80. <if test="stationId != null "> and c.station_id = #{stationId}</if>
  81. <if test="status != null and status != ''"> and c.status = #{status}</if>
  82. <if test="stationIdList != null ">
  83. and station_id in
  84. <foreach item="item" index="index" collection="stationIdList"
  85. open="(" separator="," close=")">
  86. #{item}
  87. </foreach>
  88. </if>
  89. <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
  90. AND date_format(create_time,'%Y-%m-%d %H:%i:%s') &gt;= date_format(#{beginTime},'%Y-%m-%d %H:%i:%s')
  91. </if>
  92. <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
  93. AND date_format(create_time,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{endTime},'%Y-%m-%d %H:%i:%s')
  94. </if>
  95. </where>
  96. </select>
  97. <select id="listAllCZXFData" parameterType="CustomerCardUseRecord" resultMap="CustomerCardUseRecordResult">
  98. select sum(CASE usage_type WHEN '+' THEN amt ELSE 0 END ) cz_amt,
  99. sum(CASE usage_type WHEN '-' THEN amt ELSE 0 END ) xf_amt
  100. from customer_card_use_record c
  101. <where>
  102. <if test="orderNo != null and orderNo != ''"> and c.order_no = #{orderNo}</if>
  103. <if test="unionId != null and unionId != ''"> and c.union_id = #{unionId}</if>
  104. <if test="customerNo != null and customerNo != ''"> and c.customer_no = #{customerNo}</if>
  105. <if test="customerName != null and customerName != ''"> and c.customer_name like concat('%', #{customerName}, '%')</if>
  106. <if test="usageType != null and usageType != ''"> and c.usage_type = #{usageType}</if>
  107. <if test="payType != null and payType != ''"> and c.pay_type = #{payType}</if>
  108. <if test="cardOilsType != null and cardOilsType != ''"> and c.card_oils_type = #{cardOilsType}</if>
  109. <if test="amt != null "> and c.amt = #{amt}</if>
  110. <if test="presentAmt != null "> and c.present_amt = #{presentAmt}</if>
  111. <if test="balance != null "> and c.balance = #{balance}</if>
  112. <if test="stationId != null "> and c.station_id = #{stationId}</if>
  113. <if test="status != null and status != ''"> and (c.status = #{status} or c.status=2)</if>
  114. <if test="stationIdList != null ">
  115. and station_id in
  116. <foreach item="item" index="index" collection="stationIdList"
  117. open="(" separator="," close=")">
  118. #{item}
  119. </foreach>
  120. </if>
  121. <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
  122. AND date_format(create_time,'%Y-%m-%d %H:%i:%s') &gt;= date_format(#{beginTime},'%Y-%m-%d %H:%i:%s')
  123. </if>
  124. <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
  125. AND date_format(create_time,'%Y-%m-%d %H:%i:%s') &lt;= date_format(#{endTime},'%Y-%m-%d %H:%i:%s')
  126. </if>
  127. </where>
  128. </select>
  129. <insert id="insertCustomerCardUseRecord" parameterType="CustomerCardUseRecord" useGeneratedKeys="true" keyProperty="id">
  130. insert into customer_card_use_record
  131. <trim prefix="(" suffix=")" suffixOverrides=",">
  132. <if test="orderNo != null">order_no,</if>
  133. <if test="unionId != null">union_id,</if>
  134. <if test="customerNo != null">customer_no,</if>
  135. <if test="customerName != null">customer_name,</if>
  136. <if test="usageType != null">usage_type,</if>
  137. <if test="payType != null">pay_type,</if>
  138. <if test="cardOilsType != null">card_oils_type,</if>
  139. <if test="amt != null">amt,</if>
  140. <if test="presentAmt != null">present_amt,</if>
  141. <if test="balance != null">balance,</if>
  142. <if test="createTime != null">create_time,</if>
  143. <if test="stationId != null">station_id,</if>
  144. <if test="status != null">status,</if>
  145. </trim>
  146. <trim prefix="values (" suffix=")" suffixOverrides=",">
  147. <if test="orderNo != null">#{orderNo},</if>
  148. <if test="unionId != null">#{unionId},</if>
  149. <if test="customerNo != null">#{customerNo},</if>
  150. <if test="customerName != null">#{customerName},</if>
  151. <if test="usageType != null">#{usageType},</if>
  152. <if test="payType != null">#{payType},</if>
  153. <if test="cardOilsType != null">#{cardOilsType},</if>
  154. <if test="amt != null">#{amt},</if>
  155. <if test="presentAmt != null">#{presentAmt},</if>
  156. <if test="balance != null">#{balance},</if>
  157. <if test="createTime != null">#{createTime},</if>
  158. <if test="stationId != null">#{stationId},</if>
  159. <if test="status != null">#{status},</if>
  160. </trim>
  161. </insert>
  162. <update id="updateCustomerCardUseRecord" parameterType="CustomerCardUseRecord">
  163. update customer_card_use_record
  164. <trim prefix="SET" suffixOverrides=",">
  165. <if test="orderNo != null">order_no = #{orderNo},</if>
  166. <if test="unionId != null">union_id = #{unionId},</if>
  167. <if test="customerNo != null">customer_no = #{customerNo},</if>
  168. <if test="customerName != null">customer_name = #{customerName},</if>
  169. <if test="usageType != null">usage_type = #{usageType},</if>
  170. <if test="payType != null">pay_type = #{payType},</if>
  171. <if test="cardOilsType != null">card_oils_type = #{cardOilsType},</if>
  172. <if test="amt != null">amt = #{amt},</if>
  173. <if test="presentAmt != null">present_amt = #{presentAmt},</if>
  174. <if test="balance != null">balance = #{balance},</if>
  175. <if test="createTime != null">create_time = #{createTime},</if>
  176. <if test="stationId != null">station_id = #{stationId},</if>
  177. <if test="status != null">status = #{status},</if>
  178. </trim>
  179. where id = #{id}
  180. </update>
  181. <delete id="deleteCustomerCardUseRecordById" parameterType="Long">
  182. delete from customer_card_use_record where id = #{id}
  183. </delete>
  184. <delete id="deleteCustomerCardUseRecordByIds" parameterType="String">
  185. delete from customer_card_use_record where id in
  186. <foreach item="id" collection="array" open="(" separator="," close=")">
  187. #{id}
  188. </foreach>
  189. </delete>
  190. </mapper>