package com.lemon.lifecenter.common; import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.servlet.ModelAndView; import com.lemon.lifecenter.dto.RoleDTO; import com.lemon.lifecenter.service.RoleService; public class LifeCenterController { @Autowired private RoleService roleService; public ModelAndView setMV(String viewPath) { HashMap hashMap = new HashMap(); HashMap roleMap = new HashMap(); HttpServletRequest request = getRequest(); ModelAndView mv = new ModelAndView(); String url = request.getRequestURI().toString(); String[] split = url.split("/"); String pathType = ""; String pathType2 = ""; if (split.length > 0) { pathType = split[1].toLowerCase(); } if (split.length > 1) { pathType2 = split[2].toLowerCase(); } hashMap.put("_TITLE", "생활치료센터 의료진 시스템"); hashMap.put("_INCLUDE", "/WEB-INF/jsp/include"); hashMap.put("_MENUPATH", pathType); hashMap.put("_MENUPATH2", pathType2); try { String sesId = LifeCenterSessionController.getSession( request, "sesId" ); String sesName = LifeCenterSessionController.getSession( request, "sesName" ); String sesCenterCode = LifeCenterSessionController.getSession( request, "sesCenterCode" ); String sesCenterName = LifeCenterSessionController.getSession( request, "sesCenterName" ); String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" ); hashMap.put( "_SES_ID", sesId ); hashMap.put( "_SES_NAME", sesName ); hashMap.put( "_SES_CENTER_CODE", sesCenterCode ); hashMap.put( "_SES_CENTER_NAME", sesCenterName ); hashMap.put( "_SES_GROUP_IDX", sesGroupIdx ); } catch (NullPointerException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } /* * 현재 메뉴에대한 권한 (C, R, U, D) 리턴 -> View 페이지에서 CRUD 권한에 따른 각각의 버튼 show, hide 제어 하기 위함 */ RoleDTO roleDTO = new RoleDTO(); roleDTO.setMenuPath( url ); int roleCount = roleService.selectNowPathRoleCheckTotal( roleDTO ); // roleCount가 0인경우는 권한체크하지않음 권한체크가 필요한 경로는 sys_menu_list에 등록 필수 if( roleCount > 0 ) { String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" ); roleDTO.setGroupIdx( Integer.valueOf( sesGroupIdx.toString() ) ); roleDTO = roleService.selectNowPathRoleCheckData( roleDTO ); roleMap.put( "_CREATE", roleDTO.getCreateYn() ); roleMap.put( "_READ", roleDTO.getReadYn() ); roleMap.put( "_UPDATE", roleDTO.getUpdateYn() ); roleMap.put( "_DELETE", roleDTO.getDeleteYn() ); } mv.addObject( "role", roleMap ); mv.addObject( "data", hashMap ); mv.setViewName( viewPath ); return mv; } public ModelAndView setMobileMV(String viewPath) { HashMap hashMap = new HashMap(); HttpServletRequest request = getRequest(); ModelAndView mv = new ModelAndView(); String url = request.getRequestURI().toString(); String[] split = url.split("/"); String pathType = ""; String deviceType = ""; if (split.length > 0) { deviceType = split[1].toLowerCase(); if (split.length > 1) { pathType = split[2].toLowerCase(); } } hashMap.put("_TITLE", "생활치료센터"); hashMap.put("_INCLUDE", "/WEB-INF/jsp/" + deviceType + "/include"); hashMap.put("_MENUPATH", pathType); // try { // String sesId = LifeCenterSessionController.getSession( request, "sesId" ); // String sesName = LifeCenterSessionController.getSession( request, "sesName" ); // String sesCenterCode = LifeCenterSessionController.getSession( request, "sesCenterCode" ); // String sesGroupIdx = LifeCenterSessionController.getSession( request, "sesGroupIdx" ); // // hashMap.put( "_SES_ID", sesId ); // hashMap.put( "_SES_NAME", sesName ); // hashMap.put( "_SES_CENTER_CODE", sesCenterCode ); // hashMap.put( "_SES_GROUP_IDX", sesGroupIdx ); // // } catch (NullPointerException e) { // e.printStackTrace(); // // } catch (Exception e) { // e.printStackTrace(); // // } // mv.addObject( "data", hashMap ); mv.setViewName( deviceType + "/" + viewPath ); return mv; } public HttpServletRequest getRequest() { ServletRequestAttributes servletRequestAttribute = (ServletRequestAttributes) RequestContextHolder .currentRequestAttributes(); return servletRequestAttribute.getRequest(); } }