Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

279 строки
12 KiB

  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.iformall.mapper.WxCardSpendMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCardSpend">
  5. <id column="id" jdbcType="BIGINT" property="id"/>
  6. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  7. <result column="card_id" jdbcType="BIGINT" property="cardId"/>
  8. <result column="owner_id" jdbcType="BIGINT" property="ownerId"/>
  9. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  10. <result column="order_id" jdbcType="BIGINT" property="orderId"/>
  11. <result column="deduction_amount" jdbcType="INTEGER" property="deductionAmount"/>
  12. <result column="payment" jdbcType="INTEGER" property="payment"/>
  13. <result column="real_payment" jdbcType="INTEGER" property="realPayment"/>
  14. <result column="card_remain_amount" jdbcType="INTEGER" property="cardRemainAmount"/>
  15. <result column="card_before_amount" jdbcType="INTEGER" property="cardBeforeAmount"/>
  16. <result column="card_remain_real_amount" jdbcType="INTEGER" property="cardRemainRealAmount"/>
  17. <result column="card_before_real_amount" jdbcType="INTEGER" property="cardBeforeRealAmount"/>
  18. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  19. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  20. <result column="pay_status" jdbcType="INTEGER" property="payStatus"/>
  21. </resultMap>
  22. <sql id="allColumns">
  23. `id`,`tenant_id`,`card_id`,`owner_id`,`merchant_id`,`order_id`,`deduction_amount`,`payment`,`real_payment`,
  24. `card_remain_amount`,`card_before_amount`,`card_remain_real_amount`,`card_before_real_amount`,
  25. `create_date`,`update_date`, `pay_status`
  26. </sql>
  27. <sql id="dynamicWhereConditions">
  28. where 1 = 1
  29. <if test=" null != id ">
  30. and `id` = #{id}
  31. </if>
  32. <if test=" null != tenantId ">
  33. and `tenant_id` = #{tenantId}
  34. </if>
  35. <if test=" null != cardId ">
  36. and `card_id` = #{cardId}
  37. </if>
  38. <if test=" null != ownerId ">
  39. and `owner_id` = #{ownerId}
  40. </if>
  41. <if test=" null != merchantId ">
  42. and `merchant_id` = #{merchantId}
  43. </if>
  44. <if test=" null != orderId ">
  45. and `order_id` = #{orderId}
  46. </if>
  47. <if test=" null != deductionAmount ">
  48. and `deduction_amount` = #{deductionAmount}
  49. </if>
  50. <if test=" null != payment ">
  51. and `payment` = #{payment}
  52. </if>
  53. <if test=" null != realPayment ">
  54. and `real_payment` = #{realPayment}
  55. </if>
  56. <if test=" null != cardRemainAmount ">
  57. and `card_remain_amount` = #{cardRemainAmount}
  58. </if>
  59. <if test=" null != cardBeforeAmount ">
  60. and `card_before_amount` = #{cardBeforeAmount}
  61. </if>
  62. <if test=" null != cardRemainRealAmount ">
  63. and `card_remain_real_amount` = #{cardRemainRealAmount}
  64. </if>
  65. <if test=" null != cardBeforeRealAmount ">
  66. and `card_before_real_amount` = #{cardBeforeRealAmount}
  67. </if>
  68. <if test=" null != createDate ">
  69. and `create_date` = #{createDate}
  70. </if>
  71. <if test=" null != updateDate ">
  72. and `update_date` = #{updateDate}
  73. </if>
  74. <if test=" null != payStatus ">
  75. and `pay_status` = #{payStatus}
  76. </if>
  77. <if test=" null != startdate and null!=enddate">
  78. and `create_date` between #{startdate} and #{enddate}
  79. </if>
  80. <if test=" null != ids ">
  81. and id in
  82. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  83. #{idItem}
  84. </foreach>
  85. </if>
  86. <if test=" null != sortColumns">order by ${sortColumns}</if>
  87. </sql>
  88. <select id="findList" parameterType="com.iformall.domain.po.WxCardSpend" resultMap="BaseResultMap">
  89. select
  90. <include refid="allColumns"/>
  91. from wx_card_spend
  92. <include refid="dynamicWhereConditions"/>
  93. </select>
  94. <select id="updateByCond" parameterType="com.iformall.domain.po.WxCardSpend">
  95. update wx_card_spend
  96. set `pay_status` = #{payStatus}, `update_date` = #{updateDate}
  97. <where>
  98. <if test=" null != tenantId ">
  99. and `tenant_id` = #{tenantId}
  100. </if>
  101. <if test=" null != startdate and null!=enddate">
  102. and `create_date` between #{startdate} and #{enddate}
  103. </if>
  104. <if test=" null != ids ">
  105. and id in
  106. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  107. #{idItem}
  108. </foreach>
  109. </if>
  110. </where>
  111. </select>
  112. <resultMap id="VoResultMap" type="com.iformall.domain.vo.WxCardSpendVo">
  113. <id column="id" jdbcType="BIGINT" property="id"/>
  114. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  115. <result column="card_id" jdbcType="BIGINT" property="cardId"/>
  116. <result column="owner_id" jdbcType="BIGINT" property="ownerId"/>
  117. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  118. <result column="order_id" jdbcType="BIGINT" property="orderId"/>
  119. <result column="deduction_amount" jdbcType="INTEGER" property="deductionAmount"/>
  120. <result column="payment" jdbcType="INTEGER" property="payment"/>
  121. <result column="real_payment" jdbcType="INTEGER" property="realPayment"/>
  122. <result column="card_remain_amount" jdbcType="INTEGER" property="cardRemainAmount"/>
  123. <result column="card_before_amount" jdbcType="INTEGER" property="cardBeforeAmount"/>
  124. <result column="card_remain_real_amount" jdbcType="INTEGER" property="cardRemainRealAmount"/>
  125. <result column="card_before_real_amount" jdbcType="INTEGER" property="cardBeforeRealAmount"/>
  126. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  127. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  128. <result column="pay_status" jdbcType="INTEGER" property="payStatus"/>
  129. <result column="title" jdbcType="VARCHAR" property="title"/>
  130. <result column="name" jdbcType="VARCHAR" property="merchantName"/>
  131. <result column="subsidy" jdbcType="INTEGER" property="subsidy"/>
  132. <result column="real_subsidy" jdbcType="INTEGER" property="realSubsidy"/>
  133. <result column="status" jdbcType="INTEGER" property="status"/>
  134. <result column="onick_name" jdbcType="VARCHAR" property="onickName"/>
  135. <result column="ou_phone" jdbcType="VARCHAR" property="ouPhone"/>
  136. </resultMap>
  137. <sql id="allVoColumns">
  138. cs.`id`,cs.`tenant_id`,cs.`card_id`,cs.`owner_id`,cs.`merchant_id`,cs.`order_id`,cs.`deduction_amount`,cs.`payment`,cs.`real_payment`,
  139. cs.`card_remain_amount`,cs.`card_before_amount`,cs.`card_remain_real_amount`,cs.`card_before_real_amount`,
  140. cs.`create_date`,cs.`update_date`, cs.`pay_status`,
  141. m.`name`, c.`title`,
  142. ms.`subsidy`,ms.`real_subsidy`,ms.`status`,
  143. ou.`nick_name` as onick_name, ou.`phone` as ou_phone
  144. </sql>
  145. <sql id="dynamicVoWhereConditions">
  146. where 1 = 1
  147. <if test=" null != id ">
  148. and cs.`id` = #{id}
  149. </if>
  150. <if test=" null != tenantId ">
  151. and cs.`tenant_id` = #{tenantId}
  152. </if>
  153. <if test=" null != cardId ">
  154. and cs.`card_id` = #{cardId}
  155. </if>
  156. <if test=" null != ownerId ">
  157. and cs.`owner_id` = #{ownerId}
  158. </if>
  159. <if test=" null != merchantId ">
  160. and cs.`merchant_id` = #{merchantId}
  161. </if>
  162. <if test=" null != orderId ">
  163. and cs.`order_id` = #{orderId}
  164. </if>
  165. <if test=" null != deductionAmount ">
  166. and cs.`deduction_amount` = #{deductionAmount}
  167. </if>
  168. <if test=" null != payment ">
  169. and cs.`payment` = #{payment}
  170. </if>
  171. <if test=" null != realPayment ">
  172. and cs.`real_payment` = #{realPayment}
  173. </if>
  174. <if test=" null != cardRemainAmount ">
  175. and cs.`card_remain_amount` = #{cardRemainAmount}
  176. </if>
  177. <if test=" null != cardBeforeAmount ">
  178. and cs.`card_before_amount` = #{cardBeforeAmount}
  179. </if>
  180. <if test=" null != cardRemainRealAmount ">
  181. and cs.`card_remain_real_amount` = #{cardRemainRealAmount}
  182. </if>
  183. <if test=" null != cardBeforeRealAmount ">
  184. and cs.`card_before_real_amount` = #{cardBeforeRealAmount}
  185. </if>
  186. <if test=" null != createDate ">
  187. and cs.`create_date` = #{createDate}
  188. </if>
  189. <if test=" null != updateDate ">
  190. and cs.`update_date` = #{updateDate}
  191. </if>
  192. <if test=" null != payStatus ">
  193. and cs.`pay_status` = #{payStatus}
  194. </if>
  195. <if test=" null != status ">
  196. and ms.`status` = #{status}
  197. </if>
  198. <if test=" null != ouPhone ">
  199. and ou.`phone` = #{ouPhone}
  200. </if>
  201. <if test=" null != startdate and null!=enddate">
  202. and cs.`create_date` between #{startdate} and #{enddate}
  203. </if>
  204. <if test=" null != payStatusS ">
  205. and cs.`pay_status` in
  206. <foreach collection="payStatusS" index="index" item="sItem" open="(" separator="," close=")">
  207. #{sItem}
  208. </foreach>
  209. </if>
  210. <if test=" null != ids ">
  211. and cs.id in
  212. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  213. #{idItem}
  214. </foreach>
  215. </if>
  216. </sql>
  217. <select id="findCardSpendVoList" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultMap="VoResultMap">
  218. select
  219. <include refid="allVoColumns"/>
  220. from wx_card_spend cs
  221. left join wx_coupon_order co on co.id = cs.card_id
  222. left join wx_coupon c on c.id = co.coupon_id
  223. left join wx_merchant m on m.id = cs.merchant_id
  224. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  225. left join wx_c_user ou on ou.id = co.owner_id
  226. <include refid="dynamicVoWhereConditions"/>
  227. order by cs.create_date DESC
  228. </select>
  229. <select id="sumCardSpendVoForMerchant" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultType="hashmap">
  230. select cs.merchant_id, m.name as merchantName,
  231. IFNULL(SUM(cs.`deduction_amount`),0) as sum_deduction_amount,
  232. IFNULL(SUM(cs.`payment`),0) as sum_payment,
  233. IFNULL(SUM(cs.`real_payment`),0) as sum_real_payment,
  234. IFNULL(SUM(ms.`subsidy`), 0) as sum_subsidy,
  235. IFNULL(SUM(ms.`real_subsidy`), 0) as sum_real_subsidy
  236. from wx_card_spend cs
  237. left join wx_coupon_order co on co.id = cs.card_id
  238. left join wx_coupon c on c.id = co.coupon_id
  239. left join wx_merchant m on m.id = cs.merchant_id
  240. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  241. left join wx_c_user ou on ou.id = co.owner_id
  242. <include refid="dynamicVoWhereConditions"/>
  243. group by cs.merchant_id
  244. </select>
  245. <select id="sumCardSpendVoForOwner" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultType="hashmap">
  246. select cs.owner_id,
  247. IFNULL(SUM(cs.`deduction_amount`),0) as sum_deduction_amount,
  248. IFNULL(SUM(cs.`payment`),0) as sum_payment,
  249. IFNULL(SUM(cs.`real_payment`),0) as sum_real_payment,
  250. IFNULL(SUM(ms.`subsidy`), 0) as sum_subsidy,
  251. IFNULL(SUM(ms.`real_subsidy`), 0) as sum_real_subsidy
  252. from wx_card_spend cs
  253. left join wx_coupon_order co on co.id = cs.card_id
  254. left join wx_coupon c on c.id = co.coupon_id
  255. left join wx_merchant m on m.id = cs.merchant_id
  256. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  257. left join wx_c_user ou on ou.id = co.owner_id
  258. <include refid="dynamicVoWhereConditions"/>
  259. group by cs.owner_id
  260. </select>
  261. </mapper>