订阅更新记录新增地址
This commit is contained in:
parent
b78939528a
commit
a7bfe1df29
40
pom.xml
40
pom.xml
@ -113,27 +113,33 @@
|
||||
<artifactId>java-telegram-bot-api</artifactId>
|
||||
<version>6.9.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.lionsoul</groupId>
|
||||
<artifactId>ip2region</artifactId>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.graalvm.buildtools</groupId>
|
||||
<artifactId>native-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<imageName>lionwebsite</imageName>
|
||||
<fallback>false</fallback>
|
||||
<verbose>true</verbose>
|
||||
<quickBuild>true</quickBuild>
|
||||
<buildArgs>
|
||||
<arg>-H:+ReportExceptionStackTraces</arg>
|
||||
<arg>--initialize-at-build-time=org.apache.commons.logging.LogFactory,org.apache.commons.logging.LogFactoryService</arg>
|
||||
</buildArgs>
|
||||
<metadataRepository>
|
||||
<enabled>true</enabled>
|
||||
</metadataRepository>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- <plugin>-->
|
||||
<!-- <groupId>org.graalvm.buildtools</groupId>-->
|
||||
<!-- <artifactId>native-maven-plugin</artifactId>-->
|
||||
<!-- <configuration>-->
|
||||
<!-- <imageName>lionwebsite</imageName>-->
|
||||
<!-- <fallback>false</fallback>-->
|
||||
<!-- <verbose>true</verbose>-->
|
||||
<!-- <quickBuild>true</quickBuild>-->
|
||||
<!-- <buildArgs>-->
|
||||
<!-- <arg>-H:+ReportExceptionStackTraces</arg>-->
|
||||
<!-- <arg>--initialize-at-build-time=org.apache.commons.logging.LogFactory,org.apache.commons.logging.LogFactoryService</arg>-->
|
||||
<!-- </buildArgs>-->
|
||||
<!-- <metadataRepository>-->
|
||||
<!-- <enabled>true</enabled>-->
|
||||
<!-- </metadataRepository>-->
|
||||
<!-- </configuration>-->
|
||||
<!-- </plugin>-->
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
|
||||
@ -29,7 +29,7 @@ public interface SubMapper {
|
||||
@Delete("delete from sub_bind where user=#{user}")
|
||||
void deleteSubBind(String user);
|
||||
|
||||
@Insert("insert into sub_update_record (user, ip, UA, time) values (#{user}, #{ip}, #{UA}, #{time})")
|
||||
@Insert("insert into sub_update_record (user, ip, UA, time, location) values (#{user}, #{ip}, #{UA}, #{time}, #{location})")
|
||||
void insertSubUpdateRecord(SubUpdateRecord subUpdateRecord);
|
||||
|
||||
@Select("select * from sub_update_record")
|
||||
|
||||
@ -15,4 +15,5 @@ public class SubUpdateRecord {
|
||||
String ip;
|
||||
String UA;
|
||||
Date time;
|
||||
String location;
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ import com.lion.lionwebsite.Util.FileDownload;
|
||||
import com.lion.lionwebsite.Util.Response;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.lionsoul.ip2region.xdb.Searcher;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -19,8 +20,17 @@ import java.util.Date;
|
||||
@Service
|
||||
public class SubService {
|
||||
SubMapper subMapper;
|
||||
|
||||
byte[] vIndex;
|
||||
|
||||
String dbPath = "ip2region.xdb";
|
||||
public SubService(SubMapper subMapper) {
|
||||
this.subMapper = subMapper;
|
||||
try {
|
||||
vIndex = Searcher.loadVectorIndexFromFile(dbPath);
|
||||
}catch (Exception e){
|
||||
System.out.printf("failed to load vector index from `%s`: %s\n", dbPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
public String insertSubBind(String user){
|
||||
@ -83,7 +93,21 @@ public class SubService {
|
||||
if(UA == null)
|
||||
return;
|
||||
|
||||
SubUpdateRecord subUpdateRecord = new SubUpdateRecord(0, subBind.getUser(), ip, UA, new Date());
|
||||
StringBuilder location = new StringBuilder();
|
||||
Searcher searcher;
|
||||
try {
|
||||
searcher = Searcher.newWithVectorIndex(dbPath, vIndex);
|
||||
String region = searcher.search(ip);
|
||||
String[] temp = region.split("\\|");
|
||||
for (int i = 2; i < temp.length; i++)
|
||||
if(!temp[i].equals("0"))
|
||||
location.append(temp[i]).append(" ");
|
||||
} catch (Exception e) {
|
||||
System.out.printf("failed to create vectorIndex cached searcher with `%s`: %s\n", dbPath, e);
|
||||
return;
|
||||
}
|
||||
|
||||
SubUpdateRecord subUpdateRecord = new SubUpdateRecord(0, subBind.getUser(), ip, UA, new Date(), location.toString().trim());
|
||||
subMapper.insertSubUpdateRecord(subUpdateRecord);
|
||||
if(subMapper.selectUpdateRecordCount(subBind.getUser()) > 10)
|
||||
subMapper.deleteSubUpdateRecordById(subMapper.selectMinUpdateRecordId(subBind.getUser()));
|
||||
|
||||
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user