Explorar o código

1.修改逻辑

hellohaidie hai 3 meses
pai
achega
3a7680d403

+ 10 - 4
src/main/java/com/lqkj/link/module/zone/controller/ResourceController.java

@@ -203,13 +203,13 @@ public class ResourceController {
203 203
             )
204 204
     )
205 205
     @PostMapping("/" + VERSION_V1 + "/savePersonal")
206
-    public MessageBean<String> savePersonal(@RequestBody ModelCategory category,
206
+    public MessageBean<ModelCategory> savePersonal(@RequestBody ModelCategory category,
207 207
                                     HttpServletRequest request) {
208 208
         String authHeader = request.getHeader("Authorization");
209 209
         String userCode = jwtService.decryptUsernameWithHeader(authHeader);
210
-        String msg = resourceService.savePersonal(category, userCode);
211
-        if (StringUtils.isNotBlank(msg)) return MessageBean.error(msg);
212
-        return MessageBean.ok(null, "个人文件夹保存接口");
210
+        Map<String, Object> result = resourceService.savePersonal(category, userCode);
211
+        if (result.containsKey("msg")) return MessageBean.error(String.valueOf(result.get("msg")));
212
+        return MessageBean.ok((ModelCategory) result.get("category"), "个人文件夹保存接口");
213 213
     }
214 214
 
215 215
     @Operation(
@@ -230,4 +230,10 @@ public class ResourceController {
230 230
         return MessageBean.ok(null, "个人文件夹保存接口");
231 231
     }
232 232
 
233
+    @PostMapping("/" + VERSION_V1 + "/needRefresh")
234
+    public MessageBean<Boolean> needRefresh(HttpServletRequest request) {
235
+        String authHeader = request.getHeader("Authorization");
236
+        String userCode = jwtService.decryptUsernameWithHeader(authHeader);
237
+        return MessageBean.ok(resourceService.needRefreshResource(userCode), "资源更新检查");
238
+    }
233 239
 }

+ 3 - 3
src/main/java/com/lqkj/link/module/zone/repository/GeomInfoRepository.java

@@ -15,9 +15,9 @@ public interface GeomInfoRepository extends JpaRepository<GeomInfo, String> {
15 15
 
16 16
     @Query(nativeQuery = true,
17 17
         value = "with t1 as(select zone_id, st_makepoint(" +
18
-                    "(init_location -> 'translation' ->> 'x')::float8, " +
19
-                    "(init_location -> 'translation' ->> 'y')::float8, " +
20
-                    "(init_location -> 'translation' ->> 'z')::float8) as init from zone_info where zone_id = :zoneId) " +
18
+                    "(init_location -> 'translation' ->> 'x')\\:\\:float8, " +
19
+                    "(init_location -> 'translation' ->> 'y')\\:\\:float8, " +
20
+                    "(init_location -> 'translation' ->> 'z')\\:\\:float8) as init from zone_info where zone_id = :zoneId) " +
21 21
                 "select gi.* from geom_info gi, t1 where gi.zone_id = t1.zone_id order by st_distance(gi.geom, t1.init) "
22 22
     )
23 23
     List<GeomInfo> findAllByZoneId(Integer zoneId);

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

@@ -1,5 +1,6 @@
1 1
 package com.lqkj.link.module.zone.service;
2 2
 
3
+import com.lqkj.link.module.authority.domain.UserInfo;
3 4
 import com.lqkj.link.module.authority.repository.UserInfoRepository;
4 5
 import com.lqkj.link.module.zone.domain.ModelCategory;
5 6
 import com.lqkj.link.module.zone.domain.ModelInfo;
@@ -15,10 +16,7 @@ import org.springframework.transaction.annotation.Transactional;
15 16
 
16 17
 import java.io.File;
17 18
 import java.io.IOException;
18
-import java.util.ArrayList;
19
-import java.util.List;
20
-import java.util.Map;
21
-import java.util.UUID;
19
+import java.util.*;
22 20
 import java.util.stream.Collectors;
23 21
 
24 22
 @Service
@@ -150,22 +148,29 @@ public class ResourceService {
150 148
         return infoRepository.listWitUserCode(userCode);
151 149
     }
152 150
 
153
-    public String savePersonal(ModelCategory modelCategory, String userCode) {
151
+    public Map<String, Object> savePersonal(ModelCategory modelCategory, String userCode) {
152
+        Map<String, Object> result = new HashMap<>();
154 153
         if (modelCategory.getCategoryId() == 0) {
155 154
             modelCategory.setCategoryId(null);
156 155
         }
157 156
         Integer userId = userInfoRepository.findByUserCode(userCode).getUserId();
158 157
         if ((modelCategory.getCategoryId() != null && categoryRepository.hasSameNameByUserWithoutOne(modelCategory.getCategoryName(), modelCategory.getCategoryId(), userId))
159 158
                 || (modelCategory.getCategoryId() == null && categoryRepository.hasSameNameByUser(modelCategory.getCategoryName(), userId))) {
160
-            return "不能与已有文件夹重名!";
159
+            result.put("msg", "不能与已有文件夹重名!");
160
+            return result;
161 161
         }
162 162
         modelCategory.setUserId(userId);
163
-        categoryRepository.save(modelCategory);
164
-        return null;
163
+        modelCategory = categoryRepository.save(modelCategory);
164
+        result.put("category", modelCategory);
165
+        return result;
165 166
     }
166 167
 
167 168
     public void saveModel(ModelInfo modelInfo) {
168 169
         infoRepository.save(modelInfo);
169 170
     }
170 171
 
172
+    public Boolean needRefreshResource(String userCode) {
173
+        UserInfo userInfo = userInfoRepository.findByUserCode(userCode);
174
+        return userInfo.getRefreshResource() != null && userInfo.getRefreshResource();
175
+    }
171 176
 }