mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-08-14 12:27:18 +00:00
test[gdscript]: export binary file from excel
This commit is contained in:
@@ -17,13 +17,10 @@ import com.zfoo.protocol.buffer.ByteBufUtils;
|
||||
import com.zfoo.protocol.generate.GenerateOperation;
|
||||
import com.zfoo.protocol.serializer.CodeLanguage;
|
||||
import com.zfoo.protocol.util.FileUtils;
|
||||
import com.zfoo.protocol.util.JsonUtils;
|
||||
import com.zfoo.storage.anno.AliasFieldName;
|
||||
import com.zfoo.storage.anno.Id;
|
||||
import com.zfoo.storage.anno.Index;
|
||||
import com.zfoo.storage.anno.Storage;
|
||||
import com.zfoo.storage.config.StorageConfig;
|
||||
import com.zfoo.storage.manager.StorageInt;
|
||||
import com.zfoo.storage.manager.StorageManager;
|
||||
import com.zfoo.storage.util.ExportUtils;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
@@ -34,7 +31,6 @@ import org.junit.Test;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -55,15 +51,13 @@ public class ExportBinaryTesting {
|
||||
|
||||
}
|
||||
|
||||
// 对应的excel表格,变量对应excel中的列,只有定义过的变量才能导出,没有定义的变量不会导出
|
||||
@Storage
|
||||
public record StudentResource(
|
||||
@Id
|
||||
int id,
|
||||
@Index(unique = true)
|
||||
String idCard,
|
||||
@Index
|
||||
String name,
|
||||
@Index
|
||||
@AliasFieldName("年龄")
|
||||
int age,
|
||||
float score,
|
||||
@@ -71,11 +65,9 @@ public class ExportBinaryTesting {
|
||||
User[] users,
|
||||
User user
|
||||
) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// 需要定义一个类将所有的excel对象包裹起来
|
||||
public static class ResourceData {
|
||||
|
||||
public Map<Integer, StudentResource> studentResources;
|
||||
@@ -109,51 +101,6 @@ public class ExportBinaryTesting {
|
||||
ProtocolManager.write(buffer, resourceData);
|
||||
var bytes = ByteBufUtils.readAllBytes(buffer);
|
||||
FileUtils.writeInputStreamToFile(new File("D:/github/godot-bird/binary_data.cfg"), new ByteArrayInputStream(bytes));
|
||||
|
||||
//获取storage对象
|
||||
var storage = storageManager.getStorage(StudentResource.class);
|
||||
//获取唯一索引的对象
|
||||
StudentResource uniqueIndex = storage.getUniqueIndex(StudentResource::idCard, "110101200007281903");
|
||||
System.out.println(JsonUtils.object2String(uniqueIndex));
|
||||
//获取年龄索引对象列表
|
||||
List<StudentResource> ageIndexList = storage.getIndexes(StudentResource::age, 10);
|
||||
for (StudentResource resource : ageIndexList) {
|
||||
System.out.println(JsonUtils.object2String(resource));
|
||||
}
|
||||
//获取名称索引对象列表
|
||||
List<StudentResource> nameIndexList = storage.getIndexes(StudentResource::name, "james1");
|
||||
for (StudentResource resource : nameIndexList) {
|
||||
System.out.println(JsonUtils.object2String(resource));
|
||||
}
|
||||
//获取所有列表对象
|
||||
var list = storage.getAll();
|
||||
for (StudentResource resource : list) {
|
||||
System.out.println(JsonUtils.object2String(resource));
|
||||
}
|
||||
//获取泛型的storage对象
|
||||
StorageInt<Integer, StudentResource> genericStorage = storageManager.getStorage(StudentResource.class);
|
||||
//获取配置表的所有数据
|
||||
List<StudentResource> all = storageManager.getList(StudentResource.class);
|
||||
for (StudentResource resource : all) {
|
||||
System.out.println(JsonUtils.object2String(resource));
|
||||
}
|
||||
//获取配置表索引的数据
|
||||
List<StudentResource> ageIndexes = storageManager.getIndexes(StudentResource.class, StudentResource::age, 10);
|
||||
for (StudentResource resource : ageIndexes) {
|
||||
System.out.println(JsonUtils.object2String(resource));
|
||||
}
|
||||
//获取配置表索引的数据
|
||||
List<StudentResource> nameIndexes = storageManager.getIndexes(StudentResource.class, StudentResource::name, "james1");
|
||||
for (StudentResource resource : nameIndexes) {
|
||||
System.out.println(JsonUtils.object2String(resource));
|
||||
}
|
||||
//获取主键ID的唯一数据
|
||||
StudentResource idResource = storageManager.get(StudentResource.class, 1001);
|
||||
System.out.println(JsonUtils.object2String(idResource));
|
||||
|
||||
for (StudentResource resource : storage.getAll()) {
|
||||
System.out.println(JsonUtils.object2String(resource));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user