use of com.wayn.common.exception.BusinessException in project waynboot-mall by wayn111.
the class OrderServiceImpl method cancel.
@Override
@Transactional(rollbackFor = Exception.class)
public R cancel(Long orderId) {
Order order = getById(orderId);
ReturnCodeEnum returnCodeEnum = checkOrderOperator(order);
if (!ReturnCodeEnum.SUCCESS.equals(returnCodeEnum)) {
return R.error(returnCodeEnum);
}
// 检测是否能够取消
OrderHandleOption handleOption = OrderUtil.build(order);
if (!handleOption.isCancel()) {
return R.error(ReturnCodeEnum.ORDER_CANNOT_CANCAL_ERROR);
}
// 设置订单已取消状态
order.setOrderStatus(OrderUtil.STATUS_CANCEL);
order.setOrderEndTime(LocalDateTime.now());
order.setUpdateTime(new Date());
if (!updateById(order)) {
throw new BusinessException("更新数据已失效");
}
// 商品货品数量增加
List<OrderGoods> goodsList = iOrderGoodsService.list(new QueryWrapper<OrderGoods>().eq("order_id", orderId));
for (OrderGoods orderGoods : goodsList) {
Long productId = orderGoods.getProductId();
Integer number = orderGoods.getNumber();
if (!iGoodsProductService.addStock(productId, number)) {
throw new BusinessException("商品货品库存增加失败");
}
}
// releaseCoupon(orderId);
return R.success();
}
use of com.wayn.common.exception.BusinessException in project waynboot-mall by wayn111.
the class UserController method uploadAvatar.
@PostMapping("uploadAvatar")
public R uploadAvatar(String avatar) {
LoginUserDetail loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
Member member = loginUser.getMember();
member.setAvatar(avatar);
boolean update = iMemberService.updateById(member);
if (!update) {
throw new BusinessException("上传头像失败");
}
loginUser.setMember(member);
tokenService.refreshToken(loginUser);
return R.result(true).add("userInfo", member);
}
use of com.wayn.common.exception.BusinessException in project waynboot-mall by wayn111.
the class UserController method updatePassword.
@PostMapping("updatePassword")
public R updatePassword(@RequestBody RegistryObj registryObj) {
if (!StringUtils.equalsIgnoreCase(registryObj.getPassword(), registryObj.getConfirmPassword())) {
return R.error(ReturnCodeEnum.USER_TWO_PASSWORD_NOT_SAME_ERROR);
}
String redisEmailCode = redisCache.getCacheObject(registryObj.getEmailKey());
// 判断邮箱验证码
if (registryObj.getEmailCode() == null || !redisEmailCode.equals(registryObj.getEmailCode().trim().toLowerCase())) {
return R.error(ReturnCodeEnum.USER_EMAIL_CODE_ERROR);
}
LoginUserDetail loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
Member member = loginUser.getMember();
member.setPassword(MobileSecurityUtils.encryptPassword(registryObj.getPassword()));
boolean update = iMemberService.updateById(member);
if (!update) {
throw new BusinessException("修改密码失败");
}
loginUser.setMember(member);
tokenService.refreshToken(loginUser);
return R.result(true).add("userInfo", member);
}
use of com.wayn.common.exception.BusinessException in project waynboot-mall by wayn111.
the class CommentServiceImpl method saveComment.
@Transactional(rollbackFor = Exception.class)
@Override
public boolean saveComment(CommentVO commentVO) {
Comment comment = new Comment();
BeanUtils.copyProperties(commentVO, comment);
comment.setCreateTime(new Date());
comment.setHasPicture(comment.getPicUrls().length > 0);
if (!save(comment)) {
throw new BusinessException("保存评论信息失败");
}
return iOrderGoodsService.update().set("comment", comment.getId()).eq("id", commentVO.getOrderGoodsId()).update();
}
use of com.wayn.common.exception.BusinessException in project waynboot-mall by wayn111.
the class UploadServiceImpl method uploadFile.
/**
* 七牛云上传文件
*
* @param fileName 文件名
* @return 上传后的文件访问路径
* @throws QiniuException 七牛异常
*/
@Override
public String uploadFile(String fileName) {
QiniuConfig qiniuConfig = iQiniuConfigService.getById(1);
if (qiniuConfig != null && qiniuConfig.getEnable()) {
File file = new File(WaynConfig.getUploadDir() + File.separator + fileName);
Configuration cfg = new Configuration(QiniuUtil.getRegion(qiniuConfig.getRegion()));
UploadManager uploadManager = new UploadManager(cfg);
Auth auth = Auth.create(qiniuConfig.getAccessKey(), qiniuConfig.getSecretKey());
String upToken = auth.uploadToken(qiniuConfig.getBucket());
Response response;
try {
response = uploadManager.put(file, file.getName(), upToken);
int retry = 0;
while (response.needRetry() && retry < 3) {
response = uploadManager.put(file, file.getName(), upToken);
retry++;
}
if (response.isOK()) {
JSONObject jsonObject = JSONObject.parseObject(response.bodyString());
String yunFileName = jsonObject.getString("key");
String yunFilePath = qiniuConfig.getHost() + "/" + yunFileName;
FileUtils.deleteQuietly(file);
log.info("【文件上传至七牛云】绝对路径:{}", yunFilePath);
return yunFilePath;
} else {
log.error("【文件上传至七牛云】失败,{}", JSONObject.toJSONString(response));
FileUtils.deleteQuietly(file);
throw new BusinessException("文件上传至七牛云失败");
}
} catch (QiniuException e) {
FileUtils.deleteQuietly(file);
throw new BusinessException("文件上传至七牛云失败");
}
} else {
String requestUrl = HttpUtil.getRequestContext(ServletUtils.getRequest());
return requestUrl + "/upload/" + fileName;
}
}
Aggregations