refactor: 优化部分配置及工具类使用,适配最新 ContiNew Starter
IpUtils 已经提取到 ContiNew Starter
This commit is contained in:
parent
f28fbd14fa
commit
feef427d41
@ -34,12 +34,6 @@
|
||||
<artifactId>continew-starter-data-mybatis-plus</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- ContiNew Starter 缓存模块 - Redisson -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
<artifactId>continew-starter-cache-redisson</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- ContiNew Starter 验证码模块 - 图形验证码 -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
@ -93,11 +87,5 @@
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 第三方封装 Ip2region(离线 IP 数据管理框架和定位库,支持亿级别的数据段,10 微秒级别的查询性能,提供了许多主流编程语言的 xdb 数据管理引擎的实现) -->
|
||||
<dependency>
|
||||
<groupId>net.dreamlu</groupId>
|
||||
<artifactId>mica-ip2region</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.common.config.properties;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
|
||||
/**
|
||||
* 项目配置属性
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2022/12/11 19:26
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
public class ProjectProperties extends top.charles7c.continew.starter.core.autoconfigure.ProjectProperties {
|
||||
|
||||
/**
|
||||
* 是否本地解析 IP 归属地
|
||||
*/
|
||||
public static final boolean IP_ADDR_LOCAL_PARSE_ENABLED;
|
||||
|
||||
static {
|
||||
IP_ADDR_LOCAL_PARSE_ENABLED = Convert.toBool(SpringUtil.getProperty("project.ipAddrLocalParseEnabled"));
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.common.util;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import cn.hutool.core.net.NetUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.config.properties.ProjectProperties;
|
||||
|
||||
import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
|
||||
import net.dreamlu.mica.ip2region.core.IpInfo;
|
||||
|
||||
/**
|
||||
* IP 工具类
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2022/12/23 20:00
|
||||
*/
|
||||
@Slf4j
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class IpUtils {
|
||||
|
||||
/**
|
||||
* 太平洋网开放 API:查询 IP 归属地
|
||||
*/
|
||||
private static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp?ip=%s&json=true";
|
||||
|
||||
/**
|
||||
* 根据 IP 获取归属地信息
|
||||
*
|
||||
* @param ip
|
||||
* IP 地址
|
||||
* @return 归属地信息
|
||||
*/
|
||||
public static String getCityInfo(String ip) {
|
||||
if (ProjectProperties.IP_ADDR_LOCAL_PARSE_ENABLED) {
|
||||
return getLocalCityInfo(ip);
|
||||
} else {
|
||||
return getHttpCityInfo(ip);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 IP 获取归属地信息(网络解析)
|
||||
*
|
||||
* @param ip
|
||||
* IP 地址
|
||||
* @return 归属地信息
|
||||
*/
|
||||
public static String getHttpCityInfo(String ip) {
|
||||
if (isInnerIp(ip)) {
|
||||
return "内网IP";
|
||||
}
|
||||
String api = String.format(IP_URL, ip);
|
||||
JSONObject object = JSONUtil.parseObj(HttpUtil.get(api));
|
||||
return object.get("addr", String.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 IP 获取归属地信息(本地解析)
|
||||
*
|
||||
* @param ip
|
||||
* IP 地址
|
||||
* @return 归属地信息
|
||||
*/
|
||||
public static String getLocalCityInfo(String ip) {
|
||||
if (isInnerIp(ip)) {
|
||||
return "内网IP";
|
||||
}
|
||||
Ip2regionSearcher ip2regionSearcher = SpringUtil.getBean(Ip2regionSearcher.class);
|
||||
IpInfo ipInfo = ip2regionSearcher.memorySearch(ip);
|
||||
if (null != ipInfo) {
|
||||
return ipInfo.getAddress();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为内网 IPv4
|
||||
*
|
||||
* @param ip
|
||||
* IP 地址
|
||||
* @return 是否为内网 IP
|
||||
*/
|
||||
public static boolean isInnerIp(String ip) {
|
||||
ip = "0:0:0:0:0:0:0:1".equals(ip) ? "127.0.0.1" : HtmlUtil.cleanHtmlTag(ip);
|
||||
return NetUtil.isInnerIP(ip);
|
||||
}
|
||||
}
|
@ -33,10 +33,10 @@ import top.charles7c.cnadmin.common.constant.CacheConstants;
|
||||
import top.charles7c.cnadmin.common.model.dto.LogContext;
|
||||
import top.charles7c.cnadmin.common.model.dto.LoginUser;
|
||||
import top.charles7c.cnadmin.common.service.CommonUserService;
|
||||
import top.charles7c.cnadmin.common.util.IpUtils;
|
||||
import top.charles7c.cnadmin.common.util.ServletUtils;
|
||||
import top.charles7c.cnadmin.common.util.holder.LogContextHolder;
|
||||
import top.charles7c.continew.starter.core.util.ExceptionUtils;
|
||||
import top.charles7c.continew.starter.core.util.IpUtils;
|
||||
|
||||
/**
|
||||
* 登录助手
|
||||
|
@ -54,7 +54,6 @@ import top.charles7c.cnadmin.auth.model.req.AccountLoginReq;
|
||||
import top.charles7c.cnadmin.common.constant.SysConstants;
|
||||
import top.charles7c.cnadmin.common.model.dto.LogContext;
|
||||
import top.charles7c.cnadmin.common.model.resp.R;
|
||||
import top.charles7c.cnadmin.common.util.IpUtils;
|
||||
import top.charles7c.cnadmin.common.util.ServletUtils;
|
||||
import top.charles7c.cnadmin.common.util.helper.LoginHelper;
|
||||
import top.charles7c.cnadmin.common.util.holder.LogContextHolder;
|
||||
@ -65,6 +64,7 @@ import top.charles7c.cnadmin.monitor.model.entity.LogDO;
|
||||
import top.charles7c.cnadmin.system.service.UserService;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
import top.charles7c.continew.starter.core.util.ExceptionUtils;
|
||||
import top.charles7c.continew.starter.core.util.IpUtils;
|
||||
|
||||
/**
|
||||
* 系统日志拦截器
|
||||
|
@ -39,7 +39,6 @@ import top.charles7c.cnadmin.auth.model.resp.RouteResp;
|
||||
import top.charles7c.cnadmin.auth.service.LoginService;
|
||||
import top.charles7c.cnadmin.auth.service.PermissionService;
|
||||
import top.charles7c.cnadmin.common.annotation.TreeField;
|
||||
import top.charles7c.cnadmin.common.config.properties.ProjectProperties;
|
||||
import top.charles7c.cnadmin.common.constant.RegexConstants;
|
||||
import top.charles7c.cnadmin.common.constant.SysConstants;
|
||||
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
|
||||
@ -59,6 +58,7 @@ import top.charles7c.cnadmin.system.model.req.MessageReq;
|
||||
import top.charles7c.cnadmin.system.model.resp.DeptDetailResp;
|
||||
import top.charles7c.cnadmin.system.model.resp.MenuResp;
|
||||
import top.charles7c.cnadmin.system.service.*;
|
||||
import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties;
|
||||
|
||||
import me.zhyd.oauth.model.AuthUser;
|
||||
|
||||
|
@ -38,7 +38,7 @@ import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.config.properties.ProjectProperties;
|
||||
import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties;
|
||||
|
||||
/**
|
||||
* 启动程序
|
||||
|
@ -47,7 +47,6 @@ import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.config.properties.CaptchaProperties;
|
||||
import top.charles7c.cnadmin.common.config.properties.ProjectProperties;
|
||||
import top.charles7c.cnadmin.common.constant.CacheConstants;
|
||||
import top.charles7c.cnadmin.common.constant.RegexConstants;
|
||||
import top.charles7c.cnadmin.common.model.resp.CaptchaResp;
|
||||
@ -57,6 +56,7 @@ import top.charles7c.cnadmin.common.util.TemplateUtils;
|
||||
import top.charles7c.cnadmin.common.util.validate.CheckUtils;
|
||||
import top.charles7c.continew.starter.cache.redisson.util.RedisUtils;
|
||||
import top.charles7c.continew.starter.captcha.graphic.autoconfigure.GraphicCaptchaProperties;
|
||||
import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties;
|
||||
|
||||
/**
|
||||
* 验证码 API
|
||||
|
@ -44,7 +44,6 @@ import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import top.charles7c.cnadmin.common.base.IBaseEnum;
|
||||
import top.charles7c.cnadmin.common.config.properties.LocalStorageProperties;
|
||||
import top.charles7c.cnadmin.common.config.properties.ProjectProperties;
|
||||
import top.charles7c.cnadmin.common.constant.CacheConstants;
|
||||
import top.charles7c.cnadmin.common.model.query.SortQuery;
|
||||
import top.charles7c.cnadmin.common.model.resp.LabelValueResp;
|
||||
@ -59,6 +58,7 @@ import top.charles7c.cnadmin.system.model.query.OptionQuery;
|
||||
import top.charles7c.cnadmin.system.model.query.RoleQuery;
|
||||
import top.charles7c.cnadmin.system.model.resp.RoleResp;
|
||||
import top.charles7c.cnadmin.system.service.*;
|
||||
import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties;
|
||||
|
||||
/**
|
||||
* 公共 API
|
||||
|
@ -31,7 +31,6 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
|
||||
import top.charles7c.cnadmin.common.config.properties.ProjectProperties;
|
||||
import top.charles7c.cnadmin.common.model.query.PageQuery;
|
||||
import top.charles7c.cnadmin.common.model.resp.PageDataResp;
|
||||
import top.charles7c.cnadmin.common.model.resp.R;
|
||||
@ -42,6 +41,7 @@ import top.charles7c.cnadmin.tool.model.query.TableQuery;
|
||||
import top.charles7c.cnadmin.tool.model.req.GenConfigReq;
|
||||
import top.charles7c.cnadmin.tool.model.resp.TableResp;
|
||||
import top.charles7c.cnadmin.tool.service.GeneratorService;
|
||||
import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties;
|
||||
|
||||
/**
|
||||
* 代码生成 API
|
||||
|
@ -220,8 +220,8 @@ local-storage:
|
||||
avatarMaxSizeInMb: 5
|
||||
## Windows 系统本地存储配置
|
||||
windows:
|
||||
file: C:\${project.appName}\data\file\
|
||||
avatar: C:\${project.appName}\data\avatar\
|
||||
file: C:\${project.app-name}\data\file\
|
||||
avatar: C:\${project.app-name}\data\avatar\
|
||||
## Linux 系统本地存储配置
|
||||
linux:
|
||||
file: ./data/file/
|
||||
|
@ -219,8 +219,8 @@ local-storage:
|
||||
avatarMaxSizeInMb: 5
|
||||
## Windows 系统本地存储配置
|
||||
windows:
|
||||
file: C:\${project.appName}\data\file\
|
||||
avatar: C:\${project.appName}\data\avatar\
|
||||
file: C:\${project.app-name}\data\file\
|
||||
avatar: C:\${project.app-name}\data\avatar\
|
||||
## Linux 系统本地存储配置
|
||||
linux:
|
||||
file: ../data/file/
|
||||
|
@ -3,13 +3,13 @@ project:
|
||||
# 名称
|
||||
name: ContiNew Admin
|
||||
# 应用名称
|
||||
appName: continew-admin
|
||||
app-name: continew-admin
|
||||
# 版本
|
||||
version: 2.1.0-SNAPSHOT
|
||||
# 描述
|
||||
description: ContiNew Admin 中后台管理框架/脚手架,Continue New Admin,持续以最新流行技术栈构建,拥抱变化,迭代优化。
|
||||
# 基本包
|
||||
basePackage: top.charles7c.cnadmin
|
||||
base-package: top.charles7c.cnadmin
|
||||
## 作者信息配置
|
||||
contact:
|
||||
name: Charles7c
|
||||
@ -19,8 +19,8 @@ project:
|
||||
license:
|
||||
name: Apache-2.0
|
||||
url: https://github.com/Charles7c/continew-admin/blob/dev/LICENSE
|
||||
# 是否本地解析 IP 归属地
|
||||
ipAddrLocalParseEnabled: true
|
||||
# 是否启用本地解析 IP 归属地
|
||||
ip-addr-local-parse-enabled: true
|
||||
|
||||
--- ### 日志配置(重叠部分,优先级高于 logback-spring.xml 中的配置)
|
||||
logging:
|
||||
@ -47,31 +47,31 @@ springdoc:
|
||||
group-configs:
|
||||
- group: 'all'
|
||||
paths-to-match: '/**'
|
||||
packages-to-scan: ${project.basePackage}.webapi.controller
|
||||
packages-to-scan: ${project.base-package}.webapi.controller
|
||||
- group: 'auth'
|
||||
display-name: '系统认证'
|
||||
paths-to-match:
|
||||
- '/auth/**'
|
||||
- '/oauth/**'
|
||||
packages-to-scan: ${project.basePackage}.webapi.controller.auth
|
||||
packages-to-scan: ${project.base-package}.webapi.controller.auth
|
||||
- group: 'common'
|
||||
display-name: '通用接口'
|
||||
paths-to-match:
|
||||
- '/common/**'
|
||||
- '/dashboard/**'
|
||||
packages-to-scan: ${project.basePackage}.webapi.controller.common
|
||||
packages-to-scan: ${project.base-package}.webapi.controller.common
|
||||
- group: 'system'
|
||||
display-name: '系统管理'
|
||||
paths-to-match: '/system/**'
|
||||
packages-to-scan: ${project.basePackage}.webapi.controller.system
|
||||
packages-to-scan: ${project.base-package}.webapi.controller.system
|
||||
- group: 'tool'
|
||||
display-name: '系统工具'
|
||||
paths-to-match: '/tool/**'
|
||||
packages-to-scan: ${project.basePackage}.webapi.controller.tool
|
||||
packages-to-scan: ${project.base-package}.webapi.controller.tool
|
||||
- group: 'monitor'
|
||||
display-name: '系统监控'
|
||||
paths-to-match: '/monitor/**'
|
||||
packages-to-scan: ${project.basePackage}.webapi.controller.monitor
|
||||
packages-to-scan: ${project.base-package}.webapi.controller.monitor
|
||||
## 接口文档增强配置
|
||||
knife4j:
|
||||
enable: true
|
||||
@ -114,7 +114,7 @@ mybatis-plus:
|
||||
# Mapper XML 文件目录配置
|
||||
mapper-locations: classpath*:/mapper/**/*Mapper.xml
|
||||
# 类型别名扫描包配置
|
||||
type-aliases-package: ${project.basePackage}.**.model
|
||||
type-aliases-package: ${project.base-package}.**.model
|
||||
configuration:
|
||||
# MyBatis 自动映射策略
|
||||
# NONE:不启用 PARTIAL:只对非嵌套 resultMap 自动映射 FULL:对所有 resultMap 自动映射
|
||||
@ -135,7 +135,7 @@ mybatis-plus:
|
||||
extension:
|
||||
enabled: true
|
||||
# Mapper 接口扫描包配置
|
||||
mapper-package: ${project.basePackage}.**.mapper
|
||||
mapper-package: ${project.base-package}.**.mapper
|
||||
# 数据权限实现
|
||||
data-permission-handler-impl: top.charles7c.cnadmin.common.config.mybatis.DataPermissionHandlerImpl
|
||||
# 分页插件配置
|
||||
@ -166,7 +166,7 @@ server:
|
||||
--- ### Spring 配置
|
||||
spring:
|
||||
application:
|
||||
name: ${project.appName}
|
||||
name: ${project.app-name}
|
||||
## 环境配置
|
||||
profiles:
|
||||
# 启用的环境
|
||||
|
12
pom.xml
12
pom.xml
@ -34,11 +34,7 @@
|
||||
|
||||
<properties>
|
||||
<revision>2.1.0-SNAPSHOT</revision>
|
||||
|
||||
<!-- ### 工具库相关 ### -->
|
||||
<easyexcel.version>3.3.2</easyexcel.version>
|
||||
<ip2region.version>3.1.5.1</ip2region.version>
|
||||
|
||||
<!-- Maven Plugin Versions -->
|
||||
<spotless.version>2.40.0</spotless.version>
|
||||
</properties>
|
||||
@ -54,14 +50,6 @@
|
||||
<version>${easyexcel.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 第三方封装 Ip2region(离线 IP 数据管理框架和定位库,支持亿级别的数据段,10 微秒级别的查询性能,提供了许多主流编程语言的 xdb 数据管理引擎的实现) -->
|
||||
<dependency>
|
||||
<groupId>net.dreamlu</groupId>
|
||||
<artifactId>mica-ip2region</artifactId>
|
||||
<version>${ip2region.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- ################ 本项目子模块相关 ################ -->
|
||||
<!-- API 模块(存放 Controller 层代码,打包部署的模块) -->
|
||||
<dependency>
|
||||
<groupId>top.charles7c.continew</groupId>
|
||||
|
Loading…
Reference in New Issue
Block a user