Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

366 wiersze
13 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.WxCreditHistoryMapper">
  4. <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxCreditHistory">
  5. <id column="id" jdbcType="BIGINT" property="id" />
  6. <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" />
  7. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  8. <result column="credit_amount" jdbcType="INTEGER" property="creditAmount" />
  9. <result column="credit_num" jdbcType="INTEGER" property="creditNum" />
  10. <result column="credit_type" jdbcType="INTEGER" property="creditType" />
  11. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  12. <result column="receipt_url" jdbcType="VARCHAR" property="receiptUrl" />
  13. <result column="operator_type" jdbcType="INTEGER" property="operatorType" />
  14. <result column="operator_id" jdbcType="BIGINT" property="operatorId" />
  15. <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
  16. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  17. <result column="business_id" jdbcType="BIGINT" property="businessId" />
  18. <result column="spend" jdbcType="INTEGER" property="spend" />
  19. <result column="change_purpose" jdbcType="VARCHAR" property="changePurpose" />
  20. <result column="ticket_number" jdbcType="VARCHAR" property="ticketNumber"/>
  21. <result column="buser_id" jdbcType="BIGINT" property="buserId"/>
  22. </resultMap>
  23. <sql id="allColumns">
  24. `id`,`tenant_id`,`c_user_id`,`credit_amount`,`credit_num`,`credit_type`,`create_date`,`receipt_url`,`operator_type`,`operator_id`,`merchant_id`,`coupon_id`,`business_id`,`spend`,`change_purpose`,`ticket_number`,`buser_id`
  25. </sql>
  26. <sql id="dynamicWhereConditions">
  27. where 1 = 1
  28. <if test=" null != id ">
  29. and `id` = #{id}
  30. </if>
  31. <if test=" null != tenantId and '' != tenantId">
  32. and `tenant_id` = #{tenantId}
  33. </if>
  34. <if test=" null != cUserId ">
  35. and `c_user_id` = #{cUserId}
  36. </if>
  37. <if test=" null != creditAmount ">
  38. and `credit_amount` = #{creditAmount}
  39. </if>
  40. <if test=" null != creditNum ">
  41. and `credit_num` = #{creditNum}
  42. </if>
  43. <if test=" null != creditType ">
  44. and `credit_type` = #{creditType}
  45. </if>
  46. <if test=" null != receiptUrl ">
  47. and `receipt_url` like concat('%', #{receiptUrl},'%')
  48. </if>
  49. <if test=" null != operatorType ">
  50. and `operator_type` = #{operatorType}
  51. </if>
  52. <if test=" null != operatorId ">
  53. and `operator_id` = #{operatorId}
  54. </if>
  55. <if test=" null != merchantId ">
  56. and `merchant_id` = #{merchantId}
  57. </if>
  58. <if test=" null != couponId ">
  59. and `coupon_id` = #{couponId}
  60. </if>
  61. <if test=" null != businessId ">
  62. and `business_id` = #{businessId}
  63. </if>
  64. <if test=" null != spend ">
  65. and `spend` = #{spend}
  66. </if>
  67. <if test=" null != changePurpose ">
  68. and `change_purpose` = #{changePurpose}
  69. </if>
  70. <if test=" null != ticketNumber and ''!=ticketNumber ">
  71. and ticket_number like concat('%', #{ticketNumber},'%')
  72. </if>
  73. <if test=" null != buserId ">
  74. and `buser_id` = #{buserId}
  75. </if>
  76. <if test=" null != ids ">
  77. and id in
  78. <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")">
  79. #{idItem}
  80. </foreach>
  81. </if>
  82. <if test=" null != sortColumns"> order by ${sortColumns} </if>
  83. </sql>
  84. <sql id="customWhereConditions">
  85. where 1 = 1
  86. <if test=" null != name and '' != name">
  87. and basic.nick_name like concat('%', #{name},'%')
  88. </if>
  89. <if test=" null != phone and '' != phone">
  90. and basic.phone like concat('%', #{phone},'%')
  91. </if>
  92. <if test=" null != startTime ">
  93. and credit.create_date &gt;= #{startTime}
  94. </if>
  95. <if test=" null != endTime">
  96. and credit.create_date &lt; #{endTime}
  97. </if>
  98. <if test=" null != tenantId and '' != tenantId">
  99. and credit.`tenant_id` = #{tenantId}
  100. </if>
  101. <if test=" null != operatorType ">
  102. and credit.operator_type = #{operatorType}
  103. </if>
  104. <if test=" null != operatorId ">
  105. and credit.operator_id = #{operatorId}
  106. </if>
  107. <if test=" null != creditType ">
  108. and credit.credit_type = #{creditType}
  109. </if>
  110. <if test=" null != cUserId ">
  111. and credit.c_user_id = #{cUserId}
  112. </if>
  113. <if test=" null != merchantId ">
  114. and credit.merchant_id = #{merchantId}
  115. </if>
  116. <if test=" null != merchantName and ''!=merchantName ">
  117. and merchant.name like concat('%', #{merchantName},'%')
  118. </if>
  119. <if test=" null != ticketNumber and ''!=ticketNumber ">
  120. and credit.ticket_number like concat('%', #{ticketNumber},'%')
  121. </if>
  122. <if test=" null != buserId ">
  123. and credit.buser_id = #{buserId}
  124. </if>
  125. </sql>
  126. <select id="selectById" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  127. select <include refid="allColumns" /> from wx_credit_history where id =#{id} and tenant_id = #{tenantId}
  128. </select>
  129. <select id="findList" parameterType="com.iformall.domain.po.WxCreditHistory" resultMap="BaseResultMap">
  130. select <include refid="allColumns" /> from wx_credit_history
  131. <include refid="dynamicWhereConditions" />
  132. </select>
  133. <select id="findListMore" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="com.iformall.domain.vo.WxCreditHistoryVo">
  134. SELECT
  135. credit.id creditId,
  136. case when basic.nick_name is null then basic.name else basic.nick_name end name,
  137. basic.phone phone,
  138. basic.sex sex,
  139. credit.tenant_id tenantId,
  140. credit.c_user_id cUserId,
  141. credit.credit_amount creditAmount,
  142. credit.credit_num creditNum,
  143. credit.create_date createDate,
  144. credit.credit_type creditType,
  145. credit.receipt_url receiptUrl,
  146. credit.operator_type operatorType,
  147. credit.operator_id operatorId,
  148. merchant.NAME merchantName,
  149. credit.merchant_id merchantId,
  150. credit.ticket_number ticketNumber,
  151. case when credit.operator_type=4 then (select name from mall_user_info where id=credit.operator_id)
  152. when credit.operator_type=3 then (select name from wx_merchant_b_user where id=credit.operator_id)
  153. when credit.operator_type=2 then (select nick_name from wx_c_user_basic_info where id=credit.operator_id)
  154. else '' end operator,
  155. credit.change_purpose changePurpose
  156. FROM
  157. wx_c_user_basic_info basic
  158. INNER JOIN wx_credit_history credit ON basic.id = credit.c_user_id
  159. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  160. <include refid="customWhereConditions"/>
  161. ORDER BY
  162. credit.create_date desc,credit.id DESC
  163. </select>
  164. <select id="loginCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
  165. select COUNT(0) from wx_credit_history
  166. where 1=1
  167. <if test=" null != cUserId ">
  168. and `c_user_id` = #{cUserId}
  169. </if>
  170. <if test=" null != creditType ">
  171. and `credit_type` = #{creditType}
  172. </if>
  173. and DATEDIFF(`create_date`,now())=0
  174. </select>
  175. <select id="countTodayList" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
  176. select count(0)
  177. from wx_credit_history
  178. where 1=1
  179. <if test=" null != tenantId and '' != tenantId">
  180. and `tenant_id` = #{tenantId}
  181. </if>
  182. <if test=" null != cUserId ">
  183. and `c_user_id` = #{cUserId}
  184. </if>
  185. <if test=" null != creditType ">
  186. and `credit_type` = #{creditType}
  187. </if>
  188. and DATEDIFF(`create_date`,now())=0
  189. </select>
  190. <select id="creditAmount" parameterType="java.lang.Long" resultType="java.lang.Integer">
  191. SELECT credit_amount FROM wx_credit_history where c_user_id = #{cUserId} ORDER BY id desc limit 1
  192. </select>
  193. <select id="countList" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
  194. select count(0)
  195. from wx_credit_history
  196. where 1=1
  197. <if test=" null != tenantId and '' != tenantId">
  198. and `tenant_id` = #{tenantId}
  199. </if>
  200. <if test=" null != cUserId ">
  201. and `c_user_id` = #{cUserId}
  202. </if>
  203. <if test=" null != creditType ">
  204. and `credit_type` = #{creditType}
  205. </if>
  206. </select>
  207. <select id="getTotalCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
  208. resultType="java.lang.Long">
  209. select ifnull(sum(credit.amount),0) amount from (
  210. select basic.credit as amount,credit.c_user_id from wx_credit_history credit
  211. INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
  212. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  213. <include refid="customWhereConditions"/>
  214. group by credit.c_user_id
  215. ) credit
  216. </select>
  217. <select id="getIncrementCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
  218. resultType="java.lang.Long">
  219. select ifnull(sum(credit.credit_num),0) amount from wx_credit_history credit
  220. INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
  221. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  222. <include refid="customWhereConditions"/>
  223. and credit.credit_num>0
  224. </select>
  225. <select id="getDecrementCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
  226. resultType="java.lang.Long">
  227. select ABS(ifnull(sum(credit.credit_num),0)) amount from wx_credit_history credit
  228. INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
  229. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  230. <include refid="customWhereConditions"/>
  231. and credit.credit_num &lt; 0
  232. </select>
  233. <select id="getAddCreditSummary" parameterType="com.iformall.domain.po.WxCreditHistory"
  234. resultType="java.lang.Integer">
  235. select ifnull(sum(credit.credit_num),0) amount from wx_credit_history credit
  236. where credit.`tenant_id` = #{tenantId}
  237. and credit.credit_num &gt; 0 and credit.c_user_id = #{cUserId}
  238. <if test=" null != startTime ">
  239. and credit.create_date &gt;= #{startTime}
  240. </if>
  241. <if test=" null != endTime">
  242. and credit.create_date &lt; #{endTime}
  243. </if>
  244. </select>
  245. <select id="getLesCreditSummary" parameterType="com.iformall.domain.po.WxCreditHistory"
  246. resultType="java.lang.Integer">
  247. select ifnull(sum(credit.credit_num),0) amount from wx_credit_history credit
  248. where credit.`tenant_id` = #{tenantId}
  249. and credit.credit_num &lt; 0 and credit.c_user_id = #{cUserId}
  250. <if test=" null != startTime ">
  251. and credit.create_date &gt;= #{startTime}
  252. </if>
  253. <if test=" null != endTime">
  254. and credit.create_date &lt; #{endTime}
  255. </if>
  256. </select>
  257. <select id="getPeopleCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Long">
  258. select count(1) people from (
  259. select count(*) people from wx_credit_history credit
  260. INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
  261. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  262. <include refid="customWhereConditions"/>
  263. group by credit.c_user_id
  264. ) credit
  265. </select>
  266. <delete id="deleteById" parameterType="java.util.HashMap">
  267. delete from wx_credit_history where id = #{id} and tenant_id = #{tenantId}
  268. </delete>
  269. <update id="userCreditClear" statementType="CALLABLE" >
  270. {call user_credit_clear(#{cutOffDate},#{finalTableIndex})}
  271. </update>
  272. <select id="merchantCreditRanking" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="com.iformall.domain.vo.MerchantCreditRankingVo">
  273. select wm.id merchantId,wm.name merchantName,IFNULL(a.sum_credit_num,0) sumAddCredit,
  274. IFNULL(b.sum_credit_num,0) sumLesCredit,IFNULL(c.count_c_user_id,0) countAddCreditUser,
  275. IFNULL(d.count_c_user_id,0) countLesCreditUser
  276. from
  277. (
  278. select id,name from wx_merchant
  279. where is_del = 0
  280. <if test=" null != tenantId and '' != tenantId">
  281. and `tenant_id` = #{tenantId}
  282. </if>
  283. <if test=" null != parentTenantId and '' != parentTenantId">
  284. and `parent_tenant_id` = #{parentTenantId}
  285. </if>
  286. ) wm
  287. left join
  288. (
  289. select merchant_id,sum(credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix}
  290. where merchant_id is not null and merchant_id != -1 and credit_num &gt; 0
  291. <if test=" null != startTime ">
  292. and create_date &gt;= #{startTime}
  293. </if>
  294. <if test=" null != endTime">
  295. and create_date &lt; #{endTime}
  296. </if>
  297. GROUP BY merchant_id
  298. ) a on a.merchant_id = wm.id
  299. left join
  300. (
  301. select merchant_id,sum(credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix}
  302. where merchant_id is not null and merchant_id != -1 and credit_num &lt; 0
  303. <if test=" null != startTime ">
  304. and create_date &gt;= #{startTime}
  305. </if>
  306. <if test=" null != endTime">
  307. and create_date &lt; #{endTime}
  308. </if>
  309. GROUP BY merchant_id
  310. ) b on b.merchant_id = wm.id
  311. left join
  312. (
  313. select merchant_id,count(distinct c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix}
  314. where merchant_id is not null and merchant_id != -1 and credit_num &gt; 0
  315. <if test=" null != startTime ">
  316. and create_date &gt;= #{startTime}
  317. </if>
  318. <if test=" null != endTime">
  319. and create_date &lt; #{endTime}
  320. </if>
  321. GROUP BY merchant_id
  322. ) c on c.merchant_id = wm.id
  323. left join
  324. (
  325. select merchant_id,count(distinct c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix}
  326. where merchant_id is not null and merchant_id != -1 and credit_num &lt; 0
  327. <if test=" null != startTime ">
  328. and create_date &gt;= #{startTime}
  329. </if>
  330. <if test=" null != endTime">
  331. and create_date &lt; #{endTime}
  332. </if>
  333. GROUP BY merchant_id
  334. ) d on d.merchant_id = wm.id
  335. ORDER BY sumAddCredit desc
  336. </select>
  337. </mapper>