Skip to content

Commit

Permalink
Merge pull request #2 from lijiahangmax/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lijiahangmax authored Mar 21, 2023
2 parents 8fdc3b8 + 8c64c4a commit 3c0939a
Show file tree
Hide file tree
Showing 115 changed files with 2,663 additions and 1,071 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ orion-all | 全部模块聚合 包含了上述所有模块的引用

### 如何使用
``` pom.xml
# 当前最新版本 1.0.4
# 当前最新版本 1.0.5
<dependency>
<groupId>io.github.lijiahangmax</groupId>
<artifactId>模块名称</artifactId>
Expand All @@ -61,7 +61,7 @@ orion-all | 全部模块聚合 包含了上述所有模块的引用
<dependency>
<groupId>io.github.lijiahangmax</groupId>
<artifactId>orion-all</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion orion-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.github.lijiahangmax</groupId>
<artifactId>orion-kit</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion orion-ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>io.github.lijiahangmax</groupId>
<artifactId>orion-kit</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
32 changes: 32 additions & 0 deletions orion-ext/src/main/java/com/orion/ext/KitExtConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.orion.ext;

import com.orion.lang.config.KitConfig;
import com.orion.lang.utils.Strings;

/**
* orion-ext 配置初始化器
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/3/6 18:31
*/
public final class KitExtConfiguration {

public static final KitExtConfiguration CONFIG = new KitExtConfiguration();

public final String LOCATION_UNKNOWN = "location.address.unknown";

public final String MAIL_CUSTOMER_HOST = "mail.customer.host";

public final String MAIL_CUSTOMER_PORT = "mail.customer.port";

static {
KitConfig.init(CONFIG.LOCATION_UNKNOWN, "未知");
KitConfig.init(CONFIG.MAIL_CUSTOMER_HOST, Strings.EMPTY);
KitConfig.init(CONFIG.MAIL_CUSTOMER_PORT, 465);
}

private KitExtConfiguration() {
}

}
22 changes: 22 additions & 0 deletions orion-ext/src/main/java/com/orion/ext/location/LocationConst.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.orion.ext.location;

import com.orion.ext.KitExtConfiguration;
import com.orion.lang.config.KitConfig;

/**
* 地址常量
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/3/7 17:48
*/
public class LocationConst {

private LocationConst() {
}

public static final String CZ88_NET = "CZ88.NET";

public static final String UNKNOWN = KitConfig.get(KitExtConfiguration.CONFIG.LOCATION_UNKNOWN);

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.orion.ext.location.region.core;
package com.orion.ext.location;

import java.io.Serializable;

Expand All @@ -11,8 +11,6 @@
*/
public class Region implements Serializable {

private static final String UNKNOWN = "未知";

/**
* 国家
*/
Expand All @@ -39,19 +37,19 @@ public class Region implements Serializable {
private String net;

public Region() {
this.country = UNKNOWN;
this.area = UNKNOWN;
this.province = UNKNOWN;
this.city = UNKNOWN;
this.net = UNKNOWN;
this.country = LocationConst.UNKNOWN;
this.area = LocationConst.UNKNOWN;
this.province = LocationConst.UNKNOWN;
this.city = LocationConst.UNKNOWN;
this.net = LocationConst.UNKNOWN;
}

public Region(String country, String province, String city) {
this.country = country;
this.area = UNKNOWN;
this.area = LocationConst.UNKNOWN;
this.province = province;
this.city = city;
this.net = UNKNOWN;
this.net = LocationConst.UNKNOWN;
}

public Region(String country, String area, String province, String city, String net) {
Expand Down
48 changes: 25 additions & 23 deletions orion-ext/src/main/java/com/orion/ext/location/ext/LocationExt.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.orion.ext.location.ext;

import com.orion.ext.location.Region;
import com.orion.ext.location.ext.core.IpLocation;
import com.orion.ext.location.ext.core.LocationSeeker;
import com.orion.ext.location.region.LocationRegions;
import com.orion.ext.location.region.core.Region;
import com.orion.lang.constant.Const;
import com.orion.lang.define.builder.StringJoiner;
import com.orion.lang.utils.Exceptions;
import com.orion.lang.utils.Strings;
import com.orion.lang.utils.Systems;
import com.orion.lang.utils.io.Files1;
import com.orion.lang.utils.net.IPs;
Expand Down Expand Up @@ -39,34 +41,34 @@ private LocationExt() {
/**
* 查询器
*/
private static final LocationSeeker seeker;
private static final LocationSeeker SEEKER;

// init
static {
boolean init;
try {
InputStream source = LocationRegions.class.getClassLoader().getResourceAsStream("region.dat");
init = Files1.resourceToFile(source, new File(DAT_PATH), Const.GBK);
seeker = new LocationSeeker(DAT_PATH);
SEEKER = new LocationSeeker(DAT_PATH);
} catch (IOException e) {
throw Exceptions.init("region ext 服务初始化异常", e);
throw Exceptions.init("region ext init error", e);
}
if (!init) {
throw Exceptions.init("region ext 服务初始化失败");
throw Exceptions.init("region ext init error");
}
}

/**
* 获取seeker实例
* 获取 seeker 实例
*
* @return 实例
*/
public static LocationSeeker getSeeker() {
return seeker;
return SEEKER;
}

/**
* 获取ip信息
* 获取国家
*
* @param ip ip
* @return ignore
Expand All @@ -76,14 +78,14 @@ public static String getCountry(String ip) {
return null;
}
try {
return seeker.getCountry(ip);
return SEEKER.getCountry(ip);
} catch (Exception e) {
return null;
throw Exceptions.runtime(Strings.format("country query error ip: {}", ip), e);
}
}

/**
* 获取ip信息
* 获取地址
*
* @param ip ip
* @return ignore
Expand All @@ -93,14 +95,14 @@ public static String getAddress(String ip) {
return null;
}
try {
return seeker.getAddress(ip);
return SEEKER.getAddress(ip);
} catch (Exception e) {
return null;
throw Exceptions.runtime(Strings.format("address query error ip: {}", ip), e);
}
}

/**
* 获取ip信息
* 获取地区
*
* @param ip ip
* @return ignore
Expand All @@ -110,31 +112,31 @@ public static String getArea(String ip) {
return null;
}
try {
return seeker.getArea(ip);
return SEEKER.getArea(ip);
} catch (Exception e) {
return null;
throw Exceptions.runtime(Strings.format("area query error ip: {}", ip), e);
}
}

/**
* 获取ip信息
* 获取地址
*
* @param ip ip
* @return ignore
*/
public static LocationSeeker.IpLocation getIpLocation(String ip) {
public static IpLocation getIpLocation(String ip) {
if (!IPs.isIpv4(ip)) {
return null;
}
try {
return seeker.getIpLocation(ip);
return SEEKER.getIpLocation(ip);
} catch (Exception e) {
return null;
throw Exceptions.runtime(Strings.format("location query error ip: {}", ip), e);
}
}

/**
* 获取ip信息
* 获取位置
*
* @param ip ip
* @return ignore
Expand All @@ -144,9 +146,9 @@ public static Region getRegion(String ip) {
return null;
}
try {
return seeker.getRegion(ip);
return SEEKER.getRegion(ip);
} catch (Exception e) {
return null;
throw Exceptions.runtime(Strings.format("region query error ip: {}", ip), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.orion.ext.location.ext.core;

import com.orion.ext.location.LocationConst;
import com.orion.lang.utils.Strings;

/**
* ip 所在的国家和地区
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/3/7 17:14
*/
public class IpLocation {

/**
* 国家
*/
protected String country;

/**
* 地区
*/
protected String area;

protected IpLocation() {
this.country = Strings.EMPTY;
this.area = Strings.EMPTY;
}

protected IpLocation copy() {
IpLocation ret = new IpLocation();
ret.country = this.getCountry();
ret.area = this.getArea();
return ret;
}

public String getCountry() {
return country.endsWith(LocationConst.CZ88_NET) ? LocationConst.UNKNOWN : country;
}

public String getArea() {
return area.endsWith(LocationConst.CZ88_NET) ? LocationConst.UNKNOWN : area;
}

@Override
public String toString() {
return this.getCountry() + Strings.SPACE + this.getArea();
}

}
Loading

0 comments on commit 3c0939a

Please sign in to comment.