From 84dd2d7cd9e4d490921912bd01b1a21853b8512a Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Fri, 5 Jan 2024 11:31:23 +0800 Subject: [PATCH 1/6] =?UTF-8?q?TASK:=E7=AB=AF=E5=8F=A3;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index c0b49c3e..ee0c4ef5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,4 +7,4 @@ services: # 数据挂载 - /workspace/home/aida/file/:/workspace/home/aida/file/ ports: - - "10090:5567" + - "10086:5567" From 7a95bce2b18f9f9e15ace18b6e8ef01d32cc022f Mon Sep 17 00:00:00 2001 From: zchengrong <124802516+zchengrong@users.noreply.github.com> Date: Sat, 6 Jan 2024 19:25:51 +0800 Subject: [PATCH 2/6] Update docker-compose.yml --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index ee0c4ef5..e7cd3236 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: "3" services: aida_back: - container_name: develop-version-aida-back + container_name: stable-version-aida-back build: . volumes: # 数据挂载 From 6e979d58a236ec9bb6ea46a049bcd36b868238e2 Mon Sep 17 00:00:00 2001 From: zchengrong <124802516+zchengrong@users.noreply.github.com> Date: Sat, 6 Jan 2024 20:08:19 +0800 Subject: [PATCH 3/6] Update application-prod.properties --- src/main/resources/application-prod.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application-prod.properties b/src/main/resources/application-prod.properties index 0a8163df..0d9913ab 100644 --- a/src/main/resources/application-prod.properties +++ b/src/main/resources/application-prod.properties @@ -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 \ No newline at end of file +minio.bucketName.collectionElement=aida-collection-element From 67c137392f2e1253b72a6f69ef653070b638ff90 Mon Sep 17 00:00:00 2001 From: zchengrong <124802516+zchengrong@users.noreply.github.com> Date: Sat, 6 Jan 2024 20:11:06 +0800 Subject: [PATCH 4/6] Update application.properties --- src/main/resources/application.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index e8510ce9..8550475d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,8 +1,8 @@ #����application-test�ļ�(���Ի���) -spring.profiles.active=test +#spring.profiles.active=test #����application-prod�ļ�(��������) -#spring.profiles.active=prod +spring.profiles.active=prod #����application-dev�ļ�(��������) -#spring.profiles.active=dev \ No newline at end of file +#spring.profiles.active=dev From 5bed3c180b1f084913de660d99061570c668b6f1 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Mon, 8 Jan 2024 13:02:50 +0800 Subject: [PATCH 5/6] =?UTF-8?q?TASK:=E7=BB=AD=E8=AE=A2=E9=80=9A=E7=9F=A5;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/ai/da/AiDaApplication.java | 2 + .../ai/da/common/config/MyTaskScheduler.java | 53 ++++++++++++++++++ .../com/ai/da/common/utils/SendEmailUtil.java | 55 +++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 src/main/java/com/ai/da/common/config/MyTaskScheduler.java diff --git a/src/main/java/com/ai/da/AiDaApplication.java b/src/main/java/com/ai/da/AiDaApplication.java index 2933e83a..2454e1d8 100644 --- a/src/main/java/com/ai/da/AiDaApplication.java +++ b/src/main/java/com/ai/da/AiDaApplication.java @@ -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) { diff --git a/src/main/java/com/ai/da/common/config/MyTaskScheduler.java b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java new file mode 100644 index 00000000..0aa04f9e --- /dev/null +++ b/src/main/java/com/ai/da/common/config/MyTaskScheduler.java @@ -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 qw = new QueryWrapper<>(); + qw.lambda().eq(Account::getIsTrial, 0); +// qw.lambda().eq(Account::getId, 88); + List 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); + } + } + } +} diff --git a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java index 6622798a..a14975a4 100644 --- a/src/main/java/com/ai/da/common/utils/SendEmailUtil.java +++ b/src/main/java/com/ai/da/common/utils/SendEmailUtil.java @@ -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) { From 80976f45a7dd69ad57e4e6c4acb57006f3e6d614 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Mon, 8 Jan 2024 13:30:34 +0800 Subject: [PATCH 6/6] =?UTF-8?q?TASK:=E5=BF=BD=E7=95=A5docker=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index e0bb6bbf..365943cb 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ logs/ log temp/ +docker-compose.yml +