SearchMapper.xml 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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.price as p_price,
  11. p.priceFlag 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. br.id 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.preferredFlag as p_preferred,
  28. p.productCategory as p_type,
  29. p.validFlag as p_valid,
  30. DATE_FORMAT(p.ADDTIME,'%Y%m%d') as p_time,
  31. IFNULL(p.visibility,3) as p_visibility
  32. </sql>
  33. <sql id="Product_Joins">
  34. left join tinytype as t on p.tinyTypeID = t.tinyTypeID
  35. left join smalltype as s on p.smallTypeID = s.smallTypeID
  36. left join bigtype as b on p.bigTypeID = b.bigTypeID
  37. left join cm_brand as br on p.brandID = br.id
  38. left join shop as sh on p.shopID = sh.shopID
  39. </sql>
  40. <select id="searchProductById" resultType="com.caimei365.commodity.model.search.ProductDO">
  41. select<include refid="Search_Product_List"/>, p.productCategory
  42. from product p
  43. <include refid="Product_Joins"/>
  44. where p.validFlag in (2,3,9) and p.productCategory = 1
  45. and p.productID = #{productId}
  46. </select>
  47. <select id="findProductCount" resultType="java.lang.Integer">
  48. select count(*)
  49. from product
  50. where validFlag in (2, 3, 9)
  51. and productCategory = 1
  52. </select>
  53. <select id="findProductInvalidCount" resultType="java.lang.Integer">
  54. select count(*)
  55. from product
  56. where validFlag not in (2, 3, 9)
  57. or productCategory != 1
  58. </select>
  59. <select id="findProductInvalidIds" resultType="java.lang.Integer">
  60. select productID
  61. from product
  62. where validFlag not in (2, 3, 9)
  63. or productCategory != 1
  64. </select>
  65. <select id="searchProductList" resultType="com.caimei365.commodity.model.search.ProductDO">
  66. select
  67. <include refid="Search_Product_List"/>
  68. from product p
  69. <include refid="Product_Joins"/>
  70. where p.validFlag in (2,3,9) and productCategory = 1
  71. order by productID desc
  72. </select>
  73. <select id="countMallProduct" resultType="java.lang.Integer">
  74. select COUNT(*)
  75. from cm_mall_organize_products
  76. where productID = #{productId}
  77. and organizeID = 1
  78. </select>
  79. <select id="searchMallProductByProductId" resultType="com.caimei365.commodity.model.search.MallProductDO">
  80. select m.id as m_id,
  81. m.organizeID as m_organize_id,
  82. m.productID as m_product_id,
  83. m.retailPrice as m_price,
  84. m.classifyID as m_classify_id,
  85. m.delFlag as m_valid,
  86. c.classifyName as m_classify_name
  87. from cm_mall_organize_products as m
  88. left join cm_mall_products_classify as c on m.classifyId = c.id
  89. where m.productID = #{productId}
  90. and m.organizeID = 1
  91. limit 1
  92. </select>
  93. <select id="getMallLadderPriceFlag" resultType="java.lang.Integer">
  94. select ladderPriceFlag
  95. from cm_mall_organize_products
  96. where productID = #{productId}
  97. and organizeID = 1
  98. limit 1
  99. </select>
  100. <select id="getMallLowerLadderPrice" resultType="java.lang.Double">
  101. select MIN(buyPrice)
  102. from cm_mall_product_ladder_price
  103. where delFlag = '0'
  104. and productId = #{productId}
  105. </select>
  106. <select id="findMallIdByProductId" resultType="java.lang.Integer">
  107. select id
  108. from cm_mall_organize_products
  109. where productID = #{productId}
  110. limit 1
  111. </select>
  112. <select id="findMallInvalidIdsByProductIds" resultType="java.lang.Integer">
  113. select id
  114. from cm_mall_organize_products
  115. where productID IN
  116. <foreach collection="invalidIds" open="(" separator="," close=")" item="productId">
  117. #{productId}
  118. </foreach>
  119. </select>
  120. <!-- 供应商 -->
  121. <sql id="Search_Supplier_List">
  122. s.shopID as s_id,
  123. s.name as s_name,
  124. s.logo as s_logo,
  125. s.authorizationCertificateImage as s_license,
  126. s.businessScope as s_business,
  127. s.townID as s_town_id,
  128. CONCAT(p.name, c.name) as s_address,
  129. s.sortIndex as s_sort,
  130. s.status as s_valid
  131. </sql>
  132. <sql id="Supplier_Joins">
  133. left join town as t on s.townId = t.townID
  134. left join city as c on t.cityID = c.cityID
  135. left join province as p on c.provinceID = p.provinceID
  136. </sql>
  137. <select id="findSupplierCount" resultType="java.lang.Integer">
  138. select count(*)
  139. from shop
  140. where (status = 90 or status = 9)
  141. and shopID != 1252
  142. </select>
  143. <select id="findSupplierInvalidCount" resultType="java.lang.Integer">
  144. select count(*)
  145. from shop
  146. where status not in (90, 9)
  147. or shopID = 1252
  148. </select>
  149. <select id="findSupplierInvalidIds" resultType="java.lang.Integer">
  150. select shopID
  151. from shop
  152. where status not in (90, 9)
  153. or shopID = 1252
  154. </select>
  155. <select id="searchSupplierList" resultType="com.caimei365.commodity.model.search.SupplierDO">
  156. select
  157. <include refid="Search_Supplier_List"/>
  158. from shop as s
  159. <include refid="Supplier_Joins"/>
  160. where (status = 90 or status = 9)
  161. and shopID != 1252
  162. </select>
  163. <select id="searchSupplierById" resultType="com.caimei365.commodity.model.search.SupplierDO">
  164. select
  165. <include refid="Search_Supplier_List"/>
  166. from shop as s
  167. <include refid="Supplier_Joins"/>
  168. where (status = 90 or status = 9)
  169. and shopID != 1252
  170. and s.shopID = #{shopId}
  171. </select>
  172. <!-- 项目仪器 -->
  173. <sql id="Search_Equipment_List">
  174. e.id as e_id,
  175. e.title as e_name,
  176. e.precisehKey as e_keyword,
  177. e.headImage as e_image,
  178. e.docBoost as e_sort
  179. </sql>
  180. <select id="findEquipmentCount" resultType="java.lang.Integer">
  181. select count(*)
  182. from cm_page
  183. where type = 2
  184. and enabledStatus = 1
  185. </select>
  186. <select id="findEquipmentInvalidCount" resultType="java.lang.Integer">
  187. select count(*)
  188. from cm_page
  189. where type != 2
  190. or enabledStatus != 1
  191. </select>
  192. <select id="findEquipmentInvalidIds" resultType="java.lang.Integer">
  193. select id
  194. from cm_page
  195. where type != 2
  196. or enabledStatus != 1
  197. </select>
  198. <select id="searchEquipmentList" resultType="com.caimei365.commodity.model.search.EquipmentDO">
  199. select
  200. <include refid="Search_Equipment_List"/>
  201. from cm_page as e
  202. where e.type = 2 and e.enabledStatus = 1
  203. order by e.docBoost desc
  204. </select>
  205. <select id="searchEquipmentById" resultType="com.caimei365.commodity.model.search.EquipmentDO">
  206. select
  207. <include refid="Search_Equipment_List"/>
  208. from cm_page as e
  209. where e.id = #{equipmentId}
  210. and e.type = 2 and e.enabledStatus = 1
  211. </select>
  212. <!-- 文章 -->
  213. <sql id="Search_Article_List">
  214. a.id as a_id,
  215. a.title as a_title,
  216. a.guidanceImage as a_image,
  217. a.publisher as a_publisher,
  218. a.pubdate as a_publish_date,
  219. a.recommendContent as a_intro,
  220. a.infoContent as a_content,
  221. (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) as a_pv,
  222. a.label as a_label,
  223. a.typeId as a_type_id,
  224. b.name as a_type_text,
  225. a.priorityIndex as a_sort
  226. </sql>
  227. <sql id="Article_Joins">
  228. left join info_type b on a.typeId = b.id
  229. left join info_praise c on a.id = c.infoId
  230. </sql>
  231. <select id="findArticleCount" resultType="java.lang.Integer">
  232. select count(*)
  233. from info
  234. where enabledStatus = 1
  235. </select>
  236. <select id="findArticleInvalidCount" resultType="java.lang.Integer">
  237. select count(*)
  238. from info
  239. where enabledStatus != 1
  240. </select>
  241. <select id="findArticleInvalidIds" resultType="java.lang.Integer">
  242. select id
  243. from info
  244. where enabledStatus != 1
  245. </select>
  246. <select id="searchArticleList" resultType="com.caimei365.commodity.model.search.ArticleDO">
  247. select
  248. <include refid="Search_Article_List"/>
  249. from info as a
  250. <include refid="Article_Joins"/>
  251. where a.enabledStatus = 1
  252. order by a.priorityIndex desc
  253. </select>
  254. <select id="searchArticleById" resultType="com.caimei365.commodity.model.search.ArticleDO">
  255. select
  256. <include refid="Search_Article_List"/>
  257. from info as a
  258. <include refid="Article_Joins"/>
  259. where a.id = #{articleId}
  260. and a.enabledStatus = 1
  261. </select>
  262. <select id="findLabelIdsByName" resultType="java.lang.Integer">
  263. select id
  264. from info_label
  265. where infoLabelStatus = 1
  266. and name in
  267. <foreach collection="labelTexts" item="label" open="(" close=")" index="index" separator=",">
  268. #{label}
  269. </foreach>
  270. group by name
  271. order by clickRate desc
  272. </select>
  273. <select id="findLabelNameById" resultType="java.lang.String">
  274. select name
  275. from info_label
  276. where infoLabelStatus = 1
  277. and id = #{labelId}
  278. limit 1
  279. </select>
  280. <!-- 搜索容错 商品列表 -->
  281. <select id="queryProduct" resultType="com.caimei365.commodity.model.search.ProductListVo">
  282. select
  283. p.productID as productId,
  284. p.actStatus,
  285. p.`name` as name,
  286. p.mainImage as image,
  287. br.name as brandName,
  288. p.unit as unit,
  289. p.productCode as code,
  290. p.priceFlag,
  291. p.price,
  292. p.shopID as shopId,
  293. p.searchKey as keyword
  294. from product p
  295. left join cm_brand as br on p.brandID = br.id
  296. where p.productCategory = 1
  297. <choose>
  298. <when test="identity == 1">
  299. and p.validFlag in (2,3,9)
  300. </when>
  301. <when test="identity == 2">
  302. and p.validFlag = 2
  303. </when>
  304. <when test="identity == 4">
  305. and p.visibility in (2,3) and p.validFlag = 2
  306. </when>
  307. <otherwise>
  308. and p.visibility = 3 and p.validFlag = 2
  309. </otherwise>
  310. </choose>
  311. <if test="shopId != null and shopId != ''">
  312. and p.shopID = #{shopId}
  313. </if>
  314. <if test="bigTypeId != null and bigTypeId != ''">
  315. and p.bigTypeID = #{bigTypeId}
  316. </if>
  317. <if test="smallTypeId != null and smallTypeId != ''">
  318. and p.smallTypeID = #{smallTypeId}
  319. </if>
  320. <if test="tinyTypeId != null and tinyTypeId != ''">
  321. and p.tinyTypeID = #{tinyTypeId}
  322. </if>
  323. <if test="keyword != null and keyword != ''">
  324. and p.name like concat('%',#{keyword},'%')
  325. </if>
  326. <choose>
  327. <when test="sortField != null and sortField != ''">
  328. <choose>
  329. <when test="sortField == 'price'">
  330. order by p.price
  331. </when>
  332. <when test="sortField == 'sales'">
  333. order by p.sellNumber
  334. </when>
  335. <when test="sortField == 'favorite'">
  336. order by p.favoriteTimes
  337. </when>
  338. <otherwise>
  339. order by p.productID
  340. </otherwise>
  341. </choose>
  342. </when>
  343. <otherwise>
  344. order by p.productID
  345. </otherwise>
  346. </choose>
  347. <choose>
  348. <when test="sortType == 1">
  349. desc
  350. </when>
  351. <otherwise>
  352. asc
  353. </otherwise>
  354. </choose>
  355. </select>
  356. <!-- 搜索容错 供应商列表 -->
  357. <select id="querySupplier" resultType="com.caimei365.commodity.model.search.ShopListVo">
  358. select s.shopID as shopId,
  359. s.name as name,
  360. s.logo as logo,
  361. s.authorizationCertificateImage as license,
  362. s.businessScope as business,
  363. CONCAT(p.name, c.name) as address
  364. from shop as s
  365. left join town as t on s.townId = t.townID
  366. left join city as c on t.cityID = c.cityID
  367. left join province as p on c.provinceID = p.provinceID
  368. where (status = 90 or status = 9)
  369. and shopID != 1252
  370. and s.name like concat('%', #{keyword}, '%')
  371. </select>
  372. <!-- 搜索容错 项目仪器列表 -->
  373. <select id="queryEquipment" resultType="com.caimei365.commodity.model.search.EquipmentListVo">
  374. select e.id as id,
  375. e.title as name,
  376. e.precisehKey as keyword,
  377. e.headImage as image
  378. from cm_page as e
  379. where e.type = 2
  380. and e.enabledStatus = 1
  381. and e.title like concat('%', #{keyword}, '%')
  382. order by e.docBoost desc
  383. </select>
  384. <!-- 搜索容错 文章列表 -->
  385. <select id="queryArticle" resultType="com.caimei365.commodity.model.search.ArticleListVo">
  386. select
  387. a.id as articleId,
  388. a.title as title,
  389. a.guidanceImage as image,
  390. a.publisher as publisher,
  391. a.pubdate as publishDate,
  392. a.recommendContent as intro,
  393. (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) as pv,
  394. a.typeId as typeId,
  395. b.name as typeText,
  396. a.label as labelText
  397. from info as a
  398. left join info_type b on a.typeId = b.id
  399. left join info_praise c on a.id = c.infoId
  400. <where>
  401. a.enabledStatus = 1
  402. <if test="articleId != null">
  403. and a.id = #{articleId}
  404. </if>
  405. <if test="typeId != null">
  406. and a.typeId = #{typeId}
  407. </if>
  408. <if test="keyword != null and keyword != ''">
  409. and a.title like concat ('%',#{keyword},'%')
  410. </if>
  411. <if test="labelText != null">
  412. and a.label like concat ('%',#{labelText},'%')
  413. </if>
  414. </where>
  415. <choose>
  416. <when test="typeId != null or labelText != null">
  417. order by a.id desc
  418. </when>
  419. <otherwise>
  420. order by a.priorityIndex desc
  421. </otherwise>
  422. </choose>
  423. </select>
  424. <select id="getHistoryList" resultType="com.caimei365.commodity.model.po.SearchHistoryPo">
  425. select id, userId, searchWord, searchDate, delFlag
  426. from user_search_history
  427. where userId = #{userId}
  428. order by searchDate desc
  429. </select>
  430. <select id="getHistoryIdByWord" resultType="java.lang.Integer">
  431. select id
  432. from user_search_history
  433. where searchWord = #{keyword}
  434. limit 1
  435. </select>
  436. <select id="getHistoryCount" resultType="java.lang.Integer">
  437. select COUNT(*)
  438. from user_search_history
  439. where userId = #{userId}
  440. AND delFlag = 0
  441. </select>
  442. <update id="updateSearchHistoryById">
  443. update user_search_history
  444. <set>
  445. <if test="userId != null">
  446. userId = #{userId},
  447. </if>
  448. <if test="searchWord != null">
  449. searchWord = #{searchWord},
  450. </if>
  451. <if test="searchDate != null">
  452. searchDate = #{searchDate},
  453. </if>
  454. <if test="delFlag != null">
  455. delFlag = #{delFlag},
  456. </if>
  457. </set>
  458. where id = #{id}
  459. </update>
  460. <insert id="insertSearchHistory">
  461. INSERT INTO user_search_history
  462. <trim prefix="(" suffix=")" suffixOverrides=",">
  463. <if test="userId != null">
  464. userId,
  465. </if>
  466. <if test="searchWord != null">
  467. searchWord,
  468. </if>
  469. <if test="searchDate != null">
  470. searchDate,
  471. </if>
  472. <if test="delFlag != null">
  473. delFlag,
  474. </if>
  475. </trim>
  476. <trim prefix="values (" suffix=")" suffixOverrides=",">
  477. <if test="userId != null">
  478. #{userId},
  479. </if>
  480. <if test="searchWord != null">
  481. #{searchWord},
  482. </if>
  483. <if test="searchDate != null">
  484. #{searchDate},
  485. </if>
  486. <if test="delFlag != null">
  487. #{delFlag},
  488. </if>
  489. </trim>
  490. </insert>
  491. <delete id="deleteSearchHistory">
  492. DELETE
  493. FROM user_search_history
  494. WHERE userId = #{userId}
  495. AND id NOT IN (
  496. SELECT temp.id
  497. FROM (SELECT id FROM user_search_history WHERE userId = #{userId} ORDER BY searchDate DESC LIMIT 10) AS temp
  498. )
  499. </delete>
  500. <delete id="deleteAllSearchHistory">
  501. DELETE
  502. FROM user_search_history
  503. WHERE userId = #{userId}
  504. </delete>
  505. <select id="findNew" resultType="java.lang.Integer">
  506. select productID from product
  507. where TIMESTAMP(ADDTIME) <![CDATA[ > ]]> TIMESTAMP(#{n})
  508. <if test="productIds != null">
  509. and productID in
  510. <foreach collection="productIds" item="productId" index="index" open="(" separator="," close=")">
  511. #{productId}
  512. </foreach>
  513. </if>
  514. </select>
  515. <select id="findPromotion" resultType="java.lang.Integer">
  516. select cpp.productID from cm_promotions_product cpp
  517. left join cm_promotions cp on cpp.promotionsId = cp.id
  518. where cpp.productId in
  519. <foreach collection="productIds" item="productId" index="index" open="(" separator="," close=")">
  520. #{productId}
  521. </foreach>
  522. and cp.endTime>now() or (cp.status='1')
  523. and cp.delflag = 0
  524. </select>
  525. <select id="findPromotionId" resultType="java.lang.Integer">
  526. select pr.id
  527. from cm_promotions pr
  528. left join cm_promotions_product prp on pr.id = prp.promotionsId
  529. where (prp.productId = #{p_id} or
  530. prp.supplierId = (select p.shopID from product p where p.productID = #{p_id})
  531. )
  532. and (pr.status = 1 or (pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
  533. and pr.delFlag not in (1, 2)
  534. order by pr.type desc
  535. limit 1
  536. </select>
  537. </mapper>