Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Fedex
/
iClear-Connect-Pre-Clearance
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
zelong.shao
2024-12-23 20:36:06 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ab4fcdfe6369ef6be0337ed04fd637484d35f9f4
ab4fcdfe
1 parent
c56c99ae
task|邮件调整
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
79 additions
and
47 deletions
server/biz-customer/src/main/java/com/fedex/connect/customer/service/biz/IEmailService.java
server/biz-customer/src/main/java/com/fedex/connect/customer/service/biz/impl/EmailServiceImpl.java
server/biz-customer/src/main/java/com/fedex/connect/customer/util/service/biz/ConsignmentUtil.java
server/biz-customer/src/main/java/com/fedex/connect/customer/util/service/biz/EmailUtil.java
server/task-schedule/src/main/java/com/fedex/connect/task/config/PropertiesConfig.java
server/task-schedule/src/main/java/com/fedex/connect/task/data/dto/PushZipEmailDto.java
server/task-schedule/src/main/java/com/fedex/connect/task/repository/dao/AttachmentExtMapper.java
server/task-schedule/src/main/java/com/fedex/connect/task/service/biz/impl/PushConsignmentFileServiceImpl.java
server/task-schedule/src/main/java/com/fedex/connect/task/utils/sys/ConFileEmailUtil.java
server/task-schedule/src/main/resources/application-dev.yml
server/task-schedule/src/main/resources/application-test.yml
server/biz-customer/src/main/java/com/fedex/connect/customer/service/biz/IEmailService.java
View file @
ab4fcdf
package
com
.
fedex
.
connect
.
customer
.
service
.
biz
;
import
com.fedex.connect.common.model.biz.Consignment
;
import
com.fedex.connect.common.model.biz.UploadRecord
;
import
com.fedex.connect.common.model.sys.User
;
public
interface
IEmailService
{
void
saveNotificationEmail
(
Consignment
consignment
,
User
user
)
throws
Exception
;
void
savePushConsignmentFileEmail
(
Consignment
consignment
,
U
ser
user
)
throws
Exception
;
void
savePushConsignmentFileEmail
(
Consignment
consignment
,
U
ploadRecord
uploadRecord
)
throws
Exception
;
}
...
...
server/biz-customer/src/main/java/com/fedex/connect/customer/service/biz/impl/EmailServiceImpl.java
View file @
ab4fcdf
...
...
@@ -2,6 +2,7 @@ package com.fedex.connect.customer.service.biz.impl;
import
com.fedex.connect.common.model.biz.Consignment
;
import
com.fedex.connect.common.model.biz.Email
;
import
com.fedex.connect.common.model.biz.UploadRecord
;
import
com.fedex.connect.common.model.sys.User
;
import
com.fedex.connect.customer.service.base.BaseService
;
import
com.fedex.connect.customer.service.biz.IEmailService
;
...
...
@@ -41,15 +42,12 @@ public class EmailServiceImpl extends BaseService implements IEmailService {
}
@Override
public
void
savePushConsignmentFileEmail
(
Consignment
consignment
,
User
user
)
throws
Exception
{
if
(!
StringUtils
.
isEmpty
(
consignment
.
getUserUuid
())
&&
consignment
.
getUserUuid
().
equals
(
user
.
getUserUuid
())){
return
;
}
public
void
savePushConsignmentFileEmail
(
Consignment
consignment
,
UploadRecord
uploadRecord
)
throws
Exception
{
/**
* 初始化Email对象
*/
Email
email
=
new
Email
();
emailUtil
.
initPushConsignmentFileEmail
(
email
,
consignment
);
emailUtil
.
initPushConsignmentFileEmail
(
email
,
consignment
,
uploadRecord
);
/**
* 保存入库
*/
...
...
server/biz-customer/src/main/java/com/fedex/connect/customer/util/service/biz/ConsignmentUtil.java
View file @
ab4fcdf
...
...
@@ -293,7 +293,7 @@ public class ConsignmentUtil {
/**
* 初始化插入预清关文件邮件推送日志
*/
emailService
.
savePushConsignmentFileEmail
(
consignment
,
u
ser
);
emailService
.
savePushConsignmentFileEmail
(
consignment
,
u
ploadRecord
);
/**
* 推送进口文件主表
*/
...
...
server/biz-customer/src/main/java/com/fedex/connect/customer/util/service/biz/EmailUtil.java
View file @
ab4fcdf
...
...
@@ -5,6 +5,7 @@ import com.fedex.connect.common.dependencies.enums.biz.EmailTypeEnum;
import
com.fedex.connect.common.dependencies.util.AssignmentFieldUtils
;
import
com.fedex.connect.common.model.biz.Consignment
;
import
com.fedex.connect.common.model.biz.Email
;
import
com.fedex.connect.common.model.biz.UploadRecord
;
import
com.fedex.connect.customer.repository.repo.IUserRepository
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -33,8 +34,8 @@ public class EmailUtil {
AssignmentFieldUtils
.
assignmentTableBaseField
(
email
);
}
public
void
initPushConsignmentFileEmail
(
Email
email
,
Consignment
consignment
)
throws
Exception
{
email
.
setBizId
(
consignment
.
getId
());
public
void
initPushConsignmentFileEmail
(
Email
email
,
Consignment
consignment
,
UploadRecord
uploadRecord
)
throws
Exception
{
email
.
setBizId
(
uploadRecord
.
getId
());
email
.
setBizCode
(
consignment
.
getConsignmentCode
());
String
emailAddress
=
Optional
.
ofNullable
(
consignment
.
getUserUuid
())
.
map
(
iUserRepository:
:
findUserByUuid
)
...
...
server/task-schedule/src/main/java/com/fedex/connect/task/config/PropertiesConfig.java
View file @
ab4fcdf
...
...
@@ -79,4 +79,7 @@ public class PropertiesConfig {
//文件异常文件存放目录
@Value
(
"${imp001.path.error}"
)
String
imp001PathError
;
@Value
(
"${upload.path.zip}"
)
private
String
zipPath
;
}
\ No newline at end of file
...
...
server/task-schedule/src/main/java/com/fedex/connect/task/data/dto/PushZipEmailDto.java
View file @
ab4fcdf
...
...
@@ -10,4 +10,5 @@ public class PushZipEmailDto {
private
String
shipperPhone
;
private
String
shipperAccount
;
private
String
originCountry
;
private
String
fileName
;
}
...
...
server/task-schedule/src/main/java/com/fedex/connect/task/repository/dao/AttachmentExtMapper.java
View file @
ab4fcdf
...
...
@@ -9,10 +9,19 @@ import java.util.List;
@Mapper
public
interface
AttachmentExtMapper
{
@Select
(
"SELECT a.FILE_PATH, c.DEST_IATA_CODE, c.CONSIGNMENT_CODE, c.SHIPPER_CONTACT_NAME, c.SHIPPER_EMAIL, c.SHIPPER_PHONE, c.SHIPPER_ACCOUNT, c.ORIGIN_COUNTRY "
+
@Select
(
"SELECT a.FILE_PATH, "
+
"c.DEST_IATA_CODE, "
+
"c.CONSIGNMENT_CODE, "
+
"c.SHIPPER_CONTACT_NAME, "
+
"c.SHIPPER_EMAIL, "
+
"c.SHIPPER_PHONE, "
+
"c.SHIPPER_ACCOUNT, "
+
"c.ORIGIN_COUNTRY, "
+
"a.FILE_NAME "
+
"FROM T_BIZ_ATTACHMENT a "
+
"JOIN T_BIZ_CONSIGNMENT c ON a.BIZ_ID = c.ID "
+
"WHERE a.BIZ_ID = #{bizId,jdbcType=NUMERIC}"
)
"JOIN T_BIZ_UPLOAD_RECORD ur ON a.UPLOAD_RECORD_ID = ur.ID "
+
"JOIN T_BIZ_CONSIGNMENT c ON ur.CONSIGNMENT_ID = c.ID "
+
"WHERE a.UPLOAD_RECORD_ID = #{bizId,jdbcType=NUMERIC}"
)
List
<
PushZipEmailDto
>
findAttachmentDetailsByBizId
(
@Param
(
"bizId"
)
Long
bizId
);
@Select
(
"SELECT * FROM T_BIZ_ATTACHMENT WHERE UPLOAD_RECORD_ID = #{uploadRecordId,jdbcType=NUMERIC} AND BIZ_ID = #{consignmentId,jdbcType=NUMERIC} AND STATUS = 1"
)
...
...
server/task-schedule/src/main/java/com/fedex/connect/task/service/biz/impl/PushConsignmentFileServiceImpl.java
View file @
ab4fcdf
...
...
@@ -61,22 +61,23 @@ public class PushConsignmentFileServiceImpl extends BaseService implements IPush
for
(
Email
conPushEmail
:
conPushEmails
)
{
boolean
result
=
true
;
String
filePath
=
null
;
MailConfigDto
mailMessageReqDto
=
new
MailConfigDto
();
try
{
//获取待发送的文件并打zip包
PortFileDto
portFileDto
=
new
PortFileDto
();
List
<
PushZipEmailDto
>
attachmentDetailsByBizId
=
attachmentExtRepository
.
findAttachmentDetailsByBizId
(
conPushEmail
.
getBizId
());
portFileDto
=
conFileEmailUtil
.
getPortZipMap
(
portFileDto
,
attachmentDetailsByBizId
,
tempPath
,
finalPath
,
zipUtils
);
//发送邮件
MailConfigDto
mailMessageReqDto
=
new
MailConfigDto
();
result
=
conFileEmailUtil
.
sendEmail
(
portFileDto
,
emailUtil
,
mailMessageReqDto
,
conPushEmail
);
//根据是否成功发送邮件对文件进行备份
String
filePath
=
conFileEmailUtil
.
backFile
(
portFileDto
.
getZipPath
(),
nioFileUtils
,
result
);
//更新邮件记录表
conFileEmailUtil
.
createEmail
(
cacheSystem
,
conPushEmail
,
mailMessageReqDto
,
result
,
filePath
);
filePath
=
conFileEmailUtil
.
backFile
(
portFileDto
.
getZipPath
(),
nioFileUtils
,
conPushEmail
);
}
catch
(
Exception
e
){
log
.
error
(
"推送清关文件邮件异常"
,
e
);
result
=
false
;
}
//更新邮件记录表
conFileEmailUtil
.
createEmail
(
cacheSystem
,
conPushEmail
,
mailMessageReqDto
,
result
,
filePath
);
//保存入库
conFileEmailUtil
.
saveEmail
(
conPushEmail
,
result
);
}
...
...
server/task-schedule/src/main/java/com/fedex/connect/task/utils/sys/ConFileEmailUtil.java
View file @
ab4fcdf
...
...
@@ -73,7 +73,7 @@ public class ConFileEmailUtil {
* @param zipUtils
* @return void
*/
public
PortFileDto
getPortZipMap
(
PortFileDto
portFileDto
,
List
<
PushZipEmailDto
>
attachmentDetailsByBizId
,
String
tempPath
,
String
finalPath
,
ZipUtils
zipUtils
){
public
PortFileDto
getPortZipMap
(
PortFileDto
portFileDto
,
List
<
PushZipEmailDto
>
attachmentDetailsByBizId
,
String
tempPath
,
String
finalPath
,
ZipUtils
zipUtils
)
throws
Exception
{
List
<
File
>
filesList
=
new
ArrayList
<>();
String
portCode
=
null
;
for
(
PushZipEmailDto
pushZipEmailDto
:
attachmentDetailsByBizId
)
{
...
...
@@ -81,7 +81,7 @@ public class ConFileEmailUtil {
if
(
pushZipEmailDto
.
getDestIataCode
()
==
null
||
pushZipEmailDto
.
getDestIataCode
().
isEmpty
())
{
portCode
=
BaseConstants
.
CONSIGNMENT_TABLE_COLUMN_KEYS
.
DEST_IATA_CODE
;
// 使用 "destTataCode" 代替空口岸
}
File
file
=
new
File
(
pushZipEmailDto
.
getFilePath
());
File
file
=
new
File
(
pushZipEmailDto
.
getFilePath
()
+
File
.
separator
+
pushZipEmailDto
.
getFileName
()
);
if
(
file
.
exists
())
{
filesList
.
add
(
file
);
}
...
...
@@ -115,6 +115,7 @@ public class ConFileEmailUtil {
}
catch
(
Exception
e
)
{
log
.
error
(
"生成压缩包错误:{}"
,
e
.
getMessage
(),
e
);
throw
e
;
}
finally
{
try
{
if
(
fos
!=
null
)
{
...
...
@@ -173,7 +174,7 @@ public class ConFileEmailUtil {
//ce接收人
mailConfigDto
.
setTo
(
emailAddress
);
//设置邮件标题
mailConfigDto
.
setSubject
(
clearanceEmailTemplate
.
getTitle
()
);
mailConfigDto
.
setSubject
(
"推送预清关文件"
);
//设置邮件内容
String
body
=
this
.
generateContent
(
"zelong.shao@erry.com"
,
propertiesConfig
.
getEmailAccount
(),
portFileDto
,
conPushEmail
.
getBizCode
());
mailConfigDto
.
setContent
(
body
);
...
...
@@ -189,8 +190,8 @@ public class ConFileEmailUtil {
||
propertiesConfig
.
getEnv
().
equalsIgnoreCase
(
"test"
)
)
{
//ce接收人
mailConfigDto
.
setTo
(
"
zelong.shao
@erry.com"
);
mailConfigDto
.
setCcAccount
(
""
);
mailConfigDto
.
setTo
(
"
jialiang.song
@erry.com"
);
mailConfigDto
.
setCcAccount
(
"
jialiang.song@erry.com
"
);
mailConfigDto
.
setReceiveAccount
(
"zelong.shao@erry.com"
);
//发件人
mailConfigDto
.
setFrom
(
propertiesConfig
.
getEmailAccount
());
...
...
@@ -211,24 +212,24 @@ public class ConFileEmailUtil {
StringBuilder
content
=
new
StringBuilder
();
content
.
append
(
"<font size=\"4\"><br/> "
);
content
.
append
(
"
Tracking Number
"
+
":"
+
Optional
.
ofNullable
(
consignmentCode
).
orElse
(
""
));
content
.
append
(
"
运单号
"
+
":"
+
Optional
.
ofNullable
(
consignmentCode
).
orElse
(
""
));
content
.
append
(
"<br/> "
);
content
.
append
(
"Shipper Account"
+
":"
+
Optional
.
ofNullable
(
portFileDto
.
getShipperAccount
()).
orElse
(
""
));
content
.
append
(
"<br/> "
);
content
.
append
(
"
Origin Country/Territory
"
+
":"
+
Optional
.
ofNullable
(
portFileDto
.
getOriginCountry
()).
orElse
(
""
));
content
.
append
(
"
原产国
"
+
":"
+
Optional
.
ofNullable
(
portFileDto
.
getOriginCountry
()).
orElse
(
""
));
content
.
append
(
"<br/> "
);
content
.
append
(
"
Shipper
"
+
":"
+
Optional
.
ofNullable
(
portFileDto
.
getShipperContactName
()).
orElse
(
""
));
content
.
append
(
"
发件人
"
+
":"
+
Optional
.
ofNullable
(
portFileDto
.
getShipperContactName
()).
orElse
(
""
));
content
.
append
(
"<br/> "
);
content
.
append
(
"
Shipper Email
"
+
":"
+
Optional
.
ofNullable
(
portFileDto
.
getShipperEmail
()).
orElse
(
""
));
content
.
append
(
"
发件人邮箱
"
+
":"
+
Optional
.
ofNullable
(
portFileDto
.
getShipperEmail
()).
orElse
(
""
));
content
.
append
(
"<br/> "
);
content
.
append
(
"</font><br/><br/> "
);
content
.
append
(
"<div style=\"color:#808080;font-style:Arial;font-size:14px;\">"
+
"
This email was to send declaration files uploaded by customer on the FedEx iClear Connect System platform to
"
+
"
这封电子邮件是将客户在 FedEx iClear Connect System 平台上上传的报关文件通过
"
+
Optional
.
ofNullable
(
to
).
orElse
(
"zelong.shao@erry.com"
)
+
"
through
"
+
"
发送给
"
+
Optional
.
ofNullable
(
from
).
orElse
(
"tao.mo@erry.com"
)
+
"
, please do not reply
</div>"
);
"
,请勿回复
</div>"
);
return
content
.
toString
();
}
...
...
@@ -272,16 +273,16 @@ public class ConFileEmailUtil {
conPushEmail
.
setFilePath
(
filePath
);
//如果失败次数小于三则更新为待处理,继续处理
if
(
result
){
conPushEmail
.
set
Type
Code
(
success
.
getCode
());
conPushEmail
.
set
Type
Name
(
success
.
getDescription
());
conPushEmail
.
set
Status
Code
(
success
.
getCode
());
conPushEmail
.
set
Status
Name
(
success
.
getDescription
());
}
else
{
if
(
conPushEmail
.
getSendNum
()<
3
){
conPushEmail
.
set
Type
Code
(
pending
.
getCode
());
conPushEmail
.
set
Type
Name
(
pending
.
getDescription
());
conPushEmail
.
set
Status
Code
(
pending
.
getCode
());
conPushEmail
.
set
Status
Name
(
pending
.
getDescription
());
conPushEmail
.
setSendNum
(
conPushEmail
.
getSendNum
()+
1
);
}
else
{
conPushEmail
.
set
Type
Code
(
failed
.
getCode
());
conPushEmail
.
set
Type
Name
(
failed
.
getDescription
());
conPushEmail
.
set
Status
Code
(
failed
.
getCode
());
conPushEmail
.
set
Status
Name
(
failed
.
getDescription
());
}
}
}
...
...
@@ -292,37 +293,44 @@ public class ConFileEmailUtil {
* @Date 2024/11/18
* @param filePath
* @param nioFileUtils
* @param result
* @return java.lang.String
*/
public
String
backFile
(
String
filePath
,
NIOFileUtils
nioFileUtils
,
boolean
result
){
public
String
backFile
(
String
filePath
,
NIOFileUtils
nioFileUtils
,
Email
conPushEmail
){
File
file
=
new
File
(
filePath
);
String
targetDirPath
=
null
;
try
{
// 获取文件的扩展名
String
extension
=
filePath
.
substring
(
filePath
.
lastIndexOf
(
"."
));
String
fileNameOld
=
file
.
getName
();
// 使用 getName() 获取文件名
// 生成新的文件名
String
fileName
=
String
.
format
(
"%s%s%s%s"
,
""
,
""
,
DateUtil
.
yyyyMMddHHmmss
(
new
Date
()),
extension
);
String
basePath
=
""
;
String
timeStamp
=
DateUtil
.
yyyyMMddHHmmss
(
new
Date
());
String
fileName
=
String
.
format
(
"%s%s%s"
,
fileNameOld
,
timeStamp
,
extension
);
// 构建目标文件路径
targetDirPath
=
String
.
join
(
File
.
separator
,
basePath
,
propertiesConfig
.
getZipPath
(),
DateUtil
.
format
(
new
Date
()),
// 使用提前生成的时间戳,避免重复计算
conPushEmail
.
getBizCode
(),
fileName
);
// 获取目标目录,并创建目录(如果不存在)
File
targetDir
=
new
File
(
targetDirPath
).
getParentFile
();
if
(!
targetDir
.
exists
()
&&
targetDir
.
mkdirs
())
{
// 复制文件
nioFileUtils
.
copyFile
(
file
,
targetDirPath
);
// 删除临时文件
nioFileUtils
.
deleteTempFile
(
Paths
.
get
(
filePath
));
}
}
catch
(
Exception
e
)
{
String
errorMsg
=
String
.
format
(
"文件复制失败:%s,portId:%s,fileName:%s"
,
e
.
getMessage
());
// 错误处理
// 记录错误信息
String
errorMsg
=
String
.
format
(
"文件复制失败: %s, filePath: %s"
,
e
.
getMessage
(),
filePath
);
log
.
error
(
errorMsg
,
e
);
}
// 返回目标路径
return
targetDirPath
;
}
...
...
@@ -341,11 +349,13 @@ public class ConFileEmailUtil {
if
(
result
){
//成功后需要将业务表数据删除,保存至历史表
emailRepository
.
deleteById
(
conPushEmail
.
getId
());
emailHistory
.
setId
(
null
);
emailHistoryRepository
.
saveOrUpdate
(
emailHistory
);
}
else
{
//失败则根据是否第三次,如果是第三次失败则删除,保存到历史表
if
(
conPushEmail
.
getSendNum
()
==
3
){
emailRepository
.
deleteById
(
conPushEmail
.
getId
());
emailHistory
.
setId
(
null
);
emailHistoryRepository
.
saveOrUpdate
(
emailHistory
);
}
else
{
emailRepository
.
saveOrUpdate
(
conPushEmail
);
...
...
server/task-schedule/src/main/resources/application-dev.yml
View file @
ab4fcdf
...
...
@@ -53,3 +53,7 @@ imp001:
bak
:
${imp001.path.basePath}BAK/
#异常目录
error
:
${imp001.path.basePath}ERROR/
upload
:
path
:
zip
:
/app/Oracle/Middleware/user_projects/domains/base_domain/iclearConnect/upload/zip
\ No newline at end of file
...
...
server/task-schedule/src/main/resources/application-test.yml
View file @
ab4fcdf
...
...
@@ -49,3 +49,7 @@ imp001:
bak
:
${imp001.path.basePath}BAK/
#异常目录
error
:
${imp001.path.basePath}ERROR/
upload
:
path
:
zip
:
/app/Oracle/Middleware/user_projects/domains/base_domain/iclearConnect/upload/zip
\ No newline at end of file
...
...
Please
register
or
login
to post a comment