GoodsDao.xml 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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. <mapper namespace="com.kmall.admin.dao.GoodsDao">
  4. <resultMap type="com.kmall.admin.entity.GoodsEntity" id="goodsMap">
  5. <result property="id" column="id"/>
  6. <result property="merchSn" column="merch_sn"/>
  7. <!--<result property="categoryId" column="category_id"/>-->
  8. <result property="goodsSn" column="goods_sn"/>
  9. <result property="name" column="name"/>
  10. <!--<result property="brandId" column="brand_id"/>-->
  11. <!--<result property="freightId" column="freight_id"/>-->
  12. <result property="brand" column="brand"/>
  13. <result property="goodsNumber" column="goods_number"/>
  14. <result property="keywords" column="keywords"/>
  15. <result property="goodsBrief" column="goods_brief"/>
  16. <result property="goodsDesc" column="goods_desc"/>
  17. <result property="isOnSale" column="is_on_sale"/>
  18. <result property="addTime" column="add_time"/>
  19. <result property="sortOrder" column="sort_order"/>
  20. <result property="isDelete" column="is_delete"/>
  21. <!--<result property="attributeCategory" column="attribute_category"/>-->
  22. <result property="counterPrice" column="counter_price"/>
  23. <result property="extraPrice" column="extra_price"/>
  24. <result property="isNew" column="is_new"/>
  25. <result property="goodsUnit" column="goods_unit"/>
  26. <result property="primaryPicUrl" column="primary_pic_url"/>
  27. <result property="listPicUrl" column="list_pic_url"/>
  28. <!--<result property="retailPrice" column="retail_price"/>-->
  29. <result property="sellVolume" column="sell_volume"/>
  30. <result property="primaryProductId" column="primary_product_id"/>
  31. <result property="unitPrice" column="unit_price"/>
  32. <result property="promotionDesc" column="promotion_desc"/>
  33. <result property="promotionTag" column="promotion_tag"/>
  34. <result property="appExclusivePrice" column="app_exclusive_price"/>
  35. <result property="isAppExclusive" column="is_app_exclusive"/>
  36. <result property="isLimited" column="is_limited"/>
  37. <result property="isHot" column="is_hot"/>
  38. <!--<result property="marketPrice" column="market_price"/>-->
  39. <result property="goodsType" column="goodsType"/>
  40. <result property="sku" column="sku"/>
  41. <result property="goodsBizType" column="goods_biz_type"/>
  42. <result column="creater_sn" property="createrSn" jdbcType="VARCHAR"/>
  43. <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
  44. <result column="moder_sn" property="moderSn" jdbcType="VARCHAR"/>
  45. <result column="mod_time" property="modTime" jdbcType="TIMESTAMP"/>
  46. <result column="tstm" property="tstm" jdbcType="TIMESTAMP"/>
  47. <result property="prodBarcode" column="prod_barcode"/>
  48. <result property="unitCode" column="unit_code"/>
  49. <result property="goodsDesc" column="goods_desc"/>
  50. <result property="cusGoodsCode" column="cus_goods_code"/>
  51. <result property="ciqProdModel" column="ciq_prod_model"/>
  52. <result property="oriCntCode" column="ori_cnt_code"/>
  53. <result property="cusDeclEle" column="cus_decl_ele"/>
  54. <result property="cusRecCode" column="cus_rec_code"/>
  55. <result property="supplierId" column="supplier_id"/>
  56. <result property="stockNum" column="stock_num"/>
  57. <result property="storeName" column="store_name"/>
  58. <result property="productId" column="productId"/>
  59. <result property="storeId" column="storeId"/>
  60. <result column="merch_name" property="merchName"/>
  61. <result column="storeMarketPrice" property="storeMarketPrice"/>
  62. <result column="storeRetailPrice" property="storeRetailPrice"/>
  63. <result column="third_party_merch_code" property="thirdPartyMerchCode"/>
  64. <result column="isStockShare" property="isStockShare"/>
  65. <result column="gross_weight" property="grossWeight"/>
  66. <result column="net_weight" property="netWeight"/>
  67. <result property="isGoodsShareStock" column="is_goods_share_stock"/>
  68. <result column="cost_price" property="costPrice"/>
  69. <result property="dailyPrice" column="daily_price"/>
  70. <result column="last_sale_time" property="lastSaleTime" jdbcType="TIMESTAMP"/>
  71. <result column="mychem_id" property="mychemId"/>
  72. <result column="hs_code" property="hsCode"/>
  73. <result column="hs_code_name" property="hsCodeName"/>
  74. <result column="is_sync_hs_code" property="isSyncHsCode"/>
  75. <result column="is_sync_goods_rate" property="isSyncGoodsRate"/>
  76. <result column="imp_consum_tax_rate" property="impConsumTaxRate"/>
  77. <result column="value_added_tax_rate" property="valueAddedTaxRate"/>
  78. <result column="legal_unit1_qty" property="legalUnit1Qty"/>
  79. <result column="legal_unit2_qty" property="legalUnit2Qty"/>
  80. <result column="cosm_threshold_value" property="cosmThresholdValue"/>
  81. <result column="to_be_restored" property="toBeRestored" />
  82. </resultMap>
  83. <select id="queryObject" resultType="com.kmall.admin.entity.GoodsEntity">
  84. SELECT
  85. a.*, CASE
  86. when g.id > 0 then 2 else 0 end as goodsType,
  87. mb.third_party_merch_code,
  88. mb.is_stock_share isStockShare,
  89. mb.is_supplier_goods 'isSupplierGoods'
  90. FROM
  91. mall_goods a
  92. LEFT JOIN mall_goods_group g ON g.goods_id = a.id AND g.open_status != 3
  93. LEFT JOIN third_merchant_biz mb ON a.third_party_merch_code = mb.third_party_merch_code
  94. WHERE a.id = #{value}
  95. </select>
  96. <select id="queryObjectByStoreId" resultMap="goodsMap">
  97. select
  98. a.sku,
  99. a.id,
  100. psr1.category_id,
  101. a.goods_sn,
  102. a.name,
  103. psr1.brand_id,
  104. a.goods_number,
  105. a.keywords,
  106. a.goods_brief,
  107. a.is_on_sale,
  108. a.add_time,
  109. a.sort_order,
  110. a.is_delete,
  111. psr1.attribute_category,
  112. a.counter_price,
  113. a.extra_price,
  114. a.is_new,
  115. a.goods_unit,
  116. a.primary_pic_url,
  117. a.list_pic_url,
  118. psr1.retail_price,
  119. psr1.sell_volume,
  120. a.primary_product_id,
  121. a.unit_price,
  122. a.promotion_desc,
  123. a.promotion_tag,
  124. a.app_exclusive_price,
  125. a.is_app_exclusive,
  126. a.is_limited,
  127. a.is_hot,
  128. a.merch_sn,
  129. a.to_be_restored,
  130. m.merch_name,
  131. psr1.store_id,
  132. psr1.market_price,
  133. psr1.stock_num,
  134. a.goods_desc,a.goods_biz_type,a.goods_rate,
  135. a.sell_volume goods_sell_volume,
  136. mb.third_party_merch_code,
  137. mb.is_stock_share isStockShare,
  138. mb.is_supplier_goods 'isSupplierGoods',
  139. mb2.third_party_merch_code 'supplierThirdMerchCode',
  140. mb2.is_stock_share 'isStockShareBySuppler',
  141. a.hs_code, a.legal_unit1_qty, a.legal_unit2_qty,a.ciq_prod_model
  142. from mall_goods a left join mall_merch m on a.merch_sn = m.merch_sn
  143. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  144. LEFT JOIN mall_store s ON s.id = psr1.store_id
  145. LEFT JOIN third_merchant_biz mb on s.third_party_merch_code = mb.third_party_merch_code
  146. LEFT JOIN third_merchant_biz mb2 ON a.third_party_merch_code = mb2.third_party_merch_code
  147. where a.id = #{id} and psr1.store_id = #{storeId}
  148. </select>
  149. <select id="queryGoodsByGoodsSnAndStoreId" resultMap="goodsMap">
  150. select
  151. a.sku,
  152. a.id,
  153. psr1.category_id,
  154. a.goods_sn,
  155. a.name,
  156. psr1.brand_id,
  157. a.goods_number,
  158. a.keywords,
  159. a.goods_brief,
  160. a.is_on_sale,
  161. a.add_time,
  162. a.sort_order,
  163. a.is_delete,
  164. psr1.attribute_category,
  165. a.counter_price,
  166. a.extra_price,
  167. a.is_new,
  168. a.goods_unit,
  169. a.primary_pic_url,
  170. a.list_pic_url,
  171. psr1.retail_price,
  172. psr1.sell_volume,
  173. a.primary_product_id,
  174. a.unit_price,
  175. a.promotion_desc,
  176. a.promotion_tag,
  177. a.app_exclusive_price,
  178. a.is_app_exclusive,
  179. a.is_limited,
  180. a.is_hot,
  181. a.merch_sn,
  182. a.to_be_restored,
  183. m.merch_name,
  184. psr1.store_id,
  185. psr1.market_price,
  186. psr1.stock_num,
  187. a.goods_desc,a.goods_biz_type,a.goods_rate,
  188. a.sell_volume goods_sell_volume,
  189. mb.third_party_merch_code,
  190. mb.is_stock_share isStockShare,
  191. mb.is_supplier_goods 'isSupplierGoods',
  192. mb2.third_party_merch_code 'supplierThirdMerchCode',
  193. mb2.is_stock_share 'isStockShareBySuppler',
  194. a.hs_code, a.legal_unit1_qty, a.legal_unit2_qty,a.ciq_prod_model
  195. from mall_goods a left join mall_merch m on a.merch_sn = m.merch_sn
  196. LEFT JOIN mall_product_store_rela psr1 ON a.id = psr1.goods_id and a.merch_sn = psr1.merch_sn
  197. LEFT JOIN mall_store s ON s.id = psr1.store_id
  198. LEFT JOIN third_merchant_biz mb on s.third_party_merch_code = mb.third_party_merch_code
  199. LEFT JOIN third_merchant_biz mb2 ON a.third_party_merch_code = mb2.third_party_merch_code
  200. where a.goods_sn = #{goodsSn} and psr1.store_id = #{storeId}
  201. </select>
  202. <select id="queryObjectByProdBarcodeAndBizType" resultType="com.kmall.admin.entity.GoodsEntity">
  203. SELECT
  204. a.id,a.sku,a.goods_sn,a.name,a.list_pic_url,a.prod_barcode,r.market_price storeMarketPrice,r.retail_price storeRetailPrice ,r.stock_num,s.store_name,r.product_id,s.id 'storeId',
  205. a.hs_code as hsCode , a.legal_unit1_qty as legalUnit1Qty , a.legal_unit2_qty as legalUnit2Qty,a.ciq_prod_model as ciqProdModel,a.to_be_restored
  206. FROM
  207. mall_goods a
  208. LEFT JOIN mall_product_store_rela r ON r.goods_id = a.id
  209. inner join mall_store s on r.store_id=s.id
  210. where a.prod_barcode = #{prodBarcode} and a.goods_biz_type = 11 and r.store_id = #{storeId}
  211. </select>
  212. <select id="queryObjectByProdBarcodeAndStore" resultType="com.kmall.admin.entity.GoodsEntity">
  213. SELECT
  214. a.id,a.sku,a.goods_number,a.goods_sn,a.name,a.list_pic_url,a.prod_barcode,r.market_price storeMarketPrice,r.retail_price storeRetailPrice ,r.stock_num,s.store_name,r.product_id,s.id 'storeId',a.goods_rate as goodsRate,
  215. a.hs_code as hsCode , a.legal_unit1_qty as legalUnit1Qty , a.legal_unit2_qty as legalUnit2Qty,a.ciq_prod_model as ciqProdModel,a.to_be_restored
  216. FROM
  217. mall_goods a
  218. LEFT JOIN mall_product_store_rela r ON r.goods_id = a.id
  219. inner join mall_store s on r.store_id=s.id
  220. where a.prod_barcode = #{prodBarcode} and r.store_id = #{storeId}
  221. and r.stock_num > 0
  222. limit 1
  223. </select>
  224. <select id="queryObjectByProdBarcode" resultType="com.kmall.admin.entity.GoodsEntity">
  225. SELECT
  226. a.id,a.sku,a.goods_sn,a.name,a.list_pic_url,a.prod_barcode,r.market_price storeMarketPrice,r.retail_price storeRetailPrice ,r.stock_num,s.store_name,r.product_id,s.id 'storeId',
  227. a.hs_code as hsCode , a.legal_unit1_qty as legalUnit1Qty , a.legal_unit2_qty as legalUnit2Qty,a.ciq_prod_model as ciqProdModel,a.to_be_restored
  228. FROM
  229. mall_goods a
  230. LEFT JOIN mall_product_store_rela r ON r.goods_id = a.id
  231. inner join mall_store s on r.store_id=s.id
  232. where a.prod_barcode = #{prodBarcode} and a.is_delete = 0
  233. <if test="goodsId != null and goodsId != ''">
  234. AND a.id != #{goodsId}
  235. </if>
  236. <if test="merchSn != null and merchSn != ''">
  237. AND a.merch_sn = #{merchSn}
  238. </if>
  239. </select>
  240. <select id="queryGoodsDetailsByProdBarcode" resultType="com.kmall.admin.dto.GoodsDetailsDto">
  241. SELECT distinct
  242. a.goods_sn as GoodsSn,m.retail_price as retailPrice,a.prod_barcode as prodBarcode,a.name,a.brand,a.goods_desc as goodsDesc,a.goods_unit as goodsUnit,a.goods_rate as goodsRate,a.primary_pic_url ,m.stock_num as stockNum,r.value as specification
  243. ,a.hs_code as hsCode , a.legal_unit1_qty as legalUnit1Qty , a.legal_unit2_qty as legalUnit2Qty,a.ciq_prod_model as ciqProdModel,a.to_be_restored
  244. FROM
  245. mall_goods a
  246. LEFT JOIN mall_goods_specification r ON r.goods_id = a.id
  247. left join mall_product_store_rela m on m.goods_id = a.id and r.goods_id = m.goods_id
  248. where a.prod_barcode = #{prodBarcode} and m.store_id = #{storeId}
  249. and m.stock_num > 0 order by m.stock_num desc
  250. limit 1
  251. </select>
  252. <select id="queryObjectBySn" resultType="com.kmall.admin.entity.GoodsEntity">
  253. SELECT
  254. a.*, CASE
  255. when g.id > 0 then 2 else 0 end as goodsType
  256. FROM
  257. mall_goods a
  258. LEFT JOIN mall_goods_group g ON g.goods_id = a.id
  259. AND g.open_status != 3
  260. where a.goods_sn = #{goodsSn}
  261. </select>
  262. <select id="queryList" resultType="com.kmall.admin.entity.GoodsEntity">
  263. select * from (
  264. select
  265. mall_goods.*,
  266. case when mall_goods_group.id > 0 then 2 else 0 end as goodsType,
  267. m.merch_name merchName, mb.is_stock_share isStockShare,
  268. catagory.keywords as categoryName
  269. from mall_goods
  270. left join mall_merch m on mall_goods.merch_sn = m.merch_sn
  271. left join mall_goods_group on mall_goods_group.goods_id = mall_goods.id and mall_goods_group.open_status != 3
  272. left join third_merchant_biz mb on mb.third_party_merch_code = mall_goods.third_party_merch_code and
  273. mb.merch_sn=mall_goods.merch_sn
  274. left join mall_category catagory on catagory.id = mall_goods.category_id
  275. WHERE 1=1
  276. <!-- 数据过滤 -->
  277. ${filterSql}
  278. <if test="merchSn != null and merchSn.trim() != ''">
  279. AND mall_goods.merch_sn = #{merchSn}
  280. </if>
  281. <if test="prodBarcode != null and prodBarcode.trim() != ''">
  282. AND mall_goods.prod_barcode = #{prodBarcode}
  283. </if>
  284. <if test="thirdPartyMerchCode != null and thirdPartyMerchCode.trim() != ''">
  285. AND mall_goods.third_party_merch_code = #{thirdPartyMerchCode}
  286. </if>
  287. <if test="thirdMerchSn != null and thirdMerchSn.trim() != ''">
  288. AND mb.third_merch_sn = #{thirdMerchSn}
  289. </if>
  290. <if test="goodsSn != null and goodsSn != ''">
  291. AND mall_goods.goods_sn like concat('%',#{goodsSn},'%')
  292. </if>
  293. <if test="name != null and name != ''">
  294. AND mall_goods.name LIKE concat('%',#{name},'%')
  295. </if>
  296. <if test="englishName != null and englishName != ''">
  297. AND mall_goods.english_name LIKE concat('%',#{englishName},'%')
  298. </if>
  299. <!--<if test="brandId != null and brandId != ''">
  300. AND mall_goods.brand_id = #{brandId}
  301. </if>
  302. <if test="freightId != null and freightId != ''">
  303. AND mall_goods.freight_id = #{freightId}
  304. </if>
  305. <if test="categoryId != null and categoryId != ''">
  306. AND mall_goods.category_id = #{categoryId}
  307. </if>
  308. <if test="category != null and category != ''">
  309. AND mall_goods.category_id IN (select id from mall_category where parent_id = #{category})
  310. </if>
  311. <if test="categoryTwo != null and categoryTwo != ''">
  312. AND mall_goods.category_id = #{categoryTwo}
  313. </if>-->
  314. <if test="sku != null and sku != ''">
  315. AND mall_goods.sku LIKE concat('%',#{sku},'%')
  316. </if>
  317. <if test="plu != null and plu != ''">
  318. AND mall_goods.plu LIKE concat('%',#{plu},'%')
  319. </if>
  320. <if test="isDelete != null">
  321. AND mall_goods.is_Delete = #{isDelete}
  322. </if>
  323. <if test="isOnSale != null">
  324. AND mall_goods.is_on_sale = #{isOnSale}
  325. </if>
  326. <if test="goodsBizType != null and goodsBizType != ''">
  327. AND mall_goods.goods_biz_type = #{goodsBizType}
  328. </if>
  329. <if test="id != null and id != ''">
  330. AND mall_goods.id = #{id}
  331. </if>
  332. <if test="storeId != null and storeId != ''">
  333. AND mall_goods.third_party_merch_code = ( SELECT third_party_merch_code FROM mall_store WHERE id =
  334. #{storeId} )
  335. AND mall_goods.id NOT IN (
  336. SELECT
  337. goods_id
  338. FROM
  339. mall_product_store_rela pp
  340. WHERE
  341. store_id = #{storeId}
  342. )
  343. </if>
  344. <if test="storeIdBySupplier != null and storeIdBySupplier != ''">
  345. AND mall_goods.id NOT IN (
  346. SELECT
  347. goods_id
  348. FROM
  349. mall_product_store_rela pp
  350. WHERE
  351. store_id = #{storeIdBySupplier} and supplier_third_id = #{thirdMerchSn}
  352. )
  353. </if>
  354. ) temp where 1=1
  355. <if test="lastSaleTime != null and lastSaleTime != ''">
  356. AND temp.last_sale_time &gt;= #{lastSaleTime} or temp.last_sale_time is null
  357. </if>
  358. <choose>
  359. <when test="sidx != null and sidx.trim() != ''">
  360. order by ${sidx} ${order}
  361. </when>
  362. <otherwise>
  363. order by temp.id desc
  364. </otherwise>
  365. </choose>
  366. <if test="offset != null and limit != null">
  367. limit #{offset}, #{limit}
  368. </if>
  369. </select>
  370. <select id="querySame" resultType="com.kmall.admin.entity.GoodsEntity">
  371. select
  372. mall_goods.*,
  373. case when mall_goods_group.id > 0 then 2 else 0 end as goodsType
  374. from mall_goods
  375. left join mall_goods_group on mall_goods_group.goods_id = mall_goods.id and mall_goods_group.open_status != 3
  376. WHERE 1=1
  377. <!-- 数据过滤 -->
  378. ${filterSql}
  379. <if test="isSame != null and isSame != ''">
  380. AND ((mall_goods.sku = #{sku} AND mall_goods.goods_biz_type = #{goodsBizType}) OR mall_goods.goods_sn =
  381. #{goodsSn})
  382. <if test="id != null and id != ''">
  383. AND mall_goods.id != #{id}
  384. </if>
  385. </if>
  386. <choose>
  387. <when test="sidx != null and sidx.trim() != ''">
  388. order by ${sidx} ${order}
  389. </when>
  390. <otherwise>
  391. order by mall_goods.id desc
  392. </otherwise>
  393. </choose>
  394. <if test="offset != null and limit != null">
  395. limit #{offset}, #{limit}
  396. </if>
  397. </select>
  398. <select id="queryTotal" resultType="int">
  399. select count(*) from mall_goods
  400. left join mall_merch m on mall_goods.merch_sn = m.merch_sn
  401. left join mall_goods_group on mall_goods_group.goods_id = mall_goods.id and mall_goods_group.open_status != 3
  402. WHERE 1=1
  403. <!-- 数据过滤 -->
  404. ${filterSql}
  405. <if test="merchSn != null and merchSn.trim() != ''">
  406. AND mall_goods.merch_sn = #{merchSn}
  407. </if>
  408. <if test="prodBarcode != null and prodBarcode.trim() != ''">
  409. AND mall_goods.prod_barcode = #{prodBarcode}
  410. </if>
  411. <if test="thirdPartyMerchCode != null and thirdPartyMerchCode.trim() != ''">
  412. AND mall_goods.third_party_merch_code = #{thirdPartyMerchCode}
  413. </if>
  414. <if test="goodsSn != null and goodsSn != ''">
  415. AND mall_goods.goods_sn like concat('%',#{goodsSn},'%')
  416. </if>
  417. <if test="name != null and name != ''">
  418. AND mall_goods.name LIKE concat('%',#{name},'%')
  419. </if>
  420. <if test="sku != null and sku != ''">
  421. AND mall_goods.sku LIKE concat('%',#{sku},'%')
  422. </if>
  423. <if test="isDelete != null">
  424. AND mall_goods.is_Delete = #{isDelete}
  425. </if>
  426. <if test="isOnSale != null">
  427. AND mall_goods.is_on_sale = #{isOnSale}
  428. </if>
  429. <if test="goodsBizType != null and goodsBizType != ''">
  430. AND mall_goods.goods_biz_type = #{goodsBizType}
  431. </if>
  432. <if test="storeId != null and storeId != ''">
  433. AND mall_goods.third_party_merch_code = ( SELECT third_party_merch_code FROM mall_store WHERE id =
  434. #{storeId} )
  435. AND mall_goods.id NOT IN (
  436. SELECT
  437. goods_id
  438. FROM
  439. mall_product_store_rela pp
  440. LEFT JOIN mall_goods gg ON pp.goods_id = gg.id
  441. AND pp.merch_sn = gg.merch_sn
  442. AND pp.merch_sn
  443. LEFT JOIN mall_store s ON pp.store_id = s.id
  444. AND s.third_party_merch_code = gg.third_party_merch_code
  445. WHERE
  446. store_id = #{storeId}
  447. )
  448. </if>
  449. </select>
  450. <insert id="save" parameterType="com.kmall.admin.entity.GoodsEntity" useGeneratedKeys="true" keyProperty="id">
  451. insert into mall_goods(
  452. `merch_sn`,
  453. third_party_merch_code,
  454. `supplier_id`,
  455. `goods_sn`,
  456. `prod_barcode`,
  457. `sku`,
  458. `plu`,
  459. `english_name`,
  460. `cost_price`,
  461. `daily_price`,
  462. `goods_biz_type`,
  463. `name`,
  464. `unit_code`,
  465. `brand`,
  466. `goods_number`,
  467. `keywords`,
  468. `goods_brief`,
  469. `goods_desc`,
  470. `cus_goods_code`,
  471. `ciq_prod_model`,
  472. `ori_cnt_code`,
  473. `cus_decl_ele`,
  474. `cus_rec_code`,
  475. `is_on_sale`,
  476. `add_time`,
  477. `sort_order`,
  478. `is_delete`,
  479. `counter_price`,
  480. `extra_price`,
  481. `is_new`,
  482. `goods_unit`,
  483. `primary_pic_url`,
  484. `list_pic_url`,
  485. `goods_rate`,
  486. `sell_volume`,
  487. `primary_product_id`,
  488. `unit_price`,
  489. `promotion_desc`,
  490. `promotion_tag`,
  491. `app_exclusive_price`,
  492. `is_app_exclusive`,
  493. `gross_weight`,
  494. `net_weight`,
  495. is_goods_share_stock,
  496. `is_limited`,
  497. `is_hot`,
  498. `creater_sn`,
  499. `create_time`,
  500. `moder_sn`,
  501. `mod_time`,
  502. `mychem_id`,
  503. `hs_code`,
  504. `hs_code_name`,
  505. `is_sync_hs_code`,
  506. `is_sync_goods_rate`,
  507. `imp_consum_tax_rate`,
  508. `value_added_tax_rate`,
  509. `legal_unit1_qty`,
  510. `legal_unit2_qty`,
  511. `cosm_threshold_value`,
  512. `to_be_restored`,
  513. `tstm`)
  514. values(
  515. #{merchSn},
  516. #{thirdPartyMerchCode},
  517. #{supplierId},
  518. #{goodsSn},
  519. #{prodBarcode},
  520. #{sku},
  521. #{plu},
  522. #{englishName},
  523. #{costPrice},
  524. #{dailyPrice},
  525. #{goodsBizType},
  526. #{name},
  527. #{unitCode},
  528. #{brand},
  529. #{goodsNumber},
  530. #{keywords},
  531. #{goodsBrief},
  532. #{goodsDesc},
  533. #{cusGoodsCode},
  534. #{ciqProdModel},
  535. #{oriCntCode},
  536. #{cusDeclEle},
  537. #{cusRecCode},
  538. #{isOnSale},
  539. #{addTime},
  540. #{sortOrder},
  541. #{isDelete},
  542. #{counterPrice},
  543. #{extraPrice},
  544. #{isNew},
  545. #{goodsUnit},
  546. #{primaryPicUrl},
  547. #{listPicUrl},
  548. #{goodsRate},
  549. #{sellVolume},
  550. #{primaryProductId},
  551. #{unitPrice},
  552. #{promotionDesc},
  553. #{promotionTag},
  554. #{appExclusivePrice},
  555. #{isAppExclusive},
  556. #{grossWeight},
  557. #{netWeight},
  558. #{isGoodsShareStock},
  559. #{isLimited},
  560. #{isHot},
  561. #{createrSn},
  562. #{createTime},
  563. #{moderSn},
  564. #{modTime},
  565. #{mychemId},
  566. #{hsCode},
  567. #{hsCodeName},
  568. '0',
  569. '0',
  570. #{impConsumTaxRate},
  571. #{valueAddedTaxRate},
  572. #{legalUnit1Qty},
  573. #{legalUnit2Qty},
  574. #{cosmThresholdValue},
  575. #{toBeRestored},
  576. #{tstm})
  577. </insert>
  578. <update id="update" parameterType="com.kmall.admin.entity.GoodsEntity">
  579. update mall_goods
  580. <set>
  581. <if test="merchSn != null">`merch_sn` = #{merchSn},</if>
  582. <if test="thirdPartyMerchCode != null">`third_party_merch_code` = #{thirdPartyMerchCode},</if>
  583. <if test="supplierId != null">`supplier_id` = #{supplierId},</if>
  584. <if test="goodsSn != null">`goods_sn` = #{goodsSn},</if>
  585. <if test="prodBarcode != null">`prod_barcode` = #{prodBarcode},</if>
  586. <if test="sku != null">`sku` = #{sku},</if>
  587. <if test="plu != null">`plu` = #{plu},</if>
  588. <if test="englishName != null">`english_name` = #{englishName},</if>
  589. <if test="costPrice != null">`cost_price` = #{costPrice},</if>
  590. <if test="dailyPrice != null">`daily_price` = #{dailyPrice},</if>
  591. <if test="goodsBizType != null">`goods_biz_type` = #{goodsBizType},</if>
  592. <if test="name != null">`name` = #{name},</if>
  593. <if test="unitCode != null">`unit_code` = #{unitCode},</if>
  594. <if test="brand != null">`brand` = #{brand},</if>
  595. <if test="goodsNumber != null">`goods_number` = #{goodsNumber},</if>
  596. <if test="keywords != null">`keywords` = #{keywords},</if>
  597. <if test="goodsBrief != null">`goods_brief` = #{goodsBrief},</if>
  598. <if test="goodsDesc != null">`goods_desc` = #{goodsDesc},</if>
  599. <if test="cusGoodsCode != null">`cus_goods_code` = #{cusGoodsCode},</if>
  600. <if test="ciqProdModel != null">`ciq_prod_model` = #{ciqProdModel},</if>
  601. <if test="oriCntCode != null">`ori_cnt_code` = #{oriCntCode},</if>
  602. <if test="cusDeclEle != null">`cus_decl_ele` = #{cusDeclEle},</if>
  603. <if test="cusRecCode != null">`cus_rec_code` = #{cusRecCode},</if>
  604. <if test="isOnSale != null">`is_on_sale` = #{isOnSale},</if>
  605. <if test="addTime != null">`add_time` = #{addTime},</if>
  606. <if test="sortOrder != null">`sort_order` = #{sortOrder},</if>
  607. <if test="isDelete != null">`is_delete` = #{isDelete},</if>
  608. <if test="counterPrice != null">`counter_price` = #{counterPrice},</if>
  609. <if test="extraPrice != null">`extra_price` = #{extraPrice},</if>
  610. <if test="isNew != null">`is_new` = #{isNew},</if>
  611. <if test="goodsUnit != null">`goods_unit` = #{goodsUnit},</if>
  612. <if test="primaryPicUrl != null">`primary_pic_url` = #{primaryPicUrl},</if>
  613. <if test="listPicUrl != null">`list_pic_url` = #{listPicUrl},</if>
  614. <if test="goodsRate != null">`goods_rate` = #{goodsRate},</if>
  615. <if test="sellVolume != null">`sell_volume` = #{sellVolume},</if>
  616. <if test="primaryProductId != null">`primary_product_id` = #{primaryProductId},</if>
  617. <if test="unitPrice != null">`unit_price` = #{unitPrice},</if>
  618. <if test="promotionDesc != null">`promotion_desc` = #{promotionDesc},</if>
  619. <if test="promotionTag != null">`promotion_tag` = #{promotionTag},</if>
  620. <if test="appExclusivePrice != null">`app_exclusive_price` = #{appExclusivePrice},</if>
  621. <if test="isAppExclusive != null">`is_app_exclusive` = #{isAppExclusive},</if>
  622. <if test="grossWeight != null">`gross_weight` = #{grossWeight},</if>
  623. <if test="netWeight != null">`net_weight` = #{netWeight},</if>
  624. <if test="isGoodsShareStock != null">`is_goods_share_stock` = #{isGoodsShareStock},</if>
  625. <if test="isLimited != null">`is_limited` = #{isLimited},</if>
  626. <if test="isHot != null">`is_hot` = #{isHot},</if>
  627. <if test="createrSn != null">`creater_sn` = #{createrSn},</if>
  628. <if test="createTime != null">`create_time` = #{createTime},</if>
  629. <if test="moderSn != null">`moder_sn` = #{moderSn},</if>
  630. <if test="modTime != null">`mod_time` = #{modTime},</if>
  631. <if test="tstm != null">`tstm` = #{tstm},</if>
  632. <if test="lastSaleTime != null">`last_sale_time` = #{lastSaleTime},</if>
  633. <if test="mychemId != null">`mychem_id` = #{mychemId},</if>
  634. <if test="hsCode != null">`hs_code` = #{hsCode},</if>
  635. <if test="hsCodeName != null">`hs_code_name` = #{hsCodeName},</if>
  636. <if test="isSyncHsCode != null">`is_sync_hs_code` = #{isSyncHsCode},</if>
  637. <if test="isSyncGoodsRate != null">`is_sync_goods_rate` = #{isSyncGoodsRate},</if>
  638. <if test="impConsumTaxRate != null">`imp_consum_tax_rate` = #{impConsumTaxRate},</if>
  639. <if test="valueAddedTaxRate != null">`value_added_tax_rate` = #{valueAddedTaxRate},</if>
  640. <if test="legalUnit1Qty != null">`legal_unit1_qty` = #{legalUnit1Qty},</if>
  641. <if test="legalUnit2Qty != null">`legal_unit2_qty` = #{legalUnit2Qty},</if>
  642. <if test="cosmThresholdValue != null">`cosm_threshold_value` = #{cosmThresholdValue}</if>
  643. <if test="toBeRestored != null">`to_be_restored` = #{toBeRestored}</if>
  644. </set>
  645. where id = #{id}
  646. </update>
  647. <delete id="delete">
  648. delete from mall_goods where id = #{value}
  649. </delete>
  650. <delete id="deleteBatch">
  651. delete from mall_goods where id in
  652. <foreach item="id" collection="array" open="(" separator="," close=")">
  653. #{id}
  654. </foreach>
  655. </delete>
  656. <select id="queryMaxId" resultType="java.lang.Long" parameterType="map">
  657. SELECT MAX(id) FROM mall_goods
  658. </select>
  659. <select id="searchGoodsPanoramaDtoByKeyword" resultType="com.kmall.admin.dto.GoodsPanoramaDto">
  660. SELECT
  661. g.id id,g.name `name`,g.name simpleName,g.ciq_prod_model ciqProdModel,
  662. g.goods_unit goodsBasicUnit,g.category_id categoryId,c.name categoryName,
  663. g.goods_unit goodsPurchaseUnit,g.supplier_id supplierId,s.child_supplier_name supplierName,
  664. g.prod_barcode prodBarcode,g.plu plu,g.goods_sn goodsSn,g.brand brand
  665. FROM
  666. mall_goods g
  667. INNER JOIN mall_category c
  668. INNER JOIN mall_supplier s
  669. WHERE
  670. g.category_id = c.id
  671. and g.supplier_id = s.id
  672. AND (g.goods_sn=#{keyword} OR g.prod_barcode=#{keyword})
  673. </select>
  674. <select id="queryExportList" resultType="com.kmall.admin.entity.GoodsEntity">
  675. select * from (
  676. select
  677. mall_goods.*,
  678. case when mall_goods_group.id > 0 then 2 else 0 end as goodsType,
  679. m.merch_name merchName, mb.is_stock_share isStockShare,
  680. catagory.keywords as categoryName,
  681. scnc.`name` as oriCntName
  682. from mall_goods
  683. left join mall_merch m on mall_goods.merch_sn = m.merch_sn
  684. left join mall_goods_group on mall_goods_group.goods_id = mall_goods.id and mall_goods_group.open_status != 3
  685. left join third_merchant_biz mb on mb.third_party_merch_code = mall_goods.third_party_merch_code and
  686. mb.merch_sn=mall_goods.merch_sn
  687. left join mall_category catagory on catagory.id = mall_goods.category_id
  688. left join sys_cus_nation_code scnc on mall_goods.ori_cnt_code = scnc.code
  689. WHERE 1=1
  690. <!-- 数据过滤 -->
  691. ${filterSql}
  692. <if test="merchSn != null and merchSn.trim() != ''">
  693. AND mall_goods.merch_sn = #{merchSn}
  694. </if>
  695. <if test="prodBarcode != null and prodBarcode.trim() != ''">
  696. AND mall_goods.prod_barcode = #{prodBarcode}
  697. </if>
  698. <if test="thirdPartyMerchCode != null and thirdPartyMerchCode.trim() != ''">
  699. AND mall_goods.third_party_merch_code = #{thirdPartyMerchCode}
  700. </if>
  701. <if test="goodsSn != null and goodsSn != ''">
  702. AND mall_goods.goods_sn like concat('%',#{goodsSn},'%')
  703. </if>
  704. <if test="name != null and name != ''">
  705. AND mall_goods.name LIKE concat('%',#{name},'%')
  706. </if>
  707. <if test="englishName != null and englishName != ''">
  708. AND mall_goods.english_name LIKE concat('%',#{englishName},'%')
  709. </if>
  710. <if test="goodsBizType != null and goodsBizType != ''">
  711. AND mall_goods.goods_biz_type = #{goodsBizType}
  712. </if>
  713. <if test="isDelete != null">
  714. AND mall_goods.is_Delete = #{isDelete}
  715. </if>
  716. ) temp
  717. where 1=1
  718. <if test="lastSaleTime != null and lastSaleTime != ''">
  719. AND temp.last_sale_time &gt;= #{lastSaleTime} or temp.last_sale_time is null
  720. </if>
  721. </select>
  722. <select id="queryForPDFData" resultType="com.kmall.api.entity.exportpdf.PDFGoodsDto">
  723. select
  724. g.name as productName,
  725. g.english_name as englishName,
  726. rela.retail_price as price,
  727. IFNULL((rela.market_price - rela.retail_price ),0) as savings,
  728. g.goods_rate as startFax,
  729. g.goods_rate as endFax,
  730. g.plu as plu,
  731. g.prod_barcode as barCode
  732. from
  733. mall_goods g
  734. left join mall_product_store_rela rela on g.id = rela.goods_id
  735. <where>
  736. <if test="sku != null and sku != ''">
  737. and g.sku = #{sku}
  738. </if>
  739. <if test="prodBarcode != null and prodBarcode != ''">
  740. and g.prod_barcode = #{prodBarcode}
  741. </if>
  742. <if test="storeId != null and storeId != ''">
  743. and rela.store_id = #{storeId}
  744. </if>
  745. </where>
  746. </select>
  747. <select id="queryByBarcode" resultType="com.kmall.admin.entity.GoodsEntity">
  748. select *
  749. from mall_goods
  750. where prod_barcode = #{barCode}
  751. </select>
  752. <select id="queryBySku" resultType="com.kmall.admin.entity.GoodsEntity">
  753. select *
  754. from mall_goods
  755. where sku = #{sku}
  756. </select>
  757. <select id="queryListByBarcode" resultType="com.kmall.admin.entity.GoodsEntity">
  758. SELECT
  759. a.id,a.sku,a.goods_number,a.goods_sn,a.name,a.list_pic_url,a.prod_barcode,r.market_price storeMarketPrice,r.retail_price storeRetailPrice ,r.stock_num,s.store_name,r.product_id,s.id 'storeId',a.goods_rate as goodsRate,
  760. a.hs_code as hsCode , a.legal_unit1_qty as legalUnit1Qty , a.legal_unit2_qty as legalUnit2Qty,a.ciq_prod_model as ciqProdModel,a.to_be_restored
  761. FROM
  762. mall_goods a
  763. LEFT JOIN mall_product_store_rela r ON r.goods_id = a.id
  764. inner join mall_store s on r.store_id=s.id
  765. where a.prod_barcode = #{prodBarcode} and r.store_id = #{storeId}
  766. and r.stock_num > 0 order by r.stock_num desc
  767. </select>
  768. <select id="queryByName" resultType="com.kmall.admin.entity.GoodsEntity">
  769. SELECT DISTINCT
  770. g.id,
  771. g.NAME,
  772. g.sku,
  773. g.prod_barcode
  774. FROM
  775. mall_product_store_rela r
  776. LEFT JOIN mall_goods g ON g.id = r.goods_id
  777. WHERE
  778. r.store_id = #{storeId}
  779. <if test="goodsName != null and goodsName != ''">
  780. AND g.NAME LIKE concat('%',#{goodsName},'%');
  781. </if>
  782. </select>
  783. <select id="queryNonSyncOmsHsCodeSkuList" resultType="java.lang.String">
  784. select sku
  785. from mall_goods
  786. where is_sync_hs_code = '0'
  787. </select>
  788. <select id="queryListBySku" resultType="com.kmall.admin.entity.GoodsEntity">
  789. select *
  790. from mall_goods
  791. where sku = #{sku}
  792. </select>
  793. <select id="queryNonSyncOmsGoodsRateSkuList" resultType="com.kmall.admin.entity.GoodsEntity">
  794. select *
  795. from mall_goods
  796. where is_sync_goods_rate = '0'
  797. </select>
  798. <select id="queryAllList" resultType="com.kmall.admin.entity.GoodsEntity">
  799. select * from mall_goods
  800. </select>
  801. <select id="queryByBarcodeAndSku" resultType="com.kmall.admin.entity.GoodsEntity">
  802. select * from mall_goods where
  803. goods_sn = #{goodsSn} and prod_barcode = #{prodBarcode}
  804. </select>
  805. </mapper>