浏览代码

对象信息管理-新增贴图和颜色

liaoyitao 3 月之前
父节点
当前提交
e72631b540

+ 1 - 1
src/main/java/com/lqkj/link/GlobalExceptionHandler.java

@@ -15,7 +15,7 @@ public class GlobalExceptionHandler {
15 15
 
16 16
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
17 17
 
18
-    @ExceptionHandler
18
+    @ExceptionHandler(Exception.class)
19 19
     @ResponseBody
20 20
     public MessageBean<String> resolveException(Exception e) {
21 21
         logger.error("收到异常", e);

+ 1 - 0
src/main/java/com/lqkj/link/module/authority/service/UserInfoService.java

@@ -301,6 +301,7 @@ public class UserInfoService {
301 301
      * @param movingSpeed
302 302
      * @param userCode
303 303
      */
304
+    @Transactional
304 305
     public void saveSettings(Integer autosaveTime, Integer movingSpeed, String userCode) {
305 306
         userInfoRepository.saveSettings(autosaveTime, movingSpeed, userCode);
306 307
     }

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

@@ -184,12 +184,10 @@ public class ResourceController {
184 184
             description = "5.1.2.20 模型列表接口"
185 185
     )
186 186
     @PostMapping("/" + VERSION_V1 + "/models")
187
-    public List<ModelInfo> models(@RequestParam(required = false) Integer categoryId,
188
-                                  @RequestParam(required = false, defaultValue = "") String modelName,
189
-                                  HttpServletRequest request) {
187
+    public List<ModelInfo> models(HttpServletRequest request) {
190 188
         String authHeader = request.getHeader("Authorization");
191 189
         String userCode = jwtService.decryptUsernameWithHeader(authHeader);
192
-        return resourceService.models(userCode, categoryId, modelName);
190
+        return resourceService.models(userCode);
193 191
     }
194 192
 
195 193
     @Operation(

+ 59 - 0
src/main/java/com/lqkj/link/module/zone/controller/TextureInfoController.java

@@ -0,0 +1,59 @@
1
+package com.lqkj.link.module.zone.controller;
2
+
3
+import com.lqkj.link.message.MessageBean;
4
+import com.lqkj.link.module.zone.domain.TextureInfo;
5
+import com.lqkj.link.module.zone.service.TextureInfoService;
6
+import io.swagger.v3.oas.annotations.tags.Tag;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.web.bind.annotation.*;
9
+
10
+import java.util.List;
11
+
12
+@RestController
13
+@RequestMapping("/texture")
14
+@Tag(name = "贴图管理", description = "贴图管理")
15
+public class TextureInfoController {
16
+
17
+    @Autowired
18
+    private TextureInfoService textureInfoService;
19
+
20
+
21
+    /**
22
+     * 保存贴图
23
+     * @param textureInfo
24
+     * @return
25
+     */
26
+    @PostMapping("/save")
27
+    public MessageBean save(@RequestBody TextureInfo textureInfo) {
28
+        textureInfoService.sava(textureInfo);
29
+        return MessageBean.ok(null, "保存贴图成功");
30
+    }
31
+
32
+    /**
33
+     * 批量删除贴图
34
+     * @param materialIds
35
+     * @return
36
+     */
37
+
38
+    @PostMapping("/batchDelete")
39
+    public MessageBean batchDelete(@RequestParam List<Integer> materialIds){
40
+        textureInfoService.batchDelete(materialIds);
41
+        return MessageBean.ok(null, "删除贴图成功");
42
+    }
43
+
44
+
45
+    /**
46
+     * 获取全部贴图
47
+     * @param name
48
+     * @return
49
+     */
50
+    @PostMapping("/getAll")
51
+    public MessageBean<List<TextureInfo>> getAll(@RequestParam(required = false, defaultValue = "") String name,
52
+                                                 @RequestParam(required = false) Integer userId) {
53
+        return MessageBean.ok(textureInfoService.getAll(name, userId), "贴图分页接口");
54
+
55
+    }
56
+
57
+
58
+
59
+}

+ 14 - 0
src/main/java/com/lqkj/link/module/zone/domain/GeomInfo.java

@@ -77,6 +77,20 @@ public class GeomInfo {
77 77
     @Column(name = "material_id")
78 78
     private Integer materialId;
79 79
 
80
+    /**
81
+     * 贴图ID
82
+     * @return
83
+     */
84
+    @Column(name = "texture_id")
85
+    private Integer textureId;
86
+
87
+    /**
88
+     * 颜色
89
+     * @return
90
+     */
91
+    @Column(name = "color")
92
+    private String color;
93
+
80 94
     public JSONObject getLocation() {
81 95
         if (location == null) return trans;
82 96
         return location;

+ 1 - 1
src/main/java/com/lqkj/link/module/zone/domain/MaterialInfo.java

@@ -40,7 +40,7 @@ public class MaterialInfo {
40 40
     @Schema(description = "材质图标")
41 41
     private String materialIcon;
42 42
 
43
-    @Column(name = "json_file_name")
43
+    @Transient
44 44
     @Schema(description = "json文件名")
45 45
     private String compressFileName;
46 46
 

+ 38 - 0
src/main/java/com/lqkj/link/module/zone/domain/TextureInfo.java

@@ -0,0 +1,38 @@
1
+package com.lqkj.link.module.zone.domain;
2
+
3
+
4
+import io.swagger.v3.oas.annotations.media.Schema;
5
+import jakarta.persistence.*;
6
+import lombok.AllArgsConstructor;
7
+import lombok.Getter;
8
+import lombok.NoArgsConstructor;
9
+import lombok.Setter;
10
+
11
+@Entity
12
+@Table(name = "texture_info")
13
+@Getter
14
+@Setter
15
+@NoArgsConstructor
16
+@AllArgsConstructor
17
+public class TextureInfo {
18
+
19
+
20
+    @Id
21
+    @Column(name = "texture_id")
22
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
23
+    @Schema(description = "贴图ID")
24
+    private Integer textureId;
25
+
26
+    @Column(name = "texture_name")
27
+    @Schema(description = "贴图名称")
28
+    private String textureName;
29
+
30
+    @Column(name = "texture_path")
31
+    @Schema(description = "文件路径")
32
+    private String texturePath;
33
+
34
+    @Column(name = "user_id")
35
+    @Schema(description = "用户id")
36
+    private Integer userId;
37
+
38
+}

+ 1 - 1
src/main/java/com/lqkj/link/module/zone/repository/MaterialInfoRepository.java

@@ -40,7 +40,7 @@ public interface MaterialInfoRepository extends JpaRepository<MaterialInfo, Inte
40 40
     @Query(nativeQuery = true,
41 41
             value = "select * from material_info where " +
42 42
                     "(:materialName = '' or material_name like concat('%', :materialName, '%')) " +
43
-                    "and material_type = :materialType " +
43
+                    "and (:materialType is null or material_type = :materialType) " +
44 44
                     "and (:userId is null or user_id = :userId) " +
45 45
                     "order by update_time"
46 46
     )

+ 2 - 8
src/main/java/com/lqkj/link/module/zone/repository/ModelInfoRepository.java

@@ -21,15 +21,9 @@ public interface ModelInfoRepository extends JpaRepository<ModelInfo, Integer> {
21 21
         value = "select mi.* from model_info mi " +
22 22
                 "left join model_category mc on mi.category_id = mc.category_id " +
23 23
                 "left join user_info ui on mc.user_id = ui.user_id " +
24
-                "where " +
25
-                "(:modelName = '' or mi.model_name like concat('%', :modelName, '%')) " +
26
-                "and (:categoryId = 0 or mi.category_id = :categoryId) " +
27
-                "and mc.user_id is null or ui.user_code = :userCode " +
28
-                "order by mi.order_id"
24
+                "where mc.user_id is null or ui.user_code = :userCode order by mi.order_id"
29 25
     )
30
-    List<ModelInfo> listWitUserCode(@Param("userCode") String userCode,
31
-                                    @Param("categoryId") Integer categoryId,
32
-                                    @Param("modelName") String modelName);
26
+    List<ModelInfo> listWitUserCode(@Param("userCode") String userCode);
33 27
 
34 28
     @Query("select t from ModelInfo t where t.categoryId = :categoryId")
35 29
     List<ModelInfo> listWithCategory(@Param("categoryId") Integer categoryId);

+ 58 - 0
src/main/java/com/lqkj/link/module/zone/repository/TextureInfoRepository.java

@@ -0,0 +1,58 @@
1
+package com.lqkj.link.module.zone.repository;
2
+
3
+import com.lqkj.link.module.zone.domain.TextureInfo;
4
+import org.springframework.data.domain.Page;
5
+import org.springframework.data.domain.Pageable;
6
+import org.springframework.data.jpa.repository.JpaRepository;
7
+import org.springframework.data.jpa.repository.Query;
8
+import org.springframework.data.repository.query.Param;
9
+import org.springframework.stereotype.Repository;
10
+
11
+import java.util.List;
12
+
13
+@Repository
14
+public interface TextureInfoRepository extends JpaRepository<TextureInfo, Integer> {
15
+
16
+    /**
17
+     * 判断是否重名
18
+     * @param textureId
19
+     * @param textureName
20
+     * @return
21
+     */
22
+    @Query(nativeQuery = true,
23
+            value = "select count(*) > 0 from texture_info where texture_name = :textureName and texture_id != :textureId"
24
+    )
25
+    boolean hasSameNameWithoutOne(@Param("textureId") Integer textureId,
26
+                                  @Param("textureName")String textureName);
27
+
28
+
29
+    /**
30
+     * 判断是否重名
31
+     * @param textureName
32
+     * @return
33
+     */
34
+    @Query(nativeQuery = true,
35
+            value = "select count(*) > 0 from texture_info where texture_name = :textureName"
36
+    )
37
+    boolean hasSameName(@Param("textureName") String textureName);
38
+
39
+
40
+    @Query(nativeQuery = true,
41
+            value = "select * from texture_info where " +
42
+                    "(:textureName = '' or texture_name like concat('%', :textureName, '%')) " +
43
+                    "and texture_type = :textureType " +
44
+                    "and (:userId is null or user_id = :userId) " +
45
+                    "order by update_time"
46
+    )
47
+    Page<TextureInfo> pageQuery(@Param("textureName") String textureName,
48
+                                 @Param("textureType") Integer textureType,
49
+                                 Pageable pageable,
50
+                                 @Param("userId") Integer userId);
51
+
52
+    @Query(nativeQuery = true,
53
+            value = "select * from texture_info where " +
54
+                    "(:name = '' or texture_name like concat('%', :name, '%')) " +
55
+                    "and (:userId is null or user_id = :userId) "
56
+    )
57
+    List<TextureInfo> getAll(String name, Integer userId);
58
+}

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

@@ -149,8 +149,8 @@ public class ResourceService {
149 149
         return categoryRepository.queryWithUserCode(userCode);
150 150
     }
151 151
 
152
-    public List<ModelInfo> models(String userCode, Integer categoryId, String modelName) {
153
-        return infoRepository.listWitUserCode(userCode, categoryId, modelName);
152
+    public List<ModelInfo> models(String userCode) {
153
+        return infoRepository.listWitUserCode(userCode);
154 154
     }
155 155
 
156 156
     public Map<String, Object> savePersonal(ModelCategory modelCategory, String userCode) {

+ 30 - 0
src/main/java/com/lqkj/link/module/zone/service/TextureInfoService.java

@@ -0,0 +1,30 @@
1
+package com.lqkj.link.module.zone.service;
2
+
3
+import com.lqkj.link.module.zone.domain.TextureInfo;
4
+import org.springframework.data.domain.Page;
5
+
6
+import java.util.List;
7
+
8
+public interface TextureInfoService {
9
+
10
+
11
+    /**
12
+     * 保存材质
13
+     * @param textureInfo
14
+     * @return
15
+     */
16
+    void sava(TextureInfo textureInfo);
17
+
18
+    /**
19
+     * 批量删除材质
20
+     * @param materialId
21
+     */
22
+    void batchDelete(List<Integer> materialId);
23
+
24
+    /**
25
+     * 获取全部贴图
26
+     * @param name
27
+     * @return
28
+     */
29
+    List<TextureInfo> getAll(String name, Integer userId);
30
+}

+ 59 - 0
src/main/java/com/lqkj/link/module/zone/service/impl/TextureInfoServiceImpl.java

@@ -0,0 +1,59 @@
1
+package com.lqkj.link.module.zone.service.impl;
2
+
3
+import cn.hutool.core.util.RandomUtil;
4
+import com.lqkj.link.module.authority.repository.UserInfoRepository;
5
+import com.lqkj.link.module.zone.domain.TextureInfo;
6
+import com.lqkj.link.module.zone.repository.TextureInfoRepository;
7
+import com.lqkj.link.module.zone.service.TextureInfoService;
8
+import com.lqkj.link.util.Unzipper;
9
+import org.apache.commons.lang3.StringUtils;
10
+import org.springframework.beans.factory.annotation.Autowired;
11
+import org.springframework.data.domain.Page;
12
+import org.springframework.data.domain.PageRequest;
13
+import org.springframework.data.domain.Pageable;
14
+import org.springframework.stereotype.Service;
15
+import org.springframework.transaction.annotation.Transactional;
16
+
17
+import java.io.File;
18
+import java.io.IOException;
19
+import java.util.*;
20
+import java.util.stream.Collectors;
21
+
22
+@Service
23
+public class TextureInfoServiceImpl implements TextureInfoService {
24
+
25
+    @Autowired
26
+    private TextureInfoRepository textureInfoRepository;
27
+
28
+    @Autowired
29
+    private UserInfoRepository userInfoRepository;
30
+
31
+    @Transactional
32
+    @Override
33
+    public void sava(TextureInfo textureInfo) {
34
+        if ((Objects.nonNull(textureInfo.getTextureId()) && textureInfoRepository.hasSameNameWithoutOne(textureInfo.getTextureId(), textureInfo.getTextureName()))
35
+            || (Objects.isNull(textureInfo.getTextureId()) && textureInfoRepository.hasSameName(textureInfo.getTextureName()))) {
36
+            throw new RuntimeException("贴图名称不能重复!");
37
+        }
38
+        textureInfoRepository.save(textureInfo);
39
+        userInfoRepository.updateRefreshStatus();
40
+    }
41
+
42
+    @Transactional
43
+    @Override
44
+    public void batchDelete(List<Integer> textureId) {
45
+        textureInfoRepository.deleteAllById(textureId);
46
+        // 更新用户资源刷新状态
47
+        userInfoRepository.updateRefreshStatus();
48
+    }
49
+
50
+    @Override
51
+    public List<TextureInfo> getAll(String name, Integer userId) {
52
+
53
+        return textureInfoRepository.getAll(name, userId);
54
+    }
55
+
56
+    
57
+
58
+
59
+}

+ 29 - 0
src/main/resources/db/migration/V11__2.0.6.sql

@@ -0,0 +1,29 @@
1
+
2
+create table if not exists texture_info
3
+(
4
+    texture_id      SERIAL             not null,
5
+    texture_name    VARCHAR(255)       null,
6
+    texture_path    VARCHAR(255)       null,
7
+    user_id         int                null,
8
+    constraint PK_TEXTURE_INFO primary key (texture_id)
9
+);
10
+comment on table texture_info is
11
+'贴图信息表';
12
+comment on column texture_info.texture_id is
13
+'贴图id';
14
+comment on column texture_info.texture_name is
15
+'贴图名称';
16
+comment on column texture_info.texture_path is
17
+'贴图路径';
18
+comment on column texture_info.user_id is
19
+'用户id';
20
+
21
+ALTER TABLE geom_info
22
+    add COLUMN if not exists texture_id int;
23
+comment on column geom_info.texture_id is '贴图id';
24
+
25
+ALTER TABLE geom_info
26
+    add COLUMN if not exists color VARCHAR(255);
27
+comment on column geom_info.color is '颜色';
28
+
29
+