From 66e0127ba833721b3d615b804fa8a6f86beb8da1 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期五, 22 三月 2024 11:00:56 +0800
Subject: [PATCH] 1

---
 src/main/java/com/yssh/config/ScheduleConfig.java |   14 +++++++
 src/main/java/com/yssh/service/EmailService.java  |   52 +++++++++++++++++++++++---
 src/main/resources/application-dev.yml            |    3 +
 src/main/resources/application-prod.yml           |    3 +
 src/main/resources/application-test.yml           |    5 ++
 5 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/yssh/config/ScheduleConfig.java b/src/main/java/com/yssh/config/ScheduleConfig.java
index 0e46d77..e8ae9f3 100644
--- a/src/main/java/com/yssh/config/ScheduleConfig.java
+++ b/src/main/java/com/yssh/config/ScheduleConfig.java
@@ -46,11 +46,17 @@
 	@Resource
 	XlsReportService xlsReportService;
 
+	@Resource
+	EmailService emailService;
+
 	@Value("${csv.voc_max}")
 	private int vocMax = 96;
 
 	@Value("${csv.cron_max}")
 	private int cronMax = 48;
+
+	@Value("${email.enable}")
+	private Boolean enableEmail;
 
 	private final static List<String> md5List = new ArrayList<>();
 
@@ -235,4 +241,12 @@
 			}
 		}
 	}
+
+	@Scheduled(cron = "${email.times}")
+	public void autoCalcData() {
+		if (enableEmail) {
+			//emailService.calcData();
+			System.out.println("${email.times}");
+		}
+	}
 }
diff --git a/src/main/java/com/yssh/service/EmailService.java b/src/main/java/com/yssh/service/EmailService.java
index 3a1238b..d17cadc 100644
--- a/src/main/java/com/yssh/service/EmailService.java
+++ b/src/main/java/com/yssh/service/EmailService.java
@@ -1,11 +1,13 @@
 package com.yssh.service;
 
+import com.yssh.mapper.QxshMapper;
 import com.yssh.utils.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import javax.mail.*;
 import javax.mail.internet.InternetAddress;
 import javax.mail.internet.MimeMessage;
@@ -61,7 +63,16 @@
     private Integer hours;
 
     @Value("${email.names}")
-    private Integer names;
+    private String names;
+
+    @Value("${email.title}")
+    private String title;
+
+    @Value("${email.enable}")
+    private Boolean enable;
+
+    @Resource
+    private QxshMapper qxshMapper;
 
     private final static SimpleDateFormat YMDH = new SimpleDateFormat("yyyyMMddHH");
 
@@ -94,6 +105,10 @@
 
     public Boolean send(String title, String text) {
         try {
+            if (!enable) {
+                return null;
+            }
+
             // 鍒涘缓Session浼氳瘽
             Session session = createSession();
 
@@ -126,28 +141,53 @@
     public int calcData() {
         List<String> list = new ArrayList<>();
 
+        String[] strs = names.split(",");
         int count = countCsv(bigPath, hours);
         if (0 == count) {
-            list.add("澶SV杩� " + hours + " 灏忔椂瀛樺湪鏂囦欢缂哄け锛�");
+            list.add(strs[0] + "杩�" + hours + "灏忔椂瀛樺湪鏂囦欢缂哄け锛�");
         }
         count = countCsv(filePath, hours);
         if (0 == count) {
-            list.add("涓瑿SV杩� " + hours + " 灏忔椂瀛樺湪鏂囦欢缂哄け锛�");
+            list.add(strs[1] + "杩�" + hours + "灏忔椂瀛樺湪鏂囦欢缂哄け锛�");
         }
         count = countCsv(vocPath, hours);
         if (0 == count) {
-            list.add("灏廋SV杩� " + hours + " 灏忔椂瀛樺湪鏂囦欢缂哄け锛�");
+            list.add(strs[2] + "杩�" + hours + "灏忔椂瀛樺湪鏂囦欢缂哄け锛�");
         }
 
-        Calendar calendar = getCalendar(1);
-        calendar = getCalendar(0);
+        Calendar calendar = getCalendar(0);
         Integer iEnd = Integer.parseInt(YMDH.format(calendar.getTime()));
         String sEnd = Y_M_D_H.format(calendar.getTime());
         calendar.add(Calendar.HOUR, 1 - hours);
         Integer iStart = Integer.parseInt(YMDH.format(calendar.getTime()));
         String sStart = Y_M_D_H.format(calendar.getTime());
 
+        count = qxshMapper.countGcsjByTime(iStart, iEnd);
+        if (0 == count) {
+            list.add(strs[3] + "杩�" + hours + "灏忔椂瀛樺湪鏁版嵁缂哄け锛�");
+        }
+        count = qxshMapper.countQxshByTime(iStart, iEnd);
+        if (0 == count) {
+            list.add(strs[4] + "杩�" + hours + "灏忔椂瀛樺湪鏁版嵁缂哄け锛�");
+        }
+        count = qxshMapper.countSuYuan46ByTime(sStart, sEnd);
+        if (0 == count) {
+            list.add(strs[5] + "杩�" + hours + "灏忔椂瀛樺湪鏁版嵁缂哄け锛�");
+        }
+        count = qxshMapper.countSuYuan70ByTime(sStart, sEnd);
+        if (0 == count) {
+            list.add(strs[6] + "杩�" + hours + "灏忔椂瀛樺湪鏁版嵁缂哄け锛�");
+        }
+        count = qxshMapper.countSuYuanFastByTime(sStart, sEnd);
+        if (0 == count) {
+            list.add(strs[7] + "杩�" + hours + "灏忔椂瀛樺湪鏁版嵁缂哄け锛�");
+        }
+
         int size = list.size();
+        if (size > 0) {
+            String text = String.join("锛�", list.toArray(new String[list.size()])) + "銆�";
+            send(title, text);
+        }
 
         return size;
     }
diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml
index ae72652..b9c1e26 100644
--- a/src/main/resources/application-dev.yml
+++ b/src/main/resources/application-dev.yml
@@ -11,6 +11,9 @@
     cc: zhengliusuo@smartearth.cn
     hours: 6
     names: 澶SV,涓瑿SV,灏廋SV,瑙傛祴鏁版嵁,棰勬祴鏁版嵁,婧簮46,婧簮70,蹇�熸函婧�
+    title: 鏁版嵁棰勮
+    times: '0 41 * * * ?'
+    enable: false
 
 # 鏁版嵁婧愰厤缃�
 spring:
diff --git a/src/main/resources/application-prod.yml b/src/main/resources/application-prod.yml
index 8140c8b..3601d5c 100644
--- a/src/main/resources/application-prod.yml
+++ b/src/main/resources/application-prod.yml
@@ -11,6 +11,9 @@
     cc: zhengliusuo@smartearth.cn
     hours: 6
     names: 澶SV,涓瑿SV,灏廋SV,瑙傛祴鏁版嵁,棰勬祴鏁版嵁,婧簮46,婧簮70,蹇�熸函婧�
+    title: 鏁版嵁棰勮
+    times: '0 41 * * * ?'
+    enable: false
 
 # 鏁版嵁婧愰厤缃�
 spring:
diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml
index 547c3e1..c068790 100644
--- a/src/main/resources/application-test.yml
+++ b/src/main/resources/application-test.yml
@@ -1,7 +1,7 @@
 # 鐢靛瓙閭欢璁剧疆
 email:
     userName: 252740454
-    password:
+    password: 
     smtpHost: smtp.qq.com
     smtpPort: 587
     smtpAuth: true
@@ -11,6 +11,9 @@
     cc: zhengliusuo@smartearth.cn
     hours: 6
     names: 澶SV,涓瑿SV,灏廋SV,瑙傛祴鏁版嵁,棰勬祴鏁版嵁,婧簮46,婧簮70,蹇�熸函婧�
+    title: 鏁版嵁棰勮
+    times: '0 41 * * * ?'
+    enable: false
 
 # 鏁版嵁婧愰厤缃�
 spring:

--
Gitblit v1.9.3