Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

330 řádky
14 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. <select id="findCount" parameterType="com.iformall.domain.po.WxCardSpend" resultType="Integer">
  113. select count(*)
  114. from wx_card_spend cs
  115. <if test=" null != businessId ">
  116. inner join wx_merchant m
  117. on m.id = cs.merchant_id
  118. and m.business_id = #{businessId}
  119. <if test=" null != subBusinessId ">
  120. and m.sub_business_id = #{subBusinessId}
  121. </if>
  122. </if>
  123. where 1 = 1
  124. <if test=" null != ownerId ">
  125. and cs.`owner_id` = #{ownerId}
  126. </if>
  127. <if test=" null != tenantId ">
  128. and cs.`tenant_id` = #{tenantId}
  129. </if>
  130. <if test=" null != startdate and null!=enddate">
  131. and cs.`create_date` between #{startdate} and #{enddate}
  132. </if>
  133. <if test=" 0 == timeSlot">
  134. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  135. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  136. and date_format(cs.create_date,'%w') in (1,2,3,4,5)
  137. </if>
  138. <if test=" 1 == timeSlot">
  139. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  140. and date_format(cs.create_date,'%w') in (1,2,3,4))
  141. or
  142. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  143. and date_format(cs.create_date,'%w') in (1,2,3,4,5)))
  144. </if>
  145. <if test=" 2 == timeSlot">
  146. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  147. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  148. and date_format(cs.create_date,'%w') in (0,6)
  149. </if>
  150. <if test=" 3 == timeSlot">
  151. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  152. and date_format(cs.create_date,'%w') in (5,6,0))
  153. or
  154. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  155. and date_format(cs.create_date,'%w') in (6,0)))
  156. </if>
  157. </select>
  158. <resultMap id="VoResultMap" type="com.iformall.domain.vo.WxCardSpendVo">
  159. <id column="id" jdbcType="BIGINT" property="id"/>
  160. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  161. <result column="card_id" jdbcType="BIGINT" property="cardId"/>
  162. <result column="owner_id" jdbcType="BIGINT" property="ownerId"/>
  163. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  164. <result column="order_id" jdbcType="BIGINT" property="orderId"/>
  165. <result column="deduction_amount" jdbcType="INTEGER" property="deductionAmount"/>
  166. <result column="payment" jdbcType="INTEGER" property="payment"/>
  167. <result column="real_payment" jdbcType="INTEGER" property="realPayment"/>
  168. <result column="card_remain_amount" jdbcType="INTEGER" property="cardRemainAmount"/>
  169. <result column="card_before_amount" jdbcType="INTEGER" property="cardBeforeAmount"/>
  170. <result column="card_remain_real_amount" jdbcType="INTEGER" property="cardRemainRealAmount"/>
  171. <result column="card_before_real_amount" jdbcType="INTEGER" property="cardBeforeRealAmount"/>
  172. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  173. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  174. <result column="pay_status" jdbcType="INTEGER" property="payStatus"/>
  175. <result column="title" jdbcType="VARCHAR" property="title"/>
  176. <result column="name" jdbcType="VARCHAR" property="merchantName"/>
  177. <result column="subsidy" jdbcType="INTEGER" property="subsidy"/>
  178. <result column="real_subsidy" jdbcType="INTEGER" property="realSubsidy"/>
  179. <result column="status" jdbcType="INTEGER" property="status"/>
  180. <result column="onick_name" jdbcType="VARCHAR" property="onickName"/>
  181. <result column="ou_phone" jdbcType="VARCHAR" property="ouPhone"/>
  182. </resultMap>
  183. <sql id="allVoColumns">
  184. 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`,
  185. cs.`card_remain_amount`,cs.`card_before_amount`,cs.`card_remain_real_amount`,cs.`card_before_real_amount`,
  186. cs.`create_date`,cs.`update_date`, cs.`pay_status`,
  187. m.`name`, c.`title`,
  188. ms.`subsidy`,ms.`real_subsidy`,ms.`status`,
  189. ou.`nick_name` as onick_name, ou.`phone` as ou_phone
  190. </sql>
  191. <sql id="dynamicVoWhereConditions">
  192. where 1 = 1
  193. <if test=" null != id ">
  194. and cs.`id` = #{id}
  195. </if>
  196. <if test=" null != tenantId ">
  197. and cs.`tenant_id` = #{tenantId}
  198. </if>
  199. <if test=" null != cardId ">
  200. and cs.`card_id` = #{cardId}
  201. </if>
  202. <if test=" null != ownerId ">
  203. and cs.`owner_id` = #{ownerId}
  204. </if>
  205. <if test=" null != merchantId ">
  206. and cs.`merchant_id` = #{merchantId}
  207. </if>
  208. <if test=" null != orderId ">
  209. and cs.`order_id` = #{orderId}
  210. </if>
  211. <if test=" null != deductionAmount ">
  212. and cs.`deduction_amount` = #{deductionAmount}
  213. </if>
  214. <if test=" null != payment ">
  215. and cs.`payment` = #{payment}
  216. </if>
  217. <if test=" null != realPayment ">
  218. and cs.`real_payment` = #{realPayment}
  219. </if>
  220. <if test=" null != cardRemainAmount ">
  221. and cs.`card_remain_amount` = #{cardRemainAmount}
  222. </if>
  223. <if test=" null != cardBeforeAmount ">
  224. and cs.`card_before_amount` = #{cardBeforeAmount}
  225. </if>
  226. <if test=" null != cardRemainRealAmount ">
  227. and cs.`card_remain_real_amount` = #{cardRemainRealAmount}
  228. </if>
  229. <if test=" null != cardBeforeRealAmount ">
  230. and cs.`card_before_real_amount` = #{cardBeforeRealAmount}
  231. </if>
  232. <if test=" null != createDate ">
  233. and cs.`create_date` = #{createDate}
  234. </if>
  235. <if test=" null != updateDate ">
  236. and cs.`update_date` = #{updateDate}
  237. </if>
  238. <if test=" null != payStatus ">
  239. and cs.`pay_status` = #{payStatus}
  240. </if>
  241. <if test=" null != status ">
  242. and ms.`status` = #{status}
  243. </if>
  244. <if test=" null != ouPhone ">
  245. and ou.`phone` = #{ouPhone}
  246. </if>
  247. <if test=" null != startdate and null!=enddate">
  248. and cs.`create_date` between #{startdate} and #{enddate}
  249. </if>
  250. <if test=" null != payStatusS ">
  251. and cs.`pay_status` in
  252. <foreach collection="payStatusS" index="index" item="sItem" open="(" separator="," close=")">
  253. #{sItem}
  254. </foreach>
  255. </if>
  256. <if test=" null != ids ">
  257. and cs.id in
  258. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  259. #{idItem}
  260. </foreach>
  261. </if>
  262. </sql>
  263. <select id="findCardSpendVoList" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultMap="VoResultMap">
  264. select
  265. <include refid="allVoColumns"/>
  266. from wx_card_spend cs
  267. left join wx_coupon_order co on co.id = cs.card_id
  268. left join wx_coupon c on c.id = co.coupon_id
  269. left join wx_merchant m on m.id = cs.merchant_id
  270. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  271. left join wx_c_user ou on ou.id = co.owner_id
  272. <include refid="dynamicVoWhereConditions"/>
  273. order by cs.create_date DESC
  274. </select>
  275. <select id="sumCardSpendVoForMerchant" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultType="hashmap">
  276. select cs.merchant_id, m.name as merchantName,
  277. IFNULL(SUM(cs.`deduction_amount`),0) as sum_deduction_amount,
  278. IFNULL(SUM(cs.`payment`),0) as sum_payment,
  279. IFNULL(SUM(cs.`real_payment`),0) as sum_real_payment,
  280. IFNULL(SUM(ms.`subsidy`), 0) as sum_subsidy,
  281. IFNULL(SUM(ms.`real_subsidy`), 0) as sum_real_subsidy
  282. from wx_card_spend cs
  283. left join wx_coupon_order co on co.id = cs.card_id
  284. left join wx_coupon c on c.id = co.coupon_id
  285. left join wx_merchant m on m.id = cs.merchant_id
  286. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  287. left join wx_c_user ou on ou.id = co.owner_id
  288. <include refid="dynamicVoWhereConditions"/>
  289. group by cs.merchant_id
  290. </select>
  291. <select id="sumCardSpendVoForOwner" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultType="hashmap">
  292. select cs.owner_id,
  293. IFNULL(SUM(cs.`deduction_amount`),0) as sum_deduction_amount,
  294. IFNULL(SUM(cs.`payment`),0) as sum_payment,
  295. IFNULL(SUM(cs.`real_payment`),0) as sum_real_payment,
  296. IFNULL(SUM(ms.`subsidy`), 0) as sum_subsidy,
  297. IFNULL(SUM(ms.`real_subsidy`), 0) as sum_real_subsidy
  298. from wx_card_spend cs
  299. left join wx_coupon_order co on co.id = cs.card_id
  300. left join wx_coupon c on c.id = co.coupon_id
  301. left join wx_merchant m on m.id = cs.merchant_id
  302. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  303. left join wx_c_user ou on ou.id = co.owner_id
  304. <include refid="dynamicVoWhereConditions"/>
  305. group by cs.owner_id
  306. </select>
  307. </mapper>