SearchMapper.xml 19 KB

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