Commit 6ee498e4 by chentianzhong

提一个版本

parent 854c3519
...@@ -147,6 +147,12 @@ ...@@ -147,6 +147,12 @@
<version>2.1.3</version> <version>2.1.3</version>
</dependency> </dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
......
...@@ -32,10 +32,10 @@ public class Swagger implements WebMvcConfigurer { ...@@ -32,10 +32,10 @@ public class Swagger implements WebMvcConfigurer {
@Bean @Bean
public Docket api() { public Docket api() {
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2)
.groupName("sealPlatfrom") .groupName("email")
.enable(enabled) //生产环境关闭 .enable(enabled) //生产环境关闭
.select() .select()
.apis(RequestHandlerSelectors.basePackage("com.zq.sealPlatform.controller")) .apis(RequestHandlerSelectors.basePackage("com.zq.email.controller"))
.paths(PathSelectors.any()) .paths(PathSelectors.any())
.build() .build()
.apiInfo(apiInfo()); .apiInfo(apiInfo());
......
package com.zq.email.controller; package com.zq.email.controller;
import com.zq.common.utils.AssertUtils;
import com.zq.common.vo.ResultVo;
import com.zq.email.service.IEmailContentService;
import com.zq.email.vo.EmailReqVo;
import com.zq.email.vo.EmailTaskVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
...@@ -13,8 +24,22 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -13,8 +24,22 @@ import org.springframework.web.bind.annotation.RestController;
* @author chentianzhong * @author chentianzhong
* @since 2023-03-06 * @since 2023-03-06
*/ */
@Api(tags = "邮件内容接口")
@RestController @RestController
@RequestMapping("/email/emailContent") @RequestMapping("/email/emailContent")
@Slf4j
@RequiredArgsConstructor
public class EmailContentController { public class EmailContentController {
private final IEmailContentService emailContentService;
@ApiOperation("设置任务邮件")
@PostMapping("setTaskEmail")
public ResultVo setTaskEmail(@RequestBody EmailTaskVo vo) {
AssertUtils.notEmpty(vo.getContentId(), "缺少参数: contentId");
AssertUtils.notNull(vo.getIsTask(), "缺少参数: isTask");
emailContentService.setTaskEmail(vo);
return ResultVo.success();
}
} }
...@@ -4,24 +4,27 @@ package com.zq.email.controller; ...@@ -4,24 +4,27 @@ package com.zq.email.controller;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
import com.zq.common.vo.ResultVo; import com.zq.common.vo.ResultVo;
import com.zq.email.constants.EmailConstant;
import com.zq.email.entity.EmailContent; import com.zq.email.entity.EmailContent;
import com.zq.email.entity.EmailPerson; import com.zq.email.entity.EmailPerson;
import com.zq.email.enums.EmailFolderEnum; import com.zq.email.enums.SearchRangeEnum;
import com.zq.email.enums.WhetherEnum;
import com.zq.email.service.IEmailContentService; import com.zq.email.service.IEmailContentService;
import com.zq.email.service.IEmailPersonService; import com.zq.email.service.IEmailPersonService;
import com.zq.email.vo.EmailDetailVo; import com.zq.email.vo.*;
import com.zq.email.vo.EmailEditVo;
import com.zq.email.vo.EmailReqVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.core.io.InputStreamResource;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;
/** /**
* <p> * <p>
...@@ -41,6 +44,13 @@ public class EmailController { ...@@ -41,6 +44,13 @@ public class EmailController {
private final IEmailPersonService emailPersonService; private final IEmailPersonService emailPersonService;
private final IEmailContentService emailContentService; private final IEmailContentService emailContentService;
@ApiOperation("查询范围")
@PostMapping("searchRange")
public ResultVo searchRange() {
return ResultVo.success(SearchRangeEnum.toList());
}
@ApiOperation("列表总数") @ApiOperation("列表总数")
@PostMapping("total") @PostMapping("total")
public ResultVo total(@RequestBody EmailReqVo vo) { public ResultVo total(@RequestBody EmailReqVo vo) {
...@@ -56,10 +66,12 @@ public class EmailController { ...@@ -56,10 +66,12 @@ public class EmailController {
@ApiOperation("写邮件") @ApiOperation("写邮件")
@PostMapping("edit") @PostMapping("edit")
public ResultVo edit(@RequestBody EmailEditVo vo) { public ResultVo edit(EmailEditVo vo) {
AssertUtils.hasText(vo.getTitle(), "缺少参数:title"); AssertUtils.hasText(vo.getTitle(), "缺少参数:title");
AssertUtils.notNull(vo.getIsSend(), "缺少参数: isSend"); AssertUtils.notNull(vo.getIsSend(), "缺少参数: isSend");
AssertUtils.isTrue(CollectionUtil.isNotEmpty(vo.getReceiver()) || CollectionUtil.isNotEmpty(vo.getReceiver()), "缺少参数:receiver和 receiveDeptList"); log.info("vo.getReceiver()"+vo.getReceiver());
log.info("vo.getReceiveDeptList()"+vo.getReceiveDeptList());
AssertUtils.isTrue(CollectionUtil.isNotEmpty(vo.getReceiver()) || CollectionUtil.isNotEmpty(vo.getReceiveDeptList()), "缺少参数:receiver和 receiveDeptList");
emailPersonService.emailEditVo(vo); emailPersonService.emailEditVo(vo);
return ResultVo.success(); return ResultVo.success();
} }
...@@ -67,15 +79,96 @@ public class EmailController { ...@@ -67,15 +79,96 @@ public class EmailController {
@ApiOperation("邮件详情,这个接口如果前端从列表能获取到显示就不用调用") @ApiOperation("邮件详情,这个接口如果前端从列表能获取到显示就不用调用")
@PostMapping("detail") @PostMapping("detail")
public ResultVo detail(@RequestBody EmailDetailVo vo) { public ResultVo detail(@RequestBody EmailDetailVo vo) {
AssertUtils.notNull(vo.getPersonId(), "缺少参数:id"); AssertUtils.notNull(vo.getPersonId(), "缺少参数:personId");
AssertUtils.notNull(vo.getContentId(), "缺少参数:contentId");
EmailPerson emailPerson = emailPersonService.getById(vo.getPersonId()); EmailPerson emailPerson = emailPersonService.getById(vo.getPersonId());
AssertUtils.notNull(emailPerson, "获取邮件对应人员信息失败"); AssertUtils.notNull(emailPerson, "获取邮件对应人员信息失败");
AssertUtils.isTrue(emailPerson.getEmailContentId() == vo.getContentId() , "contentId对应不一致"+emailPerson.getEmailContentId() +":"+vo.getContentId());
EmailContent content = emailContentService.getById(emailPerson.getEmailContentId()); EmailContent content = emailContentService.getById(emailPerson.getEmailContentId());
AssertUtils.notNull(content, "获取邮件内容失败"); AssertUtils.notNull(content, "获取邮件内容失败");
emailPerson.setEmailContent(content); emailPerson.setEmailContent(content);
return ResultVo.success(emailPerson); return ResultVo.success(emailPerson);
} }
// @ApiOperation("回复")
// @PostMapping("reply")
// public ResultVo reply(@RequestBody EmailEditVo vo) {
// AssertUtils.hasText(vo.getTitle(), "缺少参数:title");
// AssertUtils.notNull(vo.getIsSend(), "缺少参数: isSend");
// AssertUtils.isTrue(CollectionUtil.isNotEmpty(vo.getReceiver()) || CollectionUtil.isNotEmpty(vo.getReceiver()), "缺少参数:receiver和 receiveDeptList");
// emailPersonService.emailEditVo(vo);
// return ResultVo.success();
// }
//
// @ApiOperation("转发")
// @PostMapping("forward")
// public ResultVo forward(@RequestBody EmailEditVo vo) {
// AssertUtils.hasText(vo.getTitle(), "缺少参数:title");
// AssertUtils.notNull(vo.getIsSend(), "缺少参数: isSend");
// AssertUtils.isTrue(CollectionUtil.isNotEmpty(vo.getReceiver()) || CollectionUtil.isNotEmpty(vo.getReceiver()), "缺少参数:receiver和 receiveDeptList");
// emailPersonService.emailEditVo(vo);
// return ResultVo.success();
// }
@ApiOperation("收件箱彻底删除")
@PostMapping("delete")
public ResultVo delete(@RequestBody List<Long> personIds) {
AssertUtils.notEmpty(personIds, "缺少参数:personIds");
emailPersonService.removeByIds(personIds);
return ResultVo.success();
}
@ApiOperation("删除所有收件人已删除邮件")
@PostMapping("deleteAllReceiverDelete")
public ResultVo deleteAllReceiverDelete() {
emailPersonService.deleteAllReceiverDelete();
return ResultVo.success();
}
@ApiOperation("删除所有收件人未读邮件")
@PostMapping("deleteAllReceiverUnread")
public ResultVo deleteAllReceiverUnread() {
emailPersonService.deleteAllReceiverUnread();
return ResultVo.success();
}
@ApiOperation("导出eml格式邮件")
@PostMapping("/emlFile")
public void emlFile(HttpServletResponse response, @RequestParam(value = "contentId", required = true ) Long contentId) throws Exception {
MimeMessage mimeMessage = emailPersonService.emlFile(contentId);
response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment;filename=" + mimeMessage.getSubject()+".eml");//浏览器上提示下载时默认的文件名
ServletOutputStream out = response.getOutputStream();
mimeMessage.writeTo(out);
out.close();
out.flush();
}
@ApiOperation("上一封")
@PostMapping("lastEmail")
public ResultVo lastEmail(@RequestBody EmailLastAndAfterReqVo vo) {
AssertUtils.notNull(vo.getFolderId(), "缺少参数:folderId");
EmailPerson person = this.emailPersonService.lastAndAfterEmail(vo, 0);
AssertUtils.notNull(person, "没有上一封了");
return ResultVo.success(person);
}
@ApiOperation("下一封")
@PostMapping("afterEmail")
public ResultVo afterEmail(@RequestBody EmailLastAndAfterReqVo vo) {
AssertUtils.notNull(vo.getFolderId(), "缺少参数:folderId");
EmailPerson person = this.emailPersonService.lastAndAfterEmail(vo, 0);
AssertUtils.notNull(person, "没有下一封了");
return ResultVo.success(person);
}
......
...@@ -40,6 +40,17 @@ public class EmailFolderController { ...@@ -40,6 +40,17 @@ public class EmailFolderController {
return ResultVo.success(emailFolderService.selfFolderList(adminContext.getUserId())); return ResultVo.success(emailFolderService.selfFolderList(adminContext.getUserId()));
} }
@ApiOperation("获取自定义文件夹")
@PostMapping("otherFolderList")
public ResultVo otherFolderList() {
OnlineUserDto adminContext = TokenUtils.getAdminContext();
AssertUtils.notNull(adminContext, "登录已失效,请重新登录后再次尝试!");
return ResultVo.success(this.emailFolderService.lambdaQuery()
.eq(EmailFolder::getUserId, adminContext.getUserId())
.orderByAsc(EmailFolder::getSort).list());
}
@ApiOperation("编辑个人文件夹") @ApiOperation("编辑个人文件夹")
@PostMapping("edit") @PostMapping("edit")
public ResultVo edit(@RequestBody EmailFolderVo vo) { public ResultVo edit(@RequestBody EmailFolderVo vo) {
......
...@@ -3,18 +3,19 @@ package com.zq.email.controller; ...@@ -3,18 +3,19 @@ package com.zq.email.controller;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
import com.zq.common.vo.ResultVo; import com.zq.common.vo.ResultVo;
import com.zq.email.entity.EmailPerson;
import com.zq.email.enums.WhetherEnum;
import com.zq.email.service.IEmailPersonService; import com.zq.email.service.IEmailPersonService;
import com.zq.email.vo.EmailDetailVo; import com.zq.email.vo.EmailDetailVo;
import com.zq.email.vo.EmailFolderMoveVo; import com.zq.email.vo.EmailFolderMoveVo;
import com.zq.email.vo.EmailReadVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import java.util.List;
/** /**
* <p> * <p>
...@@ -42,10 +43,46 @@ public class EmailPersonController { ...@@ -42,10 +43,46 @@ public class EmailPersonController {
@ApiOperation("邮件收件人详情") @ApiOperation("邮件收件人详情")
@PostMapping("byContentId") @PostMapping("findReceiverByContentId")
public ResultVo byContentId(@RequestBody EmailDetailVo vo) { public ResultVo findReceiverByContentId(@RequestBody EmailDetailVo vo) {
AssertUtils.notNull(vo.getContentId(), "缺少参数:contentId"); AssertUtils.notNull(vo.getContentId(), "缺少参数:contentId");
return ResultVo.success(emailPersonService.findByContentId(vo.getContentId())); return ResultVo.success(emailPersonService.findReceiverByContentId(vo.getContentId()));
} }
@ApiOperation("邮件收件部门")
@PostMapping("findReceiveDeptByContentId")
public ResultVo findReceiveDeptByContentId(@RequestBody EmailDetailVo vo) {
AssertUtils.notNull(vo.getContentId(), "缺少参数:contentId");
return ResultVo.success(emailPersonService.findReceiveDeptByContentId(vo.getContentId()));
}
@ApiOperation("设置为已读或未读")
@PostMapping("readEmail")
public ResultVo readEmail(@RequestBody EmailReadVo vo) {
AssertUtils.notEmpty(vo.getPersonIdList(), "缺少参数:personIdList");
AssertUtils.notNull(vo.getIsRead(), "缺少参数:isSend");
this.emailPersonService.readEmail(vo);
return ResultVo.success();
}
@ApiOperation("全部设置已读")
@PostMapping("readAllEmails")
public ResultVo readAllEmails(@RequestParam(value = "folderId", required = true)Long folderId) {
this.emailPersonService.readAllEmails(folderId);
return ResultVo.success();
}
@ApiOperation("删除已读(把已读放入回收站)")
@PostMapping("readToBin")
public ResultVo readToBin(@RequestParam(value = "folderId", required = true)Long folderId) {
this.emailPersonService.readToBin(folderId);
return ResultVo.success();
}
} }
package com.zq.email.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class DeptSimpleDto {
@ApiModelProperty("部门名")
private String name;
@ApiModelProperty("部门id")
private Long deptId;
@ApiModelProperty("部门全称(便于区分同名)")
private String deptWholeName;
}
...@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.IdType; ...@@ -5,6 +5,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable; import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.*; import lombok.*;
...@@ -41,6 +43,7 @@ public class EmailAttach implements Serializable { ...@@ -41,6 +43,7 @@ public class EmailAttach implements Serializable {
private String downloadPath; private String downloadPath;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime sendTime; private LocalDateTime sendTime;
......
...@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.IdType; ...@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable; import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
...@@ -42,6 +44,7 @@ public class EmailContent implements Serializable { ...@@ -42,6 +44,7 @@ public class EmailContent implements Serializable {
private String sendUserName; private String sendUserName;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime sendTime; private LocalDateTime sendTime;
private Integer smsRemind; private Integer smsRemind;
......
...@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.IdType; ...@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable; import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.*; import lombok.*;
...@@ -38,6 +40,8 @@ public class EmailPerson implements Serializable { ...@@ -38,6 +40,8 @@ public class EmailPerson implements Serializable {
private String userEmail; private String userEmail;
private String userName;
private Long deptId; private Long deptId;
private String deptName; private String deptName;
...@@ -46,6 +50,7 @@ public class EmailPerson implements Serializable { ...@@ -46,6 +50,7 @@ public class EmailPerson implements Serializable {
private Integer personType; private Integer personType;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime sendTime; private LocalDateTime sendTime;
private Long folderId; private Long folderId;
......
...@@ -13,11 +13,11 @@ public enum EmailFolderEnum { ...@@ -13,11 +13,11 @@ public enum EmailFolderEnum {
FOLDER_INBOX(1, "收件箱"), FOLDER_INBOX(1, "收件箱"),
FOLDER_DEPT_INBOX(2, "部门邮件"), FOLDER_DEPT_INBOX(2, "部门邮件"),
FOLDER_OUTBOX(3, "发件箱"), FOLDER_OUTBOX(3, "草稿箱"),
FOLDER_ALREADY_SEND(4, "已发送"), FOLDER_ALREADY_SEND(4, "已发送"),
FOLDER_ALREADY_DELETE(5, "已删除"), FOLDER_ALREADY_DELETE(5, "回收站"),
FOLDER_OTHER(6, "其他文件夹"), FOLDER_OTHER(6, "其他文件夹"),
FOLDER_LABEL(7, "邮件标签"), //FOLDER_LABEL(7, "邮件标签"),
; ;
private Integer key; private Integer key;
...@@ -56,7 +56,7 @@ public enum EmailFolderEnum { ...@@ -56,7 +56,7 @@ public enum EmailFolderEnum {
List<EmailFolderDto> list = new ArrayList<>(); List<EmailFolderDto> list = new ArrayList<>();
for (EmailFolderEnum emailFolderEnum : EmailFolderEnum.values()) { for (EmailFolderEnum emailFolderEnum : EmailFolderEnum.values()) {
EmailFolderDto folder = EmailFolderDto.builder() EmailFolderDto folder = EmailFolderDto.builder()
.folderId(emailFolderEnum.getKey()) .folderId(emailFolderEnum.getKey().longValue())
.folderName(emailFolderEnum.getValue()) .folderName(emailFolderEnum.getValue())
.sort(emailFolderEnum.getKey()) .sort(emailFolderEnum.getKey())
.build(); .build();
......
package com.zq.email.enums; package com.zq.email.enums;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
import com.zq.email.dto.EmailFolderDto;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/** /**
* 是否 * 是否
...@@ -55,6 +61,17 @@ public enum SearchRangeEnum { ...@@ -55,6 +61,17 @@ public enum SearchRangeEnum {
return null; return null;
} }
public static List<Map<Integer, String>> toList(){
List<Map<Integer, String>> list = new ArrayList<>();
for (SearchRangeEnum searchRangeEnum : SearchRangeEnum.values()) {
Map<Integer, String> map = new LinkedHashMap<>();
map.put(searchRangeEnum.getKey(), searchRangeEnum.getValue());
list.add(map);
}
return list;
}
public Integer getKey() { public Integer getKey() {
return key; return key;
} }
......
...@@ -5,6 +5,7 @@ import com.zq.common.annotation.Log; ...@@ -5,6 +5,7 @@ import com.zq.common.annotation.Log;
import com.zq.common.vo.CustomerUserVo; import com.zq.common.vo.CustomerUserVo;
import com.zq.common.vo.OnlineUserDto; import com.zq.common.vo.OnlineUserDto;
import com.zq.common.vo.ResultVo; import com.zq.common.vo.ResultVo;
import com.zq.email.dto.DeptSimpleDto;
import com.zq.email.feign.fallback.AdminFeignFallbackFactory; import com.zq.email.feign.fallback.AdminFeignFallbackFactory;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
...@@ -31,4 +32,10 @@ public interface AdminFeignClient { ...@@ -31,4 +32,10 @@ public interface AdminFeignClient {
@GetMapping(value = "/users/getUserByDeptId/{deptId}") @GetMapping(value = "/users/getUserByDeptId/{deptId}")
ResultVo<List<CustomerUserVo>> getUserByDeptId(@PathVariable(value="deptId") Long deptId); ResultVo<List<CustomerUserVo>> getUserByDeptId(@PathVariable(value="deptId") Long deptId);
@Log("根据部门id查询部门信息")
@ApiOperation("根据部门id查询部门信息")
@AnonymousAccess
@GetMapping("/dept/getByDeptId/{deptId}")
ResultVo<DeptSimpleDto> getByDeptId(@PathVariable Long deptId);
} }
...@@ -3,6 +3,7 @@ package com.zq.email.feign.fallback; ...@@ -3,6 +3,7 @@ package com.zq.email.feign.fallback;
import com.zq.common.vo.CustomerUserVo; import com.zq.common.vo.CustomerUserVo;
import com.zq.common.vo.OnlineUserDto; import com.zq.common.vo.OnlineUserDto;
import com.zq.common.vo.ResultVo; import com.zq.common.vo.ResultVo;
import com.zq.email.dto.DeptSimpleDto;
import com.zq.email.feign.AdminFeignClient; import com.zq.email.feign.AdminFeignClient;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -43,6 +44,11 @@ public class AdminFeignFallbackFactory implements FallbackFactory<AdminFeignClie ...@@ -43,6 +44,11 @@ public class AdminFeignFallbackFactory implements FallbackFactory<AdminFeignClie
return null; return null;
} }
@Override
public ResultVo<DeptSimpleDto> getByDeptId(Long deptId) {
return null;
}
}; };
} }
......
...@@ -3,6 +3,7 @@ package com.zq.email.service; ...@@ -3,6 +3,7 @@ package com.zq.email.service;
import com.zq.email.entity.EmailAttach; import com.zq.email.entity.EmailAttach;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.zq.email.entity.EmailContent; import com.zq.email.entity.EmailContent;
import com.zq.email.vo.EmailEditVo;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.List; import java.util.List;
...@@ -17,7 +18,7 @@ import java.util.List; ...@@ -17,7 +18,7 @@ import java.util.List;
*/ */
public interface IEmailAttachService extends IService<EmailAttach> { public interface IEmailAttachService extends IService<EmailAttach> {
void saveAttach(List<MultipartFile> fileIdList, EmailContent content); void saveAttach(EmailEditVo vo, EmailContent content);
List<EmailAttach> findByContentId(Long contentId); List<EmailAttach> findByContentId(Long contentId);
......
...@@ -4,6 +4,7 @@ import com.zq.common.vo.OnlineUserDto; ...@@ -4,6 +4,7 @@ import com.zq.common.vo.OnlineUserDto;
import com.zq.email.entity.EmailContent; import com.zq.email.entity.EmailContent;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.zq.email.vo.EmailEditVo; import com.zq.email.vo.EmailEditVo;
import com.zq.email.vo.EmailTaskVo;
/** /**
* <p> * <p>
...@@ -16,4 +17,6 @@ import com.zq.email.vo.EmailEditVo; ...@@ -16,4 +17,6 @@ import com.zq.email.vo.EmailEditVo;
public interface IEmailContentService extends IService<EmailContent> { public interface IEmailContentService extends IService<EmailContent> {
EmailContent saveContent(EmailEditVo vo, OnlineUserDto adminContext); EmailContent saveContent(EmailEditVo vo, OnlineUserDto adminContext);
void setTaskEmail(EmailTaskVo vo);
} }
package com.zq.email.service; package com.zq.email.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zq.email.dto.DeptDto;
import com.zq.email.dto.DeptSimpleDto;
import com.zq.email.entity.EmailPerson; import com.zq.email.entity.EmailPerson;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.zq.email.vo.EmailEditVo; import com.zq.email.vo.*;
import com.zq.email.vo.EmailFolderMoveVo; import org.springframework.core.io.InputStreamResource;
import com.zq.email.vo.EmailReqVo; import org.springframework.http.ResponseEntity;
import javax.mail.internet.MimeMessage;
import java.util.List; import java.util.List;
/** /**
...@@ -27,5 +30,22 @@ public interface IEmailPersonService extends IService<EmailPerson> { ...@@ -27,5 +30,22 @@ public interface IEmailPersonService extends IService<EmailPerson> {
void moveEmailFolder(EmailFolderMoveVo vo); void moveEmailFolder(EmailFolderMoveVo vo);
List<EmailPerson> findByContentId(Long contentId); List<EmailPerson> findReceiverByContentId(Long contentId);
List<DeptSimpleDto> findReceiveDeptByContentId(Long contentId);
void readAllEmails(Long folderId);
void readEmail(EmailReadVo vo);
void readToBin(Long folderId);
MimeMessage emlFile(Long contentId);
void deleteAllReceiverDelete();
void deleteAllReceiverUnread();
// 0上一封 1下一封
EmailPerson lastAndAfterEmail(EmailLastAndAfterReqVo vo, Integer type);
} }
...@@ -12,11 +12,10 @@ import com.zq.email.feign.FileFeignClient; ...@@ -12,11 +12,10 @@ import com.zq.email.feign.FileFeignClient;
import com.zq.email.mapper.EmailAttachMapper; import com.zq.email.mapper.EmailAttachMapper;
import com.zq.email.service.IEmailAttachService; import com.zq.email.service.IEmailAttachService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zq.email.vo.EmailEditVo;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import sun.tools.jstat.Token;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -36,32 +35,42 @@ public class EmailAttachServiceImpl extends ServiceImpl<EmailAttachMapper, Email ...@@ -36,32 +35,42 @@ public class EmailAttachServiceImpl extends ServiceImpl<EmailAttachMapper, Email
private final FileFeignClient fileFeignClient; private final FileFeignClient fileFeignClient;
@Override @Override
public void saveAttach(List<MultipartFile> fileIdList, EmailContent content) { public void saveAttach(EmailEditVo vo, EmailContent content) {
List<EmailAttach> list = new ArrayList<>();
if(CollectionUtil.isNotEmpty(vo.getFileIds())) {
//拿到旧附件
list = this.lambdaQuery().eq(EmailAttach::getEmailContentId, content.getId()).in(EmailAttach::getAttachId, vo.getFileIds()).list();
for (EmailAttach emailAttach : list) {
emailAttach.setId(null);
}
}
//先检查旧附件 //先检查旧附件
this.lambdaUpdate().eq(EmailAttach::getEmailContentId, content.getId()).remove(); this.lambdaUpdate().eq(EmailAttach::getEmailContentId, content.getId()).remove();
ResultVo<UploadFileListRespVo> uploadFileListRespVoResultVo = fileFeignClient.uploadFileList(fileIdList.toArray(new MultipartFile[fileIdList.size()]), if(CollectionUtil.isNotEmpty(vo.getFileList())) {
EmailConstant.SYSTEM_TAG, ResultVo<UploadFileListRespVo> uploadFileListRespVoResultVo = fileFeignClient.uploadFileList(vo.getFileList().toArray(new MultipartFile[vo.getFileList().size()]),
content.getSendUserId(), EmailConstant.SYSTEM_TAG,
String.valueOf(content.getId())); content.getSendUserId(),
String.valueOf(content.getId()));
AssertUtils.isTrue(uploadFileListRespVoResultVo.isSuccess(), "上传文件失败"); AssertUtils.isTrue(uploadFileListRespVoResultVo.isSuccess(), "上传文件失败");
UploadFileListRespVo data = uploadFileListRespVoResultVo.getData(); UploadFileListRespVo data = uploadFileListRespVoResultVo.getData();
AssertUtils.isTrue(data!=null && CollectionUtil.isNotEmpty(data.getUploadFileRespVos()), "上传文件失败,结果为空"); AssertUtils.isTrue(data != null && CollectionUtil.isNotEmpty(data.getUploadFileRespVos()), "上传文件失败,结果为空");
List<EmailAttach> attachList = new ArrayList<>(); for (UploadFileRespVo uploadFileRespVo : data.getUploadFileRespVos()) {
for (UploadFileRespVo uploadFileRespVo : data.getUploadFileRespVos()) { EmailAttach emailAttach = EmailAttach.builder()
EmailAttach emailAttach = EmailAttach.builder() .emailContentId(content.getId())
.emailContentId(content.getId()) .attachId(uploadFileRespVo.getId())
.attachId(uploadFileRespVo.getId()) .attachName(uploadFileRespVo.getFileName())
.attachName(uploadFileRespVo.getFileName()) .attachSize(uploadFileRespVo.getSize())
.attachSize(uploadFileRespVo.getSize()) .downloadPath(uploadFileRespVo.getDownloadPath())
.downloadPath(uploadFileRespVo.getDownloadPath()) .sendTime(content.getSendTime())
.sendTime(content.getSendTime()) .build();
.build(); list.add(emailAttach);
attachList.add(emailAttach); }
} }
this.saveBatch(attachList); this.saveBatch(list);
} }
@Override @Override
......
package com.zq.email.service.impl; package com.zq.email.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ArrayUtil;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
import com.zq.common.vo.OnlineUserDto; import com.zq.common.vo.OnlineUserDto;
import com.zq.email.entity.EmailContent; import com.zq.email.entity.EmailContent;
...@@ -10,6 +11,8 @@ import com.zq.email.mapper.EmailContentMapper; ...@@ -10,6 +11,8 @@ import com.zq.email.mapper.EmailContentMapper;
import com.zq.email.service.IEmailContentService; import com.zq.email.service.IEmailContentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zq.email.vo.EmailEditVo; import com.zq.email.vo.EmailEditVo;
import com.zq.email.vo.EmailTaskVo;
import net.bytebuddy.matcher.CollectionErasureMatcher;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -56,9 +59,18 @@ public class EmailContentServiceImpl extends ServiceImpl<EmailContentMapper, Ema ...@@ -56,9 +59,18 @@ public class EmailContentServiceImpl extends ServiceImpl<EmailContentMapper, Ema
} }
if (CollectionUtil.isNotEmpty(vo.getReceiveDeptList())){ if (CollectionUtil.isNotEmpty(vo.getReceiveDeptList())){
content.setDeptList(vo.getReceiveDeptList().toString()); StringBuffer sb = new StringBuffer();
for (Long deptId : vo.getReceiveDeptList()) {
sb.append(deptId).append(",");
}
content.setDeptList(sb.toString());
} }
this.saveOrUpdate(content); this.saveOrUpdate(content);
return content; return content;
} }
@Override
public void setTaskEmail(EmailTaskVo vo) {
this.lambdaUpdate().in(EmailContent::getId, vo.getContentId()).set(EmailContent::getIsTask, vo.getIsTask()).update();
}
} }
...@@ -43,7 +43,7 @@ public class EmailFolderServiceImpl extends ServiceImpl<EmailFolderMapper, Email ...@@ -43,7 +43,7 @@ public class EmailFolderServiceImpl extends ServiceImpl<EmailFolderMapper, Email
List<EmailFolderDto> list = EmailFolderEnum.toList(); List<EmailFolderDto> list = EmailFolderEnum.toList();
if (CollectionUtil.isNotEmpty(folderDtoList)){ if (CollectionUtil.isNotEmpty(folderDtoList)){
for (EmailFolderDto folderDto : list) { for (EmailFolderDto folderDto : list) {
if (folderDto.getFolderId().equals(EmailFolderEnum.FOLDER_OTHER.getKey())){ if (folderDto.getFolderId().intValue() == EmailFolderEnum.FOLDER_OTHER.getKey().intValue()){
folderDto.setChildren(folderDtoList); folderDto.setChildren(folderDtoList);
} }
} }
......
package com.zq.email.service.impl; package com.zq.email.service.impl;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileWriter;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zq.common.utils.AssertUtils; import com.zq.common.utils.AssertUtils;
...@@ -9,7 +15,11 @@ import com.zq.common.vo.CustomerUserVo; ...@@ -9,7 +15,11 @@ import com.zq.common.vo.CustomerUserVo;
import com.zq.common.vo.OnlineUserDto; import com.zq.common.vo.OnlineUserDto;
import com.zq.common.vo.ResultVo; import com.zq.common.vo.ResultVo;
import com.zq.email.constants.EmailConstant; import com.zq.email.constants.EmailConstant;
import com.zq.email.dto.DeptDto;
import com.zq.email.dto.DeptSimpleDto;
import com.zq.email.entity.EmailAttach;
import com.zq.email.entity.EmailContent; import com.zq.email.entity.EmailContent;
import com.zq.email.entity.EmailFolder;
import com.zq.email.entity.EmailPerson; import com.zq.email.entity.EmailPerson;
import com.zq.email.enums.EmailFolderEnum; import com.zq.email.enums.EmailFolderEnum;
import com.zq.email.enums.WhetherEnum; import com.zq.email.enums.WhetherEnum;
...@@ -20,15 +30,38 @@ import com.zq.email.service.IEmailContentService; ...@@ -20,15 +30,38 @@ import com.zq.email.service.IEmailContentService;
import com.zq.email.service.IEmailPersonService; import com.zq.email.service.IEmailPersonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zq.email.utils.DateUtils; import com.zq.email.utils.DateUtils;
import com.zq.email.vo.EmailEditVo; import com.zq.email.utils.EmailUtil;
import com.zq.email.vo.EmailFolderMoveVo; import com.zq.email.vo.*;
import com.zq.email.vo.EmailReqVo;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.codec.binary.Base64;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.activation.URLDataSource;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Properties;
/** /**
* <p> * <p>
...@@ -42,6 +75,11 @@ import java.util.List; ...@@ -42,6 +75,11 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, EmailPerson> implements IEmailPersonService { public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, EmailPerson> implements IEmailPersonService {
private final static String DATE_FORMAT = "/yyyyMM/dd/";
private final static String DATE_FORMAT_WIN = "\\yyyyMM\\dd\\";
private final static String FILE_SAVE_PATH = "/data/file/oa-email/";
private final static String FILE_SAVE_PATH_WIN = "D:\\file\\oa-email\\";
private final IEmailContentService emailContentService; private final IEmailContentService emailContentService;
private final IEmailAttachService emailAttachService; private final IEmailAttachService emailAttachService;
private final AdminFeignClient adminFeignClient; private final AdminFeignClient adminFeignClient;
...@@ -65,17 +103,19 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email ...@@ -65,17 +103,19 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
AssertUtils.notNull(adminContext, "登录已失效,请重新登录后再次尝试!"); AssertUtils.notNull(adminContext, "登录已失效,请重新登录后再次尝试!");
Page<EmailPerson> page = new Page<>(vo.getPage(), vo.getSize()); Page<EmailPerson> page = new Page<>(vo.getPage(), vo.getSize());
page.setSearchCount(false).setOptimizeCountSql(false); page.setSearchCount(false).setOptimizeCountSql(false);
LambdaQueryChainWrapper<EmailPerson> eq = this.lambdaQuery()
.eq(EmailPerson::getUserId, adminContext.getUserId()) LambdaQueryWrapper<EmailPerson> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(EmailPerson::getUserId, adminContext.getUserId())
.eq(vo.getFolderId()!=null, EmailPerson::getFolderId, vo.getFolderId()) .eq(vo.getFolderId()!=null, EmailPerson::getFolderId, vo.getFolderId())
.eq(vo.getPersonType()!=null, EmailPerson::getPersonType, vo.getPersonType()) .eq(vo.getPersonType()!=null, EmailPerson::getPersonType, vo.getPersonType())
.eq(vo.getIsPerson()!=null, EmailPerson::getIsPerson, vo.getIsPerson()) .eq(vo.getIsPerson()!=null, EmailPerson::getIsPerson, vo.getIsPerson())
.eq(vo.getIsSend()!=null, EmailPerson::getIsSend, vo.getIsSend()); .eq(vo.getIsSend()!=null, EmailPerson::getIsSend, vo.getIsSend());
if (DateUtils.getRangeStart(vo.getSearchRange()) !=null){ if (DateUtils.getRangeStart(vo.getSearchRange()) !=null){
eq.ge(EmailPerson::getSendTime, DateUtils.getRangeStart(vo.getSearchRange())); queryWrapper.ge(EmailPerson::getSendTime, DateUtils.getRangeStart(vo.getSearchRange()));
eq.le(EmailPerson::getSendTime, LocalDateTime.now()); queryWrapper.le(EmailPerson::getSendTime, LocalDateTime.now());
} }
page = this.page(page, eq); page = this.page(page, queryWrapper);
if (page!=null && CollectionUtil.isNotEmpty(page.getRecords())){ if (page!=null && CollectionUtil.isNotEmpty(page.getRecords())){
for (EmailPerson record : page.getRecords()) { for (EmailPerson record : page.getRecords()) {
record.setEmailContent(this.emailContentService.getById(record.getEmailContentId())); record.setEmailContent(this.emailContentService.getById(record.getEmailContentId()));
...@@ -92,9 +132,7 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email ...@@ -92,9 +132,7 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
EmailContent content = emailContentService.saveContent(vo, adminContext); EmailContent content = emailContentService.saveContent(vo, adminContext);
if (content !=null) { if (content !=null) {
//附件 //附件
if (CollectionUtil.isNotEmpty(vo.getFileList())) { emailAttachService.saveAttach(vo, content);
emailAttachService.saveAttach(vo.getFileList(), content);
}
//person,先删除 //person,先删除
this.lambdaUpdate().eq(EmailPerson::getEmailContentId, content.getId()).remove(); this.lambdaUpdate().eq(EmailPerson::getEmailContentId, content.getId()).remove();
//发件人 //发件人
...@@ -124,14 +162,166 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email ...@@ -124,14 +162,166 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
} }
@Override @Override
public List<EmailPerson> findByContentId(Long contentId) { public List<EmailPerson> findReceiverByContentId(Long contentId) {
return this.lambdaQuery().eq(EmailPerson::getEmailContentId, contentId).orderByAsc(EmailPerson::getId).list(); return this.lambdaQuery()
.eq(EmailPerson::getEmailContentId, contentId)
.eq(EmailPerson::getPersonType, EmailConstant.TYPE_EMAIL_RECEIVE)
.orderByAsc(EmailPerson::getId).list();
}
@Override
public List<DeptSimpleDto> findReceiveDeptByContentId(Long contentId) {
List<DeptSimpleDto> deptDtoList = new ArrayList<>();
EmailContent content = this.emailContentService.getById(contentId);
if (StrUtil.isNotBlank(content.getDeptList())){
String[] deptIds = content.getDeptList().split(",");
for (String deptId : deptIds) {
ResultVo<DeptSimpleDto> byDeptId = adminFeignClient.getByDeptId(Long.valueOf(deptId));
if (byDeptId.isSuccess() && byDeptId.getData()!=null){
deptDtoList.add(byDeptId.getData());
}
}
}
return deptDtoList;
}
@Override
public void readAllEmails(Long folderId) {
OnlineUserDto adminContext = TokenUtils.getAdminContext();
AssertUtils.notNull(adminContext, "登录已失效,请重新登录后再次尝试!");
this.lambdaUpdate()
.eq(EmailPerson::getUserId, adminContext.getUserId())
.eq(EmailPerson::getFolderId, folderId)
.eq(EmailPerson::getPersonType, EmailConstant.TYPE_EMAIL_RECEIVE)
.set(EmailPerson::getIsRead, WhetherEnum.YES.getKey())
.update();
}
@Override
public void readEmail(EmailReadVo vo) {
this.lambdaUpdate().in(EmailPerson::getId, vo.getPersonIdList()).set(EmailPerson::getIsRead, vo.getIsRead()).update();
}
@Override
public void readToBin(Long folderId) {
OnlineUserDto adminContext = TokenUtils.getAdminContext();
AssertUtils.notNull(adminContext, "登录已失效,请重新登录后再次尝试!");
this.lambdaUpdate()
.eq(EmailPerson::getUserId, adminContext.getUserId())
.eq(EmailPerson::getFolderId, folderId)
.eq(EmailPerson::getPersonType, EmailConstant.TYPE_EMAIL_RECEIVE)
.eq(EmailPerson::getIsRead, WhetherEnum.YES.getKey())
.set(EmailPerson::getFolderId, EmailFolderEnum.FOLDER_OUTBOX.getKey())
.update();
}
@Override
public MimeMessage emlFile(Long contentId) {
MimeMessage message = null;
try {
EmailContent content = this.emailContentService.getById(contentId);
if (content!=null) {
//收件人
List<EmailPerson> list = this.lambdaQuery()
.select(EmailPerson::getUserEmail)
.eq(EmailPerson::getEmailContentId, content.getId())
.eq(EmailPerson::getPersonType, EmailConstant.TYPE_EMAIL_RECEIVE)
.list();
String recipients = "";
for (EmailPerson emailPerson : list) {
recipients+=emailPerson.getUserEmail()+",";
}
List<EmailAttach> attaches = this.emailAttachService.lambdaQuery().eq(EmailAttach::getEmailContentId, content.getId()).list();
Session session = Session.getDefaultInstance(new Properties());
message = EmailUtil.createMessage(session, content.getSendUserEmail(), recipients, content.getTitle(), content.getContent(), attaches);
}
}catch (Exception e){
log.error("生成eml邮件失败:contentId="+contentId);
log.error(e.getLocalizedMessage(), e);
AssertUtils.isTrue(false,"生成eml邮件失败:contentId="+contentId);
}
return message;
}
@Override
public void deleteAllReceiverDelete() {
OnlineUserDto adminContext = TokenUtils.getAdminContext();
AssertUtils.notNull(adminContext, "登录已失效,请重新登录后再次尝试!");
List<EmailContent> contentList = this.emailContentService.lambdaQuery().eq(EmailContent::getSendUserId, adminContext.getUserId()).list();
for (EmailContent content : contentList) {
List<EmailPerson> personList = this.lambdaQuery().eq(EmailPerson::getEmailContentId, content.getId()).eq(EmailPerson::getPersonType, EmailConstant.TYPE_EMAIL_RECEIVE).list();
Boolean flag = true;
for (EmailPerson emailPerson : personList) {
if (emailPerson.getFolderId().intValue() != EmailFolderEnum.FOLDER_ALREADY_DELETE.getKey()){
flag = false;
break;
}
}
if (flag){
this.lambdaUpdate().eq(EmailPerson::getEmailContentId, content.getId()).remove();
this.emailContentService.removeById(content);
}
}
}
@Override
public void deleteAllReceiverUnread() {
OnlineUserDto adminContext = TokenUtils.getAdminContext();
AssertUtils.notNull(adminContext, "登录已失效,请重新登录后再次尝试!");
List<EmailContent> contentList = this.emailContentService.lambdaQuery().eq(EmailContent::getSendUserId, adminContext.getUserId()).list();
for (EmailContent content : contentList) {
List<EmailPerson> personList = this.lambdaQuery().eq(EmailPerson::getEmailContentId, content.getId()).eq(EmailPerson::getPersonType, EmailConstant.TYPE_EMAIL_RECEIVE).list();
Boolean flag = true;
for (EmailPerson emailPerson : personList) {
if (emailPerson.getIsRead().equals(WhetherEnum.YES.getKey())){
flag = false;
break;
}
}
if (flag){
this.lambdaUpdate().eq(EmailPerson::getEmailContentId, content.getId()).remove();
this.emailContentService.removeById(content);
}
}
}
@Override
public EmailPerson lastAndAfterEmail(EmailLastAndAfterReqVo vo, Integer type) {
OnlineUserDto adminContext = TokenUtils.getAdminContext();
AssertUtils.notNull(adminContext, "登录已失效,请重新登录后再次尝试!");
LambdaQueryWrapper<EmailPerson> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(EmailPerson::getUserId, adminContext.getUserId())
.eq( EmailPerson::getFolderId, vo.getFolderId())
.eq(EmailPerson::getPersonType, EmailConstant.TYPE_EMAIL_RECEIVE);
if (type.equals(WhetherEnum.YES.getKey())){
queryWrapper.gt(EmailPerson::getId, vo.getCurrentPersonId());
}else if (type.equals(WhetherEnum.NO.getKey())){
queryWrapper.lt(EmailPerson::getId, vo.getCurrentPersonId());
}else{
AssertUtils.isTrue(false, "向上或向下查询参数不对");
}
EmailPerson person = this.getOne(queryWrapper, false);
if (person!=null){
EmailContent content = this.emailContentService.getById(person.getEmailContentId());
AssertUtils.notNull(content, "获取邮件内容失败");
person.setEmailContent(content);
return person;
}
return null;
} }
private void saveEmailSender(OnlineUserDto adminContext, EmailContent content, EmailEditVo vo) { private void saveEmailSender(OnlineUserDto adminContext, EmailContent content, EmailEditVo vo) {
EmailPerson sender = EmailPerson.builder() EmailPerson sender = EmailPerson.builder()
.emailContentId(content.getId())
.userId(adminContext.getUserId()) .userId(adminContext.getUserId())
.userEmail(adminContext.getUserName()) .userEmail(adminContext.getUserName())
.userName(adminContext.getNickName())
.deptId(adminContext.getDeptId()) .deptId(adminContext.getDeptId())
.deptName(adminContext.getDeptName()) .deptName(adminContext.getDeptName())
.courtCode(adminContext.getCourtCode()) .courtCode(adminContext.getCourtCode())
...@@ -141,6 +331,7 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email ...@@ -141,6 +331,7 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
.isRead(WhetherEnum.YES.getKey()) .isRead(WhetherEnum.YES.getKey())
.isPerson(WhetherEnum.YES.getKey()) .isPerson(WhetherEnum.YES.getKey())
.isTask(vo.getIsTask()) .isTask(vo.getIsTask())
.isSend(vo.getIsSend())
.build(); .build();
this.save(sender); this.save(sender);
} }
...@@ -153,8 +344,10 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email ...@@ -153,8 +344,10 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
AssertUtils.notNull(userByDeptId.getData(), "获取部门人员为null(deptId: "+deptId+")"); AssertUtils.notNull(userByDeptId.getData(), "获取部门人员为null(deptId: "+deptId+")");
for (CustomerUserVo receiver : userByDeptId.getData()) { for (CustomerUserVo receiver : userByDeptId.getData()) {
EmailPerson receivePerson = EmailPerson.builder() EmailPerson receivePerson = EmailPerson.builder()
.emailContentId(content.getId())
.userId(receiver.getUserId()) .userId(receiver.getUserId())
.userEmail(receiver.getUsername()) .userEmail(receiver.getUsername())
.userName(receiver.getNickName())
.deptId(receiver.getDeptId()) .deptId(receiver.getDeptId())
.courtCode(receiver.getCourtCode()) .courtCode(receiver.getCourtCode())
.personType(EmailConstant.TYPE_EMAIL_RECEIVE) .personType(EmailConstant.TYPE_EMAIL_RECEIVE)
...@@ -163,6 +356,7 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email ...@@ -163,6 +356,7 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
.isRead(WhetherEnum.NO.getKey()) .isRead(WhetherEnum.NO.getKey())
.isPerson(WhetherEnum.NO.getKey()) .isPerson(WhetherEnum.NO.getKey())
.isTask(vo.getIsTask()) .isTask(vo.getIsTask())
.isSend(vo.getIsSend())
.build(); .build();
receiverList.add(receivePerson); receiverList.add(receivePerson);
} }
...@@ -176,8 +370,10 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email ...@@ -176,8 +370,10 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
CustomerUserVo receiver = adminFeignClient.getUserById(userId); CustomerUserVo receiver = adminFeignClient.getUserById(userId);
AssertUtils.notNull(receiver, "获取收件人失败(userId: "+userId+")"); AssertUtils.notNull(receiver, "获取收件人失败(userId: "+userId+")");
EmailPerson receivePerson = EmailPerson.builder() EmailPerson receivePerson = EmailPerson.builder()
.emailContentId(content.getId())
.userId(receiver.getUserId()) .userId(receiver.getUserId())
.userEmail(receiver.getUsername()) .userEmail(receiver.getUsername())
.userName(receiver.getNickName())
.deptId(receiver.getDeptId()) .deptId(receiver.getDeptId())
.courtCode(receiver.getCourtCode()) .courtCode(receiver.getCourtCode())
.personType(EmailConstant.TYPE_EMAIL_RECEIVE) .personType(EmailConstant.TYPE_EMAIL_RECEIVE)
...@@ -186,6 +382,7 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email ...@@ -186,6 +382,7 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
.isRead(WhetherEnum.NO.getKey()) .isRead(WhetherEnum.NO.getKey())
.isPerson(WhetherEnum.YES.getKey()) .isPerson(WhetherEnum.YES.getKey())
.isTask(vo.getIsTask()) .isTask(vo.getIsTask())
.isSend(vo.getIsSend())
.build(); .build();
receiverList.add(receivePerson); receiverList.add(receivePerson);
} }
......
...@@ -26,20 +26,27 @@ public class DateUtils { ...@@ -26,20 +26,27 @@ public class DateUtils {
* @param monthNum * @param monthNum
* @return * @return
*/ */
public static Consumer<LambdaQueryWrapper<EmailPerson>> getRangeStart(Integer monthNum) { public static LocalDateTime getRangeStart(Integer monthNum) {
LocalDateTime localDateTime = null; LocalDateTime localDateTime = null;
if (monthNum!=null) {
if (monthNum.equals(SearchRangeEnum.LAST_THREE_MONTHS.getKey())){ if (monthNum.equals(SearchRangeEnum.LAST_THREE_MONTHS.getKey())) {
localDateTime = DateUtil.offsetMonth(new Date(), -3).toLocalDateTime(); localDateTime = DateUtil.offsetMonth(new Date(), -3).toLocalDateTime();
}else if (monthNum.equals(SearchRangeEnum.LAST_SIX_MONTHS.getKey())){ } else if (monthNum.equals(SearchRangeEnum.LAST_SIX_MONTHS.getKey())) {
localDateTime = DateUtil.offsetMonth(new Date(), -6).toLocalDateTime(); localDateTime = DateUtil.offsetMonth(new Date(), -6).toLocalDateTime();
}else if (monthNum.equals(SearchRangeEnum.LAST_ONE_YEAR.getKey())){ } else if (monthNum.equals(SearchRangeEnum.LAST_ONE_YEAR.getKey())) {
localDateTime = DateUtil.offsetMonth(new Date(), -12).toLocalDateTime(); localDateTime = DateUtil.offsetMonth(new Date(), -12).toLocalDateTime();
}else{ } else {
localDateTime = null; localDateTime = null;
}
} }
return localDateTime; return localDateTime;
} }
public static void main(String[] args) {
System.out.println(DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss"));
LocalDateTime rangeStart = getRangeStart(0);
System.out.println(DateUtil.format(rangeStart, "yyyy-MM-dd HH:mm:ss"));
}
} }
package com.zq.email.utils;
import cn.hutool.core.collection.CollectionUtil;
import com.zq.email.entity.EmailAttach;
import io.swagger.models.auth.In;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.activation.URLDataSource;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.internet.*;
import java.io.FileOutputStream;
import java.net.URL;
import java.util.List;
import java.util.Properties;
public class EmailUtil {
public static void main(String[] args) throws Exception {
InternetAddress[] parse = InternetAddress.parse("111@sina.com,111@sina.com,");
for (InternetAddress internetAddress : parse) {
System.out.println(internetAddress.toString());
System.out.println(internetAddress.getAddress());
}
// Session session = Session.getDefaultInstance(new Properties());
// MimeMessage message = createMessage(session);
//
// message.writeTo(new FileOutputStream("D:\\Eclipse\\ComplexMessage.eml"));
}
public static MimeMessage createMessage(Session session, String sender, String recipient, String subject, String content, List<EmailAttach> attachList) throws Exception {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(sender));
message.setRecipients(Message.RecipientType.TO, recipient);
// message.setFrom(new InternetAddress("sender@sina.com"));
// message.setRecipients(Message.RecipientType.TO, "recipient1@sina.com,recipient2@sina.com,recipient3@sina.com,");
message.setSubject(subject);
//创建代表邮件正文和附件的各个MimeBodyPart对象
MimeBodyPart contentBodyPart = createContent(content);
MimeMultipart allMultipart = new MimeMultipart("mixed");
allMultipart.addBodyPart(contentBodyPart);
if (CollectionUtil.isNotEmpty(attachList)) {
for (EmailAttach emailAttach : attachList) {
MimeBodyPart attachPart = createAttachment(emailAttach);
allMultipart.addBodyPart(attachPart);
}
}
//设置整个邮件内容为最终组合出的MimeMultipart对象
message.setContent(allMultipart);
message.saveChanges();
return message;
}
private static MimeBodyPart createAttachment(EmailAttach attach) throws Exception {
//创建保存附件的MimeBodyPart对象,并加入附件内容和相应信息
MimeBodyPart attachPart = new MimeBodyPart();
//FileDataSource fds = new FileDataSource(filename);
URLDataSource fds = new URLDataSource(new URL(attach.getDownloadPath()));
attachPart.setDataHandler(new DataHandler(fds));
attachPart.setFileName(MimeUtility.encodeText(attach.getAttachName()));
return attachPart;
}
private static MimeBodyPart createContent(String body) throws Exception {
//创建代表组合MIME消息的MimeMultipart对象,和将该MimeMultipart对象保存到MimeBodyPart对象
MimeBodyPart contentPart = new MimeBodyPart();
MimeMultipart contentMultipart = new MimeMultipart("related");
//创建用于保存HTML正文的MimeBodyPart对象,并将它保存到MimeMultipart中
MimeBodyPart htmlBodyPart = new MimeBodyPart();
htmlBodyPart.setContent(body,"text/html;charset=gb2312");
contentMultipart.addBodyPart(htmlBodyPart);
//将MimeMultipart对象保存到MimeBodyPart对象中
contentPart.setContent(contentMultipart);
return contentPart;
}
}
...@@ -33,7 +33,7 @@ public class EmailEditVo { ...@@ -33,7 +33,7 @@ public class EmailEditVo {
private List<Integer> remind; private List<Integer> remind;
@ApiModelProperty("附件id") @ApiModelProperty("附件id")
private List<String> fileId; private List<String> fileIds;
@ApiModelProperty("回复短信id") @ApiModelProperty("回复短信id")
private Long replyId; private Long replyId;
......
package com.zq.email.vo;
import com.zq.common.vo.PageReqVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel(description = "上一封、下一封传参")
@Data
public class EmailLastAndAfterReqVo {
@ApiModelProperty(value = "文件夹ID")
private Integer folderId;
@ApiModelProperty("人员类型")
private Integer personType;
@ApiModelProperty("是否个人邮件")
private Integer isPerson ;
@ApiModelProperty("是否已发送")
private Integer isSend;
@ApiModelProperty("查询范围,默认最近三个月")
private Long currentPersonId;
}
package com.zq.email.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@Api("移动邮件到其他文件夹Vo")
@Data
public class EmailMoveFolderVo {
@ApiModelProperty("personId集合")
private List<Long> personIdList;
@ApiModelProperty("文件夹id")
private Long folderId;
}
package com.zq.email.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Api("移动邮件到其他文件夹Vo")
@Data
public class EmailReadVo {
@ApiModelProperty("personId集合")
private List<Long> personIdList;
@ApiModelProperty("0:未读 1:已读")
private Integer isRead;
}
package com.zq.email.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
import java.util.List;
@Api("回复邮件对应VO")
@Data
public class EmailReplyVo {
@ApiModelProperty("邮箱id")
private Long id;
@ApiModelProperty("标题")
private String title;
@ApiModelProperty("内容")
private String content;
@ApiModelProperty("重要程度")
private Integer degree;
@ApiModelProperty("收件人")
private List<Long> receiver;
@ApiModelProperty("收件部门")
private List<Long> receiveDeptList;
@ApiModelProperty("提醒方式")
private List<Integer> remind;
@ApiModelProperty("附件id")
private List<String> fileId;
@ApiModelProperty("回复短信id")
private Long replyId;
@ApiModelProperty("回复内容")
private String replyContent;
@ApiModelProperty("是否任务邮件 0否 1是")
private Integer isTask = 0;
@ApiModelProperty("是否发送 0:发件箱 1:发送")
private Integer isSend = 0;
@ApiModelProperty("附件")
private List<MultipartFile> fileList;
}
...@@ -17,15 +17,59 @@ import java.util.List; ...@@ -17,15 +17,59 @@ import java.util.List;
@Data @Data
public class EmailReqVo extends PageReqVo { public class EmailReqVo extends PageReqVo {
@ApiModelProperty(value = "文件夹ID,默认收件箱")
private Integer folderId = EmailFolderEnum.FOLDER_INBOX.getKey(); /**
@ApiModelProperty("人员类型, 默认接收人") *
private Integer personType = EmailConstant.TYPE_EMAIL_RECEIVE; * 收件箱
@ApiModelProperty("是否个人邮件,默认是") * folderId = 1
private Integer isPerson = WhetherEnum.YES.getKey(); * personType = 2
@ApiModelProperty("是否已发送, 默认是") * isPerson =1
private Integer isSend = WhetherEnum.YES.getKey(); * isSend = 1
* searchRange = 0
* 部门邮件
* folderId = 2
* personType = 2
* isPerson =0
* isSend = 1
* searchRange = 0
* 草稿箱
* folderId = 3
* personType = 1
* isPerson =1
* isSend = 0
* searchRange = 0
* 已发送
* folderId = 4
* personType = 1
* isPerson =1
* isSend = 1
* searchRange = 0
* 回收站
* folderId = 5
* personType = 2
* isSend = 1
* searchRange = 0
* 其他文件夹
* folderId = 前端根据点击传入
* searchRange = 0
*/
@ApiModelProperty(value = "文件夹ID")
private Integer folderId;
@ApiModelProperty("人员类型")
private Integer personType;
@ApiModelProperty("是否个人邮件")
private Integer isPerson ;
@ApiModelProperty("是否已发送")
private Integer isSend;
@ApiModelProperty("查询范围,默认最近三个月") @ApiModelProperty("查询范围,默认最近三个月")
private Integer searchRange = SearchRangeEnum.LAST_THREE_MONTHS.getKey(); private Integer searchRange = 0;
} }
package com.zq.email.vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Api("设置任务邮件")
@Data
public class EmailTaskVo {
@ApiModelProperty("contentId集合")
private List<Long> contentId;
@ApiModelProperty("0:否 1:是")
private Integer isTask;
}
package com.zq.email.vo;
import lombok.Data;
@Data
public class EmlFileVo {
private String downloadPath;
private String emailTitle;
}
...@@ -11,7 +11,7 @@ spring: ...@@ -11,7 +11,7 @@ spring:
datasource: datasource:
druid: druid:
db-type: com.alibaba.druid.pool.DruidDataSource db-type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:kingbase8://172.18.4.84:54321/SEAL_PLATFOMR url: jdbc:kingbase8://172.18.4.84:54321/EMAIL_NEW
username: oa_system username: oa_system
password: 123456 password: 123456
driver-class-name: com.kingbase8.Driver driver-class-name: com.kingbase8.Driver
......
...@@ -11,7 +11,7 @@ spring: ...@@ -11,7 +11,7 @@ spring:
datasource: datasource:
druid: druid:
db-type: com.alibaba.druid.pool.DruidDataSource db-type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:kingbase8://127.0.0.1:54321/SEAL_PLATFOMR url: jdbc:kingbase8://172.18.4.84:54321/EMAIL_NEW
username: oa_system username: oa_system
password: 123456 password: 123456
driver-class-name: com.kingbase8.Driver driver-class-name: com.kingbase8.Driver
......
...@@ -22,6 +22,8 @@ mybatis-plus: ...@@ -22,6 +22,8 @@ mybatis-plus:
db-config: db-config:
select-strategy: not_empty select-strategy: not_empty
update-strategy: not_empty update-strategy: not_empty
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#日志 #日志
logging: logging:
config: classpath:logback-spring.xml config: classpath:logback-spring.xml
...@@ -29,3 +31,4 @@ logging: ...@@ -29,3 +31,4 @@ logging:
...@@ -4,7 +4,7 @@ spring: ...@@ -4,7 +4,7 @@ spring:
cloud: cloud:
config: config:
name: config name: config
profile: ${spring.profiles.active} profile: dev
discovery: discovery:
enabled: true enabled: true
service-id: CONFIG-SERVER service-id: CONFIG-SERVER
......
...@@ -8,11 +8,11 @@ ...@@ -8,11 +8,11 @@
<contextName>logback</contextName> <contextName>logback</contextName>
<!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 --> <!-- name的值是变量的名称,value的值时变量定义的值。通过定义的值会被插入到logger上下文中。定义变量后,可以使“${}”来使用变量。 -->
<property name="log.path" value="/data/services/email/logs/"/> <property name="log.path" value="/data/services/email_mail/logs/"/>
<!-- <property name="log.path" value="D:/seallog/"/>--> <!-- <property name="log.path" value="D:/seallog/"/>-->
<!--主要日志文件名--> <!--主要日志文件名-->
<property name="default_log_file" value="email"/> <property name="default_log_file" value="email_new"/>
<!-- 彩色日志 --> <!-- 彩色日志 -->
<!-- 彩色日志依赖的渲染类 --> <!-- 彩色日志依赖的渲染类 -->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment