|
@@ -49,8 +49,7 @@ public class ScFileDownloadService {
|
|
|
private final TbScImgnDtctRawClctRepository dtctRawClctRepo;
|
|
|
private final TbScAcrdStatHhRepository statHhRepo;
|
|
|
|
|
|
- private final String systemDir = System.getProperty("user.dir");
|
|
|
- private final String dataFilePath = "/signal_data/";
|
|
|
+ private String fileSystemDir;
|
|
|
private final String createFilePath = "/signal_data/download/";
|
|
|
private final String csvFileExtension = ".csv";
|
|
|
private final int[] BOM_MARKERS = new int[] { 0xEF, 0xBB, 0xBF };
|
|
@@ -65,13 +64,16 @@ public class ScFileDownloadService {
|
|
|
@PostConstruct
|
|
|
void init() {
|
|
|
ItsUtils.createUserDir(this.createFilePath);
|
|
|
+ this.fileSystemDir = System.getProperty("user.dir");
|
|
|
+ //this.fileSystemDir = this.fileSystemDir.replaceAll("\\.", "").replaceAll("/", "").replaceAll("\\\\", "");
|
|
|
}
|
|
|
|
|
|
public List<FileInfoDto> findAllOptimalTrafficFiles() {
|
|
|
final String optimalFileTrafficPath = "raw-clct/";
|
|
|
List<FileInfoDto> result = new ArrayList<>();
|
|
|
int id = 1;
|
|
|
- String filePath = this.dataFilePath + optimalFileTrafficPath;
|
|
|
+ String dataFilePath = "/signal_data/";
|
|
|
+ String filePath = dataFilePath + optimalFileTrafficPath;
|
|
|
FileInfoDto rootFile = FileInfoDto.builder()
|
|
|
.files(new ArrayList<>())
|
|
|
.id(id)
|
|
@@ -82,7 +84,7 @@ public class ScFileDownloadService {
|
|
|
.fileSize(0L)
|
|
|
.build();
|
|
|
|
|
|
- rootFile.setFiles(getFiles(id, this.systemDir, filePath));
|
|
|
+ rootFile.setFiles(getFiles(id, this.fileSystemDir, filePath));
|
|
|
result.add(rootFile);
|
|
|
return result;
|
|
|
}
|
|
@@ -137,7 +139,7 @@ public class ScFileDownloadService {
|
|
|
.build();
|
|
|
|
|
|
//parentId = id;
|
|
|
- fileInfo.setFiles(getFiles(id, this.systemDir, subDir));
|
|
|
+ fileInfo.setFiles(getFiles(id, this.fileSystemDir, subDir));
|
|
|
fileInfoList.add(fileInfo);
|
|
|
id += fileInfo.getFiles().size();
|
|
|
}
|
|
@@ -167,14 +169,14 @@ public class ScFileDownloadService {
|
|
|
* @throws NoSuchElementException
|
|
|
*/
|
|
|
public ResponseEntity<Object> downloadFile(String fileNameUri, HttpServletRequest req) throws NoSuchElementException{
|
|
|
- Path fullFilePath = Paths.get(this.systemDir, fileNameUri);
|
|
|
+ Path fullFilePath = Paths.get(this.fileSystemDir, fileNameUri);
|
|
|
File file = fullFilePath.toFile();
|
|
|
if (!file.exists()) {
|
|
|
throw new NoSuchElementException("파일이 존재하지 않습니다: " + fileNameUri);
|
|
|
}
|
|
|
|
|
|
String fileName = file.getName();
|
|
|
- Resource resource = null;
|
|
|
+ Resource resource;
|
|
|
try {
|
|
|
resource = new InputStreamResource(Files.newInputStream(fullFilePath));
|
|
|
} catch (IOException e) {
|
|
@@ -196,8 +198,8 @@ public class ScFileDownloadService {
|
|
|
* @param fileNameUri
|
|
|
* @return
|
|
|
*/
|
|
|
- public FileInfoDto deleteFile(String fileNameUri) {
|
|
|
- Path fullFilePath = Paths.get(this.systemDir, fileNameUri);
|
|
|
+ public FileInfoDto deleteFile(String fileNameUri) throws NoSuchElementException {
|
|
|
+ Path fullFilePath = Paths.get(this.fileSystemDir, fileNameUri);
|
|
|
File file = fullFilePath.toFile();
|
|
|
if (!file.exists()) {
|
|
|
throw new NoSuchElementException("파일이 존재하지 않습니다: " + fileNameUri);
|
|
@@ -228,7 +230,7 @@ public class ScFileDownloadService {
|
|
|
init();
|
|
|
String fileName = "IXR_MNGM_" + ItsUtils.getSysDay() + this.csvFileExtension;
|
|
|
String createFileName = this.createFilePath + "IXR_MNGM_" + ItsUtils.getSysDay() + "_" + (System.currentTimeMillis() / 1000) + this.csvFileExtension;
|
|
|
- Path fullFilePath = Paths.get(this.systemDir, createFileName);
|
|
|
+ Path fullFilePath = Paths.get(this.fileSystemDir, createFileName);
|
|
|
|
|
|
String[] csvHeader = {"IXR_ID",
|
|
|
"IXR_NM",
|
|
@@ -253,18 +255,15 @@ public class ScFileDownloadService {
|
|
|
"nodeId",
|
|
|
"sgnlIxrNmbr"};
|
|
|
List<TbScIxrMngm> dataList = this.ixrMngmRepo.findAllOrderById();
|
|
|
- try {
|
|
|
- OutputStreamWriter outputWriter = new OutputStreamWriter(Files.newOutputStream(fullFilePath), "MS949");
|
|
|
- ICsvBeanWriter csvWriter = new CsvBeanWriter(outputWriter, CsvPreference.STANDARD_PREFERENCE);//EXCEL_PREFERENCE);//STANDARD_PREFERENCE);
|
|
|
+ try (OutputStreamWriter outputWriter = new OutputStreamWriter(Files.newOutputStream(fullFilePath), "MS949");
|
|
|
+ ICsvBeanWriter csvWriter = new CsvBeanWriter(outputWriter, CsvPreference.STANDARD_PREFERENCE);//EXCEL_PREFERENCE);//STANDARD_PREFERENCE);
|
|
|
+ ) {
|
|
|
csvWriter.writeHeader(csvHeader);
|
|
|
for (TbScIxrMngm data : dataList) {
|
|
|
csvWriter.write(data, nameMapping);
|
|
|
}
|
|
|
csvWriter.flush();
|
|
|
outputWriter.flush();
|
|
|
- csvWriter.close();
|
|
|
- outputWriter.close();
|
|
|
-
|
|
|
// FileWriter writer = new FileWriter("ixrMngm.csv", Charset.forName("MS949"));
|
|
|
// StatefulBeanToCsv<TbScIxrMngm> beanToCsv = new StatefulBeanToCsvBuilder<TbScIxrMngm>(writer)
|
|
|
// .withSeparator(CSVWriter.DEFAULT_SEPARATOR)
|
|
@@ -297,7 +296,7 @@ public class ScFileDownloadService {
|
|
|
init();
|
|
|
String fileName = "CMRA_MNGM_" + ItsUtils.getSysDay() + this.csvFileExtension;
|
|
|
String createFileName = this.createFilePath + "CMRA_MNGM_" + ItsUtils.getSysDay() + "_" + (System.currentTimeMillis() / 1000) + this.csvFileExtension;
|
|
|
- Path fullFilePath = Paths.get(this.systemDir, createFileName);
|
|
|
+ Path fullFilePath = Paths.get(this.fileSystemDir, createFileName);
|
|
|
|
|
|
String[] csvHeader = {"IXR_ID",
|
|
|
"CMRA_ID",
|
|
@@ -352,14 +351,13 @@ public class ScFileDownloadService {
|
|
|
"rtcSvrPort",
|
|
|
"rtcId"};
|
|
|
List<TbScIxrCmraMngm> dataList = this.cmraMngmRepo.findAllOrderById();
|
|
|
- try {
|
|
|
- OutputStreamWriter outputWriter = new OutputStreamWriter(Files.newOutputStream(fullFilePath), "MS949");
|
|
|
- ICsvBeanWriter csvWriter = new CsvBeanWriter(outputWriter, CsvPreference.STANDARD_PREFERENCE);//EXCEL_PREFERENCE);//STANDARD_PREFERENCE);
|
|
|
+ try (OutputStreamWriter outputWriter = new OutputStreamWriter(Files.newOutputStream(fullFilePath), "MS949");
|
|
|
+ ICsvBeanWriter csvWriter = new CsvBeanWriter(outputWriter, CsvPreference.STANDARD_PREFERENCE);//EXCEL_PREFERENCE);//STANDARD_PREFERENCE);
|
|
|
+ ) {
|
|
|
csvWriter.writeHeader(csvHeader);
|
|
|
for (TbScIxrCmraMngm data : dataList) {
|
|
|
csvWriter.write(data, nameMapping);
|
|
|
}
|
|
|
- csvWriter.close();
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException("파일 저장 중 오류가 발생했습니다.");
|
|
|
}
|
|
@@ -380,7 +378,7 @@ public class ScFileDownloadService {
|
|
|
init();
|
|
|
String fileName = "IMGN_DTCT_RAW_CLCT_" + StringUtils.subString(fromDt, 12) + "_" + StringUtils.subString(toDt, 12) + this.csvFileExtension;
|
|
|
String createFileName = this.createFilePath + "IMGN_DTCT_RAW_CLCT_" + StringUtils.subString(fromDt, 12) + "_" + StringUtils.subString(toDt, 12) + "_" + (System.currentTimeMillis() / 1000) + this.csvFileExtension;
|
|
|
- Path fullFilePath = Paths.get(this.systemDir, createFileName);
|
|
|
+ Path fullFilePath = Paths.get(this.fileSystemDir, createFileName);
|
|
|
|
|
|
String[] csvHeader = {"CLCT_DT",
|
|
|
"IXR_ID",
|
|
@@ -431,14 +429,13 @@ public class ScFileDownloadService {
|
|
|
"bikeLeftTfvl",
|
|
|
"bikeRghtTfvl"};
|
|
|
List<TbScImgnDtctRawClct> dataList = this.dtctRawClctRepo.findAllByDateRange(fromDt, toDt);
|
|
|
- try {
|
|
|
- OutputStreamWriter outputWriter = new OutputStreamWriter(Files.newOutputStream(fullFilePath), "MS949");
|
|
|
- ICsvBeanWriter csvWriter = new CsvBeanWriter(outputWriter, CsvPreference.STANDARD_PREFERENCE);//EXCEL_PREFERENCE);//STANDARD_PREFERENCE);
|
|
|
+ try (OutputStreamWriter outputWriter = new OutputStreamWriter(Files.newOutputStream(fullFilePath), "MS949");
|
|
|
+ ICsvBeanWriter csvWriter = new CsvBeanWriter(outputWriter, CsvPreference.STANDARD_PREFERENCE);//EXCEL_PREFERENCE);//STANDARD_PREFERENCE);
|
|
|
+ ) {
|
|
|
csvWriter.writeHeader(csvHeader);
|
|
|
for (TbScImgnDtctRawClct data : dataList) {
|
|
|
csvWriter.write(data, nameMapping);
|
|
|
}
|
|
|
- csvWriter.close();
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException("파일 저장 중 오류가 발생했습니다.");
|
|
|
}
|
|
@@ -458,7 +455,7 @@ public class ScFileDownloadService {
|
|
|
init();
|
|
|
String fileName = "ACRD_HH_STAT_" + StringUtils.subString(fromDt, 12) + "_" + StringUtils.subString(toDt, 12) + this.csvFileExtension;
|
|
|
String createFileName = this.createFilePath + "ACRD_HH_STAT_" + StringUtils.subString(fromDt, 12) + "_" + StringUtils.subString(toDt, 12) + "_" + (System.currentTimeMillis() / 1000) + this.csvFileExtension;
|
|
|
- Path fullFilePath = Paths.get(this.systemDir, createFileName);
|
|
|
+ Path fullFilePath = Paths.get(this.fileSystemDir, createFileName);
|
|
|
|
|
|
String[] csvHeader = {"CLCT_DT",
|
|
|
"IXR_ID",
|
|
@@ -499,14 +496,13 @@ public class ScFileDownloadService {
|
|
|
"busDvrsLaneGoTfvl",
|
|
|
"busDvrsLaneLeftTfvl"};
|
|
|
List<TbScAcrdStatHh> dataList = this.statHhRepo.findAllByDateRange(fromDt, toDt);
|
|
|
- try {
|
|
|
- OutputStreamWriter outputWriter = new OutputStreamWriter(Files.newOutputStream(fullFilePath), "MS949");
|
|
|
- ICsvBeanWriter csvWriter = new CsvBeanWriter(outputWriter, CsvPreference.STANDARD_PREFERENCE);//EXCEL_PREFERENCE);//STANDARD_PREFERENCE);
|
|
|
+ try (OutputStreamWriter outputWriter = new OutputStreamWriter(Files.newOutputStream(fullFilePath), "MS949");
|
|
|
+ ICsvBeanWriter csvWriter = new CsvBeanWriter(outputWriter, CsvPreference.STANDARD_PREFERENCE);//EXCEL_PREFERENCE);//STANDARD_PREFERENCE);
|
|
|
+ ) {
|
|
|
csvWriter.writeHeader(csvHeader);
|
|
|
for (TbScAcrdStatHh data : dataList) {
|
|
|
csvWriter.write(data, nameMapping);
|
|
|
}
|
|
|
- csvWriter.close();
|
|
|
} catch (IOException e) {
|
|
|
throw new RuntimeException("파일 저장 중 오류가 발생했습니다.");
|
|
|
}
|
|
@@ -523,13 +519,13 @@ public class ScFileDownloadService {
|
|
|
* @throws NoSuchElementException
|
|
|
*/
|
|
|
public ResponseEntity<Object> downloadCreateFile(HttpServletRequest req, String fileNameUri, String fileName) throws NoSuchElementException{
|
|
|
- Path fullFilePath = Paths.get(this.systemDir, fileNameUri);
|
|
|
+ Path fullFilePath = Paths.get(this.fileSystemDir, fileNameUri);
|
|
|
File file = fullFilePath.toFile();
|
|
|
if (!file.exists()) {
|
|
|
throw new NoSuchElementException("파일이 존재하지 않습니다: " + fileNameUri);
|
|
|
}
|
|
|
|
|
|
- Resource resource = null;
|
|
|
+ Resource resource;
|
|
|
try {
|
|
|
resource = new InputStreamResource(Files.newInputStream(fullFilePath));
|
|
|
} catch (IOException e) {
|
|
@@ -547,34 +543,29 @@ public class ScFileDownloadService {
|
|
|
|
|
|
public void test(HttpServletRequest request, HttpServletResponse response) {
|
|
|
List<TbScIxrCmraMngm> dataList = this.cmraMngmRepo.findAll();
|
|
|
- CSVPrinter printer = null;
|
|
|
- try {
|
|
|
- printer = new CSVPrinter(response.getWriter(), CSVFormat.DEFAULT);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException("파일을 저장할 수 없습니다.");
|
|
|
- }
|
|
|
-
|
|
|
- response.setContentType("text/csv");
|
|
|
- response.addHeader("Content-Disposition", "attachment; filename=\"student.csv\"");
|
|
|
|
|
|
- for (TbScIxrCmraMngm entity : dataList) {
|
|
|
- try {
|
|
|
- printer.printRecord(entity);
|
|
|
- } catch (IOException e) {
|
|
|
- throw new RuntimeException("파일 저장 중 오류가 발생했습니다.");
|
|
|
+ try (CSVPrinter printer = new CSVPrinter(response.getWriter(), CSVFormat.DEFAULT);
|
|
|
+ ) {
|
|
|
+ response.setContentType("text/csv");
|
|
|
+ response.addHeader("Content-Disposition", "attachment; filename=\"student.csv\"");
|
|
|
+
|
|
|
+ for (TbScIxrCmraMngm entity : dataList) {
|
|
|
+ try {
|
|
|
+ printer.printRecord(entity);
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException("파일 저장 중 오류가 발생했습니다.");
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- try {
|
|
|
- printer.close();
|
|
|
} catch (IOException e) {
|
|
|
- //throw new RuntimeException(e);
|
|
|
+ throw new RuntimeException("파일을 저장할 수 없습니다.");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
public ResponseEntity<Object> findAllIxrMngmData2(HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
|
|
String fileName = "IXR_MNGM_" + ItsUtils.getSysDay() + this.csvFileExtension;
|
|
|
String createFileName = this.createFilePath + "IXR_MNGM_" + ItsUtils.getSysTime() + this.csvFileExtension;
|
|
|
- Path fullFilePath = Paths.get(this.systemDir, createFileName);
|
|
|
+ Path fullFilePath = Paths.get(this.fileSystemDir, createFileName);
|
|
|
File file = fullFilePath.toFile();
|
|
|
|
|
|
//response.setContentType("text/csv;charset=utf-8");
|
|
@@ -651,25 +642,26 @@ public class ScFileDownloadService {
|
|
|
// } catch (IOException e) {
|
|
|
// throw new RuntimeException("파일 저장 중 오류가 발생했습니다.");
|
|
|
// }
|
|
|
-
|
|
|
- try {
|
|
|
- //String UTF8_BOM = "\uFEFF";
|
|
|
- OutputStream out = response.getOutputStream();
|
|
|
// for (int marker : this.BOM_MARKERS) {
|
|
|
// out.write(marker);
|
|
|
// }
|
|
|
|
|
|
- OutputStreamWriter outputWriter = new OutputStreamWriter(out, StandardCharsets.UTF_8);// Charset.forName("EUC-KR"));//, StandardCharsets.UTF_8);
|
|
|
- ICsvBeanWriter csvWriter = new CsvBeanWriter(outputWriter, CsvPreference.STANDARD_PREFERENCE);//EXCEL_PREFERENCE);//STANDARD_PREFERENCE);
|
|
|
- csvWriter.writeHeader(csvHeader);
|
|
|
- for (TbScIxrMngm data : dataList) {
|
|
|
- csvWriter.write(data, nameMapping);
|
|
|
+ try (OutputStream out = response.getOutputStream();
|
|
|
+ ) {
|
|
|
+ try (OutputStreamWriter outputWriter = new OutputStreamWriter(out, StandardCharsets.UTF_8);// Charset.forName("EUC-KR"));//, StandardCharsets.UTF_8);
|
|
|
+ ICsvBeanWriter csvWriter = new CsvBeanWriter(outputWriter, CsvPreference.STANDARD_PREFERENCE);//EXCEL_PREFERENCE);//STANDARD_PREFERENCE);
|
|
|
+ ) {
|
|
|
+ csvWriter.writeHeader(csvHeader);
|
|
|
+ for (TbScIxrMngm data : dataList) {
|
|
|
+ csvWriter.write(data, nameMapping);
|
|
|
+ }
|
|
|
+ csvWriter.flush();
|
|
|
+ out.flush();
|
|
|
+ } catch (IOException e) {
|
|
|
+ throw new RuntimeException("파일 저장 중 오류가 발생했습니다.");
|
|
|
}
|
|
|
- csvWriter.flush();
|
|
|
- out.flush();
|
|
|
- csvWriter.close();
|
|
|
} catch (IOException e) {
|
|
|
- throw new RuntimeException("파일 저장 중 오류가 발생했습니다.");
|
|
|
+ throw new RuntimeException(e);
|
|
|
}
|
|
|
|
|
|
return downloadCreateFile(request, createFileName, fileName);
|