|
| 1 | +package egovframework.api.rivalWar.menuCompareItem.controller; |
| 2 | + |
| 3 | +import com.fasterxml.jackson.core.JsonProcessingException; |
| 4 | +import egovframework.api.rivalWar.menuCompareItem.service.MenuCompareItemService; |
| 5 | +import egovframework.api.rivalWar.menuCompareItem.vo.MenuCompareItemDTO; |
| 6 | +import egovframework.com.ext.jstree.springiBatis.core.util.Util_TitleChecker; |
| 7 | +import egovframework.com.ext.jstree.springiBatis.core.validation.group.*; |
| 8 | +import egovframework.com.ext.jstree.support.mvc.GenericAbstractController; |
| 9 | +import org.slf4j.Logger; |
| 10 | +import org.slf4j.LoggerFactory; |
| 11 | +import org.springframework.beans.factory.annotation.Autowired; |
| 12 | +import org.springframework.stereotype.Controller; |
| 13 | +import org.springframework.ui.ModelMap; |
| 14 | +import org.springframework.validation.BindingResult; |
| 15 | +import org.springframework.validation.annotation.Validated; |
| 16 | +import org.springframework.web.bind.annotation.RequestMapping; |
| 17 | +import org.springframework.web.bind.annotation.RequestMethod; |
| 18 | +import org.springframework.web.bind.annotation.ResponseBody; |
| 19 | +import org.springframework.web.servlet.ModelAndView; |
| 20 | + |
| 21 | +import javax.servlet.http.HttpServletRequest; |
| 22 | + |
| 23 | +/** |
| 24 | + * Created by Administrator on 2017-10-23. |
| 25 | + */ |
| 26 | +@Controller |
| 27 | +@RequestMapping(value = {"/api/rivalWar/ROLE_ADMIN/menuCompareItem"}) |
| 28 | +public class AdminMenuCompareItemController extends GenericAbstractController { |
| 29 | + |
| 30 | + @Autowired |
| 31 | + private MenuCompareItemService menuCompareItemService; |
| 32 | + |
| 33 | + private final Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 34 | + |
| 35 | + /** |
| 36 | + * 노드를 추가한다. |
| 37 | + * |
| 38 | + * @param jsTreeHibernateDTO |
| 39 | + * @param model |
| 40 | + * @param bindingResult |
| 41 | + * @return |
| 42 | + * @throws JsonProcessingException |
| 43 | + * @throws IllegalAccessException |
| 44 | + * @throws InstantiationException |
| 45 | + */ |
| 46 | + @ResponseBody |
| 47 | + @RequestMapping(value = "/addNode.do", method = RequestMethod.POST) |
| 48 | + public ModelAndView addNode(@Validated(value = AddNode.class) MenuCompareItemDTO jsTreeHibernateDTO, |
| 49 | + BindingResult bindingResult, ModelMap model) throws Exception { |
| 50 | + if (bindingResult.hasErrors()) |
| 51 | + throw new RuntimeException(); |
| 52 | + |
| 53 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 54 | + modelAndView.addObject("result", menuCompareItemService.addNode(jsTreeHibernateDTO)); |
| 55 | + return modelAndView; |
| 56 | + } |
| 57 | + |
| 58 | + /** |
| 59 | + * 노드를 삭제한다. |
| 60 | + * |
| 61 | + * @param jsTreeHibernateDTO |
| 62 | + * @param model |
| 63 | + * @param bindingResult |
| 64 | + * @return |
| 65 | + * @throws JsonProcessingException |
| 66 | + */ |
| 67 | + @ResponseBody |
| 68 | + @RequestMapping(value = "/removeNode.do", method = RequestMethod.POST) |
| 69 | + public ModelAndView removeNode(@Validated(value = RemoveNode.class) MenuCompareItemDTO jsTreeHibernateDTO, |
| 70 | + BindingResult bindingResult, ModelMap model) throws Exception { |
| 71 | + if (bindingResult.hasErrors()) |
| 72 | + throw new RuntimeException(); |
| 73 | + |
| 74 | + jsTreeHibernateDTO.setStatus(menuCompareItemService.removeNode(jsTreeHibernateDTO)); |
| 75 | + setJsonDefaultSetting(jsTreeHibernateDTO); |
| 76 | + |
| 77 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 78 | + modelAndView.addObject("result", jsTreeHibernateDTO); |
| 79 | + return modelAndView; |
| 80 | + } |
| 81 | + |
| 82 | + private void setJsonDefaultSetting(MenuCompareItemDTO jsTreeHibernateDTO) { |
| 83 | + long defaultSettingValue = 0; |
| 84 | + jsTreeHibernateDTO.setC_parentid(defaultSettingValue); |
| 85 | + jsTreeHibernateDTO.setC_position(defaultSettingValue); |
| 86 | + jsTreeHibernateDTO.setC_left(defaultSettingValue); |
| 87 | + jsTreeHibernateDTO.setC_right(defaultSettingValue); |
| 88 | + jsTreeHibernateDTO.setC_level(defaultSettingValue); |
| 89 | + jsTreeHibernateDTO.setRef(defaultSettingValue); |
| 90 | + } |
| 91 | + |
| 92 | + /** |
| 93 | + * 노드를 변경한다. |
| 94 | + * |
| 95 | + * @param jsTreeHibernateDTO |
| 96 | + * @param model |
| 97 | + * @param bindingResult |
| 98 | + * @return |
| 99 | + * @throws JsonProcessingException |
| 100 | + */ |
| 101 | + @ResponseBody |
| 102 | + @RequestMapping(value = "/alterNode.do", method = RequestMethod.POST) |
| 103 | + public ModelAndView alterNode(@Validated(value = AlterNode.class) MenuCompareItemDTO jsTreeHibernateDTO, |
| 104 | + BindingResult bindingResult, ModelMap model) throws Exception { |
| 105 | + if (bindingResult.hasErrors()){ |
| 106 | + throw new RuntimeException(); |
| 107 | + } |
| 108 | + |
| 109 | + jsTreeHibernateDTO.setC_title(Util_TitleChecker.StringReplace(jsTreeHibernateDTO.getC_title())); |
| 110 | + |
| 111 | + jsTreeHibernateDTO.setStatus(menuCompareItemService.alterNode(jsTreeHibernateDTO)); |
| 112 | + setJsonDefaultSetting(jsTreeHibernateDTO); |
| 113 | + |
| 114 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 115 | + modelAndView.addObject("result", jsTreeHibernateDTO); |
| 116 | + return modelAndView; |
| 117 | + } |
| 118 | + |
| 119 | + |
| 120 | + /** |
| 121 | + * 노드의 타입을 변경한다. |
| 122 | + * |
| 123 | + * @param jsTreeHibernateDTO |
| 124 | + * @param model |
| 125 | + * @param bindingResult |
| 126 | + * @return |
| 127 | + * @throws JsonProcessingException |
| 128 | + */ |
| 129 | + @ResponseBody |
| 130 | + @RequestMapping(value = "/alterNodeType.do", method = RequestMethod.POST) |
| 131 | + public ModelAndView alterNodeType(@Validated(value = AlterNodeType.class) MenuCompareItemDTO jsTreeHibernateDTO, |
| 132 | + BindingResult bindingResult, ModelMap model) throws Exception { |
| 133 | + if (bindingResult.hasErrors()) |
| 134 | + throw new RuntimeException(); |
| 135 | + |
| 136 | + menuCompareItemService.alterNodeType(jsTreeHibernateDTO); |
| 137 | + setJsonDefaultSetting(jsTreeHibernateDTO); |
| 138 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 139 | + modelAndView.addObject("result", jsTreeHibernateDTO); |
| 140 | + return modelAndView; |
| 141 | + } |
| 142 | + |
| 143 | + /** |
| 144 | + * 노드를 이동한다. |
| 145 | + * |
| 146 | + * @param jsTreeHibernateDTO |
| 147 | + * @param model |
| 148 | + * @param request |
| 149 | + * @return |
| 150 | + * @throws JsonProcessingException |
| 151 | + * @throws ReflectiveOperationException |
| 152 | + * @throws IllegalAccessException |
| 153 | + * @throws InstantiationException |
| 154 | + */ |
| 155 | + @ResponseBody |
| 156 | + @RequestMapping(value = "/moveMenu.do", method = RequestMethod.POST) |
| 157 | + public ModelAndView moveNode(@Validated(value = MoveNode.class) MenuCompareItemDTO jsTreeHibernateDTO, |
| 158 | + BindingResult bindingResult, ModelMap model, HttpServletRequest request) throws Exception { |
| 159 | + if (bindingResult.hasErrors()) { |
| 160 | + throw new RuntimeException(); |
| 161 | + } |
| 162 | + menuCompareItemService.moveNode(jsTreeHibernateDTO, request); |
| 163 | + setJsonDefaultSetting(jsTreeHibernateDTO); |
| 164 | + |
| 165 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 166 | + modelAndView.addObject("result", jsTreeHibernateDTO); |
| 167 | + return modelAndView; |
| 168 | + } |
| 169 | + |
| 170 | + @ResponseBody |
| 171 | + @RequestMapping(value = "/analyzeNode.do", method = RequestMethod.GET) |
| 172 | + public ModelAndView getChildNode(ModelMap model) { |
| 173 | + model.addAttribute("analyzeResult", ""); |
| 174 | + |
| 175 | + ModelAndView modelAndView = new ModelAndView("jsonView"); |
| 176 | + modelAndView.addObject("result", "true"); |
| 177 | + return modelAndView; |
| 178 | + }} |
0 commit comments