TASK:toproductimage prompt;

This commit is contained in:
shahaibo
2024-12-02 12:02:19 +08:00
parent 8d6e3e9644
commit b315ae5644
8 changed files with 301 additions and 52 deletions

View File

@@ -484,6 +484,57 @@ public class MinioUtil {
return null; // or throw an exception
}
}
/**
* 从 MinIO 下载对象到本地路径
*
* @param bucketName 存储桶名称
* @param objectName MinIO 上对象的名称
* @param localFilePath 本地文件路径
*/
public void downloadMinioObjectToLocal(String bucketName, String objectName, String localFilePath) {
File localFile = new File(localFilePath);
File parentDir = localFile.getParentFile();
if (parentDir != null) {
parentDir.mkdirs(); // 创建文件夹,确保路径结构与 MinIO 一致
}
try (InputStream stream = minioClient.getObject(
GetObjectArgs.builder().bucket(bucketName).object(objectName).build());
FileOutputStream out = new FileOutputStream(localFile)) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = stream.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
log.info("Downloaded object {} to {}", objectName, localFilePath);
} catch (Exception e) {
log.error("Error while downloading object {}: {}", objectName, e.getMessage());
}
}
/**
* 从路径中提取存储桶名称
*
* @param path MinIO 路径
* @return 存储桶名称
*/
public String getBucketNameFromPath(String path) {
int index = path.indexOf("/");
return path.substring(0, index); // 获取第一级路径作为 bucket 名称
}
/**
* 从路径中提取对象名称
*
* @param path MinIO 路径
* @return 对象名称
*/
public String getObjectNameFromPath(String path) {
int index = path.indexOf("/");
return path.substring(index + 1); // 获取路径的其余部分作为对象名称
}
}

View File

@@ -389,20 +389,20 @@ public class SendEmailUtil {
// 根据邮件类型设置不同的主题和模板
String subject = "";
Template template = new Template();
if (type == 1) {
subject = "Upcoming System Upgrade for AiDA 3.0";
template.setTemplateID(UPGRADE_NOTIFICATION_ID);
}else {
subject = "即将到来的AiDA 3.0系统升级";
template.setTemplateID(UPGRADE_NOTIFICATION_ID_CHINESE);
}
// if (type == 1) {
// subject = "Successful System Upgrade and New Features in AiDA 3.1";
// template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID);
// subject = "Upcoming System Upgrade for AiDA 3.0";
// template.setTemplateID(UPGRADE_NOTIFICATION_ID);
// }else {
// subject = "系统升级成功和AiDA 3.1新功能";
// template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID_CHINESE);
// subject = "即将到来的AiDA 3.0系统升级";
// template.setTemplateID(UPGRADE_NOTIFICATION_ID_CHINESE);
// }
if (type == 1) {
subject = "Successful System Upgrade and New Features in AiDA 3.1";
template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID);
}else {
subject = "系统升级成功和AiDA 3.1新功能";
template.setTemplateID(UPGRADE_SUCCESS_NOTIFICATION_ID_CHINESE);
}
template.setTemplateData(buildAccountData(account));
req.setSubject(subject);
@@ -759,6 +759,47 @@ public class SendEmailUtil {
req.setSubject(subject);
req.setTemplate(template);
// 发送邮件
SendEmailResponse resp = client.SendEmail(req);
log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) {
log.info("邮件发送失败###{}", e.toString());
throw new BusinessException("failed.to.send.mail");
}
}
private final static Long SYSTEM_UPGRADE_CN_ID = 131743L;
private final static Long SYSTEM_UPGRADE_EN_ID = 131744L;
public static void temporaryUpgrade(Account account, String senderAddress, int type) {
try {
// 实例化一个认证对象
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("ses.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
SesClient client = new SesClient(cred, "ap-hongkong", clientProfile);
SendEmailRequest req = new SendEmailRequest();
if (StringUtils.isEmpty(senderAddress)) {
senderAddress = CODE_CREATE_SEND_ADDRESS;
}
req.setFromEmailAddress(senderAddress);
req.setDestination(new String[]{account.getUserEmail()});
// 根据邮件类型设置不同的主题和模板
String subject = "";
Template template = new Template();
if (type == 1) {
subject = "AiDA system upgrade completed";
template.setTemplateID(SYSTEM_UPGRADE_EN_ID);
}else {
subject = "AiDA系统升级完成";
template.setTemplateID(SYSTEM_UPGRADE_CN_ID);
}
template.setTemplateData(buildAccountData(account));
req.setSubject(subject);
req.setTemplate(template);
// 发送邮件
SendEmailResponse resp = client.SendEmail(req);
log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp));