订单15分钟到期 状态监听 库存回滚
商品排序值 初始化 出入库 日志记录 酒品管理 购物车次日清空
This commit is contained in:
@@ -1,24 +1,21 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.ysk.cashier.quartz.task;
|
||||
|
||||
import cn.ysk.cashier.repository.shop.TbShopStorageRepository;
|
||||
import cn.ysk.cashier.pojo.order.TbCashierCart;
|
||||
import cn.ysk.cashier.repository.order.TbCashierCartRepository;
|
||||
import cn.ysk.cashier.repository.product.TbProductSkuRepository;
|
||||
import cn.ysk.cashier.service.shop.TbShopStorageService;
|
||||
import cn.ysk.cashier.utils.CacheKey;
|
||||
import cn.ysk.cashier.utils.QueryHelp;
|
||||
import cn.ysk.cashier.utils.RedisUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.persistence.criteria.Predicate;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 测试用
|
||||
@@ -30,7 +27,15 @@ import org.springframework.stereotype.Service;
|
||||
public class TestTask {
|
||||
|
||||
@Autowired
|
||||
private TbShopStorageRepository storageRepository;
|
||||
private TbShopStorageService storageService;
|
||||
@Autowired
|
||||
private TbCashierCartRepository cartService;
|
||||
|
||||
@Autowired
|
||||
private TbProductSkuRepository skuRepository;
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
|
||||
public void run(){
|
||||
log.info("run 执行成功");
|
||||
@@ -47,7 +52,31 @@ public class TestTask {
|
||||
|
||||
public void expStorage(){
|
||||
log.info("存酒过期开始执行");
|
||||
storageRepository.expStorage();
|
||||
storageService.expStorage();
|
||||
log.info("存酒过期执行结束");
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cleanCart(){
|
||||
log.info("购物车清楚记录开始");
|
||||
List<TbCashierCart> all = cartService.findAll((root, criteriaQuery, criteriaBuilder) -> {
|
||||
Predicate predicate = QueryHelp.getPredicate(root, null, criteriaBuilder);
|
||||
predicate = criteriaBuilder.and(predicate, criteriaBuilder.isNull(root.get("masterId")));
|
||||
predicate = criteriaBuilder.and(predicate, criteriaBuilder.equal(root.get("status"), "create"));
|
||||
predicate = criteriaBuilder.and(predicate, criteriaBuilder.notEqual(root.get("tableId"), "0"));
|
||||
predicate = criteriaBuilder.and(predicate, criteriaBuilder.lt(root.get("updatedAt"), System.currentTimeMillis() - 60 * 1000L * 60 * 24));
|
||||
predicate = criteriaBuilder.and(predicate, criteriaBuilder.gt(root.get("updatedAt"), System.currentTimeMillis() - 60 * 1000L * 60 * 24 * 2));
|
||||
return predicate;
|
||||
});
|
||||
Set<String> keys = new HashSet<>();
|
||||
for (TbCashierCart cart : all) {
|
||||
skuRepository.updateStockNumber(Integer.valueOf(cart.getSkuId()),cart.getNumber().doubleValue());
|
||||
cart.setStatus("cancelled");
|
||||
cartService.save(cart);
|
||||
keys.add(CacheKey.PRODUCT_SKU + cart.getShopId() + ":" + cart.getSkuId());
|
||||
}
|
||||
String[] keysArray = keys.toArray(new String[keys.size()]);
|
||||
redisUtils.del(keysArray);
|
||||
log.info("购物车清楚记录开始结束");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user