217 lines
7.7 KiB
Java
217 lines
7.7 KiB
Java
package sgis.board.controller;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.ui.ModelMap;
|
|
import org.springframework.validation.BindingResult;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
|
|
|
import egovframework.com.cmm.util.EgovUserDetailsHelper;
|
|
import sgis.board.entity.Board;
|
|
import sgis.board.entity.Member;
|
|
import sgis.board.mapper.BoardMapper;
|
|
import sgis.com.vo.SessionVO;
|
|
|
|
@Controller
|
|
public class BoardController{
|
|
|
|
@Autowired
|
|
BoardMapper boardMapper;
|
|
|
|
/**
|
|
* @Method_Name : getSessionInfo
|
|
* @Date : 2022. 5. 10.
|
|
* @Creator : ICTWAY KIM Yoon-Su
|
|
* @Method_Discription : 세션정보 가져오기
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public SessionVO getSessionInfo() throws Exception {
|
|
return (SessionVO) EgovUserDetailsHelper.getAuthenticatedUser();
|
|
}
|
|
|
|
private ModelMap getDisplayName(HashMap<String,Object> params, ModelMap model) {
|
|
// boardCategoryId가 ModelMap에 이미 존재하는지 확인 (board-community.do 등에서 넘어온 경우)
|
|
Object boardCategoryIdFromModel = model.get("boardCategoryId");
|
|
Integer nBoardCategoryId = null;
|
|
String displayName = "게시판"; // Default display name
|
|
|
|
// 1. ModelMap에 boardCategoryId가 이미 설정되어 있다면 그 값을 우선 사용
|
|
if (boardCategoryIdFromModel instanceof Integer) {
|
|
nBoardCategoryId = (Integer) boardCategoryIdFromModel;
|
|
} else if (boardCategoryIdFromModel instanceof String) {
|
|
try {
|
|
nBoardCategoryId = Integer.valueOf((String) boardCategoryIdFromModel);
|
|
} catch (NumberFormatException e) {
|
|
// Ignore if not a valid number, it will be handled by params below
|
|
System.err.println("Invalid boardCategoryId in model: " + boardCategoryIdFromModel);
|
|
}
|
|
}
|
|
|
|
// 2. ModelMap에 없거나 유효하지 않다면, @RequestParam에서 가져옴
|
|
if (nBoardCategoryId == null && params.get("boardCategoryId") != null) {
|
|
try {
|
|
nBoardCategoryId = Integer.valueOf((String) params.get("boardCategoryId"));
|
|
} catch (NumberFormatException e) {
|
|
// "all" 같은 문자열이 올 경우를 대비하여 처리
|
|
// 여기서는 NumberFormatException이 발생하면 nBoardCategoryId는 null로 유지
|
|
System.err.println("Invalid boardCategoryId in request params: " + params.get("boardCategoryId"));
|
|
}
|
|
}
|
|
|
|
// boardCategoryId 값에 따라 displayName 설정
|
|
if( nBoardCategoryId != null ) {
|
|
switch (nBoardCategoryId) {
|
|
case 1:
|
|
displayName = "자료실";
|
|
break;
|
|
case 2:
|
|
displayName = "공지사항";
|
|
break;
|
|
case 3:
|
|
displayName = "Q&A";
|
|
break;
|
|
case 4:
|
|
displayName = "장애신고";
|
|
break;
|
|
default:
|
|
displayName = "기타 게시판"; // 정의되지 않은 ID에 대한 기본값
|
|
break;
|
|
}
|
|
model.put("boardCategoryId", nBoardCategoryId); // 최종 확정된 ID를 모델에 다시 저장
|
|
model.put("displayName", displayName);
|
|
} else {
|
|
// boardCategoryId가 파라미터나 모델에 없는 경우 (예: "all" 또는 아예 없는 경우)
|
|
// 여기서는 기본 displayName을 "게시판"으로 유지하거나,
|
|
// 필요한 경우 "전체 게시판" 등으로 설정할 수 있습니다.
|
|
model.put("displayName", "전체 게시판"); // 또는 "게시판"
|
|
}
|
|
return model;
|
|
}
|
|
|
|
@RequestMapping("/sgis/portal/board-list.do")
|
|
public String boardList(@RequestParam HashMap<String,Object> params, ModelMap model, RedirectAttributes rttr, HttpSession session) {
|
|
|
|
SessionVO sessionVO;
|
|
|
|
try {
|
|
sessionVO = getSessionInfo();
|
|
String userId = sessionVO.getsUserId(); //사용자 ID
|
|
String userGrp = sessionVO.getsUserGrp(); //사용자 그룹ㄴ
|
|
|
|
model.put("sUserId", sessionVO.getsUserId());
|
|
model.put("sUserGrp", sessionVO.getsUserGrp());
|
|
model.put("sUserNm", sessionVO.getsUserNm());
|
|
|
|
} catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
|
|
getDisplayName(params, model);
|
|
|
|
return "sgis/com/board/boardList";
|
|
}
|
|
|
|
@RequestMapping("/sgis/portal/board-community.do")
|
|
public String boardCommunity(@RequestParam HashMap<String,Object> params, ModelMap model, RedirectAttributes rttr, HttpSession session) {
|
|
model.put("boardCategoryId", 1);
|
|
model.put("displayName", "자료실");
|
|
return boardList(params, model, rttr, session);
|
|
}
|
|
|
|
@RequestMapping("/sgis/portal/board-notice.do")
|
|
public String boardNotice(@RequestParam HashMap<String,Object> params, ModelMap model, RedirectAttributes rttr, HttpSession session) {
|
|
model.put("boardCategoryId", 2);
|
|
model.put("displayName", "공지사항");
|
|
return boardList(params, model, rttr, session);
|
|
}
|
|
|
|
@RequestMapping("/sgis/portal/board-qna.do")
|
|
public String boardQna(@RequestParam HashMap<String,Object> params, ModelMap model, RedirectAttributes rttr, HttpSession session) {
|
|
model.put("boardCategoryId", 3);
|
|
model.put("displayName", "Q&A");
|
|
return boardList(params, model, rttr, session);
|
|
}
|
|
|
|
@RequestMapping("/sgis/portal/board-bug.do")
|
|
public String boardBug(@RequestParam HashMap<String,Object> params, ModelMap model, RedirectAttributes rttr, HttpSession session) {
|
|
model.put("boardCategoryId", 4);
|
|
model.put("displayName", "장애신고");
|
|
return boardList(params, model, rttr, session);
|
|
}
|
|
|
|
@RequestMapping("/sgis/portal/boardWrite.do")
|
|
public String boardWrite(
|
|
@RequestParam HashMap<String,Object> params,
|
|
@RequestParam(value = "boardCategoryId", required = false) Integer boardCategoryId, // boardCategoryId를 선택적으로 받습니다.
|
|
@RequestParam(value = "parentPostId", required = false) Long parentPostId, // 부모 게시글 ID를 선택적으로 받습니다.
|
|
ModelMap model,
|
|
RedirectAttributes rttr,
|
|
HttpSession session) {
|
|
|
|
SessionVO sessionVO;
|
|
|
|
try {
|
|
sessionVO = getSessionInfo();
|
|
String userId = sessionVO.getsUserId(); // 사용자 ID
|
|
String userGrp = sessionVO.getsUserGrp(); // 사용자 그룹
|
|
|
|
model.put("sUserId", sessionVO.getsUserId());
|
|
model.put("sUserGrp", sessionVO.getsUserGrp());
|
|
model.put("sUserNm", sessionVO.getsUserNm());
|
|
|
|
getDisplayName(params, model);
|
|
// params 맵 전체를 넘겨야 하는 경우 (JSP에서 다른 파라미터도 필요한 경우)
|
|
model.put("params", params);
|
|
|
|
// parentPostId가 있을 경우 모델에 추가하여 JSP에서 접근할 수 있도록 합니다.
|
|
if (parentPostId != null) {
|
|
model.put("parentPostId", parentPostId);
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
|
|
return "sgis/com/board/boardWrite";
|
|
}
|
|
|
|
@RequestMapping("/sgis/portal/boardView.do")
|
|
public String boardView(@RequestParam HashMap<String,Object> params, ModelMap model, RedirectAttributes rttr, HttpSession session,HttpServletRequest request) {
|
|
|
|
SessionVO sessionVO;
|
|
|
|
try {
|
|
sessionVO = getSessionInfo();
|
|
String userId = sessionVO.getsUserId(); //사용자 ID
|
|
String userGrp = sessionVO.getsUserGrp(); //사용자 그룹
|
|
|
|
model.put("sUserId", sessionVO.getsUserId());
|
|
model.put("sUserGrp", sessionVO.getsUserGrp());
|
|
model.put("sUserNm", sessionVO.getsUserNm());
|
|
model.put("params", params);
|
|
|
|
} catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
|
|
getDisplayName(params, model);
|
|
|
|
return "sgis/com/board/boardView";
|
|
}
|
|
}
|