feat(foundations):增加查询首页热门服务和服务列表的功能

This commit is contained in:
JIAN
2024-08-25 16:40:14 +08:00
parent 1e9a265ecc
commit 0d694db8b8
5 changed files with 194 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
package com.jzo2o.foundations.controller.consumer;
import com.jzo2o.foundations.model.dto.response.ServeAggregationSimpleResDTO;
import com.jzo2o.foundations.model.dto.response.ServeAggregationTypeSimpleResDTO;
import com.jzo2o.foundations.model.dto.response.ServeCategoryResDTO;
import com.jzo2o.foundations.service.IServeService;
import com.jzo2o.foundations.service.IServeTypeService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
* 用户端 - 服务相关接口
* @author JIAN
*/
@RestController("consumerServeController")
@RequestMapping("/customer/serve")
@Api(tags = "用户端 - 服务相关接口")
public class ServeController {
/**
* 获取首页服务类型及服务项
*/
@GetMapping("/firstPageServeList")
public List<ServeCategoryResDTO> getFirstPageServeList(@RequestParam Long regionId) {
return serveService.getFirstPageServeList(regionId);
}
/**
* 获取全部服务类型
*/
@GetMapping("/serveTypeList")
public List<ServeAggregationTypeSimpleResDTO> getServeTypeList(@RequestParam Long regionId) {
return serveTypeService.getServeTypeList(regionId);
}
/**
* 获取热门服务项
*/
@GetMapping("/hotServeList")
public List<ServeAggregationSimpleResDTO> getHotServeList(@RequestParam Long regionId) {
return serveService.getHotServeList(regionId);
}
@Resource
private IServeService serveService;
@Resource
private IServeTypeService serveTypeService;
}

View File

@@ -2,6 +2,8 @@ package com.jzo2o.foundations.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.dto.response.ServeAggregationSimpleResDTO;
import com.jzo2o.foundations.model.dto.response.ServeCategoryResDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import org.apache.ibatis.annotations.Param;
@@ -20,4 +22,16 @@ public interface ServeMapper extends BaseMapper<Serve> {
* @param regionId 区域id
*/
List<ServeResDTO> queryServeListByRegionId(@Param("regionId") Long regionId);
/**
* 区域服务图标查询
* @param regionId 区域id
*/
List<ServeCategoryResDTO> queryServeIconListByRegionId(@Param("regionId") Long regionId);
/**
* 区域热门服务查询
* @param regionId 区域id
*/
List<ServeAggregationSimpleResDTO> queryHotServeListByRegionId(Long regionId);
}

View File

@@ -5,6 +5,8 @@ import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeAggregationSimpleResDTO;
import com.jzo2o.foundations.model.dto.response.ServeCategoryResDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import java.math.BigDecimal;
@@ -56,4 +58,16 @@ public interface IServeService extends IService<Serve> {
* 取消指定服务热门
*/
Serve updateOffHot(Long id);
/**
* 获取首页服务类型及服务项
* @param regionId 地区id
*/
List<ServeCategoryResDTO> getFirstPageServeList(Long regionId);
/**
* 获取首页热门服务
* @param regionId 地区id
*/
List<ServeAggregationSimpleResDTO> getHotServeList(Long regionId);
}

View File

@@ -5,24 +5,34 @@ import com.jzo2o.common.expcetions.CommonException;
import com.jzo2o.common.expcetions.ForbiddenOperationException;
import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.utils.BeanUtils;
import com.jzo2o.common.utils.CollUtils;
import com.jzo2o.common.utils.ObjectUtils;
import com.jzo2o.foundations.constants.RedisConstants;
import com.jzo2o.foundations.enums.FoundationStatusEnum;
import com.jzo2o.foundations.enums.HotStatusEnum;
import com.jzo2o.foundations.mapper.RegionMapper;
import com.jzo2o.foundations.mapper.ServeItemMapper;
import com.jzo2o.foundations.mapper.ServeMapper;
import com.jzo2o.foundations.model.domain.Region;
import com.jzo2o.foundations.model.domain.Serve;
import com.jzo2o.foundations.model.domain.ServeItem;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeAggregationSimpleResDTO;
import com.jzo2o.foundations.model.dto.response.ServeCategoryResDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.model.dto.response.ServeSimpleResDTO;
import com.jzo2o.foundations.service.IServeService;
import com.jzo2o.mysql.utils.PageHelperUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
@@ -203,6 +213,57 @@ public class ServeServiceImpl extends ServiceImpl<ServeMapper, Serve> implements
return serve;
}
@Override
@Caching(cacheable = {
@Cacheable(value = RedisConstants.CacheName.SERVE_ICON, key = "#regionId",
cacheManager = RedisConstants.CacheManager.THIRTY_MINUTES,
unless = "#result.size() != 0"), // 防止缓存穿透
@Cacheable(value = RedisConstants.CacheName.SERVE_ICON, key = "#regionId",
cacheManager = RedisConstants.CacheManager.FOREVER,
unless = "#result.size() == 0")})
public List<ServeCategoryResDTO> getFirstPageServeList(Long regionId) {
Region region = regionMapper.selectById(regionId);
if (ObjectUtils.isEmpty(region)) {
return Collections.emptyList();
}
List<ServeCategoryResDTO> serveIconList = baseMapper.queryServeIconListByRegionId(regionId);
if (CollUtils.isEmpty(serveIconList)) {
return Collections.emptyList();
}
// 保留最多前两个类型及最多前4个服务项
serveIconList = new ArrayList<>(serveIconList.subList(0, Math.min(serveIconList.size(), 2)));
serveIconList.forEach(res -> {
List<ServeSimpleResDTO> serveResDTOList = res.getServeResDTOList();
res.setServeResDTOList(new ArrayList<>(serveResDTOList.subList(0, Math.min(serveResDTOList.size(), 4))));
});
return serveIconList;
}
@Override
@Caching(cacheable = {
@Cacheable(value = RedisConstants.CacheName.HOT_SERVE, key = "#regionId",
cacheManager = RedisConstants.CacheManager.THIRTY_MINUTES,
unless = "#result.size() != 0"), // 防止缓存穿透
@Cacheable(value = RedisConstants.CacheName.HOT_SERVE, key = "#regionId",
cacheManager = RedisConstants.CacheManager.FOREVER,
unless = "#result.size() == 0")})
public List<ServeAggregationSimpleResDTO> getHotServeList(Long regionId) {
Region region = regionMapper.selectById(regionId);
if (ObjectUtils.isEmpty(region)) {
return Collections.emptyList();
}
List<ServeAggregationSimpleResDTO> hotServeList = baseMapper.queryHotServeListByRegionId(regionId);
if (CollUtils.isEmpty(hotServeList)) {
return Collections.emptyList();
}
return hotServeList;
}
@Resource
private ServeItemMapper serveItemMapper;

View File

@@ -19,4 +19,56 @@
JOIN serve_type st ON si.serve_type_id = st.id
WHERE s.region_id = #{regionId}
</select>
<resultMap id="ServeCategoryResMap" type="com.jzo2o.foundations.model.dto.response.ServeCategoryResDTO">
<id column="serve_type_id" property="serveTypeId"/>
<result column="type_name" property="serveTypeName"/>
<result column="serve_type_icon" property="serveTypeIcon"/>
<result column="city_code" property="cityCode"/>
<result column="type_sort_num" property="serveTypeSortNum"/>
<collection property="serveResDTOList" ofType="com.jzo2o.foundations.model.dto.response.ServeSimpleResDTO">
<id column="serve_id" property="id"/>
<result column="serve_item_id" property="serveItemId"/>
<result column="item_name" property="serveItemName"/>
<result column="serve_item_icon" property="serveItemIcon"/>
<result column="item_sort_num" property="serveItemSortNum"/>
</collection>
</resultMap>
<select id="queryServeIconListByRegionId" resultMap="ServeCategoryResMap">
SELECT serve_type_id,
type.name type_name,
serve_type_icon,
city_code,
type.sort_num type_sort_num,
serve_item_id,
item.name item_name,
serve_item_icon,
item.sort_num item_sort_num,
serve.id serve_id
FROM serve
JOIN serve_item item ON serve.serve_item_id = item.id
JOIN serve_type type ON item.serve_type_id = type.id
WHERE serve.region_id = #{regionId}
AND serve.sale_status = 2 # 保证上架服务
ORDER BY type.sort_num, item.sort_num
</select>
<select id="queryHotServeListByRegionId"
resultType="com.jzo2o.foundations.model.dto.response.ServeAggregationSimpleResDTO">
SELECT serve.id,
serve_item_id,
name serve_item_name,
img serve_item_img,
unit,
price,
detail_img,
city_code
FROM serve
JOIN serve_item item ON serve.serve_item_id = item.id
WHERE serve.region_id = #{regionId}
AND serve.sale_status = 2 # 保证上架服务
AND serve.is_hot = 1 # 保证热门状态
ORDER BY item.sort_num
</select>
</mapper>