parent
fc83a6dcef
commit
01de876b14
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,71 @@
|
|||||||
|
/**
|
||||||
|
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
||||||
|
* <p>
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
|
* the License at
|
||||||
|
* <p>
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* <p>
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations under
|
||||||
|
* the License.
|
||||||
|
*/
|
||||||
|
package org.opsli.modulars.tools.email.service;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @BelongsProject: opsli-boot
|
||||||
|
* @BelongsPackage: org.opsli.modulars.system.service
|
||||||
|
* @Author: Parker
|
||||||
|
* @CreateTime: 2020-09-17 13:07
|
||||||
|
* @Description: 租户 接口
|
||||||
|
*/
|
||||||
|
public interface IEmailService {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送邮件
|
||||||
|
* @param to 收件人
|
||||||
|
* @param subject 主题
|
||||||
|
* @param content 内容
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
String send(String to, String subject, String content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送邮件
|
||||||
|
* @param tos 收件人(可多人发送)
|
||||||
|
* @param subject 主题
|
||||||
|
* @param content 内容
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
String send(Collection<String> tos, String subject, String content);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送邮件
|
||||||
|
* @param to 收件人
|
||||||
|
* @param subject 主题
|
||||||
|
* @param content 内容
|
||||||
|
* @param isHtml 是否 Html内容
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
String send(String to, String subject, String content, boolean isHtml);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送邮件
|
||||||
|
* @param tos 收件人
|
||||||
|
* @param subject 主题
|
||||||
|
* @param content 内容
|
||||||
|
* @param isHtml 是否 Html内容
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
String send(Collection<String> tos, String subject, String content, boolean isHtml);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,343 +0,0 @@
|
|||||||
package org.opsli.modulars.test.web;
|
|
||||||
|
|
||||||
import cn.hutool.core.thread.ThreadUtil;
|
|
||||||
import cn.hutool.core.util.RandomUtil;
|
|
||||||
import cn.hutool.core.util.ReflectUtil;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.opsli.api.base.result.ResultVo;
|
|
||||||
import org.opsli.api.web.test.TestApi;
|
|
||||||
import org.opsli.api.wrapper.system.dict.DictWrapper;
|
|
||||||
import org.opsli.api.wrapper.test.TestModel;
|
|
||||||
import org.opsli.common.utils.WrapperUtil;
|
|
||||||
import org.opsli.core.base.controller.BaseRestController;
|
|
||||||
import org.opsli.core.cache.pushsub.enums.CacheHandleType;
|
|
||||||
import org.opsli.core.cache.pushsub.msgs.DictMsgFactory;
|
|
||||||
import org.opsli.core.persistence.Page;
|
|
||||||
import org.opsli.core.persistence.querybuilder.QueryBuilder;
|
|
||||||
import org.opsli.core.persistence.querybuilder.WebQueryBuilder;
|
|
||||||
import org.opsli.core.utils.DictUtil;
|
|
||||||
import org.opsli.modulars.test.entity.TestEntity;
|
|
||||||
import org.opsli.modulars.test.service.ITestService;
|
|
||||||
import org.opsli.plugins.mail.MailPlugin;
|
|
||||||
import org.opsli.plugins.mail.model.MailModel;
|
|
||||||
import org.opsli.plugins.redis.RedisLockPlugins;
|
|
||||||
import org.opsli.plugins.redis.RedisPlugin;
|
|
||||||
import org.opsli.plugins.redis.lock.RedisLock;
|
|
||||||
import org.opsli.plugins.redis.pushsub.entity.BaseSubMessage;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: opsli-boot
|
|
||||||
* @BelongsPackage: org.opsli.modulars.test.web
|
|
||||||
* @Author: Parker
|
|
||||||
* @CreateTime: 2020-09-13 17:40
|
|
||||||
* @Description: 测试类
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
//@ApiRestController("/test")
|
|
||||||
public class TestRestRestController extends BaseRestController<TestEntity, TestModel, ITestService>
|
|
||||||
implements TestApi {
|
|
||||||
|
|
||||||
|
|
||||||
private Random random = new Random();
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private MailPlugin mailPlugin;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisPlugin redisPlugin;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisLockPlugins redisLockPlugins;
|
|
||||||
|
|
||||||
@ApiOperation(value = "发送邮件", notes = "发送邮件")
|
|
||||||
@Override
|
|
||||||
public ResultVo<?> sendMail(){
|
|
||||||
MailModel mailModel = new MailModel();
|
|
||||||
mailModel.setTo("meet.carina@foxmail.com");
|
|
||||||
mailModel.setSubject("测试邮件功能");
|
|
||||||
mailModel.setContent("<h1>这是哪里呢?</h1><br><font color='red'>lalalalalalallalalalalal!!!!</font>");
|
|
||||||
mailPlugin.send(mailModel);
|
|
||||||
return ResultVo.success("发送邮件成功!!!!!!");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 Redis 订阅消息
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ApiOperation(value = "发送 Redis 订阅消息", notes = "发送 Redis 订阅消息")
|
|
||||||
@Override
|
|
||||||
public ResultVo<?> sendMsg(){
|
|
||||||
DictWrapper model = new DictWrapper();
|
|
||||||
|
|
||||||
BaseSubMessage msg = DictMsgFactory.createMsg(model, CacheHandleType.UPDATE);
|
|
||||||
|
|
||||||
boolean ret = redisPlugin.sendMessage(msg);
|
|
||||||
if(ret){
|
|
||||||
return ResultVo.success("发送订阅消息成功!!!!!!");
|
|
||||||
}
|
|
||||||
return ResultVo.error("发送订阅消息失败!!!!!!");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 Redis 测试
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ApiOperation(value = "发送 Redis 测试", notes = "发送 Redis 测试")
|
|
||||||
@Override
|
|
||||||
public ResultVo<?> redisTest(){
|
|
||||||
boolean ret = redisPlugin.put("opsli:test", "12315");
|
|
||||||
if(ret){
|
|
||||||
Object o = redisPlugin.get("opsli:test");
|
|
||||||
return ResultVo.success(o);
|
|
||||||
}
|
|
||||||
return ResultVo.error("发送订阅消息失败!!!!!!");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送 Redis 分布式锁
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ApiOperation(value = "发起 Redis 分布式锁", notes = "发起 Redis 分布式锁")
|
|
||||||
@Override
|
|
||||||
public ResultVo<RedisLock> testLock(){
|
|
||||||
|
|
||||||
// 锁凭证 redisLock 贯穿全程
|
|
||||||
RedisLock redisLock = new RedisLock();
|
|
||||||
redisLock.setLockName("aaabbb")
|
|
||||||
.setAcquireTimeOut(2000L)
|
|
||||||
.setLockTimeOut(10000L);
|
|
||||||
|
|
||||||
redisLock = redisLockPlugins.tryLock(redisLock);
|
|
||||||
|
|
||||||
if(redisLock == null){
|
|
||||||
ResultVo<RedisLock> error = ResultVo.error(500,"获得锁失败!!!!!!",redisLock);
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 睡眠 模拟线程执行过程
|
|
||||||
ThreadUtil.sleep(60, TimeUnit.SECONDS);
|
|
||||||
|
|
||||||
redisLockPlugins.unLock(redisLock);
|
|
||||||
ResultVo<RedisLock> success = ResultVo.success("获得锁成功!!!!!!",redisLock);
|
|
||||||
success.setData(redisLock);
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增数据
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ApiOperation(value = "新增数据", notes = "新增数据")
|
|
||||||
@Override
|
|
||||||
public ResultVo<TestModel> insert(TestModel model){
|
|
||||||
// 转化对象 处理 ApiModel 与 本地对象
|
|
||||||
|
|
||||||
model.setName("测试名称"+random.nextInt());
|
|
||||||
model.setRemark("测试备注"+random.nextInt());
|
|
||||||
|
|
||||||
// 调用新增方法
|
|
||||||
TestModel insert = IService.insert(model);
|
|
||||||
|
|
||||||
return ResultVo.success("新增成功",insert);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改数据
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ApiOperation(value = "修改数据", notes = "修改数据")
|
|
||||||
@Override
|
|
||||||
public ResultVo<TestModel> update(TestModel model){
|
|
||||||
// 转化对象 处理 ApiModel 与 本地对象
|
|
||||||
|
|
||||||
if(StringUtils.isEmpty(model.getId())){
|
|
||||||
model.setId(String.valueOf(random.nextLong()));
|
|
||||||
}
|
|
||||||
|
|
||||||
model.setName("修改名称"+random.nextInt());
|
|
||||||
model.setRemark("修改备注"+random.nextInt());
|
|
||||||
|
|
||||||
// 不需要做 锁状态处理,需要判断是否成功 能往下走的只能是成功
|
|
||||||
TestModel update = IService.update(model);
|
|
||||||
|
|
||||||
return ResultVo.success("修改成功",update);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查看对象
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ApiOperation(value = "查看对象", notes = "查看对象")
|
|
||||||
@Override
|
|
||||||
public ResultVo<TestModel> get(TestModel model){
|
|
||||||
return ResultVo.success(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除对象
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ApiOperation(value = "删除对象", notes = "删除对象")
|
|
||||||
@Override
|
|
||||||
public ResultVo<?> del(String id){
|
|
||||||
|
|
||||||
TestEntity testEntity1 = new TestEntity();
|
|
||||||
testEntity1.setId(id);
|
|
||||||
String[] ids = {id};
|
|
||||||
List<TestEntity> idList = new ArrayList<>();
|
|
||||||
idList.add(testEntity1);
|
|
||||||
|
|
||||||
|
|
||||||
//count = IService.delete(id);
|
|
||||||
|
|
||||||
//count = IService.delete(testEntity1);
|
|
||||||
|
|
||||||
//count = IService.deleteAll(idList);
|
|
||||||
|
|
||||||
IService.deleteAll(ids);
|
|
||||||
|
|
||||||
return ResultVo.error("删除对象成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除对象
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ApiOperation(value = "删除全部对象", notes = "删除全部对象")
|
|
||||||
@Override
|
|
||||||
public ResultVo<?> delAll(){
|
|
||||||
|
|
||||||
//IService.
|
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
//count = IService.delete(id);
|
|
||||||
|
|
||||||
//count = IService.delete(testEntity1);
|
|
||||||
|
|
||||||
//count = IService.deleteAll(ids);
|
|
||||||
|
|
||||||
//count = IService.deleteAll(idList);
|
|
||||||
|
|
||||||
return ResultVo.error("删除对象成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "查找一个集合", notes = "查找一个集合")
|
|
||||||
@Override
|
|
||||||
public ResultVo<List<TestModel>> findList(HttpServletRequest request) {
|
|
||||||
|
|
||||||
QueryBuilder<TestEntity> queryBuilder = new WebQueryBuilder<>(TestEntity.class, request.getParameterMap());
|
|
||||||
List<TestEntity> entitys = IService.findList(queryBuilder.build());
|
|
||||||
List<TestModel> models = WrapperUtil.transformInstance(entitys, TestModel.class);
|
|
||||||
|
|
||||||
return ResultVo.success(models);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "查找全部数据", notes = "查找全部数据")
|
|
||||||
@Override
|
|
||||||
public ResultVo<List<TestModel>> findAllList() {
|
|
||||||
List<TestEntity> list = IService.findAllList();
|
|
||||||
List<TestModel> testModels = WrapperUtil.transformInstance(list, TestModel.class);
|
|
||||||
return ResultVo.success(testModels);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "查询分页", notes = "查询分页")
|
|
||||||
@Override
|
|
||||||
public ResultVo<?> findPage(Integer pageNo, Integer pageSize, HttpServletRequest request) {
|
|
||||||
|
|
||||||
QueryBuilder<TestEntity> queryBuilder = new WebQueryBuilder<>(TestEntity.class, request.getParameterMap());
|
|
||||||
Page<TestEntity,TestModel> page = new Page<>(pageNo, pageSize);
|
|
||||||
page.setQueryWrapper(queryBuilder.build());
|
|
||||||
page = IService.findPage(page);
|
|
||||||
|
|
||||||
return ResultVo.success(page.getPageData());
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "导出Excel", notes = "导出Excel")
|
|
||||||
@Override
|
|
||||||
public void exportExcel(HttpServletRequest request, HttpServletResponse response) {
|
|
||||||
// 当前方法
|
|
||||||
Method method = ReflectUtil.getMethodByName(this.getClass(), "exportExcel");
|
|
||||||
QueryBuilder<TestEntity> queryBuilder = new WebQueryBuilder<>(entityClazz, request.getParameterMap());
|
|
||||||
super.excelExport("测试", queryBuilder.build(), response, method);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "导入Excel", notes = "导入Excel")
|
|
||||||
@Override
|
|
||||||
public ResultVo<?> importExcel(MultipartHttpServletRequest request) {
|
|
||||||
return super.importExcel(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "导出Excel模版", notes = "导出Excel模版")
|
|
||||||
@Override
|
|
||||||
public void importTemplate(HttpServletResponse response) {
|
|
||||||
// 当前方法
|
|
||||||
Method method = ReflectUtil.getMethodByName(this.getClass(), "importTemplate");
|
|
||||||
super.importTemplate("测试", response, method);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增数据
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@ApiOperation(value = "批量插入1000个随机新增数据", notes = "批量插入1000个随机新增数据")
|
|
||||||
@GetMapping("/insertAll")
|
|
||||||
public ResultVo<Boolean> insertAll(){
|
|
||||||
List<DictWrapper> testType = DictUtil.getDictList("testType");
|
|
||||||
|
|
||||||
List<TestModel> datas = new ArrayList<>();
|
|
||||||
// 转化对象 处理 ApiModel 与 本地对象
|
|
||||||
for (int i = 0; i < 1000; i++) {
|
|
||||||
int randomNum = RandomUtil.randomInt(0, testType.size());
|
|
||||||
TestModel model = new TestModel();
|
|
||||||
model.setName("测试名称"+random.nextInt());
|
|
||||||
model.setType(testType.get(randomNum).getDictValue());
|
|
||||||
model.setRemark("测试备注"+random.nextInt());
|
|
||||||
datas.add(model);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 调用新增方法
|
|
||||||
boolean b = IService.insertBatch(datas);
|
|
||||||
return ResultVo.success("新增成功",b);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ApiOperation(value = "获得字典 - By Name", notes = "获得字典 - By Name")
|
|
||||||
@GetMapping("/getDictByName")
|
|
||||||
public ResultVo<?> getDictByName(@RequestParam(name = "typeCode") String typeCode,
|
|
||||||
@RequestParam(name = "name") String name){
|
|
||||||
String value = DictUtil.getDictValueByName(typeCode, name, "我空了");
|
|
||||||
return ResultVo.success().setData(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "获得字典 - By Value", notes = "获得字典 - By Value")
|
|
||||||
@GetMapping("/getDictByValue")
|
|
||||||
public ResultVo<?> getDictByValue(@RequestParam(name = "typeCode") String typeCode,
|
|
||||||
@RequestParam(name = "value") String value){
|
|
||||||
String name = DictUtil.getDictNameByValue(typeCode, value, "我空了");
|
|
||||||
return ResultVo.success().setData(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>opsli-plugins</artifactId>
|
|
||||||
<groupId>org.opsliframework.boot</groupId>
|
|
||||||
<version>1.0.0</version>
|
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<artifactId>opsli-plugins-mail</artifactId>
|
|
||||||
<version>${project.parent.version}</version>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- 邮件服务 -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-mail</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
|
@ -1,35 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package org.opsli.plugins.mail;
|
|
||||||
|
|
||||||
import org.opsli.plugins.mail.model.MailModel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: opsli-boot
|
|
||||||
* @BelongsPackage: org.opsli.plugins.mail.handler
|
|
||||||
* @Author: Parker
|
|
||||||
* @CreateTime: 2020-09-13 18:51
|
|
||||||
* @Description: 邮件执行器
|
|
||||||
*/
|
|
||||||
public interface MailPlugin {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 发送邮件
|
|
||||||
* @param mailModel
|
|
||||||
*/
|
|
||||||
void send(MailModel mailModel);
|
|
||||||
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package org.opsli.plugins.mail.exception;
|
|
||||||
|
|
||||||
import org.opsli.common.base.msg.BaseMsg;
|
|
||||||
import org.opsli.common.exception.ServiceException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: opsli-boot
|
|
||||||
* @BelongsPackage: org.opsli.plugins.mail.exception
|
|
||||||
* @Author: Parker
|
|
||||||
* @CreateTime: 2020-09-13 18:44
|
|
||||||
* @Description: 邮件异常
|
|
||||||
*/
|
|
||||||
public class MailPluginException extends ServiceException {
|
|
||||||
|
|
||||||
public MailPluginException(Integer code, String errorMessage) {
|
|
||||||
super(code, errorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MailPluginException(BaseMsg msg) {
|
|
||||||
super(msg);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,78 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package org.opsli.plugins.mail.handler;
|
|
||||||
|
|
||||||
import cn.hutool.core.lang.Validator;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import org.opsli.common.exception.EmptyException;
|
|
||||||
import org.opsli.plugins.mail.MailPlugin;
|
|
||||||
import org.opsli.plugins.mail.exception.MailPluginException;
|
|
||||||
import org.opsli.plugins.mail.model.MailModel;
|
|
||||||
import org.opsli.plugins.mail.msg.MailMsg;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.mail.javamail.JavaMailSender;
|
|
||||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import javax.mail.internet.MimeMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: opsli-boot
|
|
||||||
* @BelongsPackage: org.opsli.plugins.mail.handler
|
|
||||||
* @Author: Parker
|
|
||||||
* @CreateTime: 2020-09-13 18:52
|
|
||||||
* @Description: 邮件执行器 实现类
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
public class MailPlugInImpl implements MailPlugin {
|
|
||||||
|
|
||||||
@Value("${spring.mail.username}")
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JavaMailSender javaMailSender;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void send(MailModel mailModel) {
|
|
||||||
try {
|
|
||||||
MimeMessage message= javaMailSender.createMimeMessage();
|
|
||||||
MimeMessageHelper helper = new MimeMessageHelper(message,true);
|
|
||||||
helper.setFrom(username);
|
|
||||||
helper.setTo(mailModel.getTo());
|
|
||||||
helper.setSubject(mailModel.getSubject());
|
|
||||||
helper.setText(mailModel.getContent(),true);
|
|
||||||
javaMailSender.send(message);
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("邮件发送异常:{}",e.getMessage());
|
|
||||||
throw new MailPluginException(MailMsg.EXCEPTION_UNKNOWN);
|
|
||||||
}
|
|
||||||
log.info("邮件发送 - 发送至:{} - 主题:{}", mailModel.getTo(),mailModel.getSubject());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 校验发送邮件的请求参数
|
|
||||||
*/
|
|
||||||
private void validationMailModel(MailModel mailModel) {
|
|
||||||
if(Validator.isEmpty(mailModel) ||
|
|
||||||
Validator.isEmpty(mailModel.getTo()) ||
|
|
||||||
Validator.isEmpty(mailModel.getSubject()) ||
|
|
||||||
Validator.isEmpty(mailModel.getContent())){
|
|
||||||
throw new EmptyException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,41 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package org.opsli.plugins.mail.model;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.ToString;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: opsli-boot
|
|
||||||
* @BelongsPackage: org.opsli.plugins.mail.model
|
|
||||||
* @Author: Parker
|
|
||||||
* @CreateTime: 2020-09-13 18:46
|
|
||||||
* @Description: 邮件传输类
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@ToString
|
|
||||||
public class MailModel {
|
|
||||||
|
|
||||||
/** 收件人 */
|
|
||||||
private String to;
|
|
||||||
|
|
||||||
/** 邮件主题 */
|
|
||||||
private String subject;
|
|
||||||
|
|
||||||
/** 邮件内容 */
|
|
||||||
private String content;
|
|
||||||
|
|
||||||
}
|
|
@ -1,51 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
|
|
||||||
* <p>
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
* <p>
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* <p>
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package org.opsli.plugins.mail.msg;
|
|
||||||
|
|
||||||
import org.opsli.common.base.msg.BaseMsg;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @BelongsProject: opsli-boot
|
|
||||||
* @BelongsPackage: org.opsli.plugins.mail.msg
|
|
||||||
* @Author: Parker
|
|
||||||
* @CreateTime: 2020-09-13 19:54
|
|
||||||
* @Description: 邮件消息
|
|
||||||
*/
|
|
||||||
public enum MailMsg implements BaseMsg {
|
|
||||||
|
|
||||||
/** 未知消息异常 */
|
|
||||||
EXCEPTION_UNKNOWN(90200,"邮件发送失败"),
|
|
||||||
;
|
|
||||||
|
|
||||||
|
|
||||||
private final int code;
|
|
||||||
private final String message;
|
|
||||||
|
|
||||||
MailMsg(int code,String message){
|
|
||||||
this.code = code;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Integer getCode() {
|
|
||||||
return this.code;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getMessage() {
|
|
||||||
return this.message;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue