CouponReceiveMapper.xml 3.4 KB

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