use of com.actionworks.flashsale.domain.model.PagesQueryCondition in project flash-sale by ThoughtsBeta.
the class FlashItemsCacheService method tryToUpdateItemsCacheByLock.
public FlashItemsCache tryToUpdateItemsCacheByLock(Long activityId) {
logger.info("itemsCache|更新远程缓存|{}", activityId);
DistributedLock lock = distributedLockFactoryService.getDistributedLock(UPDATE_ITEMS_CACHE_LOCK_KEY + activityId);
try {
boolean isLockSuccess = lock.tryLock(1, 5, TimeUnit.SECONDS);
if (!isLockSuccess) {
return new FlashItemsCache().tryLater();
}
PagesQueryCondition pagesQueryCondition = new PagesQueryCondition();
pagesQueryCondition.setActivityId(activityId);
pagesQueryCondition.setStatus(FlashItemStatus.ONLINE.getCode());
PageResult<FlashItem> flashItemPageResult = flashItemDomainService.getFlashItems(pagesQueryCondition);
FlashItemsCache flashItemsCache;
if (flashItemPageResult == null) {
flashItemsCache = new FlashItemsCache().notExist();
} else {
flashItemsCache = new FlashItemsCache().setTotal(flashItemPageResult.getTotal()).setFlashItems(flashItemPageResult.getData()).setVersion(System.currentTimeMillis());
}
distributedCacheService.put(buildItemCacheKey(activityId), JSON.toJSONString(flashItemsCache), FIVE_MINUTES);
logger.info("itemsCache|远程缓存已更新|{}", activityId);
return flashItemsCache;
} catch (Exception e) {
logger.error("itemsCache|远程缓存更新失败|{}", activityId);
return new FlashItemsCache().tryLater();
} finally {
lock.unlock();
}
}
use of com.actionworks.flashsale.domain.model.PagesQueryCondition in project flash-sale by ThoughtsBeta.
the class StocksAlignScheduler method alignStocksTask.
@Scheduled(cron = "*/2 * * * * ?")
@BetaTrace
public void alignStocksTask() {
logger.info("alignStocksTask|校准库存缓存开始");
PagesQueryCondition pagesQueryCondition = new PagesQueryCondition();
pagesQueryCondition.setStatus(FlashItemStatus.ONLINE.getCode());
PageResult<FlashItem> pageResult = flashItemDomainService.getFlashItems(pagesQueryCondition);
pageResult.getData().forEach(flashItem -> {
boolean result = itemStockCacheService.alignItemStocks(flashItem.getId());
if (!result) {
logger.info("alignStocksTask|库存校准失败", flashItem.getId(), flashItem.getAvailableStock());
return;
}
logger.info("alignStocksTask|库存校准完成", flashItem.getId(), flashItem.getAvailableStock());
});
logger.info("alignStocksTask|校准库存缓存结束");
}
use of com.actionworks.flashsale.domain.model.PagesQueryCondition in project flash-sale by ThoughtsBeta.
the class FlashActivitiesCacheService method tryToUpdateActivitiesCacheByLock.
public FlashActivitiesCache tryToUpdateActivitiesCacheByLock(Integer pageNumber) {
logger.info("activitiesCache|更新远程缓存|{}", pageNumber);
DistributedLock lock = distributedLockFactoryService.getDistributedLock(UPDATE_ACTIVITIES_CACHE_LOCK_KEY);
try {
boolean isLockSuccess = lock.tryLock(1, 5, TimeUnit.SECONDS);
if (!isLockSuccess) {
return new FlashActivitiesCache().tryLater();
}
PagesQueryCondition pagesQueryCondition = new PagesQueryCondition();
PageResult<FlashActivity> flashActivityPageResult = flashActivityDomainService.getFlashActivities(pagesQueryCondition);
FlashActivitiesCache flashActivitiesCache;
if (flashActivityPageResult == null) {
flashActivitiesCache = new FlashActivitiesCache().notExist();
} else {
flashActivitiesCache = new FlashActivitiesCache().setTotal(flashActivityPageResult.getTotal()).setFlashActivities(flashActivityPageResult.getData()).setVersion(System.currentTimeMillis());
}
distributedCacheService.put(buildActivityCacheKey(pageNumber), JSON.toJSONString(flashActivitiesCache), FIVE_MINUTES);
logger.info("activitiesCache|远程缓存已更新|{}", pageNumber);
return flashActivitiesCache;
} catch (InterruptedException e) {
logger.error("activitiesCache|远程缓存更新失败", e);
return new FlashActivitiesCache().tryLater();
} finally {
lock.unlock();
}
}
use of com.actionworks.flashsale.domain.model.PagesQueryCondition in project flash-sale by ThoughtsBeta.
the class FlashOrderAppBuilder method toFlashOrdersQuery.
public static PagesQueryCondition toFlashOrdersQuery(FlashOrdersQuery flashOrdersQuery) {
if (flashOrdersQuery == null) {
return new PagesQueryCondition();
}
PagesQueryCondition pagesQueryCondition = new PagesQueryCondition();
BeanUtils.copyProperties(flashOrdersQuery, pagesQueryCondition);
return pagesQueryCondition;
}
use of com.actionworks.flashsale.domain.model.PagesQueryCondition in project flash-sale by ThoughtsBeta.
the class FlashActivityDomainServiceImpl method getFlashActivities.
@Override
public PageResult<FlashActivity> getFlashActivities(PagesQueryCondition pagesQueryCondition) {
if (pagesQueryCondition == null) {
pagesQueryCondition = new PagesQueryCondition();
}
List<FlashActivity> flashActivities = flashActivityRepository.findFlashActivitiesByCondition(pagesQueryCondition.buildParams());
Integer total = flashActivityRepository.countFlashActivitiesByCondition(pagesQueryCondition);
return PageResult.with(flashActivities, total);
}
Aggregations