zelong.shao

task|邮件调整

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, User user) throws Exception;
void savePushConsignmentFileEmail(Consignment consignment, UploadRecord uploadRecord) throws Exception;
}
......
......@@ -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);
/**
* 保存入库
*/
......
......@@ -293,7 +293,7 @@ public class ConsignmentUtil {
/**
* 初始化插入预清关文件邮件推送日志
*/
emailService.savePushConsignmentFileEmail(consignment,user);
emailService.savePushConsignmentFileEmail(consignment,uploadRecord);
/**
* 推送进口文件主表
*/
......
......@@ -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)
......
......@@ -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
......
......@@ -10,4 +10,5 @@ public class PushZipEmailDto {
private String shipperPhone;
private String shipperAccount;
private String originCountry;
private String fileName;
}
......
......@@ -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")
......
......@@ -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);
}
......
......@@ -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.setTypeCode(success.getCode());
conPushEmail.setTypeName(success.getDescription());
conPushEmail.setStatusCode(success.getCode());
conPushEmail.setStatusName(success.getDescription());
}else {
if (conPushEmail.getSendNum()<3){
conPushEmail.setTypeCode(pending.getCode());
conPushEmail.setTypeName(pending.getDescription());
conPushEmail.setStatusCode(pending.getCode());
conPushEmail.setStatusName(pending.getDescription());
conPushEmail.setSendNum(conPushEmail.getSendNum()+1);
}else {
conPushEmail.setTypeCode(failed.getCode());
conPushEmail.setTypeName(failed.getDescription());
conPushEmail.setStatusCode(failed.getCode());
conPushEmail.setStatusName(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
);
// 复制文件
nioFileUtils.copyFile(file, targetDirPath);
nioFileUtils.deleteTempFile(Paths.get(filePath));
// 获取目标目录,并创建目录(如果不存在)
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);
......
......@@ -52,4 +52,8 @@ imp001:
#备份目录
bak: ${imp001.path.basePath}BAK/
#异常目录
error: ${imp001.path.basePath}ERROR/
\ No newline at end of file
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
......
......@@ -48,4 +48,8 @@ imp001:
#备份目录
bak: ${imp001.path.basePath}BAK/
#异常目录
error: ${imp001.path.basePath}ERROR/
\ No newline at end of file
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
......