Search in sources :

Example 11 with FlashActivity

use of com.actionworks.flashsale.domain.model.entity.FlashActivity in project flash-sale by ThoughtsBeta.

the class FlashActivityDomainServiceImpl method onlineActivity.

@Override
public void onlineActivity(Long userId, Long activityId) {
    logger.info("activityOnline|上线秒杀活动|{},{}", userId, activityId);
    if (StringUtils.isEmpty(userId) || activityId == null) {
        throw new DomainException(PARAMS_INVALID);
    }
    Optional<FlashActivity> flashActivityOptional = flashActivityRepository.findById(activityId);
    if (!flashActivityOptional.isPresent()) {
        throw new DomainException(FLASH_ACTIVITY_DOES_NOT_EXIST);
    }
    FlashActivity flashActivity = flashActivityOptional.get();
    if (FlashActivityStatus.isOnline(flashActivity.getStatus())) {
        return;
    }
    flashActivity.setStatus(FlashActivityStatus.ONLINE.getCode());
    flashActivityRepository.save(flashActivity);
    logger.info("activityOnline|活动已上线|{},{}", userId, flashActivity.getId());
    FlashActivityEvent flashActivityEvent = new FlashActivityEvent();
    flashActivityEvent.setEventType(FlashActivityEventType.ONLINE);
    flashActivityEvent.setFlashActivity(flashActivity);
    domainEventPublisher.publish(flashActivityEvent);
    logger.info("activityOnline|活动上线事件已发布|{}", JSON.toJSON(flashActivityEvent));
}
Also used : FlashActivity(com.actionworks.flashsale.domain.model.entity.FlashActivity) DomainException(com.actionworks.flashsale.domain.exception.DomainException) FlashActivityEvent(com.actionworks.flashsale.domain.event.FlashActivityEvent)

Example 12 with FlashActivity

use of com.actionworks.flashsale.domain.model.entity.FlashActivity in project flash-sale by ThoughtsBeta.

the class FlashActivityRepositoryImpl method findById.

@Override
public Optional<FlashActivity> findById(Long activityId) {
    FlashActivityDO flashActivityDO = flashActivityMapper.getById(activityId);
    if (flashActivityDO == null) {
        return Optional.empty();
    }
    FlashActivity flashActivity = FlashActivityBuilder.toDomainObject(flashActivityDO);
    return Optional.of(flashActivity);
}
Also used : FlashActivity(com.actionworks.flashsale.domain.model.entity.FlashActivity) FlashActivityDO(com.actionworks.flashsale.persistence.model.FlashActivityDO)

Aggregations

FlashActivity (com.actionworks.flashsale.domain.model.entity.FlashActivity)12 DistributedLock (com.actionworks.flashsale.lock.DistributedLock)4 AuthResult (com.actionworks.flashsale.app.auth.model.AuthResult)2 BizException (com.actionworks.flashsale.app.exception.BizException)2 FlashActivitiesCache (com.actionworks.flashsale.app.service.activity.cache.model.FlashActivitiesCache)2 FlashActivityCache (com.actionworks.flashsale.app.service.activity.cache.model.FlashActivityCache)2 AuthException (com.actionworks.flashsale.controller.exception.AuthException)2 FlashActivityEvent (com.actionworks.flashsale.domain.event.FlashActivityEvent)2 DomainException (com.actionworks.flashsale.domain.exception.DomainException)2 PagesQueryCondition (com.actionworks.flashsale.domain.model.PagesQueryCondition)2 FlashActivityDTO (com.actionworks.flashsale.app.model.dto.FlashActivityDTO)1 FlashItem (com.actionworks.flashsale.domain.model.entity.FlashItem)1 FlashActivityDO (com.actionworks.flashsale.persistence.model.FlashActivityDO)1