i-framework-lite/.svn/pristine/05/051f8c7fd7e49242a69c29f77f4...

253 lines
9.5 KiB
Plaintext

package kr.co.i4way.manage.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
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.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import kr.co.i4way.manage.model.CenterInfoVo;
import kr.co.i4way.manage.model.CommonInfoVo;
import kr.co.i4way.manage.model.FormBasedFileVo;
import kr.co.i4way.manage.model.ImageInfoVo;
import kr.co.i4way.manage.model.LoginVo;
import kr.co.i4way.manage.model.ObjInfoVo;
import kr.co.i4way.manage.model.UserInfoVo;
import kr.co.i4way.manage.model.WallInfoVo;
import kr.co.i4way.manage.service.ManageService;
import kr.co.i4way.manage.util.FileUploadUtil;
@Controller
public class ManageController {
Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired(required=true)
private ManageService service;
@RequestMapping(value="/login")
public ModelAndView login() throws Exception{
ModelAndView mv = new ModelAndView("/login/login");
return mv;
}
@RequestMapping(value="/main")
public ModelAndView main() throws Exception{
ModelAndView mv = new ModelAndView("/main/main");
return mv;
}
@RequestMapping(value="/main_info")
public ModelAndView main_info() throws Exception{
ModelAndView mv = new ModelAndView("/manage/wall_info");
return mv;
}
@RequestMapping(value="/center_info")
public ModelAndView center_info() throws Exception{
ModelAndView mv = new ModelAndView("/manage/center_info");
return mv;
}
@RequestMapping(value="/user_info")
public ModelAndView user_info() throws Exception{
ModelAndView mv = new ModelAndView("/manage/user_info");
return mv;
}
@RequestMapping(value="/obj_info")
public ModelAndView obj_info() throws Exception{
ModelAndView mv = new ModelAndView("/manage/obj_info");
return mv;
}
@RequestMapping(value="/image_info")
public ModelAndView image_info() throws Exception{
ModelAndView mv = new ModelAndView("/manage/image_info");
return mv;
}
@RequestMapping(value="/image_selector")
public ModelAndView imageSelector() throws Exception{
ModelAndView mv = new ModelAndView("/manage/image_selector");
return mv;
}
// http://localhost/manage/requestLogin
@RequestMapping(value="/manage/requestLogin")
public String requestLogin(LoginVo avo
, String targetUri
, RedirectAttributes ra
, HttpSession session) throws NullPointerException, Exception{
int mapSize = 0;
Map<String,Object> map = service.getLoginInfo(avo);
if(map != null){
mapSize = map.size();
if(mapSize > 0) {
logger.info("로그인 성공!!");
session.setAttribute("user_id", map.get("USER_ID"));
session.setAttribute("user_name", map.get("USER_NAME"));
session.setAttribute("user_centers", map.get("CENTER_ID"));
session.setAttribute("user_grade", map.get("GRADE"));
session.setAttribute("user_custom1", map.get("CUSTOM1"));
session.setAttribute("user_custom2", map.get("CUSTOM2"));
session.setMaxInactiveInterval(60 * 60);//시간 셋팅.60 * 10->10분 60 * 60 * 1->1시간
targetUri = "/main";
return "redirect:"+targetUri;//메인으로 가버리면 다시 클릭클릭해서 찾아가야하니 일케 해당페이지로 남아있게해줌
}
}
//로그인 실패(로그인 페이지 다시 리다이렉트)
logger.info("로그인 실패!!");
ra.addFlashAttribute("msg","아이디 또는 패스워드가 일치하지 않습니다.");
return "redirect:/login";
}
@RequestMapping("/getWallInfo_Manage")
public @ResponseBody Map<String , Object> getWallInfo(@ModelAttribute("wallinfovo") WallInfoVo wallinfovo) throws Exception{
Map<String, Object> rtnObject = new HashMap<String, Object>();
wallinfovo.setQuery_arry(wallinfovo.getCenter_id().split(","));
rtnObject.put("list", service.getWallInfo_Manage(wallinfovo));
rtnObject.put("param", wallinfovo);
return rtnObject;
}
@RequestMapping("/getCenterInfo_Manage")
public @ResponseBody Map<String , Object> getCenterInfo_Manage(@ModelAttribute("centerinfovo") CenterInfoVo centerinfovo) throws Exception{
Map<String, Object> rtnObject = new HashMap<String, Object>();
rtnObject.put("list", service.getCenterInfo_Manage(centerinfovo));
rtnObject.put("param", centerinfovo);
return rtnObject;
}
@RequestMapping("/insertCenterInfo")
public @ResponseBody Map<String , Object> insertCenterInfo(
@ModelAttribute("centerinfovo") CenterInfoVo centerinfovo) throws Exception{
service.insertCenterInfo(centerinfovo);
Map<String, Object> rtnObject = new HashMap<String, Object>();
rtnObject.put("list", service.getCenterInfo_Manage(centerinfovo));
rtnObject.put("param", centerinfovo);
return rtnObject;
}
@RequestMapping("/updateCenterInfo")
public @ResponseBody Map<String , Object> updateCenterInfo(
@ModelAttribute("centerinfovo") CenterInfoVo centerinfovo) throws Exception{
service.updateCenterInfo(centerinfovo);
Map<String, Object> rtnObject = new HashMap<String, Object>();
rtnObject.put("list", service.getCenterInfo_Manage(centerinfovo));
rtnObject.put("param", centerinfovo);
return rtnObject;
}
@RequestMapping("/deleteCenterInfo")
public @ResponseBody Map<String , Object> deleteCenterInfo(
@ModelAttribute("centerinfovo") CenterInfoVo centerinfovo) throws Exception{
service.deleteCenterInfo(centerinfovo);
Map<String, Object> rtnObject = new HashMap<String, Object>();
rtnObject.put("list", service.getCenterInfo_Manage(centerinfovo));
rtnObject.put("param", centerinfovo);
return rtnObject;
}
@RequestMapping("/getUserInfo_Manage")
public @ResponseBody Map<String , Object> getUserInfo_Manage(@ModelAttribute("userinfovo") UserInfoVo userinfovo) throws Exception{
Map<String, Object> rtnObject = new HashMap<String, Object>();
rtnObject.put("list", service.getUserInfo_Manage(userinfovo));
rtnObject.put("param", userinfovo);
return rtnObject;
}
@RequestMapping("/getObjInfo_Manage")
public @ResponseBody Map<String , Object> getObjInfo_Manage(@ModelAttribute("objinfovo") ObjInfoVo objinfovo) throws Exception{
Map<String, Object> rtnObject = new HashMap<String, Object>();
rtnObject.put("list", service.getObjInfo_Manage(objinfovo));
rtnObject.put("param", objinfovo);
return rtnObject;
}
@RequestMapping("/getImageInfo_Manage")
public @ResponseBody Map<String , Object> getImageInfo_Manage(@ModelAttribute("imageinfovo") ImageInfoVo imageinfovo) throws Exception{
Map<String, Object> rtnObject = new HashMap<String, Object>();
rtnObject.put("list", service.getImageInfo_Manage(imageinfovo));
rtnObject.put("param", imageinfovo);
return rtnObject;
}
@RequestMapping("/getComCode")
public @ResponseBody Map<String , Object> getCommCode(@ModelAttribute("commoninfovo") CommonInfoVo commoninfovo) throws Exception{
Map<String, Object> rtnObject = new HashMap<String, Object>();
rtnObject.put("list", service.getCommCode(commoninfovo));
rtnObject.put("param", commoninfovo);
return rtnObject;
}
@RequestMapping("/getImages")
public @ResponseBody Map<String , Object> getImages(@ModelAttribute("imageinfovo") ImageInfoVo imageinfovo) throws Exception{
Map<String, Object> rtnObject = new HashMap<String, Object>();
rtnObject.put("list", service.getImages(imageinfovo));
rtnObject.put("param", imageinfovo);
return rtnObject;
}
@RequestMapping("/saveWallInfo")
public @ResponseBody Map<String , Object> saveWallInfo(
@ModelAttribute("wallinfovo") WallInfoVo wallinfovo) throws Exception{
service.saveWallInfo(wallinfovo);
Map<String, Object> rtnObject = new HashMap<String, Object>();
wallinfovo.setQuery_arry(wallinfovo.getCenter_id().split(","));
rtnObject.put("list", service.getWallInfo_Manage(wallinfovo));
rtnObject.put("param", wallinfovo);
return rtnObject;
}
@ResponseBody
@RequestMapping(value="/ckeditor/ckeditor5ImageUpload", method= {RequestMethod.POST, RequestMethod.GET})
public String ckeditor5ImageUpload(HttpServletRequest request, HttpServletResponse response, @RequestParam MultipartFile upload) throws Exception{
String url = null;
try {
final String uploadDir = "/images/upload";
//final String uploadDir = "D://upload";
final long maxFileSize = 1024 * 1024* 600;
List<FormBasedFileVo> list = FileUploadUtil.uploadFiles(request, uploadDir, maxFileSize);
if(list == null) {
return ("업로드 실패. 에러가 발생했습니다.");
}else {
if(list.size() > 0) {
FormBasedFileVo vo = list.get(0);
url = request.getContextPath() +
"/ckeditor/ckeditor5ImageUpload?" +
"path=" + vo.getServerSubPath() +
"&physical=" + vo.getPhysicalName() +
"&contentType=" + vo.getContentType();
}
return "업로드 성공. " + url + "";
}
}catch(Exception e) {
e.printStackTrace();
}finally {
}
return ("업로드 실패. 에러가 발생했습니다.");
}
}