use of com.actionworks.flashsale.app.auth.model.AuthResult in project flash-sale by ThoughtsBeta.
the class DefaultActivityAppService method offlineFlashActivity.
@Override
public AppResult offlineFlashActivity(Long userId, Long activityId) {
logger.info("activityOffline|下线活动|{},{}", userId, activityId);
if (userId == null || activityId == null) {
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);
}
flashActivityDomainService.offlineActivity(userId, activityId);
logger.info("activityOffline|活动已下线");
return AppResult.buildSuccess();
} catch (Exception e) {
logger.error("activityModification|活动修改失败|{},{}", userId, activityId, e);
throw new BizException("活动修改失败");
} finally {
activityModificationLock.unlock();
}
}
use of com.actionworks.flashsale.app.auth.model.AuthResult in project flash-sale by ThoughtsBeta.
the class DefaultActivityAppService method onlineFlashActivity.
@Override
public AppResult onlineFlashActivity(Long userId, Long activityId) {
logger.info("activityOnline|上线活动|{},{}", userId, activityId);
if (userId == null || activityId == null) {
throw new BizException(INVALID_PARAMS);
}
AuthResult authResult = authorizationService.auth(userId, FLASH_ACTIVITY_CREATE);
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);
}
flashActivityDomainService.onlineActivity(userId, activityId);
logger.info("activityOnline|活动已上线");
return AppResult.buildSuccess();
} catch (Exception e) {
logger.error("activityModification|活动修改失败|{},{}", userId, activityId, e);
throw new BizException("活动修改失败");
} finally {
activityModificationLock.unlock();
}
}
use of com.actionworks.flashsale.app.auth.model.AuthResult in project flash-sale by ThoughtsBeta.
the class DefaultFlashItemAppService method publishFlashItem.
@Override
public AppResult publishFlashItem(Long userId, Long activityId, FlashItemPublishCommand itemPublishCommand) {
logger.info("itemPublish|发布秒杀品|{},{},{}", userId, activityId, JSON.toJSON(itemPublishCommand));
if (userId == null || activityId == null || itemPublishCommand == null || !itemPublishCommand.validate()) {
throw new BizException(INVALID_PARAMS);
}
AuthResult authResult = authorizationService.auth(userId, FLASH_ITEM_CREATE);
if (!authResult.isSuccess()) {
throw new AuthException(UNAUTHORIZED_ACCESS);
}
DistributedLock itemCreateLock = lockFactoryService.getDistributedLock(getItemCreateLockKey(userId));
try {
boolean isLockSuccess = itemCreateLock.tryLock(500, 1000, TimeUnit.MILLISECONDS);
if (!isLockSuccess) {
throw new BizException(FREQUENTLY_ERROR);
}
FlashActivity flashActivity = flashActivityDomainService.getFlashActivity(activityId);
if (flashActivity == null) {
throw new BizException(ACTIVITY_NOT_FOUND);
}
FlashItem flashItem = toDomain(itemPublishCommand);
flashItem.setActivityId(activityId);
flashItem.setStockWarmUp(0);
flashItemDomainService.publishFlashItem(flashItem);
logger.info("itemPublish|秒杀品已发布");
return AppResult.buildSuccess();
} catch (Exception e) {
logger.error("itemPublish|秒杀品发布失败|{}", userId, e);
throw new BizException("秒杀品发布失败");
} finally {
itemCreateLock.unlock();
}
}
use of com.actionworks.flashsale.app.auth.model.AuthResult in project flash-sale by ThoughtsBeta.
the class SecurityRuleChainServiceBase method getUserId.
protected Long getUserId(HttpServletRequest request) {
String token = request.getParameter("token");
if (StringUtils.isEmpty(token)) {
return null;
}
AuthResult authResult = authorizationService.auth(token);
if (authResult.isSuccess()) {
return authResult.getUserId();
}
return null;
}
Aggregations