|
@@ -3,14 +3,17 @@ package com.fjhx.mail.service.message.impl;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.mail.config.MailServiceConfig;
|
|
|
import com.fjhx.mail.entity.enterprise.po.EnterpriseDomain;
|
|
|
import com.fjhx.mail.entity.enterprise.po.EnterpriseMailbox;
|
|
|
+import com.fjhx.mail.entity.message.dto.DeleteBatchMailDto;
|
|
|
import com.fjhx.mail.entity.message.dto.DeleteMailDto;
|
|
|
import com.fjhx.mail.entity.message.dto.SendDto;
|
|
|
+import com.fjhx.mail.entity.message.dto.SetSeenDto;
|
|
|
import com.fjhx.mail.entity.personal.po.PersonalMailbox;
|
|
|
import com.fjhx.mail.service.enterprise.EnterpriseDomainService;
|
|
|
import com.fjhx.mail.service.enterprise.EnterpriseMailboxService;
|
|
@@ -91,50 +94,8 @@ public class InfoServiceImpl implements InfoService {
|
|
|
|
|
|
@Override
|
|
|
public String sendMail(SendDto dto) {
|
|
|
- Integer type = dto.getType();
|
|
|
- Long mailboxId = dto.getMailboxId();
|
|
|
- String urlPrefix;
|
|
|
-
|
|
|
- StringJoiner urlJoiner = new StringJoiner("/");
|
|
|
- urlJoiner.add("sendMail");
|
|
|
-
|
|
|
- if (type == 1) {
|
|
|
- PersonalMailbox personalMailbox = personalMailboxService.getById(mailboxId);
|
|
|
- if (personalMailbox == null) {
|
|
|
- throw new ServiceException("未找到个人邮箱");
|
|
|
- }
|
|
|
-
|
|
|
- urlJoiner.add(personalMailbox.getSendHost());
|
|
|
- urlJoiner.add(personalMailbox.getMailUser());
|
|
|
- urlJoiner.add(personalMailbox.getMailPassword());
|
|
|
-
|
|
|
- if (Objects.equals(personalMailbox.getType(), 2)) {
|
|
|
- urlPrefix = MailServiceConfig.abroadUrlPrefix;
|
|
|
- } else {
|
|
|
- urlPrefix = MailServiceConfig.urlPrefix;
|
|
|
- }
|
|
|
- } else {
|
|
|
-
|
|
|
- EnterpriseMailbox enterpriseMailbox = enterpriseMailboxService.getById(mailboxId);
|
|
|
- if (enterpriseMailbox == null) {
|
|
|
- throw new ServiceException("未找到企业邮箱");
|
|
|
- }
|
|
|
- EnterpriseDomain enterpriseDomain = enterpriseDomainService.getById(enterpriseMailbox.getDomainId());
|
|
|
- if (enterpriseDomain == null) {
|
|
|
- throw new ServiceException("未找到企业邮箱配置");
|
|
|
- }
|
|
|
- urlJoiner.add(enterpriseDomain.getSendHost());
|
|
|
- urlJoiner.add(enterpriseMailbox.getMailUserPrefix() + "@" + enterpriseDomain.getDomainName());
|
|
|
- urlJoiner.add(enterpriseMailbox.getMailPassword());
|
|
|
-
|
|
|
- if (Objects.equals(enterpriseDomain.getType(), 2)) {
|
|
|
- urlPrefix = MailServiceConfig.abroadUrlPrefix;
|
|
|
- } else {
|
|
|
- urlPrefix = MailServiceConfig.urlPrefix;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return HttpUtil.post(urlPrefix + urlJoiner, JSON.toJSONString(dto));
|
|
|
+ String sendMail = getUrl("sendMail", dto.getType(), dto.getMailboxId());
|
|
|
+ return HttpUtil.post(sendMail, JSON.toJSONString(dto));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -173,6 +134,22 @@ public class InfoServiceImpl implements InfoService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void deleteBatchMail(DeleteBatchMailDto dto) {
|
|
|
+ if (dto.getType().equals(1)) {
|
|
|
+ personalMessageService.removeBatchByIds(dto.getIdList());
|
|
|
+ } else {
|
|
|
+ enterpriseMessageService.removeBatchByIds(dto.getIdList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject setSeen(SetSeenDto dto) {
|
|
|
+ String url = getUrl("setSeen", dto.getType(), dto.getMailboxId());
|
|
|
+ String post = HttpUtil.post(url, JSON.toJSONString(dto));
|
|
|
+ return JSONObject.parseObject(post);
|
|
|
+ }
|
|
|
+
|
|
|
private void subordinateDeptId(Long deptId, Set<Long> deptSet, Map<Long, List<SysDept>> parentDeptMap) {
|
|
|
deptSet.add(deptId);
|
|
|
|
|
@@ -188,5 +165,49 @@ public class InfoServiceImpl implements InfoService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private String getUrl(String prefix, Integer type, Long mailboxId) {
|
|
|
+ String urlPrefix;
|
|
|
+
|
|
|
+ StringJoiner urlJoiner = new StringJoiner("/");
|
|
|
+ urlJoiner.add(prefix);
|
|
|
+
|
|
|
+ if (type == 1) {
|
|
|
+ PersonalMailbox personalMailbox = personalMailboxService.getById(mailboxId);
|
|
|
+ if (personalMailbox == null) {
|
|
|
+ throw new ServiceException("未找到个人邮箱");
|
|
|
+ }
|
|
|
+
|
|
|
+ urlJoiner.add(personalMailbox.getSendHost());
|
|
|
+ urlJoiner.add(personalMailbox.getMailUser());
|
|
|
+ urlJoiner.add(personalMailbox.getMailPassword());
|
|
|
+
|
|
|
+ if (Objects.equals(personalMailbox.getType(), 2)) {
|
|
|
+ urlPrefix = MailServiceConfig.abroadUrlPrefix;
|
|
|
+ } else {
|
|
|
+ urlPrefix = MailServiceConfig.urlPrefix;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ EnterpriseMailbox enterpriseMailbox = enterpriseMailboxService.getById(mailboxId);
|
|
|
+ if (enterpriseMailbox == null) {
|
|
|
+ throw new ServiceException("未找到企业邮箱");
|
|
|
+ }
|
|
|
+ EnterpriseDomain enterpriseDomain = enterpriseDomainService.getById(enterpriseMailbox.getDomainId());
|
|
|
+ if (enterpriseDomain == null) {
|
|
|
+ throw new ServiceException("未找到企业邮箱配置");
|
|
|
+ }
|
|
|
+ urlJoiner.add(enterpriseDomain.getSendHost());
|
|
|
+ urlJoiner.add(enterpriseMailbox.getMailUserPrefix() + "@" + enterpriseDomain.getDomainName());
|
|
|
+ urlJoiner.add(enterpriseMailbox.getMailPassword());
|
|
|
+
|
|
|
+ if (Objects.equals(enterpriseDomain.getType(), 2)) {
|
|
|
+ urlPrefix = MailServiceConfig.abroadUrlPrefix;
|
|
|
+ } else {
|
|
|
+ urlPrefix = MailServiceConfig.urlPrefix;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return urlPrefix + urlJoiner;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|