Browse Source

添加模版增加pak包模版

liaoyitao 1 month ago
parent
commit
1d23be9ad4

+ 6 - 0
src/main/java/com/lqkj/link/module/zone/domain/ModelInfo.java

@@ -45,6 +45,12 @@ public class ModelInfo {
45 45
     @Column(name = "template_id")
46 46
     private Integer templateId;
47 47
 
48
+    /**
49
+     * 类型编号1:fbx文件 2:pak包
50
+     **/
51
+    @Column(name = "type_number")
52
+    private Integer typeNumber;
53
+
48 54
     public String getName() {
49 55
         return modelId.toString();
50 56
     }

+ 8 - 0
src/main/java/com/lqkj/link/module/zone/domain/ZoneInfo.java

@@ -65,4 +65,12 @@ public class ZoneInfo {
65 65
     @Column(name = "effect_address")
66 66
     @Schema(description = "模板文件路径")
67 67
     private String effectAddress;
68
+
69
+    @Column(name = "type_number")
70
+    @Schema(description = "类型编号1:不需下载pak包 2:需下载pak包")
71
+    private Integer typeNumber;
72
+
73
+    @Schema(description = "pak文件地址")
74
+    @Column(name = "pak_path")
75
+    private String pakPath;
68 76
 }

+ 1 - 1
src/main/java/com/lqkj/link/module/zone/service/ResourceService.java

@@ -93,7 +93,7 @@ public class ResourceService {
93 93
                         if (!modelInfoMap.containsKey(modelFileName.substring(0, modelFileName.lastIndexOf(".")))) {
94 94
                             list.add(new ModelInfo(null, category.getCategoryId(), modelFileName.substring(0, modelFileName.lastIndexOf(".")),
95 95
                                     null, null, null, modelPath,
96
-                                    modelIconPath.substring(1), null, null));
96
+                                    modelIconPath.substring(1), null, null, 1));
97 97
                         } else {
98 98
                             ModelInfo modelInfo = modelInfoMap.get(modelFileName.substring(0, modelFileName.lastIndexOf(".")));
99 99
                             modelInfo.setOriginalPath(modelPath);

+ 34 - 24
src/main/java/com/lqkj/link/module/zone/service/ZoneInfoService.java

@@ -80,24 +80,20 @@ public class ZoneInfoService {
80 80
             return result;
81 81
         }
82 82
         zoneInfo.setUpdateTime(new Date());
83
+        boolean isUpdated = true;
83 84
         if (zoneInfo.getZoneId() == null) {
84 85
             zoneInfo.setShareCount(0);
85 86
             zoneInfo.setViewCount(0);
86 87
             zoneInfo.setTemplateUse(0);
87
-        }
88
-        Boolean isUpdated = true;
89
-        if (Objects.nonNull(zoneInfo.getZoneId())){
88
+        }else {
90 89
             ZoneInfo oldZoneInfo = zoneInfoRepository.findById(zoneInfo.getZoneId()).get();
91 90
             isUpdated = !oldZoneInfo.getTemplateFilePath().equals(zoneInfo.getTemplateFilePath());
92
-
93 91
         }
94 92
         ZoneInfo zoneInfo1 = zoneInfoRepository.save(zoneInfo);
95
-
96 93
         if (StringUtils.isNotBlank(zoneInfo.getTemplateFilePath()) && isUpdated) {
97 94
             // 清除元素与模型
98 95
             geomInfoRepository.deleteAllByZoneId(zoneInfo1.getZoneId());
99 96
             modelInfoRepository.deleteAllByTemplateIds(Collections.singletonList(zoneInfo1.getZoneId()));
100
-
101 97
             // 解压压缩文件
102 98
             // 文件目录格式:
103 99
             // --geom.json
@@ -169,34 +165,48 @@ public class ZoneInfoService {
169 165
             zoneInfoRepository.save(zoneInfo1);
170 166
 
171 167
             List<TemplateInfo> templateInfoList = templateGeom.getModels();
172
-
173
-            String modelFolderPath = "./upload/template/" + zoneInfo1.getZoneId() + "/models";
174
-            File modelFolder = new File(modelFolderPath);
175 168
             List<ModelInfo> list = new ArrayList<>();
176
-            File[] models = modelFolder.listFiles();
177
-            assert models != null;
178
-            for (File model : models) {
179
-                if (model.isFile()) {
180
-                    String modelFileName = model.getName();
181
-                    if (modelFileName.endsWith(".fbx")) {
182
-                        String modelPath = aliOSSUtils.upload(model);
183
-                        list.add(new ModelInfo(null, null, modelFileName.substring(0, modelFileName.lastIndexOf(".")).toLowerCase(),
184
-                                null, null, null, modelPath,
185
-                                zoneInfo1.getThumbnail(), null, zoneInfo1.getZoneId()));
169
+            if (zoneInfo1.getTypeNumber() == 1){
170
+                String modelFolderPath = "./upload/template/" + zoneInfo1.getZoneId() + "/models";
171
+                File modelFolder = new File(modelFolderPath);
172
+                File[] models = modelFolder.listFiles();
173
+                assert models != null;
174
+                for (File model : models) {
175
+                    if (model.isFile()) {
176
+                        String modelFileName = model.getName();
177
+                        if (modelFileName.endsWith(".fbx")) {
178
+                            String modelPath = aliOSSUtils.upload(model);
179
+                            list.add(new ModelInfo(null, null, modelFileName.substring(0, modelFileName.lastIndexOf(".")).toLowerCase(),
180
+                                    null, null, null, modelPath,
181
+                                    zoneInfo1.getThumbnail(), null, zoneInfo1.getZoneId(), 1));
182
+                        }
186 183
                     }
187 184
                 }
185
+            }else {
186
+                String directoryPath = "./upload/template/" + zoneInfo1.getZoneId();
187
+                File directory = new File(directoryPath);
188
+                // 获取目录下的所有文件
189
+                File[] files = directory.listFiles((dir, name) -> name.endsWith(".pak"));
190
+                assert files != null;
191
+                String pakPath = aliOSSUtils.upload(files[0]);
192
+                zoneInfo1.setPakPath(pakPath);
193
+                zoneInfoRepository.save(zoneInfo1);
194
+                for (TemplateInfo templateInfo : templateInfoList) {
195
+                    list.add(new ModelInfo(null, null, templateInfo.getModelPath().substring(templateInfo.getModelPath().lastIndexOf(".") + 1),
196
+                            null, null, null, templateInfo.getModelPath(),
197
+                            zoneInfo1.getThumbnail(), null, zoneInfo1.getZoneId(), 2));
198
+                }
188 199
             }
189 200
             List<ModelInfo> modelInfoList = modelInfoRepository.saveAll(list);
201
+
190 202
             Map<String, ModelInfo> modelPathIdMap = modelInfoList
191 203
                     .stream()
192
-                    .collect(Collectors.toMap(ModelInfo::getModelName, ModelInfo -> ModelInfo));
193
-
204
+                    .collect(Collectors.toMap(ModelInfo::getOriginalPath, ModelInfo -> ModelInfo));
194 205
             List<GeomInfo> geomInfoList = new ArrayList<>();
195 206
             GeometryFactory geometryFactory = new GeometryFactory();
196 207
             int j = 1;
197 208
             for (TemplateInfo templateInfo : templateInfoList) {
198
-
199
-                String modelName = templateInfo.getModelPath().substring(0, templateInfo.getModelPath().lastIndexOf(".")).toLowerCase();
209
+                String modelName = templateInfo.getModelPath();
200 210
                 ModelInfo modelInfo = modelPathIdMap.get(modelName);
201 211
                 for (int i = 0; i < templateInfo.getLocation().size(); i++) {
202 212
                     JSONObject trans = templateInfo.getLocation().get(i);
@@ -384,7 +394,7 @@ public class ZoneInfoService {
384 394
 
385 395
         ZoneInfo zoneInfo = new ZoneInfo(null, userInfo.getUserId(), name, template == null ? new JSONObject(JSON.parseObject("{\"rotation\":{\"x\":0,\"y\":0.4383658766746521,\"z\":0,\"w\":0.8987966179847717},\"translation\":{\"x\":-820.947265625,\"y\":0,\"z\":955.6719360351563},\"scale3D\":{\"x\":1,\"y\":1,\"z\":1}}")) : template.getInitLocation(),
386 396
                 template == null ? null : template.getThumbnail(), 0, new Date(), 0, 0,
387
-                null, null, 0,0, null);
397
+                null, null, 0,0, null, template == null ? 1 : template.getTypeNumber(), template == null ? null : template.getPakPath());
388 398
         ZoneInfo newInfo = zoneInfoRepository.save(zoneInfo);
389 399
         GeometryFactory geometryFactory = new GeometryFactory();
390 400
         if (templateId != null) {

+ 11 - 0
src/main/resources/db/migration/V13__1.2.0.sql

@@ -0,0 +1,11 @@
1
+ALTER TABLE zone_info
2
+    add COLUMN if not exists type_number int default 1;
3
+comment on column zone_info.type_number is '类型编号1:不需下载pak包 2:需下载pak包';
4
+
5
+ALTER TABLE zone_info
6
+    add COLUMN if not exists pak_path varchar(255);
7
+comment on column zone_info.pak_path is 'pak文件地址';
8
+
9
+ALTER TABLE model_info
10
+    add COLUMN if not exists type_number int default 1;
11
+comment on column model_info.type_number is '类型编号1:fbx文件 2:pak包';