FAISP/src/main/java/com/dbnt/faisp/publicBoard/PublicBoardController.java

117 lines
4.4 KiB
Java
Raw Normal View History

2022-09-16 09:01:22 +00:00
package com.dbnt.faisp.publicBoard;
import com.dbnt.faisp.config.Role;
import com.dbnt.faisp.publicBoard.model.PublicBoard;
2022-09-19 09:20:49 +00:00
import com.dbnt.faisp.publicBoard.model.PublicComment;
2022-09-16 09:01:22 +00:00
import com.dbnt.faisp.publicBoard.service.PublicBoardService;
import com.dbnt.faisp.userInfo.model.UserInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
2022-09-19 09:20:49 +00:00
import org.springframework.web.multipart.MultipartHttpServletRequest;
2022-09-16 09:01:22 +00:00
import org.springframework.web.servlet.ModelAndView;
import java.time.LocalDateTime;
2022-09-19 09:20:49 +00:00
import java.util.List;
2022-09-16 09:01:22 +00:00
@RestController
@RequiredArgsConstructor
@RequestMapping("/publicBoard")
public class PublicBoardController {
private final PublicBoardService publicBoardService;
@GetMapping("/noticePage")
public ModelAndView organMgtPage(@AuthenticationPrincipal UserInfo loginUser, PublicBoard publicBoard) {
2022-09-19 09:20:49 +00:00
ModelAndView mav = new ModelAndView("publicBoard/notice/noticePage");
2022-09-16 09:01:22 +00:00
publicBoard.setQueryInfo();
2022-09-19 09:20:49 +00:00
publicBoard.setPublicType("PLB001");
if(loginUser.getUserRole().contains(Role.SUB_ADMIN.getValue())){
2022-09-20 05:09:20 +00:00
publicBoard.setDownOrganCdList(loginUser.getDownOrganCdList());
mav.addObject("mgtOrganList", loginUser.getDownOrganCdList());
2022-09-16 09:01:22 +00:00
}
2022-09-20 05:09:20 +00:00
publicBoard.setUpOrganCdList(loginUser.getUpOrganCdList());
2022-09-16 09:01:22 +00:00
mav.addObject("noticeList", publicBoardService.selectContentList(publicBoard));
publicBoard.setContentCnt(publicBoardService.selectContentListCnt(publicBoard));
publicBoard.setPaginationInfo();
mav.addObject("searchParams", publicBoard);
return mav;
}
@GetMapping("/editModal")
public ModelAndView editModal(@AuthenticationPrincipal UserInfo loginUser, PublicBoard publicBoard){
2022-09-19 09:20:49 +00:00
ModelAndView mav = null;
switch (publicBoard.getPublicType()){
case "PLB001": // 공지사항
mav = new ModelAndView("publicBoard/notice/noticeEditModal");
if(publicBoard.getPublicKey()!=null){
publicBoard = publicBoardService.selectPublicBoard(publicBoard.getPublicKey());
}
break;
case "PLB002": // 공용게시판
break;
case "PLB003": // 자료실
break;
case "PLB004": // Q&A
break;
}
if(publicBoard.getPublicKey()==null){
2022-09-16 09:01:22 +00:00
publicBoard.setWrtOrgan(loginUser.getOgCd());
publicBoard.setWrtPart(loginUser.getOfcCd());
publicBoard.setWrtUserSeq(loginUser.getUserSeq());
publicBoard.setWrtUserNm(loginUser.getUserNm());
publicBoard.setWrtDt(LocalDateTime.now());
}
mav.addObject("info", publicBoard);
return mav;
}
2022-09-19 09:20:49 +00:00
@GetMapping("/viewModal")
public ModelAndView viewModal(@AuthenticationPrincipal UserInfo loginUser, PublicBoard publicBoard){
ModelAndView mav = null;
switch (publicBoard.getPublicType()){
case "PLB001": // 공지사항
mav = new ModelAndView("publicBoard/notice/noticeViewModal");
break;
case "PLB002": // 공용게시판
break;
case "PLB003": // 자료실
break;
case "PLB004": // Q&A
break;
}
2022-09-16 09:01:22 +00:00
publicBoard = publicBoardService.selectPublicBoard(publicBoard.getPublicKey());
2022-09-19 09:20:49 +00:00
mav.addObject("userSeq", loginUser.getUserSeq());
2022-09-16 09:01:22 +00:00
mav.addObject("info", publicBoard);
return mav;
}
2022-09-19 09:20:49 +00:00
@PostMapping("/saveContent")
public Integer saveContent(PublicBoard publicBoard,
MultipartHttpServletRequest request,
@RequestParam(value = "fileSeq", required = false) List<Integer> deleteFileSeq){
publicBoard.setMultipartFileList(request.getMultiFileMap().get("uploadFiles"));
return publicBoardService.saveContent(publicBoard, deleteFileSeq);
}
@PostMapping("/saveComment")
2022-09-20 05:09:20 +00:00
public ModelAndView saveComment(@AuthenticationPrincipal UserInfo loginUser, PublicComment comment){
2022-09-19 09:20:49 +00:00
comment.setWrtOrgan(loginUser.getOgCd());
comment.setWrtPart(loginUser.getOfcCd());
comment.setWrtUserSeq(loginUser.getUserSeq());
comment.setWrtUserNm(loginUser.getUserNm());
comment.setWrtDt(LocalDateTime.now());
2022-09-20 05:09:20 +00:00
publicBoardService.saveComment(comment);
ModelAndView mav = new ModelAndView("publicBoard/commentDiv");
mav.addObject("comment", comment);
mav.addObject("userSeq", loginUser.getUserSeq());
return mav;
2022-09-19 09:20:49 +00:00
}
@PostMapping("/deleteComment")
@ResponseBody
2022-09-20 05:09:20 +00:00
public void deleteComment(@RequestBody PublicComment comment){
publicBoardService.deleteComment(comment.getPublicKey(), comment.getCommentKey());
2022-09-19 09:20:49 +00:00
}
2022-09-16 09:01:22 +00:00
}