‘linchangsheng’ 4 months ago
parent
commit
49407b72eb

+ 8 - 3
mall-server-api/src/main/java/com/gree/mall/manager/logic/policy/AgreementLogic.java

@@ -597,7 +597,8 @@ public class AgreementLogic {
             return;
         }
 
-        if (mailboxSendRecordService.lambdaQuery().gt(MailboxSendRecord::getSendTime, DateUtil.beginOfDay(date)).count() > 0) {
+        if (mailboxSendRecordService.lambdaQuery().gt(MailboxSendRecord::getSendTime, DateUtil.beginOfDay(date))
+                .eq(MailboxSendRecord::getPolicyType,PolicyTypeEnum.AC.getKey()).count() > 0) {
             return;
         }
 
@@ -1132,7 +1133,9 @@ public class AgreementLogic {
             return;
         }
 
-        if (mailboxSendRecordService.lambdaQuery().gt(MailboxSendRecord::getSendTime, DateUtil.beginOfDay(date)).count() > 0) {
+        if (mailboxSendRecordService.lambdaQuery().gt(MailboxSendRecord::getSendTime, DateUtil.beginOfDay(date))
+                .eq(MailboxSendRecord::getPolicyType,PolicyTypeEnum.EM.getKey())
+                .count() > 0) {
             return;
         }
 
@@ -1323,7 +1326,9 @@ public class AgreementLogic {
             return;
         }
 
-        if (mailboxSendRecordService.lambdaQuery().gt(MailboxSendRecord::getSendTime, DateUtil.beginOfDay(date)).count() > 0) {
+        if (mailboxSendRecordService.lambdaQuery().gt(MailboxSendRecord::getSendTime, DateUtil.beginOfDay(date))
+                .eq(MailboxSendRecord::getPolicyType,PolicyTypeEnum.IN.getKey())
+                .count() > 0) {
             return;
         }
 

+ 13 - 1
mall-server-api/src/main/java/com/gree/mall/manager/schedule/InsureEmailSchedule.java

@@ -2,7 +2,9 @@ package com.gree.mall.manager.schedule;
 
 
 
+import cn.hutool.core.date.DateUtil;
 import com.gree.mall.manager.logic.policy.AgreementLogic;
+import org.apache.http.client.utils.DateUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -10,6 +12,7 @@ import org.springframework.stereotype.Component;
 
 import javax.mail.MessagingException;
 import java.io.IOException;
+import java.util.Date;
 
 /**
  * 定时购买保险
@@ -25,8 +28,17 @@ public class InsureEmailSchedule {
 
 
     //每小时执行1次
-    @Scheduled(cron = "0 0/5 8,20 * * ?")
+    @Scheduled(fixedDelay = 600* 1000)
     public void task() throws IOException {
+
+        Date startTime = DateUtil.parseDateTime(DateUtils.formatDate(new Date(),"yyyy-MM-dd") +" "+"08:00:00");
+        Date endTime = DateUtil.parseDateTime(DateUtils.formatDate(new Date(),"yyyy-MM-dd") +" "+"20:00:00");
+
+        if (new Date().before(startTime))
+            return;
+        if (new Date().after(endTime))
+            return;
+
         agreementLogic.sendEmailSche();
         agreementLogic.sendEmailScheEM();
         agreementLogic.sendEmailScheIN();