From 2f55cebbad3dea187a5f91d16ec80a9677dab699 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 13 十一月 2024 11:16:53 +0800 Subject: [PATCH] 1 --- src/main/java/com/yssh/service/EmailService.java | 109 ++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 81 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/yssh/service/EmailService.java b/src/main/java/com/yssh/service/EmailService.java index 3a1238b..2729437 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; @@ -13,12 +15,6 @@ import java.text.SimpleDateFormat; import java.util.*; -/** - * 閭欢鏈嶅姟绫� - * - * @author www - * @date 2024-03-21 - */ @Service public class EmailService { @Value("${email.userName}") @@ -61,7 +57,21 @@ private Integer hours; @Value("${email.names}") - private Integer names; + private String names; + + @Value("${email.title}") + private String title; + + @Value("${email.enable}") + private Boolean enable; + + @Value("${email.debug}") + private Boolean debug; + + @Resource + private QxshMapper qxshMapper; + + private static boolean isBusy = false; private final static SimpleDateFormat YMDH = new SimpleDateFormat("yyyyMMddHH"); @@ -70,14 +80,13 @@ protected final Logger logger = LoggerFactory.getLogger(this.getClass()); public Session createSession() { - // 鍒涘缓涓�涓厤缃枃浠讹紝骞朵繚瀛� Properties props = new Properties(); - // SMTP鏈嶅姟鍣ㄨ繛鎺ヤ俊鎭細126鈥攕mtp.126.com锛�163鈥攕mtp.163.com锛宷q-smtp.qq.com" - props.put("mail.smtp.host", smtpHost); // SMTP涓绘満鍚� - props.put("mail.smtp.port", smtpPort); // 涓绘満绔彛鍙凤細126鈥�25锛�163鈥�645锛宷q-587 - props.put("mail.smtp.auth", smtpAuth); // 鏄惁闇�瑕佺敤鎴疯璇� - props.put("mail.smtp.starttls.enale", smtpTls); // 鍚敤TlS鍔犲瘑 + // 126鈥攕mtp.126.com锛�163鈥攕mtp.163.com锛宷q-smtp.qq.com" + props.put("mail.smtp.host", smtpHost); + props.put("mail.smtp.port", smtpPort); + props.put("mail.smtp.auth", smtpAuth); + props.put("mail.smtp.starttls.enale", smtpTls); Session session = Session.getInstance(props, new Authenticator() { @Override @@ -86,18 +95,19 @@ } }); - // 鎺у埗鍙版墦鍗拌皟璇曚俊鎭� - session.setDebug(true); + session.setDebug(debug); return session; } public Boolean send(String title, String text) { try { - // 鍒涘缓Session浼氳瘽 + if (!enable) { + return null; + } + Session session = createSession(); - // 鍒涘缓閭欢瀵硅薄 MimeMessage message = new MimeMessage(session); message.setSubject(title); message.setText(text); @@ -113,7 +123,6 @@ message.setRecipients(Message.RecipientType.CC, ias); } - // 鍙戦�� Transport.send(message); return true; @@ -123,33 +132,77 @@ } } - public int calcData() { - List<String> list = new ArrayList<>(); + public Integer calcData() { + try { + if (isBusy) { + return null; + } + isBusy = true; + List<String> list = new ArrayList<>(); + calcCsvData(list); + calcDbData(list); + + int size = list.size(); + if (size > 0) { + String text = String.join("銆�", list.toArray(new String[list.size()])) + "锛岃繎" + hours + "灏忔椂鍐呭瓨鍦ㄦ暟鎹己澶便��"; + send(title, text); + } + isBusy = false; + + return size; + } catch (Exception ex) { + logger.error(ex.getMessage(), ex); + isBusy = false; + return null; + } + } + + private void calcCsvData(List<String> list) { + String[] strs = names.split(","); int count = countCsv(bigPath, hours); if (0 == count) { - list.add("澶SV杩� " + hours + " 灏忔椂瀛樺湪鏂囦欢缂哄け锛�"); + list.add(strs[0]); } count = countCsv(filePath, hours); if (0 == count) { - list.add("涓瑿SV杩� " + hours + " 灏忔椂瀛樺湪鏂囦欢缂哄け锛�"); + list.add(strs[1]); } count = countCsv(vocPath, hours); if (0 == count) { - list.add("灏廋SV杩� " + hours + " 灏忔椂瀛樺湪鏂囦欢缂哄け锛�"); + list.add(strs[2]); } + } - Calendar calendar = getCalendar(1); - calendar = getCalendar(0); + private void calcDbData(List<String> list) { + 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()); - int size = list.size(); - - return size; + String[] strs = names.split(","); + int count = qxshMapper.countGcsjByTime(iStart, iEnd); + if (0 == count) { + list.add(strs[3]); + } + count = qxshMapper.countQxshByTime(iStart, iEnd); + if (0 == count) { + list.add(strs[4]); + } + count = qxshMapper.countSuYuan46ByTime(sStart, sEnd); + if (0 == count) { + list.add(strs[5]); + } + count = qxshMapper.countSuYuan70ByTime(sStart, sEnd); + if (0 == count) { + list.add(strs[6]); + } + count = qxshMapper.countSuYuanFastByTime(sStart, sEnd); + if (0 == count) { + list.add(strs[7]); + } } public int countCsv(String path, Integer hours) { -- Gitblit v1.9.3