From e66081a8be1a819d6f414914f8cf57c2ee0a2a08 Mon Sep 17 00:00:00 2001 From: xuwenbo <717567226@qq.com> Date: Tue, 1 Sep 2020 17:47:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A6=96=E9=A1=B5=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/shop/rest/IndexController.java | 45 +++++++--------- .../co/yixiang/modules/shop/vo/IndexVo.java | 53 +++++++++++++++++++ .../service/YxStoreSeckillService.java | 7 +++ .../impl/YxStoreSeckillServiceImpl.java | 27 +++++++++- 4 files changed, 106 insertions(+), 26 deletions(-) create mode 100644 yshop-app/src/main/java/co/yixiang/modules/shop/vo/IndexVo.java diff --git a/yshop-app/src/main/java/co/yixiang/modules/shop/rest/IndexController.java b/yshop-app/src/main/java/co/yixiang/modules/shop/rest/IndexController.java index 86775ea6..91f841f0 100644 --- a/yshop-app/src/main/java/co/yixiang/modules/shop/rest/IndexController.java +++ b/yshop-app/src/main/java/co/yixiang/modules/shop/rest/IndexController.java @@ -14,11 +14,15 @@ import co.yixiang.api.ApiResult; import co.yixiang.api.YshopException; import co.yixiang.constant.ShopConstants; import co.yixiang.enums.ProductEnum; +import co.yixiang.modules.activity.service.YxStoreCombinationService; +import co.yixiang.modules.activity.service.YxStoreSeckillService; +import co.yixiang.modules.activity.vo.YxStoreSeckillQueryVo; import co.yixiang.modules.product.service.YxStoreProductService; import co.yixiang.modules.product.vo.YxSystemStoreQueryVo; import co.yixiang.modules.shop.param.YxSystemStoreQueryParam; import co.yixiang.modules.shop.service.YxSystemGroupDataService; import co.yixiang.modules.shop.service.YxSystemStoreService; +import co.yixiang.modules.shop.vo.IndexVo; import co.yixiang.utils.FileUtil; import co.yixiang.utils.RedisUtil; import co.yixiang.utils.ShopKeyUtils; @@ -54,35 +58,26 @@ public class IndexController { private final YxSystemGroupDataService systemGroupDataService; private final YxStoreProductService storeProductService; private final YxSystemStoreService systemStoreService; - + private final YxStoreCombinationService storeCombinationService; + private final YxStoreSeckillService storeSeckillService; @Cacheable(cacheNames = ShopConstants.YSHOP_REDIS_INDEX_KEY) @GetMapping("/index") @ApiOperation(value = "首页数据",notes = "首页数据") - public ApiResult> index(){ - - Map map = new LinkedHashMap<>(); - //banner - map.put("banner",systemGroupDataService.getDatas(ShopConstants.YSHOP_HOME_BANNER)); - //首页按钮 - map.put("menus",systemGroupDataService.getDatas(ShopConstants.YSHOP_HOME_MENUS)); - - - //精品推荐 - map.put("bastList",storeProductService.getList(1,6, ProductEnum.TYPE_1.getValue())); - //首发新品 - map.put("firstList",storeProductService.getList(1,6,ProductEnum.TYPE_3.getValue())); - //猜你喜欢 - map.put("benefit",storeProductService.getList(1,10,ProductEnum.TYPE_4.getValue())); - //热门榜单 - map.put("likeInfo",storeProductService.getList(1,3,ProductEnum.TYPE_2.getValue())); - - //滚动 - map.put("roll",systemGroupDataService.getDatas(ShopConstants.YSHOP_HOME_ROLL_NEWS)); - - map.put("mapKey",RedisUtil.get(ShopKeyUtils.getTengXunMapKey())); - - return ApiResult.ok(map); + public ApiResult index(){ + IndexVo indexVo = IndexVo.builder() + .banner(systemGroupDataService.getDatas(ShopConstants.YSHOP_HOME_BANNER)) + .bastList(storeProductService.getList(1,6, ProductEnum.TYPE_1.getValue())) + .benefit(storeProductService.getList(1,10,ProductEnum.TYPE_4.getValue())) + .combinationList(storeCombinationService.getList(1,4)) + .firstList(storeProductService.getList(1,6,ProductEnum.TYPE_3.getValue())) + .likeInfo(storeProductService.getList(1,3,ProductEnum.TYPE_2.getValue())) + .mapKey(RedisUtil.get(ShopKeyUtils.getTengXunMapKey())) + .menus(systemGroupDataService.getDatas(ShopConstants.YSHOP_HOME_MENUS)) + .roll(systemGroupDataService.getDatas(ShopConstants.YSHOP_HOME_ROLL_NEWS)) + .seckillList(storeSeckillService.getList(1, 4)) + .build(); + return ApiResult.ok(indexVo); } @GetMapping("/search/keyword") diff --git a/yshop-app/src/main/java/co/yixiang/modules/shop/vo/IndexVo.java b/yshop-app/src/main/java/co/yixiang/modules/shop/vo/IndexVo.java new file mode 100644 index 00000000..1597eaaf --- /dev/null +++ b/yshop-app/src/main/java/co/yixiang/modules/shop/vo/IndexVo.java @@ -0,0 +1,53 @@ +package co.yixiang.modules.shop.vo; + +import co.yixiang.modules.activity.vo.YxStoreCombinationQueryVo; +import co.yixiang.modules.activity.vo.YxStoreSeckillQueryVo; +import co.yixiang.modules.product.vo.YxStoreProductQueryVo; +import com.alibaba.fastjson.JSONObject; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +@ApiModel("首页数据") +public class IndexVo { + + @ApiModelProperty("banner") + private List banner; + //首页按钮 + @ApiModelProperty("首页按钮") + private List menus; + //精品推荐->拼团 + @ApiModelProperty("精品推荐") + private List bastList; + //首发新品->秒杀 + @ApiModelProperty("首发新品") + private List firstList; + //猜你喜欢 + @ApiModelProperty("猜你喜欢") + private List benefit; + //热门榜单 + @ApiModelProperty("热门榜单") + private List likeInfo; + //滚动 + @ApiModelProperty("滚动") + private List roll; + //地图key + @ApiModelProperty("地图key") + private String mapKey; + //精品推荐->拼团 + @ApiModelProperty("精品推荐->拼团") + private List combinationList; + //首发新品->秒杀 + @ApiModelProperty("首发新品->秒杀") + private List seckillList; + +} diff --git a/yshop-mall/src/main/java/co/yixiang/modules/activity/service/YxStoreSeckillService.java b/yshop-mall/src/main/java/co/yixiang/modules/activity/service/YxStoreSeckillService.java index 5bbc570a..46ea792f 100644 --- a/yshop-mall/src/main/java/co/yixiang/modules/activity/service/YxStoreSeckillService.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/activity/service/YxStoreSeckillService.java @@ -58,6 +58,13 @@ public interface YxStoreSeckillService extends BaseService{ */ List getList(int page, int limit, int time); + /** + * 秒杀产品列表(首页用) + * @param page page + * @param limit limit + * @return list + */ + List getList(int page, int limit); /** * 查询数据分页 diff --git a/yshop-mall/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreSeckillServiceImpl.java b/yshop-mall/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreSeckillServiceImpl.java index 7a4be7ae..a95e562c 100644 --- a/yshop-mall/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreSeckillServiceImpl.java +++ b/yshop-mall/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreSeckillServiceImpl.java @@ -182,7 +182,32 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl getList(int page, int limit) { + Date nowTime = new Date(); + Page pageModel = new Page<>(page, limit); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.lambda().eq(YxStoreSeckill::getStatus, ShopCommonEnum.IS_STATUS_1.getValue()) + .eq(YxStoreSeckill::getIsHot,1) + .le(YxStoreSeckill::getStartTime,nowTime) + .ge(YxStoreSeckill::getStopTime,nowTime) + .orderByDesc(YxStoreSeckill::getSort); + List yxStoreSeckillQueryVos = generator.convert + (yxStoreSeckillMapper.selectPage(pageModel,wrapper).getRecords(), + YxStoreSeckillQueryVo.class); + yxStoreSeckillQueryVos.forEach(item->{ + Integer sum = item.getSales() + item.getStock(); + item.setPercent(NumberUtil.round(NumberUtil.mul(NumberUtil.div(item.getSales(),sum), + 100),0).intValue()); + }); + return yxStoreSeckillQueryVos; + } @Override //@Cacheable public Map queryAll(YxStoreSeckillQueryCriteria criteria, Pageable pageable) {