SearchMapper.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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. <select id="findLabelNameById" resultType="java.lang.String">
  260. select name
  261. from info_label
  262. where infoLabelStatus = 1
  263. and id = #{labelId}
  264. limit 1
  265. </select>
  266. <!-- 搜索容错 商品列表 -->
  267. <select id="queryProduct" resultType="com.caimei365.commodity.model.search.ProductListVo">
  268. select
  269. p.productID as productId,
  270. p.`name` as name,
  271. p.mainImage as image,
  272. br.name as brandName,
  273. p.unit as unit,
  274. p.productCode as code,
  275. p.price1TextFlag as priceFlag,
  276. p.price1 as price,
  277. p.shopID as shopId,
  278. p.searchKey as keyword,
  279. p.price8Text as actFlag
  280. from product p
  281. left join cm_brand as br on p.brandID = br.id
  282. where p.productCategory = 1
  283. <choose>
  284. <when test="identity == 1">
  285. and p.validFlag in (2,3,9)
  286. </when>
  287. <when test="identity == 2">
  288. and p.validFlag = 2
  289. </when>
  290. <when test="identity == 4">
  291. and p.visibility in (2,3) and p.validFlag = 2
  292. </when>
  293. <otherwise>
  294. and p.visibility = 3 and p.validFlag = 2
  295. </otherwise>
  296. </choose>
  297. <if test="shopId != null and shopId != ''">
  298. and p.shopID = #{shopId}
  299. </if>
  300. <if test="bigTypeId != null and bigTypeId != ''">
  301. and p.bigTypeID = #{bigTypeId}
  302. </if>
  303. <if test="smallTypeId != null and smallTypeId != ''">
  304. and p.smallTypeID = #{smallTypeId}
  305. </if>
  306. <if test="tinyTypeId != null and tinyTypeId != ''">
  307. and p.tinyTypeID = #{tinyTypeId}
  308. </if>
  309. <if test="classifyId != null and classifyId != ''">
  310. and p.classifyId = #{classifyId}
  311. </if>
  312. <if test="keyword != null and keyword != ''">
  313. and p.name like concat('%',#{keyword},'%')
  314. </if>
  315. <choose>
  316. <when test="sortField != null and sortField != ''">
  317. <choose>
  318. <when test="sortField == 'price'">
  319. order by p.price1
  320. </when>
  321. <when test="sortField == 'sales'">
  322. order by p.sellNumber
  323. </when>
  324. <when test="sortField == 'favorite'">
  325. order by p.favoriteTimes
  326. </when>
  327. <otherwise>
  328. order by p.productID
  329. </otherwise>
  330. </choose>
  331. </when>
  332. <otherwise>
  333. order by p.productID
  334. </otherwise>
  335. </choose>
  336. <choose>
  337. <when test="sortType == 1">
  338. desc
  339. </when>
  340. <otherwise>
  341. asc
  342. </otherwise>
  343. </choose>
  344. </select>
  345. <!-- 搜索容错 供应商列表 -->
  346. <select id="querySupplier" resultType="com.caimei365.commodity.model.search.ShopListVo">
  347. select
  348. s.shopID as shopId,
  349. s.name as name,
  350. s.logo as logo,
  351. s.authorizationCertificateImage as license,
  352. s.businessScope as business,
  353. CONCAT(p.name, c.name) as address
  354. from shop as s
  355. left join town as t on s.townId = t.townID
  356. left join city as c on t.cityID = c.cityID
  357. left join province as p on c.provinceID = p.provinceID
  358. where (status = 90 or status = 9)
  359. and shopID != 1252
  360. and s.name like concat('%',#{keyword},'%')
  361. </select>
  362. <!-- 搜索容错 项目仪器列表 -->
  363. <select id="queryEquipment" resultType="com.caimei365.commodity.model.search.EquipmentListVo">
  364. select
  365. e.id as id,
  366. e.title as name,
  367. e.precisehKey as keyword,
  368. e.headImage as image
  369. from cm_page as e
  370. where e.type = 2 and e.enabledStatus = 1
  371. and e.title like concat('%',#{keyword},'%')
  372. order by e.docBoost desc
  373. </select>
  374. <!-- 搜索容错 文章列表 -->
  375. <select id="queryArticle" resultType="com.caimei365.commodity.model.search.ArticleListVo">
  376. select
  377. a.id as articleId,
  378. a.title as title,
  379. a.guidanceImage as image,
  380. a.publisher as publisher,
  381. a.pubdate as publishDate,
  382. a.recommendContent as intro,
  383. (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) as pv,
  384. a.typeId as typeId,
  385. b.name as typeText,
  386. a.label as labelText,
  387. from info as a
  388. left join info_type b on a.typeId = b.id
  389. left join info_praise c on a.id = c.infoId
  390. <where>
  391. a.enabledStatus = 1
  392. <if test="articleId != null">
  393. and a.id = #{articleId}
  394. </if>
  395. <if test="typeId != null">
  396. and a.typeId = #{typeId}
  397. </if>
  398. <if test="keyword != null and keyword != ''">
  399. and a.title like concat ('%',#{keyword},'%')
  400. </if>
  401. <if test="labelText != null">
  402. and a.label like concat ('%',#{labelText},'%')
  403. </if>
  404. </where>
  405. <choose>
  406. <when test="typeId != null or labelText != null">
  407. order by a.id desc
  408. </when>
  409. <otherwise>
  410. order by a.priorityIndex desc
  411. </otherwise>
  412. </choose>
  413. </select>
  414. </mapper>