From 4cc84dadd3f8f26e86e03d1f7fc318099892d342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E5=B5=A9?= Date: Tue, 6 Jun 2023 17:13:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9OTA=E7=94=9F=E6=88=90CSV?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=8E=BB=E6=8E=89header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/OtaBaSjSjmbclServiceImpl.java | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaSjSjmbclServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaSjSjmbclServiceImpl.java index e583dc9c3..a32b99547 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaSjSjmbclServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaSjSjmbclServiceImpl.java @@ -31,9 +31,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; +import java.io.*; import java.text.SimpleDateFormat; import java.util.*; @@ -262,19 +260,35 @@ public class OtaBaSjSjmbclServiceImpl extends ServiceImpl(); - Map vrow = null; - for (int i = 0; i < vinList.size(); i++) { - vrow = new LinkedHashMap(); - vrow.put("1", vinList.get(i).getVin()); - exportData.add(vrow); - } +// LinkedHashMap map = new LinkedHashMap(); +// map.put("1", "VIN"); +// List exportData = new ArrayList(); +// Map vrow = null; +// for (int i = 0; i < vinList.size(); i++) { +// vrow = new LinkedHashMap(); +// vrow.put("1", vinList.get(i).getVin()); +// exportData.add(vrow); +// } +// String fileName = "VIN码.csv"; +// File file = CSVUtil.createCSVFile(exportData, map, uploadPath + System.currentTimeMillis(), fileName); +// String filePath = uploadPath + "/" + file.getName(); + String fileName = "VIN码.csv"; - File file = CSVUtil.createCSVFile(exportData, map, uploadPath + System.currentTimeMillis(), fileName); - String filePath = uploadPath + "/" + file.getName(); - OSSFile ossFile = ossFileService.uploadLocalOfCos(ImportFileUtil.createMfileByFile(file), "/ota", "", CutEnum.CN.getValue()); + File csvFileDir = new File(uploadPath + System.currentTimeMillis()); + csvFileDir.mkdirs(); + File csvFile = new File(csvFileDir.getAbsolutePath() + "/" + fileName); + try (BufferedWriter writer = new BufferedWriter(new FileWriter(csvFile))) { + // 写入数据 + for (VinObj data : vinList) { + String row = data.getVin(); + writer.write(row); + writer.newLine(); + } + } catch (IOException e) { + System.err.println("生成CSV文件失败:" + e.getMessage()); + } + + OSSFile ossFile = ossFileService.uploadLocalOfCos(ImportFileUtil.createMfileByFile(csvFile), "/ota", "", CutEnum.CN.getValue()); mbcl.setCsv(ossFile.getId()); } }