123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704 |
- package com.lemon.lifecenter.controller;
- import java.io.File;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.UUID;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.commons.io.FilenameUtils;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.transaction.annotation.Propagation;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.util.FileCopyUtils;
- import org.springframework.web.bind.annotation.ModelAttribute;
- 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.multipart.MultipartFile;
- import org.springframework.web.servlet.ModelAndView;
- import com.lemon.lifecenter.common.LifeCenterConfigVO;
- import com.lemon.lifecenter.common.LifeCenterController;
- import com.lemon.lifecenter.common.LifeCenterFileDownload;
- import com.lemon.lifecenter.common.LifeCenterFunction;
- import com.lemon.lifecenter.common.LifeCenterPaging;
- import com.lemon.lifecenter.common.LifeCenterSessionController;
- import com.lemon.lifecenter.dto.BoardDTO;
- import com.lemon.lifecenter.service.BoardService;
- @Controller
- public class BoardController extends LifeCenterController {
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
-
- @Autowired
- private BoardService boardService;
-
- @Autowired
- private LifeCenterConfigVO config;
-
- private LifeCenterPaging paging;
-
- @RequestMapping("/notice/list")
- public ModelAndView boardList(
- @RequestParam(value="searchTxt", required=false, defaultValue="") String searchTxt,
- @RequestParam(value="selectState", required=false, defaultValue="") String selectState,
- @RequestParam(value="page", required=false, defaultValue="1") int page,
- HttpServletRequest request, HttpServletResponse response) {
- BoardDTO dto = new BoardDTO();
-
- if (!selectState.equals("")) {
- if (selectState.equals("title")) {
- dto.setTitle(searchTxt);
- } else if (selectState.equals("content")) {
- dto.setContent(searchTxt);
- }
- }
-
- dto.setLimit( ( Integer.valueOf( page ) - 1 ) * config.pageDataSize );
- dto.setLimitMax( config.pageDataSize );
-
- List<BoardDTO> list = new ArrayList<BoardDTO>();
-
- int total = boardService.selectNoticeBoardListCount(dto);
- if (total == 0) {
- } else {
- list = boardService.selectNoticeBoardList(dto);
- }
-
- String param = "";
- paging = LifeCenterPaging.getInstance();
- paging.paging(config, total, page, param);
-
- ModelAndView mv = setMV("notice/list");
- mv.addObject("list", list);
- mv.addObject("total", total);
- mv.addObject("selectState", selectState);
- mv.addObject("searchTxt", searchTxt);
- mv.addObject("paging", paging);
- mv.addObject("page", page);
- mv.addObject("pageSize", dto.getLimitMax());
- return mv;
- }
-
- @RequestMapping("/notice/new")
- public ModelAndView boardNew(HttpServletRequest request, HttpServletResponse response) {
- // String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" );
- ModelAndView mv = setMV("notice/new");
- // mv.addObject("groupIdx",sesGroupIdx);
-
- return mv;
- }
-
- @RequestMapping(value="/notice/new/insert", method = RequestMethod.POST)
- @Transactional(propagation=Propagation.REQUIRED)
- public String boardNewInsert(
- HttpServletRequest request, HttpServletResponse response,
- @ModelAttribute("dto") final BoardDTO dto,
- MultipartFile file) {
- String sesId = LifeCenterSessionController.getSession(request, "sesId");
- // String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
- //
- // if (!sesGroupIdx.equals("1")) {
- // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '공지사항 작성 권한이 없습니다.', callBack : function(){ location.href='/notice/list'; } });" );
- // return "/common/blank";
- // }
-
- String noticeInsertTime = LifeCenterSessionController.getSession(request, "noticeInsertTime");
- long time = LifeCenterFunction.getNowUnixTimeStamp();
- if( noticeInsertTime != null && !noticeInsertTime.equals( "" ) ) {
- long i = Long.parseLong( noticeInsertTime );
-
- if( ( time - i ) < 61 ) {
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '<font style=\"color:red\">자동화공격방지</font><br/>게시글 작성 후 60초 동안 작성이 불가능 합니다<br/>"+( 61 - ( time - i ) )+"초 이후 작성 가능', callBack : function(){ history.back(); } });" );
- return "/common/blank";
- }
- }
-
- if (file.isEmpty() == false) {
- UUID uuid = UUID.randomUUID();
- String fileName = file.getOriginalFilename();
- int fileSize = (int) file.getSize(); //단위는 byte
- String ext = FilenameUtils.getExtension(fileName);
- String saveFileName = uuid + "." + ext;
-
- final String[] PERMISSION_FILE_EXT_ARR = {"gif","png","jpg","jpeg","doc","docx","xls","xlsx","hwp","pdf", "txt"};
- boolean extFlag = false;
- for( int i = 0; i < PERMISSION_FILE_EXT_ARR.length; i++ ) {
- if( PERMISSION_FILE_EXT_ARR[i].equals( ext.toLowerCase() ) ) {
- extFlag = true;
- }
- }
-
- if( extFlag == false ) {
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt : \"등록할수 없는 확장자입니다.<br/>.gif, .jpg, .png, .jpeg, .doc, .docx, .xls, .xlsx, .hwp, .pdf, .txt 확장자만 등록가능\", callBack : function(){ history.back(); } });" );
- return "/common/blank";
- }
-
- try {
- String tempPath = config.filePath;
- File saveFile = new File(tempPath, saveFileName);
- FileCopyUtils.copy(file.getBytes(),saveFile);
- } catch (IOException e) {
- e.printStackTrace();
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '파일 업로드에 실패하였습니다.', callBack : function(){ history.back(); } });" );
- return "/common/blank";
- }
-
- dto.setFileOriginalName(fileName);
- dto.setFileName(saveFileName);
- dto.setFileExtension(ext);
- dto.setFileSize(fileSize);
- dto.setBoardType("N");
- }
- String title = dto.getTitle().trim();
- String content = dto.getContent().trim();
-
- dto.setTitle(title);
- dto.setContent(content);
- dto.setCreateBy(sesId);
-
- boardService.noticeInsert(dto);
- int postSeq = dto.getPostSeq();
-
- if (postSeq == 0) {
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '게시물 등록에 실패하였습니다.', callBack : function(){ history.back(); } });" );
- return "/common/blank";
- } else {
- if (file.isEmpty() == false) {
- boardService.fileUploadDataInsert(dto);
- int fileIdx = dto.getFileIdx();
- if (fileIdx == 0) {
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '게시물 등록에 실패하였습니다.', callBack : function(){ history.back(); } });" );
- return "/common/blank";
- }
- }
- }
-
- LifeCenterSessionController.setSession( request, "noticeInsertTime", String.valueOf( time ) );
-
- return "redirect:/notice/content?postSeq=" + dto.getPostSeq();
- }
-
- @RequestMapping("/notice/content")
- public ModelAndView boardContent(
- @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq,
- HttpServletRequest request, HttpServletResponse response) {
- String referer = request.getHeader("referer");
- // String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" );
-
- int total = boardService.selectNoticeBoardCountOne(postSeq);
- BoardDTO dto = new BoardDTO();
- if (total > 0) {
- boardService.updateNoticeView(postSeq);
- dto = boardService.selectNoticeBoardInfoOne(postSeq);
- }
-
- int prePostCnt = boardService.selectPrePostCount(postSeq);
- int nextPostCnt = boardService.selectNextPostCount(postSeq);
-
- BoardDTO preDto = new BoardDTO();
- BoardDTO nextDto = new BoardDTO();
- if (prePostCnt > 0) {
- preDto = boardService.selectPrePost(postSeq);
- }
-
- if (nextPostCnt > 0) {
- nextDto = boardService.selectNextPost(postSeq);
- }
-
- ModelAndView mv = setMV("notice/content");
- mv.addObject("filePath", config.filePath);
- mv.addObject("content", dto);
- // mv.addObject("groupIdx", sesGroupIdx);
- mv.addObject("prePostCnt", prePostCnt);
- mv.addObject("nextPostCnt", nextPostCnt);
- mv.addObject("prePost", preDto);
- mv.addObject("nextPost", nextDto);
- mv.addObject("referer", referer);
- return mv;
- }
-
- @RequestMapping(value="/notice/content/file", method=RequestMethod.GET)
- public void boardFile(HttpServletRequest request, HttpServletResponse response,
- @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq) {
-
- BoardDTO dto = new BoardDTO();
- dto.setPostSeq(postSeq);
- dto.setBoardType("N");
- int total = boardService.selectFileCount(dto);
-
- if (total > 0) {
- dto.setPostSeq(postSeq);
- dto.setBoardType("N");
- dto = boardService.selectFile(dto);
- String filePath = config.filePath + "/" + dto.getFileName();
- String fileName = dto.getFileOriginalName();
- LifeCenterFileDownload.download(request, response, filePath, fileName);
- }
- }
-
- @RequestMapping(value="/notice/content/delete", method = RequestMethod.POST)
- @Transactional(propagation=Propagation.REQUIRED)
- public String contentDelete(HttpServletRequest request, HttpServletResponse response,
- @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq,
- @RequestParam(value="fileName", required=false, defaultValue="") String fileName) {
- // String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
-
- // if (!sesGroupIdx.equals("1")) {
- // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '해당 글을 삭제할 수 없습니다.', callBack : function(){ location.href='/notice/list'; } });" );
- // return "/common/blank";
- // }
-
- BoardDTO dto = new BoardDTO();
- dto.setPostSeq(postSeq);
- dto.setBoardType("N");
- boardService.deleteNoticeIfno(postSeq);
-
- String path = config.filePath + "/" + fileName.trim();
- File rFile = new File(path);
- rFile.delete();
-
- boardService.deleteFile(dto);
-
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '게시글이 삭제되었습니다. ', callBack : function(){ location.href='/notice/list'; } });" );
-
- return "/common/blank";
- }
-
- @RequestMapping("/notice/edit")
- public ModelAndView boardEdit(HttpServletRequest request, HttpServletResponse response,
- @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq) {
- ModelAndView mv = setMV("notice/edit");
- String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
- //
- // if (!sesGroupIdx.equals("1")) {
- // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '공지사항 작성 권한이 없습니다.', callBack : function(){ location.href='./list'; } });" );
- // return "/common/blank";
- // }
-
- BoardDTO dto = new BoardDTO();
- int cnt = boardService.selectNoticeBoardCountOne(postSeq);
- if (cnt == 0) {
-
- } else {
- dto = boardService.selectNoticeBoardInfoOne(postSeq);
- }
- mv.addObject("groupIdx", sesGroupIdx);
- mv.addObject("item", dto);
- return mv;
- }
-
- @RequestMapping(value="/notice/edit/update", method = RequestMethod.POST)
- @Transactional(propagation=Propagation.REQUIRED)
- public String boardEditUpdate(
- HttpServletRequest request, HttpServletResponse response,
- @ModelAttribute("dto") final BoardDTO dto,
- MultipartFile file) {
-
- String sesId = LifeCenterSessionController.getSession(request, "sesId");
- // String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
- // if (!sesGroupIdx.equals("1")) {
- // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '공지사항 수정 권한이 없습니다.', callBack : function(){ location.href='./list'; } });" );
- // return "/common/blank";
- // }
-
- int postSeq = dto.getPostSeq();
-
- if (file.isEmpty() == false) {
- UUID uuid = UUID.randomUUID();
- String fileName = file.getOriginalFilename();
- int fileSize = (int) file.getSize(); //단위는 byte
- String ext = FilenameUtils.getExtension(fileName);
- String saveFileName = uuid + "." + ext;
-
- try {
- File saveFile = new File(config.filePath, saveFileName);
- FileCopyUtils.copy(file.getBytes(),saveFile);
-
- String path = config.filePath + "/" + dto.getFileName().trim();
- File rFile = new File(path);
- rFile.delete();
- } catch (IOException e) {
- e.printStackTrace();
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '파일 업로드에 실패하였습니다.', callBack : function(){ history.back(); } });" );
- return "/common/blank";
- }
-
- dto.setFileOriginalName(fileName);
- dto.setFileName(saveFileName);
- dto.setFileExtension(ext);
- dto.setFileSize(fileSize);
- dto.setBoardType("N");
- int cnt = boardService.selectFileCount(dto);
- if (cnt > 0) {
- boardService.updateFile(dto);
- } else {
- boardService.fileUploadDataInsert(dto);
- }
-
- } else {
- if (dto.getFileOriginalName().equals("")) {
- String path = config.filePath + "/" + dto.getFileName().trim();
- File rFile = new File(path);
- rFile.delete();
- dto.setBoardType("N");
- boardService.deleteFile(dto);
- }
- }
-
- dto.setUpdateBy(sesId);
- boardService.updateNoticeBoard(dto);
-
- return "redirect:/notice/content?postSeq=" + dto.getPostSeq();
- }
-
- @RequestMapping(value="/qna/content/file", method=RequestMethod.GET)
- public void boardFileQna(HttpServletRequest request, HttpServletResponse response,
- @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq) {
-
- BoardDTO dto = new BoardDTO();
- dto.setPostSeq(postSeq);
- dto.setBoardType("Q");
- int total = boardService.selectFileCount(dto);
-
- if (total > 0) {
- dto.setPostSeq(postSeq);
- dto.setBoardType("Q");
- dto = boardService.selectFile(dto);
- String filePath = config.filePath + "/" + dto.getFileName();
- String fileName = dto.getFileOriginalName();
- LifeCenterFileDownload.download(request, response, filePath, fileName);
- }
- }
-
- @RequestMapping("/qna/list")
- public ModelAndView qnsList(@RequestParam(value="searchTxt", required=false, defaultValue="") String searchTxt,
- @RequestParam(value="selectState", required=false, defaultValue="") String selectState,
- @RequestParam(value="page", required=false, defaultValue="1") int page,
- HttpServletRequest request, HttpServletResponse response) {
- String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" );
- BoardDTO dto = new BoardDTO();
-
- if (!selectState.equals("")) {
- if (selectState.equals("title")) {
- dto.setTitle(searchTxt);
- } else if (selectState.equals("createBy")) {
- dto.setCreateBy(searchTxt);
- } else if (selectState.equals("content")) {
- dto.setContent(searchTxt);
- }
- }
-
- dto.setLimit( ( Integer.valueOf( page ) - 1 ) * config.pageDataSize );
- dto.setLimitMax( config.pageDataSize );
-
- List<BoardDTO> list = new ArrayList<BoardDTO>();
-
- int total = boardService.selectQnaListCount(dto);
- if (total == 0) {
- } else {
- list = boardService.selectQnaList(dto);
- }
-
- String param = "";
- paging = LifeCenterPaging.getInstance();
- paging.paging(config, total, page, param);
-
- ModelAndView mv = setMV("qna/list");
- mv.addObject("sesGroupIdx", sesGroupIdx);
- mv.addObject("list", list);
- mv.addObject("total", total);
- mv.addObject("selectState", selectState);
- mv.addObject("searchTxt", searchTxt);
- mv.addObject("paging", paging);
- mv.addObject("page", page);
- mv.addObject("pageSize", dto.getLimitMax());
- return mv;
- }
-
- @RequestMapping("/qna/new")
- public ModelAndView boardQnaNew(HttpServletRequest request, HttpServletResponse response) {
- String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" );
- ModelAndView mv = setMV("qna/new");
- mv.addObject("groupIdx",sesGroupIdx);
-
- return mv;
- }
-
- @RequestMapping(value="/qna/new/insert", method = RequestMethod.POST)
- @Transactional(propagation=Propagation.REQUIRED)
- public String boardQnaNewInsert(
- HttpServletRequest request, HttpServletResponse response,
- @ModelAttribute("dto") final BoardDTO dto,
- MultipartFile file) {
- String sesId = LifeCenterSessionController.getSession(request, "sesId");
-
- String qnaInsertTime = LifeCenterSessionController.getSession(request, "qnaInsertTime");
- long time = LifeCenterFunction.getNowUnixTimeStamp();
- if( qnaInsertTime != null && !qnaInsertTime.equals( "" ) ) {
- long i = Long.parseLong( qnaInsertTime );
-
- if( ( time - i ) < 61 ) {
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '<font style=\"color:red\">자동화공격방지</font><br/>게시글 작성 후 60초 동안 작성이 불가능 합니다<br/>"+( 61 - ( time - i ) )+"초 이후 작성 가능', callBack : function(){ history.back(); } });" );
- return "/common/blank";
- }
- }
-
- if (file.isEmpty() == false) {
- UUID uuid = UUID.randomUUID();
- String fileName = file.getOriginalFilename();
- int fileSize = (int) file.getSize(); //단위는 byte
- String ext = FilenameUtils.getExtension(fileName);
- String saveFileName = uuid + "." + ext;
-
- try {
- String tempPath = config.filePath;
- File saveFile = new File(tempPath, saveFileName);
- FileCopyUtils.copy(file.getBytes(),saveFile);
- } catch (IOException e) {
- e.printStackTrace();
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '파일 업로드에 실패하였습니다.', callBack : function(){ history.back(); } });" );
- return "/common/blank";
- }
-
- dto.setFileOriginalName(fileName);
- dto.setFileName(saveFileName);
- dto.setFileExtension(ext);
- dto.setFileSize(fileSize);
- dto.setBoardType("Q");
- }
- String title = dto.getTitle().trim();
- String content = dto.getContent().trim();
-
- dto.setTitle(title);
- dto.setContent(content);
- dto.setCreateBy(sesId);
-
- boardService.qnaInsert(dto);
- int postSeq = dto.getPostSeq();
-
- if (postSeq == 0) {
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '게시물 등록에 실패하였습니다.', callBack : function(){ history.back(); } });" );
- return "/common/blank";
- } else {
- if (file.isEmpty() == false) {
- boardService.fileUploadDataInsert(dto);
- int fileIdx = dto.getFileIdx();
- if (fileIdx == 0) {
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '게시물 등록에 실패하였습니다.', callBack : function(){ history.back(); } });" );
- return "/common/blank";
- }
- }
- }
-
- LifeCenterSessionController.setSession( request, "qnaInsertTime", String.valueOf( time ) );
-
- return "redirect:/qna/content?postSeq=" + dto.getPostSeq();
- }
-
- @RequestMapping("/qna/content")
- public ModelAndView boardQnaContent(
- @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq,
- HttpServletRequest request, HttpServletResponse response) {
- String referer = request.getHeader("referer");
- String sesId = LifeCenterSessionController.getSession(request, "sesId");
- String sesName = LifeCenterSessionController.getSession(request, "sesName");
- String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" );
- String sesPermissions = LifeCenterSessionController.getSession( request, "sesPermissions" );
-
- int total = boardService.selectQnaBoardCountOne(postSeq);
- BoardDTO dto = new BoardDTO();
- if (total > 0) {
- boardService.updateQnaView(postSeq);
- dto = boardService.selectQnaBoardInfoOne(postSeq);
- }
-
- int prePostCnt = boardService.selectQnaPrePostCount(postSeq);
- int nextPostCnt = boardService.selectQnaNextPostCount(postSeq);
-
- BoardDTO preDto = new BoardDTO();
- BoardDTO nextDto = new BoardDTO();
- if (prePostCnt > 0) {
- preDto = boardService.selectQnaPrePost(postSeq);
- }
-
- if (nextPostCnt > 0) {
- nextDto = boardService.selectQnaNextPost(postSeq);
- }
-
- ModelAndView mv = setMV("qna/content");
- mv.addObject("filePath", config.filePath);
- mv.addObject("content", dto);
- mv.addObject("sesId", sesId);
- mv.addObject("sesName", sesName);
- mv.addObject("groupIdx", sesGroupIdx);
- mv.addObject("prePostCnt", prePostCnt);
- mv.addObject("nextPostCnt", nextPostCnt);
- mv.addObject("prePost", preDto);
- mv.addObject("nextPost", nextDto);
- mv.addObject("referer", referer);
- mv.addObject( "sesPermissions", sesPermissions );
-
- return mv;
- }
-
- @RequestMapping(value="/qna/content/answer", method = RequestMethod.POST)
- public String boardQnaAnswer(HttpServletRequest request, HttpServletResponse response,
- @ModelAttribute("dto") final BoardDTO dto) {
- // String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
- //
- // if (!sesGroupIdx.equals("1")) {
- // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '권한이 없습니다.', callBack : function(){ location.href='./list'; } });" );
- // return "/common/blank";
- // }
- boardService.qnaAnswerInsert(dto);
-
- return "redirect:/qna/content?postSeq=" + dto.getPostSeq();
- }
-
- @RequestMapping(value="/qna/content/answerDelete", method = RequestMethod.POST)
- public String boardQnaAnswerDelete(HttpServletRequest request, HttpServletResponse response,
- @ModelAttribute("dto") final BoardDTO dto) {
-
- // String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
- //
- // if (!sesGroupIdx.equals("1")) {
- // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '권한이 없습니다.', callBack : function(){ location.href='./list'; } });" );
- // return "/common/blank";
- // }
-
- dto.setAnswerContent("");
- boardService.qnaAnswerInsert(dto);
- return "redirect:/qna/content?postSeq=" + dto.getPostSeq();
- }
-
- @RequestMapping("/qna/edit")
- public ModelAndView boarQnadEdit(HttpServletRequest request, HttpServletResponse response,
- @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq) {
- ModelAndView mv = setMV("qna/edit");
-
- BoardDTO dto = new BoardDTO();
- int cnt = boardService.selectQnaBoardCountOne(postSeq);
- if (cnt == 0) {
-
- } else {
- dto = boardService.selectQnaBoardInfoOne(postSeq);
- }
- mv.addObject("item", dto);
- return mv;
- }
-
- @RequestMapping(value="/qna/edit/update", method = RequestMethod.POST)
- @Transactional(propagation=Propagation.REQUIRED)
- public String boardQnaEditUpdate(
- HttpServletRequest request, HttpServletResponse response,
- @ModelAttribute("dto") final BoardDTO dto,
- MultipartFile file) {
-
- String sesId = LifeCenterSessionController.getSession(request, "sesId");
-
- if (!sesId.equals(dto.getCreateBy())) {
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '해당글의 수정 권한이 없습니다.', callBack : function(){ location.href='./list'; } });" );
- return "/common/blank";
- }
-
- int postSeq = dto.getPostSeq();
-
- if (file.isEmpty() == false) {
- UUID uuid = UUID.randomUUID();
- String fileName = file.getOriginalFilename();
- int fileSize = (int) file.getSize(); //단위는 byte
- String ext = FilenameUtils.getExtension(fileName);
- String saveFileName = uuid + "." + ext;
-
- try {
- File saveFile = new File(config.filePath, saveFileName);
- FileCopyUtils.copy(file.getBytes(),saveFile);
-
- String path = config.filePath + "/" + dto.getFileName().trim();
- File rFile = new File(path);
- rFile.delete();
- } catch (IOException e) {
- e.printStackTrace();
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '파일 업로드에 실패하였습니다.', callBack : function(){ history.back(); } });" );
- return "/common/blank";
- }
-
- dto.setFileOriginalName(fileName);
- dto.setFileName(saveFileName);
- dto.setFileExtension(ext);
- dto.setFileSize(fileSize);
- dto.setBoardType("Q");
- int cnt = boardService.selectFileCount(dto);
- if (cnt > 0) {
- boardService.updateFile(dto);
- } else {
- boardService.fileUploadDataInsert(dto);
- }
-
- } else {
- if (dto.getFileOriginalName().equals("")) {
- String path = config.filePath + "/" + dto.getFileName().trim();
- File rFile = new File(path);
- rFile.delete();
- dto.setBoardType("Q");
- boardService.deleteFile(dto);
- }
- }
-
- dto.setUpdateBy(sesId);
- boardService.updateQnaBoard(dto);
-
- return "redirect:/qna/content?postSeq=" + postSeq;
- }
-
- @RequestMapping(value="/qna/content/delete", method = RequestMethod.POST)
- @Transactional(propagation=Propagation.REQUIRED)
- public String contentQnaDelete(HttpServletRequest request, HttpServletResponse response,
- @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq,
- @RequestParam(value="createBy", required=false, defaultValue="") String createBy,
- @RequestParam(value="fileName", required=false, defaultValue="") String fileName) {
-
- String sesId = LifeCenterSessionController.getSession(request, "sesId");
- // String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
-
- if (!sesId.equals(createBy)) {
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '해당 글을 삭제할 수 없습니다.', callBack : function(){ location.href='/qna/list'; } });" );
- return "/common/blank";
- }
-
- // if (!sesGroupIdx.equals("1")) {
- // if (!sesId.equals(createBy)) {
- // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '해당 글을 삭제할 수 없습니다.', callBack : function(){ location.href='/qna/list'; } });" );
- // return "/common/blank";
- // }
- // }
-
-
- BoardDTO dto = new BoardDTO();
- dto.setPostSeq(postSeq);
- dto.setBoardType("Q");
- boardService.deleteQnaIfno(postSeq);
-
- String path = config.filePath + "/" + fileName.trim();
- File rFile = new File(path);
- rFile.delete();
-
- boardService.deleteFile(dto);
-
- LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '게시글이 삭제되었습니다. ', callBack : function(){ location.href='/qna/list'; } });" );
-
- return "/common/blank";
- }
- }
|