- 在商品搜索接口中添加环保等级、防火等级、试用场景等筛选条件 - 更新相关服务和 mapper 方法,支持新增的筛选条件 - 修改 SQL 查询语句,增加相应的 WHERE条件
199 lines
6.8 KiB
XML
199 lines
6.8 KiB
XML
<?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="org.dromara.mall.mapper.TzProdMapper">
|
|
|
|
<sql id="prodAndShopNameWithNoContent_SQL">
|
|
p.prod_id,
|
|
p.pic,
|
|
p.prod_name,
|
|
p.price,
|
|
p.guiding_price,
|
|
p.brief,
|
|
p.video,
|
|
p.factory_address,
|
|
p.browse_num,
|
|
p.collect_num,
|
|
p.packing_rate,
|
|
p.unit,
|
|
p.is_floor,
|
|
p.label
|
|
</sql>
|
|
|
|
<select id="pageByCategoryId" resultType="org.dromara.mall.domain.vo.TzProdVo">
|
|
select tp.*,tc.category_name from tz_prod tp
|
|
left join tz_category tc on tp.category_id = tc.category_id
|
|
where tp.status = 1
|
|
<if test="categoryId != null">
|
|
AND tp.category_id = #{categoryId}
|
|
</if>
|
|
</select>
|
|
|
|
<select id="pageByPutAwayTime" resultType="org.dromara.mall.domain.vo.TzProdVo">
|
|
SELECT
|
|
<include refid="prodAndShopNameWithNoContent_SQL"/>
|
|
FROM tz_prod as p
|
|
WHERE p.`status` = 1
|
|
ORDER BY putaway_time DESC
|
|
</select>
|
|
|
|
|
|
<select id="randomProdPage" resultType="org.dromara.mall.domain.vo.TzProdVo">
|
|
SELECT
|
|
<include refid="prodAndShopNameWithNoContent_SQL"/>
|
|
FROM tz_prod as p
|
|
WHERE p.`status` = 1
|
|
ORDER BY RAND()
|
|
</select>
|
|
|
|
|
|
<select id="hotProdPage" resultType="org.dromara.mall.domain.vo.TzProdVo">
|
|
SELECT
|
|
<include refid="prodAndShopNameWithNoContent_SQL"/>
|
|
FROM tz_prod as p
|
|
WHERE p.`status` = 1
|
|
ORDER BY collect_num DESC,browse_num DESC
|
|
</select>
|
|
|
|
|
|
<select id="getSearchProdPageByProdName" resultType="org.dromara.mall.domain.vo.TzProdVo">
|
|
select
|
|
p.*
|
|
from
|
|
tz_prod p
|
|
where
|
|
p.`status` = 1
|
|
<if test="categoryId != 0">
|
|
and p.category_id = #{categoryId}
|
|
</if>
|
|
<if test="floor == 1">
|
|
and p.is_floor = 1
|
|
</if>
|
|
<if test="prodName != null and prodName != ''">
|
|
and p.prod_name like concat('%',#{prodName} ,'%')
|
|
or
|
|
p.prod_code like concat('%',#{prodName} ,'%')
|
|
</if>
|
|
<if test="envLevel != null and envLevel != ''">
|
|
and FIND_IN_SET(p.env_level, #{envLevel}) > 0
|
|
</if>
|
|
<if test="fireLevel != null and fireLevel != ''">
|
|
and FIND_IN_SET(p.fire_level, #{fireLevel}) > 0
|
|
</if>
|
|
<if test="trialScenario != null and trialScenario != ''">
|
|
and FIND_IN_SET(p.trial_scenario, #{trialScenario}) > 0
|
|
</if>
|
|
|
|
<if test="sort == 0">
|
|
ORDER BY RAND()
|
|
</if>
|
|
<if test="sort == 1">
|
|
ORDER BY p.price
|
|
</if>
|
|
<if test="sort == 2">
|
|
ORDER BY p.browse_num desc
|
|
</if>
|
|
<if test="sort == 3">
|
|
ORDER BY p.update_time desc
|
|
</if>
|
|
<if test="orderBy == 0">
|
|
asc
|
|
</if>
|
|
<if test="orderBy == 1">
|
|
desc
|
|
</if>
|
|
</select>
|
|
|
|
<select id="monthPerProd" resultType="org.dromara.mall.domain.vo.PerSumVo">
|
|
SELECT
|
|
`type`,
|
|
max( `count` ) AS `num`
|
|
FROM
|
|
(
|
|
SELECT
|
|
count(1) AS `count`,
|
|
DATE_FORMAT( create_time, '%Y-%m-%d' ) AS `type`
|
|
FROM
|
|
`tz_prod` a
|
|
WHERE
|
|
DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT(#{month}, '%Y%m' )
|
|
AND `status` in (0,1)
|
|
GROUP BY
|
|
`type` UNION ALL
|
|
SELECT
|
|
0 AS `copunt`,
|
|
@cdate := date_add( @cdate, INTERVAL - 1 DAY ) `type`
|
|
FROM
|
|
( SELECT @cdate := date_add( last_day(#{month}), INTERVAL + 1 DAY ) FROM `tz_prod` ) t1
|
|
WHERE
|
|
@cdate > (
|
|
date_add(#{month}, INTERVAL - DAY (#{month})+ 1 DAY ))
|
|
) _tmpAllTable
|
|
GROUP BY `type`
|
|
ORDER BY `type`
|
|
</select>
|
|
|
|
|
|
<select id="yearPerProd" resultType="org.dromara.mall.domain.vo.PerSumVo">
|
|
WITH RECURSIVE DateSeries AS (
|
|
SELECT STR_TO_DATE(CONCAT(YEAR(#{year}), '-', '01', '-', '01'), '%Y-%m-%d') AS click_date
|
|
UNION ALL
|
|
SELECT DATE_ADD(click_date, INTERVAL 1 MONTH)
|
|
FROM DateSeries
|
|
WHERE click_date < DATE_ADD(STR_TO_DATE(CONCAT(YEAR(#{year}), '-', '01', '-', '01'), '%Y-%m-%d'), INTERVAL 11 MONTH)
|
|
)
|
|
SELECT
|
|
CONCAT(YEAR(ds.click_date), '-', LPAD(MONTH(ds.click_date), 2, '0')) AS `type`,
|
|
IFNULL(b.`sum`, 0) AS `sum`
|
|
FROM
|
|
DateSeries ds
|
|
LEFT JOIN (
|
|
SELECT
|
|
COUNT(1) AS `sum`,
|
|
CONCAT(YEAR(create_time), '-', LPAD(MONTH(create_time), 2, '0')) AS mon
|
|
FROM
|
|
`tz_prod`
|
|
WHERE
|
|
`status` = 1
|
|
AND create_time BETWEEN STR_TO_DATE(CONCAT(YEAR(#{year}), '-', '01', '-', '01'), '%Y-%m-%d')
|
|
AND DATE_ADD(STR_TO_DATE(CONCAT(YEAR(#{year}), '-', '01', '-', '01'), '%Y-%m-%d'), INTERVAL 11 MONTH)
|
|
GROUP BY
|
|
mon
|
|
) b ON CONCAT(YEAR(ds.click_date), '-', LPAD(MONTH(ds.click_date), 2, '0')) = b.mon
|
|
ORDER BY
|
|
ds.click_date;
|
|
</select>
|
|
|
|
|
|
<select id="prodSalesVolumeCount" resultType="org.dromara.mall.domain.vo.RankSumVo">
|
|
SELECT o.prod_id as prodId,o.prod_code as prodCode,o.prod_name as prodName,count(1) as count FROM hy_order_item as o
|
|
WHERE o.create_time BETWEEN #{startDay} and #{endDay} AND o.del_flag = 1 AND o.pay_state != 1
|
|
<if test="tenantId != null and tenantId != '000000'">
|
|
AND o.tenant_id = #{tenantId}
|
|
</if>
|
|
GROUP BY o.prod_id
|
|
ORDER BY count DESC
|
|
</select>
|
|
|
|
<select id="prodSalesVolumeSum" resultType="org.dromara.mall.domain.vo.RankSumVo">
|
|
SELECT o.prod_id as prodId,o.prod_code as prodCode,o.prod_name as prodName,sum(o.total) as sum FROM hy_order_item as o
|
|
WHERE o.create_time BETWEEN #{startDay} and #{endDay} AND o.del_flag = 1 AND o.pay_state != 1
|
|
<if test="tenantId != null and tenantId != '000000'">
|
|
AND o.tenant_id = #{tenantId}
|
|
</if>
|
|
GROUP BY o.prod_id
|
|
ORDER BY sum DESC
|
|
</select>
|
|
|
|
<select id="prodSalesVolumeSumByZh" resultType="org.dromara.mall.domain.vo.RankSumVo">
|
|
SELECT o.prod_id as prodId,o.prod_code as prodCode,o.prod_name as prodName,sum(o.actual_total) as sum FROM hy_order_item as o
|
|
WHERE o.create_time BETWEEN #{startDay} and #{endDay} AND o.del_flag = 1 AND o.pay_state != 1
|
|
<if test="tenantId != null and tenantId != '000000'">
|
|
AND o.tenant_id = #{tenantId}
|
|
</if>
|
|
GROUP BY o.prod_id
|
|
ORDER BY sum DESC
|
|
</select>
|
|
</mapper>
|