Search in sources :

Example 6 with BusinessException

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();
}
Also used : OrderHandleOption(com.wayn.common.core.util.OrderHandleOption) BusinessException(com.wayn.common.exception.BusinessException) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ReturnCodeEnum(com.wayn.common.enums.ReturnCodeEnum) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with BusinessException

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);
}
Also used : BusinessException(com.wayn.common.exception.BusinessException) LoginUserDetail(com.wayn.mobile.framework.security.LoginUserDetail) Member(com.wayn.common.core.domain.shop.Member)

Example 8 with BusinessException

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);
}
Also used : BusinessException(com.wayn.common.exception.BusinessException) LoginUserDetail(com.wayn.mobile.framework.security.LoginUserDetail) Member(com.wayn.common.core.domain.shop.Member)

Example 9 with BusinessException

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();
}
Also used : Comment(com.wayn.common.core.domain.shop.Comment) BusinessException(com.wayn.common.exception.BusinessException) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with BusinessException

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;
    }
}
Also used : Response(com.qiniu.http.Response) BusinessException(com.wayn.common.exception.BusinessException) QiniuException(com.qiniu.common.QiniuException) Configuration(com.qiniu.storage.Configuration) JSONObject(com.alibaba.fastjson.JSONObject) Auth(com.qiniu.util.Auth) QiniuConfig(com.wayn.common.core.domain.tool.QiniuConfig) File(java.io.File) UploadManager(com.qiniu.storage.UploadManager)

Aggregations

BusinessException (com.wayn.common.exception.BusinessException)14 Transactional (org.springframework.transaction.annotation.Transactional)4 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)3 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)3 LoginUserDetail (com.wayn.mobile.framework.security.LoginUserDetail)3 Member (com.wayn.common.core.domain.shop.Member)2 OrderHandleOption (com.wayn.common.core.util.OrderHandleOption)2 ReturnCodeEnum (com.wayn.common.enums.ReturnCodeEnum)2 Cart (com.wayn.mobile.api.domain.Cart)2 File (java.io.File)2 BeanUtil (cn.hutool.core.bean.BeanUtil)1 JSON (com.alibaba.fastjson.JSON)1 JSONObject (com.alibaba.fastjson.JSONObject)1 AlipayApiException (com.alipay.api.AlipayApiException)1 AlipayClient (com.alipay.api.AlipayClient)1 DefaultAlipayClient (com.alipay.api.DefaultAlipayClient)1 AlipaySignature (com.alipay.api.internal.util.AlipaySignature)1 AlipayTradeWapPayRequest (com.alipay.api.request.AlipayTradeWapPayRequest)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Wrappers (com.baomidou.mybatisplus.core.toolkit.Wrappers)1