package com.ld.igds.web; import com.bstek.bdf2.core.business.IDept; import com.bstek.bdf2.core.business.IUser; import com.bstek.bdf2.core.model.DefaultCompany; import com.bstek.bdf2.core.model.DefaultDept; import com.ld.igds.common.CoreCommonService; import com.ld.igds.constant.BizType; import com.ld.igds.constant.Constant; import com.ld.igds.data.Menu; import com.ld.igds.models.DicSysConf; import com.ld.igds.sys.service.SysCompanyService; import com.ld.igds.sys.service.SysDeptService; import com.ld.igds.sys.service.SystemService; import com.ld.igds.util.ContextUtil; import com.ld.igds.util.FilesUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.servlet.ModelAndView; import java.util.List; /** * 系统总控制层,包括登录,登出等 * * @author Andy */ @Controller @RequestMapping public class WebController { @Autowired private SysCompanyService companyService; @Autowired private SystemService systemService; @Autowired private SysDeptService sysDeptService; @Autowired private CoreCommonService coreCommonService; /** * 跳转不同页面 * * @return */ @RequestMapping("/index-gateway") public String indexGateway() { //获取当前用户的部门 IUser user = ContextUtil.getLoginUser(); DefaultDept defaultDept = sysDeptService.loadUserDept(user.getUsername()); if (Constant.DEPT_TYPE_10.equals(defaultDept.getType())) { return "redirect:home-group"; } DefaultCompany company = companyService.getCompany(user.getCompanyId()); if (!"all".equals(company.getModel())) { return "redirect:home?t=" + company.getModel(); } return "redirect:index"; } /** * 首页 * * @return */ @RequestMapping("/index") public ModelAndView index(@RequestParam(value = "g", required = false) String groupTag) { ModelAndView view = new ModelAndView(); IUser user = ContextUtil.getLoginUser(); String companyId = user.getCompanyId(); view.addObject(Constant.MODEL_KEY_LOGIN_USER, user); // 设置logo String logName = FilesUtil.getLogoTitleByCompanyId(companyId); view.addObject("logoTitle", "./static/img/" + logName); DicSysConf sysConf = coreCommonService.getCacheSysConf(user.getCompanyId()); // 数量检测地址,如果没有用#代替 view.addObject("quantityPath", StringUtils.isEmpty(sysConf .getQuantityPath()) ? "#" : sysConf.getQuantityPath()); // 三维演示地址 view.addObject( "threePath", StringUtils.isEmpty(sysConf.getThreePath()) ? "#" : sysConf .getThreePath()); // 技术支持信息 view.addObject("support", "技术支持:" + sysConf.getSupport()); if (StringUtils.isEmpty(groupTag)) { groupTag = "0"; } view.addObject("groupTag", groupTag); view.setViewName("index/index"); //定制首页-上海嘉定 if ("5303".equals(companyId)) { view.setViewName("index/index-5303"); } if ("5318".equals(companyId)) { view.setViewName("index/index-5318"); } if ("5326".equals(companyId)) { view.setViewName("index/index-5326"); } if ("5327".equals(companyId)) { view.setViewName("index/index-5327"); } if ("5329".equals(companyId)) { view.setViewName("index/index-5329"); } return view; } /** * 主页 * * @param code URL模块的标记位置,需要调整格式为:companyId-code * @return */ @RequestMapping("/home") public ModelAndView home( @RequestParam(value = "t", required = false) String code, @RequestParam(value = "g", required = false) String groupTag) { ModelAndView view = new ModelAndView(); // 用户信息 IUser user = ContextUtil.getLoginUser(); // 避免非管理恶意访问 if (StringUtils.isEmpty(code)) { code = "0000"; if (user.isAdministrator()) { code = null; } } view.addObject(Constant.MODEL_KEY_LOGIN_USER, user); DicSysConf sysConf = coreCommonService.getCacheSysConf(user .getCompanyId()); // 获取当前人选择的分库ID,如果页面没有带入默认获取当前人所在分库。 String deptId = ContextUtil.subDeptId(user); view.addObject(Constant.MODEL_KEY_DEPT_ID, deptId); // 设置logo String logName = FilesUtil.getLogoByCompanyId(user.getCompanyId()); view.addObject("logo", "./static/img/" + logName); // 技术支持信息 view.addObject("support", "技术支持:" + sysConf.getSupport()); if ("5318".equals(user.getCompanyId())) { view.addObject("support", ""); } // 系统名称 String sysName = sysConf.getSysName(); if (sysName.indexOf(Constant.TAG_SUB_NAME) != -1) { DefaultDept defaultDept = sysDeptService.getCacheDept( user.getCompanyId(), deptId); sysName = sysName.replace(Constant.TAG_SUB_NAME, (null == defaultDept ? "" : defaultDept.getName())); } view.addObject("sysName", sysName); // 组织信息 DefaultCompany company = companyService.getCompany(user.getCompanyId()); view.addObject("model", company.getModel()); view.addObject(Constant.MODEL_KEY_DEFAULT_COMPANY, company); view.addObject("bizType", BizType.SYS.getCode()); // 获取整个分库下拉框 List listDept = sysDeptService.getCacheDept(user.getCompanyId()); view.addObject("listDept", listDept); // 验证当前登录人分库权限 boolean isMain = ContextUtil.isMainDept(user); view.addObject("isMain", isMain); // 获取当前登陆人的菜单 List menuList; String welcomeUrl = "./basic/common/welcome?t="; if (StringUtils.isEmpty(code)) { menuList = systemService.getSysMenu(); welcomeUrl += "all"; } else { welcomeUrl += code; menuList = systemService.getMenuBySystemId(company.getId(), code, user); } view.addObject("menuList", menuList); if (null == menuList || menuList.isEmpty()) { welcomeUrl = "./no-access"; view.addObject("menuTag", "NO"); } else { view.addObject("menuTag", "YES"); } // 配置默认模块欢迎页面 view.addObject("welcomeUrl", welcomeUrl); if (StringUtils.isEmpty(groupTag)) { groupTag = "0"; } view.addObject("groupTag", groupTag); view.setViewName("admin/home"); return view; } /** * 集团/公司-主页,主页直接展示当前人所在的实际部门,并获取组织专用菜单 * * @param code * @return */ @RequestMapping("/home-group") public ModelAndView homeGroup(@RequestParam(value = "t", required = false) String code) { ModelAndView view = new ModelAndView(); // 用户信息 IUser user = ContextUtil.getLoginUser(); view.addObject(Constant.MODEL_KEY_LOGIN_USER, user); DicSysConf sysConf = coreCommonService.getCacheSysConf(user.getCompanyId()); // 获取当前人选择的分库ID,如果页面没有带入默认获取当前人所在分库。 String deptId = ContextUtil.subDeptId(user); view.addObject(Constant.MODEL_KEY_DEPT_ID, deptId); // 获取当前人所配置的实际部门 IDept dept = user.getDepts().get(0); view.addObject("dept", dept); //框架上左侧的LGOO // 设置logo String logName = FilesUtil.getLogoByCompanyId(user.getCompanyId()); view.addObject("logo", "./static/img/" + logName); // 技术支持信息 view.addObject("support", "技术支持:" + sysConf.getSupport()); // 系统名称 String sysName = sysConf.getSysName(); if (sysName.indexOf(Constant.TAG_SUB_NAME) != -1) { DefaultDept defaultDept = sysDeptService.getCacheDept(user.getCompanyId(), dept.getId()); sysName = sysName.replace(Constant.TAG_SUB_NAME, (null == defaultDept ? "" : defaultDept.getName())); } view.addObject("sysName", sysName); view.addObject("bizType", BizType.SYS.getCode()); // 获取当前登陆人的菜单-公司集团专用 List menuList = systemService.getSysGroupMenu(); view.addObject("menuList", menuList); // 配置默认模块欢迎页面 String welcomeUrl = ".../../basic/gis/gis-group"; view.addObject("welcomeUrl", welcomeUrl); if (null == menuList || menuList.isEmpty()) { view.addObject("menuTag", "NO"); } else { view.addObject("menuTag", "YES"); } view.setViewName("admin/home-group"); return view; } /** * 无权限页面 * * @return */ @RequestMapping("/no-access") public String noAccess() { return "no-access"; } /** * 会话超时 * * @return */ @RequestMapping("/session-out") public String sessionOut() { return "session-out"; } /** * 登陆被踢出 * * @return */ @RequestMapping("/session-kick-away") public String sessionKickAway() { return "session-kick-away"; } /** * 没有授权页面 * * @return */ @RequestMapping("/no-license") public String noLicense() { return "no-license"; } }