CouponIssueMapper.xml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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.yonge.cooleshow.biz.dal.mapper.CouponIssueMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.yonge.cooleshow.biz.dal.entity.CouponIssue">
  6. <id column="id_" property="id" />
  7. <result column="user_id_" property="userId" />
  8. <result column="coupon_id_" property="couponId" />
  9. <result column="client_type_" property="clientType" />
  10. <result column="use_state_" property="useState" />
  11. <result column="use_time_" property="useTime" />
  12. <result column="order_no_" property="orderNo" />
  13. <result column="start_time_" property="startTime" />
  14. <result column="end_time_" property="endTime" />
  15. <result column="issue_way_" property="issueWay" />
  16. <result column="issuer_" property="issuer" />
  17. <result column="issue_time_" property="issueTime" />
  18. <result column="remark_" property="remark" />
  19. <result column="status_" property="status" />
  20. <result column="created_time_" property="createdTime" />
  21. </resultMap>
  22. <!-- 通用查询结果列 -->
  23. <sql id="Base_Column_List">
  24. id_, user_id_, coupon_id_, client_type_, use_state_, use_time_, order_no_, start_time_, end_time_, issue_way_, issuer_, issue_time_, remark_, status_, created_time_
  25. </sql>
  26. <select id="queryCouponIssueInfo" resultType="com.yonge.cooleshow.biz.dal.vo.coupon.CouponIssueWrapper">
  27. select
  28. su.id_ as userId,
  29. ci.id_ as couponIssueId,
  30. su.real_name_ as realName,
  31. su.username_ as username,
  32. ci.client_type_ as clientType,
  33. ci.use_state_ as useState,
  34. ci.order_no_ as orderNo,
  35. from_unixtime(ci.start_time_) as startTime,
  36. from_unixtime(ci.end_time_) as endTime,
  37. from_unixtime(ci.issue_time_) as issueTime,
  38. from_unixtime(ci.use_time_) as useTime,
  39. (case when ci.status_ = 0 then 'WITHDRAW' when ci.end_time_ &lt; unix_timestamp(now()) and ci.issue_way_ = 'USABLE' then 'EXPIRED' else ci.issue_way_ end ) as issueWay,
  40. ci.issuer_ as issuer,
  41. ci.remark_ as remark,
  42. cou.name_ as couponName,
  43. cou.id_ as couponId,
  44. cou.coupon_type_ as couponType,
  45. cou.category_ as couponCategory,
  46. cou.use_limit_ as useLimit,
  47. cou.discount_price_ as discountPrice
  48. from coupon_issue ci
  49. left join sys_user su on ci.user_id_ = su.id_
  50. left join coupon_info cou on cou.id_ = ci.coupon_id_
  51. <where>
  52. <if test="query.userId != null">
  53. and #{query.userId} = ci.user_id_
  54. </if>
  55. <if test="query.couponId != null">
  56. and #{query.couponId} = ci.coupon_id_
  57. </if>
  58. <if test="query.clientType != null">
  59. and #{query.clientType} = ci.client_type_
  60. </if>
  61. <if test="query.couponCategory != null">
  62. and #{query.couponCategory} = cou.category_
  63. </if>
  64. <if test="query.couponType != null">
  65. and #{query.couponType} = cou.coupon_type_
  66. </if>
  67. <if test="query.couponKeyword != null and query.couponKeyword != ''">
  68. and (
  69. cou.id_ like concat('%',#{query.couponKeyword},'%')
  70. or cou.name_ like concat('%',#{query.couponKeyword},'%')
  71. )
  72. </if>
  73. <if test="query.issueWay != null">
  74. <choose>
  75. <when test="query.issueWay.code == 'EXPIRED'">
  76. and ci.end_time_ &lt; unix_timestamp(now()) and ci.issue_way_ = 'USABLE'
  77. </when>
  78. <when test="query.issueWay.code == 'USABLE'">
  79. and ci.end_time_ &gt;= unix_timestamp(now()) and ci.issue_way_ = 'USABLE'
  80. </when>
  81. <when test="query.issueWay.code == 'WITHDRAW'">
  82. and ci.status_ = 0
  83. </when>
  84. <otherwise>
  85. and ci.issue_way_ = #{query.issueWay}
  86. </otherwise>
  87. </choose>
  88. </if>
  89. <if test="query.useState != null">
  90. and #{query.useState} = ci.use_state_
  91. </if>
  92. <if test="query.issueStartTime != null">
  93. and unix_timestamp( #{query.issueStartTime}) &lt;= ci.issue_time_
  94. </if>
  95. <if test="query.issueEndTime != null">
  96. and unix_timestamp(#{query.issueEndTime}) &gt;= ci.issue_time_
  97. </if>
  98. <if test="query.usedStartTime != null">
  99. and unix_timestamp(#{query.usedStartTime}) &lt;= ci.use_time_
  100. </if>
  101. <if test="query.usedEndTime != null">
  102. and unix_timestamp(#{query.usedEndTime}) &gt;= ci.use_time_
  103. </if>
  104. <if test="query.keyword !=null and query.keyword != ''">
  105. and (
  106. su.real_name_ like concat('%',#{query.keyword},'%')
  107. or su.username_ like concat('%',#{query.keyword},'%')
  108. or su.phone_ like concat('%',#{query.keyword},'%')
  109. or su.id_ like concat('%',#{query.keyword},'%')
  110. )
  111. </if>
  112. </where>
  113. order by ci.id_ desc
  114. </select>
  115. <!--用户优惠券状态统计-->
  116. <select id="selectCouponStateStatInfo" resultType="com.yonge.cooleshow.biz.dal.wrapper.StatGroupWrapper">
  117. SELECT t1.use_state_ AS gid, COUNT(DISTINCT t1.id_) AS total FROM coupon_issue t1 <if test="record.couponType != null"> JOIN coupon_info t2 ON (t1.coupon_id_ = t2.id_)</if>
  118. <where>
  119. <if test="userId != null">
  120. AND t1.user_id_ = #{userId}
  121. </if>
  122. <if test="record.clientType != null">
  123. AND t1.client_type_ = #{record.clientType}
  124. </if>
  125. <if test="record.couponType != null">
  126. AND t2.coupon_type_ = #{record.couponType}
  127. </if>
  128. </where>
  129. GROUP BY t1.use_state_
  130. </select>
  131. <!--用户优惠券状态统计-->
  132. </mapper>