Merge remote-tracking branch 'origin/develop' into dev/dev

# Conflicts:
#	.gitignore
This commit is contained in:
shahaibo
2024-01-08 13:32:56 +08:00
6 changed files with 117 additions and 7 deletions

View File

@@ -1,10 +1,10 @@
version: "3"
services:
aida_back:
container_name: develop-version-aida-back
container_name: stable-version-aida-back
build: .
volumes:
# 数据挂载
- /workspace/home/aida/file/:/workspace/home/aida/file/
ports:
- "10090:5567"
- "10086:5567"

View File

@@ -3,9 +3,11 @@ package com.ai.da;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@Slf4j
@SpringBootApplication
@EnableScheduling
public class AiDaApplication {
public static void main(String[] args) {

View File

@@ -0,0 +1,53 @@
package com.ai.da.common.config;
import com.ai.da.common.utils.SendEmailUtil;
import com.ai.da.mapper.AccountMapper;
import com.ai.da.mapper.entity.Account;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
@Component
public class MyTaskScheduler {
@Resource
private AccountMapper accountMapper;
// 定时任务,每周一零点执行一次
@Scheduled(cron = "0 0 0 ? * MON")
// @Scheduled(cron = "0 0/1 * * * ?")
public void checkExpiry() {
// 检测正式用户是否快要过期
QueryWrapper<Account> qw = new QueryWrapper<>();
qw.lambda().eq(Account::getIsTrial, 0);
// qw.lambda().eq(Account::getId, 88);
List<Account> accountList = accountMapper.selectList(qw);
for (Account account : accountList) {
// 用户到期时间戳
Long timestamp = account.getValidEndTime(); // 替换为你的时间戳
// 获取当前时间戳
Long currentTimestamp = System.currentTimeMillis();
// 计算时间差(毫秒)
long timeDifference = currentTimestamp - timestamp;
if (timeDifference < 0) {
continue;
}
// 判断是否在30天以内30天的毫秒数
long thirtyDaysInMillis = 30L * 24 * 60 * 60 * 1000;
boolean within30Days = timeDifference <= thirtyDaysInMillis;
if (within30Days) {
// 发邮件
SendEmailUtil.sendWillBeExpiredEmail(account, null);
}
}
}
}

View File

@@ -1,5 +1,6 @@
package com.ai.da.common.utils;
import com.ai.da.mapper.entity.Account;
import com.ai.da.mapper.entity.TrialOrder;
import com.alibaba.fastjson.JSONObject;
import com.ai.da.common.config.exception.BusinessException;
@@ -178,6 +179,60 @@ public class SendEmailUtil {
throw new BusinessException("failed.to.send.mail");
}
}
private final static Long WILLBEEXPIRED_TEMPLATE_ID = 118178L;
public static void sendWillBeExpiredEmail(Account account, String senderAddress) {
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 = SEND_ADDRESS;
}
req.setFromEmailAddress(senderAddress);
req.setDestination(new String[]{account.getUserEmail()});
// 根据邮件类型设置不同的主题和模板
String subject = "";
Template template = new Template();
subject = "Renewal notice";
template.setTemplateID(WILLBEEXPIRED_TEMPLATE_ID);
template.setTemplateData(buildAccountData(account));
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 static String buildAccountData(Account account) {
JSONObject jsonObject = new JSONObject();
// 设置试用订单相关数据
jsonObject.put("userName", account.getUserName());
// 用户到期时间戳
Long timestamp = account.getValidEndTime(); // 替换为你的时间戳
// 获取当前时间戳
Long currentTimestamp = System.currentTimeMillis();
// 计算时间差(毫秒)
long timeDifference = currentTimestamp - timestamp;
// 向上取整计算天数
long days = (timeDifference + 24 * 60 * 60 * 1000 - 1) / (24 * 60 * 60 * 1000);
jsonObject.put("days", days);
return jsonObject.toJSONString();
}
// 构建试用订单数据
private static String buildTrialOrderData(TrialOrder trialOrder) {

View File

@@ -42,7 +42,7 @@ spring.servlet.multipart.max-request-size= 5MB
#access.python.ip=http://43.198.80.117
access.python.ip=http://18.167.251.121
#access.python.ip=http://18.167.251.121:9991/
access.python.port=9992
access.python.port=9991
minio.endpoint=https://www.minio.aida.com.hk:9000
minio.accessKey=admin
@@ -52,4 +52,4 @@ minio.bucketName.mannequins=aida-mannequins
minio.bucketName.results=aida-results
minio.bucketName.sysImage=aida-sys-image
minio.bucketName.users=aida-users
minio.bucketName.collectionElement=aida-collection-element
minio.bucketName.collectionElement=aida-collection-element

View File

@@ -1,8 +1,8 @@
#<23><><EFBFBD><EFBFBD>application-test<73>ļ<EFBFBD>(<28><><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD>)
spring.profiles.active=test
#spring.profiles.active=test
#<23><><EFBFBD><EFBFBD>application-prod<6F>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
#spring.profiles.active=prod
spring.profiles.active=prod
#<23><><EFBFBD><EFBFBD>application-dev<65>ļ<EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
#spring.profiles.active=dev
#spring.profiles.active=dev