208 lines
5.6 KiB
Java
208 lines
5.6 KiB
Java
package kcg.faics.board.service.impl;
|
|
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import kcg.faics.board.util.BoardUtils;
|
|
import kcg.faics.board.util.BoardVOHandler;
|
|
import kcg.faics.board.vo.BoardFileVO;
|
|
import kcg.faics.cmmn.bbs.BaseFileService;
|
|
import kcg.faics.cmmn.egov.file.EgovFileMngUtil;
|
|
import kcg.faics.cmmn.egov.vo.FileVO;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
/**
|
|
* BoardFileServiceImpl.java
|
|
* @author 임새미
|
|
* @since 2016. 9. 28.
|
|
*
|
|
* 수정일 수정자 수정내용
|
|
* ------------- -------- ---------------------------
|
|
* 2016. 9. 28. 임새미 최초생성
|
|
*
|
|
*/
|
|
@Service("boardFileService")
|
|
public class BoardFileServiceImpl implements BaseFileService<BoardFileVO> {
|
|
|
|
/**
|
|
* BoardFileMapper - 게시판 파일 데이터 처리에 관한 Mapper 클래스
|
|
**/
|
|
@Resource(name = "boardFileMapper")
|
|
private BoardFileMapper boardFileMapper;
|
|
|
|
/**
|
|
* EgovFileMngUtil - 파일 업로드 처리에 관한 Util 클래스
|
|
**/
|
|
@Resource(name = "EgovFileMngUtil")
|
|
private EgovFileMngUtil fileUtil;
|
|
|
|
|
|
/**
|
|
* 선택한 게시물의 파일 리스트를 반환한다.
|
|
*
|
|
* @param bfBdSeq 게시판 아이디
|
|
* @return 선택한 게시물의 덧글 리스트
|
|
* @throws Exception 기본 예외 처리
|
|
*/
|
|
@Override
|
|
public List<BoardFileVO> selectList(final BoardFileVO boardFileVO) throws Exception {
|
|
return (List<BoardFileVO>) boardFileMapper.selectFiles(boardFileVO);
|
|
}
|
|
|
|
|
|
/**
|
|
* 선택한 파일정보를 반환한다.
|
|
*
|
|
* @param bfSeq 덧글 아이디
|
|
* @return 선택한 덧글의 상세 내용
|
|
* @throws Exception 기본 예외 처리
|
|
*/
|
|
@Override
|
|
public BoardFileVO select(final BoardFileVO boardFileVO) throws Exception {
|
|
return boardFileMapper.selectFile(boardFileVO);
|
|
}
|
|
|
|
|
|
/**
|
|
* 게시물의 첨부파일을 DB에 추가한다.
|
|
*
|
|
* @param bfBdSeq 게시물 아이디
|
|
* @param fileVO 파일 정보 객체
|
|
* @return 성공 - 1, 실패 - 0
|
|
* @exception Exception 기본 예외 처리
|
|
*/
|
|
@Override
|
|
public int insert(final BoardFileVO boardFileVO) throws Exception {
|
|
return boardFileMapper.insertFile(boardFileVO);
|
|
}
|
|
|
|
/**
|
|
* 게시물의 첨부파일들을 업로드한다.
|
|
*
|
|
* @param bfBdSeq 게시물 아이디
|
|
* @param fileMap 검색, 페이지 정보 객체
|
|
* @return 성공 - 1, 실패 - 0
|
|
* @exception Exception 기본 예외 처리
|
|
*/
|
|
@Override
|
|
@Transactional
|
|
public int insertAndSaveFiles(BoardFileVO boardFileVO, final Map<String, MultipartFile> fileMap) throws Exception {
|
|
int result = 1;
|
|
String storePathKey = "";
|
|
String boardId = "";
|
|
|
|
/* 파일쓰기 */
|
|
if (!fileMap.isEmpty()) {
|
|
if (boardFileVO != null) {
|
|
boardId = boardFileVO.getId();
|
|
boardId = StringUtils.lowerCase(boardId);
|
|
}
|
|
storePathKey = BoardUtils.getStorePathKey(boardId);
|
|
|
|
List<FileVO> uploadedFile = fileUtil.parseFileInf(fileMap, "_", 0, "", storePathKey);
|
|
|
|
/* DB에 업로드한 첨부파일 레코드를 추가한다. */
|
|
Iterator<FileVO> itr = uploadedFile.iterator();
|
|
while (itr.hasNext()) {
|
|
FileVO fileVO = itr.next();
|
|
boardFileVO.setOrgName(fileVO.getOrignlFileNm());
|
|
boardFileVO.setSaveName(fileVO.getStreFileNm());
|
|
boardFileVO.setOrders(Integer.parseInt(fileVO.getFileSn().replace("file", "")));
|
|
result = insert(boardFileVO);
|
|
if (result != 1) {
|
|
throw new Exception();
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 파일을 삭제한다.
|
|
*
|
|
* @param boardFileVO 파일정보
|
|
* @return 성공 - 1, 실패 - 0
|
|
* @throws Exception 기본 예외 처리
|
|
*/
|
|
@Override
|
|
public int deleteAndRemoveFile(final BoardFileVO boardFileVO) throws Exception {
|
|
int result = boardFileMapper.deleteFile(boardFileVO);
|
|
String storePathKey = "";
|
|
if (result == 1) {
|
|
/* DB에서 파일 데이터 삭제 후 실제 파일 삭제 여부는 보장하지 않는다. */
|
|
try {
|
|
storePathKey = BoardUtils.getStorePathKey(boardFileVO.getId());
|
|
fileUtil.deleteFile(boardFileVO.getSaveName(), storePathKey);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 선택한 파일을 삭제한다.
|
|
*
|
|
* @param bfBdSeq 선택한 게시물 아이디
|
|
* @param deleteFiles 선택한 게시물 아이디
|
|
* @return 성공 - 1, 실패 - 0
|
|
* @throws Exception 기본 예외 처리
|
|
*/
|
|
@Override
|
|
@Transactional
|
|
public int delete(final BoardFileVO boardFileVO) throws Exception {
|
|
int result = 1;
|
|
if (boardFileVO.getDeleteFiles() != null) {
|
|
for (String fileSeq : boardFileVO.getDeleteFiles()) {
|
|
BoardFileVO deleteFile = BoardVOHandler.getBFileVO(boardFileVO);
|
|
deleteFile.setSeq(Integer.parseInt(fileSeq));
|
|
deleteFile = select(deleteFile);
|
|
result = deleteAndRemoveFile(deleteFile);
|
|
|
|
if (result != 1) {
|
|
throw new Exception();
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
/**
|
|
* 게시물 내의 모든 파일을 삭제한다.
|
|
*
|
|
* @param bfBdSeq 선택한 게시물 아이디
|
|
* @return 성공 - 1, 실패 - 0
|
|
* @throws Exception 기본 예외 처리
|
|
*/
|
|
@Override
|
|
@Transactional
|
|
public int deleteAndRemoveFiles(final BoardFileVO boardFileVO) throws Exception {
|
|
|
|
int result = 1;
|
|
|
|
List<BoardFileVO> fileList = boardFileMapper.selectFiles(boardFileVO);
|
|
|
|
if (fileList != null) {
|
|
for (BoardFileVO file : fileList) {
|
|
result = deleteAndRemoveFile(file);
|
|
if (result != 1) {
|
|
throw new Exception();
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
}
|