GoodsMapper.xml 31 KB

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