|
|
|
@ -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) { |
|
|
|
|