Search in sources :

Example 6 with PagesQueryCondition

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();
    }
}
Also used : DistributedLock(com.actionworks.flashsale.lock.DistributedLock) FlashItem(com.actionworks.flashsale.domain.model.entity.FlashItem) FlashItemsCache(com.actionworks.flashsale.app.service.item.cache.model.FlashItemsCache) PagesQueryCondition(com.actionworks.flashsale.domain.model.PagesQueryCondition)

Example 7 with PagesQueryCondition

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|校准库存缓存结束");
}
Also used : FlashItem(com.actionworks.flashsale.domain.model.entity.FlashItem) PagesQueryCondition(com.actionworks.flashsale.domain.model.PagesQueryCondition) Scheduled(org.springframework.scheduling.annotation.Scheduled) BetaTrace(com.actionworks.flashsale.config.annotion.BetaTrace)

Example 8 with PagesQueryCondition

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();
    }
}
Also used : DistributedLock(com.actionworks.flashsale.lock.DistributedLock) FlashActivity(com.actionworks.flashsale.domain.model.entity.FlashActivity) FlashActivitiesCache(com.actionworks.flashsale.app.service.activity.cache.model.FlashActivitiesCache) PagesQueryCondition(com.actionworks.flashsale.domain.model.PagesQueryCondition)

Example 9 with PagesQueryCondition

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;
}
Also used : PagesQueryCondition(com.actionworks.flashsale.domain.model.PagesQueryCondition)

Example 10 with 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);
}
Also used : FlashActivity(com.actionworks.flashsale.domain.model.entity.FlashActivity) PagesQueryCondition(com.actionworks.flashsale.domain.model.PagesQueryCondition)

Aggregations

PagesQueryCondition (com.actionworks.flashsale.domain.model.PagesQueryCondition)11 FlashItem (com.actionworks.flashsale.domain.model.entity.FlashItem)4 BetaTrace (com.actionworks.flashsale.config.annotion.BetaTrace)2 FlashActivity (com.actionworks.flashsale.domain.model.entity.FlashActivity)2 FlashOrder (com.actionworks.flashsale.domain.model.entity.FlashOrder)2 DistributedLock (com.actionworks.flashsale.lock.DistributedLock)2 Scheduled (org.springframework.scheduling.annotation.Scheduled)2 FlashActivitiesCache (com.actionworks.flashsale.app.service.activity.cache.model.FlashActivitiesCache)1 FlashItemsCache (com.actionworks.flashsale.app.service.item.cache.model.FlashItemsCache)1