LiveGoodsMapper.xml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. <!--
  4. 这个文件是自动生成的。
  5. 不要修改此文件。所有改动将在下次重新自动生成时丢失。
  6. -->
  7. <mapper namespace="com.ym.mec.biz.dal.dao.LiveGoodsDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.LiveGoods" id="LiveGoods">
  9. <result column="id_" property="id" />
  10. <result column="name_" property="name" />
  11. <result column="image_" property="image" />
  12. <result column="stock_count_" property="stockCount" />
  13. <result column="sell_count_" property="sellCount" />
  14. <result column="current_price_" property="currentPrice" />
  15. <result column="original_price_" property="originalPrice" />
  16. <result column="goods_detail_url_" property="goodsDetailUrl" />
  17. <result column="desc_" property="desc" />
  18. <result column="create_time_" property="createTime" />
  19. <result column="update_time_" property="updateTime" />
  20. <result column="tenant_id_" property="tenantId" />
  21. <result column="status_" property="status" />
  22. </resultMap>
  23. <!-- 根据主键查询一条记录 -->
  24. <select id="get" resultMap="LiveGoods" >
  25. SELECT * FROM live_goods WHERE id_ = #{id}
  26. </select>
  27. <!-- 全查询 -->
  28. <select id="findAll" resultMap="LiveGoods">
  29. SELECT * FROM live_goods ORDER BY id_
  30. </select>
  31. <!-- 向数据库增加一条记录 -->
  32. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.LiveGoods" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  33. INSERT INTO live_goods (name_,image_,stock_count_,sell_count_,current_price_,
  34. original_price_,goods_detail_url_,desc_,
  35. create_time_,update_time_,tenant_id_)
  36. VALUES(#{name},#{image},#{stockCount},#{sellCount},#{currentPrice},
  37. #{originalPrice},#{goodsDetailUrl},#{desc},NOW(),NOW(),#{tenantId})
  38. </insert>
  39. <insert id="addStock">
  40. UPDATE live_goods SET stock_count_ = stock_count_ + 1 WHERE id_ = #{liveGoodsId}
  41. </insert>
  42. <!-- 根据主键查询一条记录 -->
  43. <update id="update" parameterType="com.ym.mec.biz.dal.entity.LiveGoods">
  44. UPDATE live_goods <set>
  45. <if test="tenantId != null">
  46. tenant_id_ = #{tenantId},
  47. </if>
  48. <if test="originalPrice != null">
  49. original_price_ = #{originalPrice},
  50. </if>
  51. <if test="name != null">
  52. name_ = #{name},
  53. </if>
  54. <if test="stockCount != null">
  55. stock_count_ = #{stockCount},
  56. </if>
  57. <if test="currentPrice != null">
  58. current_price_ = #{currentPrice},
  59. </if>
  60. <if test="sellCount != null">
  61. sell_count_ = #{sellCount},
  62. </if>
  63. <if test="image != null">
  64. image_ = #{image},
  65. </if>
  66. <if test="desc != null">
  67. desc_ = #{desc},
  68. </if>
  69. <if test="goodsDetailUrl != null">
  70. goods_detail_url_ = #{goodsDetailUrl},
  71. </if>
  72. update_time_ = NOW()
  73. </set> WHERE id_ = #{id}
  74. </update>
  75. <update id="reduceStock">
  76. UPDATE live_goods SET stock_count_ = stock_count_ - 1 WHERE id_ = #{liveGoodsId} AND stock_count_ > 0
  77. </update>
  78. <!-- 根据主键删除一条记录 -->
  79. <delete id="delete" >
  80. DELETE FROM live_goods WHERE id_ = #{id}
  81. </delete>
  82. <sql id="queryPageSql">
  83. <where>
  84. <if test="search != null and search != ''">
  85. AND (name_ like '%${search}%' OR id_ = #{search})
  86. </if>
  87. <if test="ignoreGoodsIds != null and ignoreGoodsIds.size > 0">
  88. AND id_ NOT IN
  89. <foreach collection="ignoreGoodsIds" item="ignoreGoodsId" open="(" separator="," close=")">
  90. #{ignoreGoodsId}
  91. </foreach>
  92. </if>
  93. </where>
  94. </sql>
  95. <!-- 分页查询 -->
  96. <select id="queryPage" resultMap="LiveGoods" parameterType="map">
  97. SELECT * FROM live_goods
  98. <include refid="queryPageSql" />
  99. ORDER BY id_
  100. <include refid="global.limit"/>
  101. </select>
  102. <!-- 查询当前表的总记录数 -->
  103. <select id="queryCount" resultType="int">
  104. SELECT COUNT(*) FROM live_goods
  105. <include refid="queryPageSql" />
  106. </select>
  107. <select id="getLock" resultMap="LiveGoods">
  108. SELECT * FROM live_goods WHERE id_ = #{id} LIMIT 1 FOR UPDATE
  109. </select>
  110. <select id="getByName" resultMap="LiveGoods">
  111. SELECT * FROM live_goods WHERE name_ = #{name} LIMIT 1
  112. </select>
  113. </mapper>