From c68e1cd6def52ce0ff9342fa374a6e64f8f8ee53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E5=B5=A9?= Date: Tue, 28 Mar 2023 04:00:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91OTA=E5=A4=87=E6=A1=88?= =?UTF-8?q?=E5=B7=A5=E5=85=B7-=E5=AF=BC=E5=85=A5=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ota/service/IOtaBaCxAqcsService.java | 2 + .../ota/service/IOtaBaCxKsjjsmccsService.java | 2 + .../ota/service/IOtaBaCxKsjxtmccsService.java | 2 + .../ota/service/IOtaBaCxZxsjyqService.java | 2 +- .../service/impl/OtaBaCxAqcsServiceImpl.java | 47 ++++++++++ .../impl/OtaBaCxKsjjsmccsServiceImpl.java | 67 +++++++++++++ .../impl/OtaBaCxKsjxtmccsServiceImpl.java | 93 ++++++++++++++++++- .../service/impl/OtaBaCxListServiceImpl.java | 19 +++- .../impl/OtaBaCxZxsjyqServiceImpl.java | 59 +++++++++++- .../modules/ota/utils/ImportFileUtil.java | 47 ++++++++++ 10 files changed, 333 insertions(+), 7 deletions(-) diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxAqcsService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxAqcsService.java index 10614ff9d..30fbd0593 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxAqcsService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxAqcsService.java @@ -71,4 +71,6 @@ public interface IOtaBaCxAqcsService extends IService { OtaBaCxAqcs importData(MultipartFile file, String otaId, String cut) throws Exception; OtaBaCxAqcs parseFileList(List upLoadFiles, String otaId, String cut) throws Exception; + + void exportData(File file, File attFile, String otaId, String cut) throws Exception; } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjjsmccsService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjjsmccsService.java index 414f5cfad..857e3eb74 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjjsmccsService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjjsmccsService.java @@ -71,4 +71,6 @@ public interface IOtaBaCxKsjjsmccsService extends IService { void importData(MultipartFile file, String otaId, String cut) throws Exception; void parseFileList(List upLoadFiles, String otaId, String cut) throws Exception; + + void exportData(File file, File attFile, String otaId, String cut) throws Exception } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjxtmccsService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjxtmccsService.java index 8fda6c543..3a5133cd0 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjxtmccsService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxKsjxtmccsService.java @@ -71,4 +71,6 @@ public interface IOtaBaCxKsjxtmccsService extends IService { void importData(MultipartFile file, String otaId, String cut) throws Exception; void parseFileList(List upLoadFiles, String otaId, String cut) throws Exception; + + void exportData(File file, File attFile, String otaId, String cut) throws Exception; } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxZxsjyqService.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxZxsjyqService.java index 1a9db6653..f8e6cb910 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxZxsjyqService.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/IOtaBaCxZxsjyqService.java @@ -73,5 +73,5 @@ public interface IOtaBaCxZxsjyqService extends IService { OtaBaCxZxsjyq parseFileList(List upLoadFiles, String otaId, String cut) throws Exception; - void exportData(File file, String otaId, String cut) throws Exception; + void exportData(File file, File attFile,String otaId, String cut) throws Exception; } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxAqcsServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxAqcsServiceImpl.java index d77a727dd..1cdd57027 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxAqcsServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxAqcsServiceImpl.java @@ -3,6 +3,7 @@ package com.jero.modules.ota.service.impl; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.jero.common.exception.JeroBootException; +import com.jero.common.util.oss.CosBootUtil; import com.jero.modules.oss.entity.OSSFile; import com.jero.modules.oss.service.IOSSFileService; import com.jero.modules.ota.entity.*; @@ -24,6 +25,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.io.File; +import java.io.InputStream; import java.util.List; import java.util.Date; @@ -233,4 +235,49 @@ public class OtaBaCxAqcsServiceImpl extends ServiceImpl attList = JSONArray.parseArray(attStr, AttachmentEO.class); + if (ObjectUtils.isNotEmpty(attList)) { + for (AttachmentEO aeo : attList) { + List ossFileList = ossFileService.getFileInfos(aeo.getId()); + for (OSSFile ossFile : ossFileList) { + String filePath = ossFile.getUrl(); + boolean b = CosBootUtil.doesObjectExist(filePath); + if (b) { + InputStream download = CosBootUtil.download(filePath); + ImportFileUtil.writeToLocal(attFile.getCanonicalPath() + "/" + ossFile.getFileName(), download); + sb.append(ossFile.getFileName()).append(","); + } + } + } + } + cell.setCellValue(sb.toString()); + } } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjjsmccsServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjjsmccsServiceImpl.java index 68e221205..9c3d2722e 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjjsmccsServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjjsmccsServiceImpl.java @@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.jero.common.exception.JeroBootException; +import com.jero.common.util.oss.CosBootUtil; +import com.jero.modules.oss.entity.OSSFile; import com.jero.modules.oss.service.IOSSFileService; import com.jero.modules.ota.entity.*; import com.jero.modules.ota.enums.OtaModuleEnum; @@ -27,6 +29,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.io.File; +import java.io.InputStream; import java.lang.reflect.Field; import java.util.*; @@ -299,4 +302,68 @@ public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl mccsList = this.getByOtaId(otaId); + Workbook wb = ImportFileUtil.readExcel(file); + Sheet s = wb.getSheetAt(0); + int startRow = 3; + for (OtaBaCxKsjjsmccs mccs : mccsList) { + Row row = s.getRow(startRow); + Cell cell = row.createCell(0); + cell.setCellValue(mccs.getGnmc()); + cell = row.createCell(1); + cell.setCellValue(ImportFileUtil.getCellValueYesOrNo(mccs.getPzqk())); + cell = row.createCell(2); + cell.setCellValue(ImportFileUtil.getCellValueYesOrNo(mccs.getSfksj())); + cell = row.createCell(3); + cell.setCellValue(mccs.getJszdhjb()); + cell = row.createCell(4); + cell.setCellValue(mccs.getSjggcs()); + cell = row.createCell(5); + cell.setCellValue(mccs.getGnms()); + cell = row.createCell(6); + cell.setCellValue(mccs.getSytj()); + cell = row.createCell(7); + cell.setCellValue(mccs.getKzqmc()); + cell = row.createCell(8); + cell.setCellValue(mccs.getKzqscqy()); + cell = row.createCell(9); + cell.setCellValue(mccs.getKzqxh()); + cell = row.createCell(10); + cell.setCellValue(mccs.getYjbbxx()); + cell = row.createCell(11); + cell.setCellValue(mccs.getRjkfqy()); + cell = row.createCell(12); + cell.setCellValue(mccs.getCzxtbbh()); + cell = row.createCell(13); + cell.setCellValue(mccs.getCsyzsj()); + } + Row row = s.getRow(startRow); + Cell cell = row.createCell(0); + cell.setCellValue("证明材料"); + cell = row.getCell(1); + OtaBaCxList otaBaCxList = otaBaCxListService.queryById(otaId); + if (ObjectUtils.isNotEmpty(otaBaCxList)) { + StringBuilder sb = new StringBuilder(); + String fj = otaBaCxList.getZxsjjsfj(); + if (StringUtils.isNotEmpty(fj)) { + String[] strs = fj.split(","); + for (String str : strs) { + List ossFileList = ossFileService.getFileInfos(str); + for (OSSFile ossFile : ossFileList) { + String filePath = ossFile.getUrl(); + boolean b = CosBootUtil.doesObjectExist(filePath); + if (b) { + InputStream download = CosBootUtil.download(filePath); + ImportFileUtil.writeToLocal(attFile.getCanonicalPath() + "/" + ossFile.getFileName(), download); + sb.append(ossFile.getFileName()).append(","); + } + } + } + cell.setCellValue(sb.toString()); + } + } + } } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjxtmccsServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjxtmccsServiceImpl.java index c66e097fc..f4f3d2c04 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjxtmccsServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjxtmccsServiceImpl.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.jero.common.exception.JeroBootException; +import com.jero.common.util.oss.CosBootUtil; import com.jero.modules.oss.entity.OSSFile; import com.jero.modules.oss.service.IOSSFileService; import com.jero.modules.ota.entity.*; @@ -28,6 +29,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.io.File; +import java.io.InputStream; import java.lang.reflect.Field; import java.util.*; @@ -300,4 +302,93 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl mccsList = this.getByOtaId(otaId); + Workbook wb = ImportFileUtil.readExcel(file); + Sheet s = wb.getSheetAt(0); + + int startRow = 3; + for (OtaBaCxKsjxtmccs mccs : mccsList) { + Row row = s.getRow(startRow); + Cell cell = row.createCell(0); + cell.setCellValue(mccs.getXtlb()); + + cell = row.createCell(1); + cell.setCellValue(ImportFileUtil.getCellValueYesOrNo(mccs.getSfksj())); + + cell = row.createCell(2); + cell.setCellValue(mccs.getSjbgcs()); + cell = row.createCell(3); + StringBuilder sb = new StringBuilder(); + String tptStr = mccs.getTpt(); + if (StringUtils.isNotEmpty(tptStr)) { + String[] strs = tptStr.split(","); + for (String str : strs) { + List ossFileList = ossFileService.getFileInfos(str); + for (OSSFile ossFile : ossFileList) { + String filePath = ossFile.getUrl(); + boolean b = CosBootUtil.doesObjectExist(filePath); + if (b) { + InputStream download = CosBootUtil.download(filePath); + ImportFileUtil.writeToLocal(attFile.getCanonicalPath() + "/" + ossFile.getFileName(), download); + sb.append(ossFile.getFileName()).append(","); + } + } + } + cell.setCellValue(sb.toString()); + } + cell = row.createCell(4); + cell.setCellValue(mccs.getKzqmc()); + cell = row.createCell(5); + cell.setCellValue(mccs.getAqwzxdj()); + cell = row.createCell(6); + cell.setCellValue(mccs.getKzqscqy()); + cell = row.createCell(7); + cell.setCellValue(mccs.getKzqxh()); + cell = row.createCell(8); + cell.setCellValue(mccs.getYjbbxx()); + cell = row.createCell(9); + cell.setCellValue(mccs.getCsrjbbh()); + cell = row.createCell(10); + cell.setCellValue(mccs.getCsrjbwzsj()); + cell = row.createCell(11); + cell.setCellValue(mccs.getSjsfyx()); + cell = row.createCell(12); + cell.setCellValue(mccs.getCzxtlx()); + cell = row.createCell(13); + cell.setCellValue(mccs.getCzxtscqy()); + cell = row.createCell(14); + cell.setCellValue(mccs.getCzxtbbh()); + startRow++; + } + Row row = s.getRow(startRow); + Cell cell = row.createCell(0); + cell.setCellValue("证明材料"); + cell = row.getCell(1); + OtaBaCxList otaBaCxList = otaBaCxListService.queryById(otaId); + if (ObjectUtils.isNotEmpty(otaBaCxList)) { + StringBuilder sb = new StringBuilder(); + String fj = otaBaCxList.getZxsjxtfj(); + if (StringUtils.isNotEmpty(fj)) { + String[] strs = fj.split(","); + for (String str : strs) { + List ossFileList = ossFileService.getFileInfos(str); + for (OSSFile ossFile : ossFileList) { + String filePath = ossFile.getUrl(); + boolean b = CosBootUtil.doesObjectExist(filePath); + if (b) { + InputStream download = CosBootUtil.download(filePath); + ImportFileUtil.writeToLocal(attFile.getCanonicalPath() + "/" + ossFile.getFileName(), download); + sb.append(ossFile.getFileName()).append(","); + } + } + } + cell.setCellValue(sb.toString()); + } + } + } + +} \ No newline at end of file diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxListServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxListServiceImpl.java index c7c31763c..5c02abaa9 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxListServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxListServiceImpl.java @@ -187,16 +187,27 @@ public class OtaBaCxListServiceImpl extends ServiceImpl attList = JSONArray.parseArray(attStr, AttachmentEO.class); + if (ObjectUtils.isNotEmpty(attList)) { + for (AttachmentEO aeo : attList) { + List ossFileList = ossFileService.getFileInfos(aeo.getId()); + for (OSSFile ossFile : ossFileList) { + String filePath = ossFile.getUrl(); + boolean b = CosBootUtil.doesObjectExist(filePath); + if (b) { + InputStream download = CosBootUtil.download(filePath); + ImportFileUtil.writeToLocal(attFile.getCanonicalPath() + "/" + ossFile.getFileName(), download); + sb.append(ossFile.getFileName()).append(","); + } + } + } + } + cell.setCellValue(sb.toString()); } } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ImportFileUtil.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ImportFileUtil.java index d5b017a1e..6855a6cec 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ImportFileUtil.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ImportFileUtil.java @@ -179,6 +179,18 @@ public class ImportFileUtil { return res; } + public static String getCellValueYesOrNo(String str) throws Exception { + String res = ""; + if (StringUtils.isNotEmpty(str)) { + if (str.equals("1")) { + res = "是"; + } else if (str.equals("2")) { + res = "否"; + } + } + return res; + } + public static String getCellValueDict(Cell cell, Workbook wb, String dictType, ISysDictService sysDictService, String cut) throws Exception { String res = ""; String str = ImportFileUtil.getCellValue(cell, wb); @@ -212,6 +224,21 @@ public class ImportFileUtil { return null; } + public static File findFoder(File file, String fileName) throws Exception { + // 获取此地址中的所有文件以及文件夹(File[] list) + File[] listFiles = file.listFiles();// 获取此地址中的所有文件以及文件夹(File[] list) + for (File file1 : listFiles) {// 遍历数组 + // 判断当前的File对象是否为文件夹 + if (file1.isDirectory()) { + String name = file1.getName(); + if (name.equals(fileName)) { + return file1; + } + } + } + return null; + } + public static File findFile(List file, String fileName) throws Exception { for (File file1 : file) {// 遍历数组 // 判断当前的File对象是否为文件夹 @@ -401,5 +428,25 @@ public class ImportFileUtil { } } } + + /** + * 将InputStream写入本地文件 + * + * @param input 输入流 + * @throws IOException IOException + */ + public static void writeToLocal(String path, InputStream input) + throws IOException { + int index; + byte[] bytes = new byte[1024]; + FileOutputStream downloadFile = new FileOutputStream(path); + while ((index = input.read(bytes)) != -1) { + downloadFile.write(bytes, 0, index); + downloadFile.flush(); + } + input.close(); + downloadFile.close(); + + } }