| | |
| | | //判断是否存在普通用户(uid>100),若无,初始为1001 |
| | | int judgecount=mapper.judgeUname(); |
| | | if(judgecount==0){ |
| | | uinf.setUid(101); |
| | | uinf.setUid(1001); |
| | | } |
| | | String pwd= RSAUtil.encrypt("123456", RSAUtil.getPublicKey()); |
| | | uinf.setUsnid(pwd); |
| | |
| | | request.getSession().setAttribute("user", userDB); |
| | | return response.setII(1,true, userDB,"登录成功"); |
| | | } |
| | | |
| | | //等出 |
| | | public void logout() { |
| | | Subject subject = SecurityUtils.getSubject(); |
| | | subject.logout(); |
| | | } |
| | | //将用户添加至100~1000管理员 |
| | | public Response improveRole(int uid) { |
| | | //判断表是否存在 |
| | | String tableName = mapper.existTable(); |
| | | if(tableName==null){ |
| | | ///创建100~1000的id表,不存在则创建 |
| | | mapper.createNumber(); |
| | | //插入默认数据 |
| | | String sql=" INSERT INTO temp_numbers(unumber) " + |
| | | " VALUES "; |
| | | for(int i=101;i<=1000;i++){ |
| | | sql+="("+i+")"; |
| | | if(i!=1000){ |
| | | sql+=","; |
| | | } |
| | | } |
| | | mapper.setUnumber(sql); |
| | | } |
| | | String minUid=mapper.getIn1000(); |
| | | if(minUid==null){ |
| | | return new Response().set(1,false,"管理员个数已经用完"); |
| | | } |
| | | UpdateWrapper wrapper =new UpdateWrapper(); |
| | | wrapper.set("uid",minUid); |
| | | wrapper.eq("uid",uid); |
| | | int flag= mapper.update(null,wrapper); |
| | | return new Response().set(1,flag>0,flag>0?"升级管理员成功":"升级为管理员失败"); |
| | | } |
| | | //将管理员变成普通用户 |
| | | public Response dropRole(int uid) { |
| | | //查询最大的uid |
| | | String maxUid=mapper.getMaxUid(); |
| | | if(maxUid==null){ |
| | | maxUid="1001"; |
| | | } |
| | | UpdateWrapper wrapper =new UpdateWrapper(); |
| | | wrapper.set("uid",Integer.valueOf(maxUid)+1); |
| | | wrapper.eq("uid",uid); |
| | | int flag= mapper.update(null,wrapper); |
| | | return new Response().set(1,flag>0,flag>0?"管理员变成普通用户成功":"管理员变成普通用户失败"); |
| | | } |
| | | } |