192 lines
8.3 KiB
Java
192 lines
8.3 KiB
Java
package seed.common.service;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import net.coobird.thumbnailator.Thumbnails;
|
|
|
|
import org.apache.log4j.Logger;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
import egovframework.rte.fdl.cmmn.AbstractServiceImpl;
|
|
|
|
import seed.dao.CommonFileDAO;
|
|
import seed.map.T_COMMON_FILE;
|
|
import seed.utils.SeedFileUtils;
|
|
import seed.utils.SeedFtpType;
|
|
import seed.utils.SeedUtils;
|
|
|
|
@Service
|
|
public class CommonFileServiceImpl extends AbstractServiceImpl implements CommonFileService{
|
|
|
|
private Logger log = Logger.getLogger(this.getClass());
|
|
|
|
@Autowired
|
|
private CommonFileDAO commonFileDAO;
|
|
|
|
public List<T_COMMON_FILE> getCommonFileList(Integer funcIdx, String fileCode){
|
|
|
|
return commonFileDAO.getCommonFileList(funcIdx, fileCode);
|
|
}
|
|
|
|
public T_COMMON_FILE getCommonFileForm(Integer commonFileIdx){
|
|
|
|
return commonFileDAO.getCommonFileForm(commonFileIdx);
|
|
}
|
|
|
|
@Transactional
|
|
public T_COMMON_FILE setCommonFileRegProc(T_COMMON_FILE tCommonFile, MultipartFile upFile, String siteIdx, boolean fileEncryChk, Integer funcIdx, String fileCode, String rootPath){
|
|
|
|
try{
|
|
|
|
SimpleDateFormat sdfFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
|
String toDate = sdfFormat.format(new Date()).substring(0, 8);
|
|
|
|
//오늘날짜 18시 이후면 다른 폴더 삭제 및 DB삭제
|
|
if(Integer.parseInt(sdfFormat.format(new Date()).substring(8, 10)) >= 18){
|
|
SeedUtils.setSeedDeleteFiles(rootPath + "/" + siteIdx + "/upload/tempFiles/", toDate);
|
|
|
|
List<T_COMMON_FILE> tCommonFileList = commonFileDAO.getCommonFileList(toDate);
|
|
if(tCommonFileList != null && tCommonFileList.size() > 0){
|
|
for(int i=0; i<tCommonFileList.size(); i++){
|
|
T_COMMON_FILE tCommonFileDB = tCommonFileList.get(i);
|
|
commonFileDAO.setCommonFileDelProc(tCommonFileDB);
|
|
}
|
|
}
|
|
}
|
|
|
|
//오늘날짜로 폴더 생성(MD5로 폴더 변환하여 생성)
|
|
SeedUtils.setSeedMkDirs(rootPath + "/" + siteIdx + "/upload/tempFiles/" + toDate + "/" + fileCode);
|
|
|
|
String reFileName = funcIdx + "_" + sdfFormat.format(new Date()) + "_" + SeedUtils.getSeedMD5Code(String.valueOf(SeedUtils.getRandom(999,1)));
|
|
|
|
File makeFile = new File(rootPath + "/" + siteIdx + "/upload/tempFiles/" + toDate + "/" +
|
|
fileCode + "/" + reFileName + upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf(".")));
|
|
upFile.transferTo(makeFile);
|
|
|
|
if(upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf(".")+1).toLowerCase().equals("jpg") ||
|
|
upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf(".")+1).toLowerCase().equals("jpeg") ||
|
|
upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf(".")+1).toLowerCase().equals("bmp") ||
|
|
upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf(".")+1).toLowerCase().equals("png")){
|
|
|
|
Thumbnails.of(
|
|
new File(rootPath + "/" + siteIdx + "/upload/tempFiles/" + toDate + "/" +
|
|
fileCode + "/" + reFileName + upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf(".")))).
|
|
size(100, 50).
|
|
toFile(new File(rootPath + "/" + siteIdx + "/upload/tempFiles/" + toDate + "/" +
|
|
fileCode + "/thumb_" + reFileName + upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf(".")))
|
|
);
|
|
|
|
}else if(upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf(".")+1).toLowerCase().equals("gif")){
|
|
|
|
SeedUtils.setSeedFileCopy(rootPath + "/" + siteIdx + "/upload/tempFiles/" + toDate + "/" +
|
|
fileCode + "/" + reFileName + upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf(".")),
|
|
rootPath + "/" + siteIdx + "/upload/tempFiles/" + toDate + "/" + fileCode + "/thumb_" + reFileName + upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf(".")));
|
|
}
|
|
|
|
tCommonFile.setCommonFileFuncIdx(funcIdx);
|
|
tCommonFile.setCommonFileCode(fileCode);
|
|
tCommonFile.setCommonFileDate(toDate);
|
|
tCommonFile.setCommonFileRegDate(new Date());
|
|
tCommonFile.setCommonFileName(upFile.getOriginalFilename());
|
|
tCommonFile.setCommonFileReName(reFileName+upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf(".")));
|
|
tCommonFile.setCommonFileSize(upFile.getSize());
|
|
tCommonFile.setCommonFileType(upFile.getOriginalFilename().toLowerCase().substring(upFile.getOriginalFilename().lastIndexOf(".")+1));
|
|
tCommonFile.setCommonFileEncryption("N");
|
|
|
|
if(fileEncryChk){
|
|
|
|
//파일 암호화
|
|
SeedFileUtils.setSeedEncryptFile(rootPath + "/" + siteIdx + "/upload/tempFiles/" + toDate + "/" +
|
|
fileCode + "/" + reFileName + upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf(".")));
|
|
|
|
//원본 파일 삭제
|
|
makeFile.delete();
|
|
|
|
//암호화된 파일명 원본 파일명으로 변경
|
|
File encryFile = new File(rootPath + "/" + siteIdx + "/upload/tempFiles/" + toDate + "/" +
|
|
fileCode + "/" + reFileName + upFile.getOriginalFilename().substring(upFile.getOriginalFilename().lastIndexOf("."))+".des");
|
|
|
|
encryFile.renameTo(makeFile);
|
|
|
|
tCommonFile.setCommonFileEncryption("Y");
|
|
}
|
|
}catch(IOException e){
|
|
log.error("CHECK ERROR:",e);
|
|
}
|
|
|
|
return commonFileDAO.setCommonFileRegProc(tCommonFile);
|
|
}
|
|
|
|
@Transactional
|
|
public boolean setCommonFileDelProc(Integer commonFileIdx, String siteIdx, String rootPath){
|
|
|
|
SimpleDateFormat sdfFormat = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
String toDate = sdfFormat.format(new Date()).substring(0, 8);
|
|
|
|
T_COMMON_FILE tCommonFile = commonFileDAO.getCommonFileForm(commonFileIdx);
|
|
|
|
SeedUtils.setSeedDeleteFile(rootPath + "/" + siteIdx + "/upload/tempFiles/" + toDate + "/" +
|
|
tCommonFile.getCommonFileCode() + "/" + tCommonFile.getCommonFileReName());
|
|
|
|
return commonFileDAO.setCommonFileDelProc(tCommonFile);
|
|
}
|
|
|
|
public boolean setMultiFileRegProc(List<MultipartFile> upFiles, String siteIdx, String filePath, String rootPath){
|
|
|
|
boolean success = false;
|
|
|
|
try{
|
|
|
|
//FTP 전송
|
|
SeedFtpType seedFtpType = new SeedFtpType();
|
|
|
|
for(int f=0; f<upFiles.size(); f++){
|
|
|
|
if(filePath != null && !filePath.equals("")){
|
|
File makeFile = new File(rootPath + "/" + siteIdx + filePath + "/" + upFiles.get(f).getOriginalFilename());
|
|
upFiles.get(f).transferTo(makeFile);
|
|
|
|
//WEB 서버의 경로
|
|
seedFtpType.setDestFilePath(siteIdx + filePath);
|
|
//WAS 서버의 경로
|
|
seedFtpType.setSrcFilePath(rootPath + "/" + siteIdx + filePath);
|
|
//WAS 파일명
|
|
seedFtpType.setFileName(upFiles.get(f).getOriginalFilename());
|
|
//파일 전송 타입 regFile=WEB 서버에 파일전송, delFile=WEB 서버에 파일삭제
|
|
seedFtpType.setFtpType("regFile");
|
|
seedFtpType.setSeedFtp();
|
|
|
|
}else{
|
|
File makeFile = new File(rootPath + "/" + siteIdx + "/" + upFiles.get(f).getOriginalFilename());
|
|
upFiles.get(f).transferTo(makeFile);
|
|
|
|
//WEB 서버의 경로
|
|
seedFtpType.setDestFilePath(siteIdx);
|
|
//WAS 서버의 경로
|
|
seedFtpType.setSrcFilePath(rootPath + "/" + siteIdx);
|
|
//WAS 파일명
|
|
seedFtpType.setFileName(upFiles.get(f).getOriginalFilename());
|
|
//파일 전송 타입 regFile=WEB 서버에 파일전송, delFile=WEB 서버에 파일삭제
|
|
seedFtpType.setFtpType("regFile");
|
|
seedFtpType.setSeedFtp();
|
|
}
|
|
}
|
|
success = true;
|
|
|
|
}catch(IOException e){
|
|
success = false;
|
|
log.error("CHECK ERROR:",e);
|
|
}
|
|
|
|
return success;
|
|
}
|
|
}
|