GoodsMapper.xml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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="tax_stock_count_" property="taxStockCount"/>
  19. <result column="sell_count_" property="sellCount"/>
  20. <result column="market_price_" property="marketPrice"/>
  21. <result column="discount_price_" property="discountPrice"/>
  22. <result column="group_purchase_price_" property="groupPurchasePrice"/>
  23. <result column="agree_cost_price_" property="agreeCostPrice"/>
  24. <result column="brief_" property="brief"/>
  25. <result column="desc_" property="desc"/>
  26. <result column="is_new_" property="isNew" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  27. <result column="is_top_" property="isTop" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  28. <result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  29. <result column="memo_" property="memo"/>
  30. <result column="publish_time_" property="publishTime"/>
  31. <result column="create_time_" property="createTime"/>
  32. <result column="update_time_" property="updateTime"/>
  33. <result column="complement_goods_id_list_" property="complementGoodsIdList"/>
  34. <result column="type_" property="type" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  35. <result column="supply_channel_" property="supplyChannel" />
  36. <result column="stock_type_" property="stockType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  37. <result column="client_show_" property="clientShow" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  38. <result column="educational_show_" property="educationalShow" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  39. <result column="music_group_show_" property="musicGroupShow" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  40. <result column="stock_warning_" property="stockWarning" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  41. </resultMap>
  42. <!-- 根据主键查询一条记录 -->
  43. <select id="get" resultMap="Goods" useCache="false" flushCache="true">
  44. SELECT * FROM goods WHERE id_ = #{id}
  45. </select>
  46. <select id="lock" resultMap="Goods" useCache="false" flushCache="true">
  47. SELECT * FROM goods WHERE id_ = #{goodsId} LOCK IN SHARE MODE
  48. </select>
  49. <!-- 全查询 -->
  50. <select id="findAll" resultMap="Goods">
  51. SELECT * FROM goods ORDER BY id_
  52. </select>
  53. <!-- 向数据库增加一条记录 -->
  54. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Goods" useGeneratedKeys="true" keyColumn="id"
  55. keyProperty="id">
  56. INSERT INTO goods
  57. (goods_category_id_,sn_,name_,brand_,specification_,image_,stock_count_,tax_stock_count_,sell_count_,market_price_,
  58. discount_price_,group_purchase_price_,brief_,desc_,is_new_,is_top_,status_,memo_,publish_time_,
  59. complement_goods_id_list_,update_time_,create_time_,type_,agree_cost_price_,client_show_,educational_show_,music_group_show_,stock_warning_,stock_type_)
  60. VALUES(#{goodsCategoryId},#{sn},#{name},#{brand},#{specification},#{image},#{stockCount},#{taxStockCount},#{sellCount},#{marketPrice},
  61. #{discountPrice},#{groupPurchasePrice},#{brief},#{desc},
  62. #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  63. #{memo},#{publishTime},#{complementGoodsIdList},now(),now(),#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{agreeCostPrice},
  64. #{clientShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{educationalShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  65. #{musicGroupShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  66. #{stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler})
  67. </insert>
  68. <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
  69. INSERT INTO goods
  70. (goods_category_id_,name_,brand_,specification_,image_,market_price_,
  71. discount_price_,group_purchase_price_,brief_,desc_,update_time_,create_time_,type_,agree_cost_price_,sn_,
  72. stock_count_,tax_stock_count_,client_show_,educational_show_,music_group_show_,stock_warning_,stock_type_)
  73. VALUES
  74. <foreach collection="list" separator="," item="goods">
  75. (#{goods.goodsCategoryId},#{goods.name},#{goods.brand},#{goods.specification},#{goods.image},#{goods.marketPrice},
  76. #{goods.discountPrice},#{goods.groupPurchasePrice},#{goods.brief},#{goods.desc},now(),now(),
  77. #{goods.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{goods.agreeCostPrice},#{goods.sn},
  78. #{goods.stockCount},#{goods.taxStockCount},#{goods.clientShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  79. #{goods.educationalShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  80. #{goods.musicGroupShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  81. #{goods.stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  82. #{goods.stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler})
  83. </foreach>
  84. </insert>
  85. <!-- 根据主键查询一条记录 -->
  86. <update id="update" parameterType="com.ym.mec.biz.dal.entity.Goods">
  87. UPDATE goods
  88. <set>
  89. <if test="agreeCostPrice != null">
  90. agree_cost_price_ = #{agreeCostPrice},
  91. </if>
  92. <if test="specification != null">
  93. specification_ = #{specification},
  94. </if>
  95. <if test="status != null">
  96. status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  97. </if>
  98. <if test="isTop != null">
  99. is_top_ = #{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  100. </if>
  101. <if test="type != null">
  102. type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  103. </if>
  104. <if test="sn != null">
  105. sn_ = #{sn},
  106. </if>
  107. <if test="marketPrice != null">
  108. market_price_ = #{marketPrice},
  109. </if>
  110. <if test="memo != null">
  111. memo_ = #{memo},
  112. </if>
  113. <if test="isNew != null">
  114. is_new_ = #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  115. </if>
  116. <if test="groupPurchasePrice != null">
  117. group_purchase_price_ = #{groupPurchasePrice},
  118. </if>
  119. <if test="name != null">
  120. name_ = #{name},
  121. </if>
  122. <if test="stockCount != null">
  123. stock_count_ = #{stockCount},
  124. </if>
  125. <if test="goodsCategoryId != null">
  126. goods_category_id_ = #{goodsCategoryId},
  127. </if>
  128. <if test="brand != null">
  129. brand_ = #{brand},
  130. </if>
  131. <if test="brief != null">
  132. brief_ = #{brief},
  133. </if>
  134. <if test="discountPrice != null">
  135. discount_price_ = #{discountPrice},
  136. </if>
  137. <if test="sellCount != null">
  138. sell_count_ = #{sellCount},
  139. </if>
  140. <if test="image != null">
  141. image_ = #{image},
  142. </if>
  143. <if test="desc != null">
  144. desc_ = #{desc},
  145. </if>
  146. <if test="publishTime != null">
  147. publish_time_ = #{publishTime},
  148. </if>
  149. <if test="complementGoodsIdList != null">
  150. complement_goods_id_list_ = #{complementGoodsIdList},
  151. </if>
  152. <if test="taxStockCount != null">
  153. tax_stock_count_ = #{taxStockCount},
  154. </if>
  155. <if test="clientShow != null">
  156. client_show_ = #{clientShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  157. </if>
  158. <if test="educationalShow != null">
  159. educational_show_ = #{educationalShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  160. </if>
  161. <if test="musicGroupShow != null">
  162. music_group_show_ = #{musicGroupShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  163. </if>
  164. <if test="stockWarning != null">
  165. stock_warning_ = #{stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  166. </if>
  167. <if test="stockType != null">
  168. stock_type_ = #{stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  169. </if>
  170. update_time_ = NOW()
  171. </set>
  172. WHERE id_ = #{id}
  173. </update>
  174. <update id="batchUpdate" parameterType="com.ym.mec.biz.dal.entity.Goods">
  175. <foreach collection="goodsList" item="goods" separator=";">
  176. UPDATE goods
  177. <set>
  178. <if test="goods.agreeCostPrice != null">
  179. agree_cost_price_ = #{goods.agreeCostPrice},
  180. </if>
  181. <if test="goods.specification != null">
  182. specification_ = #{goods.specification},
  183. </if>
  184. <if test="goods.status != null">
  185. status_ = #{goods.status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  186. </if>
  187. <if test="goods.isTop != null">
  188. is_top_ = #{goods.isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  189. </if>
  190. <if test="goods.type != null">
  191. type_ = #{goods.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  192. </if>
  193. <if test="goods.sn != null">
  194. sn_ = #{goods.sn},
  195. </if>
  196. <if test="goods.marketPrice != null">
  197. market_price_ = #{goods.marketPrice},
  198. </if>
  199. <if test="goods.memo != null">
  200. memo_ = #{goods.memo},
  201. </if>
  202. <if test="goods.isNew != null">
  203. is_new_ = #{goods.isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  204. </if>
  205. <if test="goods.groupPurchasePrice != null">
  206. group_purchase_price_ = #{goods.groupPurchasePrice},
  207. </if>
  208. <if test="goods.name != null">
  209. name_ = #{goods.name},
  210. </if>
  211. <if test="goods.stockCount != null">
  212. stock_count_ = #{goods.stockCount},
  213. </if>
  214. <if test="goods.goodsCategoryId != null">
  215. goods_category_id_ = #{goods.goodsCategoryId},
  216. </if>
  217. <if test="goods.brand != null">
  218. brand_ = #{goods.brand},
  219. </if>
  220. <if test="goods.brief != null">
  221. brief_ = #{goods.brief},
  222. </if>
  223. <if test="goods.discountPrice != null">
  224. discount_price_ = #{goods.discountPrice},
  225. </if>
  226. <if test="goods.sellCount != null">
  227. sell_count_ = #{goods.sellCount},
  228. </if>
  229. <if test="goods.image != null">
  230. image_ = #{goods.image},
  231. </if>
  232. <if test="goods.desc != null">
  233. desc_ = #{goods.desc},
  234. </if>
  235. <if test="goods.publishTime != null">
  236. publish_time_ = #{goods.publishTime},
  237. </if>
  238. <if test="goods.complementGoodsIdList != null">
  239. complement_goods_id_list_ = #{goods.complementGoodsIdList},
  240. </if>
  241. <if test="goods.taxStockCount != null">
  242. tax_stock_count_ = #{goods.taxStockCount},
  243. </if>
  244. <if test="goods.clientShow != null">
  245. client_show_ = #{goods.clientShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  246. </if>
  247. <if test="goods.educationalShow != null">
  248. educational_show_ = #{goods.educationalShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  249. </if>
  250. <if test="goods.musicGroupShow != null">
  251. music_group_show_ = #{goods.musicGroupShow,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  252. </if>
  253. <if test="goods.stockWarning != null">
  254. stock_warning_ = #{goods.stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  255. </if>
  256. <if test="goods.stockType != null">
  257. stock_type_ = #{goods.stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  258. </if>
  259. update_time_ = NOW()
  260. </set>
  261. WHERE id_ = #{goods.id}
  262. </foreach>
  263. </update>
  264. <!-- 根据主键删除一条记录 -->
  265. <delete id="delete">
  266. DELETE FROM goods WHERE id_ = #{id}
  267. </delete>
  268. <!-- 分页查询 -->
  269. <select id="queryPage" resultMap="Goods" parameterType="map">
  270. SELECT g.*,gc.name_ goods_category_name_ FROM goods g
  271. LEFT JOIN goods_category gc ON g.goods_category_id_ = gc.id_
  272. <include refid="queryGoodsPageSql"/>
  273. ORDER BY g.id_ DESC
  274. <include refid="global.limit"/>
  275. </select>
  276. <!-- 查询当前表的总记录数 -->
  277. <select id="queryCount" resultType="int">
  278. SELECT COUNT(*) FROM goods g
  279. <include refid="queryGoodsPageSql"/>
  280. </select>
  281. <sql id="queryGoodsPageSql">
  282. <where>
  283. <if test="goodsCategoryId != null">
  284. AND g.goods_category_id_ = #{goodsCategoryId}
  285. </if>
  286. <if test="type != null">
  287. AND g.type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  288. </if>
  289. <if test="isNew != null">
  290. AND g.is_new_ = #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  291. </if>
  292. <if test="isTop != null">
  293. AND g.is_top_ = #{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  294. </if>
  295. <if test="status != null">
  296. AND g.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  297. </if>
  298. <if test="groupGoods!=null and groupGoods==0">
  299. AND g.complement_goods_id_list_ IS NULL
  300. </if>
  301. <if test="groupGoods!=null and groupGoods==1">
  302. AND g.complement_goods_id_list_ IS NOT NULL
  303. </if>
  304. <if test="clientShow!=null">
  305. AND g.client_show_=#{clientShow}
  306. </if>
  307. <if test="educationalShow!=null">
  308. AND g.educational_show_=#{educationalShow}
  309. </if>
  310. <if test="musicGroupShow!=null">
  311. AND g.music_group_show_=#{musicGroupShow}
  312. </if>
  313. <if test="search!=null and search!=''">
  314. AND (g.sn_=#{search} OR g.id_=#{search} OR g.name_ LIKE CONCAT('%', #{search}, '%'))
  315. </if>
  316. </where>
  317. </sql>
  318. <select id="findGoodsBySubId" resultMap="Goods">
  319. SELECT g.* FROM subject_goods_mapper sgm
  320. LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
  321. WHERE sgm.subject_id_ = #{subjectId} AND g.type_ = #{type} and g.status_ != 0
  322. </select>
  323. <!-- 根据 -->
  324. <select id="findGoodsNumByCategoryId" resultType="int">
  325. SELECT COUNT(*) FROM goods WHERE goods_category_id_ = #{goodsCategoryId}
  326. </select>
  327. <select id="findGoodsByIds" resultMap="Goods">
  328. SELECT * FROM goods WHERE FIND_IN_SET(id_,#{ids})
  329. </select>
  330. <select id="findTypeGoods" resultMap="Goods">
  331. SELECT * FROM goods WHERE type_ = #{type} AND status_ != 0
  332. </select>
  333. <select id="getGoodies" resultMap="Goods">
  334. SELECT * FROM goods WHERE id_ IN
  335. <foreach collection="goodsIds" item="goodsId" open="(" close=")" separator=",">
  336. #{goodsId}
  337. </foreach>
  338. </select>
  339. <select id="lockGoods" resultMap="Goods" useCache="false" flushCache="true">
  340. SELECT * FROM goods WHERE id_ IN
  341. <foreach collection="goodsIds" item="goodsId" open="(" close=")" separator=",">
  342. #{goodsId}
  343. </foreach>
  344. FOR UPDATE
  345. </select>
  346. <select id="findBySn" resultMap="Goods">
  347. SELECT * FROM goods WHERE sn_ = #{sn}
  348. </select>
  349. <select id="lockBySn" resultMap="Goods">
  350. SELECT * FROM goods WHERE sn_ = #{sn} FOR UPDATE
  351. </select>
  352. <select id="findBySns" resultMap="Goods">
  353. SELECT * FROM goods WHERE sn_ IN
  354. <foreach collection="sns" item="sn" separator="," open="(" close=")">
  355. #{sn}
  356. </foreach>
  357. </select>
  358. <select id="getInnerRepertoryWarnName" resultType="java.lang.String">
  359. SELECT GROUP_CONCAT( DISTINCT name_) FROM goods WHERE stock_count_ &lt;= #{innerRepertoryWarnNum} AND stock_warning_ = 1 AND complement_goods_id_list_ IS NULL
  360. </select>
  361. <select id="getOuterRepertoryWarnName" resultType="java.lang.String">
  362. SELECT GROUP_CONCAT( DISTINCT name_) FROM goods WHERE tax_stock_count_ &lt;= #{outerRepertoryWarnNum} AND stock_warning_ = 1 AND complement_goods_id_list_ IS NULL
  363. </select>
  364. <select id="getWithComplementGoodsAndStatus" resultMap="Goods">
  365. SELECT * FROM goods WHERE status_ = #{status} AND FIND_IN_SET(#{goodsId}, complement_goods_id_list_)
  366. </select>
  367. <resultMap id="GoodsSellDtoMap" type="com.ym.mec.biz.dal.dto.GoodsSellDto">
  368. <result property="goodsId" column="id_"/>
  369. <result property="image" column="image_"/>
  370. <result property="goodsName" column="name_"/>
  371. <result property="goodsType" column="type_"/>
  372. <result property="goodsPrice" column="discount_price_"/>
  373. <result property="totalGoodsPrice" column="discount_price_"/>
  374. </resultMap>
  375. <select id="queryGoodsSellDtos" resultMap="GoodsSellDtoMap">
  376. SELECT id_,image_,name_,type_,discount_price_ FROM goods WHERE FIND_IN_SET(id_,#{goodsId})
  377. </select>
  378. <resultMap id="MusicGroupGoods" type="com.ym.mec.biz.dal.dto.MusicGroupGoodsAndDiscountDto" extends="Goods"/>
  379. <select id="getMusicGroupGoodsAndDiscount" resultMap="MusicGroupGoods">
  380. SELECT g.* FROM subject_goods_mapper sgm
  381. LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
  382. WHERE sgm.subject_id_ = #{subjectId} AND g.music_group_show_=1 AND g.status_ != 0
  383. <if test="type!=null">
  384. AND g.type_ = #{type}
  385. </if>
  386. </select>
  387. <select id="getMusicGroupGoodsAndDiscountWithSubjects" resultMap="MusicGroupGoods">
  388. SELECT g.* FROM subject_goods_mapper sgm
  389. LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
  390. WHERE FIND_IN_SET(sgm.subject_id_, #{subjectIds}) and g.status_ != 0
  391. <if test="type!=null">
  392. AND g.type_ = #{type}
  393. </if>
  394. </select>
  395. <select id="findByIdAndStatus" resultType="java.lang.Boolean">
  396. SELECT COUNT(0) FROM goods WHERE status_ = #{status} AND id_ = #{goodsId}
  397. </select>
  398. <select id="getGoodsInfo" resultMap="Goods">
  399. SELECT g.*,gc.name_ goods_category_name_ FROM goods g
  400. LEFT JOIN goods_category gc on g.goods_category_id_ = gc.id_
  401. WHERE g.id_=#{id}
  402. </select>
  403. <select id="getGoodiesAndCate" resultMap="Goods">
  404. SELECT g.*,gc.name_ goods_category_name_ FROM goods g
  405. LEFT JOIN goods_category gc on g.goods_category_id_ = gc.id_
  406. WHERE g.id_ IN
  407. <foreach collection="goodsIds" item="goodsId" open="(" close=")" separator=",">
  408. #{goodsId}
  409. </foreach>
  410. </select>
  411. </mapper>