CouponReceiveMapper.xml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.ylx.massage.mapper.CouponReceiveMapper">
  4. <resultMap id="CouponReceiveVoMap" type="com.ylx.massage.domain.vo.CouponReceiveVo">
  5. <result property="id" column="id" jdbcType="VARCHAR"/>
  6. <result property="openid" column="receive_open_id" jdbcType="VARCHAR"/>
  7. <result property="couponId" column="coupon_id" jdbcType="VARCHAR"/>
  8. <result property="couponName" column="coupon_name" jdbcType="VARCHAR"/>
  9. <result property="couponType" column="coupon_type" jdbcType="INTEGER"/>
  10. <result property="validityType" column="validity_type" jdbcType="INTEGER"/>
  11. <result property="validStartTime" column="valid_start_time" jdbcType="TIMESTAMP"/>
  12. <result property="expirationTime" column="expiration_time" jdbcType="TIMESTAMP"/>
  13. <result property="ruleMinSpendAmount" column="rule_min_spend_amount" jdbcType="DECIMAL"/>
  14. <result property="ruleDiscountRate" column="rule_discount_rate" jdbcType="DECIMAL"/>
  15. <result property="ruleDiscountCapAmount" column="rule_discount_cap_amount" jdbcType="DECIMAL"/>
  16. <result property="ruleReductionAmount" column="rule_reduction_amount" jdbcType="DECIMAL"/>
  17. </resultMap>
  18. <sql id="selectCouponReceiveVo">
  19. distinct a.id, a.receive_open_id, a.coupon_id, b.coupon_name,a.validity_type,a.valid_start_time,a.expiration_time,a.coupon_status,b.market_price,a.create_time, a.update_time, a.is_delete
  20. </sql>
  21. <!-- 批量插入 -->
  22. <insert id="insertBatch" keyProperty="id">
  23. insert into coupon_receive(id,openid,coupon_id,expiration_time,dept_id,dept_name)
  24. values
  25. <foreach collection="entities" item="entity" separator=",">
  26. (#{entity.id},#{entity.openid},#{entity.couponId},#{entity.expirationTime},#{entity.deptId},#{entity.deptName})
  27. </foreach>
  28. </insert>
  29. <!-- 批量插入或按主键更新 -->
  30. <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
  31. insert into coupon_receive(openid,coupon_id,expiration_time,dept_id,dept_name,create_time,update_time,is_delete)
  32. values
  33. <foreach collection="entities" item="entity" separator=",">
  34. (#{entity.openid},#{entity.couponId},#{entity.expirationTime},#{entity.deptId},#{entity.deptName},#{entity.createTime},#{entity.updateTime},#{entity.isDelete})
  35. </foreach>
  36. on duplicate key update
  37. openid = values(openid),
  38. coupon_id = values(coupon_id),
  39. expiration_time = values(expiration_time),
  40. dept_id = values(dept_id),
  41. dept_name = values(dept_name),
  42. create_time = values(create_time),
  43. update_time = values(update_time),
  44. is_delete = values(is_delete)
  45. </insert>
  46. <!-- 查询我的待使用的优惠券 -->
  47. <!--<select id="getByOpenId" resultMap="CouponReceiveVoMap">
  48. SELECT
  49. <include refid="selectCouponReceiveVo"/>
  50. FROM coupon_receive a
  51. LEFT JOIN coupon b ON a.coupon_id = b.id
  52. WHERE a.is_delete = 0
  53. AND b.is_delete = 0
  54. AND a.use_state = 0
  55. and a.expiration_time &gt;= now()
  56. and a.openid = #{openid}
  57. </select>-->
  58. <select id="getByOpenId" resultMap="CouponReceiveVoMap">
  59. SELECT
  60. <include refid="selectCouponReceiveVo"/>
  61. FROM coupon_receive a
  62. LEFT JOIN user_coupon_relation b ON a.coupon_id = b.coupon_id
  63. WHERE a.is_delete = 0
  64. AND a.coupon_status = 0
  65. and a.receive_open_id = #{openid}
  66. </select>
  67. </mapper>