740 lines
24 KiB
Java
740 lines
24 KiB
Java
package kcc.com.utl.user.service;
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
import kcc.com.cmm.service.EgovFileMngService;
|
|
import kcc.com.cmm.service.EgovFileMngUtil;
|
|
import kcc.com.cmm.service.FileVO;
|
|
import kcc.com.cmm.util.StringUtil;
|
|
import kcc.let.cop.bbs.service.BoardMaster;
|
|
|
|
/**
|
|
*
|
|
* 파일 체크에 대한 Util 클래스
|
|
* @author 사업기술본부 조용준(ITN)
|
|
* @since 2021.07.16
|
|
* @version 1.0
|
|
* @see
|
|
*
|
|
* <pre>
|
|
* << 개정이력(Modification Information) >>
|
|
*
|
|
* 수정일 수정자 수정내용
|
|
* ------- -------- ---------------------------
|
|
* 2021.07.16 조용준 최초 생성 *
|
|
*
|
|
* </pre>
|
|
*/
|
|
/**
|
|
* @author User
|
|
*
|
|
*/
|
|
@Service("checkFileUtil")
|
|
public class CheckFileUtil {
|
|
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(CheckFileUtil.class);
|
|
|
|
/** EgovMessageSource */
|
|
/*
|
|
@Resource(name="egovMessageSource")
|
|
EgovMessageSource egovMessageSource;
|
|
*/
|
|
|
|
|
|
//파일 처리 egov
|
|
@Resource(name="EgovFileMngUtil")
|
|
private EgovFileMngUtil egovFileMngUtil;
|
|
|
|
//파일 처리 egov
|
|
@Resource(name = "EgovFileMngService")
|
|
private EgovFileMngService fileMngService;
|
|
|
|
|
|
|
|
private String s_exts = "txt|xls|xlsx|png|jpg|doc|ppt|hwp|pdf|pptx|bmp|jpeg|hwpx"; //첨부 가능한 확장자
|
|
|
|
private int i_file_count = 10; //첨부가능한 파일 수량
|
|
|
|
private int i_limit_size = 10; //첨부가능한 파일 용량 10MB
|
|
|
|
|
|
public String getS_exts() {
|
|
return s_exts;
|
|
}
|
|
|
|
//파일 업로드 수량 체크하기
|
|
public int getLimitCount(
|
|
HttpServletRequest p_request
|
|
)throws Exception{
|
|
|
|
return this.p_getLimitCount(p_request);
|
|
}
|
|
|
|
//파일 업로드 용량 체크하기
|
|
public int getLimitSize(
|
|
HttpServletRequest p_request
|
|
)throws Exception{
|
|
|
|
return this.p_getLimitSize(p_request);
|
|
}
|
|
|
|
/**
|
|
* //게시판 첨부 파일 제약 조건 체크
|
|
*
|
|
* @param encrypt
|
|
*/
|
|
/*
|
|
public boolean isPosblAtchFileMvWithBoardMaster1(
|
|
List<FileVO> fileList
|
|
, ModelAndView p_mv
|
|
, int atchFileCnt //기존에 파일이 있는 경우
|
|
, String p_exts //가능한 확장자를 받는다. |
|
|
|
|
, BoardMaster boardMaster //관리자 게시판 생성 정보
|
|
) throws Exception {
|
|
|
|
//LOGGER.debug("commonLoginUtil.isPosblAtchFileMv()");
|
|
|
|
return this.p_isPosblAtchFileMvWithBoardMaster(fileList, boardMaster, p_mv, atchFileCnt, p_exts);
|
|
}
|
|
*/
|
|
|
|
/**
|
|
* //게시판 첨부 파일 제약 조건 체크
|
|
*
|
|
* @param encrypt
|
|
*/
|
|
|
|
/**
|
|
* @param fileList
|
|
* @param p_mv
|
|
* @param atchFileCnt
|
|
* @param p_exts
|
|
* @param p_i_file_size
|
|
* @param p_i_file_count
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public boolean isPosblAtchFileMvWithUserSetting(
|
|
List<FileVO> fileList
|
|
, ModelAndView p_mv
|
|
|
|
, String p_exts //가능한 확장자를 받는다. |
|
|
, int p_i_file_size //파일 사이즈MB
|
|
, int p_i_file_count //파일 수량
|
|
, int atchFileCnt //기존에 파일이 있는 경우
|
|
|
|
) throws Exception {
|
|
|
|
//LOGGER.debug("commonLoginUtil.isPosblAtchFileMv()");
|
|
|
|
return this.p_isPosblAtchFileMvWithUserSetting(fileList, p_mv, p_exts, p_i_file_size, p_i_file_count, atchFileCnt);
|
|
}
|
|
|
|
/**
|
|
* @param p_multiRequest - MultipartHttpServletRequest
|
|
* @param p_modelAndView - ModelAndView
|
|
* @param p_file_nm_prefix - 파일 저장명 prefix
|
|
* @param p_exts - 가능한 확장자
|
|
* @param p_i_file_size - 가능한 파일 용량 MB 단위
|
|
* @param p_i_file_count - 가능한 파일 수량
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public String fileValCheckNdbInsert(
|
|
MultipartHttpServletRequest p_multiRequest
|
|
, ModelAndView p_modelAndView
|
|
, String p_file_nm_prefix //파일 저장명 prefix
|
|
, String p_exts //가능한 확장자를 받는다. |
|
|
, int p_i_file_size //가능한 파일 용량 MB 단위
|
|
, int p_i_file_count //가능한 파일 수량
|
|
|
|
) throws Exception{
|
|
|
|
return this.p_fileValCheckNdbInsert(p_multiRequest, p_modelAndView, p_file_nm_prefix, p_exts, p_i_file_size, p_i_file_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @param p_multiRequest - MultipartHttpServletRequest
|
|
* @param p_modelAndView - ModelAndView
|
|
* @param p_file_nm_prefix - 파일 저장명 prefix
|
|
* @param p_exts - 가능한 확장자
|
|
* @param p_i_file_size - 가능한 파일 용량 MB 단위
|
|
* @param p_i_file_count - 가능한 파일 수량
|
|
* @param p_atchFileId - 기존 파일 그룹명
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public String fileValCheckNdbUpdate(
|
|
MultipartHttpServletRequest p_multiRequest
|
|
, ModelAndView p_modelAndView
|
|
, String p_file_nm_prefix //파일 저장명 prefix
|
|
, String p_exts //가능한 확장자를 받는다. |
|
|
, int p_i_file_size //가능한 파일 용량 MB 단위
|
|
, int p_i_file_count //가능한 파일 수량
|
|
, String p_atchFileId
|
|
//, BoardMasterVO p_bmVO //게시판 형인 경우 사용
|
|
) throws Exception{
|
|
|
|
return this.p_fileValCheckNdbUpdate(p_multiRequest, p_modelAndView, p_file_nm_prefix, p_exts, p_i_file_size, p_i_file_count, p_atchFileId);
|
|
}
|
|
/**
|
|
* //업로드된 text 파일에서 내용 추출하기
|
|
*
|
|
* @param encrypt
|
|
*/
|
|
//text 파일에서 추출하기
|
|
/*
|
|
public List<String> extractFromTxtFile3(
|
|
MultipartHttpServletRequest p_multiRequest
|
|
, List<String> p_sb
|
|
) throws Exception{
|
|
|
|
return this.p_extractFromTxtFile(p_multiRequest, p_sb);
|
|
}
|
|
*/
|
|
|
|
/**
|
|
* //업로드된 excel 파일에서 내용 추출하기
|
|
*
|
|
* @param encrypt
|
|
*/
|
|
//excel 파일에서 추출하기(xls, xlsx)
|
|
/*
|
|
public List<String> extractFromExcelFile4(
|
|
MultipartHttpServletRequest p_multiRequest
|
|
, List<String> p_sb
|
|
) throws Exception{
|
|
|
|
return this.p_extractFromExcelFile(p_multiRequest, p_sb);
|
|
}
|
|
*/
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
//
|
|
// private function
|
|
//
|
|
//
|
|
|
|
|
|
/**
|
|
* //게시판 첨부 파일 제약 조건으로 파일 체크
|
|
*
|
|
* @param encrypt
|
|
*/
|
|
private boolean p_isPosblAtchFileMvWithBoardMaster(
|
|
List<FileVO> fileList
|
|
, BoardMaster boardMaster
|
|
, ModelAndView p_mv
|
|
, int atchFileCnt //기존에 파일이 있는 경우
|
|
, String p_exts //가능한 확장자를 받는다. |
|
|
) throws Exception {
|
|
|
|
boolean posblAtchFileFlag = true;
|
|
|
|
try {
|
|
LOGGER.debug("CheckFileUtil.isPosblAtchFileMvWithBoardMaster()");
|
|
|
|
|
|
int fileCnt = 0;
|
|
long posblAtchFileSize = Long.parseLong(boardMaster.getPosblAtchFileSize()) * 1024 * 1024 ;
|
|
int posblAtchFileNumber = Integer.parseInt(boardMaster.getPosblAtchFileNumber());
|
|
//String bbsTyCode = boardMaster.getBbsTyCode();
|
|
String flashMessage = "";
|
|
boolean posblAtchFileSizeFlag = true;
|
|
boolean posblAtchFileExtFlag = true;
|
|
|
|
String[] imgExts = p_exts.split("\\|");
|
|
|
|
Iterator<?> iter = fileList.iterator();
|
|
while (iter.hasNext()) {
|
|
FileVO vo = (FileVO) iter.next();
|
|
long fileMg = Long.parseLong(vo.getFileMg());
|
|
String fileExt = vo.getFileExtsn();
|
|
|
|
if (fileMg > posblAtchFileSize) posblAtchFileSizeFlag = false;
|
|
|
|
//String[] imgExts = {"gif", "jpg", "bmp", "jpeg", "png"};
|
|
//String[] imgExts = {"xlsx", "xls", "zip", "hwp", "txt", "doc", "docx", "csv"};
|
|
|
|
if (ArrayUtils.indexOf(imgExts, fileExt.toLowerCase()) == -1) posblAtchFileExtFlag = false;
|
|
|
|
fileCnt++;
|
|
}
|
|
|
|
if (!posblAtchFileExtFlag) {
|
|
for (int i=0;i<imgExts.length;i++) {
|
|
if (i==0) flashMessage += imgExts[i];
|
|
else flashMessage += ", " + imgExts[i];
|
|
}
|
|
flashMessage += " 형식의 확장자만 업로드 가능합니다." + "\\n";
|
|
posblAtchFileFlag = false;
|
|
}
|
|
if(!posblAtchFileSizeFlag) {
|
|
flashMessage += "파일사이즈가 초과되었습니다. 최대크기 " + posblAtchFileSize + "mb" + "\\n";
|
|
posblAtchFileFlag = false;
|
|
}
|
|
if ((fileCnt+atchFileCnt) > posblAtchFileNumber) {
|
|
flashMessage += "파일 개수가 초과되었습니다. 최대개수 " + posblAtchFileNumber + "개" + "\\n";
|
|
posblAtchFileFlag = false;
|
|
}
|
|
|
|
if (!posblAtchFileFlag) p_mv.addObject("message", flashMessage);
|
|
|
|
} catch(IllegalArgumentException e) {
|
|
LOGGER.error("[IllegalArgumentException] Try/Catch...usingParameters Runing : "+ e.getMessage());
|
|
} catch (Exception e) {
|
|
LOGGER.error("[" + e.getClass() +"] :" + e.getMessage());
|
|
}
|
|
|
|
return posblAtchFileFlag;
|
|
}
|
|
|
|
|
|
/**
|
|
* //사용자의 조건으로 첨부 파일 제약 조건 체크
|
|
* * @param p_multiRequest - MultipartHttpServletRequest
|
|
* @param p_modelAndView - ModelAndView
|
|
* @param p_file_nm_prefix - 파일 저장명 prefix
|
|
* @param p_exts - 가능한 확장자
|
|
* @param p_i_file_size - 가능한 파일 용량 MB 단위
|
|
* @param p_i_file_count - 가능한 파일 수량
|
|
* @param encrypt
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
* @param fileList - 대상 파일 리스트
|
|
* @param p_mv - ModelAndView *
|
|
* @param p_exts - 가능한 확장자를 받는다.
|
|
* @param p_i_file_size - 가능한 파일 용량 MB 단위
|
|
* @param p_i_file_count - 가능한 파일 수량
|
|
* @param atchFileCnt - 기존 첨부된 파일 수량
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
private boolean p_isPosblAtchFileMvWithUserSetting(
|
|
List<FileVO> fileList
|
|
, ModelAndView p_mv
|
|
, String p_exts //가능한 확장자를 받는다. |
|
|
, int p_i_file_size //파일 제한 사이즈 MB
|
|
, int p_i_file_count //파일 제한 수량
|
|
, int atchFileCnt //기존에 파일이 있는 경우
|
|
) throws Exception {
|
|
|
|
boolean posblAtchFileFlag = true;
|
|
|
|
try {
|
|
LOGGER.debug("CheckFileUtil.isPosblAtchFileMvWithUserSetting()");
|
|
|
|
|
|
int fileCnt = 0;
|
|
long posblAtchFileSize = p_i_file_size * 1024 * 1024 ;
|
|
int posblAtchFileNumber = p_i_file_count;
|
|
//String bbsTyCode = boardMaster.getBbsTyCode();
|
|
String flashMessage = "";
|
|
boolean posblAtchFileSizeFlag = true;
|
|
boolean posblAtchFileExtFlag = true;
|
|
|
|
String[] imgExts = p_exts.split("\\|");
|
|
|
|
Iterator<?> iter = fileList.iterator();
|
|
while (iter.hasNext()) {
|
|
FileVO vo = (FileVO) iter.next();
|
|
long fileMg = Long.parseLong(vo.getFileMg());
|
|
String fileExt = vo.getFileExtsn();
|
|
|
|
if (fileMg > posblAtchFileSize) posblAtchFileSizeFlag = false;
|
|
|
|
//String[] imgExts = {"gif", "jpg", "bmp", "jpeg", "png"};
|
|
//String[] imgExts = {"xlsx", "xls", "zip", "hwp", "txt", "doc", "docx", "csv"};
|
|
|
|
if (ArrayUtils.indexOf(imgExts, fileExt.toLowerCase()) == -1) posblAtchFileExtFlag = false;
|
|
|
|
System.out.println("fileMg");
|
|
System.out.println(fileCnt);
|
|
System.out.println(fileMg);
|
|
System.out.println(vo.getOrignlFileNm());
|
|
|
|
fileCnt++;
|
|
}
|
|
|
|
if (!posblAtchFileExtFlag) {
|
|
for (int i=0;i<imgExts.length;i++) {
|
|
if (i==0) flashMessage += imgExts[i];
|
|
else flashMessage += ", " + imgExts[i];
|
|
}
|
|
flashMessage += " 형식의 확장자만 업로드 가능합니다." + "\\n";
|
|
posblAtchFileFlag = false;
|
|
}
|
|
if(!posblAtchFileSizeFlag) {
|
|
flashMessage += "파일사이즈가 초과되었습니다. 최대크기 " + posblAtchFileSize + "mb" + "\\n";
|
|
posblAtchFileFlag = false;
|
|
}
|
|
if ((fileCnt+atchFileCnt) > posblAtchFileNumber) {
|
|
flashMessage += fileCnt + " " + atchFileCnt + " ";
|
|
flashMessage += "파일 개수가 초과되었습니다. 최대개수 " + posblAtchFileNumber + "개" + "\\n";
|
|
posblAtchFileFlag = false;
|
|
}
|
|
|
|
if (!posblAtchFileFlag) p_mv.addObject("message", flashMessage);
|
|
|
|
} catch(IllegalArgumentException e) {
|
|
LOGGER.error("[IllegalArgumentException] Try/Catch...usingParameters Runing : "+ e.getMessage());
|
|
} catch (Exception e) {
|
|
LOGGER.error("[" + e.getClass() +"] :" + e.getMessage());
|
|
}
|
|
|
|
return posblAtchFileFlag;
|
|
}
|
|
|
|
/**
|
|
* //업로드된 text 파일에서 내용 추출하기
|
|
*
|
|
* @param encrypt
|
|
*/
|
|
//text 파일에서 추출하기
|
|
private List<String> p_extractFromTxtFile(
|
|
MultipartHttpServletRequest p_multiRequest
|
|
, List<String> p_sb
|
|
) throws Exception{
|
|
|
|
LOGGER.debug("CheckFileUtil.extractFromTxtFile()");
|
|
|
|
List<MultipartFile> files = (List<MultipartFile>) p_multiRequest.getFiles("file");
|
|
|
|
if(!files.isEmpty()) {
|
|
|
|
if (files.get(0).getSize() > 0
|
|
&& files.get(0).getOriginalFilename().split("[.]")[1].indexOf("txt") > -1) {
|
|
|
|
//Multi file to file 변환해주기
|
|
File file = new File(files.get(0).getOriginalFilename());
|
|
file.createNewFile();
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
|
|
try {
|
|
|
|
fos.write(files.get(0).getBytes());
|
|
fos.close();
|
|
|
|
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
|
|
|
|
String line = null;
|
|
|
|
while ((line = reader.readLine()) != null) {
|
|
p_sb.add(line);
|
|
|
|
} // end while
|
|
|
|
} catch (IOException e) {
|
|
System.err.println("IOException Occured");
|
|
} finally {
|
|
|
|
try {
|
|
|
|
if (fos != null) fos.close();
|
|
|
|
} catch (IOException e2) {
|
|
System.err.println("IOException Occured");
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return p_sb;
|
|
}
|
|
|
|
/**
|
|
* //업로드된 excel 파일에서 내용 추출하기
|
|
*
|
|
* @param encrypt
|
|
*/
|
|
//excel 파일에서 추출하기(xls, xlsx)
|
|
private List<String> p_extractFromExcelFile(
|
|
MultipartHttpServletRequest p_multiRequest
|
|
, List<String> p_sb
|
|
) throws Exception{
|
|
|
|
LOGGER.debug("CheckFileUtil.extractFromExcelFile()");
|
|
|
|
List<MultipartFile> files = (List<MultipartFile>) p_multiRequest.getFiles("file");
|
|
|
|
if(!files.isEmpty()) {
|
|
|
|
if (files.get(0).getSize() > 0
|
|
&& (files.get(0).getContentType().indexOf("spreadsheetml") > -1
|
|
|| files.get(0).getContentType().indexOf("ms-excel") > -1
|
|
)
|
|
|
|
&&(
|
|
files.get(0).getOriginalFilename().split("[.]")[1].indexOf("xlsx") > -1
|
|
|| files.get(0).getOriginalFilename().split("[.]")[1].indexOf("xls") > -1
|
|
)
|
|
) {
|
|
|
|
String Ext = files.get(0).getOriginalFilename().split("[.]")[1];
|
|
|
|
String cellValue = "";
|
|
|
|
//엑셀 확장자에 따른 처리 로직 분리
|
|
if(Ext.equals("xls")) {
|
|
|
|
HSSFWorkbook workbook = new HSSFWorkbook(files.get(0).getInputStream());
|
|
HSSFSheet sheet = workbook.getSheetAt(0); //첫번째 sheet 만 처리
|
|
|
|
for(int i=0; i< sheet.getLastRowNum(); i++){ //먼저 밸리데이션 체크(1줄은 생략)
|
|
HSSFRow row = sheet.getRow(i); //열읽기
|
|
|
|
cellValue = "";
|
|
|
|
for(int j = 0 ; j < row.getLastCellNum(); j++){ //행읽기(6행까지나 2행까지만 필요)
|
|
HSSFCell cell = row.getCell(j); //이름/핸드폰/변환1/변환2/변환3/변환4/변환5
|
|
|
|
if(cell != null){
|
|
switch(cell.getCellType()){ //숫자타임을 문자로 변환
|
|
case Cell.CELL_TYPE_NUMERIC:
|
|
cell.setCellType(Cell.CELL_TYPE_STRING);
|
|
}
|
|
cellValue = cellValue + StringUtil.getString(cell.getStringCellValue().trim()) + "\t";
|
|
}
|
|
}
|
|
|
|
p_sb.add(cellValue);
|
|
}
|
|
|
|
}else { //확장자가 xlsx
|
|
|
|
OPCPackage opcPackage = OPCPackage.open(files.get(0).getInputStream());
|
|
XSSFWorkbook workbook = new XSSFWorkbook(opcPackage);
|
|
XSSFSheet sheet = workbook.getSheetAt(0); // 첫번째 시트 불러오기
|
|
opcPackage.close();
|
|
|
|
for(int i=0; i< sheet.getLastRowNum(); i++){ //먼저 밸리데이션 체크(1줄은 생략)
|
|
XSSFRow row = sheet.getRow(i); //열읽기
|
|
|
|
cellValue = "";
|
|
|
|
for(int j = 0 ; j < row.getLastCellNum(); j++){ //행읽기(6행까지나 2행까지만 필요)
|
|
XSSFCell cell = row.getCell(j); //이름/핸드폰/변환1/변환2/변환3/변환4/변환5
|
|
|
|
if(cell != null){
|
|
switch(cell.getCellType()){ //숫자타임을 문자로 변환
|
|
case Cell.CELL_TYPE_NUMERIC:
|
|
cell.setCellType(Cell.CELL_TYPE_STRING);
|
|
}
|
|
cellValue = cellValue + StringUtil.getString(cell.getStringCellValue().trim()) + "\t";
|
|
}
|
|
}
|
|
|
|
p_sb.add(cellValue);
|
|
}
|
|
} //xlsx 처리 끝
|
|
}
|
|
}
|
|
|
|
return p_sb;
|
|
}
|
|
|
|
|
|
//파일 업로드 수량 체크하기
|
|
private int p_getLimitCount(
|
|
HttpServletRequest p_request
|
|
)throws Exception{
|
|
|
|
LOGGER.debug("CheckFileUtil.getLimitCount()");
|
|
|
|
int i_ret = i_file_count; //기본 파일 첨부 가능 수량 가져오기
|
|
|
|
try {
|
|
String s_file_limit = p_request.getParameter("limitcount");
|
|
if (!"".equals(s_file_limit)) {
|
|
i_ret = Integer.parseInt(s_file_limit);
|
|
}
|
|
|
|
}catch(Exception ex) {
|
|
System.out.println("Exception Occured!!!");
|
|
}
|
|
|
|
return i_ret;
|
|
}
|
|
|
|
|
|
//파일 업로드 사이즈 체크하기
|
|
private int p_getLimitSize(
|
|
HttpServletRequest p_request
|
|
)throws Exception{
|
|
|
|
LOGGER.debug("CheckFileUtil.getLimitSize()");
|
|
|
|
int i_ret = i_limit_size; //기본 파일 첨부 가능 수량 가져오기
|
|
|
|
try {
|
|
String s_limit_size = p_request.getParameter("limitsize");
|
|
if (s_limit_size != null && !"".equals(s_limit_size)) {
|
|
i_ret = Integer.parseInt(s_limit_size);
|
|
}
|
|
|
|
}catch(Exception ex) {
|
|
System.out.println("Exception Occured!!!");
|
|
}
|
|
|
|
return i_ret;
|
|
}
|
|
|
|
//사용자 업로드 파일 처리 - 파일수량 상관없음 - 전자정부 게시판 인 경우에 대한 변형만 있음(파일수량은 1~ 처리 가능)
|
|
/**
|
|
* @param p_multiRequest - MultipartHttpServletRequest
|
|
* @param p_modelAndView - ModelAndView
|
|
* @param p_file_nm_prefix - 파일 저장명 prefix
|
|
* @param p_exts - 가능한 확장자
|
|
* @param p_i_file_size - 가능한 파일 용량 MB 단위
|
|
* @param p_i_file_count - 가능한 파일 수량
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
private String p_fileValCheckNdbInsert(
|
|
MultipartHttpServletRequest p_multiRequest
|
|
, ModelAndView p_modelAndView
|
|
, String p_file_nm_prefix //파일 저장명 prefix
|
|
, String p_exts //가능한 확장자를 받는다. |
|
|
, int p_i_file_size //가능한 파일 용량 MB 단위
|
|
, int p_i_file_count //가능한 파일 수량
|
|
|
|
) throws Exception{
|
|
|
|
LOGGER.debug("CheckFileUtil.fileValCheckNdbInsert()");
|
|
|
|
boolean in_bool = true;
|
|
|
|
|
|
List<FileVO> result = null;
|
|
String atchFileId = "";
|
|
String isThumbFile = "";
|
|
//String isThumbFile = "thumbFile"; //"thumbFile" - 썸네일을 생성한다.
|
|
|
|
final Map<String, MultipartFile> files = p_multiRequest.getFileMap();
|
|
if (!files.isEmpty()) {
|
|
result = egovFileMngUtil.parseFileInf(files, p_file_nm_prefix, 0, "", "", isThumbFile);
|
|
|
|
|
|
//관리자에서 게시판 설정시 업로드 파일 사이즈와 수량 체크용
|
|
//사용자 설정용 업로드 파일 사이즈 & 파일 수량 & 확장자 체크용
|
|
if(!isPosblAtchFileMvWithUserSetting(result, p_modelAndView, p_exts, p_i_file_size, p_i_file_count, 0)) {
|
|
p_modelAndView.addObject("result", "fail");
|
|
|
|
in_bool = false;
|
|
|
|
}else {
|
|
atchFileId = fileMngService.insertFileInfs(result); //첨부 파일
|
|
|
|
}
|
|
|
|
}else {
|
|
System.out.println("isempty");
|
|
}
|
|
|
|
if (!in_bool) atchFileId = "ERROR";
|
|
|
|
return atchFileId;
|
|
}
|
|
|
|
//사용자 업로드 파일 처리 - 파일수량 상관없음 - 전자정부 게시판 인 경우에 대한 변형만 있음(파일수량은 1~ 처리 가능)
|
|
/**
|
|
* @param p_multiRequest - MultipartHttpServletRequest
|
|
* @param p_modelAndView - ModelAndView
|
|
* @param p_file_nm_prefix - 파일 저장명 prefix
|
|
* @param p_exts - 가능한 확장자
|
|
* @param p_i_file_size - 가능한 파일 용량 MB 단위
|
|
* @param p_i_file_count - 가능한 파일 수량
|
|
* @param p_atchFileId - 기존 파일 그룹명
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
private String p_fileValCheckNdbUpdate(
|
|
MultipartHttpServletRequest p_multiRequest
|
|
, ModelAndView p_modelAndView
|
|
, String p_file_nm_prefix //파일 저장명 prefix
|
|
, String p_exts //가능한 확장자를 받는다. |
|
|
, int p_i_file_size //가능한 파일 용량 MB 단위
|
|
, int p_i_file_count //가능한 파일 수량
|
|
, String p_atchFileId
|
|
//, BoardMasterVO p_bmVO //게시판 형인 경우 사용
|
|
) throws Exception{
|
|
|
|
LOGGER.debug("CheckFileUtil.fileValCheckNdbUpdate()");
|
|
|
|
boolean in_bool = true;
|
|
|
|
List<FileVO> result = null;
|
|
//String atchFileId = "";
|
|
String isThumbFile = "";
|
|
//String isThumbFile = "thumbFile"; //"thumbFile" - 썸네일을 생성한다.
|
|
|
|
final Map<String, MultipartFile> files = p_multiRequest.getFileMap();
|
|
if (!files.isEmpty()) {
|
|
FileVO fvo = new FileVO();
|
|
fvo.setAtchFileId(p_atchFileId);
|
|
int cnt = fileMngService.getMaxFileSN(fvo);
|
|
|
|
|
|
//관리자에서 게시판 설정시 업로드 파일 사이즈와 수량 체크용
|
|
//사용자 설정용 업로드 파일 사이즈 & 파일 수량 & 확장자 체크용
|
|
if(!isPosblAtchFileMvWithUserSetting(result, p_modelAndView, p_exts, p_i_file_size, p_i_file_count, 0)) {
|
|
p_modelAndView.addObject("result", "fail");
|
|
|
|
in_bool = false;
|
|
|
|
}else {
|
|
//atchFileId = fileMngService.insertFileInfs(result); //첨부 파일
|
|
//result = egovFileMngUtil.parseFileInf(files, "CHGDATE_", cnt, p_atchFileId, "", isThumbFile);
|
|
result = egovFileMngUtil.parseFileInf(files, p_file_nm_prefix, cnt, p_atchFileId, "", isThumbFile);
|
|
fileMngService.updateFileInfs(result);
|
|
|
|
}
|
|
|
|
}else {
|
|
System.out.println("isempty");
|
|
}
|
|
|
|
if (!in_bool) p_atchFileId = "ERROR";
|
|
|
|
return p_atchFileId;
|
|
}
|
|
|
|
} |