package itn.let.cop.cmt.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springmodules.validation.commons.DefaultBeanValidator;

import egovframework.rte.fdl.property.EgovPropertyService;
import egovframework.rte.fdl.security.userdetails.util.EgovUserDetailsHelper;
import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
import itn.com.cmm.EgovMessageSource;
import itn.com.cmm.LoginVO;
import itn.com.cmm.UserVO;
import itn.com.cmm.util.StringUtil;
import itn.com.cmm.util.WebUtil;
import itn.com.uss.ion.cnf.service.ProhibitMngService;
import itn.let.cop.bbs.service.Board;
import itn.let.cop.bbs.service.BoardVO;
import itn.let.cop.bbs.service.EgovBBSAttributeManageService;
import itn.let.cop.cmt.service.Comment;
import itn.let.cop.cmt.service.CommentVO;
import itn.let.cop.cmt.service.EgovArticleCommentService;
import itn.let.sym.site.service.EgovSiteManagerService;
import itn.let.sym.site.service.SiteManagerVO;

@Controller
public class EgovArticleCommentController {

	@Resource(name = "EgovArticleCommentService")
    protected EgovArticleCommentService egovArticleCommentService;
    
    @Resource(name="propertiesService")
    protected EgovPropertyService propertyService;
    
    @Resource(name="egovMessageSource")
    EgovMessageSource egovMessageSource;
    
    @Autowired
    private DefaultBeanValidator beanValidator;
    
    @Resource(name = "egovSiteManagerService")
	private EgovSiteManagerService egovSiteManagerService;
    
    @Resource(name = "EgovBBSAttributeManageService")
	private EgovBBSAttributeManageService bbsAttrbService;
    
    /** scriptMngService 금지어 */
	@Resource(name = "prohibitMngService")
	private ProhibitMngService prohibitMngService;
    
    //protected Logger log = Logger.getLogger(this.getClass());
    
    /**
     * 댓글관리 목록 조회를 제공한다.
     * 
     * @param boardVO
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("/cop/cmt/selectArticleCommentList.do")
    public String selectArticleCommentList(HttpServletRequest request, 
    		@ModelAttribute("searchVO") CommentVO commentVO, 
    		ModelMap model) throws Exception {
    	CommentVO articleCommentVO = new CommentVO();
    	
		String isTotalPage = request.getParameter("isTotalPage");
		if (StringUtil.isEmpty(isTotalPage)) {
			isTotalPage = "N";
		}
		model.addAttribute("isTotalPage", isTotalPage);		
		
		// 수정 처리된 후 댓글 등록 화면으로 처리되기 위한 구현
		if (commentVO.isModified()) {
		    commentVO.setCommentNo("");
		    commentVO.setCommentCn("");
		}
		
		// 수정을 위한 처리
		if (!commentVO.getCommentNo().equals("")) {
			return "forward:/cop/cmt/updateArticleCommentView.do";
		}
		
//		model.addAttribute("sessionUniqId", userVO.get());
//		commentVO.setWrterNm(user.getName());
		
//		commentVO.setSubPageUnit(propertyService.getInt("pageUnit"));
//		commentVO.setSubPageSize(propertyService.getInt("pageSize"));
	
		PaginationInfo paginationInfo = new PaginationInfo();
		paginationInfo.setCurrentPageNo(commentVO.getSubPageIndex());
		paginationInfo.setRecordCountPerPage(commentVO.getSubPageUnit());
		paginationInfo.setPageSize(commentVO.getSubPageSize());
	
		commentVO.setSubFirstIndex(paginationInfo.getFirstRecordIndex());
		commentVO.setSubLastIndex(paginationInfo.getLastRecordIndex());
		commentVO.setSubRecordCountPerPage(paginationInfo.getRecordCountPerPage());
	
		Map<String, Object> map = egovArticleCommentService.selectArticleCommentList(commentVO);
		int totCnt = Integer.parseInt((String)map.get("resultCnt"));
		
		paginationInfo.setTotalRecordCount(totCnt);
	
		model.addAttribute("resultList", map.get("resultList"));
		model.addAttribute("resultCnt", map.get("resultCnt"));
		model.addAttribute("paginationInfo", paginationInfo);
		model.addAttribute("type", "body");	// 댓글 페이지 body import용
		
		articleCommentVO.setSiteId(commentVO.getSiteId()); //금지어 체크를 위한 사이트 아이디 등록
		model.addAttribute("articleCommentVO", articleCommentVO);	// validator 용도 
		
		commentVO.setCommentCn("");	// 등록 후 댓글 내용 처리
	
		return "cop/cmt/EgovArticleCommentList";
    }
    
    
    /**
     * 댓글을 등록한다.
     * 
     * @param commentVO
     * @param comment
     * @param bindingResult
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("/cop/cmt/insertArticleComment.do")
    public String insertArticleComment(@ModelAttribute("searchVO") CommentVO commentVO, 
    		@ModelAttribute("comment") Comment comment,
    		BoardVO boardVO,
    		Board board,
    		BindingResult bindingResult, 
    		ModelMap model,
    		HttpServletRequest request,
    		@RequestParam HashMap<String, String> map, 
    		RedirectAttributes redirectAttributes) throws Exception {

		String isTotalPage = request.getParameter("isTotalPage");
		if (StringUtil.isEmpty(isTotalPage)) {
			isTotalPage = "N";
		}
		model.addAttribute("isTotalPage", isTotalPage);		

		LoginVO user = (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser();
	
		beanValidator.validate(comment, bindingResult);
		if (bindingResult.hasErrors()) {
		    return "forward:/cop/bbs/selectBoardArticle.do";
		}
		
		comment.setFrstRegisterId(user.getUniqId());
		comment.setWrterId(user.getUniqId());
		comment.setWrterNm(user.getName());
		
		egovArticleCommentService.insertArticleComment(comment);
		
		commentVO.setCommentCn("");
		commentVO.setCommentNo("");
		
		redirectAttributes.addAttribute("pageIndex", commentVO.getPageIndex());
		redirectAttributes.addAttribute("searchCnd", commentVO.getSearchCnd());
		redirectAttributes.addAttribute("searchWrd", commentVO.getSearchWrd());
		redirectAttributes.addAttribute("bbsId", commentVO.getBbsId());
		redirectAttributes.addAttribute("nttId", commentVO.getNttId());
		redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("success.common.insert"));
		
		return "redirect:/cop/bbs/selectBoardArticle.do";
    }
    
    
    /**
     * 댓글을 삭제한다.
     * 
     * @param commentVO
     * @param comment
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("/cop/cmt/deleteArticleComment.do")
    public String deleteArticleComment(@ModelAttribute("searchVO") CommentVO commentVO, @ModelAttribute("comment") Comment comment, 
    		ModelMap model, @RequestParam HashMap<String, String> map, RedirectAttributes redirectAttributes) throws Exception {

	    egovArticleCommentService.deleteArticleComment(commentVO);
		
		commentVO.setCommentCn("");
		commentVO.setCommentNo("");
		
		redirectAttributes.addAttribute("pageIndex", commentVO.getPageIndex());
		redirectAttributes.addAttribute("searchCnd", commentVO.getSearchCnd());
		redirectAttributes.addAttribute("searchWrd", commentVO.getSearchWrd());
		redirectAttributes.addAttribute("bbsId", commentVO.getBbsId());
		redirectAttributes.addAttribute("nttId", commentVO.getNttId());
		redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("success.common.delete"));
		return "redirect:/cop/bbs/selectBoardArticle.do";
    }
    
    
    /**
     * 댓글 수정 페이지로 이동한다.
     * 
     * @param commentVO
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("/cop/cmt/updateArticleCommentView.do")
    public String updateArticleCommentView(@ModelAttribute("searchVO") CommentVO commentVO
    		, HttpServletRequest request
    		, ModelMap model) throws Exception {
		LoginVO user = (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser();
	
		CommentVO articleCommentVO = new CommentVO();
		
		commentVO.setWrterNm(user.getName());
	
//		commentVO.setSubPageUnit(propertyService.getInt("pageUnit"));
//		commentVO.setSubPageSize(propertyService.getInt("pageSize"));
	
		PaginationInfo paginationInfo = new PaginationInfo();
		paginationInfo.setCurrentPageNo(commentVO.getSubPageIndex());
		paginationInfo.setRecordCountPerPage(commentVO.getSubPageUnit());
		paginationInfo.setPageSize(commentVO.getSubPageSize());
	
		commentVO.setSubFirstIndex(paginationInfo.getFirstRecordIndex());
		commentVO.setSubLastIndex(paginationInfo.getLastRecordIndex());
		commentVO.setSubRecordCountPerPage(paginationInfo.getRecordCountPerPage());
	
		Map<String, Object> map = egovArticleCommentService.selectArticleCommentList(commentVO);
		int totCnt = Integer.parseInt((String)map.get("resultCnt"));
		
		paginationInfo.setTotalRecordCount(totCnt);
	
		model.addAttribute("resultList", map.get("resultList"));
		model.addAttribute("resultCnt", map.get("resultCnt"));
		model.addAttribute("paginationInfo", paginationInfo);
		model.addAttribute("type", "body");	// body import
		
		articleCommentVO = egovArticleCommentService.selectArticleCommentDetail(commentVO);
		articleCommentVO.setMblDn("");
		
		articleCommentVO.setSiteId(commentVO.getSiteId());
		model.addAttribute("articleCommentVO", articleCommentVO);
		
		String isTotalPage = request.getParameter("isTotalPage");
		if (StringUtil.isEmpty(isTotalPage)) {
			isTotalPage = "N";
		}
		model.addAttribute("isTotalPage", isTotalPage);
			
		return "cop/cmt/EgovArticleCommentList";
    }
    
    
    /**
     * 댓글을 수정한다.
     * 
     * @param commentVO
     * @param comment
     * @param bindingResult
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("/cop/cmt/updateArticleComment.do")
    public String updateArticleComment(@ModelAttribute("searchVO") CommentVO commentVO, @ModelAttribute("comment") Comment comment, 
	    BindingResult bindingResult, ModelMap model, RedirectAttributes redirectAttributes) throws Exception {

		LoginVO user = (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser();
		
		beanValidator.validate(comment, bindingResult);
		if (bindingResult.hasErrors()) {
		    return "forward:/cop/bbs/selectBoardArticle.do";
		}
		
		user = (LoginVO)EgovUserDetailsHelper.getAuthenticatedUser();
	    comment.setLastUpdusrId(user.getUniqId());
	    
	    egovArticleCommentService.updateArticleComment(comment);
	    
	    commentVO.setCommentCn("");
	    commentVO.setCommentNo("");
	
		redirectAttributes.addAttribute("pageIndex", commentVO.getPageIndex());
		redirectAttributes.addAttribute("searchCnd", commentVO.getSearchCnd());
		redirectAttributes.addAttribute("searchWrd", commentVO.getSearchWrd());
		redirectAttributes.addAttribute("bbsId", commentVO.getBbsId());
		redirectAttributes.addAttribute("nttId", commentVO.getNttId());
		redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("success.common.update"));
		return "redirect:/cop/bbs/selectBoardArticle.do";
    }
    

    // @@@@@@@@@@@@@@@@@@@@@@@@@@@ 사용자 @@@@@@@@@@@@@@@@@@@@

	/**
	 * (사용자)댓글관리 목록 조회를 제공한다.
	 * 
	 * @param boardVO
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/web/cop/cmt/selectArticleCommentList.do")
	public String selectArticleCommentListWeb(HttpServletRequest request, @ModelAttribute("searchVO") CommentVO commentVO, ModelMap model) throws Exception {
		CommentVO articleCommentVO = new CommentVO();
		
		// 수정 처리된 후 댓글 등록 화면으로 처리되기 위한 구현
		if (commentVO.isModified()) {
			commentVO.setCommentNo("");
			commentVO.setCommentCn("");
		}
		
		// 수정을 위한 처리
		if (!commentVO.getCommentNo().equals("")) {
			return "forward:/web/cop/cmt/updateArticleCommentView.do";
		}
		
		List<?> resultList = egovArticleCommentService.selectArticleCommentListAll(commentVO);
		int totCnt = resultList.size();
		
		model.addAttribute("resultList", resultList);
		model.addAttribute("resultCnt", totCnt);
		model.addAttribute("type", "body");	// 댓글 페이지 body import용
		
		model.addAttribute("userFlag", "Y");	// 사용자 화면 유무
		model.addAttribute("userPath", "/web");	// 사용자 화면 경로
		
		model.addAttribute("articleCommentVO", articleCommentVO);	// validator 용도 
		
		commentVO.setCommentCn("");	// 등록 후 댓글 내용 처리
		
		return "cop/cmt/EgovArticleCommentListWeb";
	}
	
	
	/**
	 * (사용자)댓글을 등록한다.
	 * 
	 * @param commentVO
	 * @param comment
	 * @param bindingResult
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/web/cop/cmt/insertArticleComment.do")
	public String insertArticleCommentWeb(HttpServletRequest request, @ModelAttribute("searchVO") CommentVO commentVO, @ModelAttribute("comment") Comment comment, 
			BindingResult bindingResult, ModelMap model, @RequestParam HashMap<String, String> map, RedirectAttributes redirectAttributes) throws Exception {
		
		UserVO userVO = (UserVO)request.getSession().getAttribute("userVO"); // 사용자 정보
		
		if (userVO == null) { // 인증 필요
			BoardVO boardVO = new BoardVO();
			boardVO.setPageIndex(commentVO.getPageIndex());
			boardVO.setSearchCnd(commentVO.getSearchCnd());
			boardVO.setSearchWrd(commentVO.getSearchWrd());
			boardVO.setBbsId(commentVO.getBbsId());
			boardVO.setNttId(commentVO.getNttId());
			request.getSession().setAttribute("searchVO", boardVO);
			request.getSession().setAttribute("url", "/web/cop/bbsWeb/selectBoardArticle.do");
			return "web/cop/selfauth/authentication";
		}

		beanValidator.validate(comment, bindingResult);
		if (bindingResult.hasErrors()) {
			return "forward:/web/cop/bbsWeb/selectBoardArticle.do";
		}
		
		comment.setWrterNm(userVO.getName());
		comment.setMblDn(userVO.getMblDn());
		
		egovArticleCommentService.insertArticleComment(comment);
		
		commentVO.setCommentCn("");
		commentVO.setCommentNo("");
		
		redirectAttributes.addAttribute("pageIndex", commentVO.getPageIndex());
		redirectAttributes.addAttribute("searchCnd", commentVO.getSearchCnd());
		redirectAttributes.addAttribute("searchWrd", commentVO.getSearchWrd());
		redirectAttributes.addAttribute("bbsId", commentVO.getBbsId());
		redirectAttributes.addAttribute("nttId", commentVO.getNttId());
		redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("success.common.insert"));
		return "redirect:/web/cop/bbsWeb/selectBoardArticle.do";
	}
	
	
	/**
	 * (사용자)댓글을 삭제한다.
	 * 
	 * @param commentVO
	 * @param comment
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/web/cop/cmt/deleteArticleComment.do")
	public String deleteArticleCommentWeb(HttpServletRequest request, @ModelAttribute("searchVO") CommentVO commentVO, @ModelAttribute("comment") Comment comment, 
			ModelMap model, @RequestParam HashMap<String, String> map, RedirectAttributes redirectAttributes) throws Exception {
		
		UserVO userVO = (UserVO)request.getSession().getAttribute("userVO"); // 사용자 정보
		
		if (userVO == null) { // 인증 필요
			BoardVO boardVO = new BoardVO();
			boardVO.setPageIndex(commentVO.getPageIndex());
			boardVO.setSearchCnd(commentVO.getSearchCnd());
			boardVO.setSearchWrd(commentVO.getSearchWrd());
			boardVO.setBbsId(commentVO.getBbsId());
			boardVO.setNttId(commentVO.getNttId());
			request.getSession().setAttribute("searchVO", boardVO);
			request.getSession().setAttribute("url", "/web/cop/bbsWeb/selectBoardArticle.do");
			return "web/cop/selfauth/authentication";
		}

		redirectAttributes.addAttribute("pageIndex", commentVO.getPageIndex());
		redirectAttributes.addAttribute("searchCnd", commentVO.getSearchCnd());
		redirectAttributes.addAttribute("searchWrd", commentVO.getSearchWrd());
		redirectAttributes.addAttribute("bbsId", commentVO.getBbsId());
		redirectAttributes.addAttribute("nttId", commentVO.getNttId());
		
		// 본인 댓글 확인
		CommentVO articleCommentVO = egovArticleCommentService.selectArticleCommentDetail(commentVO);
		
		if (!articleCommentVO.getMblDn().equals(userVO.getMblDn())){
			redirectAttributes.addFlashAttribute("message", "본인 댓글만 삭제할 수 있습니다.");
			return "redirect:/web/cop/bbsWeb/selectBoardArticle.do";
		} else {
			egovArticleCommentService.deleteArticleComment(commentVO);
		}

		commentVO.setCommentCn("");
		commentVO.setCommentNo("");
		
		redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("success.common.delete"));
		return "redirect:/web/cop/bbsWeb/selectBoardArticle.do";
	}
	
	
	/**
	 * (사용자)댓글 수정 페이지로 이동한다.
	 * 
	 * @param commentVO
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/web/cop/cmt/updateArticleCommentView.do")
	public String updateArticleCommentViewWeb(HttpServletRequest request, @ModelAttribute("searchVO") CommentVO commentVO, ModelMap model, RedirectAttributes redirectAttributes) throws Exception {

		UserVO userVO = (UserVO)request.getSession().getAttribute("userVO"); // 사용자 정보
		
		if (userVO == null) { // 인증 필요
			BoardVO boardVO = new BoardVO();
			boardVO.setPageIndex(commentVO.getPageIndex());
			boardVO.setSearchCnd(commentVO.getSearchCnd());
			boardVO.setSearchWrd(commentVO.getSearchWrd());
			boardVO.setBbsId(commentVO.getBbsId());
			boardVO.setNttId(commentVO.getNttId());
			request.getSession().setAttribute("searchVO", boardVO);
			request.getSession().setAttribute("url", "/web/cop/bbsWeb/selectBoardArticle.do");
			return "web/cop/selfauth/authentication";
		}

		// 본인 댓글 확인
		CommentVO articleCommentVO = egovArticleCommentService.selectArticleCommentDetail(commentVO);
		
		if (!articleCommentVO.getMblDn().equals(userVO.getMblDn())){
			model.addAttribute("commentMessage", "본인 댓글만 수정할 수 있습니다.");
			articleCommentVO = new CommentVO();
			commentVO.setCommentNo("");
			commentVO.setCommentCn("");
		}
		articleCommentVO.setMblDn(""); // 사용자 인증키 화면단 전송 제거
		
		List<?> resultList = egovArticleCommentService.selectArticleCommentListAll(commentVO);
		int totCnt = resultList.size();
		
		model.addAttribute("resultList", resultList);
		model.addAttribute("resultCnt", totCnt);
		model.addAttribute("type", "body");	// body import
		
		model.addAttribute("userFlag", "Y");	// 사용자 화면 유무
		model.addAttribute("userPath", "/web");	// 사용자 화면 경로
		
		model.addAttribute("articleCommentVO", articleCommentVO);
		
		return "cop/cmt/EgovArticleCommentListWeb";
	}


	/**
	 * (사용자)댓글을 수정한다.
	 * 
	 * @param commentVO
	 * @param comment
	 * @param bindingResult
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/web/cop/cmt/updateArticleComment.do")
	public String updateArticleCommentWeb(HttpServletRequest request, @ModelAttribute("searchVO") CommentVO commentVO, @ModelAttribute("comment") Comment comment, 
			BindingResult bindingResult, ModelMap model, RedirectAttributes redirectAttributes) throws Exception {
		
		UserVO userVO = (UserVO)request.getSession().getAttribute("userVO"); // 사용자 정보
		
		if (userVO == null) { // 인증 필요
			BoardVO boardVO = new BoardVO();
			boardVO.setPageIndex(commentVO.getPageIndex());
			boardVO.setSearchCnd(commentVO.getSearchCnd());
			boardVO.setSearchWrd(commentVO.getSearchWrd());
			boardVO.setBbsId(commentVO.getBbsId());
			boardVO.setNttId(commentVO.getNttId());
			request.getSession().setAttribute("searchVO", boardVO);
			request.getSession().setAttribute("url", "/web/cop/bbsWeb/selectBoardArticle.do");
			return "web/cop/selfauth/authentication";
		}

		redirectAttributes.addAttribute("pageIndex", commentVO.getPageIndex());
		redirectAttributes.addAttribute("searchCnd", commentVO.getSearchCnd());
		redirectAttributes.addAttribute("searchWrd", commentVO.getSearchWrd());
		redirectAttributes.addAttribute("bbsId", commentVO.getBbsId());
		redirectAttributes.addAttribute("nttId", commentVO.getNttId());

		// 본인 댓글 확인
		CommentVO articleCommentVO = egovArticleCommentService.selectArticleCommentDetail(commentVO);
		
		if (!articleCommentVO.getMblDn().equals(userVO.getMblDn())){
			redirectAttributes.addFlashAttribute("message", "본인 댓글만 수정할 수 있습니다.");

			commentVO.setCommentCn("");
			commentVO.setCommentNo("");

			return "redirect:/web/cop/bbsWeb/selectBoardArticle.do";
		} else {
			beanValidator.validate(comment, bindingResult);
			if (bindingResult.hasErrors()) {
				return "forward:/web/cop/bbsWeb/selectBoardArticle.do";
			}

			egovArticleCommentService.updateArticleComment(comment);
			commentVO.setCommentCn("");
			commentVO.setCommentNo("");
		}
		
		redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("success.common.update"));
		return "redirect:/web/cop/bbsWeb/selectBoardArticle.do";
	}
	
	/**
	 * (사용자)댓글관리 목록 조회를 제공한다.
	 * 
	 * @param boardVO
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/{siteId}/web/cop/cmt/selectArticleCommentList.do")
	public String siteSelectArticleCommentListWeb(@PathVariable("siteId") String siteId , HttpServletRequest request, @ModelAttribute("searchVO") CommentVO commentVO, ModelMap model) throws Exception {
		CommentVO articleCommentVO = new CommentVO();
		
		// 수정 처리된 후 댓글 등록 화면으로 처리되기 위한 구현
		if (commentVO.isModified()) {
			commentVO.setCommentNo("");
			commentVO.setCommentCn("");
		}
		
		// 수정을 위한 처리
		if (!commentVO.getCommentNo().equals("")) {
			return "forward:/"+siteId+"/web/cop/cmt/updateArticleCommentView.do";
		}
		
		List<?> resultList = egovArticleCommentService.selectArticleCommentListAll(commentVO);
		int totCnt = resultList.size();
		
		model.addAttribute("resultList", resultList);
		model.addAttribute("resultCnt", totCnt);
		model.addAttribute("type", "body");	// 댓글 페이지 body import용
		
		model.addAttribute("userFlag", "Y");	// 사용자 화면 유무
		model.addAttribute("userPath", "/web");	// 사용자 화면 경로
		
		model.addAttribute("articleCommentVO", articleCommentVO);	// validator 용도 
		
		commentVO.setCommentCn("");	// 등록 후 댓글 내용 처리
		model.addAttribute("siteId", siteId);
		String siteFolder = "site/"+siteId ; 
		/*if(!("linc".equals(siteId) || "klc".equals(siteId)) ){
			String theme = "01";
			String isMobile = "pc";
			setSiteinfo(siteId , theme , isMobile, model , request );
			return "web/site/"+siteId+"/"+isMobile+"/cop/cmt/EgovArticleCommentListWeb";
		}*/
		return "web/"+siteFolder+"/cop/cmt/EgovArticleCommentListWeb";
	}
	
	/**
	 * (사용자)댓글을 삭제한다.
	 * 
	 * @param commentVO
	 * @param comment
	 * @param model
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/{siteId}/web/member/cop/cmt/deleteArticleComment.do")
	public String siteDeleteArticleCommentWeb(@PathVariable("siteId") String siteId , HttpServletRequest request, @ModelAttribute("searchVO") CommentVO commentVO, @ModelAttribute("comment") Comment comment, 
			ModelMap model, @RequestParam HashMap<String, String> map, RedirectAttributes redirectAttributes) throws Exception {
		
		//UserVO userVO = (UserVO)request.getSession().getAttribute("userVO"); // 사용자 정보
		LoginVO loginVO = (LoginVO) EgovUserDetailsHelper.getAuthenticatedUser();

		redirectAttributes.addAttribute("pageIndex", commentVO.getPageIndex());
		redirectAttributes.addAttribute("searchCnd", commentVO.getSearchCnd());
		redirectAttributes.addAttribute("searchWrd", commentVO.getSearchWrd());
		redirectAttributes.addAttribute("bbsId", commentVO.getBbsId());
		redirectAttributes.addAttribute("nttId", commentVO.getNttId());
		
		// 본인 댓글 확인
		CommentVO articleCommentVO = egovArticleCommentService.selectArticleCommentDetail(commentVO);
		
		if (!articleCommentVO.getFrstRegisterId().equals(loginVO.getUniqId())){
			redirectAttributes.addFlashAttribute("message", "본인 댓글만 삭제할 수 있습니다.");
			return "redirect:/web/cop/bbsWeb/selectBoardArticle.do";
		} else {
			egovArticleCommentService.deleteArticleComment(commentVO);
		}

		commentVO.setCommentCn("");
		commentVO.setCommentNo("");
		
		redirectAttributes.addFlashAttribute("message", egovMessageSource.getMessage("success.common.delete"));
		return "redirect:/web/cop/bbsWeb/selectBoardArticle.do";
	}
	
	
	private void setSiteinfo(String siteId , String theme , String isMobile , ModelMap model , HttpServletRequest request) throws Exception{
		SiteManagerVO siteManagerVO = new SiteManagerVO();
		siteManagerVO.setSiteId(siteId);
		siteManagerVO = egovSiteManagerService.selectSiteManagerVO(siteManagerVO) ;
		if( !"".equals(siteManagerVO.getTheme()) && null != siteManagerVO.getTheme()){
			theme = siteManagerVO.getTheme() ;
		}
		WebUtil util = new WebUtil();
		if(util.isMobile(request)){
			isMobile = "mobile";
		}
		
		model.addAttribute("siteId", siteId);
		model.addAttribute("site_path" , "/site/theme_"+theme+"/"+isMobile);
	}
}
