Exemplo n.º 1
0
 public OnlineMap online(User user, String company, Integer roleId) {
   OnlineMap online = new OnlineMap();
   online.setUsercode(user.getUser_Code());
   online.setUsername(user.getUser_Realname());
   online.setRole(roleService.getRole(roleId).getRole_Name());
   online.setCompany(companyService.getCompanyInforByNo(company).getOrganization_Name());
   Department department =
       departmentService.getDepartmentByCondition(user.getUser_Code(), company);
   online.setDepartment(department.getDepartName());
   online.setState("Y");
   return online;
 }
Exemplo n.º 2
0
  /**
   * 登录
   *
   * @param currentUser当前登录用户
   * @param map
   * @param req
   * @param company 当前公司
   * @param loginMap 当前在线集合
   * @return
   */
  @SuppressWarnings({})
  @RequestMapping("/login.do")
  public String login(
      User currentUser, ModelMap map, HttpServletRequest req, String company, String time) {
    //		System.out.println(req.getSession().getServletContext()
    //				.getRealPath("/"));
    //		System.out.println(FileUtil.getUploadRoot());
    // 定义时,分 字符串
    List<String> hours = new ArrayList<String>();
    List<String> minutes = new ArrayList<String>();
    for (int i = 0; i < 24; i++) {
      if (i < 10) {
        hours.add("0" + i);
      } else {
        hours.add("" + i);
      }
    }
    for (int i = 0; i < 60; i++) {
      if (i < 10) {
        minutes.add("0" + i);
      } else {
        minutes.add("" + i);
      }
    }
    req.getSession().setAttribute("hours", hours);
    req.getSession().setAttribute("minutes", minutes);
    // map.put("hours", hours);
    // map.put("minutes", minutes);
    String errorMsg = "";
    // List<Role> roles = roleService.getAllRole(company);// 用户拥有的所有角色
    List<Role> roles = roleService.getAllRole();
    String page = "login/login"; // 定义跳转页面
    Integer roleId = 0; // 定义用户角色id
    // && ((company != null) && (!"0".equals(company)))
    if (currentUser != null) { // 判断提交信息是否为空
      User mesUser = userService.findByUser_Code(currentUser.getUser_Code()); // 根据工号拿到用户信息(资讯平台)
      ModelUser agentflowUser =
          userService.getMemGeninf(currentUser.getUser_Code()); // 根据工号从agentflow中查询用户
      System.out.println("登錄賬號:" + currentUser.getUser_Code());
      // 查询出所有公司
      List<Company> allCompany = companyService.getAllCompany();

      // List<Department> departments = departmentService
      //		.getDepartmentsByCom(company);// 根据公司编号查询部门
      // map.put("departments", departments);
      // req.getSession().setAttribute("departments", departments);
      req.getSession().setAttribute("company", allCompany);
      // map.put("company", company);

      if (mesUser == null) { // 资讯系统中不存在该用户
        if (agentflowUser == null) { // agentflow中不存在该用户
          errorMsg = "此工号不存在";
        } else { // agentflow中存在该用户
          String password = MD5Utils.encrypt(currentUser.getUser_Password()); // 加密
          // password = "******";(谁改了数据库)
          if (!agentflowUser.getPassword().equals(password)) {
            errorMsg = "账号或密码错误";
          } else if ("true".equals(agentflowUser.getResign())) {
            errorMsg = "当前工号已离职";
          } else if (("true".equals(agentflowUser.getInvisible()))
              || ("true".equals(agentflowUser.getDeniedLogin()))) {
            errorMsg = "当前工号不可以登陆";
          } else { // 第一次登录请先完善信息吧!
            String comStr = "";
            if (agentflowUser.getId().startsWith("kgo")) comStr = "昆山和霖光电科技有限公司";
            if (agentflowUser.getId().startsWith("kgp")) comStr = "昆山凌达光电科技有限公司";
            if (agentflowUser.getId().startsWith("sgo")) comStr = "深圳旭茂光电技术有限公司";
            if (agentflowUser.getId().startsWith("gp")) comStr = "凌巨科技股份有限公司";
            agentflowUser.setCompany(comStr);
            // map.put("agentflowUser", agentflowUser);
            req.getSession().setAttribute("agentflowUser", agentflowUser);
            // map.put("mark", "2");// 定义标志,确定添加之后跳转到那个页面
            page = "redirect:../user/initAdd.do?mark=2";
          }
        }
      } else { // 资讯系统中存在该用户
        Company com = null;
        List<Role> user_roles =
            roleService.getRolesByUsercode(currentUser.getUser_Code()); // 查询用户的所有的角色信息
        List<Company> user_companys =
            companyService.getCompanyByUsercode(currentUser.getUser_Code()); // 查询用户任职的公司信息

        //	if (company != null && !"".equals(company)) {
        for (Company c : user_companys) {
          // if (c.getSeg_Segment_No().equals(company)) {
          //	com = c;// 当前登陆的公司
          // }
          com = c;
        }
        for (Role r : user_roles) {
          // if (r.getCompany().getSeg_Segment_No().equals(company)) {
          //	roleId = r.getId();// 当前用户角色id
          // }
          roleId = r.getId();
        }
        // }
        boolean check =
            userService.checkUser(currentUser.getUser_Code()); // 查询咨讯平台与agentflow中用户信息是否一致
        if (!check) { // 不一致
          mesUser = synchronizedUser(mesUser, agentflowUser); // 同步用户信息
          userService.updateUser(mesUser); // 更新用户信息
          errorMsg = "差异信息已更新,请重新登陆";
        } else if (!mesUser
            .getUser_Password()
            .equals(MD5Utils.encrypt(currentUser.getUser_Password()))) {
          errorMsg = "密码错误";
        } else if (com == null) {
          errorMsg = "对不起,公司选择有误!请重新选择";
        } else if (!"账号启用".equals(mesUser.getRegStatus())) {
          errorMsg = mesUser.getRegStatus() + ",请等待系统管理员处理!";
        } else if ("true".equals(mesUser.getResign())) {
          errorMsg = "当前工号已离职";
        } else if (("true".equals(mesUser.getInvisible()))
            || ("true".equals(mesUser.getDeniedLogin()))) {
          errorMsg = "当前工号不可以登陆";
        } else { // 登陆成功
          map.put("currentUser", mesUser);
          List<String> modelnameList = permissonService.getModelname();
          Collections.sort(modelnameList);
          List<MenuLv1> lv1s = new ArrayList<MenuLv1>();
          for (String s : modelnameList) {
            MenuLv1 menuLv1 = new MenuLv1();
            menuLv1.setName(s);
            List<Permisson> pers = permissonService.getPermissionIdByCondition(roleId, s);
            List<MenuLv2> lv2s = new ArrayList<MenuLv2>();
            for (Permisson p : pers) {
              MenuLv2 lv2 = new MenuLv2();
              lv2.setId(p.getPermissionId());
              lv2.setName(p.getPermissionName());
              lv2.setUrl(p.getUrl());
              lv2s.add(lv2);
            }
            menuLv1.setLv2s(lv2s);
            lv1s.add(menuLv1);
          }
          map.put("menu", lv1s); // 封装侧边栏菜单
          System.out.println(getIpAddr(req));
          String ip = getIpAddr(req); // 获取用户客户端ip地址
          OnlineMap online = onlineService.queryOnline(currentUser.getUser_Code());

          if (online != null) {
            if (!StringUtils.isBlank(ip)) online.setIp(ip);
            online.setState("Y");
            onlineService.updateOnline(online);
          } else {
            online = online(mesUser, com.getSeg_Segment_No(), roleId);
            onlineService.saveOnline(online);
          }

          Long count = onlineService.getOnlineCount();
          map.put("time", time);
          map.put("count", count);
          map.put("roleId", roleId); // 用户当前角色Id
          map.put("loginCompany", com); // 用户当前所属的公司
          map.put("user_companys", user_companys); // 用户当前所属的公司号
          map.put("companyCount", user_companys.size()); // 用户任职的公司的个数
          map.put("roles", roles);

          SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

          LoginLog loginLog = new LoginLog();
          loginLog.setLoginName(mesUser.getUser_Realname());
          loginLog.setLoginID(mesUser.getUser_Code());
          loginLog.setLoginTime(df.format(new Date()));
          loginLog.setCompany(com.getSeg_Segment_No());
          Department department =
              departmentService.getDepartmentByCondition(
                  mesUser.getUser_Code(), com.getSeg_Segment_No());
          loginLog.setDepart(department.getDepartName());
          loginLog.setState("Y");
          loginLogService.saveHistory(loginLog);

          page = "main/main";
        }
      }
    } else {
      errorMsg = "请完善 用户名/密码"; // 登录信息不完整
    }
    map.put("errorMsg", errorMsg);
    return page;
  }