Merge remote-tracking branch 'origin/dev_shb' into dev-xp
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
package com.ai.da.common.utils;
|
package com.ai.da.common.utils;
|
||||||
|
|
||||||
|
import com.ai.da.common.config.exception.BusinessException;
|
||||||
import com.ai.da.mapper.entity.ObjectItem;
|
import com.ai.da.mapper.entity.ObjectItem;
|
||||||
import io.minio.*;
|
import io.minio.*;
|
||||||
|
import io.minio.errors.MinioException;
|
||||||
|
import io.minio.http.Method;
|
||||||
import io.minio.messages.DeleteError;
|
import io.minio.messages.DeleteError;
|
||||||
import io.minio.messages.DeleteObject;
|
import io.minio.messages.DeleteObject;
|
||||||
import io.minio.messages.Item;
|
import io.minio.messages.Item;
|
||||||
@@ -20,9 +23,12 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -210,6 +216,30 @@ public class MinioUtil {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取文件的临时URL
|
||||||
|
*
|
||||||
|
* @param bucketName 存储桶名称
|
||||||
|
* @param fileName 文件名
|
||||||
|
* @param expiry 过期时间(单位:分)
|
||||||
|
* @return 文件的临时URL,如果出现异常则返回null
|
||||||
|
*/
|
||||||
|
public String getPresignedUrl(String bucketName, String fileName, int expiry) {
|
||||||
|
try {
|
||||||
|
return minioClient.getPresignedObjectUrl(
|
||||||
|
GetPresignedObjectUrlArgs.builder()
|
||||||
|
.bucket(bucketName)
|
||||||
|
.object(fileName)
|
||||||
|
.expiry(expiry, TimeUnit.MINUTES)
|
||||||
|
.method(Method.GET)
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
} catch (MinioException | InvalidKeyException | IOException | NoSuchAlgorithmException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new BusinessException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -29,6 +30,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
@RequestMapping("/api/workspace")
|
@RequestMapping("/api/workspace")
|
||||||
@Api(value = "", tags = "接口")
|
@Api(value = "", tags = "接口")
|
||||||
public class WorkspaceController {
|
public class WorkspaceController {
|
||||||
@@ -40,10 +42,10 @@ public class WorkspaceController {
|
|||||||
private MinioUtil minIoUtil;
|
private MinioUtil minIoUtil;
|
||||||
|
|
||||||
@Value("${minio.endpoint}")
|
@Value("${minio.endpoint}")
|
||||||
private static String address;
|
public String address;
|
||||||
|
|
||||||
@Value("${minio.bucketName}")
|
@Value("${minio.bucketName}")
|
||||||
private static String bucketName;
|
public String bucketName;
|
||||||
|
|
||||||
@PostMapping("/upload")
|
@PostMapping("/upload")
|
||||||
public Object upload(MultipartFile file) {
|
public Object upload(MultipartFile file) {
|
||||||
@@ -53,6 +55,12 @@ public class WorkspaceController {
|
|||||||
return address+"/"+bucketName+"/"+upload.get(0);
|
return address+"/"+bucketName+"/"+upload.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/getUrl")
|
||||||
|
public Object getUrl() {
|
||||||
|
|
||||||
|
return minIoUtil.getPresignedUrl("test", "R-C_1694066189047.png", 5);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 详情
|
* 详情
|
||||||
*/
|
*/
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -6,10 +6,7 @@ import com.ai.da.common.config.exception.BusinessException;
|
|||||||
import com.ai.da.common.context.UserContext;
|
import com.ai.da.common.context.UserContext;
|
||||||
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
||||||
import com.ai.da.common.enums.SysFileLevel2TypeEnum;
|
import com.ai.da.common.enums.SysFileLevel2TypeEnum;
|
||||||
import com.ai.da.common.utils.CopyUtil;
|
import com.ai.da.common.utils.*;
|
||||||
import com.ai.da.common.utils.DateUtil;
|
|
||||||
import com.ai.da.common.utils.FileUtil;
|
|
||||||
import com.ai.da.common.utils.LocalCacheUtils;
|
|
||||||
import com.ai.da.mapper.DesignMapper;
|
import com.ai.da.mapper.DesignMapper;
|
||||||
import com.ai.da.mapper.entity.*;
|
import com.ai.da.mapper.entity.*;
|
||||||
import com.ai.da.mapper.entity.Collection;
|
import com.ai.da.mapper.entity.Collection;
|
||||||
@@ -178,7 +175,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
//保存collection
|
//保存collection
|
||||||
Long collectionId = (null == collectionIdParam) ?
|
Long collectionId = (null == collectionIdParam) ?
|
||||||
collectionService.saveCollection(userInfo.getId(),designDTO.getTimeZone(),designDTO.getMoodTemplateId()) : collectionIdParam;
|
collectionService.saveCollection(userInfo.getId(),designDTO.getTimeZone(),designDTO.getMoodTemplateId()) : collectionIdParam;
|
||||||
List<Long> elementIds =getElementId(elementVO);
|
List<Long> elementIds = getElementId(elementVO);
|
||||||
//批量关联element 到 collection
|
//批量关联element 到 collection
|
||||||
collectionElementService.relationCollection(elementIds,collectionId);
|
collectionElementService.relationCollection(elementIds,collectionId);
|
||||||
//library转化为collection(生成)
|
//library转化为collection(生成)
|
||||||
@@ -233,7 +230,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
//计算library
|
//计算library
|
||||||
calculateLibraryAndSysFile(designDTO,elementVO,userInfo);
|
calculateLibraryAndSysFile(designDTO,elementVO,userInfo);
|
||||||
//组装design入参
|
//组装design入参
|
||||||
DesignPythonObjects pythonObjects =pythonService.covertDesignParam(designDTO.getSystemScale(),
|
DesignPythonObjects pythonObjects = pythonService.covertDesignParam(designDTO.getSystemScale(),
|
||||||
designDTO.getSingleOverall(),designDTO.getSwitchCategory(),elementVO);
|
designDTO.getSingleOverall(),designDTO.getSwitchCategory(),elementVO);
|
||||||
//缓存保存的文件 方便后面处理进度问题
|
//缓存保存的文件 方便后面处理进度问题
|
||||||
setDesignProcess(userInfo.getId(),pythonObjects);
|
setDesignProcess(userInfo.getId(),pythonObjects);
|
||||||
@@ -344,6 +341,9 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
return object.getBasic().getSave_name();}).collect(Collectors.toList());
|
return object.getBasic().getSave_name();}).collect(Collectors.toList());
|
||||||
LocalCacheUtils.setDesignProcessCache(userId,saveNames);
|
LocalCacheUtils.setDesignProcessCache(userId,saveNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MinioUtil minIoUtil;
|
||||||
private DesignCollectionVO savePythonDesignItemAndDetail(DesignPythonObjects pythonObjects
|
private DesignCollectionVO savePythonDesignItemAndDetail(DesignPythonObjects pythonObjects
|
||||||
,Long designId,Long collectionId,AuthPrincipalVo userInfo,String timeZone, JSONObject responseJSONObject){
|
,Long designId,Long collectionId,AuthPrincipalVo userInfo,String timeZone, JSONObject responseJSONObject){
|
||||||
DesignCollectionVO response = new DesignCollectionVO();
|
DesignCollectionVO response = new DesignCollectionVO();
|
||||||
@@ -352,6 +352,9 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
List<DesignCollectionItemVO> designCollectionItems = Lists.newArrayList();
|
List<DesignCollectionItemVO> designCollectionItems = Lists.newArrayList();
|
||||||
response.setDesignCollectionItems(designCollectionItems);
|
response.setDesignCollectionItems(designCollectionItems);
|
||||||
JSONObject data = responseJSONObject.getJSONObject("data");
|
JSONObject data = responseJSONObject.getJSONObject("data");
|
||||||
|
if (data == null) {
|
||||||
|
throw new BusinessException("python response data is null");
|
||||||
|
}
|
||||||
for (int i = 0; i < pythonObjects.getObjects().size(); i++) {
|
for (int i = 0; i < pythonObjects.getObjects().size(); i++) {
|
||||||
DesignPythonObject item = pythonObjects.getObjects().get(i);
|
DesignPythonObject item = pythonObjects.getObjects().get(i);
|
||||||
DesignItem designItem = new DesignItem();
|
DesignItem designItem = new DesignItem();
|
||||||
@@ -385,7 +388,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
designPythonOutfitDetail.setDesignPythonOutfitId(designPythonOutfit.getId());
|
designPythonOutfitDetail.setDesignPythonOutfitId(designPythonOutfit.getId());
|
||||||
JSONArray position = jsonObject.getJSONArray("position");
|
JSONArray position = jsonObject.getJSONArray("position");
|
||||||
if (position != null && !CollectionUtils.isEmpty(position)) {
|
if (position != null && !CollectionUtils.isEmpty(position)) {
|
||||||
StringBuilder builder = null;
|
StringBuilder builder = new StringBuilder();
|
||||||
for (int i2 = 0; i2 < position.size(); i2++) {
|
for (int i2 = 0; i2 < position.size(); i2++) {
|
||||||
if (i2 != position.size() - 1) {
|
if (i2 != position.size() - 1) {
|
||||||
builder.append(position.getInteger(i2)).append(",");
|
builder.append(position.getInteger(i2)).append(",");
|
||||||
@@ -397,7 +400,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
}
|
}
|
||||||
JSONArray imageSize = jsonObject.getJSONArray("image_size");
|
JSONArray imageSize = jsonObject.getJSONArray("image_size");
|
||||||
if (imageSize != null && !CollectionUtils.isEmpty(position)) {
|
if (imageSize != null && !CollectionUtils.isEmpty(position)) {
|
||||||
StringBuilder builder = null;
|
StringBuilder builder = new StringBuilder();
|
||||||
for (int i2 = 0; i2 < imageSize.size(); i2++) {
|
for (int i2 = 0; i2 < imageSize.size(); i2++) {
|
||||||
if (i2 != imageSize.size() - 1) {
|
if (i2 != imageSize.size() - 1) {
|
||||||
builder.append(imageSize.getInteger(i2)).append(",");
|
builder.append(imageSize.getInteger(i2)).append(",");
|
||||||
@@ -418,7 +421,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
|||||||
designCollectionItemVO.setDesignItemId(designItemId);
|
designCollectionItemVO.setDesignItemId(designItemId);
|
||||||
designCollectionItemVO.setDesignItemUrl(designItem.getDesignUrl());
|
designCollectionItemVO.setDesignItemUrl(designItem.getDesignUrl());
|
||||||
designCollectionItemVO.setDesignOutfitId(designPythonOutfit.getId());
|
designCollectionItemVO.setDesignOutfitId(designPythonOutfit.getId());
|
||||||
designCollectionItemVO.setDesignOutfitUrl(endpoint + "/" + bucketName + "/" + designPythonOutfit.getDesignUrl());
|
designCollectionItemVO.setDesignOutfitUrl(minIoUtil.getPresignedUrl(bucketName, designPythonOutfit.getDesignUrl(), 5));
|
||||||
//response
|
//response
|
||||||
designCollectionItems.add(designCollectionItemVO);
|
designCollectionItems.add(designCollectionItemVO);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user