From c7ef23a41cc5f81ebae95b5f6e8dca2294d71e1f Mon Sep 17 00:00:00 2001
From: 李宇 <986321569@qq.com>
Date: 星期五, 20 八月 2021 13:49:41 +0800
Subject: [PATCH] 修改邮件发送
---
src/main/java/com/nanometer/smartlab/util/EmailSend.java | 4 ++--
src/main/java/com/nanometer/smartlab/email/EmailSendSchedule.java | 9 +++++----
src/main/java/com/nanometer/smartlab/util/HttpUtil.java | 9 +++++----
3 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/src/main/java/com/nanometer/smartlab/email/EmailSendSchedule.java b/src/main/java/com/nanometer/smartlab/email/EmailSendSchedule.java
index 387622c..5bbf6b0 100644
--- a/src/main/java/com/nanometer/smartlab/email/EmailSendSchedule.java
+++ b/src/main/java/com/nanometer/smartlab/email/EmailSendSchedule.java
@@ -138,7 +138,7 @@
content.append("</body></html>");
try {
- EmailSend.sendArrivalEmail(revicerList,content.toString());
+ EmailSend.sendArrivalEmail(revicerList,content.toString(),"-待补货试剂");
// 发送成功,更新邮件发送状态为:已发送
} catch (BusinessException e) {
// 发送失败,更新邮件发送状态为:发送失败
@@ -165,6 +165,7 @@
* @date 2021/8/19 9:06
*/
@Scheduled(cron = "0 0 2 * * ?")
+// @Scheduled(cron = "0/5 * * * * ?") //每隔5秒执行一次
public void ReagentPriceSend(){
//0.限制在姑苏实验室
if (StringUtils.isBlank(reagentApi) || reagentApi.length() == 0) return;
@@ -204,8 +205,8 @@
BigDecimal goodsCostPrice = goodJson.getBigDecimal("goodsCostPrice");
BigDecimal price = reagent.getPrice();
//保留两位
- BigDecimal price_afterDiscount = SALE_85.multiply(price).setScale(2, RoundingMode.HALF_UP);
- if (price_afterDiscount.compareTo(goodsCostPrice) != 0) {
+ BigDecimal price_afterDiscount = SALE_85.multiply(goodsCostPrice).setScale(2, RoundingMode.HALF_UP);
+ if (price_afterDiscount.compareTo(price) > 0) {
sendDataList.add(new JSONObject() {{
put("goodsName", goodsName);
put("goodsCostPrice", goodsCostPrice);
@@ -241,7 +242,7 @@
//发送邮件
- EmailSend.sendArrivalEmail(Collections.singletonList(admin.getEmail()),content.toString());
+ EmailSend.sendArrivalEmail(Collections.singletonList(admin.getEmail()),content.toString(),"-国药试剂价格变动");
// 发送成功,更新邮件发送状态为:已发送
} catch (BusinessException e) {
diff --git a/src/main/java/com/nanometer/smartlab/util/EmailSend.java b/src/main/java/com/nanometer/smartlab/util/EmailSend.java
index 4eb6c29..fb7760f 100644
--- a/src/main/java/com/nanometer/smartlab/util/EmailSend.java
+++ b/src/main/java/com/nanometer/smartlab/util/EmailSend.java
@@ -79,7 +79,7 @@
}
- public static void sendArrivalEmail(List<String> revicerList, String msg){
+ public static void sendArrivalEmail(List<String> revicerList, String msg, String title){
EmailConfigService cs = SpringUtil.getBean("emailConfigService", EmailConfigService.class);
String sender = cs.getZkySmtpUser();/*发送人*/
String password = cs.getZkySmtpPwd();
@@ -127,7 +127,7 @@
//指明邮件的收件人
message.setRecipient(Message.RecipientType.TO, new InternetAddress(revicer));
//邮件的标题
- message.setSubject(sdf.format(new Date())+"-待补货试剂");
+ message.setSubject(sdf.format(new Date())+title);
//邮件的文本内容
message.setContent(msg, "text/html;charset=UTF-8");
//5、发送邮件
diff --git a/src/main/java/com/nanometer/smartlab/util/HttpUtil.java b/src/main/java/com/nanometer/smartlab/util/HttpUtil.java
index 38008a0..50c6a9a 100644
--- a/src/main/java/com/nanometer/smartlab/util/HttpUtil.java
+++ b/src/main/java/com/nanometer/smartlab/util/HttpUtil.java
@@ -3,16 +3,13 @@
import com.nanometer.smartlab.exception.BusinessException;
import com.nanometer.smartlab.exception.ExceptionEnumCode;
import org.apache.http.NameValuePair;
-import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
-
-import javax.swing.text.html.parser.Entity;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.List;
@@ -25,7 +22,11 @@
CloseableHttpClient client = HttpClients.createDefault();
URIBuilder builder = new URIBuilder(url);
URIBuilder uriBuilder = builder.setParameters(params);
+
+ RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(120000)
+ .setSocketTimeout(120000).setConnectTimeout(120000).build(); //设置超时
HttpGet get = new HttpGet(uriBuilder.build());
+ get.setConfig(requestConfig);
CloseableHttpResponse res = client.execute(get);
return EntityUtils.toString(res.getEntity(), "UTF-8");
} catch (IOException | URISyntaxException e) {
--
Gitblit v1.9.2