|
@@ -8,10 +8,12 @@ import com.lqkj.link.module.zone.domain.*;
|
8
|
8
|
import com.lqkj.link.module.zone.repository.GeomInfoRepository;
|
9
|
9
|
import com.lqkj.link.module.zone.repository.ModelInfoRepository;
|
10
|
10
|
import com.lqkj.link.module.zone.repository.ZoneInfoRepository;
|
|
11
|
+import com.lqkj.link.util.AliOSSUtils;
|
11
|
12
|
import com.lqkj.link.util.Unzipper;
|
12
|
13
|
import org.apache.commons.lang3.StringUtils;
|
13
|
14
|
import org.locationtech.jts.geom.Coordinate;
|
14
|
15
|
import org.locationtech.jts.geom.GeometryFactory;
|
|
16
|
+import org.springframework.beans.factory.annotation.Autowired;
|
15
|
17
|
import org.springframework.data.domain.Page;
|
16
|
18
|
import org.springframework.data.domain.PageRequest;
|
17
|
19
|
import org.springframework.data.domain.Pageable;
|
|
@@ -19,6 +21,7 @@ import org.springframework.stereotype.Service;
|
19
|
21
|
import org.springframework.transaction.annotation.Transactional;
|
20
|
22
|
|
21
|
23
|
import java.io.File;
|
|
24
|
+import java.io.IOException;
|
22
|
25
|
import java.nio.file.Files;
|
23
|
26
|
import java.nio.file.Paths;
|
24
|
27
|
import java.util.*;
|
|
@@ -31,6 +34,9 @@ public class ZoneInfoService {
|
31
|
34
|
private final GeomInfoRepository geomInfoRepository;
|
32
|
35
|
private final ModelInfoRepository modelInfoRepository;
|
33
|
36
|
|
|
37
|
+ @Autowired
|
|
38
|
+ private AliOSSUtils aliOSSUtils;
|
|
39
|
+
|
34
|
40
|
public ZoneInfoService(ZoneInfoRepository zoneInfoRepository, UserInfoRepository userInfoRepository,
|
35
|
41
|
GeomInfoRepository geomInfoRepository, ModelInfoRepository modelInfoRepository) {
|
36
|
42
|
this.zoneInfoRepository = zoneInfoRepository;
|
|
@@ -59,150 +65,137 @@ public class ZoneInfoService {
|
59
|
65
|
zoneInfo.setTemplateUse(0);
|
60
|
66
|
}
|
61
|
67
|
ZoneInfo zoneInfo1 = zoneInfoRepository.save(zoneInfo);
|
62
|
|
- try {
|
63
|
|
- if (StringUtils.isNotBlank(zoneInfo.getTemplateFilePath())) {
|
64
|
|
- // 清除元素与模型
|
65
|
|
- geomInfoRepository.deleteAllByZoneId(zoneInfo1.getZoneId());
|
66
|
|
- modelInfoRepository.deleteAllByTemplateIds(Collections.singletonList(zoneInfo1.getZoneId()));
|
67
|
68
|
|
68
|
|
- // 解压压缩文件
|
69
|
|
- // 文件目录格式:
|
70
|
|
- // --geom.json
|
71
|
|
- // --models
|
72
|
|
- // ----model1.fbx 模型1文件
|
73
|
|
- // ----model2.fbx 模型2文件
|
74
|
|
- // ----model1.json 模型1材质
|
75
|
|
- // ----model2.json 模型2材质
|
76
|
|
- //
|
77
|
|
- // geom.json文件总json格式:
|
78
|
|
- // {
|
79
|
|
- // "init": {
|
80
|
|
- // "rotation": {
|
81
|
|
- // "x": 0,
|
82
|
|
- // "y": 0,
|
83
|
|
- // "z": 0,
|
84
|
|
- // "w": 0
|
85
|
|
- // },
|
86
|
|
- // "translation": {
|
87
|
|
- // "x": 0,
|
88
|
|
- // "y": 0,
|
89
|
|
- // "z": 0
|
90
|
|
- // },
|
91
|
|
- // "scale3D": {
|
92
|
|
- // "x": 0,
|
93
|
|
- // "y": 0,
|
94
|
|
- // "z": 0
|
95
|
|
- // }
|
96
|
|
- // },
|
97
|
|
- // "models": [
|
98
|
|
- // {
|
99
|
|
- // "modelPath": "model1.fbx",
|
100
|
|
- // "location": [
|
101
|
|
- // {
|
102
|
|
- // "rotation": {
|
103
|
|
- // "x": 0,
|
104
|
|
- // "y": 0,
|
105
|
|
- // "z": 0,
|
106
|
|
- // "w": 0
|
107
|
|
- // },
|
108
|
|
- // "translation": {
|
109
|
|
- // "x": 0,
|
110
|
|
- // "y": 0,
|
111
|
|
- // "z": 0
|
112
|
|
- // },
|
113
|
|
- // "scale3D": {
|
114
|
|
- // "x": 0,
|
115
|
|
- // "y": 0,
|
116
|
|
- // "z": 0
|
117
|
|
- // }
|
118
|
|
- // }
|
119
|
|
- // ]
|
120
|
|
- // }
|
121
|
|
- // ]
|
122
|
|
- // }
|
|
69
|
+ if (StringUtils.isNotBlank(zoneInfo.getTemplateFilePath())) {
|
|
70
|
+ // 清除元素与模型
|
|
71
|
+ geomInfoRepository.deleteAllByZoneId(zoneInfo1.getZoneId());
|
|
72
|
+ modelInfoRepository.deleteAllByTemplateIds(Collections.singletonList(zoneInfo1.getZoneId()));
|
|
73
|
+
|
|
74
|
+ // 解压压缩文件
|
|
75
|
+ // 文件目录格式:
|
|
76
|
+ // --geom.json
|
|
77
|
+ // --models
|
|
78
|
+ // ----model1.fbx 模型1文件
|
|
79
|
+ // ----model2.fbx 模型2文件
|
|
80
|
+ // ----model1.json 模型1材质
|
|
81
|
+ // ----model2.json 模型2材质
|
|
82
|
+ //
|
|
83
|
+ // geom.json文件总json格式:
|
|
84
|
+ // {
|
|
85
|
+ // "init": {
|
|
86
|
+ // "rotation": {
|
|
87
|
+ // "x": 0,
|
|
88
|
+ // "y": 0,
|
|
89
|
+ // "z": 0,
|
|
90
|
+ // "w": 0
|
|
91
|
+ // },
|
|
92
|
+ // "translation": {
|
|
93
|
+ // "x": 0,
|
|
94
|
+ // "y": 0,
|
|
95
|
+ // "z": 0
|
|
96
|
+ // },
|
|
97
|
+ // "scale3D": {
|
|
98
|
+ // "x": 0,
|
|
99
|
+ // "y": 0,
|
|
100
|
+ // "z": 0
|
|
101
|
+ // }
|
|
102
|
+ // },
|
|
103
|
+ // "models": [
|
|
104
|
+ // {
|
|
105
|
+ // "modelPath": "model1.fbx",
|
|
106
|
+ // "location": [
|
|
107
|
+ // {
|
|
108
|
+ // "rotation": {
|
|
109
|
+ // "x": 0,
|
|
110
|
+ // "y": 0,
|
|
111
|
+ // "z": 0,
|
|
112
|
+ // "w": 0
|
|
113
|
+ // },
|
|
114
|
+ // "translation": {
|
|
115
|
+ // "x": 0,
|
|
116
|
+ // "y": 0,
|
|
117
|
+ // "z": 0
|
|
118
|
+ // },
|
|
119
|
+ // "scale3D": {
|
|
120
|
+ // "x": 0,
|
|
121
|
+ // "y": 0,
|
|
122
|
+ // "z": 0
|
|
123
|
+ // }
|
|
124
|
+ // }
|
|
125
|
+ // ]
|
|
126
|
+ // }
|
|
127
|
+ // ]
|
|
128
|
+ // }
|
|
129
|
+ String geomJsonString = null;
|
|
130
|
+ try {
|
123
|
131
|
Unzipper.unZipFiles(new File("." + zoneInfo.getTemplateFilePath()), "./upload/template/" + zoneInfo1.getZoneId() + "/");
|
124
|
|
- String geomJsonString = Files.readString(Paths.get("./upload/template/" + zoneInfo1.getZoneId() + "/geom.json"));
|
125
|
|
- TemplateGeom templateGeom = JSON.parseObject(geomJsonString, TemplateGeom.class);
|
126
|
|
-
|
127
|
|
- zoneInfo1.setInitLocation(templateGeom.getInit());
|
128
|
|
- zoneInfoRepository.save(zoneInfo1);
|
129
|
|
-
|
130
|
|
- List<TemplateInfo> templateInfoList = templateGeom.getModels();
|
131
|
|
-
|
132
|
|
- String modelFolderPath = "./upload/template/" + zoneInfo1.getZoneId() + "/models";
|
133
|
|
- File modelFolder = new File(modelFolderPath);
|
134
|
|
- List<ModelInfo> list = new ArrayList<>();
|
135
|
|
- File[] models = modelFolder.listFiles();
|
136
|
|
- assert models != null;
|
137
|
|
- for (File model : models) {
|
138
|
|
- if (model.isFile()) {
|
139
|
|
- String modelFileName = model.getName();
|
140
|
|
- if (modelFileName.endsWith(".fbx")) {
|
141
|
|
- String modelPath = "/upload/template/" + zoneInfo1.getZoneId() + "/models/";
|
142
|
|
- if (modelFileName.matches(".*[\u4e00-\u9fa5]+.*")) {
|
143
|
|
- // 如果包含中文,重命名
|
144
|
|
- String newFileName =UUID.randomUUID() + ".fbx";
|
145
|
|
- modelPath += newFileName;
|
146
|
|
- boolean rename = model.renameTo(new File("." + modelPath));
|
147
|
|
- System.out.println(rename);
|
148
|
|
- // 材质文件也需要重命名
|
149
|
|
- File oldMaterialFile = new File("." + "/upload/template/" + zoneInfo1.getZoneId() + "/models/" + modelFileName.replace(".fbx", ".json"));
|
150
|
|
- if (oldMaterialFile.exists()) {
|
151
|
|
- File newMaterialFile = new File("." + "/upload/template/" + zoneInfo1.getZoneId() + "/models/" + newFileName.replace(".fbx", ".json"));
|
152
|
|
- rename = oldMaterialFile.renameTo(newMaterialFile);
|
153
|
|
- System.out.println(rename);
|
154
|
|
- }
|
155
|
|
- } else {
|
156
|
|
- modelPath += modelFileName;
|
157
|
|
- }
|
158
|
|
- list.add(new ModelInfo(null, null, modelFileName.substring(0, modelFileName.lastIndexOf(".")).toLowerCase(),
|
159
|
|
- null, null, null, modelPath,
|
160
|
|
- zoneInfo1.getThumbnail(), null, zoneInfo1.getZoneId()));
|
161
|
|
- }
|
|
132
|
+ geomJsonString = Files.readString(Paths.get("./upload/template/" + zoneInfo1.getZoneId() + "/geom.json"));
|
|
133
|
+ } catch (IOException e) {
|
|
134
|
+ modelInfoRepository.deleteAllByTemplateIds(Collections.singletonList(zoneInfo1.getZoneId()));
|
|
135
|
+ zoneInfoRepository.delete(zoneInfo1);
|
|
136
|
+ result.put("msg", "模板压缩文件解压失败!");
|
|
137
|
+ return result;
|
|
138
|
+ }
|
|
139
|
+ TemplateGeom templateGeom = JSON.parseObject(geomJsonString, TemplateGeom.class);
|
|
140
|
+
|
|
141
|
+ zoneInfo1.setInitLocation(templateGeom.getInit());
|
|
142
|
+ zoneInfoRepository.save(zoneInfo1);
|
|
143
|
+
|
|
144
|
+ List<TemplateInfo> templateInfoList = templateGeom.getModels();
|
|
145
|
+
|
|
146
|
+ String modelFolderPath = "./upload/template/" + zoneInfo1.getZoneId() + "/models";
|
|
147
|
+ File modelFolder = new File(modelFolderPath);
|
|
148
|
+ List<ModelInfo> list = new ArrayList<>();
|
|
149
|
+ File[] models = modelFolder.listFiles();
|
|
150
|
+ assert models != null;
|
|
151
|
+ for (File model : models) {
|
|
152
|
+ if (model.isFile()) {
|
|
153
|
+ String modelFileName = model.getName();
|
|
154
|
+ if (modelFileName.endsWith(".fbx")) {
|
|
155
|
+ String modelPath = aliOSSUtils.upload(model);
|
|
156
|
+ list.add(new ModelInfo(null, null, modelFileName.substring(0, modelFileName.lastIndexOf(".")).toLowerCase(),
|
|
157
|
+ null, null, null, modelPath,
|
|
158
|
+ zoneInfo1.getThumbnail(), null, zoneInfo1.getZoneId()));
|
162
|
159
|
}
|
163
|
160
|
}
|
164
|
|
- List<ModelInfo> modelInfoList = modelInfoRepository.saveAll(list);
|
165
|
|
- Map<String, ModelInfo> modelPathIdMap = modelInfoList
|
166
|
|
- .stream()
|
167
|
|
- .collect(Collectors.toMap(ModelInfo::getModelName, ModelInfo -> ModelInfo));
|
168
|
|
-
|
169
|
|
- List<GeomInfo> geomInfoList = new ArrayList<>();
|
170
|
|
- GeometryFactory geometryFactory = new GeometryFactory();
|
171
|
|
- int j = 1;
|
172
|
|
- for (TemplateInfo templateInfo : templateInfoList) {
|
173
|
|
-
|
174
|
|
- String modelName = templateInfo.getModelPath().substring(0, templateInfo.getModelPath().lastIndexOf(".")).toLowerCase();
|
175
|
|
- ModelInfo modelInfo = modelPathIdMap.get(modelName);
|
176
|
|
- for (int i = 0; i < templateInfo.getLocation().size(); i++) {
|
177
|
|
- JSONObject trans = templateInfo.getLocation().get(i);
|
178
|
|
- GeomInfo geomInfo = new GeomInfo();
|
179
|
|
-
|
180
|
|
- geomInfo.setGeomId(zoneInfo1.getZoneId() + "_" + j);
|
181
|
|
- geomInfo.setModelId(modelInfo.getModelId());
|
182
|
|
- geomInfo.setGeomName(modelInfo.getModelName());
|
183
|
|
- geomInfo.setZoneId(zoneInfo1.getZoneId());
|
184
|
|
- geomInfo.setLocking(false);
|
185
|
|
-
|
186
|
|
- geomInfo.setTrans(trans);
|
187
|
|
- JSONObject pointObject = trans.getJSONObject("translation");
|
188
|
|
- geomInfo.setGeom(geometryFactory.createPoint(new Coordinate(
|
189
|
|
- Double.parseDouble(pointObject.get("x").toString()),
|
190
|
|
- Double.parseDouble(pointObject.get("y").toString()),
|
191
|
|
- Double.parseDouble(pointObject.get("z").toString()))));
|
192
|
|
- j++;
|
193
|
|
- geomInfoList.add(geomInfo);
|
194
|
|
- }
|
|
161
|
+ }
|
|
162
|
+ List<ModelInfo> modelInfoList = modelInfoRepository.saveAll(list);
|
|
163
|
+ Map<String, ModelInfo> modelPathIdMap = modelInfoList
|
|
164
|
+ .stream()
|
|
165
|
+ .collect(Collectors.toMap(ModelInfo::getModelName, ModelInfo -> ModelInfo));
|
195
|
166
|
|
|
167
|
+ List<GeomInfo> geomInfoList = new ArrayList<>();
|
|
168
|
+ GeometryFactory geometryFactory = new GeometryFactory();
|
|
169
|
+ int j = 1;
|
|
170
|
+ for (TemplateInfo templateInfo : templateInfoList) {
|
|
171
|
+
|
|
172
|
+ String modelName = templateInfo.getModelPath().substring(0, templateInfo.getModelPath().lastIndexOf(".")).toLowerCase();
|
|
173
|
+ ModelInfo modelInfo = modelPathIdMap.get(modelName);
|
|
174
|
+ for (int i = 0; i < templateInfo.getLocation().size(); i++) {
|
|
175
|
+ JSONObject trans = templateInfo.getLocation().get(i);
|
|
176
|
+ GeomInfo geomInfo = new GeomInfo();
|
|
177
|
+
|
|
178
|
+ geomInfo.setGeomId(zoneInfo1.getZoneId() + "_" + j);
|
|
179
|
+ geomInfo.setModelId(modelInfo.getModelId());
|
|
180
|
+ geomInfo.setGeomName(modelInfo.getModelName());
|
|
181
|
+ geomInfo.setZoneId(zoneInfo1.getZoneId());
|
|
182
|
+ geomInfo.setLocking(false);
|
|
183
|
+
|
|
184
|
+ geomInfo.setTrans(trans);
|
|
185
|
+ JSONObject pointObject = trans.getJSONObject("translation");
|
|
186
|
+ geomInfo.setGeom(geometryFactory.createPoint(new Coordinate(
|
|
187
|
+ Double.parseDouble(pointObject.get("x").toString()),
|
|
188
|
+ Double.parseDouble(pointObject.get("y").toString()),
|
|
189
|
+ Double.parseDouble(pointObject.get("z").toString()))));
|
|
190
|
+ j++;
|
|
191
|
+ geomInfoList.add(geomInfo);
|
196
|
192
|
}
|
197
|
|
- geomInfoRepository.saveAll(geomInfoList);
|
198
|
193
|
|
199
|
194
|
}
|
200
|
|
- } catch (Exception e) {
|
201
|
|
- modelInfoRepository.deleteAllByTemplateIds(Collections.singletonList(zoneInfo1.getZoneId()));
|
202
|
|
- zoneInfoRepository.delete(zoneInfo1);
|
203
|
|
- result.put("msg", "模板压缩文件解压失败!");
|
204
|
|
- return result;
|
|
195
|
+ geomInfoRepository.saveAll(geomInfoList);
|
|
196
|
+
|
205
|
197
|
}
|
|
198
|
+
|
206
|
199
|
result.put("zone", zoneInfo1);
|
207
|
200
|
return result;
|
208
|
201
|
}
|