GoodsMapper.xml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.GoodsDao">
  8. <resultMap type="com.ym.mec.biz.dal.entity.Goods" id="Goods">
  9. <result column="id_" property="id"/>
  10. <result column="goods_category_id_" property="goodsCategoryId"/>
  11. <result column="goods_category_name_" property="goodsCategoryName"/>
  12. <result column="sn_" property="sn"/>
  13. <result column="name_" property="name"/>
  14. <result column="brand_" property="brand"/>
  15. <result column="specification_" property="specification"/>
  16. <result column="image_" property="image"/>
  17. <result column="stock_count_" property="stockCount"/>
  18. <result column="sell_count_" property="sellCount"/>
  19. <result column="market_price_" property="marketPrice"/>
  20. <result column="discount_price_" property="discountPrice"/>
  21. <result column="group_purchase_price_" property="groupPurchasePrice"/>
  22. <result column="brief_" property="brief"/>
  23. <result column="desc_" property="desc"/>
  24. <result column="is_new_" property="isNew" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  25. <result column="is_top_" property="isTop" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  26. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  27. <result column="memo_" property="memo"/>
  28. <result column="publish_time_" property="publishTime"/>
  29. <result column="create_time_" property="createTime"/>
  30. <result column="update_time_" property="updateTime"/>
  31. <result column="complement_goods_id_list_" property="complementGoodsIdList"/>
  32. <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  33. </resultMap>
  34. <!-- 根据主键查询一条记录 -->
  35. <select id="get" resultMap="Goods">
  36. SELECT * FROM goods WHERE id_ = #{id}
  37. </select>
  38. <!-- 全查询 -->
  39. <select id="findAll" resultMap="Goods">
  40. SELECT * FROM goods ORDER BY id_
  41. </select>
  42. <!-- 向数据库增加一条记录 -->
  43. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Goods" useGeneratedKeys="true" keyColumn="id"
  44. keyProperty="id">
  45. INSERT INTO goods
  46. (goods_category_id_,sn_,name_,brand_,specification_,image_,stock_count_,sell_count_,market_price_,discount_price_,group_purchase_price_,brief_,desc_,is_new_,is_top_,status_,memo_,publish_time_,complement_goods_id_list_,update_time_,create_time_,type_)
  47. VALUES(#{goodsCategoryId},#{sn},#{name},#{brand},#{specification},#{image},#{stockCount},#{sellCount},#{marketPrice},#{discountPrice},#{groupPurchasePrice},#{brief},#{desc},
  48. #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  49. #{memo},#{publishTime},#{complementGoodsIdList},now(),now(),#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler})
  50. </insert>
  51. <!-- 根据主键查询一条记录 -->
  52. <update id="update" parameterType="com.ym.mec.biz.dal.entity.Goods">
  53. UPDATE goods
  54. <set>
  55. <if test="specification != null">
  56. specification_ = #{specification},
  57. </if>
  58. <if test="status != null">
  59. status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  60. </if>
  61. <if test="isTop != null">
  62. is_top_ = #{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  63. </if>
  64. <if test="type != null">
  65. type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  66. </if>
  67. <if test="sn != null">
  68. sn_ = #{sn},
  69. </if>
  70. <if test="marketPrice != null">
  71. market_price_ = #{marketPrice},
  72. </if>
  73. <if test="memo != null">
  74. memo_ = #{memo},
  75. </if>
  76. <if test="isNew != null">
  77. is_new_ = #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  78. </if>
  79. <if test="groupPurchasePrice != null">
  80. group_purchase_price_ = #{groupPurchasePrice},
  81. </if>
  82. <if test="name != null">
  83. name_ = #{name},
  84. </if>
  85. <if test="stockCount != null">
  86. stock_count_ = #{stockCount},
  87. </if>
  88. <if test="goodsCategoryId != null">
  89. goods_category_id_ = #{goodsCategoryId},
  90. </if>
  91. <if test="brand != null">
  92. brand_ = #{brand},
  93. </if>
  94. <if test="brief != null">
  95. brief_ = #{brief},
  96. </if>
  97. <if test="updateTime != null">
  98. update_time_ = NOW(),
  99. </if>
  100. <if test="discountPrice != null">
  101. discount_price_ = #{discountPrice},
  102. </if>
  103. <if test="sellCount != null">
  104. sell_count_ = #{sellCount},
  105. </if>
  106. <if test="image != null">
  107. image_ = #{image},
  108. </if>
  109. <if test="desc != null">
  110. desc_ = #{desc},
  111. </if>
  112. <if test="publishTime != null">
  113. publish_time_ = #{publishTime},
  114. </if>
  115. <if test="complementGoodsIdList != null">
  116. complement_goods_id_list_ = #{complementGoodsIdList},
  117. </if>
  118. </set>
  119. WHERE id_ = #{id}
  120. </update>
  121. <!-- 根据主键删除一条记录 -->
  122. <delete id="delete">
  123. DELETE FROM goods WHERE id_ = #{id}
  124. </delete>
  125. <!-- 分页查询 -->
  126. <select id="queryPage" resultMap="Goods" parameterType="map">
  127. SELECT g.*,gc.name_ goods_category_name_ FROM goods g
  128. LEFT JOIN goods_category gc ON g.goods_category_id_ = gc.id_
  129. <include refid="queryGoodsPageSql"/>
  130. ORDER BY g.id_
  131. <include refid="global.limit"/>
  132. </select>
  133. <sql id="queryGoodsPageSql">
  134. <where>
  135. <if test="goodsCategoryId != null">
  136. g.goods_category_id_ = #{goodsCategoryId}
  137. </if>
  138. <if test="isNew != null">
  139. g.is_new_ = #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  140. </if>
  141. <if test="isTop != null">
  142. g.is_top_ = #{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  143. </if>
  144. <if test="status != null">
  145. g.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  146. </if>
  147. </where>
  148. </sql>
  149. <!-- 查询当前表的总记录数 -->
  150. <select id="queryCount" resultType="int">
  151. SELECT COUNT(*) FROM goods g
  152. <include refid="queryGoodsPageSql"/>
  153. </select>
  154. <select id="findGoodsBySubId" resultMap="Goods">
  155. SELECT g.* FROM subject_goods_mapper sgm
  156. LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
  157. WHERE sgm.subject_id_ = #{subjectId} AND g.type_ = #{type} and g.status_ != 0
  158. </select>
  159. <!-- 根据 -->
  160. <select id="findGoodsNumByCategoryId" resultType="int">
  161. SELECT COUNT(*) FROM goods WHERE goods_category_id_ = #{goodsCategoryId}
  162. </select>
  163. <select id="findGoodsByIds" resultMap="Goods">
  164. SELECT * FROM goods WHERE FIND_IN_SET(id_,#{ids})
  165. </select>
  166. <select id="findTypeGoods" resultMap="Goods">
  167. SELECT * FROM goods WHERE type_ = #{type}
  168. </select>
  169. </mapper>