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

343 строки
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.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. <if test=" null != startTime ">
  28. and credit.create_date &gt;= #{startTime}
  29. </if>
  30. <if test=" null != endTime">
  31. and credit.create_date &lt; #{endTime}
  32. </if>
  33. <if test=" null != operatorType ">
  34. and credit.operator_type = #{operatorType}
  35. </if>
  36. <if test=" null != operatorId ">
  37. and credit.operator_id = #{operatorId}
  38. </if>
  39. <if test=" null != creditType ">
  40. and credit.credit_type = #{creditType}
  41. </if>
  42. <if test=" null != cUserId ">
  43. and credit.c_user_id = #{cUserId}
  44. </if>
  45. <if test=" null != merchantId ">
  46. and credit.merchant_id = #{merchantId}
  47. </if>
  48. <if test=" null != ticketNumber and ''!=ticketNumber ">
  49. and credit.ticket_number like concat('%', #{ticketNumber},'%')
  50. </if>
  51. <if test=" null != buserId ">
  52. and credit.buser_id = #{buserId}
  53. </if>
  54. <if test=" null != merchantIds ">
  55. and credit.merchant_id in
  56. <foreach collection="merchantIds" index="index" item="merchantIdItem" open="(" separator="," close=")">
  57. #{merchantIdItem}
  58. </foreach>
  59. </if>
  60. <if test=" null != cUserIds ">
  61. and credit.c_user_id in
  62. <foreach collection="cUserIds" index="index" item="cUserIdItem" open="(" separator="," close=")">
  63. #{cUserIdItem}
  64. </foreach>
  65. </if>
  66. </sql>
  67. <select id="selectById" parameterType="java.util.HashMap" resultMap="BaseResultMap">
  68. select <include refid="allColumns" /> from wx_credit_history where id =#{id} and tenant_id = #{tenantId}
  69. </select>
  70. <select id="findList" parameterType="com.iformall.domain.po.WxCreditHistory" resultMap="BaseResultMap">
  71. select <include refid="allColumns" />
  72. from wx_credit_history credit
  73. where `tenant_id` = #{tenantId}
  74. <include refid="dynamicWhereConditions" />
  75. </select>
  76. <select id="findListMore" parameterType="com.iformall.domain.po.WxCreditHistory" resultMap="BaseResultMap">
  77. SELECT
  78. credit.id ,credit.tenant_id ,credit.c_user_id ,credit.credit_amount ,credit.credit_num,credit.create_date,credit.credit_type,credit.receipt_url ,
  79. credit.operator_type,credit.operator_id,credit.merchant_id,credit.ticket_number,credit.change_purpose
  80. FROM wx_credit_history credit
  81. where credit.`tenant_id` = #{tenantId}
  82. <include refid="dynamicWhereConditions" />
  83. ORDER BY credit.create_date DESC
  84. <if test=" null != begin ">
  85. limit #{begin}, #{limit}
  86. </if>
  87. </select>
  88. <select id="loginCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
  89. select COUNT(0) from wx_credit_history
  90. where 1=1
  91. <if test=" null != cUserId ">
  92. and `c_user_id` = #{cUserId}
  93. </if>
  94. <if test=" null != creditType ">
  95. and `credit_type` = #{creditType}
  96. </if>
  97. and DATEDIFF(`create_date`,now())=0
  98. </select>
  99. <select id="monthCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
  100. select COUNT(0) from wx_credit_history
  101. where 1=1
  102. <if test=" null != cUserId ">
  103. and `c_user_id` = #{cUserId}
  104. </if>
  105. <if test=" null != creditType ">
  106. and `credit_type` = #{creditType}
  107. </if>
  108. and DATE_FORMAT(`create_date`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m');
  109. </select>
  110. <select id="countTodayList" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
  111. select count(0)
  112. from wx_credit_history
  113. where 1=1
  114. <if test=" null != tenantId and '' != tenantId">
  115. and `tenant_id` = #{tenantId}
  116. </if>
  117. <if test=" null != cUserId ">
  118. and `c_user_id` = #{cUserId}
  119. </if>
  120. <if test=" null != creditType ">
  121. and `credit_type` = #{creditType}
  122. </if>
  123. and DATEDIFF(`create_date`,now())=0
  124. </select>
  125. <select id="creditAmount" parameterType="java.lang.Long" resultType="java.lang.Integer">
  126. SELECT credit_amount FROM wx_credit_history where c_user_id = #{cUserId} ORDER BY create_date desc limit 1
  127. </select>
  128. <select id="countList" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
  129. select count(0)
  130. from wx_credit_history
  131. where 1=1
  132. <if test=" null != tenantId and '' != tenantId">
  133. and `tenant_id` = #{tenantId}
  134. </if>
  135. <if test=" null != cUserId ">
  136. and `c_user_id` = #{cUserId}
  137. </if>
  138. <if test=" null != creditType ">
  139. and `credit_type` = #{creditType}
  140. </if>
  141. </select>
  142. <select id="getIncrementCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
  143. resultType="java.lang.Long">
  144. select ifnull(sum(credit.credit_num),0) amount
  145. from wx_credit_history credit
  146. where credit.`tenant_id` = #{tenantId}
  147. <include refid="dynamicWhereConditions"/>
  148. and credit.credit_num>0
  149. </select>
  150. <select id="getDecrementCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
  151. resultType="java.lang.Long">
  152. select ABS(ifnull(sum(credit.credit_num),0)) amount
  153. from wx_credit_history credit
  154. where credit.`tenant_id` = #{tenantId}
  155. <include refid="dynamicWhereConditions"/>
  156. and credit.credit_num &lt; 0
  157. </select>
  158. <select id="getAddCreditSummary" parameterType="com.iformall.domain.po.WxCreditHistory"
  159. resultType="java.lang.Integer">
  160. select ifnull(sum(credit.credit_num),0) amount
  161. from wx_credit_history credit
  162. where credit.`tenant_id` = #{tenantId}
  163. and credit.credit_num &gt; 0 and credit.c_user_id = #{cUserId}
  164. <if test=" null != startTime ">
  165. and credit.create_date &gt;= #{startTime}
  166. </if>
  167. <if test=" null != endTime">
  168. and credit.create_date &lt; #{endTime}
  169. </if>
  170. </select>
  171. <select id="getLesCreditSummary" parameterType="com.iformall.domain.po.WxCreditHistory"
  172. resultType="java.lang.Integer">
  173. select ifnull(sum(credit.credit_num),0) amount
  174. from wx_credit_history credit
  175. where credit.`tenant_id` = #{tenantId}
  176. and credit.credit_num &lt; 0
  177. and credit.c_user_id = #{cUserId}
  178. <if test=" null != startTime ">
  179. and credit.create_date &gt;= #{startTime}
  180. </if>
  181. <if test=" null != endTime">
  182. and credit.create_date &lt; #{endTime}
  183. </if>
  184. </select>
  185. <select id="getPeopleCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Long">
  186. select count(distinct credit.c_user_id) people
  187. from wx_credit_history credit
  188. where credit.`tenant_id` = #{tenantId}
  189. <include refid="dynamicWhereConditions"/>
  190. </select>
  191. <delete id="deleteById" parameterType="java.util.HashMap">
  192. delete from wx_credit_history where id = #{id} and tenant_id = #{tenantId}
  193. </delete>
  194. <update id="userCreditClear" statementType="CALLABLE" >
  195. {call user_credit_clear(#{cutOffDate},#{finalTableIndex})}
  196. </update>
  197. <select id="merchantCreditRanking" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="com.iformall.domain.vo.MerchantCreditRankingVo">
  198. select wm.id merchantId,wm.tenant_id tenantId,wm.parent_tenant_id parentTenantId,wm.name merchantName,IFNULL(a.sum_credit_num,0) sumAddCredit,
  199. IFNULL(b.sum_credit_num,0) sumLesCredit,IFNULL(c.count_c_user_id,0) countAddCreditUser,
  200. IFNULL(d.count_c_user_id,0) countLesCreditUser
  201. from
  202. (
  203. select id,tenant_id,parent_tenant_id,name from wx_merchant
  204. where is_del = 0
  205. <if test=" null != tenantId and '' != tenantId">
  206. and `tenant_id` = #{tenantId}
  207. </if>
  208. <if test=" null != parentTenantId and '' != parentTenantId">
  209. and `parent_tenant_id` = #{parentTenantId}
  210. </if>
  211. ) wm
  212. left join
  213. (
  214. select credit.merchant_id,sum(credit.credit_num) sum_credit_num
  215. from wx_credit_history${shardFinalTableSuffix} credit
  216. where credit.merchant_id is not null
  217. and credit.merchant_id != -1 and credit.credit_num &gt; 0
  218. <if test=" null != startTime ">
  219. and credit.create_date &gt;= #{startTime}
  220. </if>
  221. <if test=" null != endTime">
  222. and credit.create_date &lt; #{endTime}
  223. </if>
  224. GROUP BY credit.merchant_id
  225. ) a on a.merchant_id = wm.id
  226. left join
  227. (
  228. select credit.merchant_id,sum(credit.credit_num) sum_credit_num
  229. from wx_credit_history${shardFinalTableSuffix} credit
  230. where credit.merchant_id is not null
  231. and credit.merchant_id != -1 and credit.credit_num &lt; 0
  232. <if test=" null != startTime ">
  233. and credit.create_date &gt;= #{startTime}
  234. </if>
  235. <if test=" null != endTime">
  236. and credit.create_date &lt; #{endTime}
  237. </if>
  238. GROUP BY credit.merchant_id
  239. ) b on b.merchant_id = wm.id
  240. left join
  241. (
  242. select credit.merchant_id,count(distinct credit.c_user_id) count_c_user_id
  243. from wx_credit_history${shardFinalTableSuffix} credit
  244. where credit.merchant_id is not null
  245. and credit.merchant_id != -1 and credit.credit_num &gt; 0
  246. <if test=" null != startTime ">
  247. and credit.create_date &gt;= #{startTime}
  248. </if>
  249. <if test=" null != endTime">
  250. and credit.create_date &lt; #{endTime}
  251. </if>
  252. GROUP BY credit.merchant_id
  253. ) c on c.merchant_id = wm.id
  254. left join
  255. (
  256. select credit.merchant_id,count(distinct credit.c_user_id) count_c_user_id
  257. from wx_credit_history${shardFinalTableSuffix} credit
  258. where credit.merchant_id is not null
  259. and credit.merchant_id != -1 and credit.credit_num &lt; 0
  260. <if test=" null != startTime ">
  261. and credit.create_date &gt;= #{startTime}
  262. </if>
  263. <if test=" null != endTime">
  264. and credit.create_date &lt;= #{endTime}
  265. </if>
  266. GROUP BY credit.merchant_id
  267. ) d on d.merchant_id = wm.id
  268. where (IFNULL(a.sum_credit_num,0) &gt; 0 or IFNULL(b.sum_credit_num,0) &lt; 0)
  269. ORDER BY sumAddCredit desc
  270. </select>
  271. <select id="findAddList" parameterType="com.iformall.domain.po.WxCreditHistory"
  272. resultType="com.iformall.domain.po.WxCreditHistory">
  273. select credit.c_user_id cUserId,ifnull(sum(credit.credit_num),0) creditNum
  274. from wx_credit_history credit
  275. where credit.`tenant_id` = #{tenantId}
  276. and credit.credit_num &gt; 0
  277. <if test=" null != userIdList ">
  278. and credit.`c_user_id` in
  279. <foreach collection="userIdList" index="index" item="uItem" open="(" separator="," close=")">
  280. #{uItem}
  281. </foreach>
  282. </if>
  283. <if test=" null != startTime ">
  284. and credit.create_date &gt;= #{startTime}
  285. </if>
  286. <if test=" null != endTime">
  287. and credit.create_date &lt; #{endTime}
  288. </if>
  289. GROUP BY credit.`c_user_id`
  290. </select>
  291. <select id="findLesList" parameterType="com.iformall.domain.po.WxCreditHistory"
  292. resultType="com.iformall.domain.po.WxCreditHistory">
  293. select credit.c_user_id cUserId,ifnull(sum(credit.credit_num),0) creditNum
  294. from wx_credit_history credit
  295. where credit.`tenant_id` = #{tenantId}
  296. and credit.credit_num &lt; 0
  297. <if test=" null != userIdList ">
  298. and credit.`c_user_id` in
  299. <foreach collection="userIdList" index="index" item="uItem" open="(" separator="," close=")">
  300. #{uItem}
  301. </foreach>
  302. </if>
  303. <if test=" null != startTime ">
  304. and credit.create_date &gt;= #{startTime}
  305. </if>
  306. <if test=" null != endTime">
  307. and credit.create_date &lt; #{endTime}
  308. </if>
  309. GROUP BY credit.`c_user_id`
  310. </select>
  311. </mapper>