用户登录业务逻辑(单点登录,权限登录,普通登录)

  /**
     *  APP登录时传的参数 1管理 2维修 3安装 4巡检
     *  1管理APP:需要判定是账号和密码和管理员的权限
     *  2安装APP,4巡检APP:只需要判定账号和密码
     *  3维修APP:需要判定账号密码和单点登录
     * @param userName 用户账号
     * @param passWord 用户密码
     * @param appType APP登录参数类型
     * @return
     */

   public ResultModel getcheckUser(String userName, String passWord, int appType){
       JSONObject json = new JSONObject();
       ResultModel rm = new ResultModel();
       String userCode = this.getUserCode(userName, null);
       switch (appType){
           case 1:
               System.out.println("1管理APP业务,有登录权限认证");
               //检查用户名是否存在
//               String userCode = this.getUserCode(userName, null);
               if(userCode==null){
                  json.put("userCode", "账号不存在");
                  json.put("result", "2");
                  return rm.renderSuccessResultModelList(json);
               }else{ //用户名存在
                   User user=userMapper.selectBycode(userCode);
                  // String admincode=user.getExtendS2();  //只有管理人员允许登录 extendS2(角色ID)
                  // String userCodes = "";
                   String userCodes = this.getUserCode(userName,encryptionPassWord(passWord, userCode, userName));
                   if(userCodes==null){
                       json.put("userCode", "密码错误");
                       json.put("result", "1");
                       //0 为员工    1位领导
                   }else if(user.getUserType().equals("1")){  //成功登陆
                       json.put("result", "3");
                       json.put("userCode", userCode);
                   }else{
                       json.put("result", "4");
                       json.put("userCode", "没有权限");
                   }
                   return rm.renderSuccessResultModelList(json);
               }
           case 2:
               System.out.println("3维修APP业务,有单点登录");
               //查询用户名是否存在
             //  String userCode = this.getUserCode(userName, null);
               if(userCode!=null){
                   //查询密码是否存在
                   String userCodes = this.getUserCode(userName,encryptionPassWord(passWord, userCode, userName));
                   if(userCodes!=null){
                       //根据userCodes查询用户,判断logkey字符串是否为空
                       User user = userMapper.selectBycode(userCodes);
                       String logKey = user.getLogKey();
                       //不为null空时
                       if( logKey != null && logKey.length() != 0){
                           //执行单点登录,这时旧的设备会收到掉线提醒
                           this.singleVerificationNew(logKey);
                           //生成新的newlogKey
                           String newlogKey = UUID.randomUUID().toString();
                           user.setUserCode(userCode);
                           user.setLogKey(newlogKey);
                           //更新到用户表
                           userMapper.update(user);
                           //并把新的newlogKey推送给APP
                           json.put("result", "3");
                           json.put("logKey", newlogKey);
                           json.put("userCode", userCode);
                       }else{
                           //为空时,说明第一次登录设备,需要生成新的logkey
                           String newlogKey = UUID.randomUUID().toString();
                           user.setUserCode(userCode);
                           user.setLogKey(newlogKey);
                           //更新到用户表
                           userMapper.update(user);
                           //并把新的newlogKey推送给APP
                           json.put("result", "3");
                           json.put("logKey", newlogKey);
                           json.put("userCode", userCode);
                       }
                       return rm.renderSuccessResultModelList(json);
                   }else{
                       json.put("userCode", "密码错误");
                       json.put("result", "1");
                       return rm.renderSuccessResultModelList(json);
                   }
               }else{
                    json.put("userCode", "账号不存在");
                    json.put("result", "2");
                    return rm.renderSuccessResultModelList(json);
               }
           default:
               System.out.println("2安装APP和4巡检APP业务");
               //查询用户名是否存在
//               String userCode = this.getUserCode(userName, null);
               if(userCode!=null){
                   //查询密码是否存在
                   String userCodes = this.getUserCode(userName,encryptionPassWord(passWord, userCode, userName));
                   if(userCodes!=null){ //用户名密码都正确
                       json.put("result", "3");
                       json.put("userCode", userCode);
                       return rm.renderSuccessResultModelList(json);
                   }else{
                       json.put("userCode", "密码错误");
                       json.put("result", "1");
                       return rm.renderSuccessResultModelList(json);
                   }
               }else{
                   json.put("userCode", "账号不存在");
                   json.put("result", "2");
                   return rm.renderSuccessResultModelList(json);
               }
       }
   }

用到的方法


    /**
     * 根据用户名和密码查询用户 返回此用户usercode
     */
    public String getUserCode(String userName,String passWord) {
        return userMapper.getUserCode(userName, passWord);
    }

    public String encryptionPassWord(String passWord,String userCode,String userName){
        String SaltValue =userCode.substring(5, 10)+userName;
        Md5Hash md5 = new Md5Hash(passWord, SaltValue, 828);
        return md5.toString();
    }

    /**
     * 单点登录是挤掉旧的logkey,所以这里要传旧的logKey
     * @param logKey
     */

    public void singleVerificationNew(String logKey){
        if(logKey!=null && logKey!="" && logKey != "del") {
            sendIOS(logKey);
            sendAndroid(logKey);
        }
    }
    public void sendIOS(String key) {
        MessageIOS message = new MessageIOS();
        JSONObject obj = new JSONObject();
        JSONObject aps = new JSONObject();
        aps.put("content-available", 1);
        aps.put("code", "1");
        obj.put("aps", aps);
        message.setRaw(obj.toString());
        XingeApp xinapp =  new XingeApp(2200295273L, sysConfigService.queryMap().get("IosSecretKey"));
        
        //IOSENV_PROD代表生产环境 ;IOSENV_DEV 代表开发环境
        ///
        JSONObject s = xinapp.pushSingleAccount(0,key,message,XingeApp.IOSENV_PROD);
    }
    public  void sendAndroid(String key){
        XingeApp android  = new XingeApp(2100295082,sysConfigService.queryMap().get("AndroidSecretKey"));
        Message  message = new Message();
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("code", "1");
        message.setCustom(map);
        message.setType(Message.TYPE_MESSAGE);
        JSONObject pushSingleAccount = android.pushSingleAccount(0,key, message);
    }

  <select id="getUserCode"  resultType="String">
    select 
    	user_code
    from sys_user 
    <where>
  	    <if test="userName != null and userName !='' ">
  	    	and user_name = #{userName}
		</if>
		 <if test="passWord != null and passWord !='' ">
  	    	and password = #{passWord}
		</if>
			and status =0
    </where>
  </select>
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值