huanghongfa
2021-05-12 9b15ddbe6b0106261c7c59889ad75d5627a2b545
Merge remote-tracking branch 'origin/test' into test
2个文件已修改
47 ■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/java/com/panzhihua/zuul/filters/JWTAuthenticationTokenFilter.java 26 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_user/src/main/java/com/panzhihua/service_user/service/impl/UserServiceImpl.java
@@ -514,10 +514,28 @@
     */
    @Override
    public R putUserIsVolunteer(String phone, int type) {
        SysUserDO sysUserDO = new SysUserDO();
        sysUserDO.setIsVolunteer(type);
        int update = userDao.update(sysUserDO, new UpdateWrapper<SysUserDO>().lambda().eq(SysUserDO::getPhone, phone));
        if (update > 0) {
            ComMngVolunteerMngVO comMngVolunteerMngVO = userDao.selectVolunteerMngByPhone(phone);
            if(comMngVolunteerMngVO!=null&&comMngVolunteerMngVO.getSubmitUserId()!=null) {
                Long userId = comMngVolunteerMngVO.getSubmitUserId();
                //删除用户信息缓存
                String userKey = UserConstants.LOGIN_USER_INFO + userId;
                stringRedisTemplate.delete(userKey);
            }else{
                List<SysUserDO> userDOList =  userDao.selectList(new LambdaQueryWrapper<SysUserDO>().eq(SysUserDO::getPhone, phone));
                if(userDOList!=null && userDOList.size()>0){
                    userDOList.forEach(usrDo ->{
                        Long userId = usrDo.getUserId();
                        //删除用户信息缓存
                        String userKey = UserConstants.LOGIN_USER_INFO + userId;
                        stringRedisTemplate.delete(userKey);
                    });
                }
            }
            return R.ok();
        }
        return R.fail();
@@ -547,6 +565,9 @@
            }
            int update = userDao.updateById(sysUserDO);
            if (update > 0) {
                //删除用户信息缓存
                String userKey = UserConstants.LOGIN_USER_INFO + userId;
                stringRedisTemplate.delete(userKey);
                return R.ok();
            }
        }
springcloud_k8s_panzhihuazhihuishequ/zuul/src/main/java/com/panzhihua/zuul/filters/JWTAuthenticationTokenFilter.java
@@ -114,22 +114,22 @@
                    ResultUtil.responseJson(response, R.fail(HttpStatus.UNAUTHORIZED, "token校验失败"));
                    return;
                }
                String username = claims.getSubject();
                String userId = claims.getSubject();
                int type = (Integer) claims.get("type");
                if (ObjectUtils.isEmpty(username)) {
                if (ObjectUtils.isEmpty(userId)) {
                    ResultUtil.responseJson(response, R.fail(HttpStatus.UNAUTHORIZED, "token校验失败"));
                    return;
                }
                List<SimpleGrantedAuthority> authorities = new ArrayList<>();
                List<SimpleGrantedAuthority> authorities1 = new ArrayList<>();
                if (1 == type) {//小程序用户统一角色
                    String roleAppletKey = SecurityConstants.ROLE_APPLETS_USER +username;
                    String roleAppletKey = SecurityConstants.ROLE_APPLETS_USER +userId;
                    if(stringRedisTemplate.hasKey(roleAppletKey)){
                        String roles = valueOperations.get(roleAppletKey);
                        authorities = JSONArray.parseArray(roles, SimpleGrantedAuthority.class);
                    }else {
                        authorities.add(new SimpleGrantedAuthority(SecurityConstants.ROLE_APPLETS));
                        String userKey = UserConstants.LOGIN_USER_INFO + username;
                        String userKey = UserConstants.LOGIN_USER_INFO + userId;
                        Boolean hasKeyLoginUserInfo = stringRedisTemplate.hasKey(userKey);
                        if (hasKeyLoginUserInfo) {
                            String userInfo = valueOperations.get(userKey);
@@ -140,25 +140,27 @@
                            }
                        }else{
                            //查询登陆用户信息
                            R<LoginUserInfoVO> r = userService.getUserInfoByUserId(username);
                            R<LoginUserInfoVO> r = userService.getUserInfoByUserId(userId);
                            if (!R.isOk(r)) {
                                ResultUtil.responseJson(response, R.fail(HttpStatus.ERROR, "登录用户信息查询失败"));
                                return;
                            }
                            LoginUserInfoVO data = r.getData();
                            String userInfo = JSONObject.toJSONString(data);
                            valueOperations.set(userKey,userInfo,24,TimeUnit.HOURS);
                            //判断用户是否已实名制
                            if (data.getIsRealNamed() != null && data.getIsRealNamed()) {
                                authorities.add(new SimpleGrantedAuthority(SecurityConstants.ROLE_APPLETS_REAL_NAMED));
                            }
                        }
                        valueOperations.set(roleAppletKey, JSONArray.toJSONString(authorities), 24, TimeUnit.HOURS);
                    }
                } else {
                    String key = SecurityConstants.ROLE_USER + username;
                    String key = SecurityConstants.ROLE_USER + userId;
                    Boolean aBoolean = stringRedisTemplate.hasKey(key);
                    if (aBoolean) {
                        String roles = valueOperations.get(key);
                        authorities = JSONArray.parseArray(roles, SimpleGrantedAuthority.class);
                    } else {
                        R<List<String>> r = userService.getUserRoles(username);
                        R<List<String>> r = userService.getUserRoles(userId);
                        List<String> data =(List<String>)r.getData();
                        if (!ObjectUtils.isEmpty(data)) {
                            data.forEach(s -> {
@@ -169,11 +171,11 @@
                        }
                    }
                }
                UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(username, username, authorities);//主要使用权限 账户 密码 不重要
                UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userId, userId, authorities);//主要使用权限 账户 密码 不重要
                SecurityContextHolder.getContext().setAuthentication(authentication);
                safeboxRequestWrapper.addHeader(TokenConstant.TOKEN_LOGOUT,tokenHeader);
                //登录用户的所有信息
                String userKey = UserConstants.LOGIN_USER_INFO + username;
                String userKey = UserConstants.LOGIN_USER_INFO + userId;
                Boolean hasKeyLoginUserInfo = stringRedisTemplate.hasKey(userKey);
                if(hasKeyLoginUserInfo){
                    String userInfo = valueOperations.get(userKey);
@@ -181,7 +183,7 @@
                    String hexStr = AES.parseByte2HexStr(encrypt);
                    safeboxRequestWrapper.addHeader(TokenConstant.TOKEN_USERINFO, hexStr);
                }else{
                    R<LoginUserInfoVO> r = userService.getUserInfoByUserId(username);
                    R<LoginUserInfoVO> r = userService.getUserInfoByUserId(userId);
                    if (!R.isOk(r)) {
                        ResultUtil.responseJson(response, R.fail(HttpStatus.ERROR, "登录用户信息查询失败"));
                        return;