Browse Source

首页独立出秒杀接口

sj
1304317391@qq.com 2 years ago
parent
commit
01c93c3adf
  1. 13
      zsw-bxg/src/main/java/co/yixiang/app/modules/activity/rest/AppStoreSeckillController.java
  2. 17
      zsw-bxg/src/main/java/co/yixiang/app/modules/shop/rest/BxgIndexController.java
  3. 16
      zsw-bxg/src/main/java/co/yixiang/modules/activity/service/YxStoreSeckillService.java
  4. 143
      zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreSeckillServiceImpl.java

13
zsw-bxg/src/main/java/co/yixiang/app/modules/activity/rest/AppStoreSeckillController.java

@ -69,6 +69,19 @@ public class AppStoreSeckillController {
private final YxSystemGroupDataService yxSystemGroupDataService;
private final YxStoreProductRelationService relationService;
/**
* 秒杀产品抢购中
*/
@GetMapping("/seckillIng/list")
@ApiOperation(value = "抢购中秒杀产品列表", notes = "抢购中秒杀产品列表")
public ApiResult<List<YxStoreSeckillQueryVo>> getYxSeckillingList(@RequestParam(value = "page",defaultValue = "1") int page,
@RequestParam(value = "limit",defaultValue = "10") int limit){
return ApiResult.resultPage(yxStoreSeckillService.getSeckillingList(page,limit),limit);
}
/**
* 秒杀产品列表
*/

17
zsw-bxg/src/main/java/co/yixiang/app/modules/shop/rest/BxgIndexController.java

@ -18,6 +18,7 @@ import co.yixiang.enums.ShopCommonEnum;
import co.yixiang.modules.activity.service.YxStoreBargainService;
import co.yixiang.modules.activity.service.YxStoreCombinationService;
import co.yixiang.modules.activity.service.YxStoreSeckillService;
import co.yixiang.modules.activity.vo.SeckillConfigVo;
import co.yixiang.modules.activity.vo.YxStoreSeckillQueryVo;
import co.yixiang.modules.canvas.domain.StoreCanvas;
import co.yixiang.modules.canvas.service.StoreCanvasService;
@ -100,6 +101,21 @@ public class BxgIndexController {
.orderByDesc(StoreCanvas::getCanvasId).last("limit 1"));
return new ResponseEntity<>(canvas, HttpStatus.OK);
}
@GetMapping("/getSeckillList")
@ApiOperation(value = "读取首页秒杀商品")
public ApiResult<List<YxStoreSeckillQueryVo> > getseckillList(){
List<YxStoreSeckillQueryVo> list=storeSeckillService.getList(1, 4); //秒杀商品
return ApiResult.ok(list);
}
@GetMapping("/getSeckillConfig")
@ApiOperation(value = "读取首页秒杀配置")
public ApiResult<SeckillConfigVo> getseckillConfigVo(){
SeckillConfigVo seckillConfigVo=yxStoreSeckillService.getStoreSeckil(); //秒杀商品
return ApiResult.ok(seckillConfigVo);
}
@Cacheable(cacheNames = ShopConstants.ZSW_REDIS_INDEX_KEY)
@GetMapping("/index")
@ApiOperation(value = "首页数据",notes = "首页数据")
@ -118,7 +134,6 @@ public class BxgIndexController {
.hotListDTOS(yxStoreHotListService.getList())//首页榜单
.bargainList(yxStoreBargainService.getList(1,10))//砍价活动列表
.seckillConfigVo(yxStoreSeckillService.getStoreSeckil())//秒杀配置
// .yxStoreSeckillQueryVoList(yxStoreSeckillService.getIndexList())//秒杀商品
.bastList(storeProductService.getList(1,100, ProductEnum.TYPE_1.getValue())) //精品推荐
.evaluationList(evaluationService.getList(1,5))
.benefit(storeProductService.getList(1,100,ProductEnum.TYPE_4.getValue())) //猜你喜欢

16
zsw-bxg/src/main/java/co/yixiang/modules/activity/service/YxStoreSeckillService.java

@ -42,16 +42,26 @@ public interface YxStoreSeckillService extends BaseService<YxStoreSeckill> {
StoreSeckillVo getDetail(Long id);
/**
* 秒杀产品列表
* 秒杀产品列表改为只用于下去预告
*
* @param page page
* @param limit limit
* @param time 时间配置id
* @return list
*/
List<YxStoreSeckillQueryVo> getList(int page, int limit, int time);
List<YxStoreSeckillQueryVo> getIndexList();
// List<YxStoreSeckillQueryVo> getIndexList();
/**
* 抢购中的秒杀产品列表
*
* @param page page
* @param limit limit
* @return list
*/
List<YxStoreSeckillQueryVo> getSeckillingList(int page, int limit);
/**
* 秒杀产品列表(首页用)
*
@ -88,4 +98,6 @@ public interface YxStoreSeckillService extends BaseService<YxStoreSeckill> {
void download(List<YxStoreSeckillDto> all, HttpServletResponse response) throws IOException;
boolean saveSeckill(YxStoreSeckillDto resources);
}

143
zsw-bxg/src/main/java/co/yixiang/modules/activity/service/impl/YxStoreSeckillServiceImpl.java

@ -66,7 +66,6 @@ import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
/**
@ -108,7 +107,6 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
public SeckillConfigVo getStoreSeckil() {
//获取秒杀配置
AtomicInteger seckillTimeIndex = new AtomicInteger();
seckillTimeIndex.set(-1);//初始值改为-1
SeckillConfigVo seckillConfigVo = new SeckillConfigVo();
seckillConfigVo.setIsCanbuy(false);
seckillConfigVo.setSeckillTimeIndex(seckillTimeIndex.get());
@ -118,6 +116,7 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
List<YxSystemGroupData> yxSystemGroupDataList = yxSystemGroupDataService.queryAll(queryCriteria);
List<SeckillTimeDto> list = new ArrayList<>();
AtomicInteger timeId = new AtomicInteger();
List<Integer> timeIds=new ArrayList<>();
int today = OrderUtil.dateToTimestampT(DateUtil.beginOfDay(new Date()));
yxSystemGroupDataList.forEach(i -> {
String jsonStr = i.getValue();
@ -151,15 +150,7 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
seckillTimeDto.setStop(today + activityEndHour * 3600);
// seckillTimeIndex.set(yxSystemGroupDataList.indexOf(i));
timeId.set(i.getId()); //存入抢购中的id,便于排序后进行索引
Long count=yxStoreSeckillService.lambdaQuery()
.eq(YxStoreSeckill::getStatus, ShopCommonEnum.IS_STATUS_1.getValue())
.le(YxStoreSeckill::getStartTime,new Date())
.ge(YxStoreSeckill::getStopTime,new Date())
.eq(YxStoreSeckill::getTimeId,seckillTimeDto.getId())
.count();
if (count>0){
seckillConfigVo.setIsCanbuy(true);
}
timeIds.add(i.getId());
} else if (currentHour < time) {
seckillTimeDto.setState("即将开始");
seckillTimeDto.setTime(jsonObject.get("time").toString().length() > 1 ? jsonObject.get("time").toString() + ":00" : "0" + jsonObject.get("time").toString() + ":00");
@ -176,6 +167,17 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
}
list.add(seckillTimeDto);
});
if (timeIds.size()!=0){ //有抢购中的
Long count=yxStoreSeckillService.lambdaQuery()
.eq(YxStoreSeckill::getStatus, ShopCommonEnum.IS_STATUS_1.getValue())
.le(YxStoreSeckill::getStartTime,new Date())
.ge(YxStoreSeckill::getStopTime,new Date())
.in(YxStoreSeckill::getTimeId,timeIds)
.count();
if (count>0){ //抢购中的商品数量不为0
seckillConfigVo.setIsCanbuy(true);
}
}
list.sort(Comparator.comparing(SeckillTimeDto::getTime));
list.forEach(seckillTimeDto->{
if (seckillTimeDto.getId()==timeId.get()){
@ -233,7 +235,7 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
}
/**
* 秒杀产品列表
* 下期预告秒杀产品列表
* @param page page
* @param limit limit
* @return list
@ -241,10 +243,25 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
@Override
public List<YxStoreSeckillQueryVo> getList(int page, int limit, int time) {
Date nowTime = new Date();
SeckillConfigVo seckillConfigVo=yxStoreSeckillService.getStoreSeckil();
List<Integer> idList=new ArrayList<>();
Integer startTime = null;
for (SeckillTimeDto seckillTimeDto:seckillConfigVo.getSeckillTime()){
if (seckillTimeDto.getId()==time){ //获取即将开始的时间
int today = OrderUtil.dateToTimestampT(DateUtil.beginOfDay(new Date()));
startTime=today + Integer.valueOf(seckillTimeDto.getTime().split(":")[0]) * 3600;
}
}
for (SeckillTimeDto seckillTimeDto:seckillConfigVo.getSeckillTime()){
if (seckillTimeDto.getStatus()==1&&seckillTimeDto.getStop()>startTime){
idList.add(seckillTimeDto.getId());
}
}
Page<YxStoreSeckill> pageModel = new Page<>(page, limit);
LambdaQueryWrapper<YxStoreSeckill> wrapper = new LambdaQueryWrapper<>();
LambdaQueryWrapper<YxStoreSeckill> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(YxStoreSeckill::getStatus, ShopCommonEnum.IS_STATUS_1.getValue())
.eq(YxStoreSeckill::getTimeId,time)
// .eq(YxStoreSeckill::getTimeId,time)
.in(YxStoreSeckill::getTimeId,idList)
.le(YxStoreSeckill::getStartTime,nowTime)
.ge(YxStoreSeckill::getStopTime,nowTime)
.orderByDesc(YxStoreSeckill::getSort);
@ -259,22 +276,69 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
return yxStoreSeckillQueryVos;
}
// @Override
// public List<YxStoreSeckillQueryVo> getIndexList() {
// SeckillConfigVo seckillConfigVo=this.getStoreSeckil();
// if (seckillConfigVo.getSeckillTime().size()==0){
// return null;
// }else{
//// int timeId=seckillConfigVo.getSeckillTime().get(seckillConfigVo.getSeckillTimeIndex()).getId();
// List<Integer> timeIds=new ArrayList<>();
// seckillConfigVo.getSeckillTime().forEach(seckillTimeDto -> {
// if (seckillTimeDto.getStatus()==2){
// timeIds.add(seckillTimeDto.getId());
// }
// });
// return this.getList(1,4,timeIds); //有两个抢购中
//// }
// }
// }
@Override
public List<YxStoreSeckillQueryVo> getIndexList() {
SeckillConfigVo seckillConfigVo=this.getStoreSeckil();
if (seckillConfigVo.getSeckillTime().size()==0){
return null;
}else {
int timeId=seckillConfigVo.getSeckillTime().get(seckillConfigVo.getSeckillTimeIndex()).getId();
return this.getList(1,10,timeId);
public List<YxStoreSeckillQueryVo> getSeckillingList(int page,int limit) {
Page<YxStoreSeckill> pageModel = new Page<>(page, limit);
SeckillConfigVo seckillConfigVo=yxStoreSeckillService.getStoreSeckil();
List<Integer> timeIds=new ArrayList<>();
seckillConfigVo.getSeckillTime().forEach(seckillTimeDto -> {
if (seckillTimeDto.getStatus()==1){
timeIds.add(seckillTimeDto.getId());
}
});
if (timeIds.size()!=0){ //有抢购中的
Long count=yxStoreSeckillService.lambdaQuery()
.eq(YxStoreSeckill::getStatus, ShopCommonEnum.IS_STATUS_1.getValue())
.le(YxStoreSeckill::getStartTime,new Date())
.ge(YxStoreSeckill::getStopTime,new Date())
.in(YxStoreSeckill::getTimeId,timeIds)
.count();
if (count>0){ //抢购中的商品数量不为0
LambdaQueryWrapper<YxStoreSeckill> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(YxStoreSeckill::getStatus, ShopCommonEnum.IS_STATUS_1.getValue())
.le(YxStoreSeckill::getStartTime,new Date())
.ge(YxStoreSeckill::getStopTime,new Date())
.in(YxStoreSeckill::getTimeId,timeIds)
.orderByDesc(YxStoreSeckill::getSort);
List<YxStoreSeckillQueryVo> 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;
}
}
return null;
};
/**
* 秒杀产品列表首页用
* @param page page
* @param limit limit
* @return list
* @return list 当前抢购中有商品就返回抢购中的不然就返回即将开始的
*/
@Override
public List<YxStoreSeckillQueryVo> getList(int page, int limit) {
@ -282,7 +346,6 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
Page<YxStoreSeckill> pageModel = new Page<>(page, limit);
LambdaQueryWrapper<YxStoreSeckill> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(YxStoreSeckill::getStatus, ShopCommonEnum.IS_STATUS_1.getValue())
// .eq(YxStoreSeckill::getIsHot,1)
.le(YxStoreSeckill::getStartTime,nowTime)
.ge(YxStoreSeckill::getStopTime,nowTime)
.orderByDesc(YxStoreSeckill::getSort);
@ -291,21 +354,29 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
return null; //没有秒杀配置,不返回秒杀商品
}else if (seckillConfigVo.getSeckillTime().size()==1){ //只有1条不管是正在进行中还是未开始)
wrapper.eq(YxStoreSeckill::getTimeId,seckillConfigVo.getSeckillTime().get(0).getId());
}else{ //有多条
if (seckillConfigVo.getSeckillTimeIndex() != -1){ //不为-1,有进行中的
List<YxStoreSeckill> list=yxStoreSeckillService.lambdaQuery()
}else{ //有多条进行判断
List<Integer> timeIds=new ArrayList<>(); //进行中的时间配置
List<Integer> willTimeIds=new ArrayList<>(); //即将开始的时间配置
seckillConfigVo.getSeckillTime().forEach(seckillTimeDto -> {
if (seckillTimeDto.getStatus()==1){
timeIds.add(seckillTimeDto.getId());
}
if (seckillTimeDto.getStatus()==2){
willTimeIds.add(seckillTimeDto.getId());
}
});
if (timeIds.size()!=0){ //有抢购中的
Long count=yxStoreSeckillService.lambdaQuery()
.eq(YxStoreSeckill::getStatus, ShopCommonEnum.IS_STATUS_1.getValue())
.le(YxStoreSeckill::getStartTime,nowTime)
.ge(YxStoreSeckill::getStopTime,nowTime)
.eq(YxStoreSeckill::getTimeId,seckillConfigVo.getSeckillTime().get(seckillConfigVo.getSeckillTimeIndex()).getId())
.list();
if (list.size()!=0){ //进行中的不为0
wrapper.eq(YxStoreSeckill::getStatus, ShopCommonEnum.IS_STATUS_1.getValue())
// .eq(YxStoreSeckill::getIsHot,1)
.le(YxStoreSeckill::getStartTime,nowTime)
.ge(YxStoreSeckill::getStopTime,nowTime)
.eq(YxStoreSeckill::getTimeId,seckillConfigVo.getSeckillTime().get(seckillConfigVo.getSeckillTimeIndex()).getId())
.orderByDesc(YxStoreSeckill::getSort);
.in(YxStoreSeckill::getTimeId,timeIds)
.count();
if (count>0){ //抢购中的商品数量不为0
wrapper.in(YxStoreSeckill::getTimeId,timeIds);
}else {
wrapper.in(YxStoreSeckill::getTimeId,willTimeIds);
}
}
}
@ -319,6 +390,8 @@ public class YxStoreSeckillServiceImpl extends BaseServiceImpl<YxStoreSeckillMap
});
return yxStoreSeckillQueryVos;
}
@Override
//@Cacheable
public Map<String, Object> queryAll(YxStoreSeckillQueryCriteria criteria, Pageable pageable) {

Loading…
Cancel
Save