123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623 |
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
- <mapper namespace="com.caimei365.commodity.mapper.SearchMapper">
- <sql id="Search_Product_List">
- p.productID as p_id,
- p.`name` as p_name,
- p.searchKey as p_keyword,
- p.tags as p_tags,
- p.mainImage as p_image,
- p.priceFlag as p_price_flag,
- p.productCode as p_code,
- br.id as p_brand_id,
- br.name as p_brand_name,
- p.shopID as p_supplier_id,
- sh.name as p_supplier_name,
- p.bigTypeID as p_category1_id,
- b.name as p_category1_name,
- p.smallTypeID as p_category2_id,
- s.name as p_category2_name,
- p.tinyTypeID as p_category3_id,
- t.name as p_category3_name,
- p.preferredFlag as p_preferred,
- p.productCategory as p_type,
- copi.validFlag as p_valid,
- br.weights as p_sort,
- DATE_FORMAT(p.ADDTIME,'%Y%m%d') as p_time,
- IFNULL(p.visibility,3) as p_visibility,
- ifnull(p.newvalidflag,0) as p_newvalidflag,
- p.productType as p_product_type,
- p.relatedLabels as p_labels,
- (select unit from cm_sku where productID=
- #{productId}
- order
- by
- price
- asc
- LIMIT
- 1
- )
- as
- p_unit,
- (
- select
- price
- from
- cm_sku
- where
- productID
- =
- #{productId}
- order
- by
- price
- asc
- LIMIT
- 1
- )
- as
- p_price
- </sql>
- <sql id="Product_Joins">
- left join tinytype as t on p.tinyTypeID = t.tinyTypeID
- left join smalltype as s on p.smallTypeID = s.smallTypeID
- left join bigtype as b on p.bigTypeID = b.bigTypeID
- left join cm_brand as br on p.brandID = br.id
- left join shop as sh on p.shopID = sh.shopID
- </sql>
- <select id="searchProductById" resultType="com.caimei365.commodity.model.search.ProductDO">
- select
- <include refid="Search_Product_List"/>
- from product p
- <include refid="Product_Joins"/>
- left join cm_organize_product_info copi on copi.productId = p.productID and copi.organizeId = 0
- where copi.validFlag in (2,3,9) and p.productCategory = 1
- and p.productID = #{productId}
- </select>
- <select id="findProductCount" resultType="java.lang.Integer">
- select count(*)
- from product p
- left join cm_organize_product_info copi on p.productID = copi.productId
- where validFlag in (2, 3, 9)
- and productCategory = 1
- </select>
- <select id="findProductInvalidCount" resultType="java.lang.Integer">
- select count(*)
- from product p
- left join cm_organize_product_info copi on p.productID = copi.productId
- where validFlag in (2, 3, 9)
- or productCategory != 1
- </select>
- <select id="findProductInvalidIds" resultType="java.lang.Integer">
- select p.productID
- from product p
- left join cm_organize_product_info copi on p.productID = copi.productId
- where validFlag in (2, 3, 9)
- or productCategory != 1
- </select>
- <select id="searchProductList" resultType="com.caimei365.commodity.model.search.ProductDO">
- select
- <include refid="Search_Product_List"/>
- from product p
- <include refid="Product_Joins"/>
- left join cm_organize_product_info copi on copi.productId = p.productID and copi.organizeId = 0
- where copi.validFlag in (2,3,9) and productCategory = 1
- order by productID desc
- </select>
- <!-- 供应商 -->
- <sql id="Search_Supplier_List">
- s.shopID as s_id,
- s.name as s_name,
- s.logo as s_logo,
- s.authorizationCertificateImage as s_license,
- s.businessScope as s_business,
- s.townID as s_town_id,
- CONCAT(p.name, c.name) as s_address,
- s.status as s_valid
- </sql>
- <sql id="Supplier_Joins">
- left join town as t on s.townId = t.townID
- left join city as c on t.cityID = c.cityID
- left join province as p on c.provinceID = p.provinceID
- </sql>
- <select id="findSupplierCount" resultType="java.lang.Integer">
- select count(*)
- from shop
- where shopType = 1
- and (status = 90 or status = 9)
- and shopID != 1252
- </select>
- <select id="findSupplierInvalidCount" resultType="java.lang.Integer">
- select count(*)
- from shop
- where shopType = 1
- and (status not in (90, 9)
- or shopID = 1252)
- </select>
- <select id="findSupplierInvalidIds" resultType="java.lang.Integer">
- select shopID
- from shop
- where shopType = 1
- and (status not in (90, 9)
- or shopID = 1252)
- </select>
- <select id="searchSupplierList" resultType="com.caimei365.commodity.model.search.SupplierDO">
- select
- <include refid="Search_Supplier_List"/>
- from shop as s
- <include refid="Supplier_Joins"/>
- where shopType = 1
- and (status = 90 or status = 9)
- and shopID != 1252
- </select>
- <select id="searchSupplierById" resultType="com.caimei365.commodity.model.search.SupplierDO">
- select
- <include refid="Search_Supplier_List"/>
- from shop as s
- <include refid="Supplier_Joins"/>
- where shopType = 1
- and (status = 90 or status = 9)
- and shopID != 1252
- and s.shopID = #{shopId}
- </select>
- <!-- 项目仪器 -->
- <sql id="Search_Equipment_List">
- e.id as e_id,
- e.title as e_name,
- e.precisehKey as e_keyword,
- e.headImage as e_image,
- e.docBoost as e_sort
- </sql>
- <select id="findEquipmentCount" resultType="java.lang.Integer">
- select count(*)
- from cm_page
- where type = 2
- and enabledStatus = 1
- </select>
- <select id="findEquipmentInvalidCount" resultType="java.lang.Integer">
- select count(*)
- from cm_page
- where type != 2
- or enabledStatus != 1
- </select>
- <select id="findEquipmentInvalidIds" resultType="java.lang.Integer">
- select id
- from cm_page
- where type != 2
- or enabledStatus != 1
- </select>
- <select id="searchEquipmentList" resultType="com.caimei365.commodity.model.search.EquipmentDO">
- select
- <include refid="Search_Equipment_List"/>
- from cm_page as e
- where e.type = 2 and e.enabledStatus = 1
- order by e.docBoost desc
- </select>
- <select id="searchEquipmentById" resultType="com.caimei365.commodity.model.search.EquipmentDO">
- select
- <include refid="Search_Equipment_List"/>
- from cm_page as e
- where e.id = #{equipmentId}
- and e.type = 2 and e.enabledStatus = 1
- </select>
- <!-- 文章 -->
- <sql id="Search_Article_List">
- a.id as a_id,
- a.title as a_title,
- a.guidanceImage as a_image,
- a.publisher as a_publisher,
- a.pubdate as a_publish_date,
- a.recommendContent as a_intro,
- a.infoContent as a_content,
- (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) as a_pv,
- a.label as a_label,
- a.typeId as a_type_id,
- b.name as a_type_text,
- a.priorityIndex as a_sort,
- a.relatedLabels as a_labels
- </sql>
- <sql id="Article_Joins">
- left join info_type b on a.typeId = b.id
- left join info_praise c on a.id = c.infoId
- </sql>
- <select id="findArticleCount" resultType="java.lang.Integer">
- select count(*)
- from info
- where enabledStatus = 1
- and auditStatus = 2
- and onlineStatus = 2
- </select>
- <select id="findArticleInvalidCount" resultType="java.lang.Integer">
- select count(*)
- from info
- where enabledStatus != 1
- or auditStatus != 2
- or onlineStatus != 2
- </select>
- <select id="findArticleInvalidIds" resultType="java.lang.Integer">
- select id
- from info
- where enabledStatus != 1
- or auditStatus != 2
- or onlineStatus != 2
- </select>
- <select id="searchArticleList" resultType="com.caimei365.commodity.model.search.ArticleDO">
- select
- <include refid="Search_Article_List"/>
- from info as a
- <include refid="Article_Joins"/>
- where a.enabledStatus = 1 and a.auditStatus = 2 and a.onlineStatus = 2
- order by a.id desc
- </select>
- <select id="searchArticleById" resultType="com.caimei365.commodity.model.search.ArticleDO">
- select
- <include refid="Search_Article_List"/>
- from info as a
- <include refid="Article_Joins"/>
- where a.id = #{articleId}
- and a.enabledStatus = 1
- and a.auditStatus = 2
- and a.onlineStatus = 2
- </select>
- <select id="findLabelIdsByName" resultType="java.lang.Integer">
- select id
- from info_label
- where infoLabelStatus = 1
- and name in
- <foreach collection="labelTexts" item="label" open="(" close=")" index="index" separator=",">
- #{label}
- </foreach>
- group by name
- order by clickRate desc
- </select>
- <select id="findLabelNameById" resultType="java.lang.String">
- select name
- from info_label
- where infoLabelStatus = 1
- and id = #{labelId}
- limit 1
- </select>
- <!-- 搜索容错 商品列表 -->
- <select id="queryProduct" resultType="com.caimei365.commodity.model.search.ProductListVo">
- select
- p.productID as productId,
- p.actStatus,
- p.`name` as name,
- p.mainImage as image,
- br.name as brandName,
- (select unit from cm_sku where productID=p.productID order by price asc limit 1) as unit,
- p.productCode as code,
- p.priceFlag,
- (select price from cm_sku where productID=p.productID order by price asc limit 1)as price,
- p.shopID as shopId,
- p.productType,
- p.searchKey as keyword
- from product p
- left join cm_brand as br on p.brandID = br.id
- left join cm_organize_product_info copi on copi.productId = p.productID and copi.organizeId = 0
- where p.productCategory = 1 and p.newvalidFlag=1
- <choose>
- <when test="identity == 1">
- and copi.validFlag in (2,3,9)
- </when>
- <when test="identity == 5">
- and copi.validFlag = 2
- </when>
- <when test="identity == 2">
- and p.visibility in (1,2,3) and copi.validFlag = 2
- </when>
- <when test="identity == 4">
- and p.visibility in (2,3) and copi.validFlag = 2
- </when>
- <when test="identity == 5">
- and p.visibility in (1,2,3,4) and copi.validFlag = 2
- </when>
- <otherwise>
- and p.visibility = 3 and copi.validFlag = 2
- </otherwise>
- </choose>
- <if test="shopId != null and shopId != ''">
- and p.shopID = #{shopId}
- </if>
- <if test="bigTypeId != null and bigTypeId != ''">
- and p.bigTypeID = #{bigTypeId}
- </if>
- <if test="smallTypeId != null and smallTypeId != ''">
- and p.smallTypeID = #{smallTypeId}
- </if>
- <if test="tinyTypeId != null and tinyTypeId != ''">
- and p.tinyTypeID = #{tinyTypeId}
- </if>
- <if test="keyword != null and keyword != ''">
- and p.name like concat('%',#{keyword},'%')
- </if>
- <choose>
- <when test="sortField != null and sortField != ''">
- <choose>
- <when test="sortField == 'price'">
- order by price
- </when>
- <when test="sortField == 'sales'">
- order by p.sellNumber
- </when>
- <when test="sortField == 'favorite'">
- order by p.favoriteTimes
- </when>
- <otherwise>
- order by p.productID
- </otherwise>
- </choose>
- </when>
- <otherwise>
- order by p.productID
- </otherwise>
- </choose>
- <choose>
- <when test="sortType == 1">
- desc
- </when>
- <otherwise>
- asc
- </otherwise>
- </choose>
- </select>
- <!-- 搜索容错 供应商列表 -->
- <select id="querySupplier" resultType="com.caimei365.commodity.model.search.ShopListVo">
- select s.shopID as shopId,
- s.name as name,
- s.logo as logo,
- s.authorizationCertificateImage as license,
- s.businessScope as business,
- CONCAT(p.name, c.name) as address
- from shop as s
- left join town as t on s.townId = t.townID
- left join city as c on t.cityID = c.cityID
- left join province as p on c.provinceID = p.provinceID
- where (status = 90 or status = 9)
- and shopID != 1252
- and s.name like concat('%', #{keyword}, '%')
- </select>
- <!-- 搜索容错 项目仪器列表 -->
- <select id="queryEquipment" resultType="com.caimei365.commodity.model.search.EquipmentListVo">
- select e.id as id,
- e.title as name,
- e.precisehKey as keyword,
- e.headImage as image
- from cm_page as e
- where e.type = 2
- and e.enabledStatus = 1
- and e.title like concat('%', #{keyword}, '%')
- order by e.docBoost desc
- </select>
- <!-- 搜索容错 文章列表 -->
- <select id="queryArticle" resultType="com.caimei365.commodity.model.search.ArticleListVo">
- select
- a.id as articleId,
- a.title as title,
- a.guidanceImage as image,
- a.publisher as publisher,
- a.pubdate as publishDate,
- a.recommendContent as intro,
- (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) as pv,
- a.typeId as typeId,
- b.name as typeText,
- a.label as labelText
- from info as a
- left join info_type b on a.typeId = b.id
- left join info_praise c on a.id = c.infoId
- <where>
- a.enabledStatus = 1
- and a.auditStatus = 2
- and a.onlineStatus = 2
- and a.delFlag = 0
- <if test="articleId != null">
- and a.id = #{articleId}
- </if>
- <if test="typeId != null">
- and a.typeId = #{typeId}
- </if>
- <if test="keyword != null and keyword != ''">
- and a.title like concat ('%',#{keyword},'%')
- </if>
- <if test="labelText != null">
- and a.label like concat ('%',#{labelText},'%')
- </if>
- </where>
- <choose>
- <when test="typeId != null or labelText != null">
- order by a.id desc
- </when>
- <otherwise>
- order by a.priorityIndex desc
- </otherwise>
- </choose>
- </select>
- <!-- 搜索容错 文章列表 v1.2.8新加根据时间排序-->
- <select id="queryArticleByProDate" resultType="com.caimei365.commodity.model.search.ArticleListVo">
- select
- a.id as articleId,
- a.title as title,
- a.guidanceImage as image,
- a.publisher as publisher,
- a.pubdate as publishDate,
- a.recommendContent as intro,
- (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) as pv,
- a.typeId as typeId,
- b.name as typeText,
- a.label as labelText
- from info as a
- left join info_type b on a.typeId = b.id
- left join info_praise c on a.id = c.infoId
- <where>
- a.enabledStatus = 1
- and a.auditStatus = 2
- <if test="articleId != null">
- and a.id = #{articleId}
- </if>
- <if test="typeId != null">
- and a.typeId = #{typeId}
- </if>
- <if test="keyword != null and keyword != ''">
- and a.title like concat ('%',#{keyword},'%')
- </if>
- <if test="labelText != null">
- and a.label like concat ('%',#{labelText},'%')
- </if>
- </where>
- <if test="sortType != null">
- <if test="sortType == 1">
- order by a.pubdate desc
- </if>
- <if test="sortType != 1">
- order by (IFNULL(c.pv, 0) +IFNULL(c.num, 0) + IFNULL(a.basePv, 0) + IFNULL(a.basePraise, 0)) desc
- </if>
- </if>
- </select>
- <select id="getHistoryList" resultType="com.caimei365.commodity.model.po.SearchHistoryPo">
- select id, userId, searchWord, searchDate, delFlag
- from user_search_history
- where userId = #{userId}
- order by searchDate desc
- </select>
- <select id="getHistoryIdByWord" resultType="java.lang.Integer">
- select id
- from user_search_history
- where searchWord = #{keyword}
- and userId = #{userId}
- limit 1
- </select>
- <select id="getHistoryCount" resultType="java.lang.Integer">
- select COUNT(*)
- from user_search_history
- where userId = #{userId}
- AND delFlag = 0
- </select>
- <update id="updateSearchHistoryById">
- update user_search_history
- <set>
- <if test="userId != null">
- userId = #{userId},
- </if>
- <if test="searchWord != null">
- searchWord = #{searchWord},
- </if>
- <if test="searchDate != null">
- searchDate = #{searchDate},
- </if>
- <if test="delFlag != null">
- delFlag = #{delFlag},
- </if>
- </set>
- where id = #{id}
- </update>
- <insert id="insertSearchHistory">
- INSERT INTO user_search_history
- <trim prefix="(" suffix=")" suffixOverrides=",">
- <if test="userId != null">
- userId,
- </if>
- <if test="searchWord != null">
- searchWord,
- </if>
- <if test="searchDate != null">
- searchDate,
- </if>
- <if test="delFlag != null">
- delFlag,
- </if>
- </trim>
- <trim prefix="values (" suffix=")" suffixOverrides=",">
- <if test="userId != null">
- #{userId},
- </if>
- <if test="searchWord != null">
- #{searchWord},
- </if>
- <if test="searchDate != null">
- #{searchDate},
- </if>
- <if test="delFlag != null">
- #{delFlag},
- </if>
- </trim>
- </insert>
- <delete id="deleteSearchHistory">
- DELETE
- FROM user_search_history
- WHERE userId = #{userId}
- AND id NOT IN (SELECT temp.id
- FROM (SELECT id
- FROM user_search_history
- WHERE userId = #{userId}
- ORDER BY searchDate DESC
- LIMIT 10) AS temp)
- </delete>
- <delete id="deleteAllSearchHistory">
- DELETE
- FROM user_search_history
- WHERE userId = #{userId}
- </delete>
- <select id="findNew" resultType="java.lang.Integer">
- select productID from product
- where TIMESTAMP(ADDTIME) <![CDATA[ > ]]> TIMESTAMP(#{n})
- <if test="productIds != null">
- and productID in
- <foreach collection="productIds" item="productId" index="index" open="(" separator="," close=")">
- #{productId}
- </foreach>
- </if>
- </select>
- <select id="findPromotion" resultType="java.lang.Integer">
- select cpp.productID from cm_promotions_product cpp
- left join cm_promotions cp on cpp.promotionsId = cp.id
- where cpp.productId in
- <foreach collection="productIds" item="productId" index="index" open="(" separator="," close=")">
- #{productId}
- </foreach>
- and cp.endTime>now() or (cp.status='1')
- and cp.delflag = 0
- </select>
- <select id="findPromotionId" resultType="java.lang.Integer">
- select pr.id
- from cm_promotions pr
- left join cm_promotions_product prp on pr.id = prp.promotionsId
- where (prp.productId = #{p_id} or
- prp.supplierId = (select p.shopID from product p where p.productID = #{p_id})
- )
- and (pr.status = 1 or (pr.status = 2 and (NOW() between pr.beginTime and pr.endTime)))
- and pr.delFlag not in (1, 2)
- order by pr.type desc
- limit 1
- </select>
- <select id="countViewsByDate" resultType="java.lang.Integer">
- select IFNULL(sum(views), 0)
- from cm_product_views_record
- where productId = #{productId}
- and viewTime > #{date}
- </select>
- <select id="countSalesByDate" resultType="java.lang.Integer">
- select IFNULL(sum(sales), 0)
- from cm_product_sales_record
- where productId = #{productId}
- and saleTime > #{date}
- </select>
- <select id="findPromotions" resultType="java.lang.Integer">
- SELECT DISTINCT cpp.productId
- FROM cm_promotions cp
- LEFT JOIN cm_promotions_product cpp ON cp.id = cpp.promotionsId
- WHERE (cp.status = 1 OR (cp.status = 2 AND cp.endTime > NOW()))
- AND cp.delFlag = 0
- </select>
- <select id="findServiceProductIds" resultType="java.lang.String">
- SELECT GROUP_CONCAT(cpp.productId SEPARATOR '|') AS ps
- FROM cm_provider_product cpp
- LEFT JOIN serviceprovider sp ON cpp.providerId = sp.serviceProviderID
- WHERE sp.serviceProviderId = #{serviceProviderId}
- </select>
- </mapper>
|