You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

233 lines
11 KiB

2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.example.demo.mapper.cash.CashCollectionMapper">
  4. <insert id="add" parameterType="com.example.demo.domain.entity.CashRecord"
  5. useGeneratedKeys="true" keyProperty="id">
  6. insert into
  7. cash_record(order_type,jwcode,name,market,activity,
  8. order_code,goods_name,good_num,permanent_gold,free_gold,
  9. payment_currency,payment_amount,received_market,
  10. pay_type,pay_time,status,submitter_id,submitter_market,
  11. voucher,remark)
  12. values(#{orderType},#{jwcode},#{name},#{market},#{activity},
  13. #{orderCode},#{goodsName},#{goodNum},#{permanentGold},#{freeGold},#{paymentCurrency},
  14. #{paymentAmount},#{receivedMarket},#{payType},#{payTime},
  15. #{status},#{submitterId},#{submitterMarket},#{voucher},#{remark})
  16. </insert>
  17. <!-- <insert id="syncToCashRecord">
  18. insert into cash_record(order_type,jwcode,name,market,activity,
  19. order_code,goods_name,good_num,permanent_gold,free_gold,
  20. payment_currency,payment_amount,received_market,
  21. pay_type,pay_time,status,submitter_id,
  22. voucher,remark)
  23. values(1,#{jwcode},#{name},#{market},#{activity},
  24. #{order_code},#{goods_name},#{good_num},#{permanent}
  25. )
  26. </insert>-->
  27. <!--更新订单状态-->
  28. <update id="updateStatus">
  29. update cash_record
  30. set status=#{status}
  31. where order_code=#{orderCode}
  32. </update>
  33. <!--更新订单-->
  34. <update id="updateByOrderCode">
  35. UPDATE cash_record
  36. <set>
  37. jwcode = #{cashRecord.jwcode},
  38. name = #{cashRecord.name},
  39. market = #{cashRecord.market},
  40. activity = #{cashRecord.activity},
  41. goods_name = #{cashRecord.goodsName},
  42. good_num = #{cashRecord.goodNum},
  43. payment_currency = #{cashRecord.paymentCurrency},
  44. payment_amount = #{cashRecord.paymentAmount},
  45. received_market = #{cashRecord.receivedMarket},
  46. pay_type = #{cashRecord.payType},
  47. pay_time = #{cashRecord.payTime},
  48. voucher = #{cashRecord.voucher},
  49. remark = #{cashRecord.remark},
  50. status = 0,
  51. </set>
  52. WHERE order_code = #{cashRecord.orderCode}
  53. AND status = 5
  54. </update>
  55. <!--补全手续费等字段-->
  56. <update id="complete">
  57. UPDATE cash_record
  58. <set>
  59. <if test="cashRecord.handlingCharge != null and cashRecord.handlingCharge!=''">
  60. handling_charge = #{cashRecord.handlingCharge},
  61. </if>
  62. <if test="cashRecord.receivedCurrency != null and cashRecord.receivedCurrency != ''">
  63. received_currency = #{cashRecord.receivedCurrency},
  64. </if>
  65. <if test="cashRecord.receivedAmount != null">
  66. received_amount = #{cashRecord.receivedAmount},
  67. </if>
  68. <if test="cashRecord.receivedTime != null">
  69. received_time = #{cashRecord.receivedTime},
  70. </if>
  71. <if test="cashRecord.paymentCurrency != null and cashRecord.paymentCurrency != ''">
  72. payment_currency = #{cashRecord.paymentCurrency},
  73. </if>
  74. <!-- 关键:null 就不拼这一列 -->
  75. <if test="cashRecord.paymentAmount != null">
  76. payment_amount = #{cashRecord.paymentAmount},
  77. </if>
  78. <!-- 只有 这些字段全部非空才更新状态 -->
  79. status = CASE
  80. WHEN
  81. handling_charge IS NOT NULL
  82. AND received_currency IS NOT NULL AND received_currency != ''
  83. AND received_amount IS NOT NULL
  84. AND received_time IS NOT NULL
  85. AND payment_currency IS NOT NULL AND payment_currency != ''
  86. AND payment_amount IS NOT NULL
  87. THEN 4
  88. ELSE status
  89. END
  90. </set>
  91. WHERE order_code = #{cashRecord.orderCode}
  92. AND status IN (1, 3)
  93. </update>
  94. <!--设置gOrder订单为已同步-->
  95. <update id="markSynced">
  96. update g_order
  97. set is_synced = 1
  98. where id = #{orderId}
  99. </update>
  100. <!--根据jwcode获取所属地区-->
  101. <select id="getMarketByJwcode" resultType="java.lang.String">
  102. select market from user where jwcode=#{jwcode}
  103. </select>
  104. <!--根据订单号获取订单id与状态-->
  105. <select id="selectByOrderCode" resultType="com.example.demo.domain.entity.CashRecord">
  106. select id ,status
  107. from cash_record
  108. where order_code=#{orderCode}
  109. </select>
  110. <!--多条件查询收款订单列表-->
  111. <select id="selectCollection1" resultType="com.example.demo.domain.vo.cash.CashCollection">
  112. select cr.id,cr.jwcode,cr.name,cr.market,
  113. m1.name as marketName,
  114. cr.activity,cr.order_code,cr.bank_code,
  115. cr.goods_name,cr.good_num,
  116. cr.permanent_gold/100 as permanentGold,cr.free_gold/100 as freeGold,cr.payment_amount/100 as paymentAmount,
  117. r1.rate_name as paymentCurrency,
  118. r2.rate_name as receivedCurrency,
  119. m2.name as receivedMarket,
  120. cr.received_amount/100 as receivedAmount,cr.handling_charge/100 as handlingCharge,
  121. cr.pay_type,cr.pay_time,cr.received_time,
  122. cr.status,cr.submitter_id,cr.submitter_market,cr.voucher,cr.remark,cr.reject_reason,
  123. cr.audit_id,cr.create_time,cr.update_time,cr.audit_time,
  124. a1.admin_name as submitterName,
  125. a2.admin_name as auditName
  126. from cash_record cr
  127. left join admin a1 on cr.submitter_id = a1.id
  128. left join admin a2 on cr.audit_id = a2.id
  129. left join market m1 on m1.id = cr.market
  130. left join market m2 on m2.id = cr.received_market
  131. left join rate r1 on r1.id = cr.payment_currency
  132. left join rate r2 on r2.id = cr.received_currency
  133. <where>
  134. 1 = 1
  135. <if test="cashCollection.market != null and cashCollection.market != ''">
  136. AND cr.market = #{cashCollection.market}
  137. </if>
  138. <if test="cashCollection.jwcode != null and cashCollection.jwcode!=''">
  139. AND cr.jwcode = #{cashCollection.jwcode}
  140. </if>
  141. <if test="cashCollection.name!=null and cashCollection.name !=''">
  142. AND cr.name like concat('%',#{cashCollection.name},'%')
  143. </if>
  144. <if test="cashCollection.submitterId!=null and cashCollection.submitterId !=''">
  145. AND cr.submitter_id = #{cashCollection.submitterId}
  146. </if>
  147. <!-- 其他原有条件不变 -->
  148. <choose>
  149. <when test="cashCollection.status != null and cashCollection.status == 46">
  150. <if test="cashCollection.receivedMarket != null and cashCollection.receivedMarket != ''">
  151. AND (cr.received_market = #{cashCollection.receivedMarket}
  152. <if test="cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  153. OR cr.submitter_market = #{cashCollection.submitterMarket}
  154. </if>
  155. )
  156. </if>
  157. <if test="(cashCollection.receivedMarket == null or cashCollection.receivedMarket == '')
  158. and cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  159. AND cr.submitter_market = #{cashCollection.submitterMarket}
  160. </if>
  161. </when>
  162. <!-- 非 status=46 保持原逻辑:同时满足 -->
  163. <otherwise>
  164. <if test="cashCollection.receivedMarket != null and cashCollection.receivedMarket != ''">
  165. AND cr.received_market = #{cashCollection.receivedMarket}
  166. </if>
  167. <if test="cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  168. AND cr.submitter_market = #{cashCollection.submitterMarket}
  169. </if>
  170. </otherwise>
  171. </choose>
  172. <if test="cashCollection.activity!=null and cashCollection.activity!=''">
  173. AND cr.activity like concat('%',#{cashCollection.activity},'%')
  174. </if>
  175. <if test="cashCollection.paymentCurrency!=null and cashCollection.paymentCurrency!=''">
  176. AND cr.payment_currency like concat('%',#{cashCollection.paymentCurrency},'%')
  177. </if>
  178. <if test="cashCollection.goodsName!=null and cashCollection.goodsName!=''">
  179. AND cr.goods_name like concat('%',#{cashCollection.goodsName},'%')
  180. </if>
  181. <if test="cashCollection.payType!=null and cashCollection.payType!=''">
  182. AND cr.pay_type = #{cashCollection.payType}
  183. </if>
  184. <if test="cashCollection.status != null">
  185. AND cr.status IN
  186. <foreach collection="cashCollection.status.toString().toCharArray()" item="digit" open="(" separator="," close=")">
  187. #{digit}
  188. </foreach>
  189. </if>
  190. <if test="cashCollection.startTime!=null and cashCollection.endTime!=null">
  191. AND cr.pay_time between #{cashCollection.startTime} and #{cashCollection.endTime}
  192. </if>
  193. and cr.order_type=1
  194. </where>
  195. <choose>
  196. <when test="cashCollection.sortField != null and cashCollection.sortField.length > 0 or cashCollection.sortOrder != null and cashCollection.sortOrder.length > 0">
  197. ORDER BY ${cashCollection.sortField} ${cashCollection.sortOrder}
  198. </when>
  199. <otherwise>
  200. ORDER BY update_time DESC
  201. </otherwise>
  202. </choose>
  203. </select>
  204. <select id="selectAuditByOrderCode" resultType="com.example.demo.domain.entity.CashRecord">
  205. select id, status,jwcode,name,market,activity,
  206. order_code,bank_code,goods_name,good_num,permanent_gold,free_gold,
  207. payment_currency,payment_amount,pay_type,pay_time,status,submitter_id,
  208. voucher,remark from cash_record where order_code=#{orderCode}
  209. </select>
  210. <!--根据精网号获取姓名-->
  211. <select id="getNameByJwcode" resultType="java.lang.String">
  212. select name from user where jwcode=#{jwcode}
  213. </select>
  214. <select id="getMarketNameByJwcode" resultType="java.lang.String">
  215. select m.name from user u left join market m on u.market=m.id
  216. where u.jwcode=#{jwcode}</select>
  217. <select id="getActivityList" resultType="java.lang.String">
  218. select distinct activity from cash_record
  219. </select>
  220. <!--查找未同步的订单-->
  221. <select id="getUnSync" resultType="com.example.demo.domain.entity.GOrder">
  222. select id,jwcode,order_no,type,price,count,pay_style,state,
  223. success_time,ios_environment,ios_transaction_id,ios_receipt_data,
  224. add_time,is_synced
  225. from g_order
  226. where is_synced=0 and state=1 and type='gold_coin' and pay_style in(3,5,6,7,9)
  227. limit #{size}
  228. </select>
  229. </mapper>