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.

278 lines
14 KiB

2 months ago
2 months ago
2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
2 weeks ago
2 weeks 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_collection(order_type,jwcode,name,market,activity,
  8. order_code,goods_name,good_num,num_unit,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},#{numUnit},#{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_collection
  30. set status=#{status}
  31. where order_code=#{orderCode}
  32. </update>
  33. <!--更新订单-->
  34. <update id="updateByOrderCode">
  35. UPDATE cash_record_collection
  36. <set>
  37. jwcode = #{cashRecordCollection.jwcode},
  38. name = #{cashRecordCollection.name},
  39. market = #{cashRecordCollection.market},
  40. activity = #{cashRecordCollection.activity},
  41. goods_name = #{cashRecordCollection.goodsName},
  42. good_num = #{cashRecordCollection.goodNum},
  43. num_unit = #{cashRecordCollection.numUnit},
  44. permanent_gold = #{cashRecordCollection.permanentGold},
  45. free_gold = #{cashRecordCollection.freeGold},
  46. payment_currency = #{cashRecordCollection.paymentCurrency},
  47. payment_amount = #{cashRecordCollection.paymentAmount},
  48. received_market = #{cashRecordCollection.receivedMarket},
  49. pay_type = #{cashRecordCollection.payType},
  50. pay_time = #{cashRecordCollection.payTime},
  51. voucher = #{cashRecordCollection.voucher},
  52. remark = #{cashRecordCollection.remark},
  53. status = 0,
  54. </set>
  55. WHERE order_code = #{cashRecordCollection.orderCode}
  56. AND status = 5
  57. </update>
  58. <!--补全手续费等字段-->
  59. <update id="complete">
  60. UPDATE cash_record_collection
  61. <set>
  62. <if test="cashRecordCollection.handlingCharge != null ">
  63. handling_charge = #{cashRecordCollection.handlingCharge},
  64. </if>
  65. <if test="cashRecordCollection.receivedCurrency != null and cashRecordCollection.receivedCurrency != ''">
  66. received_currency = #{cashRecordCollection.receivedCurrency},
  67. </if>
  68. <if test="cashRecordCollection.receivedAmount != null and cashRecordCollection.receivedAmount != ''">
  69. received_amount = #{cashRecordCollection.receivedAmount},
  70. </if>
  71. <if test="cashRecordCollection.receivedTime != null">
  72. received_time = #{cashRecordCollection.receivedTime},
  73. </if>
  74. <if test="cashRecordCollection.paymentCurrency != null and cashRecordCollection.paymentCurrency != ''">
  75. payment_currency = #{cashRecordCollection.paymentCurrency},
  76. </if>
  77. <!-- 关键:null 就不拼这一列 -->
  78. <if test="cashRecordCollection.paymentAmount != null">
  79. payment_amount = #{cashRecordCollection.paymentAmount},
  80. </if>
  81. <!-- 只有 这些字段全部非空才更新状态 -->
  82. status = CASE
  83. WHEN
  84. handling_charge IS NOT NULL
  85. AND received_currency IS NOT NULL AND received_currency != ''
  86. AND received_amount IS NOT NULL
  87. AND received_time IS NOT NULL
  88. AND payment_currency IS NOT NULL AND payment_currency != ''
  89. AND payment_amount IS NOT NULL
  90. THEN 4
  91. ELSE status
  92. END
  93. </set>
  94. WHERE order_code = #{cashRecordCollection.orderCode}
  95. AND status IN (1, 3)
  96. </update>
  97. <!--设置gOrder订单为已同步-->
  98. <update id="markSynced">
  99. update g_order
  100. set is_synced = 1
  101. where id = #{orderId}
  102. </update>
  103. <!--根据jwcode获取所属地区-->
  104. <select id="getMarketByJwcode" resultType="java.lang.String">
  105. select market from user where jwcode=#{jwcode}
  106. </select>
  107. <!--根据订单号获取订单id与状态-->
  108. <select id="selectByOrderCode" resultType="com.example.demo.domain.entity.CashRecord">
  109. select id ,status
  110. from cash_record_collection
  111. where order_code=#{orderCode}
  112. </select>
  113. <!--多条件查询收款订单列表-->
  114. <select id="selectCollection1" resultType="com.example.demo.domain.vo.cash.CashCollection">
  115. select cr.order_type, cr.id,cr.jwcode,cr.name,cr.market,
  116. m1.name as marketName, ra.id as activityId,
  117. ra.activity_name as activity,cr.order_code,cr.bank_code,
  118. cr.goods_name,cr.good_num,
  119. cr.num_unit,
  120. cr.permanent_gold/100 as permanentGold,cr.free_gold/100 as freeGold,cr.payment_amount/100 as paymentAmount,
  121. r1.rate_name as paymentCurrency,
  122. r2.rate_name as receivedCurrency,
  123. m2.name as receivedMarket,
  124. cr.received_amount/100 as receivedAmount,cr.handling_charge/100 as handlingCharge,
  125. cr.pay_type,cr.pay_time,cr.received_time,
  126. cr.status,cr.submitter_id,cr.submitter_market,cr.voucher,cr.remark,cr.reject_reason,
  127. cr.audit_id,cr.create_time,cr.update_time,cr.audit_time,
  128. a1.admin_name as submitterName,
  129. a2.admin_name as auditName
  130. from cash_record_collection cr
  131. left join admin a1 on cr.submitter_id = a1.id
  132. left join admin a2 on cr.audit_id = a2.id
  133. left join market m1 on m1.id = cr.market
  134. left join market m2 on m2.id = cr.received_market
  135. left join rate r1 on r1.id = cr.payment_currency
  136. left join rate r2 on r2.id = cr.received_currency
  137. left join recharge_activity ra on ra.id = cr.activity
  138. <where>
  139. 1 = 1
  140. <if test="cashCollection.market != null and cashCollection.market != ''">
  141. AND cr.market = #{cashCollection.market}
  142. </if>
  143. <if test="cashCollection.jwcode != null and cashCollection.jwcode!=''">
  144. AND cr.jwcode = #{cashCollection.jwcode}
  145. </if>
  146. <if test="cashCollection.name!=null and cashCollection.name !=''">
  147. AND cr.name like concat('%',#{cashCollection.name},'%')
  148. </if>
  149. <if test="cashCollection.submitterId!=null and cashCollection.submitterId !=''">
  150. AND cr.submitter_id = #{cashCollection.submitterId}
  151. </if>
  152. <!-- 其他原有条件不变 -->
  153. <choose>
  154. <when test="cashCollection.status != null and cashCollection.status == 46">
  155. <if test="cashCollection.receivedMarket != null and cashCollection.receivedMarket != ''">
  156. AND (cr.received_market = #{cashCollection.receivedMarket}
  157. <if test="cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  158. OR cr.submitter_market = #{cashCollection.submitterMarket}
  159. </if>
  160. )
  161. </if>
  162. <if test="(cashCollection.receivedMarket == null or cashCollection.receivedMarket == '')
  163. and cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  164. AND cr.submitter_market = #{cashCollection.submitterMarket}
  165. </if>
  166. </when>
  167. <!-- 非 status=46 保持原逻辑:同时满足 -->
  168. <otherwise>
  169. <if test="cashCollection.receivedMarket != null and cashCollection.receivedMarket != ''">
  170. AND cr.received_market = #{cashCollection.receivedMarket}
  171. </if>
  172. <if test="cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
  173. AND cr.submitter_market = #{cashCollection.submitterMarket}
  174. </if>
  175. </otherwise>
  176. </choose>
  177. <if test="cashCollection.activity!=null and cashCollection.activity!=''">
  178. AND cr.activity like concat('%',#{cashCollection.activity},'%')
  179. </if>
  180. <if test="cashCollection.paymentCurrency!=null and cashCollection.paymentCurrency!=''">
  181. AND cr.payment_currency like concat('%',#{cashCollection.paymentCurrency},'%')
  182. </if>
  183. <if test="cashCollection.goodsName!=null and cashCollection.goodsName!=''">
  184. AND cr.goods_name like concat('%',#{cashCollection.goodsName},'%')
  185. </if>
  186. <if test="cashCollection.payType!=null and cashCollection.payType!=''">
  187. AND cr.pay_type = #{cashCollection.payType}
  188. </if>
  189. <if test="cashCollection.status != null">
  190. AND cr.status IN
  191. <foreach collection="cashCollection.status.toString().toCharArray()" item="digit" open="(" separator="," close=")">
  192. #{digit}
  193. </foreach>
  194. </if>
  195. <if test="cashCollection.startTime!=null and cashCollection.endTime!=null">
  196. AND cr.pay_time between #{cashCollection.startTime} and #{cashCollection.endTime}
  197. </if>
  198. and cr.order_type=1
  199. </where>
  200. <choose>
  201. <when test="cashCollection.sortField != null and cashCollection.sortField.length > 0 or cashCollection.sortOrder != null and cashCollection.sortOrder.length > 0">
  202. ORDER BY ${cashCollection.sortField} ${cashCollection.sortOrder}
  203. </when>
  204. <otherwise>
  205. ORDER BY update_time DESC
  206. </otherwise>
  207. </choose>
  208. </select>
  209. <select id="selectAuditByOrderCode" resultType="com.example.demo.domain.entity.CashRecord">
  210. select crc.id,jwcode,name,market,ra.activity_name as activity,
  211. order_code,bank_code,goods_name,good_num,num_unit,permanent_gold,free_gold,
  212. payment_currency,payment_amount,pay_type,pay_time,crc.status,submitter_id,
  213. voucher,remark
  214. from cash_record_collection crc
  215. left join recharge_activity ra on ra.id = crc.activity
  216. where order_code=#{orderCode}
  217. </select>
  218. <!--根据精网号获取姓名-->
  219. <select id="getNameByJwcode" resultType="java.lang.String">
  220. select name from user where jwcode=#{jwcode}
  221. </select>
  222. <select id="getMarketNameByJwcode" resultType="java.lang.String">
  223. select m.name from user u left join market m on u.market=m.id
  224. where u.jwcode=#{jwcode}</select>
  225. <select id="getActivityList" resultType="com.example.demo.domain.entity.RechargeActivity">
  226. select id,activity_name,business_belong,status
  227. from recharge_activity
  228. where #{now} between start_time and end_time
  229. </select>
  230. <!--查找未同步的订单-->
  231. <select id="getUnSync" resultType="com.example.demo.domain.entity.GOrder">
  232. select id,jwcode,order_no,type,price,count,pay_style,state,
  233. success_time,ios_environment,ios_transaction_id,ios_receipt_data,
  234. add_time,is_synced
  235. from g_order
  236. where is_synced=0 and state=1 and type='gold_coin' and pay_style in(3,5,6,7,9)
  237. limit #{size}
  238. </select>
  239. <select id="selectById" resultType="com.example.demo.domain.vo.cash.CashCollection">
  240. select cr.id,cr.jwcode,cr.name,cr.market,
  241. cr.order_code,cr.bank_code,cr.goods_name,cr.good_num,cr.num_unit,cr.permanent_gold,cr.free_gold,
  242. cr.payment_currency,cr.payment_amount,cr.received_currency,cr.received_amount,cr.handling_charge,
  243. cr.pay_type,cr.received_market,cr.pay_time,cr.received_time,cr.audit_id,cr.status,cr.submitter_id,
  244. cr.submitter_market,cr.voucher,cr.remark,cr.audit_time,a1.admin_name as submitterName,
  245. a2.admin_name as auditName,ra.activity_name as activity
  246. from cash_record_collection cr
  247. left join admin a1 on cr.submitter_id = a1.id
  248. left join admin a2 on cr.audit_id = a2.id
  249. left join recharge_activity ra on ra.id = cr.activity
  250. where cr.id=#{id}
  251. </select>
  252. <select id="selectBatchIds" resultType="com.example.demo.domain.vo.cash.CashCollection">
  253. select
  254. cr.id, cr.jwcode, cr.name, cr.market,
  255. cr.order_code, cr.bank_code, cr.goods_name, cr.good_num, cr.num_unit, cr.permanent_gold, cr.free_gold,
  256. cr.payment_currency, cr.payment_amount, cr.received_currency, cr.received_amount, cr.handling_charge,
  257. cr.pay_type, cr.received_market, cr.pay_time, cr.received_time, cr.audit_id, cr.status, cr.submitter_id,
  258. cr.submitter_market, cr.voucher, cr.remark, cr.audit_time,
  259. a1.admin_name as submitterName,
  260. a2.admin_name as auditName,
  261. ra.activity_name as activity
  262. from cash_record_collection cr
  263. left join admin a1 on cr.submitter_id = a1.id
  264. left join admin a2 on cr.audit_id = a2.id
  265. left join recharge_activity ra on ra.id = cr.activity
  266. where 1 = 0
  267. <if test="relatedIds != null and relatedIds.size() > 0">
  268. OR cr.id IN
  269. <foreach collection="relatedIds" item="id" open="(" separator="," close=")">
  270. #{id}
  271. </foreach>
  272. </if>
  273. </select>
  274. </mapper>