GoodsMapper.xml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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.*,gc.name_ goods_category_name_ FROM goods g
  304. LEFT JOIN goods_category gc ON g.goods_category_id_ = gc.id_
  305. <include refid="queryGoodsPageSql"/>
  306. GROUP BY g.id_
  307. ORDER BY g.id_ DESC
  308. <include refid="global.limit"/>
  309. </select>
  310. <!-- 查询当前表的总记录数 -->
  311. <select id="queryCount" resultType="int">
  312. SELECT COUNT(*) FROM goods g
  313. <include refid="queryGoodsPageSql"/>
  314. </select>
  315. <sql id="queryGoodsPageSql">
  316. <where>
  317. g.tenant_id_ = #{tenantId}
  318. <if test="goodsCategoryId != null">
  319. AND g.goods_category_id_ = #{goodsCategoryId}
  320. </if>
  321. <if test="type != null">
  322. AND g.type_ = #{type,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  323. </if>
  324. <if test="isNew != null">
  325. AND g.is_new_ = #{isNew,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  326. </if>
  327. <if test="isTop != null">
  328. AND g.is_top_ = #{isTop,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  329. </if>
  330. <if test="status != null">
  331. AND g.status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
  332. </if>
  333. <if test="groupGoods!=null and groupGoods==0">
  334. AND g.complement_goods_id_list_ IS NULL
  335. </if>
  336. <if test="groupGoods!=null and groupGoods==1">
  337. AND g.complement_goods_id_list_ IS NOT NULL
  338. </if>
  339. <if test="studentShowOrganId != null and studentShowOrganId!=''">
  340. AND INTE_ARRAY(#{studentShowOrganId},g.student_show_organ_id_)
  341. </if>
  342. <if test="educationShowOrganId != null and educationShowOrganId!=''">
  343. AND INTE_ARRAY(#{educationShowOrganId},g.education_show_organ_id_)
  344. </if>
  345. <if test="courseFeeShowOrganId != null and courseFeeShowOrganId!=''">
  346. AND INTE_ARRAY(#{courseFeeShowOrganId},g.course_fee_show_organ_id_)
  347. </if>
  348. <if test="memberFeeShowOrganId!=null and memberFeeShowOrganId!=''">
  349. AND INTE_ARRAY(#{memberFeeShowOrganId},g.member_fee_show_organ_id_)
  350. </if>
  351. <if test="freeFeeShowOrganId!=null and freeFeeShowOrganId!=''">
  352. AND INTE_ARRAY(#{freeFeeShowOrganId},g.free_fee_show_organ_id_)
  353. </if>
  354. <if test="replacementShowOrganId!=null and replacementShowOrganId!=''">
  355. AND INTE_ARRAY(#{replacementShowOrganId},g.replacement_show_organ_id_)
  356. </if>
  357. <if test="brandId != null and brandId != ''">
  358. AND g.brand_ = #{brandId}
  359. </if>
  360. <if test="noOrganSearch == null">
  361. <if test="organId != null and organId != ''">
  362. AND INTE_ARRAY (#{organId},CONCAT_WS(',',
  363. CASE WHEN member_fee_show_organ_id_ = '' THEN NULL ELSE member_fee_show_organ_id_ END,
  364. CASE WHEN course_fee_show_organ_id_ = '' THEN NULL ELSE course_fee_show_organ_id_ END,
  365. CASE WHEN free_fee_show_organ_id_ = '' THEN NULL ELSE free_fee_show_organ_id_ END,
  366. CASE WHEN education_show_organ_id_ = '' THEN NULL ELSE education_show_organ_id_ END,
  367. CASE WHEN student_show_organ_id_ = '' THEN NULL ELSE student_show_organ_id_ END,
  368. CASE WHEN replacement_show_organ_id_ = '' THEN NULL ELSE replacement_show_organ_id_ END))
  369. </if>
  370. </if>
  371. <if test="search!=null and search!=''">
  372. AND (g.sn_=#{search} OR g.id_=#{search} OR g.name_ LIKE CONCAT('%', #{search}, '%'))
  373. </if>
  374. </where>
  375. </sql>
  376. <select id="findGoodsBySubId" resultMap="Goods">
  377. SELECT g.* FROM subject_goods_mapper sgm
  378. LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
  379. <include refid="queryOrganIdSql"/>
  380. </select>
  381. <sql id="queryOrganIdSql">
  382. <where>
  383. AND g.status_ != 0 and g.tenant_id_ = #{goodsQuery.tenantId}
  384. <if test="goodsQuery.subjectId != null">
  385. AND sgm.subject_id_ = #{goodsQuery.subjectId}
  386. </if>
  387. <if test="goodsQuery.type != null and goodsQuery.type != ''">
  388. AND g.type_ = #{goodsQuery.type}
  389. </if>
  390. <if test="goodsQuery.studentShowOrganId != null">
  391. AND FIND_IN_SET(#{goodsQuery.studentShowOrganId},g.student_show_organ_id_)
  392. </if>
  393. <if test="goodsQuery.educationShowOrganId != null">
  394. AND FIND_IN_SET(#{goodsQuery.educationShowOrganId},g.education_show_organ_id_)
  395. </if>
  396. <if test="goodsQuery.courseFeeShowOrganId != null">
  397. AND FIND_IN_SET(#{goodsQuery.courseFeeShowOrganId},g.course_fee_show_organ_id_)
  398. </if>
  399. <if test="goodsQuery.memberFeeShowOrganId!=null">
  400. AND FIND_IN_SET(#{goodsQuery.memberFeeShowOrganId},g.member_fee_show_organ_id_)
  401. </if>
  402. <if test="goodsQuery.freeFeeShowOrganId!=null">
  403. AND FIND_IN_SET(#{goodsQuery.freeFeeShowOrganId},g.free_fee_show_organ_id_)
  404. </if>
  405. <if test="goodsQuery.replacementShowOrganId!=null">
  406. AND FIND_IN_SET(#{goodsQuery.replacementShowOrganId},g.replacement_show_organ_id_)
  407. </if>
  408. <if test="goodsQuery.organId != null">
  409. AND FIND_IN_SET (#{goodsQuery.organId},CONCAT_WS(',',
  410. CASE WHEN member_fee_show_organ_id_ = '' THEN NULL ELSE member_fee_show_organ_id_ END,
  411. CASE WHEN course_fee_show_organ_id_ = '' THEN NULL ELSE course_fee_show_organ_id_ END,
  412. CASE WHEN free_fee_show_organ_id_ = '' THEN NULL ELSE free_fee_show_organ_id_ END,
  413. CASE WHEN education_show_organ_id_ = '' THEN NULL ELSE education_show_organ_id_ END,
  414. CASE WHEN student_show_organ_id_ = '' THEN NULL ELSE student_show_organ_id_ END,
  415. CASE WHEN replacement_show_organ_id_ = '' THEN NULL ELSE replacement_show_organ_id_ END))
  416. </if>
  417. </where>
  418. </sql>
  419. <!-- 根据 -->
  420. <select id="findGoodsNumByCategoryId" resultType="int">
  421. SELECT COUNT(*) FROM goods WHERE goods_category_id_ = #{goodsCategoryId} and tenant_id_ = #{tenantId}
  422. </select>
  423. <select id="findGoodsByIds" resultMap="Goods">
  424. SELECT * FROM goods WHERE FIND_IN_SET(id_,#{ids})
  425. </select>
  426. <select id="findTypeGoods" resultMap="Goods">
  427. SELECT * FROM goods WHERE type_ = #{type} AND status_ != 0 and tenant_id_ = #{tenantId}
  428. </select>
  429. <select id="getGoodies" resultMap="Goods">
  430. SELECT * FROM goods WHERE id_ IN
  431. <foreach collection="goodsIds" item="goodsId" open="(" close=")" separator=",">
  432. #{goodsId}
  433. </foreach>
  434. </select>
  435. <select id="lockGoods" resultMap="Goods" useCache="false" flushCache="true">
  436. SELECT * FROM goods WHERE id_ IN
  437. <foreach collection="goodsIds" item="goodsId" open="(" close=")" separator=",">
  438. #{goodsId}
  439. </foreach>
  440. FOR UPDATE
  441. </select>
  442. <select id="findBySn" resultMap="Goods">
  443. SELECT * FROM goods WHERE sn_ = #{sn}
  444. </select>
  445. <select id="lockBySn" resultMap="Goods">
  446. SELECT * FROM goods WHERE sn_ = #{sn} FOR UPDATE
  447. </select>
  448. <select id="findBySns" resultMap="Goods">
  449. SELECT * FROM goods WHERE sn_ IN
  450. <foreach collection="sns" item="sn" separator="," open="(" close=")">
  451. #{sn}
  452. </foreach>
  453. </select>
  454. <select id="getInnerRepertoryWarnName" resultType="java.lang.String">
  455. SELECT GROUP_CONCAT( DISTINCT name_) FROM goods WHERE stock_count_ &lt;= #{innerRepertoryWarnNum} AND stock_warning_ = 1 AND complement_goods_id_list_ IS NULL
  456. </select>
  457. <select id="getOuterRepertoryWarnName" resultType="java.lang.String">
  458. SELECT GROUP_CONCAT( DISTINCT name_) FROM goods WHERE tax_stock_count_ &lt;= #{outerRepertoryWarnNum} AND stock_warning_ = 1 AND complement_goods_id_list_ IS NULL
  459. </select>
  460. <select id="getWithComplementGoodsAndStatus" resultMap="Goods">
  461. SELECT * FROM goods WHERE status_ = #{status} AND FIND_IN_SET(#{goodsId}, complement_goods_id_list_)
  462. </select>
  463. <resultMap id="GoodsSellDtoMap" type="com.ym.mec.biz.dal.dto.GoodsSellDto">
  464. <result property="goodsId" column="id_"/>
  465. <result property="image" column="image_"/>
  466. <result property="goodsName" column="name_"/>
  467. <result property="goodsType" column="type_"/>
  468. <result property="goodsPrice" column="discount_price_"/>
  469. <result property="totalGoodsPrice" column="discount_price_"/>
  470. </resultMap>
  471. <select id="queryGoodsSellDtos" resultMap="GoodsSellDtoMap">
  472. SELECT id_,image_,name_,type_,discount_price_ FROM goods WHERE FIND_IN_SET(id_,#{goodsId})
  473. </select>
  474. <resultMap id="MusicGroupGoods" type="com.ym.mec.biz.dal.dto.MusicGroupGoodsAndDiscountDto" extends="Goods"/>
  475. <select id="getMusicGroupGoodsAndDiscount" resultMap="MusicGroupGoods">
  476. SELECT g.* FROM subject_goods_mapper sgm
  477. LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
  478. WHERE sgm.subject_id_ = #{subjectId} AND g.status_ != 0 and g.tenant_id_ = #{tenantId}
  479. <if test="organId != null">
  480. <if test="courseViewType != null">
  481. <if test="courseViewType == 2">
  482. AND FIND_IN_SET(#{organId},g.member_fee_show_organ_id_)
  483. </if>
  484. <if test="courseViewType == 1 or courseViewType == 0">
  485. AND FIND_IN_SET(#{organId},g.course_fee_show_organ_id_)
  486. </if>
  487. <if test="courseViewType == 3">
  488. AND FIND_IN_SET(#{organId},g.free_fee_show_organ_id_)
  489. </if>
  490. </if>
  491. </if>
  492. <if test="type!=null">
  493. AND g.type_ = #{type}
  494. </if>
  495. </select>
  496. <select id="findByIdAndStatus" resultType="java.lang.Boolean">
  497. SELECT COUNT(0) FROM goods WHERE status_ = #{status} AND id_ = #{goodsId}
  498. </select>
  499. <select id="getGoodsInfo" resultMap="Goods">
  500. SELECT g.*,gc.name_ goods_category_name_ FROM goods g
  501. LEFT JOIN goods_category gc on g.goods_category_id_ = gc.id_
  502. WHERE g.id_=#{id}
  503. </select>
  504. <select id="getGoodiesAndCate" resultMap="Goods">
  505. SELECT g.*,gc.name_ goods_category_name_ FROM goods g
  506. LEFT JOIN goods_category gc on g.goods_category_id_ = gc.id_
  507. WHERE g.id_ IN
  508. <foreach collection="goodsIds" item="goodsId" open="(" close=")" separator=",">
  509. #{goodsId}
  510. </foreach>
  511. </select>
  512. <!-- 根据子商品获取所有包含的子商品的父商品(全部状态)-->
  513. <select id="getGoodsByBaseGoodsId" resultMap="Goods">
  514. SELECT * FROM goods WHERE FIND_IN_SET(#{goodsId}, complement_goods_id_list_)
  515. </select>
  516. <!-- 根据分部获取乐器置换的商品-->
  517. <select id="getReplacementGoodsPage" resultMap="com.ym.mec.biz.dal.dao.ReplacementInstrumentDao.ReplacementInstrument">
  518. SELECT g.id_,g.brand_,g.specification_,g.brief_ param_,g.market_price_,g.discount_price_,g.group_purchase_price_ sale_price_,
  519. (g.discount_price_-g.group_purchase_price_) depreciation_price_
  520. FROM subject_goods_mapper sgm
  521. LEFT JOIN goods_category gc ON gc.id_=sgm.goods_category_id_
  522. LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
  523. <include refid="replacementQuerySql"/>
  524. <include refid="global.limit"/>
  525. </select>
  526. <select id="getReplacementInstrumentCount" resultType="int">
  527. SELECT COUNT(*)
  528. FROM subject_goods_mapper sgm
  529. LEFT JOIN goods_category gc ON gc.id_=sgm.goods_category_id_
  530. LEFT JOIN goods g ON sgm.goods_category_id_ = g.goods_category_id_
  531. <include refid="replacementQuerySql"/>
  532. <include refid="global.limit"/>
  533. </select>
  534. <select id="getOrganCostPrice" resultType="java.math.BigDecimal">
  535. select SUM(organ_cost_price_) from goods where FIND_IN_SET(id_,#{complementGoodsIdList});
  536. </select>
  537. <select id="exportGoods" resultMap="Goods">
  538. SELECT g.*,gc.name_ goods_category_name_,
  539. GROUP_CONCAT(gs.name_) child_name_,GROUP_CONCAT(gs.sn_) child_sn_,
  540. GROUP_CONCAT(gs.id_) child_id_,GROUP_CONCAT(gs.organ_cost_price_) child_organ_cost_price_ FROM goods g
  541. LEFT JOIN goods_category gc ON g.goods_category_id_ = gc.id_
  542. left join goods gs ON FIND_IN_SET(gs.id_,g.complement_goods_id_list_)
  543. <include refid="queryGoodsPageSql"/>
  544. GROUP BY g.id_
  545. ORDER BY g.id_ DESC
  546. </select>
  547. <sql id="replacementQuerySql">
  548. <where>
  549. g.status_ != 0
  550. AND g.type_ = 'INSTRUMENT'
  551. AND gc.del_flag_ = 0 and g.tenant_id_ = #{tenantId}
  552. <if test="organId != null">
  553. AND FIND_IN_SET(#{organId},g.replacement_show_organ_id_)
  554. </if>
  555. <if test="subjectId != null">
  556. AND sgm.subject_id_ = #{subjectId}
  557. </if>
  558. <if test="brand != null and brand!=''">
  559. AND g.brand_ = #{brand}
  560. </if>
  561. <if test="specification != null and specification!=''">
  562. AND g.specification_ = #{specification}
  563. </if>
  564. </where>
  565. </sql>
  566. <update id="updateStatus">
  567. update goods set status_= #{status}
  568. where id_ in
  569. <foreach collection="goodIdList" separator="," open="(" close=")" item="item">
  570. #{item}
  571. </foreach>
  572. </update>
  573. <update id="updateStock">
  574. <foreach collection="goodsList" item="goods" separator=";">
  575. UPDATE goods set stock_count_ = #{goods.stockCount}
  576. where id_ = #{goods.id}
  577. </foreach>
  578. </update>
  579. </mapper>