LiveGoodsMapperMapper.xml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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.LiveGoodsMapperDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.LiveGoodsMapper" id="LiveGoodsMapper">
  9. <result column="id_" property="id" />
  10. <result column="goods_id_" property="goodsId" />
  11. <result column="live_id_" property="liveId" />
  12. <result column="sell_count_" property="sellCount" />
  13. <result column="status_" property="status" />
  14. <result column="create_time_" property="createTime" />
  15. <result column="update_time_" property="updateTime" />
  16. </resultMap>
  17. <!-- 根据主键查询一条记录 -->
  18. <select id="get" resultMap="LiveGoodsMapper" >
  19. SELECT * FROM live_goods_mapper WHERE id_ = #{id}
  20. </select>
  21. <!-- 全查询 -->
  22. <select id="findAll" resultMap="LiveGoodsMapper">
  23. SELECT * FROM live_goods_mapper ORDER BY id_
  24. </select>
  25. <!-- 向数据库增加一条记录 -->
  26. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.LiveGoodsMapper" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
  27. INSERT INTO live_goods_mapper (goods_id_,live_id_,sell_count_,create_time_,update_time_)
  28. VALUES(#{goodsId},#{liveId},#{sellCount},NOW(),NOW())
  29. </insert>
  30. <insert id="batchInsert">
  31. INSERT INTO live_goods_mapper (goods_id_,live_id_,create_time_,update_time_)
  32. VALUES
  33. <foreach collection="liveGoodsIds" item="goodsId" index="index" separator=",">
  34. (#{goodsId},#{liveId},NOW(),NOW())
  35. </foreach>
  36. ON DUPLICATE KEY UPDATE
  37. goods_id_ = VALUES(goods_id_),
  38. live_id_ = VALUES(live_id_)
  39. </insert>
  40. <!-- 根据主键查询一条记录 -->
  41. <update id="update" parameterType="com.ym.mec.biz.dal.entity.LiveGoodsMapper">
  42. UPDATE live_goods_mapper <set>
  43. <if test="status != null">
  44. status_ = #{status},
  45. </if>
  46. <if test="liveId != null">
  47. live_id_ = #{liveId},
  48. </if>
  49. <if test="sellCount != null">
  50. sell_count_ = #{sellCount},
  51. </if>
  52. <if test="goodsId != null">
  53. goods_id_ = #{goodsId},
  54. </if>
  55. update_time_ = NOW()
  56. </set> WHERE id_ = #{id}
  57. </update>
  58. <update id="updateStatus">
  59. UPDATE live_goods_mapper SET status_ = #{status},update_time_ = NOW()
  60. WHERE goods_id_ = #{liveGoodsId}
  61. <if test="liveId != null and liveId != ''">
  62. AND live_id_ = #{liveId}
  63. </if>
  64. </update>
  65. <!-- 根据主键删除一条记录 -->
  66. <delete id="delete" >
  67. DELETE FROM live_goods_mapper WHERE id_ = #{id}
  68. </delete>
  69. <sql id="queryPageSql">
  70. <where>
  71. <if test="liveId != null and liveId != ''">
  72. AND lgm.live_id_ = #{liveId}
  73. </if>
  74. <if test="search != null and search != ''">
  75. AND (lg.name_ LIKE CONCAT('%',#{search},'%') OR lg.id_ = #{search})
  76. </if>
  77. <if test="status != null">
  78. AND lgm.status_ = #{status}
  79. </if>
  80. <if test="liveGoodsId != null">
  81. AND lg.id_ = #{liveGoodsId}
  82. </if>
  83. </where>
  84. </sql>
  85. <!-- 分页查询 -->
  86. <select id="queryPage" resultMap="LiveGoodsMapper" parameterType="map">
  87. SELECT lg.*,lgm.status_ FROM live_goods_mapper lgm
  88. LEFT JOIN live_goods lg ON lgm.goods_id_ = lg.id_
  89. <include refid="queryPageSql" />
  90. ORDER BY lgm.id_
  91. <include refid="global.limit"/>
  92. </select>
  93. <!-- 查询当前表的总记录数 -->
  94. <select id="queryCount" resultType="int">
  95. SELECT COUNT(lgm.id_) FROM live_goods_mapper lgm
  96. LEFT JOIN live_goods lg ON lgm.goods_id_ = lg.id_
  97. <include refid="queryPageSql" />
  98. </select>
  99. <select id="findByLiveGoodsIdAndStatus" resultMap="LiveGoodsMapper">
  100. SELECT * FROM live_goods_mapper WHERE goods_id_ = #{liveGoodsId}
  101. <if test="status != null">
  102. AND status_ = #{status}
  103. </if>
  104. </select>
  105. <select id="findByLiveIdAndGoodsId" resultMap="LiveGoodsMapper">
  106. SELECT * FROM live_goods_mapper WHERE live_id_ = #{liveId} AND goods_id_ = #{liveGoodsId}
  107. </select>
  108. <sql id="queryGoodsPageSql">
  109. <where>
  110. <if test="liveId != null and liveId != ''">
  111. AND lgm.live_id_ = #{liveId}
  112. </if>
  113. <if test="status != null">
  114. AND lgm.status_ = #{status}
  115. </if>
  116. <if test="liveGoodsId != null">
  117. AND lg.id_ = #{liveGoodsId}
  118. </if>
  119. </where>
  120. </sql>
  121. <resultMap id="LiveGoodsMapperDto" type="com.ym.mec.biz.dal.dto.LiveGoodsMapperDto">
  122. <result column="id_" property="id" />
  123. <result column="image_" property="image" />
  124. <result column="status_" property="status" />
  125. <result column="name_" property="name" />
  126. <result column="original_price_" property="originalPrice" />
  127. <result column="current_price_" property="currentPrice" />
  128. <result column="goods_detail_url_" property="goodsDetailUrl" />
  129. <result column="desc_" property="desc" />
  130. <result column="stock_count_" property="stockCount" />
  131. </resultMap>
  132. <select id="getLiveGoodsList" resultMap="LiveGoodsMapperDto">
  133. SELECT lg.*,lgm.status_
  134. FROM live_goods_mapper lgm
  135. LEFT JOIN live_goods lg ON lgm.goods_id_ = lg.id_
  136. <include refid="queryGoodsPageSql"/>
  137. </select>
  138. <select id="countLiveGoods" resultType="java.lang.Integer">
  139. SELECT COUNT(lgm.id_) FROM live_goods_mapper lgm
  140. LEFT JOIN live_goods lg ON lgm.goods_id_ = lg.id_
  141. <include refid="queryPageSql" />
  142. </select>
  143. <select id="queryGoodsPage" resultMap="LiveGoodsMapperDto">
  144. SELECT lg.*,lgm.status_
  145. FROM live_goods_mapper lgm
  146. LEFT JOIN live_goods lg ON lgm.goods_id_ = lg.id_
  147. <include refid="queryPageSql" />
  148. ORDER BY lgm.id_
  149. <include refid="global.limit"/>
  150. </select>
  151. <select id="queryGoodsIdsByLiveId" resultType="java.lang.Integer">
  152. SELECT DISTINCT lgm.goods_id_ FROM live_goods_mapper lgm
  153. WHERE lgm.live_id_ = #{liveId}
  154. </select>
  155. </mapper>