Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
email
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈天仲
email
Commits
558de846
Commit
558de846
authored
Mar 20, 2023
by
chentianzhong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
7777777
parent
4716e1c0
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
160 additions
and
48 deletions
+160
-48
src/main/java/com/zq/email/EmailApplication.java
+2
-0
src/main/java/com/zq/email/config/MyThreadPoolTaskExecutor.java
+49
-0
src/main/java/com/zq/email/controller/EmailController.java
+15
-4
src/main/java/com/zq/email/controller/EmailPersonController.java
+5
-1
src/main/java/com/zq/email/service/IEmailPersonService.java
+5
-0
src/main/java/com/zq/email/service/impl/EmailPersonServiceImpl.java
+77
-43
src/main/java/com/zq/email/vo/EmailFolderMoveVo.java
+4
-0
src/main/java/com/zq/email/vo/EmailReadVo.java
+3
-0
No files found.
src/main/java/com/zq/email/EmailApplication.java
View file @
558de846
...
...
@@ -4,12 +4,14 @@ import org.mybatis.spring.annotation.MapperScan;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.cloud.openfeign.EnableFeignClients
;
import
org.springframework.scheduling.annotation.EnableAsync
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
@EnableFeignClients
@SpringBootApplication
(
scanBasePackages
=
{
"com.zq.email"
,
"com.zq.common.config"
})
@MapperScan
(
"com.zq.email.mapper"
)
@EnableTransactionManagement
@EnableAsync
public
class
EmailApplication
{
public
static
void
main
(
String
[]
args
)
{
...
...
src/main/java/com/zq/email/config/MyThreadPoolTaskExecutor.java
0 → 100644
View file @
558de846
package
com
.
zq
.
email
.
config
;
import
org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor
;
import
org.springframework.web.context.request.RequestAttributes
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
java.util.concurrent.Callable
;
import
java.util.concurrent.Future
;
/**
* 解决异步丢失请求信息
*
* @author wilmiam
* @since 2022/12/10 16:23
*/
public
class
MyThreadPoolTaskExecutor
extends
ThreadPoolTaskExecutor
{
public
MyThreadPoolTaskExecutor
()
{
super
();
}
@Override
public
void
execute
(
Runnable
task
)
{
RequestAttributes
requestAttributes
=
RequestContextHolder
.
getRequestAttributes
();
super
.
execute
(()
->
{
RequestContextHolder
.
setRequestAttributes
(
requestAttributes
);
task
.
run
();
});
}
@Override
public
<
T
>
Future
<
T
>
submit
(
Callable
<
T
>
task
)
{
RequestAttributes
requestAttributes
=
RequestContextHolder
.
getRequestAttributes
();
return
super
.
submit
(()
->
{
RequestContextHolder
.
setRequestAttributes
(
requestAttributes
);
return
task
.
call
();
});
}
@Override
public
Future
<?>
submit
(
Runnable
task
)
{
RequestAttributes
requestAttributes
=
RequestContextHolder
.
getRequestAttributes
();
return
super
.
submit
(()
->
{
RequestContextHolder
.
setRequestAttributes
(
requestAttributes
);
task
.
run
();
});
}
}
src/main/java/com/zq/email/controller/EmailController.java
View file @
558de846
...
...
@@ -101,12 +101,12 @@ public class EmailController {
public
ResultVo
detail
(
@RequestBody
EmailDetailVo
vo
)
{
OnlineUserDto
adminContext
=
TokenUtils
.
getAdminContext
();
AssertUtils
.
notNull
(
adminContext
,
"登录已失效,请重新登录后再次尝试!"
);
AssertUtils
.
notNull
(
vo
.
getPersonId
(),
"缺少参数:personId"
);
EmailPerson
emailPerson
=
emailPersonService
.
getById
(
vo
.
getPersonId
());
AssertUtils
.
notNull
(
vo
.
getContentId
(),
"缺少参数:contentId"
);
EmailContent
content
=
emailContentService
.
getById
(
vo
.
getContentId
());
AssertUtils
.
notNull
(
content
,
"获取邮件内容失败"
);
EmailPerson
emailPerson
=
emailPersonService
.
getByIdAndSendTime
(
vo
.
getPersonId
(),
content
.
getSendTime
());
AssertUtils
.
notNull
(
emailPerson
,
"获取邮件对应人员信息失败"
);
AssertUtils
.
isTrue
(
emailPerson
.
getUserId
().
equals
(
adminContext
.
getUserId
())
,
"非本人邮件,不允许阅读"
);
EmailContent
content
=
emailContentService
.
getById
(
emailPerson
.
getEmailContentId
());
AssertUtils
.
notNull
(
content
,
"获取邮件内容失败"
);
emailPerson
.
setEmailContent
(
content
);
return
ResultVo
.
success
(
emailPerson
);
}
...
...
@@ -208,6 +208,17 @@ public class EmailController {
@ApiOperation
(
"移动邮件到自定义文件夹或回收站"
)
@PostMapping
(
"detail/move"
)
public
ResultVo
edit
(
@RequestBody
EmailDetailVo
vo
)
{
AssertUtils
.
notNull
(
vo
.
getContentId
(),
"缺少参数:contentId"
);
AssertUtils
.
notNull
(
vo
.
getPersonId
(),
"缺少参数:personId"
);
emailPersonService
.
moveDetailEmailFolder
(
vo
);
return
ResultVo
.
success
();
}
...
...
src/main/java/com/zq/email/controller/EmailPersonController.java
View file @
558de846
...
...
@@ -40,6 +40,9 @@ public class EmailPersonController {
@ApiOperation
(
"移动邮件到自定义文件夹或回收站"
)
@PostMapping
(
"move"
)
public
ResultVo
edit
(
@RequestBody
EmailFolderMoveVo
vo
)
{
AssertUtils
.
notEmpty
(
vo
.
getPersonIdList
(),
"缺少参数:personIdList"
);
AssertUtils
.
notNull
(
vo
.
getSearchRange
(),
"缺少参数:searchRange"
);
AssertUtils
.
notNull
(
vo
.
getFolderId
(),
"缺少参数:folderId"
);
emailPersonService
.
moveEmailFolder
(
vo
);
return
ResultVo
.
success
();
}
...
...
@@ -63,6 +66,7 @@ public class EmailPersonController {
public
ResultVo
readEmail
(
@RequestBody
EmailReadVo
vo
)
{
AssertUtils
.
notEmpty
(
vo
.
getPersonIdList
(),
"缺少参数:personIdList"
);
AssertUtils
.
notNull
(
vo
.
getIsRead
(),
"缺少参数:isSend"
);
AssertUtils
.
notNull
(
vo
.
getSearchRange
(),
"缺少参数:searchRange"
);
log
.
info
(
"执行前: {}"
+
DateUtil
.
format
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
));
this
.
emailPersonService
.
readEmail
(
vo
);
log
.
info
(
"执行后: {}"
+
DateUtil
.
format
(
new
Date
(),
"yyyy-MM-dd HH:mm:ss"
));
...
...
@@ -101,7 +105,7 @@ public class EmailPersonController {
}
@ApiOperation
(
"回收站恢复"
)
@ApiOperation
(
"回收站恢复
(列表)
"
)
@PostMapping
(
"resumeEmail"
)
public
ResultVo
resumeEmail
(
@RequestBody
List
<
Long
>
personIdList
)
{
this
.
emailPersonService
.
resumeEmail
(
personIdList
);
...
...
src/main/java/com/zq/email/service/IEmailPersonService.java
View file @
558de846
...
...
@@ -13,6 +13,7 @@ import org.springframework.core.io.InputStreamResource;
import
org.springframework.http.ResponseEntity
;
import
javax.mail.internet.MimeMessage
;
import
java.time.LocalDateTime
;
import
java.util.List
;
/**
...
...
@@ -66,4 +67,8 @@ public interface IEmailPersonService extends IService<EmailPerson> {
ResultVo
getUserPolice
();
List
<
CustomerUserVo
>
recentlyContacts
(
List
<
Long
>
recentlySendEmail
);
EmailPerson
getByIdAndSendTime
(
Long
personId
,
LocalDateTime
sendTime
);
void
moveDetailEmailFolder
(
EmailDetailVo
vo
);
}
src/main/java/com/zq/email/service/impl/EmailPersonServiceImpl.java
View file @
558de846
...
...
@@ -15,6 +15,7 @@ import com.zq.common.utils.TokenUtils;
import
com.zq.common.vo.CustomerUserVo
;
import
com.zq.common.vo.OnlineUserDto
;
import
com.zq.common.vo.ResultVo
;
import
com.zq.email.config.MyThreadPoolTaskExecutor
;
import
com.zq.email.constants.EmailConstant
;
import
com.zq.email.dto.DeptDto
;
import
com.zq.email.dto.DeptSimpleDto
;
...
...
@@ -67,6 +68,8 @@ import java.io.InputStream;
import
java.net.URL
;
import
java.time.LocalDateTime
;
import
java.util.*
;
import
java.util.concurrent.ExecutorService
;
import
java.util.concurrent.Executors
;
/**
* <p>
...
...
@@ -81,6 +84,8 @@ import java.util.*;
@Slf4j
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/"
;
...
...
@@ -188,14 +193,13 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
if
(
content
.
getSmsRemind
()!=
null
&&
content
.
getSmsRemind
()
==
1
)
{
new
Thread
(()
->
{
smsUtil
.
sendBatchSms
(
receiverList
,
"您有一封新的邮件,标题为《"
+
content
.
getTitle
()
+
"》。请及时查收。"
,
content
.
getId
());
});
})
.
start
()
;
}
}
if
(
CollectionUtil
.
isNotEmpty
(
deptUserList
))
{
//增加收件部门
this
.
saveEmailReceiveDept
(
deptUserList
,
content
,
vo
);
...
...
@@ -203,7 +207,7 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
if
(
content
.
getSmsRemind
()!=
null
&&
content
.
getSmsRemind
()
==
1
)
{
new
Thread
(()
->
{
smsUtil
.
sendBatchSms
(
deptUserList
,
"您有一封新的邮件,标题为《"
+
content
.
getTitle
()
+
"》。请及时查收。"
,
content
.
getId
());
});
})
.
start
()
;
}
}
}
...
...
@@ -214,7 +218,11 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
@Override
public
void
moveEmailFolder
(
EmailFolderMoveVo
vo
)
{
List
<
EmailPerson
>
personList
=
this
.
listByIds
(
vo
.
getPersonIdList
());
List
<
EmailPerson
>
personList
=
this
.
lambdaQuery
()
.
ge
(
EmailPerson:
:
getSendTime
,
DateUtils
.
getRangeStart
(
vo
.
getSearchRange
()))
.
le
(
EmailPerson:
:
getSendTime
,
LocalDateTime
.
now
())
.
in
(
EmailPerson:
:
getId
,
vo
.
getPersonIdList
()).
list
();
for
(
EmailPerson
emailPerson
:
personList
)
{
emailPerson
.
setOldFolderId
(
emailPerson
.
getFolderId
());
emailPerson
.
setFolderId
(
vo
.
getFolderId
());
...
...
@@ -252,25 +260,26 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
public
void
readAllEmails
(
Long
folderId
)
{
OnlineUserDto
adminContext
=
TokenUtils
.
getAdminContext
();
AssertUtils
.
notNull
(
adminContext
,
"登录已失效,请重新登录后再次尝试!"
);
LocalDateTime
rangeStart
=
DateUtils
.
getRangeStart
(
2
);
this
.
lambdaUpdate
()
.
eq
(
EmailPerson:
:
getUserId
,
adminContext
.
getUserId
())
.
eq
(
EmailPerson:
:
getFolderId
,
folderId
)
.
eq
(
EmailPerson:
:
getPersonType
,
EmailConstant
.
TYPE_EMAIL_RECEIVE
)
.
ge
(
EmailPerson:
:
getSendTime
,
rangeStart
)
.
le
(
EmailPerson:
:
getSendTime
,
LocalDateTime
.
now
())
.
set
(
EmailPerson:
:
getIsRead
,
WhetherEnum
.
YES
.
getKey
())
.
update
();
}
@Override
public
void
readEmail
(
EmailReadVo
vo
)
{
List
<
EmailPerson
>
personList
=
new
ArrayList
<>();
for
(
Long
id
:
vo
.
getPersonIdList
())
{
EmailPerson
byId
=
this
.
getById
(
id
);
byId
.
setIsRead
(
vo
.
getIsRead
());
personList
.
add
(
byId
);
}
this
.
updateBatchById
(
personList
);
//this.lambdaUpdate().in(EmailPerson::getId, vo.getPersonIdList()).set(EmailPerson::getIsRead, vo.getIsRead()).update();
// List<EmailPerson> personList = new ArrayList<>();
// LocalDateTime rangeStart = DateUtils.getRangeStart(vo.getSearchRange());
this
.
lambdaUpdate
()
.
ge
(
EmailPerson:
:
getSendTime
,
DateUtils
.
getRangeStart
(
vo
.
getSearchRange
()))
.
le
(
EmailPerson:
:
getSendTime
,
LocalDateTime
.
now
())
.
in
(
EmailPerson:
:
getId
,
vo
.
getPersonIdList
())
.
set
(
EmailPerson:
:
getIsRead
,
vo
.
getIsRead
()).
update
();
}
@Override
...
...
@@ -597,6 +606,21 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
return
list
;
}
@Override
public
EmailPerson
getByIdAndSendTime
(
Long
personId
,
LocalDateTime
sendTime
)
{
return
this
.
lambdaQuery
().
eq
(
EmailPerson:
:
getId
,
personId
).
eq
(
EmailPerson:
:
getSendTime
,
sendTime
).
one
();
}
@Override
public
void
moveDetailEmailFolder
(
EmailDetailVo
vo
)
{
EmailContent
content
=
this
.
emailContentService
.
getById
(
vo
.
getContentId
());
this
.
lambdaUpdate
().
eq
(
EmailPerson:
:
getId
,
vo
.
getPersonId
())
.
eq
(
EmailPerson:
:
getSendTime
,
content
.
getSendTime
())
.
set
(
EmailPerson:
:
getFolderId
,
vo
.
getFolderId
()).
update
();
}
private
void
saveEmailSender
(
OnlineUserDto
adminContext
,
EmailContent
content
,
EmailEditVo
vo
)
{
EmailPerson
sender
=
EmailPerson
.
builder
()
...
...
@@ -644,23 +668,37 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
this
.
save
(
receivePerson
);
//内部消息提醒
if
(
content
.
getMessageRemind
()!=
null
&&
content
.
getMessageRemind
()
==
1
){
new
Thread
(()
->
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"systemTag"
,
EmailConstant
.
SYSTEM_TAG
);
params
.
put
(
"title"
,
"您有一封新邮件提醒"
);
params
.
put
(
"content"
,
"您有一封新的邮件,标题为《"
+
content
.
getTitle
()+
"》。请及时查收。"
);
params
.
put
(
"userIdList"
,
Collections
.
singletonList
(
userVo
.
getUserId
()));
params
.
put
(
"businessId"
,
receivePerson
.
getId
());
params
.
put
(
"jumpUrl"
,
systemInfo
.
getHomeUrl
()
+
"/#/detail?personId="
+
receivePerson
.
getId
());
log
.
info
(
"发送内部短信内容打印: {}"
,
JSONUtil
.
toJsonStr
(
params
));
messageFeignClient
.
sendWebMessage
(
params
);
messageFeignClient
.
addToDo
(
params
);
});
// if (content.getMessageRemind()!=null && content.getMessageRemind() == 1){
// new Thread(() -> {
// Map<String, Object> params = new HashMap<>();
// params .put("systemTag", EmailConstant.SYSTEM_TAG);
// params .put("title","您有一封新邮件提醒");
// params .put("content", "您有一封新的邮件,标题为《"+content.getTitle()+"》。请及时查收。");
// params.put("userIdList", Collections.singletonList(userVo.getUserId()));
// params .put("businessId", receivePerson.getId());
// params.put("jumpUrl", systemInfo.getHomeUrl() + "/#/detail?personId=" + receivePerson.getId());
// log.info("发送内部短信内容打印: {}", JSONUtil.toJsonStr(params));
// messageFeignClient .sendWebMessage(params);
// messageFeignClient .addToDo(params);
// }).start();
//
// }
//内部消息提醒
if
(
content
.
getMessageRemind
()!=
null
&&
content
.
getMessageRemind
()
==
1
){
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"systemTag"
,
EmailConstant
.
SYSTEM_TAG
);
params
.
put
(
"title"
,
"您有一封新邮件提醒"
);
params
.
put
(
"content"
,
"您有一封新的邮件,标题为《"
+
content
.
getTitle
()+
"》。请及时查收。"
);
params
.
put
(
"userIdList"
,
Collections
.
singletonList
(
userVo
.
getUserId
()));
params
.
put
(
"businessId"
,
receivePerson
.
getId
());
params
.
put
(
"jumpUrl"
,
systemInfo
.
getHomeUrl
()
+
"/#/detail?personId="
+
receivePerson
.
getId
()+
"&contentId="
+
content
.
getId
());
ResultVo
resultVo
=
messageFeignClient
.
sendWebMessage
(
params
);
log
.
info
(
"发送内部短信内容打印: {}, feign结果:{}"
,
JSONUtil
.
toJsonStr
(
params
),
JSONUtil
.
toJsonStr
(
resultVo
));
ResultVo
resultVo1
=
messageFeignClient
.
addToDo
(
params
);
log
.
info
(
"发送代办内容打印: {}, feign结果:{}"
,
JSONUtil
.
toJsonStr
(
params
),
JSONUtil
.
toJsonStr
(
resultVo1
));
}
}
}
...
...
@@ -690,22 +728,18 @@ public class EmailPersonServiceImpl extends ServiceImpl<EmailPersonMapper, Email
this
.
save
(
receivePerson
);
//内部消息提醒
if
(
content
.
getMessageRemind
()!=
null
&&
content
.
getMessageRemind
()
==
1
){
new
Thread
(()
->
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"systemTag"
,
EmailConstant
.
SYSTEM_TAG
);
params
.
put
(
"title"
,
"您有一封新邮件提醒"
);
params
.
put
(
"content"
,
"您有一封新的邮件,标题为《"
+
content
.
getTitle
()+
"》。请及时查收。"
);
params
.
put
(
"userIdList"
,
Collections
.
singletonList
(
userVo
.
getUserId
()));
params
.
put
(
"businessId"
,
receivePerson
.
getId
());
params
.
put
(
"jumpUrl"
,
systemInfo
.
getHomeUrl
()
+
"/#/detail?personId="
+
receivePerson
.
getId
());
log
.
info
(
"发送内部短信内容打印: {}"
,
JSONUtil
.
toJsonStr
(
params
));
ResultVo
resultVo
=
messageFeignClient
.
sendWebMessage
(
params
);
log
.
info
(
"sendWebMessage: {}"
+
JSONUtil
.
toJsonStr
(
resultVo
));
ResultVo
resultVo1
=
messageFeignClient
.
addToDo
(
params
);
log
.
info
(
"addToDo: {}"
+
JSONUtil
.
toJsonStr
(
resultVo1
));
});
if
(
content
.
getMessageRemind
()!=
null
&&
content
.
getMessageRemind
()
==
1
)
{
Map
<
String
,
Object
>
params
=
new
HashMap
<>();
params
.
put
(
"systemTag"
,
EmailConstant
.
SYSTEM_TAG
);
params
.
put
(
"title"
,
"您有一封新邮件提醒"
);
params
.
put
(
"content"
,
"您有一封新的邮件,标题为《"
+
content
.
getTitle
()
+
"》。请及时查收。"
);
params
.
put
(
"userIdList"
,
Collections
.
singletonList
(
userVo
.
getUserId
()));
params
.
put
(
"businessId"
,
receivePerson
.
getId
());
params
.
put
(
"jumpUrl"
,
systemInfo
.
getHomeUrl
()
+
"/#/detail?personId="
+
receivePerson
.
getId
()+
"&contentId="
+
content
.
getId
());
ResultVo
resultVo
=
messageFeignClient
.
sendWebMessage
(
params
);
log
.
info
(
"发送内部短信内容打印: {}, feign结果:{}"
,
JSONUtil
.
toJsonStr
(
params
),
JSONUtil
.
toJsonStr
(
resultVo
));
ResultVo
resultVo1
=
messageFeignClient
.
addToDo
(
params
);
log
.
info
(
"发送代办内容打印: {}, feign结果:{}"
,
JSONUtil
.
toJsonStr
(
params
),
JSONUtil
.
toJsonStr
(
resultVo1
));
}
...
...
src/main/java/com/zq/email/vo/EmailFolderMoveVo.java
View file @
558de846
package
com
.
zq
.
email
.
vo
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.util.List
;
...
...
@@ -18,5 +19,8 @@ public class EmailFolderMoveVo {
private
List
<
Long
>
personIdList
;
@ApiModelProperty
(
"查询范围,默认最近三个月"
)
private
Integer
searchRange
;
}
src/main/java/com/zq/email/vo/EmailReadVo.java
View file @
558de846
...
...
@@ -13,6 +13,9 @@ public class EmailReadVo {
@ApiModelProperty
(
"personId集合"
)
private
List
<
Long
>
personIdList
;
@ApiModelProperty
(
"查询范围,默认最近三个月"
)
private
Integer
searchRange
;
@ApiModelProperty
(
"0:未读 1:已读"
)
private
Integer
isRead
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment