UserCouponDao.xml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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.kmall.admin.dao.UserCouponDao">
  4. <resultMap type="com.kmall.admin.entity.UserCouponEntity" id="userCouponMap">
  5. <result property="id" column="id"/>
  6. <result property="couponId" column="coupon_id"/>
  7. <result property="couponNumber" column="coupon_number"/>
  8. <result property="userId" column="user_id"/>
  9. <result property="usedTime" column="used_time"/>
  10. <result property="orderId" column="order_id"/>
  11. <result property="addTime" column="add_time"/>
  12. <result property="isUsed" column="is_used"/>
  13. </resultMap>
  14. <select id="queryObject" resultType="com.kmall.admin.entity.UserCouponEntity">
  15. select
  16. `id`,
  17. `coupon_id`,
  18. `coupon_number`,
  19. `user_id`,
  20. `used_time`,
  21. `add_time`,
  22. `order_id`,
  23. `is_used`
  24. from mall_user_coupon
  25. where id = #{id}
  26. </select>
  27. <select id="queryByOrderId" resultType="com.kmall.admin.entity.UserCouponEntity">
  28. select
  29. `id`,
  30. `coupon_id`,
  31. `coupon_number`,
  32. `user_id`,
  33. `used_time`,
  34. `add_time`,
  35. `order_id`,
  36. `is_used`
  37. from mall_user_coupon
  38. where order_id = #{orderId}
  39. </select>
  40. <select id="queryList" resultType="com.kmall.admin.entity.UserCouponEntity">
  41. select
  42. mall_user_coupon.id,
  43. mall_user_coupon.coupon_id,
  44. mall_user_coupon.coupon_number,
  45. mall_user_coupon.user_id,
  46. mall_user_coupon.used_time,
  47. mall_user_coupon.add_time,
  48. mall_user_coupon.order_id,
  49. mall_user_coupon.is_used,
  50. mall_user.username user_name,
  51. mall_coupon.name coupon_name
  52. from mall_user_coupon
  53. LEFT JOIN mall_user ON mall_user_coupon.user_id = mall_user.id
  54. LEFT JOIN mall_coupon ON mall_user_coupon.coupon_id = mall_coupon.id
  55. WHERE 1=1
  56. <if test="userName != null and userName.trim() != ''">
  57. AND mall_user.username LIKE concat('%',#{userName},'%')
  58. </if>
  59. <if test="couponName != null and couponName.trim() != ''">
  60. AND mall_coupon.name LIKE concat('%',#{couponName},'%')
  61. </if>
  62. <if test="userId != null">
  63. AND mall_user_coupon.user_id = #{userId}
  64. </if>
  65. <choose>
  66. <when test="sidx != null and sidx.trim() != ''">
  67. order by ${sidx} ${order}
  68. </when>
  69. <otherwise>
  70. order by mall_user_coupon.id desc
  71. </otherwise>
  72. </choose>
  73. <if test="offset != null and limit != null">
  74. limit #{offset}, #{limit}
  75. </if>
  76. </select>
  77. <select id="queryTotal" resultType="int">
  78. select count(*)
  79. from mall_user_coupon LEFT JOIN mall_user ON mall_user_coupon.user_id = mall_user.id
  80. LEFT JOIN mall_coupon ON mall_user_coupon.coupon_id = mall_coupon.id
  81. WHERE 1=1
  82. <if test="userName != null and userName.trim() != ''">
  83. AND mall_user.username LIKE concat('%',#{userName},'%')
  84. </if>
  85. <if test="couponName != null and couponName.trim() != ''">
  86. AND mall_coupon.name LIKE concat('%',#{couponName},'%')
  87. </if>
  88. <if test="userId != null">
  89. AND mall_user_coupon.user_id = #{userId}
  90. </if>
  91. </select>
  92. <insert id="save" parameterType="com.kmall.admin.entity.UserCouponEntity" useGeneratedKeys="true" keyProperty="id">
  93. insert into mall_user_coupon(
  94. `coupon_id`,
  95. `coupon_number`,
  96. `user_id`,
  97. `used_time`,
  98. `add_time`,
  99. `order_id`,
  100. `is_used`)
  101. values(
  102. #{couponId},
  103. #{couponNumber},
  104. #{userId},
  105. #{usedTime},
  106. #{addTime},
  107. #{orderId},
  108. #{isUsed})
  109. </insert>
  110. <update id="update" parameterType="com.kmall.admin.entity.UserCouponEntity">
  111. update mall_user_coupon
  112. <set>
  113. <if test="couponId != null">`coupon_id` = #{couponId},</if>
  114. <if test="couponNumber != null">`coupon_number` = #{couponNumber},</if>
  115. <if test="userId != null">`user_id` = #{userId},</if>
  116. <if test="usedTime != null">`used_time` = #{usedTime},</if>
  117. <if test="addTime != null">`add_time` = #{addTime},</if>
  118. <if test="orderId != null">`order_id` = #{orderId}</if>
  119. <if test="isUsed != null">`is_used` = #{isUsed}</if>
  120. </set>
  121. where id = #{id}
  122. </update>
  123. <update id="cancelOrder" parameterType="com.kmall.admin.entity.UserCouponEntity">
  124. update mall_user_coupon
  125. <set>
  126. `used_time` = null,
  127. `order_id` = 0
  128. </set>
  129. where id = #{id}
  130. </update>
  131. <delete id="delete">
  132. delete from mall_user_coupon where id = #{value}
  133. </delete>
  134. <delete id="deleteBatch">
  135. delete from mall_user_coupon where id in
  136. <foreach item="id" collection="array" open="(" separator="," close=")">
  137. #{id}
  138. </foreach>
  139. </delete>
  140. </mapper>