Ver código fonte

fix: 类型转换错误异常修复

chenjianhua 1 mês atrás
pai
commit
f1ed356481

+ 49 - 0
service-base/src/main/java/com/simuwang/base/common/util/ExcelUtil.java

@@ -275,10 +275,59 @@ public class ExcelUtil {
             }
             } catch (Exception e) {
                 logger.error(e.getMessage(),e);
+                //调用unrar命令解压
+                try{
+                    unrar(inputFilePath,outputDirPath);
+                    File dir  = new File(outputDirPath);
+                    for (File file : Objects.requireNonNull(dir.listFiles())) {
+                        logger.info(file.getAbsolutePath());
+                        fileList.add(file.getAbsolutePath());
+                    }
+                }catch (Exception e1){
+                    logger.error(e.getMessage(),e1);
+                }
+
             }
         return fileList;
     }
 
+    /**
+     * 解压RAR文件
+     * @param rarFilePath RAR文件路径
+     * @param destDir 目标解压目录
+     * @throws IOException 如果IO错误或解压失败
+     * @throws InterruptedException 如果进程被中断
+     */
+    public static void unrar(String rarFilePath, String destDir) throws IOException, InterruptedException {
+        // 确保目标目录存在
+        File destDirFile = new File(destDir);
+        if(!destDirFile.exists()){
+            destDirFile.mkdirs();
+        }
+        // 构建解压命令
+        ProcessBuilder processBuilder = new ProcessBuilder(
+                "unrar", "x", "-o+", rarFilePath, destDir
+        );
+        processBuilder.redirectErrorStream(true); // 合并标准错误流和标准输出流
+        // 执行命令
+        Process process = processBuilder.start();
+        // 读取命令输出(避免阻塞)
+        try (BufferedReader reader = new BufferedReader(
+                new InputStreamReader(process.getInputStream()))) {
+            String line;
+            while ((line = reader.readLine()) != null) {
+                // 可选:处理输出信息(例如记录日志)
+                System.out.println(line);
+            }
+        }
+        // 等待命令执行完成
+        int exitCode = process.waitFor();
+        if (exitCode != 0) {
+            throw new IOException("解压失败,退出码: " + exitCode);
+        }
+    }
+
+
     public static void writeDataToSheet(Sheet sheet, Elements rows) {
         int rowSize = rows.size();
         for (int rowNum = 0; rowNum < rowSize; rowNum++) {

+ 1 - 1
service-daq/src/main/java/com/simuwang/daq/service/EmailParseService.java

@@ -191,7 +191,7 @@ public class EmailParseService {
     }
 
     public void saveRelatedTable(String emailAddress, List<EmailContentInfoDTO> emailContentInfoDTOList, Map<EmailContentInfoDTO, List<EmailFundNavDTO>> fileNameNavMap) {
-        String emailTitle = CollUtil.isNotEmpty(emailContentInfoDTOList) ? emailContentInfoDTOList.get(0).getEmailTitle() : null;
+        String emailTitle = CollUtil.isNotEmpty(emailContentInfoDTOList) ? emailContentInfoDTOList.get(0).getEmailTitle() : "";
         String emailDate = CollUtil.isNotEmpty(emailContentInfoDTOList) ? emailContentInfoDTOList.get(0).getEmailDate() : null;
         Integer emailType = CollUtil.isNotEmpty(emailContentInfoDTOList) ? emailContentInfoDTOList.get(0).getEmailType() : null;
         Integer emailId = CollUtil.isNotEmpty(emailContentInfoDTOList) ? emailContentInfoDTOList.get(0).getEmailId() : null;

+ 18 - 1
service-daq/src/main/java/com/simuwang/daq/service/ValuationEmailParser.java

@@ -12,6 +12,7 @@ import com.simuwang.base.pojo.dto.ValuationPdfTransformToExcelDTO;
 import com.simuwang.base.pojo.valuation.AssetsValuationResult;
 import com.simuwang.base.pojo.valuation.ParseValuationInfo;
 import com.simuwang.base.pojo.valuation.ValuationNeedParseParam;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
 import java.io.File;
@@ -29,9 +30,14 @@ public class ValuationEmailParser extends AbstractEmailParser {
     private final ValuationParseService valuationParseService;
     private final PdfToExcelService pdfToExcelService;
 
-    public ValuationEmailParser(ValuationParseService valuationParseService, PdfToExcelService pdfToExcelService) {
+    private final EmailTemplateService emailTemplateService;
+    @Value("${email.parse.force-template-enable}")
+    private boolean forceTemplateEnable;
+
+    public ValuationEmailParser(ValuationParseService valuationParseService, PdfToExcelService pdfToExcelService, EmailTemplateService emailTemplateService) {
         this.valuationParseService = valuationParseService;
         this.pdfToExcelService = pdfToExcelService;
+        this.emailTemplateService = emailTemplateService;
     }
 
     @Override
@@ -53,6 +59,17 @@ public class ValuationEmailParser extends AbstractEmailParser {
             List<EmailFundNavDTO> fundNavDTOList = convertToFundNavDTO(recordList);
             Optional.ofNullable(fundNavDTOList).ifPresent(emailFundNavDTOList::addAll);
         }
+        long successNavCount = 0;
+        if (CollUtil.isNotEmpty(emailFundNavDTOList)) {
+            successNavCount = emailFundNavDTOList.stream().filter(e -> e != null && StrUtil.isBlank(e.getFailReason())).count();
+        }
+        //如果通用模板解析不到正确数据,就走模板解析一次
+        if (successNavCount == 0 || forceTemplateEnable) {
+            List<EmailFundNavDTO> templateFundNavDTOList = emailTemplateService.parseUsingTemplate(emailContentInfoDTO);
+            if(CollUtil.isNotEmpty(templateFundNavDTOList)){
+                emailFundNavDTOList.addAll(templateFundNavDTOList);
+            }
+        }
         return emailFundNavDTOList;
     }
 

+ 0 - 3
service-deploy/src/test/java/com/simuwang/ApplicationTest.java

@@ -5,9 +5,6 @@ import com.simuwang.base.common.conts.DateConst;
 import com.simuwang.base.pojo.dto.MailboxInfoDTO;
 import com.simuwang.daq.service.EmailParseApiService;
 import com.simuwang.daq.service.EmailParseService;
-import org.jasypt.encryption.StringEncryptor;
-import org.jasypt.encryption.pbe.PooledPBEStringEncryptor;
-import org.jasypt.encryption.pbe.StandardPBEByteEncryptor;
 import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
 import org.jasypt.iv.RandomIvGenerator;
 import org.jasypt.util.text.BasicTextEncryptor;

+ 4 - 4
service-manage/src/main/java/com/simuwang/manage/service/impl/DeletionServiceImpl.java

@@ -167,7 +167,7 @@ public class DeletionServiceImpl implements DeletionService {
         List<DistributionDO> distributionDOS = distributionMapper.getDistributionByFundId(fundId, DistributeType.DIVIDENDS_SPLIT.getCode());
         if(distributionDOS.size() > 0){
             //存在拆分,不做分红缺失计算,同时把以往的数据添加备注
-            deletionInfoMapper.updateRemark(fundId,DeletionType.ASSET_DELETION.getCode(),null,DeletionType.EXIST_SPLIT.getInfo(),null);
+            deletionInfoMapper.updateRemark(fundId,DeletionType.DISTRIBUTION_DELETION.getCode(),null,DeletionType.EXIST_SPLIT.getInfo(),null);
             return;
         }
         BigDecimal threshold = new BigDecimal(0.0035);
@@ -365,7 +365,7 @@ public class DeletionServiceImpl implements DeletionService {
                     }
 
                 }
-                //不包含的话,默认取每的最后一个交易日作为周净值日期
+                //不包含的话,默认取每的最后一个交易日作为周净值日期
                 List<TradeDateDO> tradeDateDOS = tradeListMap.get(yearMonth);
                 String tradeDate = null;
                 if(tradeDateDOS.size() > 0){
@@ -546,7 +546,7 @@ public class DeletionServiceImpl implements DeletionService {
                     }
 
                 }
-                //不包含的话,默认取每的最后一个交易日作为周净值日期
+                //不包含的话,默认取每的最后一个交易日作为周净值日期
                 List<TradeDateDO> tradeDateDOS = tradeListMap.get(yearMonth);
                 String tradeDate = null;
                 if(tradeDateDOS.size() > 0){
@@ -727,7 +727,7 @@ public class DeletionServiceImpl implements DeletionService {
                     }
 
                 }
-                //不包含的话,默认取每的最后一个交易日作为周净值日期
+                //不包含的话,默认取每的最后一个交易日作为周净值日期
                 List<TradeDateDO> tradeDateDOS = tradeListMap.get(yearMonth);
                 String tradeDate = null;
                 if(tradeDateDOS.size() > 0){