2022-12-22 01:55:19 +00:00
|
|
|
package com.dbnt.faisp.config;
|
|
|
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class BaseService {
|
|
|
|
|
|
|
|
|
|
@Value("${spring.servlet.multipart.location}")
|
|
|
|
|
protected String locationPath;
|
2022-12-30 09:01:34 +00:00
|
|
|
@Value("${file.dir.publicBoard}")
|
|
|
|
|
protected String publicBoardPath;
|
|
|
|
|
@Value("${file.dir.faRpt}")
|
|
|
|
|
protected String faRptPath;
|
|
|
|
|
@Value("${file.dir.vulnerable}")
|
|
|
|
|
protected String vulnerablePath;
|
|
|
|
|
@Value("${file.dir.part}")
|
|
|
|
|
protected String partPath;
|
|
|
|
|
@Value("${file.dir.equip}")
|
|
|
|
|
protected String equipPath;
|
|
|
|
|
@Value("${file.dir.sailor}")
|
|
|
|
|
protected String sailorPath;
|
|
|
|
|
@Value("${file.dir.affair}")
|
|
|
|
|
protected String affairPath;
|
|
|
|
|
@Value("${file.dir.affair.plan}")
|
|
|
|
|
protected String affairPlanPath;
|
|
|
|
|
@Value("${file.dir.affair.result}")
|
|
|
|
|
protected String affairResultPath;
|
|
|
|
|
@Value("${file.dir.editor}")
|
|
|
|
|
protected String editorPath;
|
|
|
|
|
@Value("${file.dir.sri}")
|
|
|
|
|
protected String sriPath;
|
|
|
|
|
@Value("${file.dir.ciw}")
|
|
|
|
|
protected String ciwPath;
|
|
|
|
|
@Value("${file.dir.cia.safty}")
|
|
|
|
|
protected String ciaSaftyPath;
|
|
|
|
|
@Value("${file.dir.cia.company}")
|
|
|
|
|
protected String ciaCompanyPath;
|
|
|
|
|
@Value("${file.dir.cia.foreigner}")
|
|
|
|
|
protected String ciaForeignerPath;
|
|
|
|
|
@Value("${file.dir.cia.edu}")
|
|
|
|
|
protected String ciaEduPath;
|
2023-01-04 09:28:18 +00:00
|
|
|
@Value("${file.dir.activityCase}")
|
|
|
|
|
protected String activityCasePath;
|
2023-01-06 05:00:33 +00:00
|
|
|
@Value("${file.dir.majorStatus}")
|
|
|
|
|
protected String majorStatusPath;
|
2022-12-22 01:55:19 +00:00
|
|
|
|
|
|
|
|
protected String calculationSize(double fileSize){
|
|
|
|
|
String[] units = {"bytes", "KB", "MB", "GB", "TB", "PB"};
|
|
|
|
|
double unitSelector = Math.floor(Math.log(fileSize)/Math.log(1024));
|
|
|
|
|
if(fileSize>0){
|
|
|
|
|
return Math.round((fileSize/Math.pow(1024, unitSelector))*100)/100d+" "+units[(int)unitSelector];
|
|
|
|
|
}else{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-30 09:01:34 +00:00
|
|
|
protected void deleteStoredFile(File deleteFile){
|
2022-12-22 01:55:19 +00:00
|
|
|
deleteFile.delete();
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-30 09:01:34 +00:00
|
|
|
protected void saveFile(MultipartFile file, File saveFile){
|
2022-12-22 01:55:19 +00:00
|
|
|
if(file.getSize()!=0){ // 저장될 파일 확인
|
|
|
|
|
if(!saveFile.exists()){ // 저장될 경로 확인
|
|
|
|
|
if(saveFile.getParentFile().mkdirs()){
|
|
|
|
|
try{
|
|
|
|
|
saveFile.createNewFile();
|
|
|
|
|
}catch (IOException e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
file.transferTo(saveFile);
|
|
|
|
|
}catch (IllegalStateException | IOException e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|