File name
Commit message
Commit date
File name
Commit message
Commit date
2025-05-08
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
File name
Commit message
Commit date
package itn.let.utl.user.service;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.ModelAndView;
import itn.com.cmm.EgovMessageSource;
import itn.com.cmm.service.FileVO;
import itn.let.cop.bbs.service.BoardMaster;
import itn.let.cop.bbs.service.BoardMasterVO;
import itn.let.cop.bbs.service.EgovBBSAttributeManageService;
/**
*
* 게시판 체크에 대한 Util 클래스
* @author 사업기술본부 조용준(ITN)
* @since 2021.07.16
* @version 1.0
* @see
*
* <pre>
* << 개정이력(Modification Information) >>
*
* 수정일 수정자 수정내용
* ------- -------- ---------------------------
* 2021.07.16 조용준 최초 생성 *
*
* </pre>
*/
@Service("checkBoardUtil")
public class CheckBoardUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(CheckBoardUtil.class);
/** EgovMessageSource */
@Resource(name="egovMessageSource")
EgovMessageSource egovMessageSource;
/**
* //게시판 사용 여부 체크
*
* @param encrypt
*/
public BoardMasterVO checkBoardUse(
String p_boardBbsId
, ModelAndView p_modelAndView
, EgovBBSAttributeManageService bbsAttrbService
) throws Exception{
//LOGGER.debug("commonLoginUtil.checkBoardUse()");
return this.p_checkBoardUse(p_boardBbsId, p_modelAndView, bbsAttrbService);
}
/**
* //게시판 첨부 파일 제약 조건 체크
*
* @param encrypt
*/
/*
public boolean isPosblAtchFileMv(
List<FileVO> fileList
, BoardMaster boardMaster
, ModelAndView p_mv
, int atchFileCnt //기존에 파일이 있는 경우
, String p_exts //가능한 확장자를 받는다. |
) throws Exception {
//LOGGER.debug("commonLoginUtil.isPosblAtchFileMv()");
return this.p_isPosblAtchFileMv(fileList, boardMaster, p_mv, atchFileCnt, p_exts);
}
*/
/**
* //게시판 첨부 파일 제약 조건 체크
*
* @param encrypt
*/
/*
public boolean isPosblAtchFileMvNoBoard(
List<FileVO> fileList
, ModelAndView p_mv
, int atchFileCnt //기존에 파일이 있는 경우
, String p_exts //가능한 확장자를 받는다. |
, int p_i_file_size
, int p_i_file_count
) throws Exception {
//LOGGER.debug("commonLoginUtil.isPosblAtchFileMv()");
return this.p_isPosblAtchFileMvNoBoard(fileList, p_mv, atchFileCnt, p_exts, p_i_file_size, p_i_file_count);
}
*/
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//
// private function
//
//
/**
* //게시판 사용 여부 체크
*
* @param encrypt
*/
private BoardMasterVO p_checkBoardUse(
String p_boardBbsId
, ModelAndView p_modelAndView
, EgovBBSAttributeManageService bbsAttrbService
) throws Exception{
//게시판 관리 정보 획득 및 사용 여부 체크
BoardMasterVO bmVO = null;
try {
LOGGER.debug("commonLoginUtil.checkBoardUse()");
//게시판 관리 정보 획득 및 사용 여부 체크
bmVO = this.getBoardInfo(p_boardBbsId, bbsAttrbService);
//게시판 사용여부 체크
if (bmVO == null || ("N").equals(bmVO.getUseAt())) {
p_modelAndView.addObject("message", egovMessageSource.getMessage("fail.common.imposbl"));
p_modelAndView.addObject("result", "fail");
return null;
}
} catch(IllegalArgumentException e) {
LOGGER.error("[IllegalArgumentException] Try/Catch...usingParameters Runing : "+ e.getMessage());
} catch (Exception e) {
LOGGER.error("[" + e.getClass() +"] :" + e.getMessage());
}
return bmVO;
}
/**
* //게시판 첨부 파일 제약 조건 체크
*
* @param encrypt
*/
private boolean p_isPosblAtchFileMv(
List<FileVO> fileList
, BoardMaster boardMaster
, ModelAndView p_mv
, int atchFileCnt //기존에 파일이 있는 경우
, String p_exts //가능한 확장자를 받는다. |
) throws Exception {
boolean posblAtchFileFlag = true;
try {
LOGGER.debug("commonLoginUtil.isPosblAtchFileMv()");
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 encrypt
*/
private boolean p_isPosblAtchFileMvNoBoard(
List<FileVO> fileList
, ModelAndView p_mv
, int atchFileCnt //기존에 파일이 있는 경우
, String p_exts //가능한 확장자를 받는다. |
, int p_i_file_size
, int p_i_file_count
) throws Exception {
boolean posblAtchFileFlag = true;
try {
LOGGER.debug("commonLoginUtil.isPosblAtchFileMv()");
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;
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;
}
//관리자 설정 게시판 정보 가져오기
private BoardMasterVO getBoardInfo(
String p_bbsId
, EgovBBSAttributeManageService bbsAttrbService
)throws Exception{
BoardMasterVO bmVO = null;
try {
LOGGER.debug("commonLoginUtil.getBoardInfo()");
//게시판 등록 정보 획득
bmVO = new BoardMasterVO();
bmVO.setBbsId(p_bbsId);
bmVO = bbsAttrbService.selectBBSMasterInf(bmVO);
} catch(IllegalArgumentException e) {
LOGGER.error("[IllegalArgumentException] Try/Catch...usingParameters Runing : "+ e.getMessage());
} catch (Exception e) {
LOGGER.error("[" + e.getClass() +"] :" + e.getMessage());
}
return bmVO;
}
}