use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.
the class FlashItemDomainServiceImpl method onlineFlashItem.
@Override
public void onlineFlashItem(Long itemId) {
logger.info("itemOnline|上线秒杀品|{}", itemId);
if (itemId == null) {
throw new DomainException(PARAMS_INVALID);
}
Optional<FlashItem> flashItemOptional = flashItemRepository.findById(itemId);
if (!flashItemOptional.isPresent()) {
throw new DomainException(FLASH_ITEM_DOES_NOT_EXIST);
}
FlashItem flashItem = flashItemOptional.get();
if (FlashItemStatus.isOnline(flashItem.getStatus())) {
return;
}
flashItem.setStatus(FlashItemStatus.ONLINE.getCode());
flashItemRepository.save(flashItem);
logger.info("itemOnline|秒杀品已上线|{}", itemId);
FlashItemEvent flashItemPublishEvent = new FlashItemEvent();
flashItemPublishEvent.setEventType(FlashItemEventType.ONLINE);
flashItemPublishEvent.setFlashItem(flashItem);
domainEventPublisher.publish(flashItemPublishEvent);
logger.info("itemOnline|秒杀品上线事件已发布|{}", itemId);
}
use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.
the class FlashItemDomainServiceImpl method offlineFlashItem.
@Override
public void offlineFlashItem(Long itemId) {
logger.info("itemOffline|下线秒杀品|{}", itemId);
if (itemId == null) {
throw new DomainException(PARAMS_INVALID);
}
Optional<FlashItem> flashItemOptional = flashItemRepository.findById(itemId);
if (!flashItemOptional.isPresent()) {
throw new DomainException(FLASH_ITEM_DOES_NOT_EXIST);
}
FlashItem flashItem = flashItemOptional.get();
if (FlashItemStatus.isOffline(flashItem.getStatus())) {
return;
}
flashItem.setStatus(FlashItemStatus.OFFLINE.getCode());
flashItemRepository.save(flashItem);
logger.info("itemOffline|秒杀品已下线|{}", itemId);
FlashItemEvent flashItemEvent = new FlashItemEvent();
flashItemEvent.setEventType(FlashItemEventType.OFFLINE);
flashItemEvent.setFlashItem(flashItem);
domainEventPublisher.publish(flashItemEvent);
logger.info("itemOffline|秒杀品下线事件已发布|{}", itemId);
}
use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.
the class FlashOrderDomainServiceImpl method placeOrder.
@Override
public boolean placeOrder(Long userId, FlashOrder flashOrder) {
logger.info("placeOrder|下单|{},{}", userId, JSON.toJSONString(flashOrder));
if (flashOrder == null || !flashOrder.validateParamsForCreate()) {
throw new DomainException(PARAMS_INVALID);
}
flashOrder.setStatus(FlashOrderStatus.CREATED.getCode());
boolean saveSuccess = flashOrderRepository.save(flashOrder);
if (saveSuccess) {
FlashOrderEvent flashOrderEvent = new FlashOrderEvent();
flashOrderEvent.setEventType(FlashOrderEventType.CREATED);
domainEventPublisher.publish(flashOrderEvent);
}
logger.info("placeOrder|订单已创建成功|{},{}", userId, JSON.toJSONString(flashOrder));
return saveSuccess;
}
use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.
the class BadRequestExceptionHandler method handleConflict.
@ExceptionHandler(value = { BizException.class, FlowException.class, AuthException.class, DomainException.class })
protected ResponseEntity<Object> handleConflict(RuntimeException ex, WebRequest request) {
ExceptionResponse exceptionResponse = new ExceptionResponse();
if (ex instanceof UndeclaredThrowableException) {
if (((UndeclaredThrowableException) ex).getUndeclaredThrowable() instanceof FlowException) {
exceptionResponse.setErrorCode(LIMIT_BLOCK.getCode());
exceptionResponse.setErrorMessage(LIMIT_BLOCK.getDesc());
}
} else if (ex instanceof BizException || ex instanceof DomainException) {
exceptionResponse.setErrorCode(BIZ_ERROR.getCode());
exceptionResponse.setErrorMessage(ex.getMessage());
} else if (ex instanceof AuthException) {
exceptionResponse.setErrorCode(AUTH_ERROR.getCode());
exceptionResponse.setErrorMessage(AUTH_ERROR.getDesc());
}
logger.error("expectedException|预期错误|{},{}", ex.getMessage(), ex);
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
return handleExceptionInternal(ex, JSON.toJSONString(exceptionResponse), httpHeaders, HttpStatus.BAD_REQUEST, request);
}
use of com.actionworks.flashsale.domain.exception.DomainException in project flash-sale by ThoughtsBeta.
the class FlashOrderDomainServiceImpl method cancelOrder.
@Override
public boolean cancelOrder(Long userId, Long orderId) {
logger.info("placeOrder|取消订单|{},{}", userId, orderId);
if (StringUtils.isEmpty(userId) || orderId == null) {
throw new DomainException(PARAMS_INVALID);
}
Optional<FlashOrder> flashOrderOptional = flashOrderRepository.findById(orderId);
if (!flashOrderOptional.isPresent()) {
throw new DomainException(FLASH_ITEM_DOES_NOT_EXIST);
}
FlashOrder flashOrder = flashOrderOptional.get();
if (!flashOrder.getUserId().equals(userId)) {
throw new DomainException(FLASH_ITEM_DOES_NOT_EXIST);
}
if (FlashOrderStatus.isCancled(flashOrder.getStatus())) {
return false;
}
flashOrder.setStatus(FlashOrderStatus.CANCELED.getCode());
boolean saveSuccess = flashOrderRepository.updateStatus(flashOrder);
if (saveSuccess) {
FlashOrderEvent flashOrderEvent = new FlashOrderEvent();
flashOrderEvent.setEventType(FlashOrderEventType.CANCEL);
domainEventPublisher.publish(flashOrderEvent);
}
logger.info("placeOrder|订单已取消|{},{}", userId, orderId);
return saveSuccess;
}
Aggregations