Initial commit
Made-with: Cursor
This commit is contained in:
2
astral-service/astral-business/.gitattributes
vendored
Normal file
2
astral-service/astral-business/.gitattributes
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/mvnw text eol=lf
|
||||
*.cmd text eol=crlf
|
||||
33
astral-service/astral-business/.gitignore
vendored
Normal file
33
astral-service/astral-business/.gitignore
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
HELP.md
|
||||
target/
|
||||
!.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
|
||||
### IntelliJ IDEA ###
|
||||
.idea
|
||||
*.iws
|
||||
*.iml
|
||||
*.ipr
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
build/
|
||||
!**/src/main/**/build/
|
||||
!**/src/test/**/build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
21
astral-service/astral-business/pom.xml
Normal file
21
astral-service/astral-business/pom.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.astral</groupId>
|
||||
<artifactId>astral-parent</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>astral-business</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.astral</groupId>
|
||||
<artifactId>astral-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.astral.business.assets.controller;
|
||||
|
||||
import com.astral.business.assets.entity.AssetsCategory;
|
||||
import com.astral.business.assets.service.AssetsCategoryService;
|
||||
import com.astral.common.result.Result;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 资产分类
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/assets/assetsCategory")
|
||||
public class AssetsCategoryController {
|
||||
|
||||
@Autowired
|
||||
private AssetsCategoryService assetsCategoryService;
|
||||
|
||||
/**
|
||||
* 条件查询资产分类
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public Result<?> list(@RequestBody AssetsCategory assetsCategory) {
|
||||
QueryWrapper<AssetsCategory> queryWrapper = new QueryWrapper<>(assetsCategory);
|
||||
List<AssetsCategory> list = assetsCategoryService.list(queryWrapper);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询树型结构数据
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/treeList")
|
||||
public Result<?> treeList(@RequestParam(required = false, value = "type") String type) {
|
||||
return Result.success(assetsCategoryService.treeList(type));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询资产分类
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<AssetsCategory> getById(@PathVariable Long id) {
|
||||
AssetsCategory assetsCategory = assetsCategoryService.getById(id);
|
||||
return assetsCategory != null ? Result.success(assetsCategory) : Result.error("未找到该资产");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增资产分类
|
||||
*/
|
||||
@PostMapping
|
||||
public Result<?> add(@RequestBody AssetsCategory assetsCategory) {
|
||||
boolean success = assetsCategoryService.add(assetsCategory);
|
||||
return success ? Result.success("添加成功") : Result.error("添加失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新资产分类
|
||||
*/
|
||||
@PutMapping
|
||||
public Result<?> update(@RequestBody AssetsCategory assetsCategory) {
|
||||
boolean success = assetsCategoryService.edit(assetsCategory);
|
||||
return success ? Result.success("更新成功") : Result.error("更新失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID删除资产分类
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<?> delete(@PathVariable Long id) {
|
||||
boolean success = assetsCategoryService.delete(id);
|
||||
return success ? Result.success("删除成功") : Result.error("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
package com.astral.business.assets.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.astral.business.assets.entity.AssetsInfo;
|
||||
import com.astral.business.assets.service.AssetsCategoryService;
|
||||
import com.astral.business.assets.service.AssetsInfoService;
|
||||
import com.astral.common.result.Result;
|
||||
import com.astral.common.utils.CommonUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 资产信息
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/assets/assetsInfo")
|
||||
public class AssetsInfoController {
|
||||
|
||||
@Autowired
|
||||
private AssetsInfoService assetsInfoService;
|
||||
|
||||
@Autowired
|
||||
private AssetsCategoryService assetsCategoryService;
|
||||
|
||||
/**
|
||||
* 分页查询资产信息
|
||||
*/
|
||||
@GetMapping("/getAll")
|
||||
public Result<?> getAll(HttpServletRequest request) {
|
||||
String fieldsStr = request.getParameter("fields");
|
||||
List<String> fields = StringUtils.hasLength(fieldsStr) ? Arrays.asList(fieldsStr.split(",")) : new ArrayList<>();
|
||||
String limitStr = request.getParameter("limit");
|
||||
Integer limit = StringUtils.hasLength(limitStr) ? Integer.parseInt(limitStr) : 10;
|
||||
String offsetStr = request.getParameter("offset");
|
||||
Integer offset = StringUtils.hasLength(offsetStr) ? Integer.parseInt(offsetStr) : 0;
|
||||
String sortbyStr = request.getParameter("sortby");
|
||||
List<String> sortby = StringUtils.hasLength(sortbyStr) ? Arrays.asList(sortbyStr.split(",")) : new ArrayList<>();
|
||||
String orderStr = request.getParameter("order");
|
||||
List<String> order = StringUtils.hasLength(orderStr) ? Arrays.asList(orderStr.split(",")) : new ArrayList<>();
|
||||
String queryStr = request.getParameter("query");
|
||||
String searchStr = request.getParameter("search");
|
||||
Map<String, String> query = new HashMap<>();
|
||||
if (StringUtils.hasLength(queryStr)) {
|
||||
try {
|
||||
query = Arrays.stream(queryStr.split(",")).map(s -> {
|
||||
String[] split = s.split(":");
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException("error:无效的查询键/值对");
|
||||
}
|
||||
return split;
|
||||
}).collect(Collectors.toMap(s -> s[0], s -> s[1], (v1, v2) -> v1));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
QueryWrapper<AssetsInfo> queryWrapper = new QueryWrapper<AssetsInfo>();
|
||||
query.forEach((k, v) -> {
|
||||
String filedName = StringUtils.replace(k, ".", "__");
|
||||
if ("isnull".equals(filedName)) {
|
||||
queryWrapper.eq(filedName, "true".equals(v) || "1".equals(v));
|
||||
} else {
|
||||
queryWrapper.eq(filedName, v);
|
||||
}
|
||||
});
|
||||
Map<String, String> search = new HashMap<>();
|
||||
if (StringUtils.hasLength(searchStr)) {
|
||||
try {
|
||||
search = Arrays.stream(searchStr.split(";")).map(s -> {
|
||||
String[] split = s.split(":");
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException("error:无效的查询键/值对");
|
||||
}
|
||||
return split;
|
||||
}).collect(Collectors.toMap(s -> s[0], s -> s[1], (v1, v2) -> v1));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
search.forEach((k, v) -> {
|
||||
String filedName = StringUtils.replace(k, ".", "__");
|
||||
if ("name".equals(k)) {
|
||||
queryWrapper.like("name", v);
|
||||
} else if ("tags".equals(k)) {
|
||||
String[] tags = v.split(",");
|
||||
String regex = Arrays.stream(tags)
|
||||
.map(Pattern::quote)
|
||||
.collect(Collectors.joining("|", "(^|,)", "(,|$)"));
|
||||
queryWrapper.apply("tags REGEXP {0}", regex);
|
||||
}
|
||||
});
|
||||
if (!CollectionUtils.isEmpty(sortby)) {
|
||||
if (sortby.size() == order.size()) {
|
||||
for (int i = 0; i < sortby.size(); i++) {
|
||||
if ("desc".equals(order.get(i))) {
|
||||
queryWrapper.orderByDesc(sortby.get(i));
|
||||
} else if ("asc".equals(order.get(i))) {
|
||||
queryWrapper.orderByAsc(sortby.get(i));
|
||||
} else {
|
||||
return Result.error("Error: Invalid order. Must be either [asc|desc]");
|
||||
}
|
||||
}
|
||||
} else if (order.size() == 1) {
|
||||
if ("desc".equals(order.get(0))) {
|
||||
queryWrapper.orderByDesc(sortby);
|
||||
} else if ("asc".equals(order.get(0))) {
|
||||
queryWrapper.orderByAsc(sortby);
|
||||
}else {
|
||||
return Result.error("Error: Invalid order. Must be either [asc|desc]");
|
||||
}
|
||||
} else {
|
||||
return Result.error("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1");
|
||||
}
|
||||
} else {
|
||||
if (!CollectionUtils.isEmpty(order)) {
|
||||
return Result.error("Error: unused 'order' fields");
|
||||
}
|
||||
}
|
||||
Page<AssetsInfo> page = new Page<>();
|
||||
page.setSize(limit);
|
||||
page.setCurrent(offset / limit + 1);
|
||||
if (!CollectionUtils.isEmpty(fields)) {
|
||||
queryWrapper.select(fields);
|
||||
}
|
||||
try {
|
||||
Page<AssetsInfo> resultPage = assetsInfoService.page(page, queryWrapper);
|
||||
long count = assetsInfoService.count(queryWrapper);
|
||||
JSONObject result = new JSONObject();
|
||||
List<AssetsInfo> records = resultPage.getRecords();
|
||||
if (!CollectionUtils.isEmpty(records)) {
|
||||
Map<String, Map<String, String>> typeMap = assetsCategoryService.selectCategoryNameMap();
|
||||
for (AssetsInfo record : records) {
|
||||
Map<String, String> categoryMap = typeMap.get(record.getType());
|
||||
if (!CollectionUtils.isEmpty(categoryMap)) {
|
||||
record.setCategoryName(categoryMap.get(record.getCategory()));
|
||||
}
|
||||
}
|
||||
}
|
||||
result.put("items", resultPage.getRecords());
|
||||
result.put("current", offset + 1);
|
||||
result.put("pageSize", limit);
|
||||
result.put("pages", (count + limit - 1) / limit);
|
||||
result.put("total", count);
|
||||
return Result.success(result);
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 条件查询资产信息
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public Result<?> list(AssetsInfo assetsInfo) {
|
||||
QueryWrapper<AssetsInfo> queryWrapper = new QueryWrapper<>(assetsInfo);
|
||||
List<AssetsInfo> list = assetsInfoService.list(queryWrapper);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID查询资产信息
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
public Result<AssetsInfo> getById(@PathVariable Long id) {
|
||||
AssetsInfo assetsInfo = assetsInfoService.getById(id);
|
||||
return assetsInfo != null ? Result.success(assetsInfo) : Result.error("未找到该资产");
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增资产信息
|
||||
*/
|
||||
@PostMapping
|
||||
public Result<?> add(@RequestBody AssetsInfo assetsInfo) {
|
||||
boolean success = assetsInfoService.save(assetsInfo);
|
||||
return success ? Result.success("添加成功",assetsInfo) : Result.error("添加失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新资产信息
|
||||
*/
|
||||
@PutMapping
|
||||
public Result<?> update(@RequestBody AssetsInfo assetsInfo) {
|
||||
AssetsInfo metaAssetsInfo = assetsInfoService.getById(assetsInfo.getId());
|
||||
String thumbnail = metaAssetsInfo.getThumbnail();
|
||||
|
||||
boolean success = assetsInfoService.updateById(assetsInfo);
|
||||
|
||||
if(success){
|
||||
if(!Objects.equals(thumbnail, assetsInfo.getThumbnail())){
|
||||
CommonUtils.deleteFile(thumbnail);
|
||||
}
|
||||
|
||||
return Result.success("更新成功",assetsInfo);
|
||||
}
|
||||
|
||||
return Result.error("更新失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID删除资产信息
|
||||
*/
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<?> delete(@PathVariable Long id) {
|
||||
AssetsInfo assetsInfo = assetsInfoService.getById(id);
|
||||
if (assetsInfo == null) {
|
||||
return Result.error("未找到该资产");
|
||||
}
|
||||
String thumbnail = assetsInfo.getThumbnail();
|
||||
if (org.apache.commons.lang3.StringUtils.isNotBlank(thumbnail)) {
|
||||
CommonUtils.deleteFile(thumbnail);
|
||||
}
|
||||
String file = assetsInfo.getFile();
|
||||
if (org.apache.commons.lang3.StringUtils.isNotBlank(file)) {
|
||||
CommonUtils.deleteFile(file);
|
||||
}
|
||||
boolean success = assetsInfoService.removeById(id);
|
||||
return success ? Result.success("删除成功") : Result.error("删除失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类查询标签
|
||||
* @param category
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/selectTags")
|
||||
public Result<?> selectTages(@RequestParam("category") String category, @RequestParam("type") String type) {
|
||||
List<String> list = assetsInfoService.selectTages(category, type);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.astral.business.assets.entity;
|
||||
|
||||
import com.astral.common.base.TreeNode;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 资产分类
|
||||
*/
|
||||
@TableName(value ="astral_3d_assets_category")
|
||||
@Data
|
||||
public class AssetsCategory implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 父级编码
|
||||
*/
|
||||
private String pcode;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
private Integer sortNum;
|
||||
|
||||
/**
|
||||
* 删除标记,0 未删除 1 已删除
|
||||
*/
|
||||
@TableField("delTag")
|
||||
private Integer delTag;
|
||||
|
||||
@TableField("createTime")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
@TableField("updateTime")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTime;
|
||||
|
||||
@TableField("delTime")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date delTime;
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.astral.business.assets.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*
|
||||
* @TableName 资产信息
|
||||
*/
|
||||
@TableName(value ="astral_3d_assets_info")
|
||||
@Data
|
||||
public class AssetsInfo implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 文件名
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 类型
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 类别
|
||||
*/
|
||||
private String category;
|
||||
|
||||
/**
|
||||
* 缩略图
|
||||
*/
|
||||
private String thumbnail;
|
||||
|
||||
/**
|
||||
* 文件大小
|
||||
*/
|
||||
private String size;
|
||||
|
||||
/**
|
||||
* 标签
|
||||
*/
|
||||
private String tags;
|
||||
|
||||
/**
|
||||
* 附件地址
|
||||
*/
|
||||
private String file;
|
||||
|
||||
/**
|
||||
* 删除标记,0 未删除 1 已删除
|
||||
*/
|
||||
@TableField("delTag")
|
||||
private Integer delTag;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField("createTime")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField("updateTime")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date updateTime;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@TableField("delTime")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private Date delTime;
|
||||
|
||||
/**
|
||||
* 分类名称
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private String categoryName;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.astral.business.assets.mapper;
|
||||
|
||||
import com.astral.business.assets.entity.AssetsCategory;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
public interface AssetsCategoryMapper extends BaseMapper<AssetsCategory> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.astral.business.assets.mapper;
|
||||
|
||||
import com.astral.business.assets.entity.AssetsInfo;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*/
|
||||
public interface AssetsInfoMapper extends BaseMapper<AssetsInfo> {
|
||||
|
||||
@Select({"<script>",
|
||||
"SELECT DISTINCT tags FROM astral_3d_assets_info WHERE category IN ",
|
||||
"<foreach item='item' collection='categoryCodeList' open='(' separator=',' close=')'>",
|
||||
"#{item}",
|
||||
"</foreach>",
|
||||
"</script>"})
|
||||
public List<String> selectTagsByCategory(@Param("categoryCodeList") List<String> categoryCodeList);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.astral.business.assets.service;
|
||||
|
||||
import com.astral.business.assets.entity.AssetsCategory;
|
||||
import com.astral.common.base.TreeNode;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface AssetsCategoryService extends IService<AssetsCategory> {
|
||||
|
||||
List<TreeNode> treeList(String type);
|
||||
|
||||
boolean add(AssetsCategory assetsCategory);
|
||||
|
||||
boolean edit(AssetsCategory assetsCategory);
|
||||
|
||||
boolean delete(Long id);
|
||||
|
||||
List<AssetsCategory> selectCategoryAndChildren(String code, String type);
|
||||
|
||||
Map<String, Map<String, String>> selectCategoryNameMap();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.astral.business.assets.service;
|
||||
|
||||
import com.astral.business.assets.entity.AssetsInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AssetsInfoService extends IService<AssetsInfo> {
|
||||
|
||||
public boolean checkCategoryExistAssets(String type, String category);
|
||||
|
||||
public List<String> selectTages(String category, String type);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package com.astral.business.assets.service.impl;
|
||||
|
||||
import com.astral.business.assets.mapper.AssetsCategoryMapper;
|
||||
import com.astral.business.assets.service.AssetsCategoryService;
|
||||
import com.astral.business.assets.service.AssetsInfoService;
|
||||
import com.astral.common.base.TreeNode;
|
||||
import com.astral.common.utils.TreeBuilderUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.astral.business.assets.entity.AssetsCategory;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 资产分类实现层
|
||||
*/
|
||||
@Service
|
||||
public class AssetsCategoryServiceImpl extends ServiceImpl<AssetsCategoryMapper, AssetsCategory> implements AssetsCategoryService {
|
||||
|
||||
@Autowired
|
||||
private AssetsInfoService assetsInfoService;
|
||||
|
||||
@Override
|
||||
public List<TreeNode> treeList(String type) {
|
||||
LambdaQueryWrapper<AssetsCategory> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotBlank(type)) {
|
||||
queryWrapper.eq(AssetsCategory::getType, type);
|
||||
}
|
||||
List<AssetsCategory> list = this.list(queryWrapper);
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<TreeNode> treeNodeList = list.stream().map(item -> {
|
||||
TreeNode node = new TreeNode();
|
||||
node.setId(String.valueOf(item.getId()));
|
||||
node.setKey(item.getCode());
|
||||
node.setPkey(item.getPcode());
|
||||
node.setSortNum(item.getSortNum());
|
||||
node.setLabel(item.getName());
|
||||
node.setType(item.getType());
|
||||
return node;
|
||||
}).collect(Collectors.toList());
|
||||
List<TreeNode> treeList = TreeBuilderUtil.buildTree(treeNodeList);
|
||||
// 先type排序,asc,再sortNum排序,asc 仅排序顶级(处理全部查询时排序混乱问题)
|
||||
treeList = treeList.stream().sorted(Comparator.comparing(TreeNode::getType, Comparator.nullsLast(Comparator.naturalOrder())).thenComparing(TreeNode::getSortNum, Comparator.nullsLast(Comparator.naturalOrder()))).collect(Collectors.toList());
|
||||
return treeList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(AssetsCategory assetsCategory) {
|
||||
checkData(assetsCategory);
|
||||
return this.save(assetsCategory);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据校验
|
||||
* @param assetsCategory
|
||||
*/
|
||||
private void checkData(AssetsCategory assetsCategory) {
|
||||
String code = assetsCategory.getCode();
|
||||
if (StringUtils.isBlank(assetsCategory.getType()) || StringUtils.isBlank(assetsCategory.getName())
|
||||
|| StringUtils.isBlank(code)) {
|
||||
throw new RuntimeException("分类、编码、名称不能为空");
|
||||
}
|
||||
if (code.indexOf(".") > 0) {
|
||||
throw new RuntimeException("编码中不能含有特殊字符.");
|
||||
}
|
||||
if (assetsCategory.getId() == null) {
|
||||
AssetsCategory oldEntity = this.getOne(new LambdaQueryWrapper<AssetsCategory>().eq(AssetsCategory::getType, assetsCategory.getType()).eq(AssetsCategory::getCode, code));
|
||||
if (oldEntity != null) {
|
||||
throw new RuntimeException("编码已存在");
|
||||
}
|
||||
} else {
|
||||
AssetsCategory oldEntity = this.getById(assetsCategory.getId());
|
||||
if (!oldEntity.getCode().equals(code)) {
|
||||
if (assetsInfoService.checkCategoryExistAssets(oldEntity.getType(), oldEntity.getCode())) {
|
||||
throw new RuntimeException("该分类存在资产台账信息,不能修改编码/删除");
|
||||
}
|
||||
long count = this.count(new LambdaQueryWrapper<AssetsCategory>().eq(AssetsCategory::getType, assetsCategory.getType()).eq(AssetsCategory::getPcode, code));
|
||||
if (count > 0) {
|
||||
throw new RuntimeException("存在下级分类,不能修改编码或者删除");
|
||||
}
|
||||
long exitsCount = this.count(new LambdaQueryWrapper<AssetsCategory>().eq(AssetsCategory::getType, assetsCategory.getType()).eq(AssetsCategory::getCode, code));
|
||||
if (exitsCount > 0) {
|
||||
throw new RuntimeException("编码已存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean edit(AssetsCategory assetsCategory) {
|
||||
checkData(assetsCategory);
|
||||
return this.updateById(assetsCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(Long id) {
|
||||
AssetsCategory oldEntity = this.getById(id);
|
||||
if (oldEntity == null) {
|
||||
return true;
|
||||
}
|
||||
if (assetsInfoService.checkCategoryExistAssets(oldEntity.getType(), oldEntity.getCode())) {
|
||||
throw new RuntimeException("该分类存在资产台账信息,不能修改编码/删除");
|
||||
}
|
||||
long count = this.count(new LambdaQueryWrapper<AssetsCategory>().eq(AssetsCategory::getType, oldEntity.getType()).eq(AssetsCategory::getPcode, oldEntity.getCode()));
|
||||
if (count > 0) {
|
||||
throw new RuntimeException("存在下级分类,不能修改编码或者删除");
|
||||
}
|
||||
return this.removeById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code查询分类及其子分类
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<AssetsCategory> selectCategoryAndChildren(String code, String type) {
|
||||
LambdaQueryWrapper<AssetsCategory> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.isNotBlank(type)) {
|
||||
queryWrapper.eq(AssetsCategory::getType, type);
|
||||
}
|
||||
List<AssetsCategory> list = this.list(queryWrapper);
|
||||
if (StringUtils.isBlank(code)) {
|
||||
return list;
|
||||
}
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<AssetsCategory> resultList = selectChildren(list, code);
|
||||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询子集
|
||||
* @return
|
||||
*/
|
||||
private List<AssetsCategory> selectChildren(List<AssetsCategory> list, String code) {
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<AssetsCategory> resultList = new ArrayList<>();
|
||||
for (AssetsCategory assetsCategory : list) {
|
||||
if (code.equals(assetsCategory.getPcode())) {
|
||||
selectChildren(list, assetsCategory.getCode());
|
||||
}
|
||||
if (code.equals(assetsCategory.getCode())) {
|
||||
resultList.add(assetsCategory);
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Map<String, String>> selectCategoryNameMap() {
|
||||
List<AssetsCategory> list = this.list();
|
||||
Map<String, Map<String, String>> result = new HashMap<>();
|
||||
for (AssetsCategory category : list) {
|
||||
String type = category.getType();
|
||||
Map<String, String> map = result.get(type);
|
||||
if (map == null) {
|
||||
map = new HashMap<>();
|
||||
}
|
||||
map.put(category.getCode(), category.getName());
|
||||
result.put(type, map);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.astral.business.assets.service.impl;
|
||||
|
||||
import com.astral.business.assets.entity.AssetsCategory;
|
||||
import com.astral.business.assets.entity.AssetsInfo;
|
||||
import com.astral.business.assets.mapper.AssetsInfoMapper;
|
||||
import com.astral.business.assets.service.AssetsCategoryService;
|
||||
import com.astral.business.assets.service.AssetsInfoService;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 13623
|
||||
* @description 针对表【assets_info】的数据库操作Service实现
|
||||
* @createDate 2025-07-03 11:03:38
|
||||
*/
|
||||
@Service
|
||||
public class AssetsInfoServiceImpl extends ServiceImpl<AssetsInfoMapper, AssetsInfo> implements AssetsInfoService {
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private AssetsCategoryService assetsCategoryService;
|
||||
|
||||
/**
|
||||
* 校验分类下是否存在资产
|
||||
* 存在则返回true,不存在则返回false
|
||||
* @param category
|
||||
*/
|
||||
@Override
|
||||
public boolean checkCategoryExistAssets(String type, String category) {
|
||||
long count = this.count(new LambdaQueryWrapper<AssetsInfo>().eq(AssetsInfo::getType, type).likeRight(AssetsInfo::getCategory, category));
|
||||
if (count > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> selectTages(String category, String type) {
|
||||
List<AssetsCategory> categoryList = assetsCategoryService.selectCategoryAndChildren(category, "");
|
||||
if (CollectionUtils.isEmpty(categoryList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<String> categoryCodeList = categoryList.stream().map(AssetsCategory::getCode).collect(Collectors.toList());
|
||||
List<AssetsInfo> list = this.list(new LambdaQueryWrapper<AssetsInfo>().eq(AssetsInfo::getType, type).in(AssetsInfo::getCategory, categoryCodeList));
|
||||
if (CollectionUtils.isEmpty(list)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Set<String> tagsSet = new HashSet<>();
|
||||
for (AssetsInfo assetsInfo : list) {
|
||||
String tags = assetsInfo.getTags();
|
||||
if (StringUtils.isBlank(tags)) {
|
||||
continue;
|
||||
}
|
||||
String[] split = tags.split(",");
|
||||
tagsSet.addAll(Arrays.asList(split));
|
||||
}
|
||||
return new ArrayList<>(tagsSet);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,361 @@
|
||||
package com.astral.business.bim.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.astral.business.bim.entity.RvtConversionRequest;
|
||||
import com.astral.business.bim.entity.RvtConversionResult;
|
||||
import com.astral.common.result.Result;
|
||||
import com.astral.common.utils.CommonUtils;
|
||||
import com.astral.core.config.webSocketConfig.RevitWsClient;
|
||||
import com.astral.core.config.webSocketConfig.WebSocket;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.astral.business.bim.entity.Astral3DBimToGltf;
|
||||
import com.astral.business.bim.service.Astral3DBimToGltfService;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* BIM模型轻量化(Astral3DBimToGltf)表控制层
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/editor3d/bim2gltf")
|
||||
public class Astral3DBimToGltfController {
|
||||
/**
|
||||
* 服务对象
|
||||
*/
|
||||
@Autowired
|
||||
private Astral3DBimToGltfService astral3DEditorBimToGltfService;
|
||||
|
||||
@Autowired
|
||||
private WebSocket wsocket;
|
||||
|
||||
private RevitWsClient revitWs;
|
||||
|
||||
@Value("${dev.currentAbPath}")
|
||||
private String _appPath;
|
||||
|
||||
@Value("${revit.address}")
|
||||
private String address;
|
||||
|
||||
@Value("${revit.port}")
|
||||
private String port;
|
||||
|
||||
@Value("${revit.path}")
|
||||
private String path;
|
||||
|
||||
@Value("${revit.timeout}")
|
||||
private int timeout;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
revitWs = new RevitWsClient(address, port, path, timeout);
|
||||
revitWs.start();
|
||||
|
||||
long reconnectInterval = 8 * 60 * 60 * 1000;
|
||||
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
Runnable reconnectTask = () -> {
|
||||
try {
|
||||
if (revitWs.isConnected()) {
|
||||
System.out.println("会话已打开,无需重连。");
|
||||
return;
|
||||
}
|
||||
revitWs.reconnect();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.out.println("重连时发生错误: " + e.getMessage());
|
||||
}
|
||||
};
|
||||
scheduler.scheduleAtFixedRate(reconnectTask, 0, reconnectInterval, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public Result<?> post(@RequestBody Astral3DBimToGltf lb3dEditorBimToGltf) {
|
||||
return Result.toAjax(astral3DEditorBimToGltfService.save(lb3dEditorBimToGltf));
|
||||
}
|
||||
|
||||
@PostMapping("/addAndConversion")
|
||||
public Result<?> addAndConversion(HttpServletRequest request, @RequestBody Map<String, Object> reqMap) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
String jsonStr = JSONObject.toJSONString(reqMap);
|
||||
RvtConversionRequest op = JSONObject.parseObject(jsonStr, RvtConversionRequest.class);
|
||||
Astral3DBimToGltf v = JSONObject.parseObject(jsonStr, Astral3DBimToGltf.class);
|
||||
v.setOptions(null);
|
||||
v.setGltfFilePath("");
|
||||
// 添加记录到数据库
|
||||
if (!astral3DEditorBimToGltfService.save(v)) {
|
||||
return Result.error("保存失败");
|
||||
}
|
||||
final Astral3DBimToGltf savedV = v;
|
||||
// 启动异步转换任务
|
||||
CompletableFuture.runAsync(() -> {
|
||||
String uName = request.getParameter("uname");
|
||||
String bimFilePath = _appPath + "/" + savedV.getBimFilePath();
|
||||
|
||||
if (!revitWs.isConnected()) {
|
||||
wsocket.sendMessage(uName, JSONObject.toJSONString(Result.error("rvt 轻量化服务未连接")));
|
||||
return;
|
||||
}
|
||||
// 构造转换请求消息
|
||||
RvtConversionRequest m = new RvtConversionRequest();
|
||||
m.setFileId(savedV.getId());
|
||||
m.setFilePath(bimFilePath);
|
||||
m.setOptions(op.getOptions());
|
||||
m.getOptions().setUseDraco(true);
|
||||
|
||||
|
||||
try {
|
||||
String sm = JSONObject.toJSONString(m);
|
||||
// String sm = objectMapper.writeValueAsString(m);
|
||||
revitWs.sendMsg(sm);
|
||||
|
||||
// 读取Revit消息
|
||||
String tmpGltfPath = "";
|
||||
while (true) {
|
||||
String msg = revitWs.readMsg();
|
||||
Map<String, Object> msgMap = objectMapper.readValue(msg, Map.class);
|
||||
if (!bimFilePath.equals(msgMap.get("filePath"))) {
|
||||
System.out.println("文件名对比: " + bimFilePath + " ---- " + msgMap.get("filePath"));
|
||||
continue;
|
||||
}
|
||||
String type = (String) msgMap.get("type");
|
||||
if ("progress".equals(type)) {
|
||||
// 处理进度消息
|
||||
BigDecimal progress = (BigDecimal)msgMap.get("progress");
|
||||
JSONObject webSocketMsg = new JSONObject();
|
||||
webSocketMsg.put("type", "bim2gltf");
|
||||
webSocketMsg.put("subscriber", uName);
|
||||
webSocketMsg.put("data", new RvtConversionResult("progress", savedV, progress));
|
||||
wsocket.sendMessage(webSocketMsg.toJSONString());
|
||||
continue;
|
||||
} else if ("completed".equals(type)) {
|
||||
// 处理转换完成消息
|
||||
String gltfPath = (String) msgMap.get("gltfPath");
|
||||
savedV.setConversionDuration(new BigDecimal(msgMap.get("runSeconds").toString()));
|
||||
savedV.setConversionStatus(1);
|
||||
|
||||
// String gltfFilePath = _appPath + savedV.getGltfFilePath();
|
||||
String gltfFileFolderPath = bimFilePath.substring(0, bimFilePath.lastIndexOf("/") + 1);
|
||||
String gltfFilePath = gltfFileFolderPath + gltfPath;
|
||||
tmpGltfPath = gltfFilePath;
|
||||
File gltfFile = new File(gltfFilePath);
|
||||
if (gltfFile.exists()) {
|
||||
savedV.setGltfFileSize(BigDecimal.valueOf(gltfFile.length()));
|
||||
}
|
||||
String uploadGltfDir = "upload/bim/bim2gltf";
|
||||
String uploadGltfPath = uploadGltfDir + "/" + gltfPath;
|
||||
// UpYunUtil.upload(upYunGltfPath, gltfFile);
|
||||
CommonUtils.upload(uploadGltfDir, gltfFile);
|
||||
savedV.setGltfFilePath(uploadGltfPath);
|
||||
// 更新数据库
|
||||
astral3DEditorBimToGltfService.updateById(savedV);
|
||||
// 发送完成消息
|
||||
JSONObject webSocketMsg = new JSONObject();
|
||||
webSocketMsg.put("type", "bim2gltf");
|
||||
webSocketMsg.put("subscriber", uName);
|
||||
webSocketMsg.put("data", new RvtConversionResult("completed", savedV, BigDecimal.valueOf(100)));
|
||||
wsocket.sendMessage(webSocketMsg.toJSONString());
|
||||
break;
|
||||
} else if ("failed".equals(type)) {
|
||||
// 处理转换失败消息
|
||||
savedV.setGltfFilePath("");
|
||||
savedV.setConversionDuration(BigDecimal.valueOf(0));
|
||||
savedV.setConversionStatus(2);
|
||||
savedV.setGltfFileSize(BigDecimal.valueOf(0));
|
||||
// 更新数据库
|
||||
astral3DEditorBimToGltfService.updateById(savedV);
|
||||
// 发送失败消息
|
||||
JSONObject webSocketMsg = new JSONObject();
|
||||
webSocketMsg.put("type", "bim2gltf");
|
||||
webSocketMsg.put("subscriber", uName);
|
||||
webSocketMsg.put("data", new RvtConversionResult("failed", savedV, BigDecimal.ZERO));
|
||||
wsocket.sendMessage(webSocketMsg.toJSONString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (StringUtils.hasLength(tmpGltfPath)) {
|
||||
// 删除临时文件
|
||||
Files.deleteIfExists(Paths.get(tmpGltfPath));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return Result.success(savedV);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("fail->" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public Result<?> getOne(@PathVariable("id") String id) {
|
||||
try {
|
||||
return Result.success(astral3DEditorBimToGltfService.getById(id));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/getAll")
|
||||
public Result<?> getAll(HttpServletRequest request) {
|
||||
String fieldsStr = request.getParameter("fields");
|
||||
List<String> fields = StringUtils.hasLength(fieldsStr) ? Arrays.asList(fieldsStr.split(",")) : new ArrayList<>();
|
||||
String limitStr = request.getParameter("limit");
|
||||
Integer limit = StringUtils.hasLength(limitStr) ? Integer.parseInt(limitStr) : 10;
|
||||
String offsetStr = request.getParameter("offset");
|
||||
Integer offset = StringUtils.hasLength(offsetStr) ? Integer.parseInt(offsetStr) : 0;
|
||||
String sortbyStr = request.getParameter("sortby");
|
||||
List<String> sortby = StringUtils.hasLength(sortbyStr) ? Arrays.asList(sortbyStr.split(",")) : new ArrayList<>();
|
||||
String orderStr = request.getParameter("order");
|
||||
List<String> order = StringUtils.hasLength(orderStr) ? Arrays.asList(orderStr.split(",")) : new ArrayList<>();
|
||||
String queryStr = request.getParameter("query");
|
||||
Map<String, String> query = new HashMap<>();
|
||||
if (StringUtils.hasLength(queryStr)) {
|
||||
try {
|
||||
query = Arrays.stream(queryStr.split(",")).map(s -> {
|
||||
String[] split = s.split(":");
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException("error:无效的查询键/值对");
|
||||
}
|
||||
return split;
|
||||
}).collect(Collectors.toMap(s -> s[0], s -> s[1], (v1, v2) -> v1));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
QueryWrapper<Astral3DBimToGltf> queryWrapper = new QueryWrapper<Astral3DBimToGltf>();
|
||||
query.forEach((k, v) -> {
|
||||
String filedName = StringUtils.replace(k, ".", "__");
|
||||
if ("isnull".equals(filedName)) {
|
||||
queryWrapper.eq(filedName, "true".equals(v) || "1".equals(v));
|
||||
} else {
|
||||
queryWrapper.eq(filedName, v);
|
||||
}
|
||||
});
|
||||
if (!CollectionUtils.isEmpty(sortby)) {
|
||||
if (sortby.size() == order.size()) {
|
||||
for (int i = 0; i < sortby.size(); i++) {
|
||||
if ("desc".equals(order.get(i))) {
|
||||
queryWrapper.orderByDesc(sortby.get(i));
|
||||
} else if ("asc".equals(order.get(i))) {
|
||||
queryWrapper.orderByAsc(sortby.get(i));
|
||||
} else {
|
||||
return Result.error("Error: Invalid order. Must be either [asc|desc]");
|
||||
}
|
||||
}
|
||||
|
||||
} else if (order.size() == 1) {
|
||||
if ("desc".equals(order.get(0))) {
|
||||
queryWrapper.orderByDesc(sortby);
|
||||
} else if ("asc".equals(order.get(0))) {
|
||||
queryWrapper.orderByAsc(sortby);
|
||||
}else {
|
||||
return Result.error("Error: Invalid order. Must be either [asc|desc]");
|
||||
}
|
||||
} else {
|
||||
return Result.error("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1");
|
||||
}
|
||||
} else {
|
||||
if (!CollectionUtils.isEmpty(order)) {
|
||||
return Result.error("Error: unused 'order' fields");
|
||||
}
|
||||
}
|
||||
Page<Astral3DBimToGltf> page = new Page<>();
|
||||
page.setSize(limit);
|
||||
page.setCurrent(offset / limit + 1);
|
||||
if (!CollectionUtils.isEmpty(fields)) {
|
||||
queryWrapper.select(fields);
|
||||
}
|
||||
try {
|
||||
Page<Astral3DBimToGltf> resultPage = astral3DEditorBimToGltfService.page(page, queryWrapper);
|
||||
long count = astral3DEditorBimToGltfService.count(queryWrapper);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("items", resultPage.getRecords());
|
||||
result.put("current", offset + 1);
|
||||
result.put("pageSize", limit);
|
||||
result.put("pages", (count + limit - 1) / limit);
|
||||
result.put("total", count);
|
||||
return Result.success(result);
|
||||
// return Result.success(astral3DEditorBimToGltfService.page(page, queryWrapper));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
public Result<?> put(@PathVariable("id") Long id, @RequestBody Astral3DBimToGltf lb3dEditorBimToGltf) {
|
||||
lb3dEditorBimToGltf.setId(id);
|
||||
return Result.toAjax(astral3DEditorBimToGltfService.updateById(lb3dEditorBimToGltf));
|
||||
}
|
||||
|
||||
@DeleteMapping("/del/{id}")
|
||||
public Result<?> delete(@PathVariable("id") Long id) {
|
||||
return Result.toAjax(astral3DEditorBimToGltfService.removeById(id));
|
||||
}
|
||||
|
||||
@PostMapping("/uploadRvt")
|
||||
public Result<?> doRvtUpload(@RequestParam("file") MultipartFile file) {
|
||||
if (file.isEmpty()) {
|
||||
return Result.error("未获取到上传文件!");
|
||||
}
|
||||
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String fileExt = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
String fileName = originalFilename.substring(0, originalFilename.lastIndexOf("."));
|
||||
|
||||
if (!".rvt".equalsIgnoreCase(fileExt)) {
|
||||
return Result.error("只能上传rvt文件!");
|
||||
}
|
||||
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||
String currentDate = sdf.format(new Date());
|
||||
|
||||
// 存储的文件夹
|
||||
String saveFolder = "static/tmp/bim/" + currentDate;
|
||||
// 存储的路径
|
||||
String newFileName = fileName + "-" + System.currentTimeMillis() + fileExt;
|
||||
String savePath = saveFolder + "/" + newFileName;
|
||||
// 保存位置在 static/upload, 没有文件夹要先创建
|
||||
Path path = Paths.get(_appPath + "/" + saveFolder);
|
||||
if (!Files.exists(path)) {
|
||||
try {
|
||||
path = Files.createDirectories(path);
|
||||
} catch (IOException e) {
|
||||
return Result.error("服务端创建文件夹" + currentDate + "失败!error=" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
file.transferTo(new File(path.toAbsolutePath().toString() + "/" + newFileName));
|
||||
// file.transferTo(new File("static/upload/" + savePath));
|
||||
return Result.success("上传成功", savePath);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("服务器端文件保存失败!error=" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.astral.business.bim.entity;
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.extension.handlers.FastjsonTypeHandler;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* BIM模型轻量化(Astral3DBimToGltf)表实体类
|
||||
*/
|
||||
@Data
|
||||
@TableName(value = "astral_3d_bim_to_gltf", autoResultMap = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Astral3DBimToGltf implements Serializable{
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
//文件名
|
||||
private String fileName;
|
||||
//缩略图
|
||||
private String thumbnail;
|
||||
//bim源文件路径
|
||||
private String bimFilePath;
|
||||
//bim源文件大小
|
||||
private BigDecimal bimFileSize;
|
||||
//转换后的gltf文件路径
|
||||
private String gltfFilePath;
|
||||
//转换后的gltf文件大小
|
||||
private BigDecimal gltfFileSize;
|
||||
//0 转换中 1 转换完成 2 转换失败
|
||||
private Integer conversionStatus;
|
||||
//转换时长(s)
|
||||
private BigDecimal conversionDuration;
|
||||
//转换配置
|
||||
@TableField(typeHandler = FastjsonTypeHandler.class, jdbcType = JdbcType.LONGNVARCHAR)
|
||||
private JSONObject options;
|
||||
//删除标记,0 未删除 1 已删除
|
||||
@TableField("delTag")
|
||||
private Integer delTag;
|
||||
|
||||
@TableField("createTime")
|
||||
private Date createTime;
|
||||
|
||||
@TableField("updateTime")
|
||||
private Date updateTime;
|
||||
|
||||
@TableField("delTime")
|
||||
private Date delTime;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.astral.business.bim.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RvtConversionRequest {
|
||||
|
||||
private Long fileId;
|
||||
|
||||
private String filePath;
|
||||
|
||||
private RvtConversionRequestOptions options;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.astral.business.bim.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RvtConversionRequestOptions {
|
||||
|
||||
private Boolean useDraco;
|
||||
|
||||
@JsonAlias("Optimize")
|
||||
private Boolean optimize;
|
||||
|
||||
@JsonAlias("ExportProperty")
|
||||
private Boolean exportProperty;
|
||||
|
||||
@JsonAlias("View")
|
||||
private String view;
|
||||
|
||||
@JsonAlias("ViewName")
|
||||
private String viewName;
|
||||
|
||||
@JsonAlias("DisplayStyle")
|
||||
private String displayStyle;
|
||||
|
||||
@JsonAlias("CoordinateReference")
|
||||
private String coordinateReference;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.astral.business.bim.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class RvtConversionResult {
|
||||
|
||||
private String conversionStatus;
|
||||
|
||||
private Astral3DBimToGltf item;
|
||||
|
||||
private BigDecimal process;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.astral.business.bim.mapper;
|
||||
|
||||
import com.astral.business.bim.entity.Astral3DBimToGltf;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* BIM模型轻量化(Astral3DBimToGltf)表数据库访问层
|
||||
*/
|
||||
@Mapper
|
||||
public interface Astral3DBimToGltfMapper extends BaseMapper<Astral3DBimToGltf> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.astral.business.bim.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.astral.business.bim.entity.Astral3DBimToGltf;
|
||||
|
||||
/**
|
||||
* BIM模型轻量化(Astral3DBimToGltf)表服务接口
|
||||
*/
|
||||
public interface Astral3DBimToGltfService extends IService<Astral3DBimToGltf> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.astral.business.bim.service.impl;
|
||||
|
||||
import com.astral.business.bim.mapper.Astral3DBimToGltfMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.astral.business.bim.entity.Astral3DBimToGltf;
|
||||
import com.astral.business.bim.service.Astral3DBimToGltfService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* BIM模型轻量化(Astral3DBimToGltf)表服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class Astral3DBimToGltfServiceImpl extends ServiceImpl<Astral3DBimToGltfMapper, Astral3DBimToGltf> implements Astral3DBimToGltfService {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,324 @@
|
||||
package com.astral.business.cad.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.astral.business.cad.entity.ConversionResult;
|
||||
import com.astral.business.cad.entity.Astral3DCad;
|
||||
import com.astral.business.cad.service.Astral3DCadService;
|
||||
import com.astral.common.result.Result;
|
||||
import com.astral.common.utils.CommonUtils;
|
||||
import com.astral.core.config.webSocketConfig.WebSocket;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* (Astral3DCad)表控制层
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/editor3d/cad")
|
||||
public class Astral3DCadController {
|
||||
|
||||
@Autowired
|
||||
private Astral3DCadService astral3DCadService;
|
||||
|
||||
@Autowired
|
||||
private WebSocket wsocket;
|
||||
|
||||
@Value("${dev.cadDwgConverterAbPath}")
|
||||
private String cadDwgConverterAbPath;
|
||||
|
||||
@Value("${dev.currentAbPath}")
|
||||
private String currentAbPath;
|
||||
|
||||
@PostMapping("/dwg2dxf")
|
||||
public Result<?> dwg2Dxf(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
|
||||
// 检查文件是否为空
|
||||
if (file.isEmpty()) {
|
||||
return Result.error("上传文件为空!");
|
||||
}
|
||||
Integer conversionStatus;
|
||||
String converterFilePath = "";
|
||||
String dataPath = "";
|
||||
|
||||
// 获取文件扩展名
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String ext = originalFilename.substring(originalFilename.lastIndexOf(".") + 1).toLowerCase();
|
||||
|
||||
// 检查文件格式
|
||||
if (!"dwg".equals(ext) && !"dxf".equals(ext)) {
|
||||
return Result.error("上传文件格式不正确!");
|
||||
}
|
||||
|
||||
// 去除文件名中的空格
|
||||
String sanitizedFilename = originalFilename.replace(" ", "");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
||||
String nowDateStr = sdf.format(new Date());
|
||||
if (!"dwg".equals(ext)) {
|
||||
conversionStatus = 1;
|
||||
String dxfUploadDir = "upload/cad/dwg2dxf/" + nowDateStr;
|
||||
dataPath = dxfUploadDir + "/" + sanitizedFilename;
|
||||
// 无需转换,直接上传
|
||||
try {
|
||||
converterFilePath = CommonUtils.upload(dxfUploadDir, file);
|
||||
} catch (Exception e) {
|
||||
return Result.error("上传失败,Error:" + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
conversionStatus = 0;
|
||||
// 需要转换,保存文件到tmp目录
|
||||
dataPath = "static/tmp/cad/" + sanitizedFilename;
|
||||
try {
|
||||
File tempFile = new File(currentAbPath + "/" + dataPath);
|
||||
file.transferTo(tempFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return Result.error("cad上传文件保存失败,Error:" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
// 更新数据库
|
||||
Astral3DCad cad = new Astral3DCad();
|
||||
cad.setFilePath(dataPath);
|
||||
cad.setThumbnail(request.getParameter("thumbnail"));
|
||||
cad.setFileName(request.getParameter("fileName"));
|
||||
cad.setConversionStatus(conversionStatus);
|
||||
cad.setConverterFilePath(converterFilePath);
|
||||
boolean saveResult = astral3DCadService.save(cad);
|
||||
if (!saveResult) {
|
||||
return Result.error("保存数据失败!");
|
||||
}
|
||||
String finalDataPath = currentAbPath + "/" + dataPath;
|
||||
if (conversionStatus == 0) {
|
||||
// 异步转换DWG文件
|
||||
new Thread(() -> {
|
||||
String uname = request.getParameter("uname");
|
||||
String outputFile = currentAbPath + "/static/tmp/cad/" + sanitizedFilename.replace(".dwg", ".dxf");
|
||||
String command = "cmd /C " + cadDwgConverterAbPath + "/dwg2dxf.exe " + finalDataPath + " -o " + outputFile;
|
||||
System.out.println("[cad] run cmd:" + command);
|
||||
try {
|
||||
ProcessBuilder builder = new ProcessBuilder("cmd.exe", "/C", cadDwgConverterAbPath + "/dwg2dxf.exe", finalDataPath, "-o", outputFile);
|
||||
builder.redirectErrorStream(true);
|
||||
Process process = builder.start();
|
||||
try (BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()))) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
// 可以在这里过滤掉错误信息,只处理需要的输出
|
||||
if (!line.startsWith("ERROR:")) { // 示例过滤条件
|
||||
System.out.println(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
if (exitCode == 0) {
|
||||
// 转换成功,上传
|
||||
try {
|
||||
File dxfFile = new File(outputFile);
|
||||
String dxfUploadDir = "upload/cad/dwg2dxf/" + nowDateStr;
|
||||
|
||||
System.out.println("[cad] 转换成功,准备上传: " + dxfFile.getName());
|
||||
try {
|
||||
String dxfUploadPath = CommonUtils.upload(dxfUploadDir, dxfFile);
|
||||
cad.setConverterFilePath(dxfUploadPath);
|
||||
cad.setConversionStatus(1);
|
||||
} catch (Exception e) {
|
||||
System.out.println("上传失败,Error:" + e.getMessage());
|
||||
cad.setConverterFilePath("");
|
||||
cad.setConversionStatus(2);
|
||||
JSONObject webSocketMsg = new JSONObject();
|
||||
webSocketMsg.put("type", "cad");
|
||||
webSocketMsg.put("subscriber", uname);
|
||||
webSocketMsg.put("data", new ConversionResult("failed", cad, "转换成功,但上传结果失败!Error:" + e.getMessage()));
|
||||
wsocket.sendMessage(uname, webSocketMsg.toJSONString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("failed to open file: " + e.getMessage());
|
||||
cad.setConversionStatus(2);
|
||||
JSONObject webSocketMsg = new JSONObject();
|
||||
webSocketMsg.put("type", "cad");
|
||||
webSocketMsg.put("subscriber", uname);
|
||||
webSocketMsg.put("data", new ConversionResult("failed", cad, "转换成功,但读取结果失败!Error: " + e.getMessage()));
|
||||
wsocket.sendMessage(uname, webSocketMsg.toJSONString());
|
||||
}
|
||||
} else {
|
||||
System.out.println("failed to call cmd.Run(): " + command);
|
||||
// 转换失败
|
||||
cad.setConversionStatus(2);
|
||||
JSONObject webSocketMsg = new JSONObject();
|
||||
webSocketMsg.put("type", "cad");
|
||||
webSocketMsg.put("subscriber", uname);
|
||||
webSocketMsg.put("data", new ConversionResult("failed", cad, "转换失败!Error: " + exitCode));
|
||||
wsocket.sendMessage(uname, webSocketMsg.toJSONString());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
cad.setConversionStatus(2);
|
||||
JSONObject webSocketMsg = new JSONObject();
|
||||
webSocketMsg.put("type", "cad");
|
||||
webSocketMsg.put("subscriber", uname);
|
||||
webSocketMsg.put("data", new ConversionResult("failed", cad, e.getMessage()));
|
||||
wsocket.sendMessage(uname, webSocketMsg.toJSONString());
|
||||
}
|
||||
|
||||
System.out.println("[cad] 转换完成,准备更新数据库: " + cad.getId());
|
||||
boolean updateResult = astral3DCadService.updateById(cad);
|
||||
if (cad.getConversionStatus() == 1) {
|
||||
if (updateResult) {
|
||||
System.out.println("[cad] 转换成功,更新数据库成功!发送成功消息");
|
||||
JSONObject webSocketMsg = new JSONObject();
|
||||
webSocketMsg.put("type", "cad");
|
||||
webSocketMsg.put("subscriber", uname);
|
||||
webSocketMsg.put("data", new ConversionResult("completed", cad, "转换成功!"));
|
||||
wsocket.sendMessage(uname, webSocketMsg.toJSONString());
|
||||
} else {
|
||||
JSONObject webSocketMsg = new JSONObject();
|
||||
webSocketMsg.put("type", "cad");
|
||||
webSocketMsg.put("subscriber", uname);
|
||||
webSocketMsg.put("data", new ConversionResult("failed", cad, "转换成功,但更新数据库失败!"));
|
||||
wsocket.sendMessage(uname, webSocketMsg.toJSONString());
|
||||
}
|
||||
}
|
||||
try {
|
||||
// 删除上传的临时文件和转换后的文件
|
||||
Files.deleteIfExists(Paths.get(finalDataPath));
|
||||
Files.deleteIfExists(Paths.get(outputFile));
|
||||
} catch (Exception e) {
|
||||
System.out.println("删除临时文件失败:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
return Result.success(cad);
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public Result<?> post(@RequestBody Astral3DCad lb3dEditorCad) {
|
||||
if (astral3DCadService.save(lb3dEditorCad)) {
|
||||
return Result.success(lb3dEditorCad);
|
||||
} else {
|
||||
return Result.error("保存失败!");
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Result<?> getOne(@PathVariable("id") Long id) {
|
||||
try {
|
||||
Astral3DCad lb3dEditorCad = astral3DCadService.getById(id);
|
||||
return Result.success(lb3dEditorCad);
|
||||
} catch (Exception e) {
|
||||
return Result.error("保存失败->" + e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/getAll")
|
||||
public Result<?> getAll(HttpServletRequest request) {
|
||||
String fieldsStr = request.getParameter("fields");
|
||||
List<String> fields = StringUtils.hasLength(fieldsStr) ? Arrays.asList(fieldsStr.split(",")) : new ArrayList<>();
|
||||
String limitStr = request.getParameter("limit");
|
||||
Integer limit = StringUtils.hasLength(limitStr) ? Integer.parseInt(limitStr) : 10;
|
||||
String offsetStr = request.getParameter("offset");
|
||||
Integer offset = StringUtils.hasLength(offsetStr) ? Integer.parseInt(offsetStr) : 0;
|
||||
String sortbyStr = request.getParameter("sortby");
|
||||
List<String> sortby = StringUtils.hasLength(sortbyStr) ? Arrays.asList(sortbyStr.split(",")) : new ArrayList<>();
|
||||
String orderStr = request.getParameter("order");
|
||||
List<String> order = StringUtils.hasLength(orderStr) ? Arrays.asList(orderStr.split(",")) : new ArrayList<>();
|
||||
String queryStr = request.getParameter("query");
|
||||
Map<String, String> query = new HashMap<>();
|
||||
if (StringUtils.hasLength(queryStr)) {
|
||||
try {
|
||||
query = Arrays.stream(queryStr.split(",")).map(s -> {
|
||||
String[] split = s.split(":");
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException("error:无效的查询键/值对");
|
||||
}
|
||||
return split;
|
||||
}).collect(Collectors.toMap(s -> s[0], s -> s[1], (v1, v2) -> v1));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
QueryWrapper<Astral3DCad> queryWrapper = new QueryWrapper<Astral3DCad>();
|
||||
query.forEach((k, v) -> {
|
||||
String filedName = StringUtils.replace(k, ".", "__");
|
||||
if ("isnull".equals(filedName)) {
|
||||
queryWrapper.eq(filedName, "true".equals(v) || "1".equals(v));
|
||||
} else {
|
||||
queryWrapper.eq(filedName, v);
|
||||
}
|
||||
});
|
||||
if (!CollectionUtils.isEmpty(sortby)) {
|
||||
if (sortby.size() == order.size()) {
|
||||
for (int i = 0; i < sortby.size(); i++) {
|
||||
if ("desc".equals(order.get(i))) {
|
||||
queryWrapper.orderByDesc(sortby.get(i));
|
||||
} else if ("asc".equals(order.get(i))) {
|
||||
queryWrapper.orderByAsc(sortby.get(i));
|
||||
} else {
|
||||
return Result.error("Error: Invalid order. Must be either [asc|desc]");
|
||||
}
|
||||
}
|
||||
} else if (order.size() == 1) {
|
||||
if ("desc".equals(order.get(0))) {
|
||||
queryWrapper.orderByDesc(sortby);
|
||||
} else if ("asc".equals(order.get(0))) {
|
||||
queryWrapper.orderByAsc(sortby);
|
||||
}else {
|
||||
return Result.error("Error: Invalid order. Must be either [asc|desc]");
|
||||
}
|
||||
} else {
|
||||
return Result.error("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1");
|
||||
}
|
||||
} else {
|
||||
if (!CollectionUtils.isEmpty(order)) {
|
||||
return Result.error("Error: unused 'order' fields");
|
||||
}
|
||||
}
|
||||
Page<Astral3DCad> page = new Page<>();
|
||||
page.setSize(limit);
|
||||
page.setCurrent(offset / limit + 1);
|
||||
if (!CollectionUtils.isEmpty(fields)) {
|
||||
queryWrapper.select(fields);
|
||||
}
|
||||
try {
|
||||
Page<Astral3DCad> resultPage = astral3DCadService.page(page, queryWrapper);
|
||||
long count = astral3DCadService.count(queryWrapper);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("items", resultPage.getRecords());
|
||||
result.put("current", offset + 1);
|
||||
result.put("pageSize", limit);
|
||||
result.put("pages", (count + limit - 1) / limit);
|
||||
result.put("total", count);
|
||||
return Result.success(result);
|
||||
// return Result.success(pageResult);
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public Result<?> put(@PathVariable("id") Long id, @RequestBody Astral3DCad lb3dEditorCad) {
|
||||
lb3dEditorCad.setId(id);
|
||||
return Result.toAjax(astral3DCadService.updateById(lb3dEditorCad));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<?> delete(@PathVariable("id") Long id) {
|
||||
return Result.toAjax(astral3DCadService.removeById(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.astral.business.cad.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* (Astral3DCad)表实体类
|
||||
*/
|
||||
@Data
|
||||
@TableName("astral_3d_cad")
|
||||
public class Astral3DCad {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
//文件名
|
||||
private String fileName;
|
||||
//缩略图
|
||||
private String thumbnail;
|
||||
//源文件路径
|
||||
private String filePath;
|
||||
//转换后的文件路径
|
||||
private String converterFilePath;
|
||||
//0 转换中 1 转换完成 2 转换失败
|
||||
private Integer conversionStatus;
|
||||
//删除标记,0 未删除 1 已删除
|
||||
@TableField("delTag")
|
||||
private Integer delTag;
|
||||
|
||||
@TableField("createTime")
|
||||
private Date createTime;
|
||||
|
||||
@TableField("updateTime")
|
||||
private Date updateTime;
|
||||
|
||||
@TableField("delTime")
|
||||
private Date delTime;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.astral.business.cad.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* cad转换结果
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ConversionResult {
|
||||
|
||||
private String conversionStatus;
|
||||
|
||||
private Astral3DCad item;
|
||||
|
||||
private String message;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.astral.business.cad.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.astral.business.cad.entity.Astral3DCad;
|
||||
|
||||
/**
|
||||
* (Astral3DCad)表数据库访问层
|
||||
*/
|
||||
public interface Astral3DCadMapper extends BaseMapper<Astral3DCad> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.astral.business.cad.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.astral.business.cad.entity.Astral3DCad;
|
||||
|
||||
/**
|
||||
* (Astral3DCad)表服务接口
|
||||
*/
|
||||
public interface Astral3DCadService extends IService<Astral3DCad> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.astral.business.cad.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.astral.business.cad.mapper.Astral3DCadMapper;
|
||||
import com.astral.business.cad.entity.Astral3DCad;
|
||||
import com.astral.business.cad.service.Astral3DCadService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* (Astral3DCad)表服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class Astral3DCadServiceImpl extends ServiceImpl<Astral3DCadMapper, Astral3DCad> implements Astral3DCadService {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,228 @@
|
||||
package com.astral.business.scenes.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.astral.business.scenes.entity.Astral3DScenesExample;
|
||||
import com.astral.business.scenes.service.Astral3DScenesExampleService;
|
||||
import com.astral.common.result.Result;
|
||||
import com.astral.common.utils.CommonUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.astral.business.scenes.entity.Astral3DScenes;
|
||||
import com.astral.business.scenes.service.Astral3DScenesService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 场景zip压缩包信息表(Astral3DScenes)表控制层
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/editor3d/scenes")
|
||||
public class Astral3DScenesController {
|
||||
/**
|
||||
* 服务对象
|
||||
*/
|
||||
@Autowired
|
||||
private Astral3DScenesService astral3DScenesService;
|
||||
|
||||
@Autowired
|
||||
private Astral3DScenesExampleService astral3DScenesExampleService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public Result<?> post(@RequestBody Astral3DScenes lb3dEditorScenes) {
|
||||
long count = astral3DScenesService.count();
|
||||
if (count > 2000) {
|
||||
return Result.error("共享项目场景数量已达上限(2000个),不允许新增");
|
||||
}
|
||||
if (astral3DScenesService.save(lb3dEditorScenes)) {
|
||||
return Result.success(lb3dEditorScenes);
|
||||
} else {
|
||||
return Result.error("新增失败");
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
public Result<?> getOne(@PathVariable("id") String id) {
|
||||
try {
|
||||
Astral3DScenes scenes = astral3DScenesService.getById(id);
|
||||
if (Objects.isNull(scenes)) {
|
||||
return Result.error("场景不存在");
|
||||
}
|
||||
if ((StringUtils.isEmpty(scenes.getZip()) || StringUtils.isEmpty(scenes.getCoverPicture()))
|
||||
&& !StringUtils.isEmpty(scenes.getExampleSceneId())) {
|
||||
Astral3DScenesExample scenesExample = astral3DScenesExampleService.getById(scenes.getExampleSceneId());
|
||||
if (Objects.nonNull(scenesExample)) {
|
||||
scenes.setZip(scenesExample.getZip());
|
||||
scenes.setCoverPicture(scenesExample.getCoverPicture());
|
||||
}
|
||||
}
|
||||
return Result.success(scenes);
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/getAll")
|
||||
public Result<?> getAll(HttpServletRequest request) {
|
||||
String fieldsStr = request.getParameter("fields");
|
||||
List<String> fields = StringUtils.hasLength(fieldsStr) ? Arrays.asList(fieldsStr.split(",")) : new ArrayList<>();
|
||||
String limitStr = request.getParameter("limit");
|
||||
Integer limit = StringUtils.hasLength(limitStr) ? Integer.parseInt(limitStr) : 10;
|
||||
String offsetStr = request.getParameter("offset");
|
||||
Integer offset = StringUtils.hasLength(offsetStr) ? Integer.parseInt(offsetStr) : 0;
|
||||
String sortbyStr = request.getParameter("sortby");
|
||||
List<String> sortby = StringUtils.hasLength(sortbyStr) ? Arrays.asList(sortbyStr.split(",")) : new ArrayList<>();
|
||||
String orderStr = request.getParameter("order");
|
||||
List<String> order = StringUtils.hasLength(orderStr) ? Arrays.asList(orderStr.split(",")) : new ArrayList<>();
|
||||
String queryStr = request.getParameter("query");
|
||||
Map<String, String> query = new HashMap<>();
|
||||
if (StringUtils.hasLength(queryStr)) {
|
||||
try {
|
||||
query = Arrays.stream(queryStr.split(",")).map(s -> {
|
||||
String[] split = s.split(":");
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException("error:无效的查询键/值对");
|
||||
}
|
||||
return split;
|
||||
}).collect(Collectors.toMap(s -> s[0], s -> s[1], (v1, v2) -> v1));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
QueryWrapper<Astral3DScenes> queryWrapper = new QueryWrapper<Astral3DScenes>();
|
||||
query.forEach((k, v) -> {
|
||||
String filedName = StringUtils.replace(k, ".", "__");
|
||||
if ("isnull".equals(filedName)) {
|
||||
queryWrapper.eq(filedName, "true".equals(v) || "1".equals(v));
|
||||
} else {
|
||||
queryWrapper.eq(filedName, v);
|
||||
}
|
||||
});
|
||||
if (!CollectionUtils.isEmpty(sortby)) {
|
||||
if (sortby.size() == order.size()) {
|
||||
for (int i = 0; i < sortby.size(); i++) {
|
||||
if ("desc".equals(order.get(i))) {
|
||||
queryWrapper.orderByDesc(sortby.get(i));
|
||||
} else if ("asc".equals(order.get(i))) {
|
||||
queryWrapper.orderByAsc(sortby.get(i));
|
||||
} else {
|
||||
return Result.error("Error: Invalid order. Must be either [asc|desc]");
|
||||
}
|
||||
}
|
||||
|
||||
} else if (order.size() == 1) {
|
||||
if ("desc".equals(order.get(0))) {
|
||||
queryWrapper.orderByDesc(sortby);
|
||||
} else if ("asc".equals(order.get(0))) {
|
||||
queryWrapper.orderByAsc(sortby);
|
||||
}else {
|
||||
return Result.error("Error: Invalid order. Must be either [asc|desc]");
|
||||
}
|
||||
} else {
|
||||
return Result.error("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1");
|
||||
}
|
||||
} else {
|
||||
if (!CollectionUtils.isEmpty(order)) {
|
||||
return Result.error("Error: unused 'order' fields");
|
||||
}
|
||||
}
|
||||
Page<Astral3DScenes> page = new Page<>();
|
||||
page.setSize(limit);
|
||||
page.setCurrent(offset / limit + 1);
|
||||
if (!CollectionUtils.isEmpty(fields)) {
|
||||
queryWrapper.select(fields);
|
||||
}
|
||||
|
||||
try {
|
||||
Page<Astral3DScenes> resultPage = astral3DScenesService.page(page, queryWrapper);
|
||||
|
||||
// 20251104 新增:封面兜底
|
||||
List<Astral3DScenes> records = resultPage.getRecords();
|
||||
if (!CollectionUtils.isEmpty(records)) {
|
||||
// 需要兜底的 exampleSceneId 集合
|
||||
Set<String> exampleIdsToFetch = records.stream()
|
||||
.filter(r -> !StringUtils.hasLength(r.getCoverPicture()) && r.getExampleSceneId() != null)
|
||||
.map(Astral3DScenes::getExampleSceneId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
if (!CollectionUtils.isEmpty(exampleIdsToFetch)) {
|
||||
// 批量查询示例场景
|
||||
List<Astral3DScenesExample> examples = astral3DScenesExampleService.listByIds(exampleIdsToFetch);
|
||||
Map<String, String> id2Cover = examples.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(e -> StringUtils.hasLength(e.getCoverPicture()))
|
||||
.collect(Collectors.toMap(Astral3DScenesExample::getId, Astral3DScenesExample::getCoverPicture, (a, b) -> a));
|
||||
|
||||
// 回填 coverPicture
|
||||
for (Astral3DScenes r : records) {
|
||||
if (!StringUtils.hasLength(r.getCoverPicture())) {
|
||||
String exId = r.getExampleSceneId();
|
||||
if (exId != null) {
|
||||
String fallbackCover = id2Cover.get(exId);
|
||||
if (StringUtils.hasLength(fallbackCover)) {
|
||||
r.setCoverPicture(fallbackCover);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
long count = astral3DScenesService.count(queryWrapper);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("items", resultPage.getRecords());
|
||||
result.put("current", offset + 1);
|
||||
result.put("pageSize", limit);
|
||||
result.put("pages", (count + limit - 1) / limit);
|
||||
result.put("total", count);
|
||||
return Result.success(result);
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/update/{id}")
|
||||
public Result<?> put(@PathVariable("id") String id, @RequestBody Astral3DScenes lb3dEditorScenes) {
|
||||
Astral3DScenes oldScenes = astral3DScenesService.getById(id);
|
||||
if (oldScenes != null) {
|
||||
String zip = oldScenes.getZip();
|
||||
if (StringUtils.hasLength(zip)) {
|
||||
// 删除文件父级的文件夹及其下所有文件
|
||||
|
||||
String folder = zip.substring(0, zip.lastIndexOf("/"));
|
||||
if (!CommonUtils.deleteFile(folder)) {
|
||||
throw new RuntimeException(folder + " 删除文件失败");
|
||||
}
|
||||
}
|
||||
String oldCoverPicture = oldScenes.getCoverPicture();
|
||||
if (StringUtils.hasLength(oldCoverPicture)) {
|
||||
// 判断封面图是否变更
|
||||
if (!oldCoverPicture.equals(lb3dEditorScenes.getCoverPicture())) {
|
||||
if (!CommonUtils.deleteFile(oldCoverPicture)) {
|
||||
throw new RuntimeException(oldCoverPicture + " 删除文件失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lb3dEditorScenes.setId(id);
|
||||
boolean b = astral3DScenesService.updateById(lb3dEditorScenes);
|
||||
if (b) {
|
||||
return Result.success(lb3dEditorScenes);
|
||||
} else {
|
||||
return Result.error("更新失败");
|
||||
}
|
||||
}
|
||||
|
||||
@DeleteMapping("/del/{id}")
|
||||
public Result<?> delete(@PathVariable String id) {
|
||||
return Result.toAjax(astral3DScenesService.removeById(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.astral.business.scenes.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.astral.common.result.Result;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.astral.business.scenes.entity.Astral3DScenesExample;
|
||||
import com.astral.business.scenes.service.Astral3DScenesExampleService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 新建场景时的示例表(Astral3DScenesExample)表控制层
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/editor3d/sceneExample")
|
||||
public class Astral3DScenesExampleController {
|
||||
/**
|
||||
* 服务对象
|
||||
*/
|
||||
@Autowired
|
||||
private Astral3DScenesExampleService astral3DScenesExampleService;
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
public Result<?> post(@RequestBody Astral3DScenesExample lb3dEditorScenesExample) {
|
||||
if (astral3DScenesExampleService.save(lb3dEditorScenesExample)) {
|
||||
return Result.success(lb3dEditorScenesExample);
|
||||
} else {
|
||||
return Result.error("新增失败");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Result<?> getOne(@PathVariable("id") String id) {
|
||||
try {
|
||||
return Result.success(astral3DScenesExampleService.getById(id));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public Result<?> getAll(HttpServletRequest request) {
|
||||
String fieldsStr = request.getParameter("fields");
|
||||
List<String> fields = StringUtils.hasLength(fieldsStr) ? Arrays.asList(fieldsStr.split(",")) : new ArrayList<>();
|
||||
String limitStr = request.getParameter("limit");
|
||||
Integer limit = StringUtils.hasLength(limitStr) ? Integer.parseInt(limitStr) : 10;
|
||||
String offsetStr = request.getParameter("offset");
|
||||
Integer offset = StringUtils.hasLength(offsetStr) ? Integer.parseInt(offsetStr) : 0;
|
||||
String sortbyStr = request.getParameter("sortby");
|
||||
List<String> sortby = StringUtils.hasLength(sortbyStr) ? Arrays.asList(sortbyStr.split(",")) : new ArrayList<>();
|
||||
String orderStr = request.getParameter("order");
|
||||
List<String> order = StringUtils.hasLength(orderStr) ? Arrays.asList(orderStr.split(",")) : new ArrayList<>();
|
||||
String queryStr = request.getParameter("query");
|
||||
Map<String, String> query = new HashMap<>();
|
||||
if (StringUtils.hasLength(queryStr)) {
|
||||
try {
|
||||
query = Arrays.stream(queryStr.split(",")).map(s -> {
|
||||
String[] split = s.split(":");
|
||||
if (split.length != 2) {
|
||||
throw new IllegalArgumentException("error:无效的查询键/值对");
|
||||
}
|
||||
return split;
|
||||
}).collect(Collectors.toMap(s -> s[0], s -> s[1], (v1, v2) -> v1));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
QueryWrapper<Astral3DScenesExample> queryWrapper = new QueryWrapper<Astral3DScenesExample>();
|
||||
query.forEach((k, v) -> {
|
||||
String filedName = StringUtils.replace(k, ".", "__");
|
||||
if ("isnull".equals(filedName)) {
|
||||
queryWrapper.eq(filedName, "true".equals(v) || "1".equals(v));
|
||||
} else {
|
||||
queryWrapper.eq(filedName, v);
|
||||
}
|
||||
});
|
||||
if (!CollectionUtils.isEmpty(sortby)) {
|
||||
if (sortby.size() == order.size()) {
|
||||
for (int i = 0; i < sortby.size(); i++) {
|
||||
if ("desc".equals(order.get(i))) {
|
||||
queryWrapper.orderByDesc(sortby.get(i));
|
||||
} else if ("asc".equals(order.get(i))) {
|
||||
queryWrapper.orderByAsc(sortby.get(i));
|
||||
} else {
|
||||
return Result.error("Error: Invalid order. Must be either [asc|desc]");
|
||||
}
|
||||
}
|
||||
|
||||
} else if (order.size() == 1) {
|
||||
if ("desc".equals(order.get(0))) {
|
||||
queryWrapper.orderByDesc(sortby);
|
||||
} else if ("asc".equals(order.get(0))) {
|
||||
queryWrapper.orderByAsc(sortby);
|
||||
}else {
|
||||
return Result.error("Error: Invalid order. Must be either [asc|desc]");
|
||||
}
|
||||
} else {
|
||||
return Result.error("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1");
|
||||
}
|
||||
} else {
|
||||
if (!CollectionUtils.isEmpty(order)) {
|
||||
return Result.error("Error: unused 'order' fields");
|
||||
}
|
||||
}
|
||||
Page<Astral3DScenesExample> page = new Page<>();
|
||||
page.setSize(limit);
|
||||
page.setCurrent(offset / limit + 1);
|
||||
if (!CollectionUtils.isEmpty(fields)) {
|
||||
queryWrapper.select(fields);
|
||||
}
|
||||
try {
|
||||
Page<Astral3DScenesExample> resultPage = astral3DScenesExampleService.page(page, queryWrapper);
|
||||
long count = astral3DScenesExampleService.count(queryWrapper);
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("items", resultPage.getRecords());
|
||||
result.put("current", offset + 1);
|
||||
result.put("pageSize", limit);
|
||||
result.put("pages", (count + limit - 1) / limit);
|
||||
result.put("total", count);
|
||||
return Result.success(result);
|
||||
} catch (Exception e) {
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{id}")
|
||||
public Result<?> put(@PathVariable("id") String id, @RequestBody Astral3DScenesExample lb3dEditorScenesExample) {
|
||||
lb3dEditorScenesExample.setId(id);
|
||||
return Result.toAjax(astral3DScenesExampleService.updateById(lb3dEditorScenesExample));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<?> delete(@PathVariable("id") String id) {
|
||||
return Result.toAjax(astral3DScenesExampleService.removeById(id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.astral.business.scenes.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 场景zip压缩包信息表(Astral3DEditorScenes)表实体类
|
||||
*/
|
||||
@Data
|
||||
@TableName("astral_3d_scenes")
|
||||
public class Astral3DScenes {
|
||||
|
||||
//主键ID,UUID
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
//场景类型
|
||||
@TableField("sceneType")
|
||||
private String sceneType;
|
||||
|
||||
//场景名称
|
||||
@TableField("sceneName")
|
||||
private String sceneName;
|
||||
|
||||
//场景版本
|
||||
@TableField("sceneVersion")
|
||||
private Integer sceneVersion;
|
||||
|
||||
//场景描述
|
||||
@TableField("sceneIntroduction")
|
||||
private String sceneIntroduction;
|
||||
|
||||
//保存场景时自动生成的封面图url
|
||||
@TableField("coverPicture")
|
||||
private String coverPicture;
|
||||
|
||||
//场景是否包含图纸 0:false 1:true
|
||||
@TableField("hasDrawing")
|
||||
private Integer hasDrawing;
|
||||
|
||||
//场景zip包
|
||||
private String zip;
|
||||
|
||||
//场景zip包大小
|
||||
@TableField("zipSize")
|
||||
private String zipSize;
|
||||
|
||||
//创建项目时来源于哪一个示例模板项目,null代表从空项目创建。(fk)
|
||||
@TableField("exampleSceneId")
|
||||
private String exampleSceneId;
|
||||
|
||||
//项目类型。0:Web3D-THREE 1:WebGIS-Cesium
|
||||
@TableField("projectType")
|
||||
private Integer projectType;
|
||||
|
||||
//WebGIS-Cesium 类型项目的基础Cesium配置
|
||||
@TableField("cesiumConfig")
|
||||
private String cesiumConfig;
|
||||
|
||||
//删除标记,0 未删除 1 已删除
|
||||
@TableField("delTag")
|
||||
private Integer delTag;
|
||||
|
||||
@TableField("createTime")
|
||||
private Date createTime;
|
||||
|
||||
@TableField("updateTime")
|
||||
private Date updateTime;
|
||||
|
||||
@TableField("delTime")
|
||||
private Date delTime;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.astral.business.scenes.entity;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 新建场景时的示例表(Astral3DScenesExample)表实体类
|
||||
*/
|
||||
@Data
|
||||
@TableName("astral_3d_scenes_example")
|
||||
public class Astral3DScenesExample {
|
||||
|
||||
//主键ID,UUID
|
||||
@TableId(type = IdType.ASSIGN_UUID)
|
||||
private String id;
|
||||
|
||||
//场景类型
|
||||
@TableField("sceneType")
|
||||
private String sceneType;
|
||||
|
||||
//场景名称
|
||||
@TableField("sceneName")
|
||||
private String sceneName;
|
||||
|
||||
//场景版本
|
||||
@TableField("sceneVersion")
|
||||
private Integer sceneVersion;
|
||||
|
||||
//场景描述
|
||||
@TableField("sceneIntroduction")
|
||||
private String sceneIntroduction;
|
||||
|
||||
//保存场景时自动生成的封面图url
|
||||
@TableField("coverPicture")
|
||||
private String coverPicture;
|
||||
|
||||
//场景是否包含图纸 0:false 1:true
|
||||
@TableField("hasDrawing")
|
||||
private Integer hasDrawing;
|
||||
|
||||
//场景zip包
|
||||
private String zip;
|
||||
|
||||
//场景zip包大小
|
||||
@TableField("zipSize")
|
||||
private String zipSize;
|
||||
|
||||
//示例项目类型。0:Web3D-THREE 1:WebGIS-Cesium
|
||||
@TableField("projectType")
|
||||
private Integer projectType;
|
||||
|
||||
//WebGIS-Cesium 类型项目的基础Cesium配置
|
||||
@TableField("cesiumConfig")
|
||||
private String cesiumConfig;
|
||||
|
||||
//删除标记,0 未删除 1 已删除
|
||||
@TableField("delTag")
|
||||
private Integer delTag;
|
||||
|
||||
@TableField("createTime")
|
||||
private Date createTime;
|
||||
|
||||
@TableField("updateTime")
|
||||
private Date updateTime;
|
||||
|
||||
@TableField("delTime")
|
||||
private Date delTime;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.astral.business.scenes.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.astral.business.scenes.entity.Astral3DScenesExample;
|
||||
|
||||
/**
|
||||
* 新建场景时的示例表(Astral3DScenesExample)表数据库访问层
|
||||
*/
|
||||
public interface Astral3DScenesExampleMapper extends BaseMapper<Astral3DScenesExample> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.astral.business.scenes.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.astral.business.scenes.entity.Astral3DScenes;
|
||||
|
||||
/**
|
||||
* 场景zip压缩包信息表(Astral3DScenes)表数据库访问层
|
||||
*/
|
||||
public interface Astral3DScenesMapper extends BaseMapper<Astral3DScenes> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.astral.business.scenes.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.astral.business.scenes.entity.Astral3DScenesExample;
|
||||
|
||||
/**
|
||||
* 新建场景时的示例表(Astral3DScenesExample)表服务接口
|
||||
*/
|
||||
public interface Astral3DScenesExampleService extends IService<Astral3DScenesExample> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.astral.business.scenes.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.astral.business.scenes.entity.Astral3DScenes;
|
||||
|
||||
/**
|
||||
* 场景zip压缩包信息表(Astral3DScenes)表服务接口
|
||||
*/
|
||||
public interface Astral3DScenesService extends IService<Astral3DScenes> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.astral.business.scenes.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.astral.business.scenes.mapper.Astral3DScenesExampleMapper;
|
||||
import com.astral.business.scenes.entity.Astral3DScenesExample;
|
||||
import com.astral.business.scenes.service.Astral3DScenesExampleService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 新建场景时的示例表(Astral3DScenesExample)表服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class Astral3DScenesExampleServiceImpl extends ServiceImpl<Astral3DScenesExampleMapper, Astral3DScenesExample> implements Astral3DScenesExampleService {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.astral.business.scenes.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.astral.business.scenes.mapper.Astral3DScenesMapper;
|
||||
import com.astral.business.scenes.entity.Astral3DScenes;
|
||||
import com.astral.business.scenes.service.Astral3DScenesService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 场景zip压缩包信息表(Astral3DScenes)表服务实现类
|
||||
*/
|
||||
@Service
|
||||
public class Astral3DScenesServiceImpl extends ServiceImpl<Astral3DScenesMapper, Astral3DScenes> implements Astral3DScenesService {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.astral.business.cad.mapper.Astral3DCadMapper">
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.astral.business.scenes.mapper.Astral3DScenesExampleMapper">
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.astral.business.scenes.mapper.Astral3DScenesMapper">
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user