Explorar el Código

feat(资方管理):bug修复

Wangyafan hace 6 meses
padre
commit
1ca8f9571b

+ 10 - 12
src/main/java/com/sunxung/factoring/service/fundmanagement/impl/FinancialInstitutionServiceImpl.java

@@ -774,8 +774,7 @@ public class FinancialInstitutionServiceImpl extends ServiceImpl<FinancialInstit
                             });
                         }
                         //下游结算单
-                        List<FileStorage> settlementFileList = sysAttachmentRefService.getFiles(AttachmentDto.builder().setChildEnum(FileModuleDict.ChildEnum.SETTLEMENT_FILE)
-                                .setEntityId(settlementBasicInfoId).build());
+                        List<FileStorageDO> settlementFileList = fileService.findByBusinessId(settlementBasicInfoId, FileModuleDict.ChildEnum.SETTLEMENT_FILE.getCode());
                         if (CollectionUtil.isNotEmpty(settlementFileList)) {
                             settlementFileList.stream().forEach(s -> {
                                 sysAttachmentRefService.copyFile(s, FileModuleDict.ChildEnum.FINANCIAL_EXPENDITURE_DOWNSTREAM_SETTLEMENT_FILE,
@@ -789,8 +788,7 @@ public class FinancialInstitutionServiceImpl extends ServiceImpl<FinancialInstit
                         List<Long> InvoiceBasicInfoIdList = invoiceGoodsInfoList.stream().map(InvoiceGoodsInfo::getInvoiceBasicInfoId).distinct().collect(Collectors.toList());
                         for (Long invoiceBasicInfoId : InvoiceBasicInfoIdList) {
                             //采购发票
-                            List<FileStorage> purchaseFileList = sysAttachmentRefService.getFiles(AttachmentDto.builder().setChildEnum(FileModuleDict.ChildEnum.INVOICE_PURCHASE_FILE)
-                                    .setEntityId(invoiceBasicInfoId).build());
+                            List<FileStorageDO> purchaseFileList = fileService.findByBusinessId(invoiceBasicInfoId, FileModuleDict.ChildEnum.SETTLEMENT_FILE.getCode());
                             if (CollectionUtil.isNotEmpty(purchaseFileList)) {
                                 purchaseFileList.stream().forEach(p -> {
                                     sysAttachmentRefService.copyFile(p, FileModuleDict.ChildEnum.FINANCIAL_EXPENDITURE_UPSTREAM_INVOICE_FILE,
@@ -798,14 +796,14 @@ public class FinancialInstitutionServiceImpl extends ServiceImpl<FinancialInstit
                                 });
                             }
                             //销售待开发票
-//                                List<FileStorage> salesFileList = sysAttachmentRefService.getFiles(AttachmentDto.builder().setChildEnum(FileModuleDict.ChildEnum.INVOICE_SALES_FILE)
-//                                        .setEntityId(invoiceBasicInfoId).build());
-//                                if (CollectionUtil.isNotEmpty(salesFileList)) {
-//                                    salesFileList.stream().forEach(p -> {
-//                                        sysAttachmentRefService.copyFile(p, FileModuleDict.ChildEnum.FINANCIAL_EXPENDITURE_DOWNSTREAM_INVOICE_FILE,
-//                                                AttachmentDto.builder().setEntityId(customerExpenditureContractInfo.getId()).build());
-//                                    });
-//                                }
+                                List<FileStorage> salesFileList = sysAttachmentRefService.getFiles(AttachmentDto.builder().setChildEnum(FileModuleDict.ChildEnum.INVOICE_SALES_FILE)
+                                        .setEntityId(invoiceBasicInfoId).build());
+                                if (CollectionUtil.isNotEmpty(salesFileList)) {
+                                    salesFileList.stream().forEach(p -> {
+                                        sysAttachmentRefService.copyFile(p, FileModuleDict.ChildEnum.FINANCIAL_EXPENDITURE_DOWNSTREAM_INVOICE_FILE,
+                                                AttachmentDto.builder().setEntityId(customerExpenditureContractInfo.getId()).build());
+                                    });
+                                }
                         }
                     }
                 }

+ 9 - 0
src/main/java/com/sunxung/factoring/service/sys/ISysAttachmentRefService.java

@@ -3,6 +3,7 @@ package com.sunxung.factoring.service.sys;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.sunxung.factoring.dict.impl.FileModuleDict;
 import com.sunxung.factoring.entity.sys.FileStorage;
+import com.sunxung.factoring.entity.sys.FileStorageDO;
 import com.sunxung.factoring.entity.sys.SysAttachmentRef;
 import com.sunxung.factoring.service.sys.dto.AttachmentDto;
 import org.springframework.util.MultiValueMap;
@@ -95,6 +96,14 @@ public interface ISysAttachmentRefService extends IService<SysAttachmentRef> {
      */
     FileStorage copyFile(FileStorage fileStorage, FileModuleDict.ChildEnum moduleType, AttachmentDto attachmentDto);
 
+    /**
+     * 拷贝文件并保存
+     *
+     * @param fileStorage
+     * @param attachmentDto
+     * @return
+     */
+    FileStorage copyFile(FileStorageDO fileStorage, FileModuleDict.ChildEnum moduleType, AttachmentDto attachmentDto);
 
     /**
      * 默认的获取文件流方法

+ 35 - 0
src/main/java/com/sunxung/factoring/service/sys/impl/SysAttachmentRefServiceImpl.java

@@ -236,6 +236,41 @@ public class SysAttachmentRefServiceImpl extends ServiceImpl<SysAttachmentRefMap
         return null;
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public FileStorage copyFile(FileStorageDO fileStorage, FileModuleDict.ChildEnum moduleType, AttachmentDto attachmentDto) {
+
+        if (fileStorage != null) {
+            File sourceFile = new File(fileStorage.getAbsolutePath());
+            if (sourceFile.exists()) {
+                String fileName = FileUtil.randomFileName();
+                String absolutePath = FileUtil.getAbsolutePath(fileName, fileStorage.getType(), moduleType);
+                File targetFile = new File(absolutePath);
+                try {
+                    FileUtils.copyFile(sourceFile, targetFile);
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+
+                //新建FileStorage
+                FileStorage newFileStorage = new FileStorage(fileName, fileStorage.getOriginalName(), absolutePath, moduleType);
+                fileStorageService.add(newFileStorage);
+
+                if (newFileStorage.getId() != null) {
+                    SysAttachmentRef sysAttachmentRef = SysAttachmentRef.builder()
+                            .setEntityId(attachmentDto.getEntityId())
+                            .setFileStorageId(newFileStorage.getId())
+                            .setEntityName(moduleType.getCode())
+                            .setEntityTypeExpand(attachmentDto.getTypeExpand())
+                            .build();
+                    save(sysAttachmentRef);
+                }
+                return newFileStorage;
+            }
+        }
+        return null;
+    }
+
     @Override
     public List<FileStorage> getCfiles(AttachmentDto attachmentDto) {