|
| 1 | +package egovframework.rivalwar.api.directChat.controller; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import javax.servlet.http.HttpServletRequest; |
| 7 | + |
| 8 | +import org.springframework.beans.factory.annotation.Autowired; |
| 9 | +import org.springframework.stereotype.Controller; |
| 10 | +import org.springframework.ui.ModelMap; |
| 11 | +import org.springframework.util.StringUtils; |
| 12 | +import org.springframework.validation.BindingResult; |
| 13 | +import org.springframework.validation.annotation.Validated; |
| 14 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 15 | +import org.springframework.web.bind.annotation.RequestMethod; |
| 16 | +import org.springframework.web.bind.annotation.ResponseBody; |
| 17 | +import org.springframework.web.servlet.ModelAndView; |
| 18 | + |
| 19 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 20 | +import com.google.common.collect.Maps; |
| 21 | + |
| 22 | +import egovframework.com.cmm.annotation.IncludedInfo; |
| 23 | +import egovframework.com.ext.jstree.springiBatis.core.util.Util_TitleChecker; |
| 24 | +import egovframework.com.ext.jstree.springiBatis.core.validation.group.AddNode; |
| 25 | +import egovframework.com.ext.jstree.springiBatis.core.validation.group.AlterNode; |
| 26 | +import egovframework.com.ext.jstree.springiBatis.core.validation.group.AlterNodeType; |
| 27 | +import egovframework.com.ext.jstree.springiBatis.core.validation.group.MoveNode; |
| 28 | +import egovframework.com.ext.jstree.springiBatis.core.validation.group.RemoveNode; |
| 29 | +import egovframework.com.ext.jstree.support.mvc.GenericAbstractController; |
| 30 | +import egovframework.com.ext.jstree.support.util.ParameterParser; |
| 31 | +import egovframework.rivalwar.api.directChat.service.DirectChatService; |
| 32 | +import egovframework.rivalwar.api.directChat.vo.DirectChatDTO; |
| 33 | + |
| 34 | +@Controller |
| 35 | +@RequestMapping(value = {"/rivalWar/api/directChat"}) |
| 36 | +public class DirectChatController extends GenericAbstractController { |
| 37 | + |
| 38 | + @Autowired |
| 39 | + private DirectChatService directChatService; |
| 40 | + |
| 41 | + @IncludedInfo(name = "RivalWar Admin DirectChat", listUrl = "/rivalWar/api/directChat/admin/getJsTreeView.do", order = 7001, gid = 7313) |
| 42 | + @RequestMapping("/admin/getJsTreeView.do") |
| 43 | + public String jsTreeSpringHibernate() { |
| 44 | + return "egovframework/rivalWar/api/directChat/admin/JsTreeView"; |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * 자식노드를 요청한다. |
| 49 | + * |
| 50 | + * @param comprehensiveTree |
| 51 | + * @param model |
| 52 | + * @param request |
| 53 | + * @return String |
| 54 | + * @throws JsonProcessingException |
| 55 | + */ |
| 56 | + @ResponseBody |
| 57 | + @RequestMapping(value = "/getChildDirectChat.do", method = RequestMethod.GET) |
| 58 | + public ModelAndView getChildDirectChat(DirectChatDTO jsTreeHibernateDTO, ModelMap model, HttpServletRequest request) |
| 59 | + throws Exception { |
| 60 | + |
| 61 | + ParameterParser parser = new ParameterParser(request); |
| 62 | + |
| 63 | + if (parser.getInt("c_id") <= 0) { |
| 64 | + throw new RuntimeException(); |
| 65 | + } |
| 66 | + |
| 67 | + jsTreeHibernateDTO.setWhere("c_parentid", new Long(parser.get("c_id"))); |
| 68 | + List<DirectChatDTO> list = directChatService.getChildDirectChat(jsTreeHibernateDTO); |
| 69 | + |
| 70 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 71 | + modelAndView.addObject("result", list); |
| 72 | + return modelAndView; |
| 73 | + } |
| 74 | + |
| 75 | + @ResponseBody |
| 76 | + @RequestMapping(value = "/getPaginatedChildMenu.do", method = RequestMethod.GET) |
| 77 | + public ModelAndView getPaginatedChildMenu(DirectChatDTO jsTreeHibernateDTO, ModelMap model, HttpServletRequest request) |
| 78 | + throws Exception { |
| 79 | + |
| 80 | + if (jsTreeHibernateDTO.getC_id() <= 0 || jsTreeHibernateDTO.getPageIndex() <= 0 |
| 81 | + || jsTreeHibernateDTO.getPageUnit() <= 0 || jsTreeHibernateDTO.getPageSize() <= 0) { |
| 82 | + throw new RuntimeException(); |
| 83 | + } |
| 84 | + |
| 85 | + jsTreeHibernateDTO.setWhere("c_parentid", jsTreeHibernateDTO.getC_id()); |
| 86 | + List<DirectChatDTO> list = directChatService.getPaginatedChildDirectChat(jsTreeHibernateDTO); |
| 87 | + jsTreeHibernateDTO.getPaginationInfo().setTotalRecordCount(list.size()); |
| 88 | + |
| 89 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 90 | + HashMap<String, Object> resultMap = Maps.newHashMap(); |
| 91 | + resultMap.put("paginationInfo", jsTreeHibernateDTO.getPaginationInfo()); |
| 92 | + resultMap.put("result", list); |
| 93 | + modelAndView.addObject("result", resultMap); |
| 94 | + return modelAndView; |
| 95 | + } |
| 96 | + |
| 97 | + @ResponseBody |
| 98 | + @RequestMapping(value = "/getDirectChat.do", method = RequestMethod.GET) |
| 99 | + public ModelAndView getDirectChat(DirectChatDTO jsTreeHibernateDTO, ModelMap model, HttpServletRequest request) |
| 100 | + throws Exception { |
| 101 | + |
| 102 | + ParameterParser parser = new ParameterParser(request); |
| 103 | + |
| 104 | + if (parser.getInt("c_id") <= 0) { |
| 105 | + throw new RuntimeException(); |
| 106 | + } |
| 107 | + |
| 108 | + DirectChatDTO directChatDTO = directChatService.getDirectChat(jsTreeHibernateDTO); |
| 109 | + |
| 110 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 111 | + modelAndView.addObject("result", directChatDTO); |
| 112 | + return modelAndView; |
| 113 | + } |
| 114 | + |
| 115 | + /** |
| 116 | + * 노드를 검색한다. |
| 117 | + * |
| 118 | + * @param comprehensiveTree |
| 119 | + * @param model |
| 120 | + * @param request |
| 121 | + * @return |
| 122 | + * @throws JsonProcessingException |
| 123 | + */ |
| 124 | + @ResponseBody |
| 125 | + @RequestMapping(value = "/searchDirectChat.do", method = RequestMethod.GET) |
| 126 | + public ModelAndView searchNode(DirectChatDTO jsTreeHibernateDTO, ModelMap model, HttpServletRequest request) |
| 127 | + throws Exception { |
| 128 | + |
| 129 | + ParameterParser parser = new ParameterParser(request); |
| 130 | + |
| 131 | + if (!StringUtils.hasText(request.getParameter("searchString"))) { |
| 132 | + throw new RuntimeException(); |
| 133 | + } |
| 134 | + |
| 135 | + jsTreeHibernateDTO.setWhereLike("c_title", parser.get("parser")); |
| 136 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 137 | + modelAndView.addObject("result", directChatService.searchDirectChat(jsTreeHibernateDTO)); |
| 138 | + return modelAndView; |
| 139 | + } |
| 140 | + |
| 141 | + /** |
| 142 | + * 노드를 추가한다. |
| 143 | + * |
| 144 | + * @param comprehensiveTree |
| 145 | + * @param model |
| 146 | + * @param request |
| 147 | + * @return |
| 148 | + * @throws JsonProcessingException |
| 149 | + * @throws IllegalAccessException |
| 150 | + * @throws InstantiationException |
| 151 | + */ |
| 152 | + @ResponseBody |
| 153 | + @RequestMapping(value = "/addDirectChat.do", method = RequestMethod.POST) |
| 154 | + public ModelAndView addDirectChat(@Validated(value = AddNode.class) DirectChatDTO jsTreeHibernateDTO, |
| 155 | + BindingResult bindingResult, ModelMap model) throws Exception { |
| 156 | + if (bindingResult.hasErrors()) |
| 157 | + throw new RuntimeException(); |
| 158 | + |
| 159 | + jsTreeHibernateDTO.setC_title(Util_TitleChecker.StringReplace(jsTreeHibernateDTO.getC_title())); |
| 160 | + |
| 161 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 162 | + modelAndView.addObject("result", directChatService.addDirectChat(jsTreeHibernateDTO)); |
| 163 | + return modelAndView; |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * 노드를 삭제한다. |
| 168 | + * |
| 169 | + * @param comprehensiveTree |
| 170 | + * @param model |
| 171 | + * @param request |
| 172 | + * @return |
| 173 | + * @throws JsonProcessingException |
| 174 | + */ |
| 175 | + @ResponseBody |
| 176 | + @RequestMapping(value = "/removeDirectChat.do", method = RequestMethod.POST) |
| 177 | + public ModelAndView removeNode(@Validated(value = RemoveNode.class) DirectChatDTO jsTreeHibernateDTO, |
| 178 | + BindingResult bindingResult, ModelMap model) throws Exception { |
| 179 | + if (bindingResult.hasErrors()) |
| 180 | + throw new RuntimeException(); |
| 181 | + |
| 182 | + jsTreeHibernateDTO.setStatus(directChatService.removeDirectChat(jsTreeHibernateDTO)); |
| 183 | + setJsonDefaultSetting(jsTreeHibernateDTO); |
| 184 | + |
| 185 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 186 | + modelAndView.addObject("result", jsTreeHibernateDTO); |
| 187 | + return modelAndView; |
| 188 | + } |
| 189 | + |
| 190 | + private void setJsonDefaultSetting(DirectChatDTO jsTreeHibernateDTO) { |
| 191 | + long defaultSettingValue = 0; |
| 192 | + jsTreeHibernateDTO.setC_parentid(defaultSettingValue); |
| 193 | + jsTreeHibernateDTO.setC_position(defaultSettingValue); |
| 194 | + jsTreeHibernateDTO.setC_left(defaultSettingValue); |
| 195 | + jsTreeHibernateDTO.setC_right(defaultSettingValue); |
| 196 | + jsTreeHibernateDTO.setC_level(defaultSettingValue); |
| 197 | + jsTreeHibernateDTO.setRef(defaultSettingValue); |
| 198 | + } |
| 199 | + |
| 200 | + /** |
| 201 | + * 노드를 변경한다. |
| 202 | + * |
| 203 | + * @param comprehensiveTree |
| 204 | + * @param model |
| 205 | + * @param request |
| 206 | + * @return |
| 207 | + * @throws JsonProcessingException |
| 208 | + */ |
| 209 | + @ResponseBody |
| 210 | + @RequestMapping(value = "/alterDirectChat.do", method = RequestMethod.POST) |
| 211 | + public ModelAndView alterNode(@Validated(value = AlterNode.class) DirectChatDTO jsTreeHibernateDTO, |
| 212 | + BindingResult bindingResult, ModelMap model) throws Exception { |
| 213 | + if (bindingResult.hasErrors()) |
| 214 | + throw new RuntimeException(); |
| 215 | + |
| 216 | + jsTreeHibernateDTO.setC_title(Util_TitleChecker.StringReplace(jsTreeHibernateDTO.getC_title())); |
| 217 | + |
| 218 | + jsTreeHibernateDTO.setStatus(directChatService.alterDirectChat(jsTreeHibernateDTO)); |
| 219 | + setJsonDefaultSetting(jsTreeHibernateDTO); |
| 220 | + |
| 221 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 222 | + modelAndView.addObject("result", jsTreeHibernateDTO); |
| 223 | + return modelAndView; |
| 224 | + } |
| 225 | + |
| 226 | + /** |
| 227 | + * 노드의 타입을 변경한다. |
| 228 | + * |
| 229 | + * @param comprehensiveTree |
| 230 | + * @param model |
| 231 | + * @param request |
| 232 | + * @return |
| 233 | + * @throws JsonProcessingException |
| 234 | + */ |
| 235 | + @ResponseBody |
| 236 | + @RequestMapping(value = "/alterNodeDirectChat.do", method = RequestMethod.POST) |
| 237 | + public ModelAndView alterNodeType(@Validated(value = AlterNodeType.class) DirectChatDTO jsTreeHibernateDTO, |
| 238 | + BindingResult bindingResult, ModelMap model) throws Exception { |
| 239 | + if (bindingResult.hasErrors()) |
| 240 | + throw new RuntimeException(); |
| 241 | + |
| 242 | + directChatService.alterDirectChatType(jsTreeHibernateDTO); |
| 243 | + setJsonDefaultSetting(jsTreeHibernateDTO); |
| 244 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 245 | + modelAndView.addObject("result", jsTreeHibernateDTO); |
| 246 | + return modelAndView; |
| 247 | + } |
| 248 | + |
| 249 | + /** |
| 250 | + * 노드를 이동한다. |
| 251 | + * |
| 252 | + * @param comprehensiveTree |
| 253 | + * @param model |
| 254 | + * @param request |
| 255 | + * @return |
| 256 | + * @throws JsonProcessingException |
| 257 | + * @throws ReflectiveOperationException |
| 258 | + * @throws IllegalAccessException |
| 259 | + * @throws InstantiationException |
| 260 | + */ |
| 261 | + @ResponseBody |
| 262 | + @RequestMapping(value = "/moveDirectChat.do", method = RequestMethod.POST) |
| 263 | + public ModelAndView moveNode(@Validated(value = MoveNode.class) DirectChatDTO jsTreeHibernateDTO, |
| 264 | + BindingResult bindingResult, ModelMap model, HttpServletRequest request) throws Exception { |
| 265 | + if (bindingResult.hasErrors()) |
| 266 | + throw new RuntimeException(); |
| 267 | + |
| 268 | + directChatService.moveDirectChat(jsTreeHibernateDTO, request); |
| 269 | + setJsonDefaultSetting(jsTreeHibernateDTO); |
| 270 | + |
| 271 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 272 | + modelAndView.addObject("result", jsTreeHibernateDTO); |
| 273 | + return modelAndView; |
| 274 | + } |
| 275 | + |
| 276 | + @ResponseBody |
| 277 | + @RequestMapping(value = "/analyzeDirectChat.do", method = RequestMethod.GET) |
| 278 | + public ModelAndView getChildNode(ModelMap model) { |
| 279 | + model.addAttribute("analyzeResult", ""); |
| 280 | + |
| 281 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 282 | + modelAndView.addObject("result", "ture"); |
| 283 | + return modelAndView; |
| 284 | + } |
| 285 | +} |
0 commit comments