根据设备号和session判断移动端重复登录的问题

if(client!=null){   //OA端
			AjaxJson ajaxJson = checkuser0(user0, request);
			if(!ajaxJson.isSuccess()){
				jsonObject.put("flag", false);
				jsonObject.put("message", "登录失败");
				jsonObject.put("login", false);
			}
			else {
//				login=checkDuplicate(user0);//重复登录检验
				
			 
				jsonObject.put("flag", true);
				jsonObject.put("message", "登录成功");
			}
			responseJSON(response, jsonObject);
			return null;
		}

public AjaxJson checkuser0(TSUser user, HttpServletRequest req) throws Exception {
		String message = "";
		HttpSession session = ContextHolderUtils.getSession();
		DataSourceContextHolder
				.setDataSourceType(DataSourceType.dataSource_jeecg);
		String iMEI=req.getParameter("code");
		AjaxJson j = new AjaxJson();
		/*int users = userService.getList(TSUser.class).size();
		if (users == 0) {
			j.setMsg("a");
			j.setSuccess(false);*/
			TSUser u = userService.checkUserExits(user);
			if (u != null) {
				
				// if (user.getUserKey().equals(u.getUserKey())) {
				if (u.getStatus()==1) {
					message = "用户: " + user.getUserName() + "["
							+ u.getTSDepart().getDepartName() + "]" + "登录成功";
					String name=user.getUserName();
					String sessionId=ClientManager.getInstance().getClientByValue(name,iMEI);
					if(StringUtil.isNotEmpty(sessionId)){
						ClientManager.getInstance().removeClinet(sessionId);
//						new Yunba3(name,null,"下线通知","登录异常","",new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()));
						new Yunba4(name,null,"下线通知","登录异常","",new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()));
						
					}
					Client client = new Client();
					client.setIp(IpUtil.getIpAddr(req));
					client.setLogindatetime(new Date());
					client.setUser(u);
					client.setType(1);
					client.setIMEI(iMEI);
					ClientManager.getInstance().addClinet(session.getId(),
							client);
					// 添加登陆日志
					systemService.addLog(message, Globals.Log_Type_LOGIN,
							Globals.Log_Leavel_INFO);

				} else {
					j.setMsg("该用户已被禁用!");
					j.setSuccess(false);
				}
			} else {
				j.setMsg("用户名或密码错误!");
				j.setSuccess(false);
			}
		return j;
	}

	/**
	 * 根据用户名查sessionid
	 * @param name
	 * @return
	 */
	public String getClientByValue(String name,String IMEI){
		String key="";
		for (Map.Entry entry : map.entrySet()) {  
	         if(entry.getValue().getUser().getUserName().equals(name)){
	        	 if(entry.getValue().getType()==1){
	        		 if(StringUtil.isNotEmpty(IMEI)){
	        			 if(entry.getValue().getIMEI()==null||!(entry.getValue().getIMEI().equals(IMEI)))
	        				 key=entry.getKey(); 
	        		 }else{
	        			 if(entry.getValue().getIMEI()!=null)
	        				 key=entry.getKey(); 
	        		 }
	        			 
	        	 }
	         }  
	     }  
	     return key;  
	}

你可能感兴趣的:(用户管理,重复登录,session,登录,用户和session绑定)