BoardController.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. package com.lemon.lifecenter.controller;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.UUID;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import org.apache.commons.io.FilenameUtils;
  10. import org.slf4j.Logger;
  11. import org.slf4j.LoggerFactory;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.stereotype.Controller;
  14. import org.springframework.transaction.annotation.Propagation;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import org.springframework.util.FileCopyUtils;
  17. import org.springframework.web.bind.annotation.ModelAttribute;
  18. import org.springframework.web.bind.annotation.RequestMapping;
  19. import org.springframework.web.bind.annotation.RequestMethod;
  20. import org.springframework.web.bind.annotation.RequestParam;
  21. import org.springframework.web.multipart.MultipartFile;
  22. import org.springframework.web.servlet.ModelAndView;
  23. import com.lemon.lifecenter.common.LifeCenterConfigVO;
  24. import com.lemon.lifecenter.common.LifeCenterController;
  25. import com.lemon.lifecenter.common.LifeCenterFileDownload;
  26. import com.lemon.lifecenter.common.LifeCenterFunction;
  27. import com.lemon.lifecenter.common.LifeCenterPaging;
  28. import com.lemon.lifecenter.common.LifeCenterSessionController;
  29. import com.lemon.lifecenter.dto.BoardDTO;
  30. import com.lemon.lifecenter.service.BoardService;
  31. @Controller
  32. public class BoardController extends LifeCenterController {
  33. private final Logger logger = LoggerFactory.getLogger(this.getClass());
  34. @Autowired
  35. private BoardService boardService;
  36. @Autowired
  37. private LifeCenterConfigVO config;
  38. private LifeCenterPaging paging;
  39. @RequestMapping("/notice/list")
  40. public ModelAndView boardList(
  41. @RequestParam(value="searchTxt", required=false, defaultValue="") String searchTxt,
  42. @RequestParam(value="selectState", required=false, defaultValue="") String selectState,
  43. @RequestParam(value="page", required=false, defaultValue="1") int page,
  44. HttpServletRequest request, HttpServletResponse response) {
  45. BoardDTO dto = new BoardDTO();
  46. if (!selectState.equals("")) {
  47. if (selectState.equals("title")) {
  48. dto.setTitle(searchTxt);
  49. } else if (selectState.equals("content")) {
  50. dto.setContent(searchTxt);
  51. }
  52. }
  53. dto.setLimit( ( Integer.valueOf( page ) - 1 ) * config.pageDataSize );
  54. dto.setLimitMax( config.pageDataSize );
  55. List<BoardDTO> list = new ArrayList<BoardDTO>();
  56. int total = boardService.selectNoticeBoardListCount(dto);
  57. if (total == 0) {
  58. } else {
  59. list = boardService.selectNoticeBoardList(dto);
  60. }
  61. String param = "";
  62. paging = LifeCenterPaging.getInstance();
  63. paging.paging(config, total, page, param);
  64. ModelAndView mv = setMV("notice/list");
  65. mv.addObject("list", list);
  66. mv.addObject("total", total);
  67. mv.addObject("selectState", selectState);
  68. mv.addObject("searchTxt", searchTxt);
  69. mv.addObject("paging", paging);
  70. mv.addObject("page", page);
  71. mv.addObject("pageSize", dto.getLimitMax());
  72. return mv;
  73. }
  74. @RequestMapping("/notice/new")
  75. public ModelAndView boardNew(HttpServletRequest request, HttpServletResponse response) {
  76. // String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" );
  77. ModelAndView mv = setMV("notice/new");
  78. // mv.addObject("groupIdx",sesGroupIdx);
  79. return mv;
  80. }
  81. @RequestMapping(value="/notice/new/insert", method = RequestMethod.POST)
  82. @Transactional(propagation=Propagation.REQUIRED)
  83. public String boardNewInsert(
  84. HttpServletRequest request, HttpServletResponse response,
  85. @ModelAttribute("dto") final BoardDTO dto,
  86. MultipartFile file) {
  87. String sesId = LifeCenterSessionController.getSession(request, "sesId");
  88. // String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
  89. //
  90. // if (!sesGroupIdx.equals("1")) {
  91. // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '공지사항 작성 권한이 없습니다.', callBack : function(){ location.href='/notice/list'; } });" );
  92. // return "/common/blank";
  93. // }
  94. String noticeInsertTime = LifeCenterSessionController.getSession(request, "noticeInsertTime");
  95. long time = LifeCenterFunction.getNowUnixTimeStamp();
  96. if( noticeInsertTime != null && !noticeInsertTime.equals( "" ) ) {
  97. long i = Long.parseLong( noticeInsertTime );
  98. if( ( time - i ) < 61 ) {
  99. LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '<font style=\"color:red\">자동화공격방지</font><br/>게시글 작성 후 60초 동안 작성이 불가능 합니다<br/>"+( 61 - ( time - i ) )+"초 이후 작성 가능', callBack : function(){ history.back(); } });" );
  100. return "/common/blank";
  101. }
  102. }
  103. if (file.isEmpty() == false) {
  104. UUID uuid = UUID.randomUUID();
  105. String fileName = file.getOriginalFilename();
  106. int fileSize = (int) file.getSize(); //단위는 byte
  107. String ext = FilenameUtils.getExtension(fileName);
  108. String saveFileName = uuid + "." + ext;
  109. final String[] PERMISSION_FILE_EXT_ARR = {"gif","png","jpg","jpeg","doc","docx","xls","xlsx","hwp","pdf", "txt"};
  110. boolean extFlag = false;
  111. for( int i = 0; i < PERMISSION_FILE_EXT_ARR.length; i++ ) {
  112. if( PERMISSION_FILE_EXT_ARR[i].equals( ext.toLowerCase() ) ) {
  113. extFlag = true;
  114. }
  115. }
  116. if( extFlag == false ) {
  117. LifeCenterFunction.scriptMessage( response, "alertBox({ txt : \"등록할수 없는 확장자입니다.<br/>.gif, .jpg, .png, .jpeg, .doc, .docx, .xls, .xlsx, .hwp, .pdf, .txt 확장자만 등록가능\", callBack : function(){ history.back(); } });" );
  118. return "/common/blank";
  119. }
  120. try {
  121. String tempPath = config.filePath;
  122. File saveFile = new File(tempPath, saveFileName);
  123. FileCopyUtils.copy(file.getBytes(),saveFile);
  124. } catch (IOException e) {
  125. e.printStackTrace();
  126. LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '파일 업로드에 실패하였습니다.', callBack : function(){ history.back(); } });" );
  127. return "/common/blank";
  128. }
  129. dto.setFileOriginalName(fileName);
  130. dto.setFileName(saveFileName);
  131. dto.setFileExtension(ext);
  132. dto.setFileSize(fileSize);
  133. dto.setBoardType("N");
  134. }
  135. String title = dto.getTitle().trim();
  136. String content = dto.getContent().trim();
  137. dto.setTitle(title);
  138. dto.setContent(content);
  139. dto.setCreateBy(sesId);
  140. boardService.noticeInsert(dto);
  141. int postSeq = dto.getPostSeq();
  142. if (postSeq == 0) {
  143. LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '게시물 등록에 실패하였습니다.', callBack : function(){ history.back(); } });" );
  144. return "/common/blank";
  145. } else {
  146. if (file.isEmpty() == false) {
  147. boardService.fileUploadDataInsert(dto);
  148. int fileIdx = dto.getFileIdx();
  149. if (fileIdx == 0) {
  150. LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '게시물 등록에 실패하였습니다.', callBack : function(){ history.back(); } });" );
  151. return "/common/blank";
  152. }
  153. }
  154. }
  155. LifeCenterSessionController.setSession( request, "noticeInsertTime", String.valueOf( time ) );
  156. return "redirect:/notice/content?postSeq=" + dto.getPostSeq();
  157. }
  158. @RequestMapping("/notice/content")
  159. public ModelAndView boardContent(
  160. @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq,
  161. HttpServletRequest request, HttpServletResponse response) {
  162. String referer = request.getHeader("referer");
  163. // String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" );
  164. int total = boardService.selectNoticeBoardCountOne(postSeq);
  165. BoardDTO dto = new BoardDTO();
  166. if (total > 0) {
  167. boardService.updateNoticeView(postSeq);
  168. dto = boardService.selectNoticeBoardInfoOne(postSeq);
  169. }
  170. int prePostCnt = boardService.selectPrePostCount(postSeq);
  171. int nextPostCnt = boardService.selectNextPostCount(postSeq);
  172. BoardDTO preDto = new BoardDTO();
  173. BoardDTO nextDto = new BoardDTO();
  174. if (prePostCnt > 0) {
  175. preDto = boardService.selectPrePost(postSeq);
  176. }
  177. if (nextPostCnt > 0) {
  178. nextDto = boardService.selectNextPost(postSeq);
  179. }
  180. ModelAndView mv = setMV("notice/content");
  181. mv.addObject("filePath", config.filePath);
  182. mv.addObject("content", dto);
  183. // mv.addObject("groupIdx", sesGroupIdx);
  184. mv.addObject("prePostCnt", prePostCnt);
  185. mv.addObject("nextPostCnt", nextPostCnt);
  186. mv.addObject("prePost", preDto);
  187. mv.addObject("nextPost", nextDto);
  188. mv.addObject("referer", referer);
  189. return mv;
  190. }
  191. @RequestMapping(value="/notice/content/file", method=RequestMethod.GET)
  192. public void boardFile(HttpServletRequest request, HttpServletResponse response,
  193. @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq) {
  194. BoardDTO dto = new BoardDTO();
  195. dto.setPostSeq(postSeq);
  196. dto.setBoardType("N");
  197. int total = boardService.selectFileCount(dto);
  198. if (total > 0) {
  199. dto.setPostSeq(postSeq);
  200. dto.setBoardType("N");
  201. dto = boardService.selectFile(dto);
  202. String filePath = config.filePath + "/" + dto.getFileName();
  203. String fileName = dto.getFileOriginalName();
  204. LifeCenterFileDownload.download(request, response, filePath, fileName);
  205. }
  206. }
  207. @RequestMapping(value="/notice/content/delete", method = RequestMethod.POST)
  208. @Transactional(propagation=Propagation.REQUIRED)
  209. public String contentDelete(HttpServletRequest request, HttpServletResponse response,
  210. @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq,
  211. @RequestParam(value="fileName", required=false, defaultValue="") String fileName) {
  212. // String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
  213. // if (!sesGroupIdx.equals("1")) {
  214. // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '해당 글을 삭제할 수 없습니다.', callBack : function(){ location.href='/notice/list'; } });" );
  215. // return "/common/blank";
  216. // }
  217. BoardDTO dto = new BoardDTO();
  218. dto.setPostSeq(postSeq);
  219. dto.setBoardType("N");
  220. boardService.deleteNoticeIfno(postSeq);
  221. String path = config.filePath + "/" + fileName.trim();
  222. File rFile = new File(path);
  223. rFile.delete();
  224. boardService.deleteFile(dto);
  225. LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '게시글이 삭제되었습니다. ', callBack : function(){ location.href='/notice/list'; } });" );
  226. return "/common/blank";
  227. }
  228. @RequestMapping("/notice/edit")
  229. public ModelAndView boardEdit(HttpServletRequest request, HttpServletResponse response,
  230. @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq) {
  231. ModelAndView mv = setMV("notice/edit");
  232. String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
  233. //
  234. // if (!sesGroupIdx.equals("1")) {
  235. // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '공지사항 작성 권한이 없습니다.', callBack : function(){ location.href='./list'; } });" );
  236. // return "/common/blank";
  237. // }
  238. BoardDTO dto = new BoardDTO();
  239. int cnt = boardService.selectNoticeBoardCountOne(postSeq);
  240. if (cnt == 0) {
  241. } else {
  242. dto = boardService.selectNoticeBoardInfoOne(postSeq);
  243. }
  244. mv.addObject("groupIdx", sesGroupIdx);
  245. mv.addObject("item", dto);
  246. return mv;
  247. }
  248. @RequestMapping(value="/notice/edit/update", method = RequestMethod.POST)
  249. @Transactional(propagation=Propagation.REQUIRED)
  250. public String boardEditUpdate(
  251. HttpServletRequest request, HttpServletResponse response,
  252. @ModelAttribute("dto") final BoardDTO dto,
  253. MultipartFile file) {
  254. String sesId = LifeCenterSessionController.getSession(request, "sesId");
  255. // String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
  256. // if (!sesGroupIdx.equals("1")) {
  257. // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '공지사항 수정 권한이 없습니다.', callBack : function(){ location.href='./list'; } });" );
  258. // return "/common/blank";
  259. // }
  260. int postSeq = dto.getPostSeq();
  261. if (file.isEmpty() == false) {
  262. UUID uuid = UUID.randomUUID();
  263. String fileName = file.getOriginalFilename();
  264. int fileSize = (int) file.getSize(); //단위는 byte
  265. String ext = FilenameUtils.getExtension(fileName);
  266. String saveFileName = uuid + "." + ext;
  267. try {
  268. File saveFile = new File(config.filePath, saveFileName);
  269. FileCopyUtils.copy(file.getBytes(),saveFile);
  270. String path = config.filePath + "/" + dto.getFileName().trim();
  271. File rFile = new File(path);
  272. rFile.delete();
  273. } catch (IOException e) {
  274. e.printStackTrace();
  275. LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '파일 업로드에 실패하였습니다.', callBack : function(){ history.back(); } });" );
  276. return "/common/blank";
  277. }
  278. dto.setFileOriginalName(fileName);
  279. dto.setFileName(saveFileName);
  280. dto.setFileExtension(ext);
  281. dto.setFileSize(fileSize);
  282. dto.setBoardType("N");
  283. int cnt = boardService.selectFileCount(dto);
  284. if (cnt > 0) {
  285. boardService.updateFile(dto);
  286. } else {
  287. boardService.fileUploadDataInsert(dto);
  288. }
  289. } else {
  290. if (dto.getFileOriginalName().equals("")) {
  291. String path = config.filePath + "/" + dto.getFileName().trim();
  292. File rFile = new File(path);
  293. rFile.delete();
  294. dto.setBoardType("N");
  295. boardService.deleteFile(dto);
  296. }
  297. }
  298. dto.setUpdateBy(sesId);
  299. boardService.updateNoticeBoard(dto);
  300. return "redirect:/notice/content?postSeq=" + dto.getPostSeq();
  301. }
  302. @RequestMapping(value="/qna/content/file", method=RequestMethod.GET)
  303. public void boardFileQna(HttpServletRequest request, HttpServletResponse response,
  304. @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq) {
  305. BoardDTO dto = new BoardDTO();
  306. dto.setPostSeq(postSeq);
  307. dto.setBoardType("Q");
  308. int total = boardService.selectFileCount(dto);
  309. if (total > 0) {
  310. dto.setPostSeq(postSeq);
  311. dto.setBoardType("Q");
  312. dto = boardService.selectFile(dto);
  313. String filePath = config.filePath + "/" + dto.getFileName();
  314. String fileName = dto.getFileOriginalName();
  315. LifeCenterFileDownload.download(request, response, filePath, fileName);
  316. }
  317. }
  318. @RequestMapping("/qna/list")
  319. public ModelAndView qnsList(@RequestParam(value="searchTxt", required=false, defaultValue="") String searchTxt,
  320. @RequestParam(value="selectState", required=false, defaultValue="") String selectState,
  321. @RequestParam(value="page", required=false, defaultValue="1") int page,
  322. HttpServletRequest request, HttpServletResponse response) {
  323. String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" );
  324. BoardDTO dto = new BoardDTO();
  325. if (!selectState.equals("")) {
  326. if (selectState.equals("title")) {
  327. dto.setTitle(searchTxt);
  328. } else if (selectState.equals("createBy")) {
  329. dto.setCreateBy(searchTxt);
  330. } else if (selectState.equals("content")) {
  331. dto.setContent(searchTxt);
  332. }
  333. }
  334. dto.setLimit( ( Integer.valueOf( page ) - 1 ) * config.pageDataSize );
  335. dto.setLimitMax( config.pageDataSize );
  336. List<BoardDTO> list = new ArrayList<BoardDTO>();
  337. int total = boardService.selectQnaListCount(dto);
  338. if (total == 0) {
  339. } else {
  340. list = boardService.selectQnaList(dto);
  341. }
  342. String param = "";
  343. paging = LifeCenterPaging.getInstance();
  344. paging.paging(config, total, page, param);
  345. ModelAndView mv = setMV("qna/list");
  346. mv.addObject("sesGroupIdx", sesGroupIdx);
  347. mv.addObject("list", list);
  348. mv.addObject("total", total);
  349. mv.addObject("selectState", selectState);
  350. mv.addObject("searchTxt", searchTxt);
  351. mv.addObject("paging", paging);
  352. mv.addObject("page", page);
  353. mv.addObject("pageSize", dto.getLimitMax());
  354. return mv;
  355. }
  356. @RequestMapping("/qna/new")
  357. public ModelAndView boardQnaNew(HttpServletRequest request, HttpServletResponse response) {
  358. String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" );
  359. ModelAndView mv = setMV("qna/new");
  360. mv.addObject("groupIdx",sesGroupIdx);
  361. return mv;
  362. }
  363. @RequestMapping(value="/qna/new/insert", method = RequestMethod.POST)
  364. @Transactional(propagation=Propagation.REQUIRED)
  365. public String boardQnaNewInsert(
  366. HttpServletRequest request, HttpServletResponse response,
  367. @ModelAttribute("dto") final BoardDTO dto,
  368. MultipartFile file) {
  369. String sesId = LifeCenterSessionController.getSession(request, "sesId");
  370. String qnaInsertTime = LifeCenterSessionController.getSession(request, "qnaInsertTime");
  371. long time = LifeCenterFunction.getNowUnixTimeStamp();
  372. if( qnaInsertTime != null && !qnaInsertTime.equals( "" ) ) {
  373. long i = Long.parseLong( qnaInsertTime );
  374. if( ( time - i ) < 61 ) {
  375. LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '<font style=\"color:red\">자동화공격방지</font><br/>게시글 작성 후 60초 동안 작성이 불가능 합니다<br/>"+( 61 - ( time - i ) )+"초 이후 작성 가능', callBack : function(){ history.back(); } });" );
  376. return "/common/blank";
  377. }
  378. }
  379. if (file.isEmpty() == false) {
  380. UUID uuid = UUID.randomUUID();
  381. String fileName = file.getOriginalFilename();
  382. int fileSize = (int) file.getSize(); //단위는 byte
  383. String ext = FilenameUtils.getExtension(fileName);
  384. String saveFileName = uuid + "." + ext;
  385. try {
  386. String tempPath = config.filePath;
  387. File saveFile = new File(tempPath, saveFileName);
  388. FileCopyUtils.copy(file.getBytes(),saveFile);
  389. } catch (IOException e) {
  390. e.printStackTrace();
  391. LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '파일 업로드에 실패하였습니다.', callBack : function(){ history.back(); } });" );
  392. return "/common/blank";
  393. }
  394. dto.setFileOriginalName(fileName);
  395. dto.setFileName(saveFileName);
  396. dto.setFileExtension(ext);
  397. dto.setFileSize(fileSize);
  398. dto.setBoardType("Q");
  399. }
  400. String title = dto.getTitle().trim();
  401. String content = dto.getContent().trim();
  402. dto.setTitle(title);
  403. dto.setContent(content);
  404. dto.setCreateBy(sesId);
  405. boardService.qnaInsert(dto);
  406. int postSeq = dto.getPostSeq();
  407. if (postSeq == 0) {
  408. LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '게시물 등록에 실패하였습니다.', callBack : function(){ history.back(); } });" );
  409. return "/common/blank";
  410. } else {
  411. if (file.isEmpty() == false) {
  412. boardService.fileUploadDataInsert(dto);
  413. int fileIdx = dto.getFileIdx();
  414. if (fileIdx == 0) {
  415. LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '게시물 등록에 실패하였습니다.', callBack : function(){ history.back(); } });" );
  416. return "/common/blank";
  417. }
  418. }
  419. }
  420. LifeCenterSessionController.setSession( request, "qnaInsertTime", String.valueOf( time ) );
  421. return "redirect:/qna/content?postSeq=" + dto.getPostSeq();
  422. }
  423. @RequestMapping("/qna/content")
  424. public ModelAndView boardQnaContent(
  425. @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq,
  426. HttpServletRequest request, HttpServletResponse response) {
  427. String referer = request.getHeader("referer");
  428. String sesId = LifeCenterSessionController.getSession(request, "sesId");
  429. String sesName = LifeCenterSessionController.getSession(request, "sesName");
  430. String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" );
  431. String sesPermissions = LifeCenterSessionController.getSession( request, "sesPermissions" );
  432. int total = boardService.selectQnaBoardCountOne(postSeq);
  433. BoardDTO dto = new BoardDTO();
  434. if (total > 0) {
  435. boardService.updateQnaView(postSeq);
  436. dto = boardService.selectQnaBoardInfoOne(postSeq);
  437. }
  438. int prePostCnt = boardService.selectQnaPrePostCount(postSeq);
  439. int nextPostCnt = boardService.selectQnaNextPostCount(postSeq);
  440. BoardDTO preDto = new BoardDTO();
  441. BoardDTO nextDto = new BoardDTO();
  442. if (prePostCnt > 0) {
  443. preDto = boardService.selectQnaPrePost(postSeq);
  444. }
  445. if (nextPostCnt > 0) {
  446. nextDto = boardService.selectQnaNextPost(postSeq);
  447. }
  448. ModelAndView mv = setMV("qna/content");
  449. mv.addObject("filePath", config.filePath);
  450. mv.addObject("content", dto);
  451. mv.addObject("sesId", sesId);
  452. mv.addObject("sesName", sesName);
  453. mv.addObject("groupIdx", sesGroupIdx);
  454. mv.addObject("prePostCnt", prePostCnt);
  455. mv.addObject("nextPostCnt", nextPostCnt);
  456. mv.addObject("prePost", preDto);
  457. mv.addObject("nextPost", nextDto);
  458. mv.addObject("referer", referer);
  459. mv.addObject( "sesPermissions", sesPermissions );
  460. return mv;
  461. }
  462. @RequestMapping(value="/qna/content/answer", method = RequestMethod.POST)
  463. public String boardQnaAnswer(HttpServletRequest request, HttpServletResponse response,
  464. @ModelAttribute("dto") final BoardDTO dto) {
  465. // String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
  466. //
  467. // if (!sesGroupIdx.equals("1")) {
  468. // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '권한이 없습니다.', callBack : function(){ location.href='./list'; } });" );
  469. // return "/common/blank";
  470. // }
  471. boardService.qnaAnswerInsert(dto);
  472. return "redirect:/qna/content?postSeq=" + dto.getPostSeq();
  473. }
  474. @RequestMapping(value="/qna/content/answerDelete", method = RequestMethod.POST)
  475. public String boardQnaAnswerDelete(HttpServletRequest request, HttpServletResponse response,
  476. @ModelAttribute("dto") final BoardDTO dto) {
  477. // String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
  478. //
  479. // if (!sesGroupIdx.equals("1")) {
  480. // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '권한이 없습니다.', callBack : function(){ location.href='./list'; } });" );
  481. // return "/common/blank";
  482. // }
  483. dto.setAnswerContent("");
  484. boardService.qnaAnswerInsert(dto);
  485. return "redirect:/qna/content?postSeq=" + dto.getPostSeq();
  486. }
  487. @RequestMapping("/qna/edit")
  488. public ModelAndView boarQnadEdit(HttpServletRequest request, HttpServletResponse response,
  489. @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq) {
  490. ModelAndView mv = setMV("qna/edit");
  491. BoardDTO dto = new BoardDTO();
  492. int cnt = boardService.selectQnaBoardCountOne(postSeq);
  493. if (cnt == 0) {
  494. } else {
  495. dto = boardService.selectQnaBoardInfoOne(postSeq);
  496. }
  497. mv.addObject("item", dto);
  498. return mv;
  499. }
  500. @RequestMapping(value="/qna/edit/update", method = RequestMethod.POST)
  501. @Transactional(propagation=Propagation.REQUIRED)
  502. public String boardQnaEditUpdate(
  503. HttpServletRequest request, HttpServletResponse response,
  504. @ModelAttribute("dto") final BoardDTO dto,
  505. MultipartFile file) {
  506. String sesId = LifeCenterSessionController.getSession(request, "sesId");
  507. if (!sesId.equals(dto.getCreateBy())) {
  508. LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '해당글의 수정 권한이 없습니다.', callBack : function(){ location.href='./list'; } });" );
  509. return "/common/blank";
  510. }
  511. int postSeq = dto.getPostSeq();
  512. if (file.isEmpty() == false) {
  513. UUID uuid = UUID.randomUUID();
  514. String fileName = file.getOriginalFilename();
  515. int fileSize = (int) file.getSize(); //단위는 byte
  516. String ext = FilenameUtils.getExtension(fileName);
  517. String saveFileName = uuid + "." + ext;
  518. try {
  519. File saveFile = new File(config.filePath, saveFileName);
  520. FileCopyUtils.copy(file.getBytes(),saveFile);
  521. String path = config.filePath + "/" + dto.getFileName().trim();
  522. File rFile = new File(path);
  523. rFile.delete();
  524. } catch (IOException e) {
  525. e.printStackTrace();
  526. LifeCenterFunction.scriptMessage( response, "alertBox({ txt : '파일 업로드에 실패하였습니다.', callBack : function(){ history.back(); } });" );
  527. return "/common/blank";
  528. }
  529. dto.setFileOriginalName(fileName);
  530. dto.setFileName(saveFileName);
  531. dto.setFileExtension(ext);
  532. dto.setFileSize(fileSize);
  533. dto.setBoardType("Q");
  534. int cnt = boardService.selectFileCount(dto);
  535. if (cnt > 0) {
  536. boardService.updateFile(dto);
  537. } else {
  538. boardService.fileUploadDataInsert(dto);
  539. }
  540. } else {
  541. if (dto.getFileOriginalName().equals("")) {
  542. String path = config.filePath + "/" + dto.getFileName().trim();
  543. File rFile = new File(path);
  544. rFile.delete();
  545. dto.setBoardType("Q");
  546. boardService.deleteFile(dto);
  547. }
  548. }
  549. dto.setUpdateBy(sesId);
  550. boardService.updateQnaBoard(dto);
  551. return "redirect:/qna/content?postSeq=" + postSeq;
  552. }
  553. @RequestMapping(value="/qna/content/delete", method = RequestMethod.POST)
  554. @Transactional(propagation=Propagation.REQUIRED)
  555. public String contentQnaDelete(HttpServletRequest request, HttpServletResponse response,
  556. @RequestParam(value="postSeq", required=false, defaultValue="") int postSeq,
  557. @RequestParam(value="createBy", required=false, defaultValue="") String createBy,
  558. @RequestParam(value="fileName", required=false, defaultValue="") String fileName) {
  559. String sesId = LifeCenterSessionController.getSession(request, "sesId");
  560. // String sesGroupIdx = LifeCenterSessionController.getSession(request, "sesGroupIdx");
  561. if (!sesId.equals(createBy)) {
  562. LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '해당 글을 삭제할 수 없습니다.', callBack : function(){ location.href='/qna/list'; } });" );
  563. return "/common/blank";
  564. }
  565. // if (!sesGroupIdx.equals("1")) {
  566. // if (!sesId.equals(createBy)) {
  567. // LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '해당 글을 삭제할 수 없습니다.', callBack : function(){ location.href='/qna/list'; } });" );
  568. // return "/common/blank";
  569. // }
  570. // }
  571. BoardDTO dto = new BoardDTO();
  572. dto.setPostSeq(postSeq);
  573. dto.setBoardType("Q");
  574. boardService.deleteQnaIfno(postSeq);
  575. String path = config.filePath + "/" + fileName.trim();
  576. File rFile = new File(path);
  577. rFile.delete();
  578. boardService.deleteFile(dto);
  579. LifeCenterFunction.scriptMessage( response, "alertBox({ txt: '게시글이 삭제되었습니다. ', callBack : function(){ location.href='/qna/list'; } });" );
  580. return "/common/blank";
  581. }
  582. }