CouponReceiveMapper.xml 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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.CouponReceive" id="CouponReceiveMap">
  5. <result property="id" column="id" jdbcType="VARCHAR"/>
  6. <result property="openid" column="openid" jdbcType="VARCHAR"/>
  7. <result property="couponId" column="coupon_id" jdbcType="VARCHAR"/>
  8. <result property="expirationTime" column="expiration_time" jdbcType="TIMESTAMP"/>
  9. <result property="useState" column="use_state" jdbcType="INTEGER"/>
  10. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  11. <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
  12. <result property="isDelete" column="is_delete" jdbcType="INTEGER"/>
  13. </resultMap>
  14. <resultMap type="com.ylx.massage.domain.vo.CouponReceiveVo" id="CouponReceiveVoMap">
  15. <result property="id" column="id" jdbcType="VARCHAR"/>
  16. <result property="openid" column="openid" jdbcType="VARCHAR"/>
  17. <result property="couponId" column="coupon_id" jdbcType="VARCHAR"/>
  18. <result property="expirationTime" column="expiration_time" jdbcType="TIMESTAMP"/>
  19. <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
  20. <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
  21. <result property="isDelete" column="is_delete" jdbcType="INTEGER"/>
  22. <result property="name" column="name" jdbcType="VARCHAR"/>
  23. <result property="type" column="type" jdbcType="INTEGER"/>
  24. <result property="discountType" column="discount_type" jdbcType="INTEGER"/>
  25. <result property="discountValue" column="discount_value" jdbcType="NUMERIC"/>
  26. <result property="thresholdAmount" column="threshold_amount" jdbcType="NUMERIC"/>
  27. <result property="obtainWay" column="obtain_way" jdbcType="INTEGER"/>
  28. <result property="termDays" column="term_days" jdbcType="INTEGER"/>
  29. <result property="status" column="status" jdbcType="INTEGER"/>
  30. <result property="usedNum" column="used_num" jdbcType="INTEGER"/>
  31. <result property="userLimit" column="user_limit" jdbcType="INTEGER"/>
  32. <result property="extParam" column="ext_param" jdbcType="VARCHAR"/>
  33. <result property="rebValue" column="reb_value" jdbcType="VARCHAR"/>
  34. </resultMap>
  35. <sql id="selectCouponReceiveVo">
  36. a.id, a.openid, a.coupon_id, a.expiration_time, a.create_time, a.update_time, a.is_delete,a.use_state,
  37. b.name, b.type, b.discount_type, b.discount_value, b.threshold_amount, b.obtain_way, b.term_days, b.status, b.used_num, b.user_limit, b.ext_param,b.reb_value
  38. </sql>
  39. <!-- 批量插入 -->
  40. <insert id="insertBatch" keyProperty="id">
  41. insert into coupon_receive(id,openid,coupon_id,expiration_time,dept_id,dept_name)
  42. values
  43. <foreach collection="entities" item="entity" separator=",">
  44. (#{entity.id},#{entity.openid},#{entity.couponId},#{entity.expirationTime},#{entity.deptId},#{entity.deptName})
  45. </foreach>
  46. </insert>
  47. <!-- 批量插入或按主键更新 -->
  48. <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
  49. insert into coupon_receive(openid,coupon_id,expiration_time,dept_id,dept_name,create_time,update_time,is_delete)
  50. values
  51. <foreach collection="entities" item="entity" separator=",">
  52. (#{entity.openid},#{entity.couponId},#{entity.expirationTime},#{entity.deptId},#{entity.deptName},#{entity.createTime},#{entity.updateTime},#{entity.isDelete})
  53. </foreach>
  54. on duplicate key update
  55. openid = values(openid),
  56. coupon_id = values(coupon_id),
  57. expiration_time = values(expiration_time),
  58. dept_id = values(dept_id),
  59. dept_name = values(dept_name),
  60. create_time = values(create_time),
  61. update_time = values(update_time),
  62. is_delete = values(is_delete)
  63. </insert>
  64. <select id="getByOpenId" resultMap="CouponReceiveVoMap">
  65. SELECT
  66. <include refid="selectCouponReceiveVo"/>
  67. FROM coupon_receive a
  68. LEFT JOIN coupon b ON a.coupon_id = b.id
  69. WHERE a.is_delete = 0
  70. AND b.is_delete = 0
  71. and a.expiration_time &gt;= now()
  72. and a.openid = #{openid}
  73. </select>
  74. </mapper>