Merge branch 'master' of gitee.com:beijing_hongye_huicheng/lilishop

This commit is contained in:
Chopper 2021-07-06 14:53:34 +08:00
commit a903160305
5 changed files with 100 additions and 42 deletions

View File

@ -177,7 +177,7 @@ public enum CachePrefix {
/**
* 店铺管理员角色权限对照表
*/
SHOP_URL_ROLE,
STORE_URL_ROLE,
/**
* 手机验证标识
@ -449,7 +449,12 @@ public enum CachePrefix {
/**
* 文章
*/
ARTICLE_CACHE
ARTICLE_CACHE,
/**
* 店铺分类
*/
STORE_CATEGORY
;

View File

@ -1,12 +1,12 @@
package cn.lili.modules.promotion.serviceimpl;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import cn.lili.common.enums.ResultCode;
import cn.lili.common.trigger.message.PromotionMessage;
import cn.lili.common.exception.ServiceException;
import cn.lili.common.utils.DateUtil;
import cn.lili.modules.order.cart.entity.vo.FullDiscountVO;
import cn.lili.modules.promotion.entity.dos.*;
import cn.lili.modules.promotion.entity.enums.*;
@ -17,7 +17,6 @@ import cn.lili.modules.search.service.EsGoodsIndexService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
@ -355,8 +354,17 @@ public class PromotionServiceImpl implements PromotionService {
this.throwPromotionException(promotionTypeEnum, promotionMessage.getPromotionId(), promotionMessage.getPromotionStatus());
return false;
}
//修改活动状态
seckill.setPromotionStatus(promotionMessage.getPromotionStatus());
result = this.seckillService.update(promotionMessage.updateWrapper());
//判断参与活动的商品是否为空如果为空则返回
if(seckill.getSeckillApplyList()==null){
return result;
}
//循环秒杀商品数据将数据按照时间段进行存储
for (SeckillApply seckillApply : seckill.getSeckillApplyList()) {
if (seckillApply.getPromotionApplyStatus().equals(PromotionApplyStatusEnum.PASS.name())) {
//下一个时间默认为当天结束时间
@ -373,12 +381,12 @@ public class PromotionServiceImpl implements PromotionService {
}
}
Seckill seckill1 = JSONUtil.toBean(JSONUtil.toJsonStr(seckill), Seckill.class);
String format = cn.hutool.core.date.DateUtil.format(seckill.getStartTime(), DateUtil.STANDARD_DATE_FORMAT);
DateTime parseStartTime = cn.hutool.core.date.DateUtil.parse((format + " " + seckillApply.getTimeLine()), "yyyy-MM-dd HH");
DateTime parseEndTime = cn.hutool.core.date.DateUtil.parse((format + " " + nextHour), "yyyy-MM-dd HH");
String format = DateUtil.format(seckill.getStartTime(), cn.lili.common.utils.DateUtil.STANDARD_DATE_FORMAT);
DateTime parseStartTime = DateUtil.parse((format + " " + seckillApply.getTimeLine()), "yyyy-MM-dd HH");
DateTime parseEndTime = DateUtil.parse((format + " " + nextHour), "yyyy-MM-dd HH");
//如果是当天最后的时间段则设置到当天结束时间的59分59秒
if (nextHour == seckillApply.getTimeLine()) {
parseEndTime = cn.hutool.core.date.DateUtil.parse((format + " " + nextHour + ":59:59"), DateUtil.STANDARD_FORMAT);
parseEndTime = DateUtil.parse((format + " " + nextHour + ":59:59"), cn.lili.common.utils.DateUtil.STANDARD_FORMAT);
}
seckill1.setStartTime(parseStartTime);
//当时商品的秒杀活动活动结束时间为下个时间段的开始

View File

@ -19,6 +19,7 @@ import cn.lili.modules.promotion.entity.dos.Seckill;
import cn.lili.modules.promotion.entity.dos.SeckillApply;
import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum;
import cn.lili.modules.promotion.entity.enums.PromotionTypeEnum;
import cn.lili.modules.promotion.entity.enums.SeckillApplyStatusEnum;
import cn.lili.modules.promotion.entity.vos.SeckillSearchParams;
import cn.lili.modules.promotion.entity.vos.SeckillVO;
import cn.lili.modules.promotion.mapper.SeckillMapper;
@ -111,6 +112,17 @@ public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> impl
@Override
public void init() {
//清除演示数据
List<Seckill> seckillList=list();
for (Seckill seckill: seckillList) {
this.timeTrigger.delete(TimeExecuteConstant.PROMOTION_EXECUTOR,
seckill.getStartTime().getTime(),
DelayQueueTools.wrapperUniqueKey(DelayTypeEnums.PROMOTION, (PromotionTypeEnum.SECKILL.name() + seckill.getId())),
rocketmqCustomProperties.getPromotionTopic());
this.removeById(seckill.getId());
}
Setting setting = settingService.get(SettingEnum.SECKILL_SETTING.name());
SeckillSetting seckillSetting = new Gson().fromJson(setting.getSettingValue(), SeckillSetting.class);
for (int i=1;i<=30;i++){
@ -124,6 +136,9 @@ public class SeckillServiceImpl extends ServiceImpl<SeckillMapper, Seckill> impl
SeckillVO seckillVO=new SeckillVO();
BeanUtil.copyProperties(seckill,seckillVO);
seckillVO.setSeckillApplyStatus(SeckillApplyStatusEnum.NOT_APPLY.name());
seckillVO.setSeckillApplyList(null);
//检查秒杀活动参数
checkSeckillParam(seckillVO, seckill.getStoreId());
//保存到MYSQL中

View File

@ -22,13 +22,6 @@ public interface StoreGoodsLabelService extends IService<StoreGoodsLabel> {
*/
List<StoreGoodsLabelVO> listByStoreId(String storeId);
/**
* 获取当前店铺的店铺分类列表
*
* @return 店铺分类列表
*/
List<StoreGoodsLabel> listByStore();
/**
* 添加商品分类
*

View File

@ -1,7 +1,10 @@
package cn.lili.modules.store.serviceimpl;
import cn.lili.common.cache.Cache;
import cn.lili.common.cache.CachePrefix;
import cn.lili.common.security.AuthUser;
import cn.lili.common.security.context.UserContext;
import cn.lili.modules.goods.entity.vos.CategoryVO;
import cn.lili.modules.store.entity.dos.StoreGoodsLabel;
import cn.lili.modules.store.entity.vos.StoreGoodsLabelVO;
import cn.lili.modules.store.mapper.StoreGoodsLabelMapper;
@ -10,10 +13,12 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/**
@ -26,11 +31,21 @@ import java.util.List;
@Transactional(rollbackFor = Exception.class)
public class StoreGoodsLabelServiceImpl extends ServiceImpl<StoreGoodsLabelMapper, StoreGoodsLabel> implements StoreGoodsLabelService {
//缓存
@Autowired
private Cache cache;
@Override
public List<StoreGoodsLabelVO> listByStoreId(String storeId) {
//TODO 从缓存获取店铺商品分类列表
//从缓存中获取店铺分类
if (cache.hasKey(CachePrefix.STORE_CATEGORY.getPrefix() + storeId + "tree")) {
return (List<StoreGoodsLabelVO>) cache.get(CachePrefix.CATEGORY.getPrefix() + "tree");
}
List<StoreGoodsLabel> list = list(storeId);
List<StoreGoodsLabelVO> storeGoodsLabelVOList = new ArrayList<>();
//循环列表判断是否为顶级如果为顶级获取下级数据
list.stream()
.filter(storeGoodsLabel -> storeGoodsLabel.getLevel() == 0)
@ -43,15 +58,55 @@ public class StoreGoodsLabelServiceImpl extends ServiceImpl<StoreGoodsLabelMappe
storeGoodsLabelVO.setChildren(storeGoodsLabelVOChildList);
storeGoodsLabelVOList.add(storeGoodsLabelVO);
});
//调整店铺分类排序
storeGoodsLabelVOList.sort(new Comparator<StoreGoodsLabelVO>() {
@Override
public int compare(StoreGoodsLabelVO o1, StoreGoodsLabelVO o2) {
return o1.getSortOrder().compareTo(o2.getSortOrder());
}
});
if (storeGoodsLabelVOList.size() != 0) {
cache.put(CachePrefix.CATEGORY.getPrefix() + storeId + "tree", storeGoodsLabelVOList);
}
return storeGoodsLabelVOList;
}
@Override
public List<StoreGoodsLabel> listByStore() {
public StoreGoodsLabel addStoreGoodsLabel(StoreGoodsLabel storeGoodsLabel) {
//获取当前登录商家账号
AuthUser tokenUser = UserContext.getCurrentUser();
//返回列表
return list(tokenUser.getId());
storeGoodsLabel.setStoreId(tokenUser.getStoreId());
//保存店铺分类
this.save(storeGoodsLabel);
//清除缓存
removeCache(storeGoodsLabel.getStoreId());
return storeGoodsLabel;
}
@Override
public StoreGoodsLabel editStoreGoodsLabel(StoreGoodsLabel storeGoodsLabel) {
//修改当前店铺的商品分类
AuthUser tokenUser = UserContext.getCurrentUser();
LambdaUpdateWrapper<StoreGoodsLabel> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
lambdaUpdateWrapper.eq(StoreGoodsLabel::getStoreId, tokenUser.getStoreId());
lambdaUpdateWrapper.eq(StoreGoodsLabel::getId, storeGoodsLabel.getId());
//修改店铺分类
this.update(storeGoodsLabel, lambdaUpdateWrapper);
//清除缓存
removeCache(storeGoodsLabel.getStoreId());
return storeGoodsLabel;
}
@Override
public void removeStoreGoodsLabel(String storeLabelId) {
//删除店铺分类
this.removeById(storeLabelId);
//清除缓存
removeCache(UserContext.getCurrentUser().getStoreId());
}
/**
@ -66,28 +121,10 @@ public class StoreGoodsLabelServiceImpl extends ServiceImpl<StoreGoodsLabelMappe
return this.baseMapper.selectList(queryWrapper);
}
@Override
public StoreGoodsLabel addStoreGoodsLabel(StoreGoodsLabel storeGoodsLabel) {
//获取当前登录商家账号
AuthUser tokenUser = UserContext.getCurrentUser();
storeGoodsLabel.setStoreId(tokenUser.getStoreId());
this.save(storeGoodsLabel);
return storeGoodsLabel;
}
@Override
public StoreGoodsLabel editStoreGoodsLabel(StoreGoodsLabel storeGoodsLabel) {
//修改当前店铺的商品分类
AuthUser tokenUser = UserContext.getCurrentUser();
LambdaUpdateWrapper<StoreGoodsLabel> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
lambdaUpdateWrapper.eq(StoreGoodsLabel::getStoreId, tokenUser.getStoreId());
lambdaUpdateWrapper.eq(StoreGoodsLabel::getId, storeGoodsLabel.getId());
this.update(storeGoodsLabel, lambdaUpdateWrapper);
return storeGoodsLabel;
}
@Override
public void removeStoreGoodsLabel(String storeLabelId) {
this.removeById(storeLabelId);
/**
* 清除缓存
*/
private void removeCache(String storeId) {
cache.remove(CachePrefix.CATEGORY.getPrefix() + storeId + "tree");
}
}