|
@@ -30,9 +30,6 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
|
30
|
30
|
@Transactional
|
31
|
31
|
@Override
|
32
|
32
|
public void sava(MaterialInfo materialInfo) {
|
33
|
|
- if (materialInfo.getCompressFileName() != null) {
|
34
|
|
- materialInfo.setMaterialName(StringUtils.split(materialInfo.getCompressFileName(), ".")[0]);
|
35
|
|
- }
|
36
|
33
|
if ((Objects.nonNull(materialInfo.getMaterialId()) && materialInfoRepository.hasSameNameWithoutOne(materialInfo.getMaterialId(), materialInfo.getMaterialName()))
|
37
|
34
|
|| (Objects.isNull(materialInfo.getMaterialId()) && materialInfoRepository.hasSameName(materialInfo.getMaterialName()))) {
|
38
|
35
|
throw new RuntimeException("材质名称不能重复!");
|
|
@@ -61,56 +58,56 @@ public class MaterialInfoServiceImpl implements MaterialInfoService {
|
61
|
58
|
@Override
|
62
|
59
|
public void batchAdd(String compressFilePath) {
|
63
|
60
|
|
64
|
|
- try {
|
65
|
|
- String unzipPath = "./upload/resource/material" + RandomUtil.randomNumbers(5) + "/";
|
66
|
|
- Unzipper.unZipFiles(new File("." + compressFilePath), unzipPath);
|
67
|
|
- Map<String, MaterialInfo> materialMap = materialInfoRepository.findAll().stream().collect(Collectors.toMap(MaterialInfo::getMaterialName, materialInfo -> materialInfo));
|
68
|
|
-
|
69
|
|
- String modelFolderPath = unzipPath + "model";
|
70
|
|
- File materialModelDir = new File(modelFolderPath);
|
71
|
|
- if (materialModelDir.isDirectory()){
|
72
|
|
- List<MaterialInfo> materialInfoList = new ArrayList<>();
|
73
|
|
- File[] jsonFiles = materialModelDir.listFiles();
|
74
|
|
- assert jsonFiles != null;
|
75
|
|
- for (File jsonFile : jsonFiles) {
|
76
|
|
- if (jsonFile.isFile() && jsonFile.getName().endsWith(".json")) {
|
77
|
|
- String modelFileName = jsonFile.getName();
|
78
|
|
- String modelPath = unzipPath + "model/";
|
79
|
|
- if (modelFileName.matches(".*[一-龥]+.*")) {
|
80
|
|
- // 如果包含中文,重命名
|
81
|
|
- String newFileName = UUID.randomUUID() + ".json";
|
82
|
|
- modelPath += newFileName;
|
83
|
|
- boolean rename = jsonFile.renameTo(new File(modelPath));
|
84
|
|
- System.out.println(rename);
|
85
|
|
- // 材质图标也要重命名
|
86
|
|
- File oldIconFile = new File(unzipPath + "icon/" + modelFileName.replace(".json", ".png"));
|
87
|
|
- if (oldIconFile.exists()) {
|
88
|
|
- File newIconFile = new File(unzipPath + "icon/" + newFileName.replace(".json", ".png"));
|
89
|
|
- rename = oldIconFile.renameTo(newIconFile);
|
90
|
|
- System.out.println(rename);
|
91
|
|
- }
|
92
|
|
- } else {
|
93
|
|
- modelPath += modelFileName;
|
94
|
|
- }
|
95
|
|
- if (!materialMap.containsKey(modelFileName.substring(0, modelFileName.lastIndexOf(".")))) {
|
96
|
|
- materialInfoList.add(new MaterialInfo(null, modelFileName.substring(0, modelFileName.lastIndexOf(".")), modelPath.substring(1),
|
97
|
|
- modelPath.replace("model", "icon").replace("json", "png").substring(1), modelFileName, 1, new Date(), null, null));
|
98
|
|
- } else {
|
99
|
|
- MaterialInfo materialInfo = materialMap.get(modelFileName.substring(0, modelFileName.lastIndexOf(".")));
|
100
|
|
- materialInfo.setMaterialIcon(modelPath.replace("model", "icon").replace("json", "png").substring(1));
|
101
|
|
- materialInfo.setCompressFileName(modelFileName.substring(1));
|
102
|
|
- materialInfo.setJsonPath(modelPath);
|
103
|
|
- materialInfo.setUpdateTime(new Date());
|
104
|
|
- materialInfoList.add(materialInfo);
|
105
|
|
- }
|
106
|
|
- }
|
107
|
|
- }
|
108
|
|
- materialInfoRepository.saveAll(materialInfoList);
|
109
|
|
- }
|
110
|
|
- userInfoRepository.updateRefreshStatus();
|
111
|
|
- } catch (IOException e) {
|
112
|
|
- throw new RuntimeException(e);
|
113
|
|
- }
|
|
61
|
+// try {
|
|
62
|
+// String unzipPath = "./upload/resource/material" + RandomUtil.randomNumbers(5) + "/";
|
|
63
|
+// Unzipper.unZipFiles(new File("." + compressFilePath), unzipPath);
|
|
64
|
+// Map<String, MaterialInfo> materialMap = materialInfoRepository.findAll().stream().collect(Collectors.toMap(MaterialInfo::getMaterialName, materialInfo -> materialInfo));
|
|
65
|
+//
|
|
66
|
+// String modelFolderPath = unzipPath + "model";
|
|
67
|
+// File materialModelDir = new File(modelFolderPath);
|
|
68
|
+// if (materialModelDir.isDirectory()){
|
|
69
|
+// List<MaterialInfo> materialInfoList = new ArrayList<>();
|
|
70
|
+// File[] jsonFiles = materialModelDir.listFiles();
|
|
71
|
+// assert jsonFiles != null;
|
|
72
|
+// for (File jsonFile : jsonFiles) {
|
|
73
|
+// if (jsonFile.isFile() && jsonFile.getName().endsWith(".json")) {
|
|
74
|
+// String modelFileName = jsonFile.getName();
|
|
75
|
+// String modelPath = unzipPath + "model/";
|
|
76
|
+// if (modelFileName.matches(".*[一-龥]+.*")) {
|
|
77
|
+// // 如果包含中文,重命名
|
|
78
|
+// String newFileName = UUID.randomUUID() + ".json";
|
|
79
|
+// modelPath += newFileName;
|
|
80
|
+// boolean rename = jsonFile.renameTo(new File(modelPath));
|
|
81
|
+// System.out.println(rename);
|
|
82
|
+// // 材质图标也要重命名
|
|
83
|
+// File oldIconFile = new File(unzipPath + "icon/" + modelFileName.replace(".json", ".png"));
|
|
84
|
+// if (oldIconFile.exists()) {
|
|
85
|
+// File newIconFile = new File(unzipPath + "icon/" + newFileName.replace(".json", ".png"));
|
|
86
|
+// rename = oldIconFile.renameTo(newIconFile);
|
|
87
|
+// System.out.println(rename);
|
|
88
|
+// }
|
|
89
|
+// } else {
|
|
90
|
+// modelPath += modelFileName;
|
|
91
|
+// }
|
|
92
|
+// if (!materialMap.containsKey(modelFileName.substring(0, modelFileName.lastIndexOf(".")))) {
|
|
93
|
+// materialInfoList.add(new MaterialInfo(null, modelFileName.substring(0, modelFileName.lastIndexOf(".")), modelPath.substring(1),
|
|
94
|
+// modelPath.replace("model", "icon").replace("json", "png").substring(1), modelFileName, 1, new Date(), null, null, ));
|
|
95
|
+// } else {
|
|
96
|
+// MaterialInfo materialInfo = materialMap.get(modelFileName.substring(0, modelFileName.lastIndexOf(".")));
|
|
97
|
+// materialInfo.setMaterialIcon(modelPath.replace("model", "icon").replace("json", "png").substring(1));
|
|
98
|
+// materialInfo.setCompressFileName(modelFileName.substring(1));
|
|
99
|
+// materialInfo.setJsonPath(modelPath);
|
|
100
|
+// materialInfo.setUpdateTime(new Date());
|
|
101
|
+// materialInfoList.add(materialInfo);
|
|
102
|
+// }
|
|
103
|
+// }
|
|
104
|
+// }
|
|
105
|
+// materialInfoRepository.saveAll(materialInfoList);
|
|
106
|
+// }
|
|
107
|
+// userInfoRepository.updateRefreshStatus();
|
|
108
|
+// } catch (IOException e) {
|
|
109
|
+// throw new RuntimeException(e);
|
|
110
|
+// }
|
114
|
111
|
}
|
115
|
112
|
|
116
|
113
|
@Override
|