package egovframework.com.cmm.web;
import java.io.File;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import egovframework.com.cmm.service.EgovFileMngService;
import egovframework.com.cmm.service.FileVO;
import egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper;
/**
* 파일 조회, 삭제, 다운로드 처리를 위한 컨트롤러 클래스
* @author 공통서비스개발팀 이삼섭
* @since 2009.06.01
* @version 1.0
* @see
*
*
* << 개정이력(Modification Information) >>
*
* 수정일 수정자 수정내용
* ------- -------- ---------------------------
* 2009.03.25 이삼섭 최초 생성
* 2011.08.31 JJY 경량환경 템플릿 커스터마이징버전 생성
*
*
*/
@Controller
public class EgovFileMngController {
@Resource(name = "EgovFileMngService")
private EgovFileMngService fileService;
/**
* 첨부파일에 대한 목록을 조회한다.
*
* @param fileVO
* @param atchFileId
* @param sessionVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/cmm/fms/selectFileInfs.do")
public String selectFileInfs(@ModelAttribute("searchVO") FileVO fileVO, @RequestParam Map commandMap, ModelMap model) throws Exception {
String atchFileId = (String) commandMap.get("param_atchFileId");
fileVO.setAtchFileId(atchFileId);
List result = fileService.selectFileInfs(fileVO);
model.addAttribute("fileList", result);
model.addAttribute("updateFlag", "N");
model.addAttribute("fileListCnt", result.size());
model.addAttribute("atchFileId", atchFileId);
return "cmm/fms/EgovFileList";
}
/**
* 첨부파일 변경을 위한 수정페이지로 이동한다.
*
* @param fileVO
* @param atchFileId
* @param sessionVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/cmm/fms/selectFileInfsForUpdate.do")
public String selectFileInfsForUpdate(@ModelAttribute("searchVO") FileVO fileVO, @RequestParam Map commandMap, ModelMap model) throws Exception {
String atchFileId = (String) commandMap.get("param_atchFileId");
fileVO.setAtchFileId(atchFileId);
List result = fileService.selectFileInfs(fileVO);
model.addAttribute("fileList", result);
model.addAttribute("updateFlag", "Y");
model.addAttribute("fileListCnt", result.size());
model.addAttribute("atchFileId", atchFileId);
if(commandMap.get("img_view") !=null){
model.addAttribute("img_view", (String)commandMap.get("img_view"));
}
if(commandMap.get("img_view_w") !=null){
model.addAttribute("img_view_w", (String)commandMap.get("img_view_w"));
}
if(commandMap.get("img_view_h") !=null){
model.addAttribute("img_view_h", (String)commandMap.get("img_view_h"));
}
if(commandMap.get("img_size_text") !=null){
model.addAttribute("img_size_text", (String)commandMap.get("img_size_text"));
}
model.addAttribute("commandMap", commandMap);
return "cmm/fms/EgovFileList";
}
/**
* 첨부파일에 대한 삭제를 처리한다.
*
* @param fileVO
* @param returnUrl
* @param sessionVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/cmm/fms/deleteFileInfs1.do")
public String deleteFileInf1(@ModelAttribute("searchVO") FileVO fileVO, @RequestParam("returnUrl") String returnUrl, HttpServletRequest request, ModelMap model)
throws Exception {
Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
if (isAuthenticated) {
fileService.deleteFileInf(fileVO);
}
return "blank";
//--------------------------------------------
// contextRoot가 있는 경우 제외 시켜야 함
//--------------------------------------------
////return "forward:/cmm/fms/selectFileInfs.do";
//return "forward:" + returnUrl;
/*if ("".equals(request.getContextPath()) || "/".equals(request.getContextPath())) {
return "forward:" + returnUrl;
}
if (returnUrl.startsWith(request.getContextPath())) {
return "forward:" + returnUrl.substring(returnUrl.indexOf("/", 1));
} else {
return "forward:" + returnUrl;
}*/
////------------------------------------------
}
@RequestMapping("/cmm/fms/deleteFileInfs.do")
public String deleteFileInf(@ModelAttribute("searchVO") FileVO fileVO , HttpServletRequest request, ModelMap model )
throws Exception {
Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
// 휴대폰 인증 유무 확인 필요
boolean authYn = true;
boolean delete = false;
if (isAuthenticated || authYn) {
FileVO delFileVO =fileService.selectItsmFileInf(fileVO) ; //실제파일삭제
if(delFileVO !=null){
String fileStreCours = delFileVO.getFileStreCours();
String streFileNm = delFileVO.getStreFileNm();
File delFile = new File(fileStreCours+streFileNm);
delete = delFile.delete();
}
fileService.deleteFileInf(fileVO);
}
return "blank";
}
/**
* 게시판 첨부파일에 대한 목록을 조회한다.
*
* @param fileVO
* @param commandMap
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/cmm/fms/selectBBSFileInfs.do")
public String selectBBSFileInfs(@ModelAttribute("searchVO") FileVO fileVO
, @RequestParam Map commandMap
, ModelMap model
, HttpSession session
) throws Exception {
String atchFileId = (String) commandMap.get("param_atchFileId");
String pdfView = (String) commandMap.get("pdf_view"); //'Y' 이면 pdf 직접 보여주기
// 세션에 파일ID 넣기
session.setAttribute("atchFileId", atchFileId);
fileVO.setAtchFileId(atchFileId);
List result = fileService.selectFileInfs(fileVO);
model.addAttribute("fileList", result);
model.addAttribute("updateFlag", "N");
model.addAttribute("fileListCnt", result.size());
model.addAttribute("atchFileId", atchFileId);
if("Y".equals(pdfView)){
model.addAttribute("pdfView", pdfView);
}
return "cmm/fms/EgovBBSFileList";
}
/**
* 게시판 첨부파일 변경을 위한 수정페이지로 이동한다.
*
* @param fileVO
* @param commandMap
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/cmm/fms/selectBBSFileInfsForUpdate.do")
public String selectBBSFileInfsForUpdate(@ModelAttribute("searchVO") FileVO fileVO, @RequestParam Map commandMap, ModelMap model) throws Exception {
String atchFileId = (String) commandMap.get("param_atchFileId");
String isMultiAtchFile = (String) commandMap.get("isMultiAtchFile");
boolean isImgView = (boolean) (commandMap.get("isImgView") != null ?
Boolean.parseBoolean((String)commandMap.get("isImgView")) : false);
String viewCnd = (String) commandMap.get("viewCnd");
fileVO.setAtchFileId(atchFileId);
List result = fileService.selectFileInfs(fileVO);
model.addAttribute("fileList", result);
model.addAttribute("updateFlag", "Y");
model.addAttribute("isImgView", isImgView);
model.addAttribute("fileListCnt", result.size());
model.addAttribute("atchFileId", atchFileId);
model.addAttribute("isMultiAtchFile", isMultiAtchFile);
model.addAttribute("viewCnd", viewCnd);
return "cmm/fms/EgovBBSFileList";
}
/**
* 게시판 첨부파일에 대한 삭제를 처리한다.
*
* @param fileVO
* @param returnUrl
* @param request
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/cmm/fms/deleteBBSFileInfs.do")
public String deleteBBSFileInfs(@ModelAttribute("searchVO") FileVO fileVO, @RequestParam("returnUrl") String returnUrl, HttpServletRequest request, ModelMap model)
throws Exception {
Boolean isAuthenticated = EgovUserDetailsHelper.isAuthenticated();
if (isAuthenticated) {
fileService.deleteFileInf(fileVO);
}
return "blank";
}
/**
* 이미지 첨부파일에 대한 목록을 조회한다.
*
* @param fileVO
* @param atchFileId
* @param sessionVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/cmm/fms/selectImageFileInfs.do")
public String selectImageFileInfs(@ModelAttribute("searchVO") FileVO fileVO, @RequestParam Map commandMap, ModelMap model) throws Exception {
String atchFileId = (String) commandMap.get("atchFileId");
fileVO.setAtchFileId(atchFileId);
List result = fileService.selectImageFileList(fileVO);
model.addAttribute("fileList", result);
return "cmm/fms/EgovImgFileList";
}
/**
* (사용자)이미지 첨부파일에 대한 목록을 조회한다.
*
* @param fileVO
* @param atchFileId
* @param sessionVO
* @param model
* @return
* @throws Exception
*/
@RequestMapping("/cmm/fms/selectImageFileInfsWeb.do")
public String selectImageFileInfsWeb(@ModelAttribute("searchVO") FileVO fileVO, @RequestParam Map commandMap, ModelMap model) throws Exception {
String atchFileId = (String) commandMap.get("atchFileId");
fileVO.setAtchFileId(atchFileId);
List result = fileService.selectImageFileList(fileVO);
model.addAttribute("fileList", result);
return "cmm/fms/EgovImgFileListWeb";
}
}