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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations