use of com.actionworks.flashsale.domain.model.entity.FlashActivity in project flash-sale by ThoughtsBeta.
the class FlashActivityAppBuilder method toDomain.
public static FlashActivity toDomain(FlashActivityPublishCommand flashActivityPublishCommand) {
if (flashActivityPublishCommand == null) {
return null;
}
FlashActivity flashActivity = new FlashActivity();
BeanUtils.copyProperties(flashActivityPublishCommand, flashActivity);
return flashActivity;
}
use of com.actionworks.flashsale.domain.model.entity.FlashActivity in project flash-sale by ThoughtsBeta.
the class FlashActivityDomainServiceImpl method offlineActivity.
@Override
public void offlineActivity(Long userId, Long activityId) {
logger.info("activityOffline|下线秒杀活动|{},{}", 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.isOffline(flashActivity.getStatus())) {
return;
}
if (!FlashActivityStatus.isOnline(flashActivity.getStatus())) {
throw new DomainException(FLASH_ACTIVITY_NOT_ONLINE);
}
flashActivity.setStatus(FlashActivityStatus.OFFLINE.getCode());
flashActivityRepository.save(flashActivity);
logger.info("activityOffline|活动已下线|{},{}", userId, flashActivity.getId());
FlashActivityEvent flashActivityEvent = new FlashActivityEvent();
flashActivityEvent.setEventType(FlashActivityEventType.OFFLINE);
flashActivityEvent.setFlashActivity(flashActivity);
domainEventPublisher.publish(flashActivityEvent);
logger.info("activityOffline|活动下线事件已发布|{}", JSON.toJSON(flashActivityEvent));
}
use of com.actionworks.flashsale.domain.model.entity.FlashActivity in project flash-sale by ThoughtsBeta.
the class DefaultActivityAppService method modifyFlashActivity.
@Override
public AppResult modifyFlashActivity(Long userId, Long activityId, FlashActivityPublishCommand flashActivityPublishCommand) {
logger.info("activityModification|秒杀活动修改|{},{},{}", userId, activityId, JSON.toJSONString(flashActivityPublishCommand));
if (userId == null || flashActivityPublishCommand == null || !flashActivityPublishCommand.validate()) {
throw new BizException(INVALID_PARAMS);
}
AuthResult authResult = authorizationService.auth(userId, FLASH_ACTIVITY_MODIFICATION);
if (!authResult.isSuccess()) {
throw new AuthException(UNAUTHORIZED_ACCESS);
}
DistributedLock activityModificationLock = lockFactoryService.getDistributedLock(getActivityModificationLockKey(activityId));
try {
boolean isLockSuccess = activityModificationLock.tryLock(500, 1000, TimeUnit.MILLISECONDS);
if (!isLockSuccess) {
throw new BizException(FREQUENTLY_ERROR);
}
FlashActivity flashActivity = toDomain(flashActivityPublishCommand);
flashActivity.setId(activityId);
flashActivityDomainService.modifyActivity(userId, flashActivity);
logger.info("activityModification|活动已修改");
return AppResult.buildSuccess();
} catch (Exception e) {
logger.error("activityModification|活动修改失败|{},{}", userId, activityId, e);
throw new BizException("活动修改失败");
} finally {
activityModificationLock.unlock();
}
}
use of com.actionworks.flashsale.domain.model.entity.FlashActivity in project flash-sale by ThoughtsBeta.
the class DefaultActivityAppService method getFlashActivities.
@Override
public AppMultiResult<FlashActivityDTO> getFlashActivities(Long userId, FlashActivitiesQuery flashActivitiesQuery) {
List<FlashActivity> activities;
Integer total;
if (flashActivitiesQuery.isFirstPureQuery()) {
FlashActivitiesCache flashActivitiesCache = flashActivitiesCacheService.getCachedActivities(flashActivitiesQuery.getPageNumber(), flashActivitiesQuery.getVersion());
if (flashActivitiesCache.isLater()) {
return AppMultiResult.tryLater();
}
activities = flashActivitiesCache.getFlashActivities();
total = flashActivitiesCache.getTotal();
} else {
PageResult<FlashActivity> flashActivityPageResult = flashActivityDomainService.getFlashActivities(toFlashActivitiesQuery(flashActivitiesQuery));
activities = flashActivityPageResult.getData();
total = flashActivityPageResult.getTotal();
}
List<FlashActivityDTO> flashActivityDTOList = activities.stream().map(FlashActivityAppBuilder::toFlashActivityDTO).collect(Collectors.toList());
return AppMultiResult.of(flashActivityDTOList, total);
}
use of com.actionworks.flashsale.domain.model.entity.FlashActivity in project flash-sale by ThoughtsBeta.
the class DefaultActivityAppService method isAllowPlaceOrderOrNot.
@Override
public boolean isAllowPlaceOrderOrNot(Long activityId) {
FlashActivityCache flashActivityCache = flashActivityCacheService.getCachedActivity(activityId, null);
if (flashActivityCache.isLater()) {
logger.info("isAllowPlaceOrderOrNot|稍后再试|{}", activityId);
return false;
}
if (!flashActivityCache.isExist() || flashActivityCache.getFlashActivity() == null) {
logger.info("isAllowPlaceOrderOrNot|活动不存在|{}", activityId);
return false;
}
FlashActivity flashActivity = flashActivityCache.getFlashActivity();
if (!flashActivity.isOnline()) {
logger.info("isAllowPlaceOrderOrNot|活动尚未上线|{}", activityId);
return false;
}
if (!flashActivity.isInProgress()) {
logger.info("isAllowPlaceOrderOrNot|活动非秒杀时段|{}", activityId);
return false;
}
// 可在此处丰富其他校验规则
return true;
}
Aggregations