|
@@ -4,6 +4,7 @@ import com.lqkj.link.module.authority.domain.UserInfo;
|
4
|
4
|
import com.lqkj.link.module.authority.repository.UserInfoRepository;
|
5
|
5
|
import com.lqkj.link.module.zone.domain.ModelCategory;
|
6
|
6
|
import com.lqkj.link.module.zone.domain.ModelInfo;
|
|
7
|
+import com.lqkj.link.module.zone.repository.GeomInfoRepository;
|
7
|
8
|
import com.lqkj.link.module.zone.repository.ModelCategoryRepository;
|
8
|
9
|
import com.lqkj.link.module.zone.repository.ModelInfoRepository;
|
9
|
10
|
import com.lqkj.link.util.AliOSSUtils;
|
|
@@ -11,6 +12,7 @@ import com.lqkj.link.util.FileUtils;
|
11
|
12
|
import com.lqkj.link.util.Unzipper;
|
12
|
13
|
import jakarta.servlet.http.HttpServletRequest;
|
13
|
14
|
import org.apache.commons.compress.archivers.ArchiveException;
|
|
15
|
+import org.checkerframework.checker.units.qual.A;
|
14
|
16
|
import org.springframework.beans.factory.annotation.Autowired;
|
15
|
17
|
import org.springframework.data.domain.Page;
|
16
|
18
|
import org.springframework.data.domain.PageRequest;
|
|
@@ -32,6 +34,9 @@ public class ResourceService {
|
32
|
34
|
@Autowired
|
33
|
35
|
private AliOSSUtils aliOSSUtils;
|
34
|
36
|
|
|
37
|
+ @Autowired
|
|
38
|
+ private GeomInfoRepository geomInfoRepository;
|
|
39
|
+
|
35
|
40
|
public ResourceService(ModelCategoryRepository categoryRepository, ModelInfoRepository infoRepository, UserInfoRepository userInfoRepository) {
|
36
|
41
|
this.categoryRepository = categoryRepository;
|
37
|
42
|
this.infoRepository = infoRepository;
|
|
@@ -62,6 +67,7 @@ public class ResourceService {
|
62
|
67
|
category = categoryRepository.save(category);
|
63
|
68
|
String filePath = category.getCompressFilePath();
|
64
|
69
|
if (uploadCompress) {
|
|
70
|
+ checkIsReferenced(category.getCategoryId());
|
65
|
71
|
// infoRepository.deleteWithCategory(category.getCategoryId());
|
66
|
72
|
// Unzipper.unzip("." + filePath, "./upload/resource/" + category.getCategoryId() + "/", false);
|
67
|
73
|
Unzipper.unZipFiles(new File("." + filePath), "./upload/resource/" + category.getCategoryId() + "/");
|
|
@@ -122,6 +128,14 @@ public class ResourceService {
|
122
|
128
|
return null;
|
123
|
129
|
}
|
124
|
130
|
|
|
131
|
+ private void checkIsReferenced(Integer categoryId) {
|
|
132
|
+ List<Integer> infoIds = infoRepository.findByCategoryId(categoryId);
|
|
133
|
+ Integer count = geomInfoRepository.findByModelIdIn(infoIds);
|
|
134
|
+ if (count > 0) {
|
|
135
|
+ throw new RuntimeException("资源被引用,无法修改和删除");
|
|
136
|
+ }
|
|
137
|
+ }
|
|
138
|
+
|
125
|
139
|
public void deleteModel(Integer modelId) {
|
126
|
140
|
ModelInfo modelInfo = infoRepository.findById(modelId).get();
|
127
|
141
|
infoRepository.deleteById(modelId);
|
|
@@ -130,6 +144,7 @@ public class ResourceService {
|
130
|
144
|
|
131
|
145
|
@Transactional
|
132
|
146
|
public void deleteCategory(List<Integer> categoryId) {
|
|
147
|
+ categoryId.forEach(this::checkIsReferenced);
|
133
|
148
|
deleteOssFiles(categoryId);
|
134
|
149
|
categoryRepository.deleteAllByIdInBatch(categoryId);
|
135
|
150
|
// 更新用户资源刷新状态
|