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()); } }