From c1f4b9b40a67667ff35fd36baf4e969c90eb5554 Mon Sep 17 00:00:00 2001
From: bunny <1319900154@qq.com>
Date: Thu, 9 May 2024 16:42:44 +0800
Subject: [PATCH] =?UTF-8?q?feat(=E6=96=B0=E5=A2=9E):=20=E6=8B=86=E5=88=86?=
=?UTF-8?q?=E5=90=84=E4=B8=AA=E6=A8=A1=E5=9D=97,=E5=B0=81=E8=A3=85?=
=?UTF-8?q?=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
common/common-utils/pom.xml | 4 ---
.../common/constant/MessageConstant.java | 4 +++
.../properties/SnowflakeProperties.java | 2 --
common/service-utils/pom.xml | 5 ---
.../service/config/WebMvcConfiguration.java | 3 +-
.../bunny/common/service/utils/EmptyUtil.java | 12 +++++++
.../bunny/common/service/utils/HttpUtil.java} | 4 +--
.../common/service}/utils/JwtHelper.java | 2 +-
.../common/service}/utils/ResponseUtil.java | 2 +-
.../service}/utils/SnowflakeIdGenerator.java | 2 +-
.../filter/TokenAuthenticationFilter.java | 11 +++----
.../security/filter/TokenLoginFilter.java | 4 +--
.../java/cn/bunny/entity/email/EmailSend.java | 3 ++
module/module-mail/pom.xml | 31 ++++++++++++++++++
.../cn/bunny/module/mail/template-propties | 23 +++++++++++++
.../module/mail/utils/MailSendCheck.java | 18 +++++++++++
.../module/mail}/utils/MailSenderHelper.java | 8 ++++-
module/module-minio/pom.xml | 27 ++++++++++++++++
.../minio}/properties/MinioProperties.java | 2 +-
module/module-rabbitMQ/pom.xml | 30 +++++++++++++++++
module/pom.xml | 32 +++++++++++++++++++
pom.xml | 1 +
service/pom.xml | 5 +++
.../service/controller/MailController.java | 7 ++--
.../bunny/service/service/EmailService.java | 3 +-
.../service/impl/EmailServiceImpl.java | 7 ++--
.../service/impl/SysUserServiceImpl.java | 2 +-
service/src/main/resources/application.yml | 22 -------------
28 files changed, 214 insertions(+), 62 deletions(-)
create mode 100644 common/service-utils/src/main/java/cn/bunny/common/service/utils/EmptyUtil.java
rename common/{common-utils/src/main/java/cn/bunny/common/utils/HttpUtils.java => service-utils/src/main/java/cn/bunny/common/service/utils/HttpUtil.java} (99%)
rename common/{common-utils/src/main/java/cn/bunny/common => service-utils/src/main/java/cn/bunny/common/service}/utils/JwtHelper.java (97%)
rename common/{common-utils/src/main/java/cn/bunny/common => service-utils/src/main/java/cn/bunny/common/service}/utils/ResponseUtil.java (94%)
rename common/{common-utils/src/main/java/cn/bunny/common => service-utils/src/main/java/cn/bunny/common/service}/utils/SnowflakeIdGenerator.java (99%)
create mode 100644 module/module-mail/pom.xml
create mode 100644 module/module-mail/src/main/java/cn/bunny/module/mail/template-propties
create mode 100644 module/module-mail/src/main/java/cn/bunny/module/mail/utils/MailSendCheck.java
rename {common/common-utils/src/main/java/cn/bunny/common => module/module-mail/src/main/java/cn/bunny/module/mail}/utils/MailSenderHelper.java (95%)
create mode 100644 module/module-minio/pom.xml
rename {common/service-utils/src/main/java/cn/bunny/common/service => module/module-minio/src/main/java/cn/bunny/module/minio}/properties/MinioProperties.java (95%)
create mode 100644 module/module-rabbitMQ/pom.xml
create mode 100644 module/pom.xml
diff --git a/common/common-utils/pom.xml b/common/common-utils/pom.xml
index 5f69e9a..44d76da 100644
--- a/common/common-utils/pom.xml
+++ b/common/common-utils/pom.xml
@@ -28,10 +28,6 @@
jaxb-api
2.1
-
- org.springframework.boot
- spring-boot-starter-mail
-
com.baomidou
diff --git a/common/common-utils/src/main/java/cn/bunny/common/constant/MessageConstant.java b/common/common-utils/src/main/java/cn/bunny/common/constant/MessageConstant.java
index 1e6f631..4ce72f8 100644
--- a/common/common-utils/src/main/java/cn/bunny/common/constant/MessageConstant.java
+++ b/common/common-utils/src/main/java/cn/bunny/common/constant/MessageConstant.java
@@ -35,4 +35,8 @@ public class MessageConstant {
public static final String LOGIN_DTO_IS_EMPTY = "登录参数不能为空";
public static final String TOKEN_IS_EMPTY = "token为空";
public static final String DATA_IS_EMPTY = "数据为空";
+ public static final String EMPTY_SEND_OBJECT = "空发送对象";
+ public static final String ADDRESS_NOT_NULL = "收件人不能为空";
+ public static final String TITLE_NOT_NULL = "标题不能为空";
+ public static final String SEND_MESSAGE_NOT_NULL = "发送消息不能为空";
}
diff --git a/common/common-utils/src/main/java/cn/bunny/common/properties/SnowflakeProperties.java b/common/common-utils/src/main/java/cn/bunny/common/properties/SnowflakeProperties.java
index 718657c..362d453 100644
--- a/common/common-utils/src/main/java/cn/bunny/common/properties/SnowflakeProperties.java
+++ b/common/common-utils/src/main/java/cn/bunny/common/properties/SnowflakeProperties.java
@@ -8,8 +8,6 @@ import org.springframework.stereotype.Component;
@ConfigurationProperties(prefix = "snowflake")
@Data
public class SnowflakeProperties {
-
-
// 数据中心id
private Long datacenterId;
// 数据中心id位数
diff --git a/common/service-utils/pom.xml b/common/service-utils/pom.xml
index 75261f2..3a851e6 100644
--- a/common/service-utils/pom.xml
+++ b/common/service-utils/pom.xml
@@ -22,11 +22,6 @@
common-utils
0.0.1-SNAPSHOT
-
-
- io.minio
- minio
-
org.springframework.boot
diff --git a/common/service-utils/src/main/java/cn/bunny/common/service/config/WebMvcConfiguration.java b/common/service-utils/src/main/java/cn/bunny/common/service/config/WebMvcConfiguration.java
index 82f1b5a..7624b83 100644
--- a/common/service-utils/src/main/java/cn/bunny/common/service/config/WebMvcConfiguration.java
+++ b/common/service-utils/src/main/java/cn/bunny/common/service/config/WebMvcConfiguration.java
@@ -1,7 +1,6 @@
package cn.bunny.common.service.config;
import lombok.extern.slf4j.Slf4j;
-import org.jetbrains.annotations.NotNull;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
@@ -11,7 +10,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Slf4j
public class WebMvcConfiguration implements WebMvcConfigurer {
@Override
- public void addResourceHandlers(@NotNull ResourceHandlerRegistry registry) {
+ public void addResourceHandlers(ResourceHandlerRegistry registry) {
log.info("WebMvcConfiguration===>设置");
registry.addResourceHandler("/favicon.ico").addResourceLocations("classpath:/");
diff --git a/common/service-utils/src/main/java/cn/bunny/common/service/utils/EmptyUtil.java b/common/service-utils/src/main/java/cn/bunny/common/service/utils/EmptyUtil.java
new file mode 100644
index 0000000..84e08ba
--- /dev/null
+++ b/common/service-utils/src/main/java/cn/bunny/common/service/utils/EmptyUtil.java
@@ -0,0 +1,12 @@
+package cn.bunny.common.service.utils;
+
+import cn.bunny.common.service.exception.BunnyException;
+import org.springframework.util.StringUtils;
+
+public class EmptyUtil {
+ public static void isEmpty(Object value, String message) {
+ if (value == null || !StringUtils.hasText(value.toString())) {
+ throw new BunnyException(message);
+ }
+ }
+}
diff --git a/common/common-utils/src/main/java/cn/bunny/common/utils/HttpUtils.java b/common/service-utils/src/main/java/cn/bunny/common/service/utils/HttpUtil.java
similarity index 99%
rename from common/common-utils/src/main/java/cn/bunny/common/utils/HttpUtils.java
rename to common/service-utils/src/main/java/cn/bunny/common/service/utils/HttpUtil.java
index 42ce443..bfb9b51 100644
--- a/common/common-utils/src/main/java/cn/bunny/common/utils/HttpUtils.java
+++ b/common/service-utils/src/main/java/cn/bunny/common/service/utils/HttpUtil.java
@@ -1,4 +1,4 @@
-package cn.bunny.common.utils;
+package cn.bunny.common.service.utils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
@@ -29,7 +29,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-public class HttpUtils {
+public class HttpUtil {
public static HttpResponse doGet(String host, String path, String method, Map headers, Map querys) throws Exception {
HttpClient httpClient = wrapClient(host);
diff --git a/common/common-utils/src/main/java/cn/bunny/common/utils/JwtHelper.java b/common/service-utils/src/main/java/cn/bunny/common/service/utils/JwtHelper.java
similarity index 97%
rename from common/common-utils/src/main/java/cn/bunny/common/utils/JwtHelper.java
rename to common/service-utils/src/main/java/cn/bunny/common/service/utils/JwtHelper.java
index de2422e..318b6bb 100644
--- a/common/common-utils/src/main/java/cn/bunny/common/utils/JwtHelper.java
+++ b/common/service-utils/src/main/java/cn/bunny/common/service/utils/JwtHelper.java
@@ -1,4 +1,4 @@
-package cn.bunny.common.utils;
+package cn.bunny.common.service.utils;
import io.jsonwebtoken.*;
import org.springframework.util.StringUtils;
diff --git a/common/common-utils/src/main/java/cn/bunny/common/utils/ResponseUtil.java b/common/service-utils/src/main/java/cn/bunny/common/service/utils/ResponseUtil.java
similarity index 94%
rename from common/common-utils/src/main/java/cn/bunny/common/utils/ResponseUtil.java
rename to common/service-utils/src/main/java/cn/bunny/common/service/utils/ResponseUtil.java
index 3ebc06a..3e822a0 100644
--- a/common/common-utils/src/main/java/cn/bunny/common/utils/ResponseUtil.java
+++ b/common/service-utils/src/main/java/cn/bunny/common/service/utils/ResponseUtil.java
@@ -1,4 +1,4 @@
-package cn.bunny.common.utils;
+package cn.bunny.common.service.utils;
import cn.bunny.common.result.Result;
import com.fasterxml.jackson.databind.ObjectMapper;
diff --git a/common/common-utils/src/main/java/cn/bunny/common/utils/SnowflakeIdGenerator.java b/common/service-utils/src/main/java/cn/bunny/common/service/utils/SnowflakeIdGenerator.java
similarity index 99%
rename from common/common-utils/src/main/java/cn/bunny/common/utils/SnowflakeIdGenerator.java
rename to common/service-utils/src/main/java/cn/bunny/common/service/utils/SnowflakeIdGenerator.java
index fcc0fa2..72215e9 100644
--- a/common/common-utils/src/main/java/cn/bunny/common/utils/SnowflakeIdGenerator.java
+++ b/common/service-utils/src/main/java/cn/bunny/common/service/utils/SnowflakeIdGenerator.java
@@ -1,4 +1,4 @@
-package cn.bunny.common.utils;
+package cn.bunny.common.service.utils;
import cn.bunny.common.properties.SnowflakeProperties;
diff --git a/common/spring-security/src/main/java/cn/bunny/security/filter/TokenAuthenticationFilter.java b/common/spring-security/src/main/java/cn/bunny/security/filter/TokenAuthenticationFilter.java
index bc7511e..dea5c18 100644
--- a/common/spring-security/src/main/java/cn/bunny/security/filter/TokenAuthenticationFilter.java
+++ b/common/spring-security/src/main/java/cn/bunny/security/filter/TokenAuthenticationFilter.java
@@ -1,13 +1,12 @@
package cn.bunny.security.filter;
import cn.bunny.common.service.context.BaseContext;
-import cn.bunny.common.utils.JwtHelper;
+import cn.bunny.common.service.utils.JwtHelper;
import com.alibaba.fastjson2.JSON;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
-import org.jetbrains.annotations.NotNull;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
@@ -28,7 +27,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
}
@Override
- protected void doFilterInternal(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull FilterChain chain) throws ServletException, IOException {
+ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
String token = request.getHeader("token");
// login请求就没token,直接放行,因为后边有其他的过滤器
@@ -46,9 +45,9 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
private UsernamePasswordAuthenticationToken getAuthentication(HttpServletRequest request) {
// 请求头是否有token
String token = request.getHeader("token");
- if (!StringUtils.isEmpty(token)) {
+ if (StringUtils.hasText(token)) {
String username = JwtHelper.getUserName(token);
- if (!StringUtils.isEmpty(username)) {
+ if (StringUtils.hasText(username)) {
// 当前用户信息放到ThreadLocal里面
BaseContext.setUserId(JwtHelper.getUserId(token));
BaseContext.setUsername(username);
@@ -56,7 +55,7 @@ public class TokenAuthenticationFilter extends OncePerRequestFilter {
// 通过username从redis获取权限数据
String authString = (String) redisTemplate.opsForValue().get(username);
// 把redis获取字符串权限数据转换要求集合类型 List
- if (!StringUtils.isEmpty(authString)) {
+ if (StringUtils.hasText(authString)) {
List
+
+ cn.bunny
+ module-mail
+ 0.0.1-SNAPSHOT
+
cn.bunny
diff --git a/service/src/main/java/cn/bunny/service/controller/MailController.java b/service/src/main/java/cn/bunny/service/controller/MailController.java
index 8412b4c..997d037 100644
--- a/service/src/main/java/cn/bunny/service/controller/MailController.java
+++ b/service/src/main/java/cn/bunny/service/controller/MailController.java
@@ -3,7 +3,6 @@ package cn.bunny.service.controller;
import cn.bunny.common.result.Result;
import cn.bunny.entity.email.EmailSend;
import cn.bunny.service.service.EmailService;
-import com.alibaba.fastjson2.JSON;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
@@ -12,7 +11,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
@RestController
@Tag(name = "发送邮件")
@@ -32,10 +30,9 @@ public class MailController {
@Operation(summary = "发送带附件邮件", description = "发送带附件邮件")
@PostMapping("send-attachment")
- public Result sendAttachment(@RequestBody MultipartFile file, String emailSend) {
+ public Result sendAttachment(@RequestBody EmailSend emailSend) {
log.info("发送带附件邮件");
- EmailSend send = JSON.parseObject(emailSend, EmailSend.class);
- boolean isSuccess = emailService.sendAttachmentEmail(send, file);
+ boolean isSuccess = emailService.sendAttachmentEmail(emailSend);
return isSuccess ? Result.success() : Result.error();
}
diff --git a/service/src/main/java/cn/bunny/service/service/EmailService.java b/service/src/main/java/cn/bunny/service/service/EmailService.java
index a040b25..afdcd89 100644
--- a/service/src/main/java/cn/bunny/service/service/EmailService.java
+++ b/service/src/main/java/cn/bunny/service/service/EmailService.java
@@ -2,7 +2,6 @@ package cn.bunny.service.service;
import cn.bunny.entity.email.EmailSend;
-import org.springframework.web.multipart.MultipartFile;
public interface EmailService {
/**
@@ -18,7 +17,7 @@ public interface EmailService {
* @param emailSend 邮件消息
* @return 是否成功
*/
- boolean sendAttachmentEmail(EmailSend emailSend, MultipartFile file);
+ boolean sendAttachmentEmail(EmailSend emailSend);
/**
* 发送富文本邮件
diff --git a/service/src/main/java/cn/bunny/service/service/impl/EmailServiceImpl.java b/service/src/main/java/cn/bunny/service/service/impl/EmailServiceImpl.java
index 7316e51..9b483b4 100644
--- a/service/src/main/java/cn/bunny/service/service/impl/EmailServiceImpl.java
+++ b/service/src/main/java/cn/bunny/service/service/impl/EmailServiceImpl.java
@@ -1,13 +1,12 @@
package cn.bunny.service.service.impl;
-import cn.bunny.common.utils.MailSenderHelper;
import cn.bunny.entity.email.EmailSend;
import cn.bunny.entity.email.EmailSendInit;
+import cn.bunny.module.mail.utils.MailSenderHelper;
import cn.bunny.service.service.EmailService;
import jakarta.mail.MessagingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
-import org.springframework.web.multipart.MultipartFile;
@Service
@Slf4j
@@ -36,7 +35,7 @@ public class EmailServiceImpl implements EmailService {
* @return 是否成功
*/
@Override
- public boolean sendAttachmentEmail(EmailSend emailSend, MultipartFile file) {
+ public boolean sendAttachmentEmail(EmailSend emailSend) {
try {
EmailSendInit emailSendInit = new EmailSendInit();
emailSendInit.setHost("smtp.qq.com");
@@ -45,7 +44,7 @@ public class EmailServiceImpl implements EmailService {
emailSendInit.setPassword("axyqbvfuxkdqdaai");
MailSenderHelper mailSenderHelper = new MailSenderHelper(emailSendInit);
- mailSenderHelper.sendAttachmentEmail(emailSend, file, true);
+ mailSenderHelper.sendEmail(emailSend);
return true;
} catch (MessagingException e) {
return false;
diff --git a/service/src/main/java/cn/bunny/service/service/impl/SysUserServiceImpl.java b/service/src/main/java/cn/bunny/service/service/impl/SysUserServiceImpl.java
index f0c4055..ac017cf 100644
--- a/service/src/main/java/cn/bunny/service/service/impl/SysUserServiceImpl.java
+++ b/service/src/main/java/cn/bunny/service/service/impl/SysUserServiceImpl.java
@@ -2,7 +2,7 @@ package cn.bunny.service.service.impl;
import cn.bunny.common.constant.MessageConstant;
import cn.bunny.common.service.exception.BunnyException;
-import cn.bunny.common.utils.JwtHelper;
+import cn.bunny.common.service.utils.JwtHelper;
import cn.bunny.entity.system.Login;
import cn.bunny.entity.system.SysUser;
import cn.bunny.entity.system.SysUserinfo;
diff --git a/service/src/main/resources/application.yml b/service/src/main/resources/application.yml
index 1017407..8921738 100644
--- a/service/src/main/resources/application.yml
+++ b/service/src/main/resources/application.yml
@@ -35,28 +35,6 @@ spring:
name: user
password: 1
- mail:
- host: smtp.qq.com # 邮箱地址
- port: 465 # 邮箱端口号
- username: 3324855376@qq.com # 设置发送邮箱
- password: axyqbvfuxkdqdaai # 如果是纯数字要加引号
- default-encoding: UTF-8 # 设置编码格式
- protocol: smtps
- properties:
- mail:
- debug: true # 是否开启debug模式发送邮件
- smtp:
- auth: true
- connectionTimeout: 5000 # 设置连接延迟
- timeout: 5000 # 延迟时间
- writeTimeout: 5000 # 写入邮箱延迟
- allow8BitMime: true
- sendPartial: true
- ssl:
- enabled: true # 是否开启SSL连接
- socketFactory:
- class: javax.net.ssl.SSLSocketFactory # 必要设置!!!
-
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
configuration: