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ů.
 
 
 
 
 

469 řádky
20 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="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  8. <result column="card_id" jdbcType="BIGINT" property="cardId"/>
  9. <result column="owner_id" jdbcType="BIGINT" property="ownerId"/>
  10. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  11. <result column="order_id" jdbcType="BIGINT" property="orderId"/>
  12. <result column="pos_order_id" jdbcType="BIGINT" property="posOrderId"/>
  13. <result column="deduction_amount" jdbcType="INTEGER" property="deductionAmount"/>
  14. <result column="payment" jdbcType="INTEGER" property="payment"/>
  15. <result column="real_payment" jdbcType="INTEGER" property="realPayment"/>
  16. <result column="card_remain_amount" jdbcType="INTEGER" property="cardRemainAmount"/>
  17. <result column="card_before_amount" jdbcType="INTEGER" property="cardBeforeAmount"/>
  18. <result column="card_remain_real_amount" jdbcType="INTEGER" property="cardRemainRealAmount"/>
  19. <result column="card_before_real_amount" jdbcType="INTEGER" property="cardBeforeRealAmount"/>
  20. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  21. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  22. <result column="pay_status" jdbcType="INTEGER" property="payStatus"/>
  23. <result column="pay_from" jdbcType="INTEGER" property="payFrom"/>
  24. </resultMap>
  25. <sql id="allColumns">
  26. `id`,`tenant_id`,`parent_tenant_id`,`card_id`,`owner_id`,`merchant_id`,`order_id`,`pos_order_id`,
  27. `deduction_amount`,`payment`,`real_payment`, `card_remain_amount`,
  28. `card_before_amount`,`card_remain_real_amount`,`card_before_real_amount`,
  29. `create_date`, `update_date`, `pay_status`, `pay_from`
  30. </sql>
  31. <sql id="dynamicWhereConditions">
  32. where 1 = 1
  33. <if test=" null != id ">
  34. and `id` = #{id}
  35. </if>
  36. <if test=" null != tenantId and '' != tenantId">
  37. and `tenant_id` = #{tenantId}
  38. </if>
  39. <if test=" null != parentTenantId and '' != parentTenantId">
  40. and `parent_tenant_id` = #{parentTenantId}
  41. </if>
  42. <if test=" null != cardId ">
  43. and `card_id` = #{cardId}
  44. </if>
  45. <if test=" null != ownerId ">
  46. and `owner_id` = #{ownerId}
  47. </if>
  48. <if test=" null != merchantId ">
  49. and `merchant_id` = #{merchantId}
  50. </if>
  51. <if test=" null != orderId ">
  52. and `order_id` = #{orderId}
  53. </if>
  54. <if test=" null != posOrderId ">
  55. and `pos_order_id` = #{posOrderId}
  56. </if>
  57. <if test=" null != deductionAmount ">
  58. and `deduction_amount` = #{deductionAmount}
  59. </if>
  60. <if test=" null != payment ">
  61. and `payment` = #{payment}
  62. </if>
  63. <if test=" null != realPayment ">
  64. and `real_payment` = #{realPayment}
  65. </if>
  66. <if test=" null != cardRemainAmount ">
  67. and `card_remain_amount` = #{cardRemainAmount}
  68. </if>
  69. <if test=" null != cardBeforeAmount ">
  70. and `card_before_amount` = #{cardBeforeAmount}
  71. </if>
  72. <if test=" null != cardRemainRealAmount ">
  73. and `card_remain_real_amount` = #{cardRemainRealAmount}
  74. </if>
  75. <if test=" null != cardBeforeRealAmount ">
  76. and `card_before_real_amount` = #{cardBeforeRealAmount}
  77. </if>
  78. <if test=" null != createDate ">
  79. and `create_date` = #{createDate}
  80. </if>
  81. <if test=" null != updateDate ">
  82. and `update_date` = #{updateDate}
  83. </if>
  84. <if test=" null != payStatus ">
  85. and `pay_status` = #{payStatus}
  86. </if>
  87. <if test=" null != payFrom ">
  88. and `pay_from` = #{payFrom}
  89. </if>
  90. <if test=" null != startdate and null!=enddate">
  91. and `create_date` between #{startdate} and #{enddate}
  92. </if>
  93. <if test=" null != ids ">
  94. and id in
  95. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  96. #{idItem}
  97. </foreach>
  98. </if>
  99. <if test=" null != sortColumns">order by ${sortColumns}</if>
  100. </sql>
  101. <select id="findList" parameterType="com.iformall.domain.po.WxCardSpend" resultMap="BaseResultMap">
  102. select
  103. <include refid="allColumns"/>
  104. from wx_card_spend
  105. <include refid="dynamicWhereConditions"/>
  106. </select>
  107. <select id="updateByCond" parameterType="com.iformall.domain.po.WxCardSpend">
  108. update wx_card_spend
  109. set `pay_status` = #{payStatus}, `update_date` = #{updateDate}
  110. <where>
  111. <if test=" null != tenantId and '' != tenantId">
  112. and `tenant_id` = #{tenantId}
  113. </if>
  114. <if test=" null != parentTenantId and '' != parentTenantId">
  115. and `parent_tenant_id` = #{parentTenantId}
  116. </if>
  117. <if test=" null != startdate and null!=enddate">
  118. and `create_date` between #{startdate} and #{enddate}
  119. </if>
  120. <if test=" null != ids ">
  121. and id in
  122. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  123. #{idItem}
  124. </foreach>
  125. </if>
  126. </where>
  127. </select>
  128. <delete id="deleteForPrevCancel" parameterType="com.iformall.domain.po.WxCardSpend">
  129. delete from wx_card_spend
  130. where `tenant_id` = #{tenantId} and `id` = #{id} and `pay_status` = #{payStatus}
  131. </delete>
  132. <select id="findCount" parameterType="com.iformall.domain.po.WxCardSpend" resultType="Integer">
  133. select count(*)
  134. from wx_card_spend cs
  135. <if test=" null != businessId ">
  136. inner join wx_merchant m
  137. on m.id = cs.merchant_id
  138. and m.business_id = #{businessId}
  139. <if test=" null != subBusinessId ">
  140. and m.sub_business_id = #{subBusinessId}
  141. </if>
  142. </if>
  143. where 1 = 1
  144. <if test=" null != ownerId ">
  145. and cs.`owner_id` = #{ownerId}
  146. </if>
  147. <if test=" null != tenantId and '' != tenantId">
  148. and cs.`tenant_id` = #{tenantId}
  149. </if>
  150. <if test=" null != parentTenantId and '' != parentTenantId">
  151. and cs.`parent_tenant_id` = #{parentTenantId}
  152. </if>
  153. <if test=" null != startdate and null!=enddate">
  154. and cs.`create_date` between #{startdate} and #{enddate}
  155. </if>
  156. <if test=" 0 == timeSlot">
  157. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  158. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  159. and date_format(cs.create_date,'%w') in (1,2,3,4,5)
  160. </if>
  161. <if test=" 1 == timeSlot">
  162. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  163. and date_format(cs.create_date,'%w') in (1,2,3,4))
  164. or
  165. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  166. and date_format(cs.create_date,'%w') in (1,2,3,4,5)))
  167. </if>
  168. <if test=" 2 == timeSlot">
  169. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  170. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  171. and date_format(cs.create_date,'%w') in (0,6)
  172. </if>
  173. <if test=" 3 == timeSlot">
  174. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  175. and date_format(cs.create_date,'%w') in (5,6,0))
  176. or
  177. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  178. and date_format(cs.create_date,'%w') in (6,0)))
  179. </if>
  180. </select>
  181. <select id="getCountByBusinessId" parameterType="com.iformall.domain.po.WxCardSpend" resultType="hashmap">
  182. select m.business_id, count(m.business_id) bu_count
  183. from wx_card_spend cs
  184. inner join wx_merchant m on m.id = cs.merchant_id
  185. where 1 = 1
  186. <if test=" null != ownerId ">
  187. and cs.`owner_id` = #{ownerId}
  188. </if>
  189. <if test=" null != tenantId and '' != tenantId">
  190. and cs.`tenant_id` = #{tenantId}
  191. </if>
  192. <if test=" null != parentTenantId and '' != parentTenantId">
  193. and cs.`parent_tenant_id` = #{parentTenantId}
  194. </if>
  195. <if test=" null != startdate and null!=enddate">
  196. and cs.`create_date` between #{startdate} and #{enddate}
  197. </if>
  198. <if test=" 0 == timeSlot">
  199. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  200. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  201. and date_format(cs.create_date,'%w') in (1,2,3,4,5)
  202. </if>
  203. <if test=" 1 == timeSlot">
  204. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  205. and date_format(cs.create_date,'%w') in (1,2,3,4))
  206. or
  207. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  208. and date_format(cs.create_date,'%w') in (1,2,3,4,5)))
  209. </if>
  210. <if test=" 2 == timeSlot">
  211. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  212. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  213. and date_format(cs.create_date,'%w') in (0,6)
  214. </if>
  215. <if test=" 3 == timeSlot">
  216. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  217. and date_format(cs.create_date,'%w') in (5,6,0))
  218. or
  219. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  220. and date_format(cs.create_date,'%w') in (6,0)))
  221. </if>
  222. group by m.business_id
  223. </select>
  224. <select id="getCountBySubBusinessId" parameterType="com.iformall.domain.po.WxCardSpend" resultType="hashmap">
  225. select m.sub_business_id, count(m.sub_business_id) bu_count
  226. from wx_card_spend cs
  227. <if test=" null != businessId ">
  228. inner join wx_merchant m on m.id = cs.merchant_id and m.business_id = #{businessId}
  229. </if>
  230. where 1 = 1
  231. <if test=" null != ownerId ">
  232. and cs.`owner_id` = #{ownerId}
  233. </if>
  234. <if test=" null != tenantId and '' != tenantId">
  235. and cs.`tenant_id` = #{tenantId}
  236. </if>
  237. <if test=" null != parentTenantId and '' != parentTenantId">
  238. and cs.`parent_tenant_id` = #{parentTenantId}
  239. </if>
  240. <if test=" null != startdate and null!=enddate">
  241. and cs.`create_date` between #{startdate} and #{enddate}
  242. </if>
  243. <if test=" 0 == timeSlot">
  244. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  245. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  246. and date_format(cs.create_date,'%w') in (1,2,3,4,5)
  247. </if>
  248. <if test=" 1 == timeSlot">
  249. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  250. and date_format(cs.create_date,'%w') in (1,2,3,4))
  251. or
  252. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  253. and date_format(cs.create_date,'%w') in (1,2,3,4,5)))
  254. </if>
  255. <if test=" 2 == timeSlot">
  256. and date_format(cs.create_date,'%H:%m') &gt;= '06:00'
  257. and date_format(cs.create_date,'%H:%m') &lt; '18:00'
  258. and date_format(cs.create_date,'%w') in (0,6)
  259. </if>
  260. <if test=" 3 == timeSlot">
  261. and ((date_format(cs.create_date,'%H:%m') &gt;= '18:00'
  262. and date_format(cs.create_date,'%w') in (5,6,0))
  263. or
  264. ((date_format(cs.create_date,'%H:%m') &lt; '06:00')
  265. and date_format(cs.create_date,'%w') in (6,0)))
  266. </if>
  267. group by m.sub_business_id
  268. </select>
  269. <resultMap id="VoResultMap" type="com.iformall.domain.vo.WxCardSpendVo">
  270. <id column="id" jdbcType="BIGINT" property="id"/>
  271. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
  272. <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  273. <result column="card_id" jdbcType="BIGINT" property="cardId"/>
  274. <result column="owner_id" jdbcType="BIGINT" property="ownerId"/>
  275. <result column="merchant_id" jdbcType="BIGINT" property="merchantId"/>
  276. <result column="order_id" jdbcType="BIGINT" property="orderId"/>
  277. <result column="pos_order_id" jdbcType="BIGINT" property="posOrderId"/>
  278. <result column="deduction_amount" jdbcType="INTEGER" property="deductionAmount"/>
  279. <result column="payment" jdbcType="INTEGER" property="payment"/>
  280. <result column="real_payment" jdbcType="INTEGER" property="realPayment"/>
  281. <result column="card_remain_amount" jdbcType="INTEGER" property="cardRemainAmount"/>
  282. <result column="card_before_amount" jdbcType="INTEGER" property="cardBeforeAmount"/>
  283. <result column="card_remain_real_amount" jdbcType="INTEGER" property="cardRemainRealAmount"/>
  284. <result column="card_before_real_amount" jdbcType="INTEGER" property="cardBeforeRealAmount"/>
  285. <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/>
  286. <result column="update_date" jdbcType="TIMESTAMP" property="updateDate"/>
  287. <result column="pay_status" jdbcType="INTEGER" property="payStatus"/>
  288. <result column="title" jdbcType="VARCHAR" property="title"/>
  289. <result column="name" jdbcType="VARCHAR" property="merchantName"/>
  290. <result column="subsidy" jdbcType="INTEGER" property="subsidy"/>
  291. <result column="real_subsidy" jdbcType="INTEGER" property="realSubsidy"/>
  292. <result column="status" jdbcType="INTEGER" property="status"/>
  293. <result column="onick_name" jdbcType="VARCHAR" property="onickName"/>
  294. <result column="ou_phone" jdbcType="VARCHAR" property="ouPhone"/>
  295. <result column="source" jdbcType="INTEGER" property="source"/>
  296. </resultMap>
  297. <sql id="allVoColumns">
  298. cs.`id`,cs.`tenant_id`,cs.`parent_tenant_id`,cs.`card_id`,cs.`owner_id`,cs.`merchant_id`,cs.`order_id`,cs.`deduction_amount`,cs.`payment`,cs.`real_payment`,
  299. cs.`card_remain_amount`,cs.`card_before_amount`,cs.`card_remain_real_amount`,cs.`card_before_real_amount`,
  300. cs.`create_date`,cs.`update_date`, cs.`pay_status`,
  301. m.`name`, c.`title`,
  302. ms.`subsidy`,ms.`real_subsidy`,ms.`status`,
  303. ou.`nick_name` as onick_name, ou.`phone` as ou_phone
  304. </sql>
  305. <sql id="dynamicVoWhereConditions">
  306. where 1 = 1
  307. <if test=" null != id ">
  308. and cs.`id` = #{id}
  309. </if>
  310. <if test=" null != tenantId and '' != tenantId">
  311. and cs.`tenant_id` = #{tenantId}
  312. </if>
  313. <if test=" null != parentTenantId and '' != parentTenantId">
  314. and cs.`parent_tenant_id` = #{parentTenantId}
  315. </if>
  316. <if test=" null != cardId ">
  317. and cs.`card_id` = #{cardId}
  318. </if>
  319. <if test=" null != ownerId ">
  320. and cs.`owner_id` = #{ownerId}
  321. </if>
  322. <if test=" null != merchantId ">
  323. and cs.`merchant_id` = #{merchantId}
  324. </if>
  325. <if test=" null != orderId ">
  326. and cs.`order_id` = #{orderId}
  327. </if>
  328. <if test=" null != deductionAmount ">
  329. and cs.`deduction_amount` = #{deductionAmount}
  330. </if>
  331. <if test=" null != payment ">
  332. and cs.`payment` = #{payment}
  333. </if>
  334. <if test=" null != realPayment ">
  335. and cs.`real_payment` = #{realPayment}
  336. </if>
  337. <if test=" null != cardRemainAmount ">
  338. and cs.`card_remain_amount` = #{cardRemainAmount}
  339. </if>
  340. <if test=" null != cardBeforeAmount ">
  341. and cs.`card_before_amount` = #{cardBeforeAmount}
  342. </if>
  343. <if test=" null != cardRemainRealAmount ">
  344. and cs.`card_remain_real_amount` = #{cardRemainRealAmount}
  345. </if>
  346. <if test=" null != cardBeforeRealAmount ">
  347. and cs.`card_before_real_amount` = #{cardBeforeRealAmount}
  348. </if>
  349. <if test=" null != createDate ">
  350. and cs.`create_date` = #{createDate}
  351. </if>
  352. <if test=" null != updateDate ">
  353. and cs.`update_date` = #{updateDate}
  354. </if>
  355. <if test=" null != payStatus ">
  356. and cs.`pay_status` = #{payStatus}
  357. </if>
  358. <if test=" null != status ">
  359. and ms.`status` = #{status}
  360. </if>
  361. <if test=" null != sources ">
  362. and ms.source in
  363. <foreach collection="sources" index="index" item="sourceItem" open="(" separator="," close=")">
  364. #{sourceItem}
  365. </foreach>
  366. </if>
  367. <if test=" null != subsidyType ">
  368. and ms.type = #{subsidyType}
  369. </if>
  370. <if test=" null != ouPhone and '' != ouPhone ">
  371. and ou.`phone` = #{ouPhone}
  372. </if>
  373. <if test=" null != startdate and null!=enddate">
  374. and cs.`create_date` between #{startdate} and #{enddate}
  375. </if>
  376. <if test=" null != payStatusS ">
  377. and cs.`pay_status` in
  378. <foreach collection="payStatusS" index="index" item="sItem" open="(" separator="," close=")">
  379. #{sItem}
  380. </foreach>
  381. </if>
  382. <if test=" null != ids ">
  383. and cs.id in
  384. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  385. #{idItem}
  386. </foreach>
  387. </if>
  388. </sql>
  389. <select id="findCardSpendVoList" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultMap="VoResultMap">
  390. select
  391. <include refid="allVoColumns"/>
  392. from wx_card_spend cs
  393. left join wx_coupon_order co on co.id = cs.card_id
  394. left join wx_coupon c on c.id = co.coupon_id
  395. left join wx_merchant m on m.id = cs.merchant_id
  396. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  397. left join wx_c_user_basic_info ou on ou.id = co.owner_id
  398. <include refid="dynamicVoWhereConditions"/>
  399. order by cs.create_date DESC
  400. </select>
  401. <select id="sumCardSpendVoForMerchant" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultType="hashmap">
  402. select cs.merchant_id, m.name as merchantName,
  403. IFNULL(SUM(cs.`deduction_amount`),0) as sum_deduction_amount,
  404. IFNULL(SUM(cs.`payment`),0) as sum_payment,
  405. IFNULL(SUM(cs.`real_payment`),0) as sum_real_payment,
  406. IFNULL(SUM(ms.`subsidy`), 0) as sum_subsidy,
  407. IFNULL(SUM(ms.`real_subsidy`), 0) as sum_real_subsidy
  408. from wx_card_spend cs
  409. left join wx_coupon_order co on co.id = cs.card_id
  410. left join wx_coupon c on c.id = co.coupon_id
  411. left join wx_merchant m on m.id = cs.merchant_id
  412. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  413. left join wx_c_user_basic_info ou on ou.id = co.owner_id
  414. <include refid="dynamicVoWhereConditions"/>
  415. group by cs.merchant_id
  416. </select>
  417. <select id="sumCardSpendVoForOwner" parameterType="com.iformall.domain.vo.WxCardSpendVo" resultType="hashmap">
  418. select cs.owner_id,
  419. IFNULL(SUM(cs.`deduction_amount`),0) as sum_deduction_amount,
  420. IFNULL(SUM(cs.`payment`),0) as sum_payment,
  421. IFNULL(SUM(cs.`real_payment`),0) as sum_real_payment,
  422. IFNULL(SUM(ms.`subsidy`), 0) as sum_subsidy,
  423. IFNULL(SUM(ms.`real_subsidy`), 0) as sum_real_subsidy
  424. from wx_card_spend cs
  425. left join wx_coupon_order co on co.id = cs.card_id
  426. left join wx_coupon c on c.id = co.coupon_id
  427. left join wx_merchant m on m.id = cs.merchant_id
  428. left join wx_merchant_subsidy ms on ms.order_id = cs.order_id
  429. left join wx_c_user_basic_info ou on ou.id = co.owner_id
  430. <include refid="dynamicVoWhereConditions"/>
  431. group by cs.owner_id
  432. </select>
  433. </mapper>