package com.nis.web.controller; import java.net.URLDecoder; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.nis.domain.SysMenu; import com.nis.domain.configuration.HelpInfo; import com.nis.util.LogUtils; import com.nis.util.StringUtil; import com.nis.util.StringUtils; import com.nis.web.security.UserUtils; import com.nis.web.service.configuration.HelpInfoService; @Controller @RequestMapping("${adminPath}/sys/") public class SystemController extends BaseController{ @Autowired private HelpInfoService helpService; @RequestMapping("index") public String index(HttpServletRequest request, HttpServletResponse response,ModelMap model){ return "/sys/sysIndex"; } @RequestMapping("help") public String help(HttpServletRequest request, HttpServletResponse response,ModelMap model){ List menuList = UserUtils.getMenuTreeList(); List newList = new ArrayList(); try { for(SysMenu menu:menuList){ if(menu.getIsTop()==1 && !StringUtil.isEmpty(menu.getChildren())){ boolean topShow = false; for(SysMenu second:menu.getChildren()){ boolean secondShow = false; if(second.getIsShow()==1){ if(!StringUtil.isEmpty(second.getMenuBg())){ secondShow = true; } if(!StringUtil.isEmpty(second.getChildren())){ for(SysMenu third:second.getChildren()){ boolean thirdShow = false; if(third.getIsShow()==1){ if(!StringUtil.isEmpty(third.getMenuBg())){ thirdShow = true; secondShow = true; } if(!StringUtil.isEmpty(third.getChildren())){ for(SysMenu fourth:third.getChildren()){ if(!StringUtil.isEmpty(fourth.getMenuBg())&&fourth.getIsShow()==1){ newList.add(fourth); thirdShow = true; secondShow = true; } } } } if(thirdShow){ newList.add(third); } } } if(secondShow){ newList.add(second); topShow = true; } } } if(topShow){ newList.add(menu); } } /*if(menu.getChildren()!=null && menu.getChildren().size()>0 && menu.getIsShow()==1){ newList.add(menu); }else if(menu.getMenuBg()!=null && !"".equals(menu.getMenuBg())){ newList.add(menu); }else if(menu.getId()==1){ newList.add(menu); }*/ /*if((menu.getParentIds().startsWith("0,1,86,") || menu.getId()==86 ||menu.getId()==0 ||menu.getId()==1) && menu.getIsShow()==1 ){ System.out.println(menu.getParentIds()); newList.add(menu); }*/ //将帮助文档缓存到redis helpService.cacheAllHelpInfo(); } } catch (Exception e) { logger.error("help error",e); LogUtils.saveLog(request, null, e, null); } logger.info("menuSize:"+newList.size()); model.addAttribute("menuList",newList); return "/help"; } /** * @param request * @param response * @param model * @param editedHelpInfo 修改之后的帮助文档内容 * @param helpHrefVal 文档的路径 * @return */ @RequestMapping("saveHelp") @ResponseBody public boolean saveHelp(HttpServletRequest request, HttpServletResponse response,ModelMap model,@RequestParam(required=true,value="editedHelpInfo")String editedHelpInfo,@RequestParam(required=true,value="helpHrefVal")String helpHrefVal){ if(StringUtils.strIsBlank(helpHrefVal)){ return false; } try { StringBuffer helpInfoText=new StringBuffer(); //修改之后的内容 helpInfoText.append(URLDecoder.decode(editedHelpInfo,"utf-8")); String helpHref=URLDecoder.decode(helpHrefVal,"utf-8"); String[] split = StringUtils.split(helpHref, "/"); if(split!=null&&split.length>0){ HelpInfo helpInfo = new HelpInfo(); helpInfo.setFileComment(helpInfoText.toString()); helpInfo.setFileName(split[split.length-1]); helpService.saveHelpInfo(helpInfo); return true; } } catch (Exception e) { logger.error("save helpInfo error",e); LogUtils.saveLog(request, null, e, null); } return false; } /** * 查看帮助文档内容 * @param request * @param response * @param model * @param helpHref * @return */ @RequestMapping("viewHelp") @ResponseBody public HelpInfo viewHelp(HttpServletRequest request, HttpServletResponse response,ModelMap model,@RequestParam(required=true,value="helpHref")String helpHref){ if(StringUtils.strIsBlank(helpHref)){ return null; } try { helpHref=URLDecoder.decode(helpHref,"utf-8"); String[] split = StringUtils.split(helpHref, "/"); if(split!=null&&split.length>0){ HelpInfo helpInfo = helpService.findHelpCommentByName(split[split.length-1]); return helpInfo; } } catch (Exception e) { logger.error("view helpInfo error",e); LogUtils.saveLog(request, null, e, null); } return null; } /** * 查看帮助文档备份内容 * @param request * @param response * @param model * @param helpHref * @return */ @RequestMapping("viewBakHelp") @ResponseBody public HelpInfo viewBakHelp(HttpServletRequest request, HttpServletResponse response,ModelMap model,@RequestParam(required=true,value="helpHref")String helpHref){ if(StringUtils.strIsBlank(helpHref)){ return null; } try { helpHref=URLDecoder.decode(helpHref,"utf-8"); String[] split = StringUtils.split(helpHref, "/"); if(split!=null&&split.length>0){ HelpInfo helpInfo = helpService.findHelpBakCommentByName(split[split.length-1]); return helpInfo; } } catch (Exception e) { logger.error("view helpBakInfo error",e); LogUtils.saveLog(request, null, e, null); } return null; } @RequestMapping("clearPolicies") @ResponseBody public boolean clearPolicies(HttpServletRequest request, HttpServletResponse response) { try { systemService.clearPolicies(); return true; } catch (Exception e) { logger.error("Clear Policies Error",e); LogUtils.saveLog(request, null, e, null); } return false; } }