266 lines
8.7 KiB
Java
266 lines
8.7 KiB
Java
|
|
package geoinfo.admins.board;
|
||
|
|
|
||
|
|
import egovframework.rte.psl.dataaccess.util.EgovMap;
|
||
|
|
import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;
|
||
|
|
import geoinfo.admins.board.service.QnaService;
|
||
|
|
import geoinfo.com.GeoinfoCommon;
|
||
|
|
import geoinfo.session.UserInfo;
|
||
|
|
|
||
|
|
import java.sql.SQLException;
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
import javax.annotation.Resource;
|
||
|
|
import javax.servlet.http.HttpServletRequest;
|
||
|
|
import javax.servlet.http.HttpServletResponse;
|
||
|
|
|
||
|
|
import org.springframework.http.MediaType;
|
||
|
|
import org.springframework.stereotype.Controller;
|
||
|
|
import org.springframework.ui.ModelMap;
|
||
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
||
|
|
|
||
|
|
@Controller
|
||
|
|
public class QnaController {
|
||
|
|
@Resource(name = "qnaService")
|
||
|
|
private QnaService masterService;
|
||
|
|
|
||
|
|
// #####
|
||
|
|
@RequestMapping(value = "admins/board/00.do")
|
||
|
|
public String board00( @RequestParam HashMap<String, Object> params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||
|
|
|
||
|
|
if (!UserInfo.isValidSession(request, response, "admin")) {
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
|
||
|
|
/** pageing */
|
||
|
|
PaginationInfo paginationInfo = new PaginationInfo();
|
||
|
|
|
||
|
|
paginationInfo.setRecordCountPerPage(10);
|
||
|
|
paginationInfo.setPageSize(10);
|
||
|
|
|
||
|
|
int maxRowNum = masterService.getMaxRowNum(params);
|
||
|
|
|
||
|
|
paginationInfo.setTotalRecordCount(maxRowNum);
|
||
|
|
|
||
|
|
if (params.get("pageIndex") == null || params.get("pageIndex").equals("") || Integer.parseInt((String) params.get("pageIndex"))<=0 ) {
|
||
|
|
paginationInfo.setCurrentPageNo(1);
|
||
|
|
params.put("pageIndex", 1);
|
||
|
|
}else if(Integer.parseInt((String)params.get("pageIndex")) > paginationInfo.getLastPageNo()){
|
||
|
|
paginationInfo.setCurrentPageNo(paginationInfo.getLastPageNo());
|
||
|
|
params.put("pageIndex", paginationInfo.getLastPageNo());
|
||
|
|
} else {
|
||
|
|
paginationInfo.setCurrentPageNo((Integer) Integer.valueOf((String) params.get("pageIndex")));
|
||
|
|
}
|
||
|
|
|
||
|
|
//System.out.println("sss - " + paginationInfo.getFirstRecordIndex());
|
||
|
|
params.put("firstIndex", paginationInfo.getFirstRecordIndex());
|
||
|
|
params.put("recordCountPerPage", paginationInfo.getRecordCountPerPage());
|
||
|
|
|
||
|
|
List<?> qnaList = masterService.getQnaList(params);
|
||
|
|
|
||
|
|
model.addAttribute("params", params);
|
||
|
|
model.addAttribute("rowNo", maxRowNum);
|
||
|
|
model.addAttribute("qnaList", qnaList);
|
||
|
|
model.addAttribute("paginationInfo", paginationInfo);
|
||
|
|
// 2018. 08.03 추가 게시판 검색 기능
|
||
|
|
model.addAttribute("pageIndex",params.get("pageIndex") );
|
||
|
|
model.addAttribute("searchTitle",params.get("searchTitle") );
|
||
|
|
model.addAttribute("searchKey",params.get("searchKey") );
|
||
|
|
|
||
|
|
return "admins/board/00";
|
||
|
|
}
|
||
|
|
|
||
|
|
@RequestMapping(value = "admins/board/00-view.do")
|
||
|
|
public String selectInfo(@RequestParam HashMap<String, Object> params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||
|
|
|
||
|
|
if (!UserInfo.isValidSession(request, response, "admin")) {
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
|
||
|
|
//int aid = Integer.parseInt(params.get("aid").toString());
|
||
|
|
|
||
|
|
List<?> result = masterService.selectQnaInfo(params);
|
||
|
|
|
||
|
|
System.out.println("params - " + params);
|
||
|
|
model.addAttribute("result", result);
|
||
|
|
model.addAttribute("br", "\r");
|
||
|
|
// 2018. 08.03 추가 게시판 검색 기능
|
||
|
|
model.addAttribute("params", params);
|
||
|
|
return "admins/board/00-view";
|
||
|
|
}
|
||
|
|
|
||
|
|
@RequestMapping(value = "admins/board/00-delete", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
|
||
|
|
public ModelMap deleteInfo(@RequestParam HashMap<String, Object> params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||
|
|
|
||
|
|
HashMap<String, Object> jsonMap = new HashMap<String, Object>();
|
||
|
|
|
||
|
|
try {
|
||
|
|
masterService.deleteInfo(params);
|
||
|
|
jsonMap.put("success", true);
|
||
|
|
} catch (SQLException Ex) {
|
||
|
|
jsonMap.put("success", false);
|
||
|
|
}
|
||
|
|
|
||
|
|
model.addAttribute("jsonView", jsonMap); // JSON으로 리턴하기 위해서는 모델키를 'jsonView'로 지정해야함
|
||
|
|
return model;
|
||
|
|
}
|
||
|
|
|
||
|
|
@RequestMapping(value = "admins/board/00-modify.do")
|
||
|
|
public String modifyInfo(@RequestParam HashMap<String, Object> params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||
|
|
|
||
|
|
if (!UserInfo.isValidSession(request, response, "admin")) {
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
|
||
|
|
int aid = Integer.parseInt(params.get("aid").toString());
|
||
|
|
|
||
|
|
EgovMap result = masterService.selectModifyInfo(params);
|
||
|
|
|
||
|
|
model.addAttribute("aid", aid);
|
||
|
|
model.addAttribute("result", result);
|
||
|
|
|
||
|
|
return "admins/board/00-modify";
|
||
|
|
}
|
||
|
|
|
||
|
|
@RequestMapping(value = "admins/board/00-modify-post", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
|
||
|
|
public ModelMap updateInfo(@RequestParam HashMap<String, Object> params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||
|
|
|
||
|
|
HashMap<String, Object> jsonMap = new HashMap<String, Object>();
|
||
|
|
|
||
|
|
try{
|
||
|
|
masterService.updateInfo(params);
|
||
|
|
jsonMap.put("success", true);
|
||
|
|
} catch (SQLException Ex) {
|
||
|
|
jsonMap.put("success", false);
|
||
|
|
}
|
||
|
|
|
||
|
|
model.addAttribute("jsonView", jsonMap); // JSON으로 리턴하기 위해서는 모델키를 'jsonView'로 지정해야함
|
||
|
|
return model;
|
||
|
|
}
|
||
|
|
|
||
|
|
@RequestMapping(value = "body/psboard/psboard_reply_write.do")
|
||
|
|
public String replyWrite(@RequestParam HashMap<String, Object> params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||
|
|
|
||
|
|
if (!UserInfo.isValidSession(request, response, "admin")) {
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
|
||
|
|
int pos = 0;
|
||
|
|
String content = "";
|
||
|
|
|
||
|
|
EgovMap result = masterService.selectReplyInfo(params);
|
||
|
|
|
||
|
|
content = result.get("content").toString();
|
||
|
|
|
||
|
|
while((pos=content.indexOf("\'", pos)) != -1) {
|
||
|
|
String left = content.substring(0, pos);
|
||
|
|
String right = content.substring(pos, content.length());
|
||
|
|
content = left + "\'" + right;
|
||
|
|
pos += 2;
|
||
|
|
}
|
||
|
|
|
||
|
|
result.put("content", content);
|
||
|
|
|
||
|
|
model.addAttribute("A", "작성자");
|
||
|
|
model.addAttribute("B", "비밀번호");
|
||
|
|
model.addAttribute("C", "제목");
|
||
|
|
model.addAttribute("D", "내 용");
|
||
|
|
model.addAttribute("result", result);
|
||
|
|
|
||
|
|
return "body/psboard/psboard_reply_write";
|
||
|
|
}
|
||
|
|
|
||
|
|
@RequestMapping(value = "body/psboard/psboard_reply_save", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
|
||
|
|
public ModelMap replySave(@RequestParam HashMap<String, Object> params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||
|
|
|
||
|
|
HashMap<String, Object> jsonMap = new HashMap<String, Object>();
|
||
|
|
|
||
|
|
try {
|
||
|
|
String seq = GeoinfoCommon.parseData(params.get("seq").toString());
|
||
|
|
String lseq = seq.substring(0, 1);
|
||
|
|
int seq_num = Integer.parseInt(seq);
|
||
|
|
params.put("password", "kictgis1234");
|
||
|
|
|
||
|
|
int idx = 0;
|
||
|
|
|
||
|
|
boolean replyMax = true;
|
||
|
|
|
||
|
|
int maxIdx = masterService.getMaxIdx();
|
||
|
|
|
||
|
|
if(maxIdx == 0) {
|
||
|
|
idx = 1;
|
||
|
|
} else {
|
||
|
|
idx = maxIdx + 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
params.put("idx", idx);
|
||
|
|
|
||
|
|
int seq_temp = 0;
|
||
|
|
String mseq_right = "";
|
||
|
|
|
||
|
|
if(seq_num == 0) {
|
||
|
|
int maxSeq = masterService.getMaxSeq(params);
|
||
|
|
|
||
|
|
seq_temp = maxSeq + 10;
|
||
|
|
seq = Integer.toString(seq_temp);
|
||
|
|
|
||
|
|
params.put("seq", seq);
|
||
|
|
masterService.replyWrite(params);
|
||
|
|
} else {
|
||
|
|
params.put("lseq", lseq);
|
||
|
|
|
||
|
|
int maxSeq2 = masterService.getMaxSeq2(params);
|
||
|
|
|
||
|
|
mseq_right = Integer.toString(maxSeq2).substring(1, 2);
|
||
|
|
|
||
|
|
if("9".equals(mseq_right)) {
|
||
|
|
replyMax = false;
|
||
|
|
} else {
|
||
|
|
seq_temp = maxSeq2 + 1;
|
||
|
|
seq = Integer.toString(seq_temp);
|
||
|
|
|
||
|
|
params.put("seq", seq);
|
||
|
|
masterService.replyWrite(params);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
jsonMap.put("replyMax", replyMax);
|
||
|
|
jsonMap.put("success", true);
|
||
|
|
} catch (SQLException Ex) {
|
||
|
|
jsonMap.put("success", false);
|
||
|
|
}
|
||
|
|
|
||
|
|
model.addAttribute("jsonView", jsonMap); // JSON으로 리턴하기 위해서는 모델키를 'jsonView'로 지정해야함
|
||
|
|
return model;
|
||
|
|
}
|
||
|
|
|
||
|
|
@RequestMapping(value = "admins/board/00_write.do")
|
||
|
|
public String writeInfo(@RequestParam HashMap<String, Object> params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||
|
|
|
||
|
|
if (!UserInfo.isValidSession(request, response, "admin")) {
|
||
|
|
return "";
|
||
|
|
}
|
||
|
|
|
||
|
|
return "admins/board/00_write";
|
||
|
|
}
|
||
|
|
|
||
|
|
@RequestMapping(value = "admins/board/00_save", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
|
||
|
|
public ModelMap saveInfo(@RequestParam HashMap<String, Object> params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception {
|
||
|
|
|
||
|
|
HashMap<String, Object> jsonMap = new HashMap<String, Object>();
|
||
|
|
params.put("password", "kictgis1234");
|
||
|
|
try{
|
||
|
|
masterService.saveInfo(params);
|
||
|
|
jsonMap.put("success", true);
|
||
|
|
} catch (SQLException Ex) {
|
||
|
|
jsonMap.put("success", false);
|
||
|
|
}
|
||
|
|
|
||
|
|
model.addAttribute("jsonView", jsonMap); // JSON으로 리턴하기 위해서는 모델키를 'jsonView'로 지정해야함
|
||
|
|
return model;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|