SearchMapper.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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.caimei365.commodity.mapper.SearchMapper">
  4. <sql id="Search_Product_List">
  5. p.productID as p_id,
  6. p.`name` as p_name,
  7. p.searchKey as p_keyword,
  8. p.tags as p_tags,
  9. p.mainImage as p_image,
  10. p.price1 as p_price,
  11. p.price1TextFlag as p_price_flag,
  12. p.productCode as p_code,
  13. p.sortIndex as p_sort,
  14. p.unit as p_unit,
  15. p.sellNumber as p_sales,
  16. p.favoriteTimes as p_favorite,
  17. p.brandID as p_brand_id,
  18. br.name as p_brand_name,
  19. p.shopID as p_supplier_id,
  20. sh.name as p_supplier_name,
  21. p.bigTypeID as p_category1_id,
  22. b.name as p_category1_name,
  23. p.smallTypeID as p_category2_id,
  24. s.name as p_category2_name,
  25. p.tinyTypeID as p_category3_id,
  26. t.name as p_category3_name,
  27. p.classifyId as p_classify_id,
  28. c.classifyName as p_classify_name,
  29. p.preferredFlag as p_preferred,
  30. p.productCategory as p_type,
  31. p.validFlag as p_valid,
  32. IFNULL(p.visibility,3) as p_visibility,
  33. p.price8Text as p_act_flag
  34. </sql>
  35. <sql id="Product_Joins">
  36. left join tinytype as t on p.tinyTypeID = t.tinyTypeID
  37. left join smalltype as s on p.smallTypeID = s.smallTypeID
  38. left join bigtype as b on p.bigTypeID = b.bigTypeID
  39. left join cm_products_classify as c on p.classifyId = c.id
  40. left join cm_brand as br on p.brandID = br.id
  41. left join shop as sh on p.shopID = sh.shopID
  42. </sql>
  43. <select id="searchProductById" resultType="com.caimei365.commodity.model.search.ProductDO">
  44. select <include refid="Search_Product_List"/>, p.productCategory
  45. from product as p
  46. <include refid="Product_Joins"/>
  47. where p.validFlag in (2,3,9) and p.productCategory = 1
  48. and p.productID = #{productId}
  49. </select>
  50. <select id="findProductCount" resultType="java.lang.Integer">
  51. select count(*)
  52. from product
  53. where validFlag in (2,3,9) and productCategory = 1
  54. </select>
  55. <select id="findProductInvalidCount" resultType="java.lang.Integer">
  56. select count(*)
  57. from product
  58. where validFlag not in (2,3,9) or productCategory != 1
  59. </select>
  60. <select id="findProductInvalidIds" resultType="java.lang.Integer">
  61. select productID
  62. from product
  63. where validFlag not in (2,3,9) or productCategory != 1
  64. </select>
  65. <select id="searchProductList" resultType="com.caimei365.commodity.model.search.ProductDO">
  66. select <include refid="Search_Product_List"/>
  67. from product as p
  68. <include refid="Product_Joins"/>
  69. where p.validFlag in (2,3,9) and productCategory = 1
  70. order by productID desc
  71. </select>
  72. <select id="countMallProduct" resultType="java.lang.Integer">
  73. select COUNT(*) from cm_mall_organize_products
  74. where productID=#{productId} and organizeID=1
  75. </select>
  76. <select id="searchMallProductByProductId" resultType="com.caimei365.commodity.model.search.MallProductDO">
  77. select
  78. m.id as m_id,
  79. m.organizeID as m_organize_id,
  80. m.productID as m_product_id,
  81. m.retailPrice as m_price,
  82. m.classifyID as m_classify_id,
  83. m.delFlag as m_valid,
  84. c.classifyName as m_classify_name
  85. from cm_mall_organize_products as m
  86. left join cm_mall_products_classify as c on m.classifyId = c.id
  87. where m.productID = #{productId} and m.organizeID = 1
  88. limit 1
  89. </select>
  90. <select id="getMallLadderPriceFlag" resultType="java.lang.Integer">
  91. select ladderPriceFlag
  92. from cm_mall_organize_products
  93. where productID = #{productId} and organizeID=1
  94. limit 1
  95. </select>
  96. <select id="getMallLowerLadderPrice" resultType="java.lang.Double">
  97. select MIN(buyPrice)
  98. from cm_mall_product_ladder_price
  99. where delFlag = '0'
  100. and productId = #{productId}
  101. </select>
  102. <select id="findMallIdByProductId" resultType="java.lang.Integer">
  103. select id
  104. from cm_mall_organize_products
  105. where productID = #{productId}
  106. limit 1
  107. </select>
  108. <select id="findMallInvalidIdsByProductIds" resultType="java.lang.Integer">
  109. select id
  110. from cm_mall_organize_products
  111. where productID IN
  112. <foreach collection="invalidIds" open="(" separator="," close=")" item="productId">
  113. #{productId}
  114. </foreach>
  115. </select>
  116. <!-- 供应商 -->
  117. <sql id="Search_Supplier_List">
  118. s.shopID as s_id,
  119. s.name as s_name,
  120. s.logo as s_logo,
  121. s.authorizationCertificateImage as s_license,
  122. s.businessScope as s_business,
  123. s.townID as s_town_id,
  124. CONCAT(p.name, c.name) as s_address,
  125. s.sortIndex as s_sort,
  126. s.status as s_valid
  127. </sql>
  128. <sql id="Supplier_Joins">
  129. left join town as t on s.townId = t.townID
  130. left join city as c on t.cityID = c.cityID
  131. left join province as p on c.provinceID = p.provinceID
  132. </sql>
  133. <select id="findSupplierCount" resultType="java.lang.Integer">
  134. select count(*)
  135. from shop
  136. where (status = 90 or status = 9)
  137. and shopID != 1252
  138. </select>
  139. <select id="findSupplierInvalidCount" resultType="java.lang.Integer">
  140. select count(*)
  141. from shop
  142. where status not in (90,9) or shopID = 1252
  143. </select>
  144. <select id="findSupplierInvalidIds" resultType="java.lang.Integer">
  145. select shopID
  146. from shop
  147. where status not in (90,9) or shopID = 1252
  148. </select>
  149. <select id="searchSupplierList" resultType="com.caimei365.commodity.model.search.SupplierDO">
  150. select <include refid="Search_Supplier_List"/>
  151. from shop as s
  152. <include refid="Supplier_Joins"/>
  153. where (status = 90 or status = 9)
  154. and shopID != 1252
  155. order by s.sortIndex
  156. </select>
  157. <select id="searchSupplierById" resultType="com.caimei365.commodity.model.search.SupplierDO">
  158. select <include refid="Search_Supplier_List"/>
  159. from shop as s
  160. <include refid="Supplier_Joins"/>
  161. where (status = 90 or status = 9)
  162. and shopID != 1252
  163. and s.shopID = #{supplierId}
  164. </select>
  165. <!-- 项目仪器 -->
  166. <sql id="Search_Equipment_List">
  167. e.id as e_id,
  168. e.title as e_name,
  169. e.precisehKey as e_keyword,
  170. e.headImage as e_image,
  171. e.docBoost as e_sort
  172. </sql>
  173. <select id="findEquipmentCount" resultType="java.lang.Integer">
  174. select count(*)
  175. from cm_page
  176. where type = 2 and enabledStatus = 1
  177. </select>
  178. <select id="findEquipmentInvalidCount" resultType="java.lang.Integer">
  179. select count(*)
  180. from cm_page
  181. where type != 2 or enabledStatus != 1
  182. </select>
  183. <select id="findEquipmentInvalidIds" resultType="java.lang.Integer">
  184. select id
  185. from cm_page
  186. where type != 2 or enabledStatus != 1
  187. </select>
  188. <select id="searchEquipmentList" resultType="com.caimei365.commodity.model.search.EquipmentDO">
  189. select <include refid="Search_Equipment_List"/>
  190. from cm_page as e
  191. where e.type = 2 and e.enabledStatus = 1
  192. order by e.docBoost desc
  193. </select>
  194. <select id="searchEquipmentById" resultType="com.caimei365.commodity.model.search.EquipmentDO">
  195. select <include refid="Search_Equipment_List"/>
  196. from cm_page as e
  197. where e.id = #{equipmentId}
  198. and e.type = 2 and e.enabledStatus = 1
  199. </select>
  200. <!-- 文章 -->
  201. <sql id="Search_Article_List">
  202. a.id as a_id,
  203. a.title as a_title,
  204. a.guidanceImage as a_image,
  205. a.publisher as a_publisher,
  206. a.pubdate as a_publish_date,
  207. a.recommendContent as a_intro,
  208. a.infoContent as a_content,
  209. (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) as a_pv,
  210. a.label as a_label,
  211. a.typeId as a_type_id,
  212. b.name as a_type_text,
  213. a.priorityIndex as a_sort
  214. </sql>
  215. <sql id="Article_Joins">
  216. left join info_type b on a.typeId = b.id
  217. left join info_praise c on a.id = c.infoId
  218. </sql>
  219. <select id="findArticleCount" resultType="java.lang.Integer">
  220. select count(*)
  221. from info
  222. where enabledStatus = 1
  223. </select>
  224. <select id="findArticleInvalidCount" resultType="java.lang.Integer">
  225. select count(*)
  226. from info
  227. where enabledStatus != 1
  228. </select>
  229. <select id="findArticleInvalidIds" resultType="java.lang.Integer">
  230. select id
  231. from info
  232. where enabledStatus != 1
  233. </select>
  234. <select id="searchArticleList" resultType="com.caimei365.commodity.model.search.ArticleDO">
  235. select <include refid="Search_Article_List"/>
  236. from info as a
  237. <include refid="Article_Joins"/>
  238. where a.enabledStatus = 1
  239. order by a.priorityIndex desc
  240. </select>
  241. <select id="searchArticleById" resultType="com.caimei365.commodity.model.search.ArticleDO">
  242. select <include refid="Search_Article_List"/>
  243. from info as a
  244. <include refid="Article_Joins"/>
  245. where a.id = #{articleId}
  246. and a.enabledStatus = 1
  247. </select>
  248. <select id="findLabelIdsByName" resultType="java.lang.Integer">
  249. select id
  250. from info_label
  251. where infoLabelStatus = 1
  252. and name in
  253. <foreach collection="labelTexts" item="label" open="(" close=")" index="index" separator=",">
  254. #{label}
  255. </foreach>
  256. group by name
  257. order by clickRate desc
  258. </select>
  259. <!-- 搜索容错 商品列表 -->
  260. <select id="queryProduct" resultType="com.caimei365.commodity.model.vo.ProductListVo">
  261. select
  262. p.productID as productId,
  263. p.`name` as name,
  264. p.mainImage as image,
  265. br.name as brandName,
  266. p.unit as unit,
  267. p.productCode as code,
  268. p.price1TextFlag as priceFlag,
  269. p.price1 as price,
  270. p.shopID as shopId,
  271. p.searchKey as keyword,
  272. p.price8Text as p_act_flag
  273. from product p
  274. left join cm_brand as br on p.brandID = br.id
  275. where p.productCategory = 1
  276. <choose>
  277. <when test="identity == 1">
  278. and p.validFlag in (2,3,9)
  279. </when>
  280. <when test="identity == 2">
  281. and p.validFlag = 2
  282. </when>
  283. <when test="identity == 4">
  284. and p.visibility in (2,3) and p.validFlag = 2
  285. </when>
  286. <otherwise>
  287. and p.visibility = 3 and p.validFlag = 2
  288. </otherwise>
  289. </choose>
  290. <if test="shopId != null and shopId != ''">
  291. and p.shopID = #{shopId}
  292. </if>
  293. <if test="bigTypeId != null and bigTypeId != ''">
  294. and p.bigTypeID = #{bigTypeId}
  295. </if>
  296. <if test="smallTypeId != null and smallTypeId != ''">
  297. and p.smallTypeID = #{smallTypeId}
  298. </if>
  299. <if test="tinyTypeId != null and tinyTypeId != ''">
  300. and p.tinyTypeID = #{tinyTypeId}
  301. </if>
  302. <if test="keyword != null and keyword != ''">
  303. and p.name like concat('%',#{keyword},'%')
  304. </if>
  305. <choose>
  306. <when test="sortField != null and sortField != ''">
  307. <choose>
  308. <when test="sortField == 'price'">
  309. order by p.price1
  310. </when>
  311. <when test="sortField == 'sales'">
  312. order by p.sellNumber
  313. </when>
  314. <when test="sortField == 'favorite'">
  315. order by p.favoriteTimes
  316. </when>
  317. <otherwise>
  318. order by p.productID
  319. </otherwise>
  320. </choose>
  321. </when>
  322. <otherwise>
  323. order by p.productID
  324. </otherwise>
  325. </choose>
  326. <choose>
  327. <when test="sortType == 1">
  328. desc
  329. </when>
  330. <otherwise>
  331. asc
  332. </otherwise>
  333. </choose>
  334. </select>
  335. <select id="searchDbSupplierByKeyword" resultType="com.caimei365.commodity.model.search.SupplierDO">
  336. select
  337. s.shopID as s_id,
  338. s.businessScope as s_business,
  339. s.authorizationCertificateImage as s_license,
  340. s.name as s_name,
  341. s.logo as s_logo,
  342. s.townID as s_town_id,
  343. CONCAT(p.name, c.name) as s_address,
  344. s.sortIndex as s_sort,
  345. s.status as s_valid
  346. from shop as s
  347. left join town as t on s.townId = t.townID
  348. left join city as c on t.cityID = c.cityID
  349. left join province as p on c.provinceID = p.provinceID
  350. where (status = 90 or status = 9)
  351. and shopID != 1252
  352. and s.name like concat('%',#{keyword},'%')
  353. </select>
  354. <select id="searchDbEquipmentByKeyword" resultType="com.caimei365.commodity.model.search.EquipmentDO">
  355. select <include refid="Search_Equipment_List"/>
  356. from cm_page as e
  357. where e.type = 2 and e.enabledStatus = 1
  358. and e.title like concat('%',#{keyword},'%')
  359. order by e.docBoost desc
  360. </select>
  361. <select id="searchDbProduct" resultType="com.caimei365.commodity.model.search.ProductDO">
  362. select <include refid="Search_Product_List"/>, p.productCategory
  363. from product as p
  364. <include refid="Product_Joins"/>
  365. <where>
  366. <choose>
  367. <when test="identity == 1">
  368. p.validFlag in (2,3,9) and p.productCategory = 1
  369. </when>
  370. <when test="identity == 2">
  371. p.validFlag = 2 and p.productCategory = 1
  372. </when>
  373. <when test="identity == 4">
  374. p.visibility in (2,3) and p.validFlag = 2 and p.productCategory = 1
  375. </when>
  376. <otherwise>
  377. p.visibility = 3 and p.validFlag = 2 and p.productCategory = 1
  378. </otherwise>
  379. </choose>
  380. <if test="keyword != null and keyword != ''">
  381. and p.name LIKE concat('%',#{keyword},'%')
  382. </if>
  383. <if test="shopID != null">
  384. and sh.shopID = #{shopID}
  385. </if>
  386. <if test="typeId != null">
  387. <choose>
  388. <when test="idType == 1">
  389. and p.bigTypeId = #{typeId}
  390. </when>
  391. <when test="idType == 2">
  392. and p.smallTypeId = #{typeId}
  393. </when>
  394. <when test="idType == 3">
  395. and p.tinyTypeId = #{typeId}
  396. </when>
  397. </choose>
  398. </if>
  399. </where>
  400. <choose>
  401. <when test="sortField != null and sortField != ''">
  402. <choose>
  403. <when test="sortField == 'p_price'">
  404. order by p.price1
  405. </when>
  406. <when test="sortField == 'p_sales'">
  407. order by p.sellNumber
  408. </when>
  409. <when test="sortField == 'p_favorite'">
  410. order by p.favoriteTimes
  411. </when>
  412. <otherwise>
  413. order by p.productID
  414. </otherwise>
  415. </choose>
  416. </when>
  417. <otherwise>
  418. order by p.productID
  419. </otherwise>
  420. </choose>
  421. <choose>
  422. <when test="sortType == 1">
  423. desc
  424. </when>
  425. <otherwise>
  426. asc
  427. </otherwise>
  428. </choose>
  429. </select>
  430. <select id="searchDbArticle" resultType="com.caimei365.commodity.model.search.DbArticleDO">
  431. select <include refid="Search_Article_List"/>
  432. from info as a
  433. <include refid="Article_Joins"/>
  434. <where>
  435. a.enabledStatus = 1
  436. <if test="articleId != null">
  437. and a.id = #{articleId}
  438. </if>
  439. <if test="keyword != null and keyword != ''">
  440. and a.title like concat ('%',#{keyword},'%')
  441. </if>
  442. <if test="typeId != null">
  443. and a.typeId = #{typeId}
  444. </if>
  445. <if test="labelId != null">
  446. and a.label = #{labelId}
  447. </if>
  448. </where>
  449. <choose>
  450. <when test="typeId != null or labelId != null">
  451. order by a.id desc
  452. </when>
  453. <otherwise>
  454. order by a.priorityIndex desc
  455. </otherwise>
  456. </choose>
  457. </select>
  458. </mapper>