LiveGoodsMapper.xml 3.9 KB

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