Showing
11 changed files
with
84 additions
and
52 deletions
| 1 | package com.fedex.connect.customer.service.biz; | 1 | package com.fedex.connect.customer.service.biz; |
| 2 | 2 | ||
| 3 | import com.fedex.connect.common.model.biz.Consignment; | 3 | import com.fedex.connect.common.model.biz.Consignment; |
| 4 | +import com.fedex.connect.common.model.biz.UploadRecord; | ||
| 4 | import com.fedex.connect.common.model.sys.User; | 5 | import com.fedex.connect.common.model.sys.User; |
| 5 | 6 | ||
| 6 | public interface IEmailService { | 7 | public interface IEmailService { |
| 7 | void saveNotificationEmail(Consignment consignment, User user) throws Exception; | 8 | void saveNotificationEmail(Consignment consignment, User user) throws Exception; |
| 8 | 9 | ||
| 9 | - void savePushConsignmentFileEmail(Consignment consignment, User user) throws Exception; | 10 | + void savePushConsignmentFileEmail(Consignment consignment, UploadRecord uploadRecord) throws Exception; |
| 10 | } | 11 | } | ... | ... |
| ... | @@ -2,6 +2,7 @@ package com.fedex.connect.customer.service.biz.impl; | ... | @@ -2,6 +2,7 @@ package com.fedex.connect.customer.service.biz.impl; |
| 2 | 2 | ||
| 3 | import com.fedex.connect.common.model.biz.Consignment; | 3 | import com.fedex.connect.common.model.biz.Consignment; |
| 4 | import com.fedex.connect.common.model.biz.Email; | 4 | import com.fedex.connect.common.model.biz.Email; |
| 5 | +import com.fedex.connect.common.model.biz.UploadRecord; | ||
| 5 | import com.fedex.connect.common.model.sys.User; | 6 | import com.fedex.connect.common.model.sys.User; |
| 6 | import com.fedex.connect.customer.service.base.BaseService; | 7 | import com.fedex.connect.customer.service.base.BaseService; |
| 7 | import com.fedex.connect.customer.service.biz.IEmailService; | 8 | import com.fedex.connect.customer.service.biz.IEmailService; |
| ... | @@ -41,15 +42,12 @@ public class EmailServiceImpl extends BaseService implements IEmailService { | ... | @@ -41,15 +42,12 @@ public class EmailServiceImpl extends BaseService implements IEmailService { |
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | @Override | 44 | @Override |
| 44 | - public void savePushConsignmentFileEmail(Consignment consignment, User user) throws Exception { | 45 | + public void savePushConsignmentFileEmail(Consignment consignment,UploadRecord uploadRecord) throws Exception { |
| 45 | - if (!StringUtils.isEmpty(consignment.getUserUuid()) && consignment.getUserUuid().equals(user.getUserUuid())){ | ||
| 46 | - return; | ||
| 47 | - } | ||
| 48 | /** | 46 | /** |
| 49 | * 初始化Email对象 | 47 | * 初始化Email对象 |
| 50 | */ | 48 | */ |
| 51 | Email email = new Email(); | 49 | Email email = new Email(); |
| 52 | - emailUtil.initPushConsignmentFileEmail(email,consignment); | 50 | + emailUtil.initPushConsignmentFileEmail(email,consignment, uploadRecord); |
| 53 | /** | 51 | /** |
| 54 | * 保存入库 | 52 | * 保存入库 |
| 55 | */ | 53 | */ | ... | ... |
| ... | @@ -293,7 +293,7 @@ public class ConsignmentUtil { | ... | @@ -293,7 +293,7 @@ public class ConsignmentUtil { |
| 293 | /** | 293 | /** |
| 294 | * 初始化插入预清关文件邮件推送日志 | 294 | * 初始化插入预清关文件邮件推送日志 |
| 295 | */ | 295 | */ |
| 296 | - emailService.savePushConsignmentFileEmail(consignment,user); | 296 | + emailService.savePushConsignmentFileEmail(consignment,uploadRecord); |
| 297 | /** | 297 | /** |
| 298 | * 推送进口文件主表 | 298 | * 推送进口文件主表 |
| 299 | */ | 299 | */ | ... | ... |
| ... | @@ -5,6 +5,7 @@ import com.fedex.connect.common.dependencies.enums.biz.EmailTypeEnum; | ... | @@ -5,6 +5,7 @@ import com.fedex.connect.common.dependencies.enums.biz.EmailTypeEnum; |
| 5 | import com.fedex.connect.common.dependencies.util.AssignmentFieldUtils; | 5 | import com.fedex.connect.common.dependencies.util.AssignmentFieldUtils; |
| 6 | import com.fedex.connect.common.model.biz.Consignment; | 6 | import com.fedex.connect.common.model.biz.Consignment; |
| 7 | import com.fedex.connect.common.model.biz.Email; | 7 | import com.fedex.connect.common.model.biz.Email; |
| 8 | +import com.fedex.connect.common.model.biz.UploadRecord; | ||
| 8 | import com.fedex.connect.customer.repository.repo.IUserRepository; | 9 | import com.fedex.connect.customer.repository.repo.IUserRepository; |
| 9 | import org.apache.commons.lang3.StringUtils; | 10 | import org.apache.commons.lang3.StringUtils; |
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| ... | @@ -33,8 +34,8 @@ public class EmailUtil { | ... | @@ -33,8 +34,8 @@ public class EmailUtil { |
| 33 | AssignmentFieldUtils.assignmentTableBaseField(email); | 34 | AssignmentFieldUtils.assignmentTableBaseField(email); |
| 34 | } | 35 | } |
| 35 | 36 | ||
| 36 | - public void initPushConsignmentFileEmail(Email email, Consignment consignment) throws Exception{ | 37 | + public void initPushConsignmentFileEmail(Email email, Consignment consignment,UploadRecord uploadRecord) throws Exception{ |
| 37 | - email.setBizId(consignment.getId()); | 38 | + email.setBizId(uploadRecord.getId()); |
| 38 | email.setBizCode(consignment.getConsignmentCode()); | 39 | email.setBizCode(consignment.getConsignmentCode()); |
| 39 | String emailAddress = Optional.ofNullable(consignment.getUserUuid()) | 40 | String emailAddress = Optional.ofNullable(consignment.getUserUuid()) |
| 40 | .map(iUserRepository::findUserByUuid) | 41 | .map(iUserRepository::findUserByUuid) | ... | ... |
| ... | @@ -79,4 +79,7 @@ public class PropertiesConfig { | ... | @@ -79,4 +79,7 @@ public class PropertiesConfig { |
| 79 | //文件异常文件存放目录 | 79 | //文件异常文件存放目录 |
| 80 | @Value("${imp001.path.error}") | 80 | @Value("${imp001.path.error}") |
| 81 | String imp001PathError; | 81 | String imp001PathError; |
| 82 | + | ||
| 83 | + @Value("${upload.path.zip}") | ||
| 84 | + private String zipPath; | ||
| 82 | } | 85 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -10,4 +10,5 @@ public class PushZipEmailDto { | ... | @@ -10,4 +10,5 @@ public class PushZipEmailDto { |
| 10 | private String shipperPhone; | 10 | private String shipperPhone; |
| 11 | private String shipperAccount; | 11 | private String shipperAccount; |
| 12 | private String originCountry; | 12 | private String originCountry; |
| 13 | + private String fileName; | ||
| 13 | } | 14 | } | ... | ... |
| ... | @@ -9,10 +9,19 @@ import java.util.List; | ... | @@ -9,10 +9,19 @@ import java.util.List; |
| 9 | @Mapper | 9 | @Mapper |
| 10 | public interface AttachmentExtMapper { | 10 | public interface AttachmentExtMapper { |
| 11 | 11 | ||
| 12 | - @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 " + | 12 | + @Select("SELECT a.FILE_PATH, " + |
| 13 | + "c.DEST_IATA_CODE, " + | ||
| 14 | + "c.CONSIGNMENT_CODE, " + | ||
| 15 | + "c.SHIPPER_CONTACT_NAME, " + | ||
| 16 | + "c.SHIPPER_EMAIL, " + | ||
| 17 | + "c.SHIPPER_PHONE, " + | ||
| 18 | + "c.SHIPPER_ACCOUNT, " + | ||
| 19 | + "c.ORIGIN_COUNTRY, " + | ||
| 20 | + "a.FILE_NAME " + | ||
| 13 | "FROM T_BIZ_ATTACHMENT a " + | 21 | "FROM T_BIZ_ATTACHMENT a " + |
| 14 | - "JOIN T_BIZ_CONSIGNMENT c ON a.BIZ_ID = c.ID " + | 22 | + "JOIN T_BIZ_UPLOAD_RECORD ur ON a.UPLOAD_RECORD_ID = ur.ID " + |
| 15 | - "WHERE a.BIZ_ID = #{bizId,jdbcType=NUMERIC}") | 23 | + "JOIN T_BIZ_CONSIGNMENT c ON ur.CONSIGNMENT_ID = c.ID " + |
| 24 | + "WHERE a.UPLOAD_RECORD_ID = #{bizId,jdbcType=NUMERIC}") | ||
| 16 | List<PushZipEmailDto> findAttachmentDetailsByBizId(@Param("bizId") Long bizId); | 25 | List<PushZipEmailDto> findAttachmentDetailsByBizId(@Param("bizId") Long bizId); |
| 17 | 26 | ||
| 18 | @Select("SELECT * FROM T_BIZ_ATTACHMENT WHERE UPLOAD_RECORD_ID = #{uploadRecordId,jdbcType=NUMERIC} AND BIZ_ID = #{consignmentId,jdbcType=NUMERIC} AND STATUS = 1") | 27 | @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 | ... | @@ -61,22 +61,23 @@ public class PushConsignmentFileServiceImpl extends BaseService implements IPush |
| 61 | 61 | ||
| 62 | for (Email conPushEmail : conPushEmails) { | 62 | for (Email conPushEmail : conPushEmails) { |
| 63 | boolean result = true; | 63 | boolean result = true; |
| 64 | + String filePath = null; | ||
| 65 | + MailConfigDto mailMessageReqDto = new MailConfigDto(); | ||
| 64 | try { | 66 | try { |
| 65 | //获取待发送的文件并打zip包 | 67 | //获取待发送的文件并打zip包 |
| 66 | PortFileDto portFileDto = new PortFileDto(); | 68 | PortFileDto portFileDto = new PortFileDto(); |
| 67 | List<PushZipEmailDto> attachmentDetailsByBizId = attachmentExtRepository.findAttachmentDetailsByBizId(conPushEmail.getBizId()); | 69 | List<PushZipEmailDto> attachmentDetailsByBizId = attachmentExtRepository.findAttachmentDetailsByBizId(conPushEmail.getBizId()); |
| 68 | portFileDto = conFileEmailUtil.getPortZipMap(portFileDto, attachmentDetailsByBizId, tempPath, finalPath, zipUtils); | 70 | portFileDto = conFileEmailUtil.getPortZipMap(portFileDto, attachmentDetailsByBizId, tempPath, finalPath, zipUtils); |
| 69 | //发送邮件 | 71 | //发送邮件 |
| 70 | - MailConfigDto mailMessageReqDto = new MailConfigDto(); | ||
| 71 | result = conFileEmailUtil.sendEmail(portFileDto, emailUtil,mailMessageReqDto,conPushEmail); | 72 | result = conFileEmailUtil.sendEmail(portFileDto, emailUtil,mailMessageReqDto,conPushEmail); |
| 72 | //根据是否成功发送邮件对文件进行备份 | 73 | //根据是否成功发送邮件对文件进行备份 |
| 73 | - String filePath = conFileEmailUtil.backFile(portFileDto.getZipPath(), nioFileUtils,result); | 74 | + filePath = conFileEmailUtil.backFile(portFileDto.getZipPath(), nioFileUtils, conPushEmail); |
| 74 | - //更新邮件记录表 | ||
| 75 | - conFileEmailUtil.createEmail(cacheSystem,conPushEmail,mailMessageReqDto,result,filePath); | ||
| 76 | }catch (Exception e){ | 75 | }catch (Exception e){ |
| 77 | log.error("推送清关文件邮件异常",e); | 76 | log.error("推送清关文件邮件异常",e); |
| 78 | result = false; | 77 | result = false; |
| 79 | } | 78 | } |
| 79 | + //更新邮件记录表 | ||
| 80 | + conFileEmailUtil.createEmail(cacheSystem,conPushEmail,mailMessageReqDto,result,filePath); | ||
| 80 | //保存入库 | 81 | //保存入库 |
| 81 | conFileEmailUtil.saveEmail(conPushEmail,result); | 82 | conFileEmailUtil.saveEmail(conPushEmail,result); |
| 82 | } | 83 | } | ... | ... |
| ... | @@ -73,7 +73,7 @@ public class ConFileEmailUtil { | ... | @@ -73,7 +73,7 @@ public class ConFileEmailUtil { |
| 73 | * @param zipUtils | 73 | * @param zipUtils |
| 74 | * @return void | 74 | * @return void |
| 75 | */ | 75 | */ |
| 76 | - public PortFileDto getPortZipMap(PortFileDto portFileDto, List<PushZipEmailDto> attachmentDetailsByBizId, String tempPath, String finalPath, ZipUtils zipUtils){ | 76 | + public PortFileDto getPortZipMap(PortFileDto portFileDto, List<PushZipEmailDto> attachmentDetailsByBizId, String tempPath, String finalPath, ZipUtils zipUtils) throws Exception{ |
| 77 | List<File> filesList = new ArrayList<>(); | 77 | List<File> filesList = new ArrayList<>(); |
| 78 | String portCode = null; | 78 | String portCode = null; |
| 79 | for (PushZipEmailDto pushZipEmailDto : attachmentDetailsByBizId) { | 79 | for (PushZipEmailDto pushZipEmailDto : attachmentDetailsByBizId) { |
| ... | @@ -81,7 +81,7 @@ public class ConFileEmailUtil { | ... | @@ -81,7 +81,7 @@ public class ConFileEmailUtil { |
| 81 | if (pushZipEmailDto.getDestIataCode() == null || pushZipEmailDto.getDestIataCode().isEmpty()) { | 81 | if (pushZipEmailDto.getDestIataCode() == null || pushZipEmailDto.getDestIataCode().isEmpty()) { |
| 82 | portCode = BaseConstants.CONSIGNMENT_TABLE_COLUMN_KEYS.DEST_IATA_CODE; // 使用 "destTataCode" 代替空口岸 | 82 | portCode = BaseConstants.CONSIGNMENT_TABLE_COLUMN_KEYS.DEST_IATA_CODE; // 使用 "destTataCode" 代替空口岸 |
| 83 | } | 83 | } |
| 84 | - File file = new File(pushZipEmailDto.getFilePath()); | 84 | + File file = new File(pushZipEmailDto.getFilePath()+File.separator+pushZipEmailDto.getFileName()); |
| 85 | if (file.exists()) { | 85 | if (file.exists()) { |
| 86 | filesList.add(file); | 86 | filesList.add(file); |
| 87 | } | 87 | } |
| ... | @@ -115,6 +115,7 @@ public class ConFileEmailUtil { | ... | @@ -115,6 +115,7 @@ public class ConFileEmailUtil { |
| 115 | 115 | ||
| 116 | } catch (Exception e) { | 116 | } catch (Exception e) { |
| 117 | log.error("生成压缩包错误:{}", e.getMessage(), e); | 117 | log.error("生成压缩包错误:{}", e.getMessage(), e); |
| 118 | + throw e; | ||
| 118 | } finally { | 119 | } finally { |
| 119 | try { | 120 | try { |
| 120 | if (fos != null) { | 121 | if (fos != null) { |
| ... | @@ -173,7 +174,7 @@ public class ConFileEmailUtil { | ... | @@ -173,7 +174,7 @@ public class ConFileEmailUtil { |
| 173 | //ce接收人 | 174 | //ce接收人 |
| 174 | mailConfigDto.setTo(emailAddress); | 175 | mailConfigDto.setTo(emailAddress); |
| 175 | //设置邮件标题 | 176 | //设置邮件标题 |
| 176 | - mailConfigDto.setSubject(clearanceEmailTemplate.getTitle()); | 177 | + mailConfigDto.setSubject("推送预清关文件"); |
| 177 | //设置邮件内容 | 178 | //设置邮件内容 |
| 178 | String body = this.generateContent("zelong.shao@erry.com", propertiesConfig.getEmailAccount(), portFileDto, conPushEmail.getBizCode()); | 179 | String body = this.generateContent("zelong.shao@erry.com", propertiesConfig.getEmailAccount(), portFileDto, conPushEmail.getBizCode()); |
| 179 | mailConfigDto.setContent(body); | 180 | mailConfigDto.setContent(body); |
| ... | @@ -189,8 +190,8 @@ public class ConFileEmailUtil { | ... | @@ -189,8 +190,8 @@ public class ConFileEmailUtil { |
| 189 | || propertiesConfig.getEnv().equalsIgnoreCase("test") | 190 | || propertiesConfig.getEnv().equalsIgnoreCase("test") |
| 190 | ) { | 191 | ) { |
| 191 | //ce接收人 | 192 | //ce接收人 |
| 192 | - mailConfigDto.setTo("zelong.shao@erry.com"); | 193 | + mailConfigDto.setTo("jialiang.song@erry.com"); |
| 193 | - mailConfigDto.setCcAccount(""); | 194 | + mailConfigDto.setCcAccount("jialiang.song@erry.com"); |
| 194 | mailConfigDto.setReceiveAccount("zelong.shao@erry.com"); | 195 | mailConfigDto.setReceiveAccount("zelong.shao@erry.com"); |
| 195 | //发件人 | 196 | //发件人 |
| 196 | mailConfigDto.setFrom(propertiesConfig.getEmailAccount()); | 197 | mailConfigDto.setFrom(propertiesConfig.getEmailAccount()); |
| ... | @@ -211,24 +212,24 @@ public class ConFileEmailUtil { | ... | @@ -211,24 +212,24 @@ public class ConFileEmailUtil { |
| 211 | 212 | ||
| 212 | StringBuilder content = new StringBuilder(); | 213 | StringBuilder content = new StringBuilder(); |
| 213 | content.append("<font size=\"4\"><br/> " ); | 214 | content.append("<font size=\"4\"><br/> " ); |
| 214 | - content.append("Tracking Number" + ":" + Optional.ofNullable(consignmentCode).orElse("")); | 215 | + content.append("运单号" + ":" + Optional.ofNullable(consignmentCode).orElse("")); |
| 215 | content.append("<br/> " ); | 216 | content.append("<br/> " ); |
| 216 | content.append("Shipper Account" + ":" + Optional.ofNullable(portFileDto.getShipperAccount()).orElse("")); | 217 | content.append("Shipper Account" + ":" + Optional.ofNullable(portFileDto.getShipperAccount()).orElse("")); |
| 217 | content.append("<br/> " ); | 218 | content.append("<br/> " ); |
| 218 | - content.append("Origin Country/Territory" + ":" + Optional.ofNullable(portFileDto.getOriginCountry()).orElse("")); | 219 | + content.append("原产国" + ":" + Optional.ofNullable(portFileDto.getOriginCountry()).orElse("")); |
| 219 | content.append("<br/> " ); | 220 | content.append("<br/> " ); |
| 220 | - content.append("Shipper" + ":" + Optional.ofNullable(portFileDto.getShipperContactName()).orElse("")); | 221 | + content.append("发件人" + ":" + Optional.ofNullable(portFileDto.getShipperContactName()).orElse("")); |
| 221 | content.append("<br/> " ); | 222 | content.append("<br/> " ); |
| 222 | - content.append("Shipper Email" + ":" + Optional.ofNullable(portFileDto.getShipperEmail()).orElse("")); | 223 | + content.append("发件人邮箱" + ":" + Optional.ofNullable(portFileDto.getShipperEmail()).orElse("")); |
| 223 | content.append("<br/> " ); | 224 | content.append("<br/> " ); |
| 224 | 225 | ||
| 225 | content.append("</font><br/><br/> " ); | 226 | content.append("</font><br/><br/> " ); |
| 226 | content.append("<div style=\"color:#808080;font-style:Arial;font-size:14px;\">" + | 227 | content.append("<div style=\"color:#808080;font-style:Arial;font-size:14px;\">" + |
| 227 | - "This email was to send declaration files uploaded by customer on the FedEx iClear Connect System platform to " + | 228 | + "这封电子邮件是将客户在 FedEx iClear Connect System 平台上上传的报关文件通过" + |
| 228 | Optional.ofNullable(to).orElse("zelong.shao@erry.com") + | 229 | Optional.ofNullable(to).orElse("zelong.shao@erry.com") + |
| 229 | - " through " + | 230 | + " 发送给 " + |
| 230 | Optional.ofNullable(from).orElse("tao.mo@erry.com") + | 231 | Optional.ofNullable(from).orElse("tao.mo@erry.com") + |
| 231 | - ", please do not reply</div>"); | 232 | + ",请勿回复</div>"); |
| 232 | return content.toString(); | 233 | return content.toString(); |
| 233 | } | 234 | } |
| 234 | 235 | ||
| ... | @@ -272,16 +273,16 @@ public class ConFileEmailUtil { | ... | @@ -272,16 +273,16 @@ public class ConFileEmailUtil { |
| 272 | conPushEmail.setFilePath(filePath); | 273 | conPushEmail.setFilePath(filePath); |
| 273 | //如果失败次数小于三则更新为待处理,继续处理 | 274 | //如果失败次数小于三则更新为待处理,继续处理 |
| 274 | if (result){ | 275 | if (result){ |
| 275 | - conPushEmail.setTypeCode(success.getCode()); | 276 | + conPushEmail.setStatusCode(success.getCode()); |
| 276 | - conPushEmail.setTypeName(success.getDescription()); | 277 | + conPushEmail.setStatusName(success.getDescription()); |
| 277 | }else { | 278 | }else { |
| 278 | if (conPushEmail.getSendNum()<3){ | 279 | if (conPushEmail.getSendNum()<3){ |
| 279 | - conPushEmail.setTypeCode(pending.getCode()); | 280 | + conPushEmail.setStatusCode(pending.getCode()); |
| 280 | - conPushEmail.setTypeName(pending.getDescription()); | 281 | + conPushEmail.setStatusName(pending.getDescription()); |
| 281 | conPushEmail.setSendNum(conPushEmail.getSendNum()+1); | 282 | conPushEmail.setSendNum(conPushEmail.getSendNum()+1); |
| 282 | }else { | 283 | }else { |
| 283 | - conPushEmail.setTypeCode(failed.getCode()); | 284 | + conPushEmail.setStatusCode(failed.getCode()); |
| 284 | - conPushEmail.setTypeName(failed.getDescription()); | 285 | + conPushEmail.setStatusName(failed.getDescription()); |
| 285 | } | 286 | } |
| 286 | } | 287 | } |
| 287 | } | 288 | } |
| ... | @@ -292,37 +293,44 @@ public class ConFileEmailUtil { | ... | @@ -292,37 +293,44 @@ public class ConFileEmailUtil { |
| 292 | * @Date 2024/11/18 | 293 | * @Date 2024/11/18 |
| 293 | * @param filePath | 294 | * @param filePath |
| 294 | * @param nioFileUtils | 295 | * @param nioFileUtils |
| 295 | - * @param result | ||
| 296 | * @return java.lang.String | 296 | * @return java.lang.String |
| 297 | */ | 297 | */ |
| 298 | - public String backFile(String filePath, NIOFileUtils nioFileUtils,boolean result){ | 298 | + public String backFile(String filePath, NIOFileUtils nioFileUtils,Email conPushEmail){ |
| 299 | File file = new File(filePath); | 299 | File file = new File(filePath); |
| 300 | String targetDirPath = null; | 300 | String targetDirPath = null; |
| 301 | + | ||
| 301 | try { | 302 | try { |
| 302 | // 获取文件的扩展名 | 303 | // 获取文件的扩展名 |
| 303 | String extension = filePath.substring(filePath.lastIndexOf(".")); | 304 | String extension = filePath.substring(filePath.lastIndexOf(".")); |
| 304 | - | 305 | + String fileNameOld = file.getName(); // 使用 getName() 获取文件名 |
| 305 | // 生成新的文件名 | 306 | // 生成新的文件名 |
| 306 | - String fileName = String.format("%s%s%s%s", | 307 | + String timeStamp = DateUtil.yyyyMMddHHmmss(new Date()); |
| 307 | - "", | 308 | + String fileName = String.format("%s%s%s", fileNameOld, timeStamp, extension); |
| 308 | - "", | 309 | + |
| 309 | - DateUtil.yyyyMMddHHmmss(new Date()), | ||
| 310 | - extension | ||
| 311 | - ); | ||
| 312 | - String basePath = ""; | ||
| 313 | // 构建目标文件路径 | 310 | // 构建目标文件路径 |
| 314 | targetDirPath = String.join(File.separator, | 311 | targetDirPath = String.join(File.separator, |
| 315 | - basePath, | 312 | + propertiesConfig.getZipPath(), |
| 313 | + DateUtil.format(new Date()), // 使用提前生成的时间戳,避免重复计算 | ||
| 314 | + conPushEmail.getBizCode(), | ||
| 316 | fileName | 315 | fileName |
| 317 | ); | 316 | ); |
| 318 | - // 复制文件 | 317 | + |
| 319 | - nioFileUtils.copyFile(file, targetDirPath); | 318 | + // 获取目标目录,并创建目录(如果不存在) |
| 320 | - nioFileUtils.deleteTempFile(Paths.get(filePath)); | 319 | + File targetDir = new File(targetDirPath).getParentFile(); |
| 320 | + if (!targetDir.exists() && targetDir.mkdirs()) { | ||
| 321 | + // 复制文件 | ||
| 322 | + nioFileUtils.copyFile(file, targetDirPath); | ||
| 323 | + | ||
| 324 | + // 删除临时文件 | ||
| 325 | + nioFileUtils.deleteTempFile(Paths.get(filePath)); | ||
| 326 | + } | ||
| 327 | + | ||
| 321 | } catch (Exception e) { | 328 | } catch (Exception e) { |
| 322 | - String errorMsg = String.format("文件复制失败:%s,portId:%s,fileName:%s", e.getMessage()); | 329 | + // 记录错误信息 |
| 323 | - // 错误处理 | 330 | + String errorMsg = String.format("文件复制失败: %s, filePath: %s", e.getMessage(), filePath); |
| 324 | log.error(errorMsg, e); | 331 | log.error(errorMsg, e); |
| 325 | } | 332 | } |
| 333 | + // 返回目标路径 | ||
| 326 | return targetDirPath; | 334 | return targetDirPath; |
| 327 | } | 335 | } |
| 328 | 336 | ||
| ... | @@ -341,11 +349,13 @@ public class ConFileEmailUtil { | ... | @@ -341,11 +349,13 @@ public class ConFileEmailUtil { |
| 341 | if (result){ | 349 | if (result){ |
| 342 | //成功后需要将业务表数据删除,保存至历史表 | 350 | //成功后需要将业务表数据删除,保存至历史表 |
| 343 | emailRepository.deleteById(conPushEmail.getId()); | 351 | emailRepository.deleteById(conPushEmail.getId()); |
| 352 | + emailHistory.setId(null); | ||
| 344 | emailHistoryRepository.saveOrUpdate(emailHistory); | 353 | emailHistoryRepository.saveOrUpdate(emailHistory); |
| 345 | }else { | 354 | }else { |
| 346 | //失败则根据是否第三次,如果是第三次失败则删除,保存到历史表 | 355 | //失败则根据是否第三次,如果是第三次失败则删除,保存到历史表 |
| 347 | if (conPushEmail.getSendNum() == 3){ | 356 | if (conPushEmail.getSendNum() == 3){ |
| 348 | emailRepository.deleteById(conPushEmail.getId()); | 357 | emailRepository.deleteById(conPushEmail.getId()); |
| 358 | + emailHistory.setId(null); | ||
| 349 | emailHistoryRepository.saveOrUpdate(emailHistory); | 359 | emailHistoryRepository.saveOrUpdate(emailHistory); |
| 350 | }else { | 360 | }else { |
| 351 | emailRepository.saveOrUpdate(conPushEmail); | 361 | emailRepository.saveOrUpdate(conPushEmail); | ... | ... |
| ... | @@ -52,4 +52,8 @@ imp001: | ... | @@ -52,4 +52,8 @@ imp001: |
| 52 | #备份目录 | 52 | #备份目录 |
| 53 | bak: ${imp001.path.basePath}BAK/ | 53 | bak: ${imp001.path.basePath}BAK/ |
| 54 | #异常目录 | 54 | #异常目录 |
| 55 | - error: ${imp001.path.basePath}ERROR/ | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 55 | + error: ${imp001.path.basePath}ERROR/ | ||
| 56 | + | ||
| 57 | +upload: | ||
| 58 | + path: | ||
| 59 | + zip: /app/Oracle/Middleware/user_projects/domains/base_domain/iclearConnect/upload/zip | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -48,4 +48,8 @@ imp001: | ... | @@ -48,4 +48,8 @@ imp001: |
| 48 | #备份目录 | 48 | #备份目录 |
| 49 | bak: ${imp001.path.basePath}BAK/ | 49 | bak: ${imp001.path.basePath}BAK/ |
| 50 | #异常目录 | 50 | #异常目录 |
| 51 | - error: ${imp001.path.basePath}ERROR/ | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 51 | + error: ${imp001.path.basePath}ERROR/ | ||
| 52 | + | ||
| 53 | +upload: | ||
| 54 | + path: | ||
| 55 | + zip: /app/Oracle/Middleware/user_projects/domains/base_domain/iclearConnect/upload/zip | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment