選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

382 行
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.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="monthCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
  176. select COUNT(0) from wx_credit_history
  177. where 1=1
  178. <if test=" null != cUserId ">
  179. and `c_user_id` = #{cUserId}
  180. </if>
  181. <if test=" null != creditType ">
  182. and `credit_type` = #{creditType}
  183. </if>
  184. and DATE_FORMAT(`create_date`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m');
  185. </select>
  186. <select id="countTodayList" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
  187. select count(0)
  188. from wx_credit_history
  189. where 1=1
  190. <if test=" null != tenantId and '' != tenantId">
  191. and `tenant_id` = #{tenantId}
  192. </if>
  193. <if test=" null != cUserId ">
  194. and `c_user_id` = #{cUserId}
  195. </if>
  196. <if test=" null != creditType ">
  197. and `credit_type` = #{creditType}
  198. </if>
  199. and DATEDIFF(`create_date`,now())=0
  200. </select>
  201. <select id="creditAmount" parameterType="java.lang.Long" resultType="java.lang.Integer">
  202. SELECT credit_amount FROM wx_credit_history where c_user_id = #{cUserId} ORDER BY id desc limit 1
  203. </select>
  204. <select id="countList" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
  205. select count(0)
  206. from wx_credit_history
  207. where 1=1
  208. <if test=" null != tenantId and '' != tenantId">
  209. and `tenant_id` = #{tenantId}
  210. </if>
  211. <if test=" null != cUserId ">
  212. and `c_user_id` = #{cUserId}
  213. </if>
  214. <if test=" null != creditType ">
  215. and `credit_type` = #{creditType}
  216. </if>
  217. </select>
  218. <select id="getTotalCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
  219. resultType="java.lang.Long">
  220. select ifnull(sum(credit.amount),0) amount from (
  221. select basic.credit as amount,credit.c_user_id from wx_credit_history credit
  222. INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
  223. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  224. <include refid="customWhereConditions"/>
  225. group by credit.c_user_id
  226. ) credit
  227. </select>
  228. <select id="getIncrementCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
  229. resultType="java.lang.Long">
  230. select ifnull(sum(credit.credit_num),0) amount from wx_credit_history credit
  231. INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
  232. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  233. <include refid="customWhereConditions"/>
  234. and credit.credit_num>0
  235. </select>
  236. <select id="getDecrementCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
  237. resultType="java.lang.Long">
  238. select ABS(ifnull(sum(credit.credit_num),0)) amount from wx_credit_history credit
  239. INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
  240. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  241. <include refid="customWhereConditions"/>
  242. and credit.credit_num &lt; 0
  243. </select>
  244. <select id="getAddCreditSummary" parameterType="com.iformall.domain.po.WxCreditHistory"
  245. resultType="java.lang.Integer">
  246. select ifnull(sum(credit.credit_num),0) amount from wx_credit_history credit
  247. where credit.`tenant_id` = #{tenantId}
  248. and credit.credit_num &gt; 0 and credit.c_user_id = #{cUserId}
  249. <if test=" null != startTime ">
  250. and credit.create_date &gt;= #{startTime}
  251. </if>
  252. <if test=" null != endTime">
  253. and credit.create_date &lt; #{endTime}
  254. </if>
  255. </select>
  256. <select id="getLesCreditSummary" parameterType="com.iformall.domain.po.WxCreditHistory"
  257. resultType="java.lang.Integer">
  258. select ifnull(sum(credit.credit_num),0) amount from wx_credit_history credit
  259. where credit.`tenant_id` = #{tenantId}
  260. and credit.credit_num &lt; 0 and credit.c_user_id = #{cUserId}
  261. <if test=" null != startTime ">
  262. and credit.create_date &gt;= #{startTime}
  263. </if>
  264. <if test=" null != endTime">
  265. and credit.create_date &lt; #{endTime}
  266. </if>
  267. </select>
  268. <select id="getPeopleCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Long">
  269. select count(1) people from (
  270. select count(*) people from wx_credit_history credit
  271. INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
  272. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  273. <include refid="customWhereConditions"/>
  274. group by credit.c_user_id
  275. ) credit
  276. </select>
  277. <delete id="deleteById" parameterType="java.util.HashMap">
  278. delete from wx_credit_history where id = #{id} and tenant_id = #{tenantId}
  279. </delete>
  280. <update id="userCreditClear" statementType="CALLABLE" >
  281. {call user_credit_clear(#{cutOffDate},#{finalTableIndex})}
  282. </update>
  283. <select id="merchantCreditRanking" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="com.iformall.domain.vo.MerchantCreditRankingVo">
  284. select wm.id merchantId,wm.name merchantName,IFNULL(a.sum_credit_num,0) sumAddCredit,
  285. IFNULL(b.sum_credit_num,0) sumLesCredit,IFNULL(c.count_c_user_id,0) countAddCreditUser,
  286. IFNULL(d.count_c_user_id,0) countLesCreditUser
  287. from
  288. (
  289. select id,name from wx_merchant
  290. where is_del = 0
  291. <if test=" null != tenantId and '' != tenantId">
  292. and `tenant_id` = #{tenantId}
  293. </if>
  294. <if test=" null != parentTenantId and '' != parentTenantId">
  295. and `parent_tenant_id` = #{parentTenantId}
  296. </if>
  297. ) wm
  298. left join
  299. (
  300. select credit.merchant_id,sum(credit.credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix} credit
  301. INNER JOIN wx_c_user_basic_info${shardFinalTableSuffix} basic ON basic.id = credit.c_user_id
  302. where credit.merchant_id is not null and credit.merchant_id != -1 and credit.credit_num &gt; 0
  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.merchant_id
  310. ) a on a.merchant_id = wm.id
  311. left join
  312. (
  313. select credit.merchant_id,sum(credit.credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix} credit
  314. INNER JOIN wx_c_user_basic_info${shardFinalTableSuffix} basic ON basic.id = credit.c_user_id
  315. where credit.merchant_id is not null and credit.merchant_id != -1 and credit.credit_num &lt; 0
  316. <if test=" null != startTime ">
  317. and credit.create_date &gt;= #{startTime}
  318. </if>
  319. <if test=" null != endTime">
  320. and credit.create_date &lt; #{endTime}
  321. </if>
  322. GROUP BY credit.merchant_id
  323. ) b on b.merchant_id = wm.id
  324. left join
  325. (
  326. select credit.merchant_id,count(distinct credit.c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix} credit
  327. INNER JOIN wx_c_user_basic_info${shardFinalTableSuffix} basic ON basic.id = credit.c_user_id
  328. where credit.merchant_id is not null and credit.merchant_id != -1 and credit.credit_num &gt; 0
  329. <if test=" null != startTime ">
  330. and credit.create_date &gt;= #{startTime}
  331. </if>
  332. <if test=" null != endTime">
  333. and credit.create_date &lt; #{endTime}
  334. </if>
  335. GROUP BY credit.merchant_id
  336. ) c on c.merchant_id = wm.id
  337. left join
  338. (
  339. select credit.merchant_id,count(distinct credit.c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix} credit
  340. INNER JOIN wx_c_user_basic_info${shardFinalTableSuffix} basic ON basic.id = credit.c_user_id
  341. where credit.merchant_id is not null and credit.merchant_id != -1 and credit.credit_num &lt; 0
  342. <if test=" null != startTime ">
  343. and credit.create_date &gt;= #{startTime}
  344. </if>
  345. <if test=" null != endTime">
  346. and credit.create_date &lt;= #{endTime}
  347. </if>
  348. GROUP BY credit.merchant_id
  349. ) d on d.merchant_id = wm.id
  350. where (IFNULL(a.sum_credit_num,0) &gt; 0 or IFNULL(b.sum_credit_num,0) &lt; 0)
  351. ORDER BY sumAddCredit desc
  352. </select>
  353. </mapper>