Search in sources :

Example 1 with OpcBizException

use of com.paascloud.provider.exceptions.OpcBizException in project paascloud-master by paascloud.

the class OptSendMailServiceImpl method sendTemplateMail.

@Override
public int sendTemplateMail(Map<String, Object> model, String templateLocation, String subject, Set<String> to) {
    log.info("sendTemplateMail - 发送模板邮件. subject={}, model={}, to={}, templateLocation={}", subject, model, to, templateLocation);
    String text;
    try {
        text = optVelocityService.getTemplate(model, templateLocation);
    } catch (IOException | TemplateException e) {
        log.info("sendTemplateMail [FAIL] ex={}", e.getMessage(), e);
        throw new OpcBizException(ErrorCodeEnum.OPC10040006, e);
    }
    return this.sendTemplateMail(subject, text, to);
}
Also used : TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) OpcBizException(com.paascloud.provider.exceptions.OpcBizException)

Example 2 with OpcBizException

use of com.paascloud.provider.exceptions.OpcBizException in project paascloud-master by paascloud.

the class OptAttachmentServiceImpl method getById.

@Override
public OptAttachment getById(Long attachmentId) {
    Preconditions.checkArgument(attachmentId != null, "文件流水号不能为空");
    OptAttachment optAttachment = optAttachmentMapper.selectByPrimaryKey(attachmentId);
    if (PublicUtil.isEmpty(optAttachment)) {
        throw new OpcBizException(ErrorCodeEnum.OPC10040008, attachmentId);
    }
    return optAttachment;
}
Also used : OptAttachment(com.paascloud.provider.model.domain.OptAttachment) OpcBizException(com.paascloud.provider.exceptions.OpcBizException)

Example 3 with OpcBizException

use of com.paascloud.provider.exceptions.OpcBizException in project paascloud-master by paascloud.

the class OptQiniuOssServiceImpl method uploadFile.

@Override
public OptUploadFileRespDto uploadFile(byte[] uploadBytes, String fileName, String filePath, String bucketName) throws IOException {
    log.info("uploadFile - 上传文件. fileName={}, bucketName={}", fileName, bucketName);
    Preconditions.checkArgument(uploadBytes != null, "读取文件失败");
    Preconditions.checkArgument(StringUtils.isNotEmpty(fileName), ErrorCodeEnum.OPC10040010.msg());
    Preconditions.checkArgument(StringUtils.isNotEmpty(filePath), "文件路径不能为空");
    Preconditions.checkArgument(StringUtils.isNotEmpty(bucketName), "存储节点不能为空");
    InputStream is = new ByteArrayInputStream(uploadBytes);
    String inputStreamFileType = FileTypeUtil.getType(is);
    String newFileName = UniqueIdGenerator.generateId() + "." + inputStreamFileType;
    // 检查数据大小
    this.checkFileSize(uploadBytes);
    Response response = uploadManager.put(uploadBytes, filePath + newFileName, getUpToken(bucketName));
    DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);
    log.info("uploadFile - 上传文件. [OK] putRet={}", putRet);
    if (PublicUtil.isEmpty(putRet) || StringUtils.isEmpty(putRet.key)) {
        throw new OpcBizException(ErrorCodeEnum.OPC10040009);
    }
    String fileUrl;
    // 获取图片路径
    if (StringUtils.equals(OPEN_IMG_BUCKET, bucketName)) {
        fileUrl = paascloudProperties.getQiniu().getOss().getPublicHost() + "/" + filePath + newFileName;
    } else {
        String domainUrl = paascloudProperties.getQiniu().getOss().getPrivateHost();
        fileUrl = this.getFileUrl(domainUrl, fileName);
    }
    OptUploadFileRespDto result = new OptUploadFileRespDto();
    result.setAttachmentUrl(fileUrl);
    result.setAttachmentName(newFileName);
    result.setAttachmentPath(filePath);
    return result;
}
Also used : Response(com.qiniu.http.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Gson(com.google.gson.Gson) DefaultPutRet(com.qiniu.storage.model.DefaultPutRet) OpcBizException(com.paascloud.provider.exceptions.OpcBizException) OptUploadFileRespDto(com.paascloud.provider.model.dto.oss.OptUploadFileRespDto)

Example 4 with OpcBizException

use of com.paascloud.provider.exceptions.OpcBizException in project paascloud-master by paascloud.

the class OptSmsServiceImpl method sendSms.

@Override
public SendSmsResponse sendSms(SendSmsRequest sendSmsRequest) {
    checkParam(sendSmsRequest);
    SendSmsResponse acsResponse;
    try {
        if (GlobalConstant.DEV_PROFILE.equals(profile)) {
            log.error("dev环境不发送短信");
            return new SendSmsResponse();
        }
        if (GlobalConstant.TEST_PROFILE.equals(profile)) {
            log.error("test环境不发送短信");
            return new SendSmsResponse();
        }
        acsResponse = iAcsClient.getAcsResponse(sendSmsRequest);
    } catch (ClientException e) {
        log.error("send sms message error={}", e.getMessage(), e);
        throw new OpcBizException(ErrorCodeEnum.OPC10040004, e);
    }
    log.info("send sms message OK acsResponse={}", acsResponse);
    return acsResponse;
}
Also used : ClientException(com.aliyuncs.exceptions.ClientException) OpcBizException(com.paascloud.provider.exceptions.OpcBizException) SendSmsResponse(com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse)

Example 5 with OpcBizException

use of com.paascloud.provider.exceptions.OpcBizException in project paascloud-master by paascloud.

the class OptSendMailServiceImpl method getMimeMessage.

private MimeMessage getMimeMessage(String subject, String text, Set<String> to) {
    Preconditions.checkArgument(!PubUtils.isNull(subject, text, to), "参数异常, 邮件信息不完整");
    String[] toArray = setToArray(to);
    Preconditions.checkArgument(PublicUtil.isNotEmpty(toArray), "请输入收件人邮箱");
    MimeMessage mimeMessage = mailSender.createMimeMessage();
    MimeMessageHelper helper;
    try {
        helper = new MimeMessageHelper(mimeMessage, true);
        helper.setFrom(from);
        helper.setTo(toArray);
        helper.setSubject(subject);
        helper.setText(text, true);
    } catch (MessagingException e) {
        log.error("生成邮件消息体, 出现异常={}", e.getMessage(), e);
        throw new OpcBizException(ErrorCodeEnum.OPC10040005);
    }
    return mimeMessage;
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) OpcBizException(com.paascloud.provider.exceptions.OpcBizException) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper)

Aggregations

OpcBizException (com.paascloud.provider.exceptions.OpcBizException)5 SendSmsResponse (com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse)1 ClientException (com.aliyuncs.exceptions.ClientException)1 Gson (com.google.gson.Gson)1 OptAttachment (com.paascloud.provider.model.domain.OptAttachment)1 OptUploadFileRespDto (com.paascloud.provider.model.dto.oss.OptUploadFileRespDto)1 Response (com.qiniu.http.Response)1 DefaultPutRet (com.qiniu.storage.model.DefaultPutRet)1 TemplateException (freemarker.template.TemplateException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 MessagingException (javax.mail.MessagingException)1 MimeMessage (javax.mail.internet.MimeMessage)1 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)1