订阅更新记录新增地址

This commit is contained in:
chuzhongzai
2023-12-08 14:58:24 +08:00
parent b78939528a
commit a7bfe1df29
8 changed files with 63 additions and 32 deletions
@@ -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