ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` /** * @author 张跃帅 * @Description: 系统用户登录区域-工具 * @date 2020/08/12 */ public class SystemUserLoginAreaUtil { private static final SystemUserLoginAreaMapper systemUserLoginAreaMapper = SpringUtil.getBean(SystemUserLoginAreaMapper.class); /** * 获取-行政区划信息 */ public static IpAreaResult getAreaInfo(String ip) { // 判断 if (StrUtil.isNotBlank(ip)) { // 获取ip地址 String areaAddress = IpUtil.getAddressByIp(ip); // 判断 if (!StrUtil.DASHED.equals(areaAddress) && !"内网地址".equals(areaAddress)) { // 查询 IpAreaResult areaInfo = systemUserLoginAreaMapper.getAreaInfo(areaAddress); // 判断 if (ObjectUtil.isNotNull(areaInfo)) { // 返回 return areaInfo; } } } // 返回 return null; } /** * 获取-行政区划编码 */ public static String getAreaCode(String ip) { // 判断 if (StrUtil.isNotBlank(ip)) { // 获取行政区划 IpAreaResult areaInfo = SystemUserLoginAreaUtil.getAreaInfo(ip); // 判断 if (ObjectUtil.isNotNull(areaInfo)) { // 返回 return areaInfo.getAreaCode(); } } // 返回 return null; } /** * 校验-用户是否在登录区域 */ public static Boolean hasUserLoginArea(Long userId, String ip) { // 判断 if (userId > 0L && StrUtil.isNotBlank(ip)) { // 判断-是否内网ip if (NetUtil.isInnerIP(ip)) { // 返回 return true; } // 获取-用户当前登录行政区划编码 String currLoginUserAreaCode = SystemUserLoginAreaUtil.getAreaCode(ip); // 判断 if (StrUtil.isNotBlank(currLoginUserAreaCode)) { // 获取参数 String appCode = SystemContext.me().getAppCode(); // 获取-设置用户登录区划编码List List<String> userLoginAreaCodeList = systemUserLoginAreaMapper.getUserLoginAreaCodeList(appCode, userId); // 判断 if (userLoginAreaCodeList != null && userLoginAreaCodeList.size() > 0) { // 判断-包含 if (userLoginAreaCodeList.contains(currLoginUserAreaCode)) { // 返回 return true; } } else { // 备注:没有说明没有设置-就是放行 return true; } } } // 返回 return false; } }