|
@@ -26,6 +26,7 @@ import org.springframework.stereotype.Service;
|
26
|
26
|
import org.springframework.transaction.annotation.Transactional;
|
27
|
27
|
|
28
|
28
|
import java.io.File;
|
|
29
|
+import java.io.IOException;
|
29
|
30
|
import java.nio.file.Files;
|
30
|
31
|
import java.nio.file.Paths;
|
31
|
32
|
import java.sql.Timestamp;
|
|
@@ -40,6 +41,9 @@ public class ZoneInfoService {
|
40
|
41
|
private final GeomInfoRepository geomInfoRepository;
|
41
|
42
|
private final ModelInfoRepository modelInfoRepository;
|
42
|
43
|
|
|
44
|
+ @Autowired
|
|
45
|
+ private AliOSSUtils aliOSSUtils;
|
|
46
|
+
|
43
|
47
|
private static final Long ONEDAY = 24 * 60 * 60 * 1000L;
|
44
|
48
|
|
45
|
49
|
@Autowired
|
|
@@ -79,150 +83,137 @@ public class ZoneInfoService {
|
79
|
83
|
zoneInfo.setTemplateUse(0);
|
80
|
84
|
}
|
81
|
85
|
ZoneInfo zoneInfo1 = zoneInfoRepository.save(zoneInfo);
|
82
|
|
- try {
|
83
|
|
- if (StringUtils.isNotBlank(zoneInfo.getTemplateFilePath())) {
|
84
|
|
- // 清除元素与模型
|
85
|
|
- geomInfoRepository.deleteAllByZoneId(zoneInfo1.getZoneId());
|
86
|
|
- modelInfoRepository.deleteAllByTemplateIds(Collections.singletonList(zoneInfo1.getZoneId()));
|
87
|
86
|
|
88
|
|
- // 解压压缩文件
|
89
|
|
- // 文件目录格式:
|
90
|
|
- // --geom.json
|
91
|
|
- // --models
|
92
|
|
- // ----model1.fbx 模型1文件
|
93
|
|
- // ----model2.fbx 模型2文件
|
94
|
|
- // ----model1.json 模型1材质
|
95
|
|
- // ----model2.json 模型2材质
|
96
|
|
- //
|
97
|
|
- // geom.json文件总json格式:
|
98
|
|
- // {
|
99
|
|
- // "init": {
|
100
|
|
- // "rotation": {
|
101
|
|
- // "x": 0,
|
102
|
|
- // "y": 0,
|
103
|
|
- // "z": 0,
|
104
|
|
- // "w": 0
|
105
|
|
- // },
|
106
|
|
- // "translation": {
|
107
|
|
- // "x": 0,
|
108
|
|
- // "y": 0,
|
109
|
|
- // "z": 0
|
110
|
|
- // },
|
111
|
|
- // "scale3D": {
|
112
|
|
- // "x": 0,
|
113
|
|
- // "y": 0,
|
114
|
|
- // "z": 0
|
115
|
|
- // }
|
116
|
|
- // },
|
117
|
|
- // "models": [
|
118
|
|
- // {
|
119
|
|
- // "modelPath": "model1.fbx",
|
120
|
|
- // "location": [
|
121
|
|
- // {
|
122
|
|
- // "rotation": {
|
123
|
|
- // "x": 0,
|
124
|
|
- // "y": 0,
|
125
|
|
- // "z": 0,
|
126
|
|
- // "w": 0
|
127
|
|
- // },
|
128
|
|
- // "translation": {
|
129
|
|
- // "x": 0,
|
130
|
|
- // "y": 0,
|
131
|
|
- // "z": 0
|
132
|
|
- // },
|
133
|
|
- // "scale3D": {
|
134
|
|
- // "x": 0,
|
135
|
|
- // "y": 0,
|
136
|
|
- // "z": 0
|
137
|
|
- // }
|
138
|
|
- // }
|
139
|
|
- // ]
|
140
|
|
- // }
|
141
|
|
- // ]
|
142
|
|
- // }
|
|
87
|
+ if (StringUtils.isNotBlank(zoneInfo.getTemplateFilePath())) {
|
|
88
|
+ // 清除元素与模型
|
|
89
|
+ geomInfoRepository.deleteAllByZoneId(zoneInfo1.getZoneId());
|
|
90
|
+ modelInfoRepository.deleteAllByTemplateIds(Collections.singletonList(zoneInfo1.getZoneId()));
|
|
91
|
+
|
|
92
|
+ // 解压压缩文件
|
|
93
|
+ // 文件目录格式:
|
|
94
|
+ // --geom.json
|
|
95
|
+ // --models
|
|
96
|
+ // ----model1.fbx 模型1文件
|
|
97
|
+ // ----model2.fbx 模型2文件
|
|
98
|
+ // ----model1.json 模型1材质
|
|
99
|
+ // ----model2.json 模型2材质
|
|
100
|
+ //
|
|
101
|
+ // geom.json文件总json格式:
|
|
102
|
+ // {
|
|
103
|
+ // "init": {
|
|
104
|
+ // "rotation": {
|
|
105
|
+ // "x": 0,
|
|
106
|
+ // "y": 0,
|
|
107
|
+ // "z": 0,
|
|
108
|
+ // "w": 0
|
|
109
|
+ // },
|
|
110
|
+ // "translation": {
|
|
111
|
+ // "x": 0,
|
|
112
|
+ // "y": 0,
|
|
113
|
+ // "z": 0
|
|
114
|
+ // },
|
|
115
|
+ // "scale3D": {
|
|
116
|
+ // "x": 0,
|
|
117
|
+ // "y": 0,
|
|
118
|
+ // "z": 0
|
|
119
|
+ // }
|
|
120
|
+ // },
|
|
121
|
+ // "models": [
|
|
122
|
+ // {
|
|
123
|
+ // "modelPath": "model1.fbx",
|
|
124
|
+ // "location": [
|
|
125
|
+ // {
|
|
126
|
+ // "rotation": {
|
|
127
|
+ // "x": 0,
|
|
128
|
+ // "y": 0,
|
|
129
|
+ // "z": 0,
|
|
130
|
+ // "w": 0
|
|
131
|
+ // },
|
|
132
|
+ // "translation": {
|
|
133
|
+ // "x": 0,
|
|
134
|
+ // "y": 0,
|
|
135
|
+ // "z": 0
|
|
136
|
+ // },
|
|
137
|
+ // "scale3D": {
|
|
138
|
+ // "x": 0,
|
|
139
|
+ // "y": 0,
|
|
140
|
+ // "z": 0
|
|
141
|
+ // }
|
|
142
|
+ // }
|
|
143
|
+ // ]
|
|
144
|
+ // }
|
|
145
|
+ // ]
|
|
146
|
+ // }
|
|
147
|
+ String geomJsonString = null;
|
|
148
|
+ try {
|
143
|
149
|
Unzipper.unZipFiles(new File("." + zoneInfo.getTemplateFilePath()), "./upload/template/" + zoneInfo1.getZoneId() + "/");
|
144
|
|
- String geomJsonString = Files.readString(Paths.get("./upload/template/" + zoneInfo1.getZoneId() + "/geom.json"));
|
145
|
|
- TemplateGeom templateGeom = JSON.parseObject(geomJsonString, TemplateGeom.class);
|
146
|
|
-
|
147
|
|
- zoneInfo1.setInitLocation(templateGeom.getInit());
|
148
|
|
- zoneInfoRepository.save(zoneInfo1);
|
149
|
|
-
|
150
|
|
- List<TemplateInfo> templateInfoList = templateGeom.getModels();
|
151
|
|
-
|
152
|
|
- String modelFolderPath = "./upload/template/" + zoneInfo1.getZoneId() + "/models";
|
153
|
|
- File modelFolder = new File(modelFolderPath);
|
154
|
|
- List<ModelInfo> list = new ArrayList<>();
|
155
|
|
- File[] models = modelFolder.listFiles();
|
156
|
|
- assert models != null;
|
157
|
|
- for (File model : models) {
|
158
|
|
- if (model.isFile()) {
|
159
|
|
- String modelFileName = model.getName();
|
160
|
|
- if (modelFileName.endsWith(".fbx")) {
|
161
|
|
- String modelPath = "/upload/template/" + zoneInfo1.getZoneId() + "/models/";
|
162
|
|
- if (modelFileName.matches(".*[\u4e00-\u9fa5]+.*")) {
|
163
|
|
- // 如果包含中文,重命名
|
164
|
|
- String newFileName =UUID.randomUUID() + ".fbx";
|
165
|
|
- modelPath += newFileName;
|
166
|
|
- boolean rename = model.renameTo(new File("." + modelPath));
|
167
|
|
- System.out.println(rename);
|
168
|
|
- // 材质文件也需要重命名
|
169
|
|
- File oldMaterialFile = new File("." + "/upload/template/" + zoneInfo1.getZoneId() + "/models/" + modelFileName.replace(".fbx", ".json"));
|
170
|
|
- if (oldMaterialFile.exists()) {
|
171
|
|
- File newMaterialFile = new File("." + "/upload/template/" + zoneInfo1.getZoneId() + "/models/" + newFileName.replace(".fbx", ".json"));
|
172
|
|
- rename = oldMaterialFile.renameTo(newMaterialFile);
|
173
|
|
- System.out.println(rename);
|
174
|
|
- }
|
175
|
|
- } else {
|
176
|
|
- modelPath += modelFileName;
|
177
|
|
- }
|
178
|
|
- list.add(new ModelInfo(null, null, modelFileName.substring(0, modelFileName.lastIndexOf(".")).toLowerCase(),
|
179
|
|
- null, null, null, modelPath,
|
180
|
|
- zoneInfo1.getThumbnail(), null, zoneInfo1.getZoneId()));
|
181
|
|
- }
|
|
150
|
+ geomJsonString = Files.readString(Paths.get("./upload/template/" + zoneInfo1.getZoneId() + "/geom.json"));
|
|
151
|
+ } catch (IOException e) {
|
|
152
|
+ modelInfoRepository.deleteAllByTemplateIds(Collections.singletonList(zoneInfo1.getZoneId()));
|
|
153
|
+ zoneInfoRepository.delete(zoneInfo1);
|
|
154
|
+ result.put("msg", "模板压缩文件解压失败!");
|
|
155
|
+ return result;
|
|
156
|
+ }
|
|
157
|
+ TemplateGeom templateGeom = JSON.parseObject(geomJsonString, TemplateGeom.class);
|
|
158
|
+
|
|
159
|
+ zoneInfo1.setInitLocation(templateGeom.getInit());
|
|
160
|
+ zoneInfoRepository.save(zoneInfo1);
|
|
161
|
+
|
|
162
|
+ List<TemplateInfo> templateInfoList = templateGeom.getModels();
|
|
163
|
+
|
|
164
|
+ String modelFolderPath = "./upload/template/" + zoneInfo1.getZoneId() + "/models";
|
|
165
|
+ File modelFolder = new File(modelFolderPath);
|
|
166
|
+ List<ModelInfo> list = new ArrayList<>();
|
|
167
|
+ File[] models = modelFolder.listFiles();
|
|
168
|
+ assert models != null;
|
|
169
|
+ for (File model : models) {
|
|
170
|
+ if (model.isFile()) {
|
|
171
|
+ String modelFileName = model.getName();
|
|
172
|
+ if (modelFileName.endsWith(".fbx")) {
|
|
173
|
+ String modelPath = aliOSSUtils.upload(model);
|
|
174
|
+ list.add(new ModelInfo(null, null, modelFileName.substring(0, modelFileName.lastIndexOf(".")).toLowerCase(),
|
|
175
|
+ null, null, null, modelPath,
|
|
176
|
+ zoneInfo1.getThumbnail(), null, zoneInfo1.getZoneId()));
|
182
|
177
|
}
|
183
|
178
|
}
|
184
|
|
- List<ModelInfo> modelInfoList = modelInfoRepository.saveAll(list);
|
185
|
|
- Map<String, ModelInfo> modelPathIdMap = modelInfoList
|
186
|
|
- .stream()
|
187
|
|
- .collect(Collectors.toMap(ModelInfo::getModelName, ModelInfo -> ModelInfo));
|
188
|
|
-
|
189
|
|
- List<GeomInfo> geomInfoList = new ArrayList<>();
|
190
|
|
- GeometryFactory geometryFactory = new GeometryFactory();
|
191
|
|
- int j = 1;
|
192
|
|
- for (TemplateInfo templateInfo : templateInfoList) {
|
193
|
|
-
|
194
|
|
- String modelName = templateInfo.getModelPath().substring(0, templateInfo.getModelPath().lastIndexOf(".")).toLowerCase();
|
195
|
|
- ModelInfo modelInfo = modelPathIdMap.get(modelName);
|
196
|
|
- for (int i = 0; i < templateInfo.getLocation().size(); i++) {
|
197
|
|
- JSONObject trans = templateInfo.getLocation().get(i);
|
198
|
|
- GeomInfo geomInfo = new GeomInfo();
|
199
|
|
-
|
200
|
|
- geomInfo.setGeomId(zoneInfo1.getZoneId() + "_" + j);
|
201
|
|
- geomInfo.setModelId(modelInfo.getModelId());
|
202
|
|
- geomInfo.setGeomName(modelInfo.getModelName());
|
203
|
|
- geomInfo.setZoneId(zoneInfo1.getZoneId());
|
204
|
|
- geomInfo.setLocking(false);
|
205
|
|
-
|
206
|
|
- geomInfo.setTrans(trans);
|
207
|
|
- JSONObject pointObject = trans.getJSONObject("translation");
|
208
|
|
- geomInfo.setGeom(geometryFactory.createPoint(new Coordinate(
|
209
|
|
- Double.parseDouble(pointObject.get("x").toString()),
|
210
|
|
- Double.parseDouble(pointObject.get("y").toString()),
|
211
|
|
- Double.parseDouble(pointObject.get("z").toString()))));
|
212
|
|
- j++;
|
213
|
|
- geomInfoList.add(geomInfo);
|
214
|
|
- }
|
|
179
|
+ }
|
|
180
|
+ List<ModelInfo> modelInfoList = modelInfoRepository.saveAll(list);
|
|
181
|
+ Map<String, ModelInfo> modelPathIdMap = modelInfoList
|
|
182
|
+ .stream()
|
|
183
|
+ .collect(Collectors.toMap(ModelInfo::getModelName, ModelInfo -> ModelInfo));
|
215
|
184
|
|
|
185
|
+ List<GeomInfo> geomInfoList = new ArrayList<>();
|
|
186
|
+ GeometryFactory geometryFactory = new GeometryFactory();
|
|
187
|
+ int j = 1;
|
|
188
|
+ for (TemplateInfo templateInfo : templateInfoList) {
|
|
189
|
+
|
|
190
|
+ String modelName = templateInfo.getModelPath().substring(0, templateInfo.getModelPath().lastIndexOf(".")).toLowerCase();
|
|
191
|
+ ModelInfo modelInfo = modelPathIdMap.get(modelName);
|
|
192
|
+ for (int i = 0; i < templateInfo.getLocation().size(); i++) {
|
|
193
|
+ JSONObject trans = templateInfo.getLocation().get(i);
|
|
194
|
+ GeomInfo geomInfo = new GeomInfo();
|
|
195
|
+
|
|
196
|
+ geomInfo.setGeomId(zoneInfo1.getZoneId() + "_" + j);
|
|
197
|
+ geomInfo.setModelId(modelInfo.getModelId());
|
|
198
|
+ geomInfo.setGeomName(modelInfo.getModelName());
|
|
199
|
+ geomInfo.setZoneId(zoneInfo1.getZoneId());
|
|
200
|
+ geomInfo.setLocking(false);
|
|
201
|
+
|
|
202
|
+ geomInfo.setTrans(trans);
|
|
203
|
+ JSONObject pointObject = trans.getJSONObject("translation");
|
|
204
|
+ geomInfo.setGeom(geometryFactory.createPoint(new Coordinate(
|
|
205
|
+ Double.parseDouble(pointObject.get("x").toString()),
|
|
206
|
+ Double.parseDouble(pointObject.get("y").toString()),
|
|
207
|
+ Double.parseDouble(pointObject.get("z").toString()))));
|
|
208
|
+ j++;
|
|
209
|
+ geomInfoList.add(geomInfo);
|
216
|
210
|
}
|
217
|
|
- geomInfoRepository.saveAll(geomInfoList);
|
218
|
211
|
|
219
|
212
|
}
|
220
|
|
- } catch (Exception e) {
|
221
|
|
- modelInfoRepository.deleteAllByTemplateIds(Collections.singletonList(zoneInfo1.getZoneId()));
|
222
|
|
- zoneInfoRepository.delete(zoneInfo1);
|
223
|
|
- result.put("msg", "模板压缩文件解压失败!");
|
224
|
|
- return result;
|
|
213
|
+ geomInfoRepository.saveAll(geomInfoList);
|
|
214
|
+
|
225
|
215
|
}
|
|
216
|
+
|
226
|
217
|
result.put("zone", zoneInfo1);
|
227
|
218
|
return result;
|
228
|
219
|
}
|