GoodsMapper.xml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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="stock_warning_" property="stockWarning" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
  38. <result column="student_show_organ_id_" property="studentShowOrganId"/>
  39. <result column="student_show_organ_name_" property="studentShowOrganName"/>
  40. <result column="education_show_organ_id_" property="educationShowOrganId"/>
  41. <result column="education_show_organ_name_" property="educationShowOrganName"/>
  42. <result column="replacement_show_organ_id_" property="replacementShowOrganId"/>
  43. <result column="replacement_show_organ_name_" property="replacementShowOrganName"/>
  44. <result column="course_fee_show_organ_id_" property="courseFeeShowOrganId"/>
  45. <result column="course_fee_show_organ_name_" property="courseFeeShowOrganName"/>
  46. <result column="member_fee_show_organ_id_" property="memberFeeShowOrganId"/>
  47. <result column="member_fee_show_organ_name_" property="memberFeeShowOrganName"/>
  48. </resultMap>
  49. <!-- 根据主键查询一条记录 -->
  50. <select id="get" resultMap="Goods" useCache="false" flushCache="true">
  51. SELECT * FROM goods WHERE id_ = #{id}
  52. </select>
  53. <select id="lock" resultMap="Goods" useCache="false" flushCache="true">
  54. SELECT * FROM goods WHERE id_ = #{goodsId} LOCK IN SHARE MODE
  55. </select>
  56. <!-- 全查询 -->
  57. <select id="findAll" resultMap="Goods">
  58. SELECT * FROM goods ORDER BY id_
  59. </select>
  60. <!-- 向数据库增加一条记录 -->
  61. <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.Goods" useGeneratedKeys="true" keyColumn="id"
  62. keyProperty="id">
  63. INSERT INTO goods
  64. (goods_category_id_,sn_,name_,brand_,specification_,image_,stock_count_,tax_stock_count_,sell_count_,market_price_,
  65. discount_price_,group_purchase_price_,brief_,desc_,is_new_,is_top_,status_,memo_,publish_time_,
  66. complement_goods_id_list_,update_time_,create_time_,type_,agree_cost_price_,stock_warning_,stock_type_
  67. ,student_show_organ_id_,education_show_organ_id_,replacement_show_organ_id_,course_fee_show_organ_id_,member_fee_show_organ_id_)
  68. VALUES(#{goodsCategoryId},#{sn},#{name},#{brand},#{specification},#{image},#{stockCount},#{taxStockCount},#{sellCount},#{marketPrice},
  69. #{discountPrice},#{groupPurchasePrice},#{brief},#{desc},
  70. #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  71. #{memo},#{publishTime},#{complementGoodsIdList},now(),now(),#{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{agreeCostPrice},
  72. #{stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}, #{stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  73. #{studentShowOrganId},#{educationShowOrganId},#{replacementShowOrganId},#{courseFeeShowOrganId},#{memberFeeShowOrganId})
  74. </insert>
  75. <insert id="batchInsert" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
  76. INSERT INTO goods
  77. (goods_category_id_,name_,brand_,specification_,image_,market_price_,
  78. discount_price_,group_purchase_price_,brief_,desc_,update_time_,create_time_,type_,agree_cost_price_,sn_,
  79. stock_count_,tax_stock_count_,stock_warning_,stock_type_
  80. ,student_show_organ_id_,education_show_organ_id_,replacement_show_organ_id_,course_fee_show_organ_id_,member_fee_show_organ_id_)
  81. VALUES
  82. <foreach collection="list" separator="," item="goods">
  83. (#{goods.goodsCategoryId},#{goods.name},#{goods.brand},#{goods.specification},#{goods.image},#{goods.marketPrice},
  84. #{goods.discountPrice},#{goods.groupPurchasePrice},#{goods.brief},#{goods.desc},now(),now(),
  85. #{goods.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{goods.agreeCostPrice},#{goods.sn},
  86. #{goods.stockCount},#{goods.taxStockCount},
  87. #{goods.stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  88. #{goods.stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  89. #{goods.studentShowOrganId},#{goods.educationShowOrganId},#{goods.replacementShowOrganId},#{goods.courseFeeShowOrganId},#{goods.memberFeeShowOrganId}
  90. )
  91. </foreach>
  92. </insert>
  93. <!-- 根据主键查询一条记录 -->
  94. <update id="update" parameterType="com.ym.mec.biz.dal.entity.Goods">
  95. UPDATE goods
  96. <set>
  97. <if test="studentShowOrganId != null">
  98. student_show_organ_id_ = #{studentShowOrganId},
  99. </if>
  100. <if test="educationShowOrganId != null">
  101. education_show_organ_id_ = #{educationShowOrganId},
  102. </if>
  103. <if test="replacementShowOrganId != null">
  104. replacement_show_organ_id_ = #{replacementShowOrganId},
  105. </if>
  106. <if test="courseFeeShowOrganId != null">
  107. course_fee_show_organ_id_ = #{courseFeeShowOrganId},
  108. </if>
  109. <if test="memberFeeShowOrganId != null">
  110. member_fee_show_organ_id_ = #{memberFeeShowOrganId},
  111. </if>
  112. <if test="agreeCostPrice != null">
  113. agree_cost_price_ = #{agreeCostPrice},
  114. </if>
  115. <if test="specification != null">
  116. specification_ = #{specification},
  117. </if>
  118. <if test="status != null">
  119. status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  120. </if>
  121. <if test="isTop != null">
  122. is_top_ = #{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  123. </if>
  124. <if test="type != null">
  125. type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  126. </if>
  127. <if test="sn != null">
  128. sn_ = #{sn},
  129. </if>
  130. <if test="marketPrice != null">
  131. market_price_ = #{marketPrice},
  132. </if>
  133. <if test="memo != null">
  134. memo_ = #{memo},
  135. </if>
  136. <if test="isNew != null">
  137. is_new_ = #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  138. </if>
  139. <if test="groupPurchasePrice != null">
  140. group_purchase_price_ = #{groupPurchasePrice},
  141. </if>
  142. <if test="name != null">
  143. name_ = #{name},
  144. </if>
  145. <if test="stockCount != null">
  146. stock_count_ = #{stockCount},
  147. </if>
  148. <if test="goodsCategoryId != null">
  149. goods_category_id_ = #{goodsCategoryId},
  150. </if>
  151. <if test="brand != null">
  152. brand_ = #{brand},
  153. </if>
  154. <if test="brief != null">
  155. brief_ = #{brief},
  156. </if>
  157. <if test="discountPrice != null">
  158. discount_price_ = #{discountPrice},
  159. </if>
  160. <if test="sellCount != null">
  161. sell_count_ = #{sellCount},
  162. </if>
  163. <if test="image != null">
  164. image_ = #{image},
  165. </if>
  166. <if test="desc != null">
  167. desc_ = #{desc},
  168. </if>
  169. <if test="publishTime != null">
  170. publish_time_ = #{publishTime},
  171. </if>
  172. <if test="complementGoodsIdList != null">
  173. complement_goods_id_list_ = #{complementGoodsIdList},
  174. </if>
  175. <if test="taxStockCount != null">
  176. tax_stock_count_ = #{taxStockCount},
  177. </if>
  178. <if test="stockWarning != null">
  179. stock_warning_ = #{stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  180. </if>
  181. <if test="stockType != null">
  182. stock_type_ = #{stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  183. </if>
  184. update_time_ = NOW()
  185. </set>
  186. WHERE id_ = #{id}
  187. </update>
  188. <update id="batchUpdate" parameterType="com.ym.mec.biz.dal.entity.Goods">
  189. <foreach collection="goodsList" item="goods" separator=";">
  190. UPDATE goods
  191. <set>
  192. <if test="goods.studentShowOrganId != null">
  193. student_show_organ_id_ = #{goods.studentShowOrganId},
  194. </if>
  195. <if test="goods.educationShowOrganId != null">
  196. education_show_organ_id_ = #{goods.educationShowOrganId},
  197. </if>
  198. <if test="goods.replacementShowOrganId != null">
  199. replacement_show_organ_id_ = #{goods.replacementShowOrganId},
  200. </if>
  201. <if test="goods.courseFeeShowOrganId != null">
  202. course_fee_show_organ_id_ = #{goods.courseFeeShowOrganId},
  203. </if>
  204. <if test="goods.memberFeeShowOrganId != null">
  205. member_fee_show_organ_id_ = #{goods.memberFeeShowOrganId},
  206. </if>
  207. <if test="goods.agreeCostPrice != null">
  208. agree_cost_price_ = #{goods.agreeCostPrice},
  209. </if>
  210. <if test="goods.specification != null">
  211. specification_ = #{goods.specification},
  212. </if>
  213. <if test="goods.status != null">
  214. status_ = #{goods.status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  215. </if>
  216. <if test="goods.isTop != null">
  217. is_top_ = #{goods.isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  218. </if>
  219. <if test="goods.type != null">
  220. type_ = #{goods.type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  221. </if>
  222. <if test="goods.sn != null">
  223. sn_ = #{goods.sn},
  224. </if>
  225. <if test="goods.marketPrice != null">
  226. market_price_ = #{goods.marketPrice},
  227. </if>
  228. <if test="goods.memo != null">
  229. memo_ = #{goods.memo},
  230. </if>
  231. <if test="goods.isNew != null">
  232. is_new_ = #{goods.isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  233. </if>
  234. <if test="goods.groupPurchasePrice != null">
  235. group_purchase_price_ = #{goods.groupPurchasePrice},
  236. </if>
  237. <if test="goods.name != null">
  238. name_ = #{goods.name},
  239. </if>
  240. <if test="goods.stockCount != null">
  241. stock_count_ = #{goods.stockCount},
  242. </if>
  243. <if test="goods.goodsCategoryId != null">
  244. goods_category_id_ = #{goods.goodsCategoryId},
  245. </if>
  246. <if test="goods.brand != null">
  247. brand_ = #{goods.brand},
  248. </if>
  249. <if test="goods.brief != null">
  250. brief_ = #{goods.brief},
  251. </if>
  252. <if test="goods.discountPrice != null">
  253. discount_price_ = #{goods.discountPrice},
  254. </if>
  255. <if test="goods.sellCount != null">
  256. sell_count_ = #{goods.sellCount},
  257. </if>
  258. <if test="goods.image != null">
  259. image_ = #{goods.image},
  260. </if>
  261. <if test="goods.desc != null">
  262. desc_ = #{goods.desc},
  263. </if>
  264. <if test="goods.publishTime != null">
  265. publish_time_ = #{goods.publishTime},
  266. </if>
  267. <if test="goods.complementGoodsIdList != null">
  268. complement_goods_id_list_ = #{goods.complementGoodsIdList},
  269. </if>
  270. <if test="goods.taxStockCount != null">
  271. tax_stock_count_ = #{goods.taxStockCount},
  272. </if>
  273. <if test="goods.stockWarning != null">
  274. stock_warning_ = #{goods.stockWarning,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  275. </if>
  276. <if test="goods.stockType != null">
  277. stock_type_ = #{goods.stockType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
  278. </if>
  279. update_time_ = NOW()
  280. </set>
  281. WHERE id_ = #{goods.id}
  282. </foreach>
  283. </update>
  284. <!-- 根据主键删除一条记录 -->
  285. <delete id="delete">
  286. DELETE FROM goods WHERE id_ = #{id}
  287. </delete>
  288. <!-- 分页查询 -->
  289. <select id="queryPage" resultMap="Goods" parameterType="map">
  290. SELECT g.*,gc.name_ goods_category_name_ FROM goods g
  291. LEFT JOIN goods_category gc ON g.goods_category_id_ = gc.id_
  292. <include refid="queryGoodsPageSql"/>
  293. GROUP BY g.id_
  294. ORDER BY g.id_ DESC
  295. <include refid="global.limit"/>
  296. </select>
  297. <!-- 查询当前表的总记录数 -->
  298. <select id="queryCount" resultType="int">
  299. SELECT COUNT(*) FROM goods g
  300. <include refid="queryGoodsPageSql"/>
  301. </select>
  302. <sql id="queryGoodsPageSql">
  303. <where>
  304. <if test="goodsCategoryId != null">
  305. AND g.goods_category_id_ = #{goodsCategoryId}
  306. </if>
  307. <if test="type != null">
  308. AND g.type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  309. </if>
  310. <if test="isNew != null">
  311. AND g.is_new_ = #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  312. </if>
  313. <if test="isTop != null">
  314. AND g.is_top_ = #{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  315. </if>
  316. <if test="status != null">
  317. AND g.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  318. </if>
  319. <if test="groupGoods!=null and groupGoods==0">
  320. AND g.complement_goods_id_list_ IS NULL
  321. </if>
  322. <if test="groupGoods!=null and groupGoods==1">
  323. AND g.complement_goods_id_list_ IS NOT NULL
  324. </if>
  325. <if test="studentShowOrganId != null">
  326. AND FIND_IN_SET(#{studentShowOrganId},g.student_show_organ_id_)
  327. </if>
  328. <if test="educationShowOrganId != null">
  329. AND FIND_IN_SET(#{educationShowOrganId},g.education_show_organ_id_)
  330. </if>
  331. <if test="courseFeeShowOrganId != null">
  332. AND FIND_IN_SET(#{courseFeeShowOrganId},g.course_fee_show_organ_id_)
  333. </if>
  334. <if test="memberFeeShowOrganId!=null">
  335. AND FIND_IN_SET(#{memberFeeShowOrganId},g.member_fee_show_organ_id_)
  336. </if>
  337. <if test="replacementShowOrganId!=null">
  338. AND FIND_IN_SET(#{replacementShowOrganId},g.replacement_show_organ_id_)
  339. </if>
  340. <if test="organId != null and organId != ''">
  341. AND INTE_ARRAY (#{organId},CONCAT_WS(",",replacement_show_organ_id_,member_fee_show_organ_id_,
  342. course_fee_show_organ_id_,education_show_organ_id_,student_show_organ_id_))
  343. </if>
  344. <if test="search!=null and search!=''">
  345. AND (g.sn_=#{search} OR g.id_=#{search} OR g.name_ LIKE CONCAT('%', #{search}, '%'))
  346. </if>
  347. </where>
  348. </sql>
  349. <select id="findGoodsBySubId" resultMap="Goods">
  350. SELECT g.* FROM subject_goods_mapper sgm
  351. LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
  352. WHERE sgm.subject_id_ = #{subjectId} AND g.type_ = #{type} and g.status_ != 0
  353. <if test="organId != null">
  354. AND FIND_IN_SET(#{organId},g.organ_id_list_)
  355. </if>
  356. </select>
  357. <!-- 根据 -->
  358. <select id="findGoodsNumByCategoryId" resultType="int">
  359. SELECT COUNT(*) FROM goods WHERE goods_category_id_ = #{goodsCategoryId}
  360. </select>
  361. <select id="findGoodsByIds" resultMap="Goods">
  362. SELECT * FROM goods WHERE FIND_IN_SET(id_,#{ids})
  363. </select>
  364. <select id="findTypeGoods" resultMap="Goods">
  365. SELECT * FROM goods WHERE type_ = #{type} AND status_ != 0
  366. </select>
  367. <select id="getGoodies" resultMap="Goods">
  368. SELECT * FROM goods WHERE id_ IN
  369. <foreach collection="goodsIds" item="goodsId" open="(" close=")" separator=",">
  370. #{goodsId}
  371. </foreach>
  372. </select>
  373. <select id="lockGoods" resultMap="Goods" useCache="false" flushCache="true">
  374. SELECT * FROM goods WHERE id_ IN
  375. <foreach collection="goodsIds" item="goodsId" open="(" close=")" separator=",">
  376. #{goodsId}
  377. </foreach>
  378. FOR UPDATE
  379. </select>
  380. <select id="findBySn" resultMap="Goods">
  381. SELECT * FROM goods WHERE sn_ = #{sn}
  382. </select>
  383. <select id="lockBySn" resultMap="Goods">
  384. SELECT * FROM goods WHERE sn_ = #{sn} FOR UPDATE
  385. </select>
  386. <select id="findBySns" resultMap="Goods">
  387. SELECT * FROM goods WHERE sn_ IN
  388. <foreach collection="sns" item="sn" separator="," open="(" close=")">
  389. #{sn}
  390. </foreach>
  391. </select>
  392. <select id="getInnerRepertoryWarnName" resultType="java.lang.String">
  393. SELECT GROUP_CONCAT( DISTINCT name_) FROM goods WHERE stock_count_ &lt;= #{innerRepertoryWarnNum} AND stock_warning_ = 1 AND complement_goods_id_list_ IS NULL
  394. </select>
  395. <select id="getOuterRepertoryWarnName" resultType="java.lang.String">
  396. SELECT GROUP_CONCAT( DISTINCT name_) FROM goods WHERE tax_stock_count_ &lt;= #{outerRepertoryWarnNum} AND stock_warning_ = 1 AND complement_goods_id_list_ IS NULL
  397. </select>
  398. <select id="getWithComplementGoodsAndStatus" resultMap="Goods">
  399. SELECT * FROM goods WHERE status_ = #{status} AND FIND_IN_SET(#{goodsId}, complement_goods_id_list_)
  400. </select>
  401. <resultMap id="GoodsSellDtoMap" type="com.ym.mec.biz.dal.dto.GoodsSellDto">
  402. <result property="goodsId" column="id_"/>
  403. <result property="image" column="image_"/>
  404. <result property="goodsName" column="name_"/>
  405. <result property="goodsType" column="type_"/>
  406. <result property="goodsPrice" column="discount_price_"/>
  407. <result property="totalGoodsPrice" column="discount_price_"/>
  408. </resultMap>
  409. <select id="queryGoodsSellDtos" resultMap="GoodsSellDtoMap">
  410. SELECT id_,image_,name_,type_,discount_price_ FROM goods WHERE FIND_IN_SET(id_,#{goodsId})
  411. </select>
  412. <resultMap id="MusicGroupGoods" type="com.ym.mec.biz.dal.dto.MusicGroupGoodsAndDiscountDto" extends="Goods"/>
  413. <select id="getMusicGroupGoodsAndDiscount" resultMap="MusicGroupGoods">
  414. SELECT g.* FROM subject_goods_mapper sgm
  415. LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
  416. WHERE sgm.subject_id_ = #{subjectId} AND g.status_ != 0
  417. <if test="organId != null">
  418. <if test="courseViewType != null">
  419. <if test="courseViewType == 1">
  420. AND FIND_IN_SET(#{organId},g.member_fee_show_organ_id_)
  421. </if>
  422. <if test="courseViewType == 0">
  423. AND FIND_IN_SET(#{organId},g.course_fee_show_organ_id_)
  424. </if>
  425. </if>
  426. </if>
  427. <if test="type!=null">
  428. AND g.type_ = #{type}
  429. </if>
  430. </select>
  431. <select id="findByIdAndStatus" resultType="java.lang.Boolean">
  432. SELECT COUNT(0) FROM goods WHERE status_ = #{status} AND id_ = #{goodsId}
  433. </select>
  434. <select id="getGoodsInfo" resultMap="Goods">
  435. SELECT g.*,gc.name_ goods_category_name_ FROM goods g
  436. LEFT JOIN goods_category gc on g.goods_category_id_ = gc.id_
  437. WHERE g.id_=#{id}
  438. </select>
  439. <select id="getGoodiesAndCate" resultMap="Goods">
  440. SELECT g.*,gc.name_ goods_category_name_ FROM goods g
  441. LEFT JOIN goods_category gc on g.goods_category_id_ = gc.id_
  442. WHERE g.id_ IN
  443. <foreach collection="goodsIds" item="goodsId" open="(" close=")" separator=",">
  444. #{goodsId}
  445. </foreach>
  446. </select>
  447. <!-- 根据子商品获取所有包含的子商品的父商品(全部状态)-->
  448. <select id="getGoodsByBaseGoodsId" resultMap="Goods">
  449. SELECT * FROM goods WHERE FIND_IN_SET(#{goodsId}, complement_goods_id_list_)
  450. </select>
  451. <!-- 根据分部获取乐器置换的商品-->
  452. <select id="getReplacementGoodsPage" resultMap="com.ym.mec.biz.dal.dao.ReplacementInstrumentDao.ReplacementInstrument">
  453. SELECT g.id_,g.brand_,g.specification_,g.brief_ param_,g.market_price_,g.discount_price_,g.group_purchase_price_ sale_price_,
  454. (g.discount_price_-g.group_purchase_price_) depreciation_price_
  455. FROM subject_goods_mapper sgm
  456. LEFT JOIN goods_category gc ON gc.id_=sgm.goods_category_id_
  457. LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
  458. <include refid="replacementQuerySql"/>
  459. <include refid="global.limit"/>
  460. </select>
  461. <select id="getReplacementInstrumentCount" resultType="int">
  462. SELECT COUNT(*)
  463. FROM subject_goods_mapper sgm
  464. LEFT JOIN goods_category gc ON gc.id_=sgm.goods_category_id_
  465. LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
  466. <include refid="replacementQuerySql"/>
  467. <include refid="global.limit"/>
  468. </select>
  469. <select id="findGoodsOrganNames" resultType="java.util.Map">
  470. SELECT g.id_ 'key',GROUP_CONCAT(DISTINCT o.name_) 'value' FROM goods g
  471. LEFT JOIN organization o ON FIND_IN_SET(o.id_,g.organ_id_list_)
  472. WHERE g.id_ IN
  473. <foreach collection="goodsIds" open="(" close=")" item="organId" separator=",">
  474. #{organId}
  475. </foreach>
  476. GROUP BY g.id_
  477. </select>
  478. <sql id="replacementQuerySql">
  479. <where>
  480. g.status_ != 0
  481. AND g.type_ = 'INSTRUMENT'
  482. AND gc.del_flag_ = 0
  483. <if test="organId != null">
  484. AND FIND_IN_SET(#{organId},g.replacement_show_organ_id_)
  485. </if>
  486. <if test="subjectId != null">
  487. AND sgm.subject_id_ = #{subjectId}
  488. </if>
  489. <if test="brand != null and brand!=''">
  490. AND g.brand_ = #{brand}
  491. </if>
  492. <if test="specification != null and specification!=''">
  493. AND g.specification_ = #{specification}
  494. </if>
  495. </where>
  496. </sql>
  497. </mapper>