|
@@ -10,9 +10,14 @@ import com.project.zcustom.service.unit.ILargeProjectService;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.core.io.FileSystemResource;
|
|
|
|
+import org.springframework.mail.javamail.JavaMailSender;
|
|
|
|
+import org.springframework.mail.javamail.MimeMessageHelper;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import javax.mail.internet.MimeMessage;
|
|
|
|
+import java.io.File;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Path;
|
|
@@ -34,6 +39,18 @@ public class PlatProjectCheckController extends BaseController {
|
|
private String uploadDirectory;
|
|
private String uploadDirectory;
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * 邮件发送接口
|
|
|
|
+ */
|
|
|
|
+ @Autowired
|
|
|
|
+ private JavaMailSender mailSender;
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 邮件发送人
|
|
|
|
+ */
|
|
|
|
+ @Value("${spring.mail.username}")
|
|
|
|
+ private String sender;
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 问题数量
|
|
* 问题数量
|
|
*/
|
|
*/
|
|
@GetMapping("/getIssueNum/{appOrg}")
|
|
@GetMapping("/getIssueNum/{appOrg}")
|
|
@@ -99,10 +116,61 @@ public class PlatProjectCheckController extends BaseController {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
return AjaxResult.error("文件上传失败");
|
|
return AjaxResult.error("文件上传失败");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ enclosureEmail(multipartFile, entity.getDescription() + "\n" + entity.getNeed());
|
|
}
|
|
}
|
|
return toAjax(largeIssueService.save(entity));
|
|
return toAjax(largeIssueService.save(entity));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public AjaxResult enclosureEmail(MultipartFile multipartFile, String content) {
|
|
|
|
+ //创建一个MINE消息
|
|
|
|
+ MimeMessage message = mailSender.createMimeMessage();
|
|
|
|
+ try {
|
|
|
|
+ MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
|
+ //谁发
|
|
|
|
+ helper.setFrom(sender);
|
|
|
|
+ //谁接收
|
|
|
|
+ helper.setTo("qwer20030522@163.com");
|
|
|
|
+ //邮件主题
|
|
|
|
+ helper.setSubject("问题上报");
|
|
|
|
+ //邮件内容 true 表示带有附件或html
|
|
|
|
+ helper.setText(content, true);
|
|
|
|
+ File multipartFileToFile = MultipartFileToFile(multipartFile);
|
|
|
|
+ if (multipartFileToFile == null) {
|
|
|
|
+ return AjaxResult.error("文件转换失败");
|
|
|
|
+ }
|
|
|
|
+ FileSystemResource file = new FileSystemResource(multipartFileToFile);
|
|
|
|
+ String filename = file.getFilename();
|
|
|
|
+ //添加附件
|
|
|
|
+ if (filename == null) {
|
|
|
|
+ return AjaxResult.error("文件名称获取失败");
|
|
|
|
+ }
|
|
|
|
+ helper.addAttachment(filename, file);
|
|
|
|
+ mailSender.send(message);
|
|
|
|
+ return AjaxResult.success("发送邮件成功");
|
|
|
|
+ } catch (javax.mail.MessagingException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return AjaxResult.error("发送邮件失败");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private File MultipartFileToFile(MultipartFile multiFile) {
|
|
|
|
+ // 获取文件名
|
|
|
|
+ String fileName = multiFile.getOriginalFilename();
|
|
|
|
+ // 获取文件后缀
|
|
|
|
+ String prefix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
+ // 若需要防止生成的临时文件重复,可以在文件名后添加随机码
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ File file = File.createTempFile(fileName, prefix);
|
|
|
|
+ multiFile.transferTo(file);
|
|
|
|
+ return file;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 本周检查计划
|
|
* 本周检查计划
|
|
* */
|
|
* */
|