GoodsMapper.xml 30 KB

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