MainController.java 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. package com.tsi.sig.server.controller;
  2. import com.tsi.sig.server.objects.UserVO;
  3. import com.tsi.sig.server.service.MainService;
  4. import com.tsi.sig.server.vo.*;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.security.core.context.SecurityContext;
  7. import org.springframework.security.core.context.SecurityContextHolder;
  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.ui.Model;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestMethod;
  12. import org.springframework.web.bind.annotation.RequestParam;
  13. import org.springframework.web.bind.annotation.ResponseBody;
  14. import javax.naming.AuthenticationException;
  15. import javax.servlet.http.HttpServletRequest;
  16. import javax.servlet.http.HttpServletResponse;
  17. import javax.servlet.http.HttpSession;
  18. import java.util.*;
  19. @Slf4j
  20. @Controller
  21. public class MainController {
  22. private final MainService mainService;
  23. public MainController(MainService mainService) {
  24. this.mainService = mainService;
  25. }
  26. // @RequestMapping(value="/login.do")
  27. // public String page() throws Exception {
  28. // System.out.println("=======================================login.do====================");
  29. // return "login";
  30. // }
  31. @RequestMapping(value="/error.do")
  32. public String error() throws Exception{
  33. //log.info("CALL.........................................: error");
  34. return "error";
  35. }
  36. // @RequestMapping(value = "/main.do")
  37. // public String main() throws Exception {
  38. // //log.info("CALL.........................................: main");
  39. // return "main";
  40. // }
  41. @RequestMapping({"/main.do"})
  42. public String main(HttpServletRequest request, HttpServletResponse response) throws Exception {
  43. HttpSession session = request.getSession();
  44. SecurityContext member = (SecurityContext)session.getAttribute("SPRING_SECURITY_CONTEXT");
  45. return member == null ? "login" : "main";
  46. }
  47. @RequestMapping({"/refreshNodeList.do"})
  48. @ResponseBody
  49. public ResultVo refreshNodeList(HttpServletRequest request, HttpServletResponse response) throws Exception {
  50. return mainService.refreshNodeList();
  51. }
  52. @RequestMapping({"/userEdit.do"})
  53. public String userEdit() throws Exception {
  54. return "userEdit";
  55. }
  56. @RequestMapping(value = "/getBottomListFrame.do")
  57. public String getBottomListFrame() throws Exception {
  58. //log.info("CALL.........................................: getBottomListFrame");
  59. return "bottomListFrame";
  60. }
  61. @RequestMapping(value = "/getTreeListFrame.do")
  62. public String getTreeListFrame(Locale locale, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
  63. //log.info("CALL.........................................: getTreeListFrame");
  64. return "treeListFrame";
  65. }
  66. @RequestMapping(value = "/getIntTreeList.do", method = RequestMethod.POST)
  67. public @ResponseBody
  68. List<CvibNodeVO> getIntTreeList(Locale locale, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
  69. //log.info("CALL.........................................: getIntTreeList");
  70. List<CvibNodeVO> nodes = mainService.getLodeList();
  71. //log.info("getIntTreeList: {}", nodes.toString());
  72. return nodes;
  73. }
  74. @RequestMapping(value = "/getSignalInfo.do", method = RequestMethod.POST)
  75. public @ResponseBody
  76. List<CvibNodeVO> getSignalInfo(@RequestParam Map<String,String> paramMap, HttpServletResponse response) throws Exception {
  77. //log.info("CALL.........................................: getSignalInfo");
  78. /*
  79. //log.info("minX: {}", request.getParameter("minX"));
  80. //log.info("minY: {}", request.getParameter("minY"));
  81. //log.info("maxX: {}", request.getParameter("maxX"));
  82. //log.info("maxY: {}", request.getParameter("maxY"));
  83. */
  84. // HashMap<String, Object> paramMap = new HashMap<String, Object>();
  85. // paramMap.put("minX", CommonUtil.checkNull(request.getParameter("minX")));
  86. // paramMap.put("minY", CommonUtil.checkNull(request.getParameter("minY")));
  87. // paramMap.put("maxX", CommonUtil.checkNull(request.getParameter("maxX")));
  88. // paramMap.put("maxY", CommonUtil.checkNull(request.getParameter("maxY")));
  89. // List<CvibNodeVO> nodes = mainService.getCvibMapNodeList(paramMap);
  90. List<CvibNodeVO> nodes = mainService.getRegionList(paramMap);
  91. //log.info("{} EA. {}", nodes.size(), nodes.toString());
  92. response.setContentType("application/json; charset=UTF-8");
  93. return nodes;
  94. }
  95. @RequestMapping(value = "/cvibInfoDetail.do", method = RequestMethod.GET)
  96. public String cvibInfoDetail(@RequestParam("nodeId") String nodeId, Model model, HttpServletRequest request, HttpServletResponse response) throws Exception {
  97. //log.info("CALL.........................................: cvibInfoDetail");
  98. model.addAttribute("nodeId", nodeId);
  99. HashMap<String, Object> paramMap = new HashMap<String, Object>();
  100. paramMap.put("nodeId", nodeId);
  101. List<CvibNodeVO> nodes = mainService.getCvibNodeInfo(paramMap);
  102. CvibNodeVO node = null;
  103. if (nodes != null && nodes.size() > 0) {
  104. node = nodes.get(0);
  105. }
  106. model.addAttribute("node", node);
  107. return "cvibInfoDetail";
  108. }
  109. @RequestMapping(value = "/getCvibList.do", method = RequestMethod.POST)
  110. @ResponseBody
  111. // public List<CvibNodeStatusVo> cvibInfoList(@RequestParam Map<String, String> paramMap) throws Exception {
  112. public Map<String,List<?>> cvibInfoList(@RequestParam Map<String, String> paramMap) throws Exception {
  113. Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  114. if (principal != null && principal != "anonymousUser") {
  115. UserVO user = (UserVO)principal;
  116. String[] test = new String[]{"I", "B", "N", "M", "S"};
  117. List<String> strList = new ArrayList<>(Arrays.asList(test));
  118. if ( strList.contains(user.getUserGrade())) {
  119. return mainService.getCvibNodeStatusList(paramMap);
  120. }
  121. else {
  122. throw new AuthenticationException("사용자 권한을 확인해주세요ㅕ.");
  123. }
  124. }
  125. throw new AuthenticationException("로그인 하지않고 API 를 사용할 수 없습니다.");
  126. }
  127. @RequestMapping(value = "/getCvibDetail.do", method = RequestMethod.POST)
  128. @ResponseBody
  129. public CvibNodeStatusVo getCvibDetail(String nodeId) throws Exception {
  130. return mainService.getCvibNodeDetail(nodeId);
  131. }
  132. @RequestMapping(value = "/getEvpServiceList.do", method = RequestMethod.POST)
  133. @ResponseBody
  134. public List<EvpServiceVo> getEvpServiceList() throws Exception {
  135. return mainService.getEvpServiceList();
  136. }
  137. @RequestMapping(value = "/getEvpRouteList.do", method = RequestMethod.POST)
  138. @ResponseBody
  139. public List<EvpRouteVo> getEvpRouteList(@RequestParam HashMap<String,Object> paramMap) throws Exception {
  140. return mainService.getEvpRouteList(paramMap);
  141. }
  142. @RequestMapping(value = "/getEvpHistory.do", method = RequestMethod.POST)
  143. @ResponseBody
  144. public List<EvpServiceVo> getEvpHistory(@RequestParam HashMap<String,Object> paramMap) throws Exception {
  145. return mainService.getEvpHistoryList(paramMap);
  146. }
  147. }