25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

287 lines
10 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="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" />
  8. <result column="c_user_id" jdbcType="BIGINT" property="cUserId" />
  9. <result column="credit_amount" jdbcType="INTEGER" property="creditAmount" />
  10. <result column="credit_num" jdbcType="INTEGER" property="creditNum" />
  11. <result column="credit_type" jdbcType="INTEGER" property="creditType" />
  12. <result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
  13. <result column="receipt_url" jdbcType="VARCHAR" property="receiptUrl" />
  14. <result column="operator_type" jdbcType="INTEGER" property="operatorType" />
  15. <result column="operator_id" jdbcType="BIGINT" property="operatorId" />
  16. <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
  17. <result column="coupon_id" jdbcType="BIGINT" property="couponId" />
  18. <result column="business_id" jdbcType="BIGINT" property="businessId" />
  19. <result column="spend" jdbcType="INTEGER" property="spend" />
  20. <result column="change_purpose" jdbcType="VARCHAR" property="changePurpose" />
  21. <result column="ticket_number" jdbcType="VARCHAR" property="ticketNumber"/>
  22. <result column="buser_id" jdbcType="BIGINT" property="buserId"/>
  23. </resultMap>
  24. <sql id="allColumns">
  25. `id`,`tenant_id`,`parent_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`
  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 and '' != tenantId">
  33. and `tenant_id` = #{tenantId}
  34. </if>
  35. <if test=" null != parentTenantId and '' != parentTenantId">
  36. and `parent_tenant_id` = #{parentTenantId}
  37. </if>
  38. <if test=" null != cUserId ">
  39. and `c_user_id` = #{cUserId}
  40. </if>
  41. <if test=" null != creditAmount ">
  42. and `credit_amount` = #{creditAmount}
  43. </if>
  44. <if test=" null != creditNum ">
  45. and `credit_num` = #{creditNum}
  46. </if>
  47. <if test=" null != creditType ">
  48. and `credit_type` = #{creditType}
  49. </if>
  50. <if test=" null != receiptUrl ">
  51. and `receipt_url` like concat('%', #{receiptUrl},'%')
  52. </if>
  53. <if test=" null != operatorType ">
  54. and `operator_type` = #{operatorType}
  55. </if>
  56. <if test=" null != operatorId ">
  57. and `operator_id` = #{operatorId}
  58. </if>
  59. <if test=" null != merchantId ">
  60. and `merchant_id` = #{merchantId}
  61. </if>
  62. <if test=" null != couponId ">
  63. and `coupon_id` = #{couponId}
  64. </if>
  65. <if test=" null != businessId ">
  66. and `business_id` = #{businessId}
  67. </if>
  68. <if test=" null != spend ">
  69. and `spend` = #{spend}
  70. </if>
  71. <if test=" null != changePurpose ">
  72. and `change_purpose` = #{changePurpose}
  73. </if>
  74. <if test=" null != ticketNumber and ''!=ticketNumber ">
  75. and ticket_number like concat('%', #{ticketNumber},'%')
  76. </if>
  77. <if test=" null != buserId ">
  78. and `buser_id` = #{buserId}
  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. <sql id="customWhereConditions">
  89. where 1 = 1
  90. <if test=" null != name and '' != name">
  91. and basic.nick_name like concat('%', #{name},'%')
  92. </if>
  93. <if test=" null != phone and '' != phone">
  94. and basic.phone like concat('%', #{phone},'%')
  95. </if>
  96. <if test=" null != startTime ">
  97. and credit.create_date &gt;= #{startTime}
  98. </if>
  99. <if test=" null != endTime">
  100. and credit.create_date &lt; #{endTime}
  101. </if>
  102. <if test=" null != tenantId and '' != tenantId">
  103. and credit.`tenant_id` = #{tenantId}
  104. </if>
  105. <if test=" null != parentTenantId and '' != parentTenantId">
  106. and credit.`parent_tenant_id` = #{parentTenantId}
  107. </if>
  108. <if test=" null != operatorType ">
  109. and credit.operator_type = #{operatorType}
  110. </if>
  111. <if test=" null != operatorId ">
  112. and credit.operator_id = #{operatorId}
  113. </if>
  114. <if test=" null != creditType ">
  115. and credit.credit_type = #{creditType}
  116. </if>
  117. <if test=" null != cUserId ">
  118. and credit.c_user_id = #{cUserId}
  119. </if>
  120. <if test=" null != merchantId ">
  121. and credit.merchant_id = #{merchantId}
  122. </if>
  123. <if test=" null != merchantName and ''!=merchantName ">
  124. and merchant.name like concat('%', #{merchantName},'%')
  125. </if>
  126. <if test=" null != ticketNumber and ''!=ticketNumber ">
  127. and credit.ticket_number like concat('%', #{ticketNumber},'%')
  128. </if>
  129. <if test=" null != buserId ">
  130. and credit.buser_id = #{buserId}
  131. </if>
  132. </sql>
  133. <select id="findList" parameterType="com.iformall.domain.po.WxCreditHistory" resultMap="BaseResultMap">
  134. select <include refid="allColumns" /> from wx_credit_history
  135. <include refid="dynamicWhereConditions" />
  136. </select>
  137. <select id="findListMore" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="com.iformall.domain.vo.WxCreditHistoryVo">
  138. SELECT
  139. credit.id creditId,
  140. case when basic.nick_name is null then basic.name else basic.nick_name end name,
  141. basic.phone phone,
  142. basic.sex sex,
  143. credit.tenant_id tenantId,
  144. credit.parent_tenant_id parentTenantId,
  145. credit.c_user_id cUserId,
  146. credit.credit_amount creditAmount,
  147. credit.credit_num creditNum,
  148. credit.create_date createDate,
  149. credit.credit_type creditType,
  150. credit.receipt_url receiptUrl,
  151. credit.operator_type operatorType,
  152. credit.operator_id operatorId,
  153. merchant.NAME merchantName,
  154. credit.merchant_id merchantId,
  155. credit.ticket_number ticketNumber,
  156. case when credit.operator_type=4 then (select name from mall_user_info where id=credit.operator_id)
  157. when credit.operator_type=3 then (select name from wx_merchant_b_user where id=credit.operator_id)
  158. when credit.operator_type=1 then (select nick_name from wx_c_user where id=credit.operator_id)
  159. else '' end operator,
  160. credit.change_purpose changePurpose
  161. FROM
  162. wx_c_user_basic_info basic
  163. INNER JOIN wx_credit_history credit ON basic.id = credit.c_user_id
  164. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  165. <include refid="customWhereConditions"/>
  166. ORDER BY
  167. credit.create_date desc,credit.id DESC
  168. </select>
  169. <select id="loginCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Integer">
  170. select COUNT(0) from wx_credit_history
  171. where 1=1
  172. <if test=" null != tenantId and '' != tenantId">
  173. and `tenant_id` = #{tenantId}
  174. </if>
  175. <if test=" null != parentTenantId and '' != parentTenantId">
  176. and `parent_tenant_id` = #{parentTenantId}
  177. </if>
  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 DATEDIFF(`create_date`,now())=0
  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 ">
  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 != parentTenantId and '' != parentTenantId">
  212. and `parent_tenant_id` = #{parentTenantId}
  213. </if>
  214. <if test=" null != cUserId ">
  215. and `c_user_id` = #{cUserId}
  216. </if>
  217. <if test=" null != creditType ">
  218. and `credit_type` = #{creditType}
  219. </if>
  220. </select>
  221. <update id="updateNewId" parameterType="com.iformall.domain.vo.WxCreditHistoryNewIdVo">
  222. update wx_credit_history
  223. set c_user_id=#{newUserId}
  224. where c_user_id = #{cUserId}
  225. <if test=" null != tenantId and '' != tenantId">
  226. and `tenant_id` = #{tenantId}
  227. </if>
  228. <if test=" null != parentTenantId and '' != parentTenantId">
  229. and `parent_tenant_id` = #{parentTenantId}
  230. </if>
  231. </update>
  232. <select id="getTotalCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
  233. resultType="java.lang.Long">
  234. select ifnull(sum(credit.amount),0) amount from (
  235. select basic.credit as amount,credit.c_user_id from wx_credit_history credit
  236. INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
  237. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  238. <include refid="customWhereConditions"/>
  239. group by credit.c_user_id
  240. ) credit
  241. </select>
  242. <select id="getIncrementCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
  243. resultType="java.lang.Long">
  244. select ifnull(sum(credit.credit_num),0) amount from wx_credit_history credit
  245. INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
  246. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  247. <include refid="customWhereConditions"/>
  248. and credit.credit_num>0
  249. </select>
  250. <select id="getDecrementCreditAmount" parameterType="com.iformall.domain.po.WxCreditHistory"
  251. resultType="java.lang.Long">
  252. select ABS(ifnull(sum(credit.credit_num),0)) amount from wx_credit_history credit
  253. INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
  254. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  255. <include refid="customWhereConditions"/>
  256. and credit.credit_num &lt; 0
  257. </select>
  258. <select id="getPeopleCount" parameterType="com.iformall.domain.po.WxCreditHistory" resultType="java.lang.Long">
  259. select count(*) people from (
  260. select count(*) people from wx_credit_history credit
  261. INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
  262. LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
  263. <include refid="customWhereConditions"/>
  264. group by credit.c_user_id
  265. ) credit
  266. </select>
  267. </mapper>