TASK:workspace、design模块代码;
This commit is contained in:
33
src/main/java/com/ai/da/common/config/MinIoClientConfig.java
Normal file
33
src/main/java/com/ai/da/common/config/MinIoClientConfig.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.ai.da.common.config;
|
||||
|
||||
import io.minio.MinioClient;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Data
|
||||
@Component
|
||||
public class MinIoClientConfig {
|
||||
@Value("${minio.endpoint}")
|
||||
private String endpoint;
|
||||
@Value("${minio.accessKey}")
|
||||
private String accessKey;
|
||||
@Value("${minio.secretKey}")
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* 注入minio 客户端
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public MinioClient minioClient(){
|
||||
|
||||
return MinioClient.builder()
|
||||
.endpoint(endpoint)
|
||||
.credentials(accessKey, secretKey)
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
216
src/main/java/com/ai/da/common/utils/MinioUtil.java
Normal file
216
src/main/java/com/ai/da/common/utils/MinioUtil.java
Normal file
@@ -0,0 +1,216 @@
|
||||
package com.ai.da.common.utils;
|
||||
|
||||
import com.ai.da.mapper.entity.ObjectItem;
|
||||
import io.minio.*;
|
||||
import io.minio.messages.DeleteError;
|
||||
import io.minio.messages.DeleteObject;
|
||||
import io.minio.messages.Item;
|
||||
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @description: minio工具类
|
||||
* @version:3.0
|
||||
*/
|
||||
@Component
|
||||
public class MinioUtil {
|
||||
@Autowired
|
||||
private MinioClient minioClient;
|
||||
|
||||
@Value("${minio.bucketName}")
|
||||
private String bucketName;
|
||||
/**
|
||||
* description: 判断bucket是否存在,不存在则创建
|
||||
*
|
||||
* @return: void
|
||||
*/
|
||||
public void existBucket(String name) {
|
||||
try {
|
||||
boolean exists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(name).build());
|
||||
if (!exists) {
|
||||
minioClient.makeBucket(MakeBucketArgs.builder().bucket(name).build());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建存储bucket
|
||||
* @param bucketName 存储bucket名称
|
||||
* @return Boolean
|
||||
*/
|
||||
public Boolean makeBucket(String bucketName) {
|
||||
try {
|
||||
minioClient.makeBucket(MakeBucketArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.build());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除存储bucket
|
||||
* @param bucketName 存储bucket名称
|
||||
* @return Boolean
|
||||
*/
|
||||
public Boolean removeBucket(String bucketName) {
|
||||
try {
|
||||
minioClient.removeBucket(RemoveBucketArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.build());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* description: 上传文件
|
||||
*
|
||||
* @param multipartFile
|
||||
* @return: java.lang.String
|
||||
|
||||
*/
|
||||
public List<String> upload(MultipartFile[] multipartFile) {
|
||||
List<String> names = new ArrayList<>(multipartFile.length);
|
||||
for (MultipartFile file : multipartFile) {
|
||||
String fileName = file.getOriginalFilename();
|
||||
String[] split = fileName.split("\\.");
|
||||
if (split.length > 1) {
|
||||
fileName = split[0] + "_" + System.currentTimeMillis() + "." + split[1];
|
||||
} else {
|
||||
fileName = fileName + System.currentTimeMillis();
|
||||
}
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = file.getInputStream();
|
||||
minioClient.putObject(PutObjectArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(fileName)
|
||||
.stream(in, in.available(), -1)
|
||||
.contentType(file.getContentType())
|
||||
.build()
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
names.add(fileName);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* description: 下载文件
|
||||
*
|
||||
* @param fileName
|
||||
* @return: org.springframework.http.ResponseEntity<byte [ ]>
|
||||
*/
|
||||
public ResponseEntity<byte[]> download(String fileName) {
|
||||
ResponseEntity<byte[]> responseEntity = null;
|
||||
InputStream in = null;
|
||||
ByteArrayOutputStream out = null;
|
||||
try {
|
||||
in = minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(fileName).build());
|
||||
out = new ByteArrayOutputStream();
|
||||
IOUtils.copy(in, out);
|
||||
//封装返回值
|
||||
byte[] bytes = out.toByteArray();
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
try {
|
||||
headers.add("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
headers.setContentLength(bytes.length);
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
headers.setAccessControlExposeHeaders(Arrays.asList("*"));
|
||||
responseEntity = new ResponseEntity<byte[]>(bytes, headers, HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看文件对象
|
||||
* @param bucketName 存储bucket名称
|
||||
* @return 存储bucket内文件对象信息
|
||||
*/
|
||||
public List<ObjectItem> listObjects(String bucketName) {
|
||||
Iterable<Result<Item>> results = minioClient.listObjects(
|
||||
ListObjectsArgs.builder().bucket(bucketName).build());
|
||||
List<ObjectItem> objectItems = new ArrayList<>();
|
||||
try {
|
||||
for (Result<Item> result : results) {
|
||||
Item item = result.get();
|
||||
ObjectItem objectItem = new ObjectItem();
|
||||
objectItem.setObjectName(item.objectName());
|
||||
objectItem.setSize(item.size());
|
||||
objectItems.add(objectItem);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return objectItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除文件对象
|
||||
* @param bucketName 存储bucket名称
|
||||
* @param objects 对象名称集合
|
||||
*/
|
||||
public Iterable<Result<DeleteError>> removeObjects(String bucketName, List<String> objects) {
|
||||
List<DeleteObject> dos = objects.stream().map(e -> new DeleteObject(e)).collect(Collectors.toList());
|
||||
Iterable<Result<DeleteError>> results = minioClient.removeObjects(RemoveObjectsArgs.builder().bucket(bucketName).objects(dos).build());
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public class DesignController {
|
||||
|
||||
@ApiOperation(value = "设计 Conllection")
|
||||
@PostMapping("/designCollection")
|
||||
public Response<JSONObject> designCollection(@Valid @RequestBody DesignCollectionDTO designDTO) {
|
||||
public Response<DesignCollectionVO> designCollection(@Valid @RequestBody DesignCollectionDTO designDTO) {
|
||||
return Response.success(designService.designCollection(designDTO));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.common.response.Response;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.MinioUtil;
|
||||
import com.ai.da.mapper.entity.Account;
|
||||
import com.ai.da.mapper.entity.UserLikeGroup;
|
||||
import com.ai.da.mapper.entity.Workspace;
|
||||
@@ -30,10 +31,12 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -56,6 +59,21 @@ public class WorkspaceController {
|
||||
@Resource
|
||||
private WorkspaceService workspaceService;
|
||||
|
||||
@Resource
|
||||
private MinioUtil minIoUtil;
|
||||
@Value("${minio.endpoint}")
|
||||
private static String address;
|
||||
@Value("${minio.bucketName}")
|
||||
private static String bucketName;
|
||||
|
||||
@PostMapping("/upload")
|
||||
public Object upload(MultipartFile file) {
|
||||
|
||||
List<String> upload = minIoUtil.upload(new MultipartFile[]{file});
|
||||
|
||||
return address+"/"+bucketName+"/"+upload.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@@ -63,19 +81,19 @@ public class WorkspaceController {
|
||||
@ApiOperationSupport(order = 1)
|
||||
@ApiOperation(value = "详情", notes = "传入workspace")
|
||||
public Response<Workspace> detail(@ApiParam(value = "主键集合", required = true) @RequestParam Long id) {
|
||||
Workspace detail = workspaceService.getById(id);
|
||||
Workspace detail = workspaceService.getByIdNew(id);
|
||||
return Response.success(detail);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@PostMapping("/list")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@ApiOperation(value = "分页", notes = "传入workspace")
|
||||
public Response<PageBaseResponse<Workspace>> list(@Valid @RequestBody WorkspaceDTO query) {
|
||||
IPage<Workspace> convert = workspaceService.getPage(query);
|
||||
return Response.success(PageBaseResponse.success(convert));
|
||||
public Response<WorkspaceVO> list(@Valid @RequestBody WorkspaceDTO query) {
|
||||
WorkspaceVO response = workspaceService.getPage(query);
|
||||
return Response.success(response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
19
src/main/java/com/ai/da/mapper/PythonTAllInfoMapper.java
Normal file
19
src/main/java/com/ai/da/mapper/PythonTAllInfoMapper.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package com.ai.da.mapper;
|
||||
|
||||
import com.ai.da.common.config.mybatis.plus.CommonMapper;
|
||||
import com.ai.da.mapper.entity.PythonTAllInfo;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (PythonTAllInfo)表数据库访问层
|
||||
*
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-09-08 17:05:24
|
||||
*/
|
||||
public interface PythonTAllInfoMapper extends CommonMapper<PythonTAllInfo> {
|
||||
|
||||
}
|
||||
|
||||
10
src/main/java/com/ai/da/mapper/entity/ObjectItem.java
Normal file
10
src/main/java/com/ai/da/mapper/entity/ObjectItem.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.ai.da.mapper.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ObjectItem {
|
||||
private String objectName;
|
||||
private Long size;
|
||||
}
|
||||
|
||||
86
src/main/java/com/ai/da/mapper/entity/PythonTAllInfo.java
Normal file
86
src/main/java/com/ai/da/mapper/entity/PythonTAllInfo.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package com.ai.da.mapper.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* (PythonTAllInfo)实体类
|
||||
*
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-09-08 17:05:25
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@TableName("python_t_all_info")
|
||||
public class PythonTAllInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private String imagePath;
|
||||
|
||||
private String imageCategory;
|
||||
|
||||
private String necklineLeft;
|
||||
|
||||
private String necklineRight;
|
||||
|
||||
private String centerFront;
|
||||
|
||||
private String shoulderLeft;
|
||||
|
||||
private String shoulderRight;
|
||||
|
||||
private String armpitLeft;
|
||||
|
||||
private String armpitRight;
|
||||
|
||||
private String waistlineLeft;
|
||||
|
||||
private String waistlineRight;
|
||||
|
||||
private String cuffLeftIn;
|
||||
|
||||
private String cuffLeftOut;
|
||||
|
||||
private String cuffRightIn;
|
||||
|
||||
private String cuffRightOut;
|
||||
|
||||
private String topHemLeft;
|
||||
|
||||
private String topHemRight;
|
||||
|
||||
private String waistbandLeft;
|
||||
|
||||
private String waistbandRight;
|
||||
|
||||
private String hemlineLeft;
|
||||
|
||||
private String hemlineRight;
|
||||
|
||||
private String crotch;
|
||||
|
||||
private String bottomLeftIn;
|
||||
|
||||
private String bottomLeftOut;
|
||||
|
||||
private String bottomRightIn;
|
||||
|
||||
private String bottomRightOut;
|
||||
|
||||
private String md5;
|
||||
|
||||
private String maskPath;
|
||||
|
||||
private String segResultPath;
|
||||
}
|
||||
|
||||
@@ -30,6 +30,11 @@ public class TDesignPythonOutfit implements Serializable {
|
||||
@ApiModelProperty(value = "ID")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
/**
|
||||
* designItemId
|
||||
*/
|
||||
@ApiModelProperty(value = "designItemId")
|
||||
private Long designItemId;
|
||||
/**
|
||||
* 关联的design ID
|
||||
*/
|
||||
|
||||
@@ -62,6 +62,11 @@ public class Workspace implements Serializable {
|
||||
*/
|
||||
@ApiModelProperty(value = "人体模型")
|
||||
private String mannequin;
|
||||
/**
|
||||
* 最后使用的工作空间标识
|
||||
*/
|
||||
@ApiModelProperty(value = "最后使用的工作空间标识")
|
||||
private Integer isLastIndex;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,7 @@ import lombok.EqualsAndHashCode;
|
||||
/**
|
||||
* 数据传输对象实体类
|
||||
*
|
||||
* @author Arcana
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-08-01
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -16,6 +16,13 @@ public class DesignCollectionItemVO {
|
||||
@ApiModelProperty("design生成的图片地址 绝对路径")
|
||||
private String designItemUrl;
|
||||
|
||||
@ApiModelProperty("t_design_python_outfit id")
|
||||
private Long designOutfitId;
|
||||
|
||||
@ApiModelProperty("t_design_python_outfit id")
|
||||
private String designOutfitUrl;
|
||||
|
||||
public DesignCollectionItemVO() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import io.swagger.annotations.ApiModel;
|
||||
/**
|
||||
* design item详情表视图实体类
|
||||
*
|
||||
* @author Arcana
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-09-04
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -10,7 +10,7 @@ import io.swagger.annotations.ApiModel;
|
||||
/**
|
||||
* design item表 存对应design的8张图片视图实体类
|
||||
*
|
||||
* @author Arcana
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-09-04
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
package com.ai.da.model.vo;
|
||||
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.mapper.entity.Workspace;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -9,13 +10,18 @@ import io.swagger.annotations.ApiModel;
|
||||
/**
|
||||
* 视图实体类
|
||||
*
|
||||
* @author Arcana
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-08-01
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ApiModel(value = "WorkspaceVO对象", description = "WorkspaceVO对象")
|
||||
public class WorkspaceVO extends Workspace {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long currentId;
|
||||
|
||||
private PageBaseResponse<Workspace> page;
|
||||
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@ public class DesignPythonItem {
|
||||
* body 对应路径(后面去掉)
|
||||
*/
|
||||
private String body_mask_path;
|
||||
/**
|
||||
* python_t_all_info image_id
|
||||
*/
|
||||
private Long imageId;
|
||||
|
||||
|
||||
public static List<String> OUTWEAR_DRESS_BLOUSE = Arrays.asList(CollectionLevel2TypeEnum.OUTWEAR.getRealName(),
|
||||
|
||||
@@ -22,7 +22,7 @@ public interface DesignService extends IService<Design> {
|
||||
* @param designDTO
|
||||
* @return
|
||||
*/
|
||||
JSONObject designCollection(DesignCollectionDTO designDTO);
|
||||
DesignCollectionVO designCollection(DesignCollectionDTO designDTO);
|
||||
|
||||
/**
|
||||
* redesign
|
||||
|
||||
@@ -9,7 +9,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
/**
|
||||
* design item详情表 服务类
|
||||
*
|
||||
* @author Arcana
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-09-04
|
||||
*/
|
||||
public interface ITDesignPythonOutfitDetailService extends IService<TDesignPythonOutfitDetail> {
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
/**
|
||||
* design item表 存对应design的8张图片 服务类
|
||||
*
|
||||
* @author Arcana
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-09-04
|
||||
*/
|
||||
public interface ITDesignPythonOutfitService extends IService<TDesignPythonOutfit> {
|
||||
|
||||
18
src/main/java/com/ai/da/service/PythonTAllInfoService.java
Normal file
18
src/main/java/com/ai/da/service/PythonTAllInfoService.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
|
||||
|
||||
import com.ai.da.mapper.entity.PythonTAllInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* (PythonTAllInfo)表服务接口
|
||||
*
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-09-08 17:03:47
|
||||
*/
|
||||
public interface PythonTAllInfoService extends IService<PythonTAllInfo> {
|
||||
|
||||
|
||||
Long getImageIdByPath(String path);
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import java.util.List;
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author Arcana
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-08-01
|
||||
*/
|
||||
public interface WorkspaceService extends IService<Workspace> {
|
||||
@@ -30,7 +30,9 @@ public interface WorkspaceService extends IService<Workspace> {
|
||||
|
||||
boolean saveOrUpdate(Workspace workspace);
|
||||
|
||||
IPage<Workspace> getPage(WorkspaceDTO query);
|
||||
WorkspaceVO getPage(WorkspaceDTO query);
|
||||
|
||||
List<BizJson> getEnumValues(String enumName);
|
||||
|
||||
Workspace getByIdNew(Long id);
|
||||
}
|
||||
|
||||
@@ -336,33 +336,34 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
|
||||
}
|
||||
}
|
||||
//校验marketingSketch
|
||||
if (CollectionUtil.isNotEmpty(designDTO.getMarketingSketchs())) {
|
||||
//校验designType
|
||||
validateDesignType(designDTO.getMarketingSketchs(),"marketingSketchs");
|
||||
List<Long> printBoardIds = designDTO.getMarketingSketchs().stream()
|
||||
.filter(f ->f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
|
||||
.map(DesignCollectionElementDTO::getId)
|
||||
.collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(printBoardIds)){
|
||||
List<CollectionElement> marketingSketchElements = collectionElementMapper.selectBatchIds(printBoardIds);
|
||||
Assert.isTrue(CollectionUtil.isNotEmpty(marketingSketchElements)
|
||||
&& marketingSketchElements.size() == printBoardIds.size(), "get marketingSketch data is mismatch");
|
||||
elementVO.setMarketingSketchElements(marketingSketchElements);
|
||||
usedElementIds.addAll(printBoardIds);
|
||||
}
|
||||
//library
|
||||
List<Long> libraryIds = designDTO.getMarketingSketchs().stream()
|
||||
.filter(f ->f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName()))
|
||||
.map(DesignCollectionElementDTO::getId)
|
||||
.collect(Collectors.toList());
|
||||
if(!CollectionUtils.isEmpty(libraryIds)){
|
||||
List<Library> librarys = libraryService.getByIds(libraryIds);
|
||||
//不校验了防止用户在library删除 对应不上
|
||||
if(CollectionUtil.isNotEmpty(librarys)){
|
||||
libraryCollectionElements.addAll(covertLibrarysToCollections(librarys,null));
|
||||
}
|
||||
}
|
||||
}
|
||||
// 2023.12版本去掉了这个入参
|
||||
// if (CollectionUtil.isNotEmpty(designDTO.getMarketingSketchs())) {
|
||||
// //校验designType
|
||||
// validateDesignType(designDTO.getMarketingSketchs(),"marketingSketchs");
|
||||
// List<Long> printBoardIds = designDTO.getMarketingSketchs().stream()
|
||||
// .filter(f ->f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
|
||||
// .map(DesignCollectionElementDTO::getId)
|
||||
// .collect(Collectors.toList());
|
||||
// if(!CollectionUtils.isEmpty(printBoardIds)){
|
||||
// List<CollectionElement> marketingSketchElements = collectionElementMapper.selectBatchIds(printBoardIds);
|
||||
// Assert.isTrue(CollectionUtil.isNotEmpty(marketingSketchElements)
|
||||
// && marketingSketchElements.size() == printBoardIds.size(), "get marketingSketch data is mismatch");
|
||||
// elementVO.setMarketingSketchElements(marketingSketchElements);
|
||||
// usedElementIds.addAll(printBoardIds);
|
||||
// }
|
||||
// //library
|
||||
// List<Long> libraryIds = designDTO.getMarketingSketchs().stream()
|
||||
// .filter(f ->f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName()))
|
||||
// .map(DesignCollectionElementDTO::getId)
|
||||
// .collect(Collectors.toList());
|
||||
// if(!CollectionUtils.isEmpty(libraryIds)){
|
||||
// List<Library> librarys = libraryService.getByIds(libraryIds);
|
||||
// //不校验了防止用户在library删除 对应不上
|
||||
// if(CollectionUtil.isNotEmpty(librarys)){
|
||||
// libraryCollectionElements.addAll(covertLibrarysToCollections(librarys,null));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//校验控制生成类型
|
||||
SingleOverallEnum singleOverall = SingleOverallEnum.of(designDTO.getSingleOverall());
|
||||
Assert.notNull(singleOverall, "unknown parameter singleOverall!");
|
||||
|
||||
@@ -5,15 +5,12 @@ import com.ai.da.common.config.FileProperties;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
||||
import com.ai.da.common.enums.SingleOverallEnum;
|
||||
import com.ai.da.common.enums.SysFileLevel2TypeEnum;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
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.TDesignPythonOutfitDetailMapper;
|
||||
import com.ai.da.mapper.TDesignPythonOutfitMapper;
|
||||
import com.ai.da.mapper.entity.*;
|
||||
import com.ai.da.mapper.entity.Collection;
|
||||
import com.ai.da.model.dto.*;
|
||||
@@ -21,6 +18,7 @@ import com.ai.da.model.vo.*;
|
||||
import com.ai.da.python.PythonService;
|
||||
import com.ai.da.python.vo.DesignPythonItem;
|
||||
import com.ai.da.python.vo.DesignPythonItemPrint;
|
||||
import com.ai.da.python.vo.DesignPythonObject;
|
||||
import com.ai.da.python.vo.DesignPythonObjects;
|
||||
import com.ai.da.service.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
@@ -30,17 +28,17 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.sf.jsqlparser.expression.operators.relational.OldOracleJoinBinaryExpression;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import sun.security.krb5.internal.crypto.Des;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.ai.da.python.vo.DesignPythonItem.*;
|
||||
@@ -82,10 +80,16 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
private ITDesignPythonOutfitService designPythonOutfitService;
|
||||
@Resource
|
||||
private ITDesignPythonOutfitDetailService designPythonOutfitDetailService;
|
||||
@Resource
|
||||
private PythonTAllInfoService pythonTAllInfoService;
|
||||
@Value("${minio.endpoint}")
|
||||
private String endpoint;
|
||||
@Value("${minio.bucketName}")
|
||||
private String bucketName;
|
||||
|
||||
// @Transactional
|
||||
@Override
|
||||
public JSONObject designCollection(DesignCollectionDTO designDTO) {
|
||||
public DesignCollectionVO designCollection(DesignCollectionDTO designDTO) {
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
//校验collection element
|
||||
ValidateElementVO elementVO =collectionElementService.validateElement(designDTO);
|
||||
@@ -183,12 +187,12 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
//计算library
|
||||
calculateLibraryAndSysFile(designDTO,elementVO,userInfo);
|
||||
//组装design入参
|
||||
DesignPythonObjects pythonObjects =pythonService.covertDesignParam(designDTO.getSystemScale(),
|
||||
DesignPythonObjects pythonObjects = pythonService.covertDesignParam(designDTO.getSystemScale(),
|
||||
designDTO.getSingleOverall(),designDTO.getSwitchCategory(),elementVO);
|
||||
//缓存保存的文件 方便后面处理进度问题
|
||||
setDesignProcess(userInfo.getId(),pythonObjects);
|
||||
//design
|
||||
JSONObject responseJSONObject= pythonService.designNew(pythonObjects);
|
||||
pythonService.design(pythonObjects);
|
||||
//生成library
|
||||
generateLibrary(elementVO,designDTO.getTimeZone());
|
||||
//处理关联关系,修复element覆盖得情况
|
||||
@@ -201,7 +205,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
return saveDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone());
|
||||
}
|
||||
|
||||
private JSONObject designOrRedesignOperateNew(DesignCollectionDTO designDTO,AuthPrincipalVo userInfo,
|
||||
private DesignCollectionVO designOrRedesignOperateNew(DesignCollectionDTO designDTO,AuthPrincipalVo userInfo,
|
||||
Long collectionIdParam,ValidateElementVO elementVO){
|
||||
if(CollectionUtil.isNotEmpty(designDTO.getSketchBoards())){
|
||||
//编辑sketchBoard
|
||||
@@ -230,6 +234,8 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
designDTO.getSingleOverall(),designDTO.getSwitchCategory(),elementVO);
|
||||
//缓存保存的文件 方便后面处理进度问题
|
||||
setDesignProcess(userInfo.getId(),pythonObjects);
|
||||
// pythonObjects增加image_id关联
|
||||
relationImageId(pythonObjects);
|
||||
//design
|
||||
JSONObject responseJSONObject= pythonService.designNew(pythonObjects);
|
||||
//生成library
|
||||
@@ -243,6 +249,26 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
//保存designItem 和detail
|
||||
// return saveDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone());
|
||||
}
|
||||
|
||||
private void relationImageId(DesignPythonObjects pythonObjects) {
|
||||
if(Objects.isNull(pythonObjects)) {
|
||||
return;
|
||||
}
|
||||
pythonObjects.getObjects().forEach(
|
||||
o -> {
|
||||
for (DesignPythonItem item : o.getItems()) {
|
||||
String path = item.getPath();
|
||||
if (StringUtils.isEmpty(path)) {
|
||||
item.setImageId(null);
|
||||
}else {
|
||||
Long imageId = pythonTAllInfoService.getImageIdByPath(path);
|
||||
item.setImageId(imageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private void handleCollectionElementRelation(Long collectionId ,Boolean isEdit,List<Long> elementIds ){
|
||||
if (CollectionUtils.isEmpty(elementIds) || collectionId == null){
|
||||
return;
|
||||
@@ -313,15 +339,16 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
return object.getBasic().getSave_name();}).collect(Collectors.toList());
|
||||
LocalCacheUtils.setDesignProcessCache(userId,saveNames);
|
||||
}
|
||||
private JSONObject savePythonDesignItemAndDetail(DesignPythonObjects pythonObjects
|
||||
private DesignCollectionVO savePythonDesignItemAndDetail(DesignPythonObjects pythonObjects
|
||||
,Long designId,Long collectionId,AuthPrincipalVo userInfo,String timeZone, JSONObject responseJSONObject){
|
||||
DesignCollectionVO response = new DesignCollectionVO();
|
||||
response.setDesignId(designId);
|
||||
response.setCollectionId(collectionId);
|
||||
List<DesignCollectionItemVO> designCollectionItems = Lists.newArrayList();
|
||||
response.setDesignCollectionItems(designCollectionItems);
|
||||
|
||||
pythonObjects.getObjects().forEach(item ->{
|
||||
JSONObject data = responseJSONObject.getJSONObject("data");
|
||||
for (int i = 0; i < pythonObjects.getObjects().size(); i++) {
|
||||
DesignPythonObject item = pythonObjects.getObjects().get(i);
|
||||
DesignItem designItem = new DesignItem();
|
||||
designItem.setAccountId(userInfo.getId());
|
||||
designItem.setCollectionId(collectionId);
|
||||
@@ -332,8 +359,37 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
designItem.setHasLike((byte)0);
|
||||
//生成designItem
|
||||
Long designItemId = designItemService.saveOne(designItem);
|
||||
// python design返回入库及封装
|
||||
JSONObject outfit = data.getJSONObject(i + "");
|
||||
TDesignPythonOutfit designPythonOutfit = new TDesignPythonOutfit();
|
||||
designPythonOutfit.setDesignItemId(designItemId);
|
||||
designPythonOutfit.setUserId(userInfo.getId());
|
||||
designPythonOutfit.setDesignId(designId);
|
||||
designPythonOutfit.setCollectionId(collectionId);
|
||||
designPythonOutfit.setDesignUrl(outfit.getString("synthesis_url"));
|
||||
designPythonOutfitService.save(designPythonOutfit);
|
||||
JSONArray layers = outfit.getJSONArray("layers");
|
||||
List<TDesignPythonOutfitDetail> list = new ArrayList<>();
|
||||
for (int i1 = 0; i1 < layers.size(); i1++) {
|
||||
JSONObject jsonObject = layers.getJSONObject(i1);
|
||||
TDesignPythonOutfitDetail designPythonOutfitDetail = new TDesignPythonOutfitDetail();
|
||||
designPythonOutfitDetail.setDesignId(designId);
|
||||
designPythonOutfitDetail.setDesignPythonOutfitId(designPythonOutfit.getId());
|
||||
designPythonOutfitDetail.setPosition(jsonObject.getString("position"));
|
||||
designPythonOutfitDetail.setImageUrl(jsonObject.getString("image_url"));
|
||||
designPythonOutfitDetail.setImageCategory(jsonObject.getString("image_category"));
|
||||
designPythonOutfitDetail.setMaskUrl(jsonObject.getString("mask_url"));
|
||||
designPythonOutfitDetail.setUserId(userInfo.getId());
|
||||
list.add(designPythonOutfitDetail);
|
||||
}
|
||||
designPythonOutfitDetailService.saveBatch(list);
|
||||
DesignCollectionItemVO designCollectionItemVO = new DesignCollectionItemVO();
|
||||
designCollectionItemVO.setDesignItemId(designItemId);
|
||||
designCollectionItemVO.setDesignItemUrl(designItem.getDesignUrl());
|
||||
designCollectionItemVO.setDesignOutfitId(designPythonOutfit.getId());
|
||||
designCollectionItemVO.setDesignOutfitUrl(endpoint + "/" + bucketName + "/" + designPythonOutfit.getDesignUrl());
|
||||
//response
|
||||
designCollectionItems.add(new DesignCollectionItemVO(designItemId,designItem.getDesignUrl()));
|
||||
designCollectionItems.add(designCollectionItemVO);
|
||||
|
||||
List<DesignItemDetail> designItemDetails = Lists.newArrayList();
|
||||
item.getItems().forEach(detail ->{
|
||||
@@ -357,33 +413,9 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
designItemDetails.add(designItemDetail);
|
||||
});
|
||||
designItemDetailService.saveBatch(designItemDetails);
|
||||
});
|
||||
JSONObject data = responseJSONObject.getJSONObject("data");
|
||||
for (int i = 0; i < 8; i++) {
|
||||
JSONObject outfit = data.getJSONObject(i + "");
|
||||
TDesignPythonOutfit designPythonOutfit = new TDesignPythonOutfit();
|
||||
designPythonOutfit.setUserId(userInfo.getId());
|
||||
designPythonOutfit.setDesignId(designId);
|
||||
designPythonOutfit.setCollectionId(collectionId);
|
||||
designPythonOutfit.setDesignUrl(outfit.getString("synthesis_url"));
|
||||
designPythonOutfitService.save(designPythonOutfit);
|
||||
JSONArray layers = outfit.getJSONArray("layers");
|
||||
List<TDesignPythonOutfitDetail> list = new ArrayList<>();
|
||||
for (int i1 = 0; i1 < layers.size(); i1++) {
|
||||
JSONObject jsonObject = layers.getJSONObject(i1);
|
||||
TDesignPythonOutfitDetail designPythonOutfitDetail = new TDesignPythonOutfitDetail();
|
||||
designPythonOutfitDetail.setDesignId(designId);
|
||||
designPythonOutfitDetail.setDesignPythonOutfitId(designPythonOutfit.getId());
|
||||
designPythonOutfitDetail.setPosition(jsonObject.getString("position"));
|
||||
designPythonOutfitDetail.setImageUrl(jsonObject.getString("image_url"));
|
||||
designPythonOutfitDetail.setImageCategory(jsonObject.getString("image_category"));
|
||||
designPythonOutfitDetail.setMaskUrl(jsonObject.getString("mask_url"));
|
||||
designPythonOutfitDetail.setUserId(userInfo.getId());
|
||||
list.add(designPythonOutfitDetail);
|
||||
}
|
||||
designPythonOutfitDetailService.saveBatch(list);
|
||||
}
|
||||
return responseJSONObject;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private DesignCollectionVO saveDesignItemAndDetail(DesignPythonObjects pythonObjects
|
||||
@@ -406,7 +438,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
//生成designItem
|
||||
Long designItemId = designItemService.saveOne(designItem);
|
||||
//response
|
||||
designCollectionItems.add(new DesignCollectionItemVO(designItemId,designItem.getDesignUrl()));
|
||||
designCollectionItems.add(new DesignCollectionItemVO(designItemId,designItem.getDesignUrl(), null, null));
|
||||
|
||||
List<DesignItemDetail> designItemDetails = Lists.newArrayList();
|
||||
item.getItems().forEach(detail ->{
|
||||
@@ -502,7 +534,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
private List<DesignCollectionItemVO> coverDesignItemToVO( List<DesignItem> designItems){
|
||||
List<DesignCollectionItemVO> response = Lists.newArrayList();
|
||||
designItems.forEach(designItem -> {
|
||||
response.add(new DesignCollectionItemVO(designItem.getId(),designItem.getDesignUrl()));
|
||||
response.add(new DesignCollectionItemVO(designItem.getId(),designItem.getDesignUrl(), null, null));
|
||||
});
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.mapper.PythonTAllInfoMapper;
|
||||
import com.ai.da.mapper.entity.PythonTAllInfo;
|
||||
import com.ai.da.service.PythonTAllInfoService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* (PythonTAllInfo)表服务实现类
|
||||
*
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-09-08 17:03:47
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PythonTAllInfoServiceImpl extends ServiceImpl<PythonTAllInfoMapper, PythonTAllInfo> implements PythonTAllInfoService {
|
||||
@Resource
|
||||
private PythonTAllInfoMapper pythonTAllInfoMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public Long getImageIdByPath(String path) {
|
||||
if (StringUtils.isEmpty(path)) {
|
||||
throw new BusinessException("path不能为空");
|
||||
}
|
||||
QueryWrapper<PythonTAllInfo> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(PythonTAllInfo::getImagePath, path);
|
||||
qw.lambda().last("limit 1");
|
||||
List<PythonTAllInfo> pythonTAllInfos = pythonTAllInfoMapper.selectList(qw);
|
||||
if (!CollectionUtils.isEmpty(pythonTAllInfos)) {
|
||||
return pythonTAllInfos.get(0).getId();
|
||||
}
|
||||
PythonTAllInfo pythonTAllInfo = new PythonTAllInfo();
|
||||
pythonTAllInfo.setImagePath(path);
|
||||
int insert = pythonTAllInfoMapper.insert(pythonTAllInfo);
|
||||
if (insert != 1) {
|
||||
throw new BusinessException("插入失败");
|
||||
}
|
||||
return pythonTAllInfo.getId();
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,16 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.response.PageBaseResponse;
|
||||
import com.ai.da.mapper.WorkspaceMapper;
|
||||
import com.ai.da.mapper.entity.Account;
|
||||
import com.ai.da.mapper.entity.Workspace;
|
||||
import com.ai.da.model.dto.WorkspaceDTO;
|
||||
import com.ai.da.model.enums.BizJson;
|
||||
import com.ai.da.model.enums.IEnumDisplay;
|
||||
import com.ai.da.model.enums.Position;
|
||||
import com.ai.da.model.enums.Sex;
|
||||
import com.ai.da.model.vo.AuthPrincipalVo;
|
||||
import com.ai.da.model.vo.WorkspaceVO;
|
||||
import com.ai.da.service.WorkspaceService;
|
||||
@@ -29,7 +33,7 @@ import java.util.List;
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author Arcana
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-08-01
|
||||
*/
|
||||
@Service
|
||||
@@ -47,6 +51,7 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
||||
public boolean saveOrUpdate(Workspace workspace) {
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
workspace.setUserName(userInfo.getUsername());
|
||||
workspace.setIsLastIndex(0);
|
||||
if (null == workspace.getId()) {
|
||||
return workspaceMapper.insert(workspace) == 1;
|
||||
}else {
|
||||
@@ -54,13 +59,42 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
||||
}
|
||||
}
|
||||
|
||||
private final static String WORKSPACE_NAME = "默认workspace名称";
|
||||
private final static Integer SYSTEM_DESIGNER_PERCENTAGE = 30;
|
||||
|
||||
@Override
|
||||
public IPage<Workspace> getPage(WorkspaceDTO query) {
|
||||
public WorkspaceVO getPage(WorkspaceDTO query) {
|
||||
WorkspaceVO vo = new WorkspaceVO();
|
||||
String userName = UserContext.getUserHolder().getUsername();
|
||||
QueryWrapper<Workspace> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(Workspace::getUserName, userName);
|
||||
IPage<Workspace> page = workspaceMapper.selectPage(new Page<>(query.getPage(), query.getSize()), qw);
|
||||
return page;
|
||||
if (page.getTotal() == 0L) {
|
||||
// 给用户新建默认workspace
|
||||
Workspace workspace = new Workspace();
|
||||
workspace.setWorkSpaceName(WORKSPACE_NAME);
|
||||
workspace.setSex(Sex.MALE.getValue());
|
||||
workspace.setSystemDesignerPercentage(SYSTEM_DESIGNER_PERCENTAGE);
|
||||
workspace.setPosition(Position.OVERALL.getValue());
|
||||
workspace.setUserName(userName);
|
||||
workspace.setIsLastIndex(1);
|
||||
workspaceMapper.insert(workspace);
|
||||
page = workspaceMapper.selectPage(new Page<>(query.getPage(), query.getSize()), qw);
|
||||
vo.setPage(PageBaseResponse.success(page));
|
||||
vo.setId(workspace.getId());
|
||||
return vo;
|
||||
}
|
||||
vo.setPage(PageBaseResponse.success(page));
|
||||
QueryWrapper<Workspace> qwIsLastIndex = new QueryWrapper<>();
|
||||
qwIsLastIndex.lambda().eq(Workspace::getUserName, userName);
|
||||
qwIsLastIndex.lambda().eq(Workspace::getIsLastIndex, 1);
|
||||
qwIsLastIndex.last("limit 1");
|
||||
List<Workspace> workspaces = workspaceMapper.selectList(qwIsLastIndex);
|
||||
if (CollectionUtils.isEmpty(workspaces)) {
|
||||
throw new BusinessException("用户工作空间未查询到最后使用标识");
|
||||
}
|
||||
vo.setId(workspaces.get(0).getId());
|
||||
return vo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,6 +108,21 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
||||
return getEnumValues(clazz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Workspace getByIdNew(Long id) {
|
||||
String userName = UserContext.getUserHolder().getUsername();
|
||||
QueryWrapper<Workspace> qwOld = new QueryWrapper<>();
|
||||
qwOld.lambda().eq(Workspace::getUserName, userName);
|
||||
qwOld.lambda().eq(Workspace::getIsLastIndex, 1);
|
||||
Workspace oldIsLastIndex = workspaceMapper.selectOne(qwOld);
|
||||
oldIsLastIndex.setIsLastIndex(0);
|
||||
workspaceMapper.updateById(oldIsLastIndex);
|
||||
Workspace newIsLastIndex= workspaceMapper.selectById(id);
|
||||
newIsLastIndex.setIsLastIndex(1);
|
||||
workspaceMapper.updateById(newIsLastIndex);
|
||||
return newIsLastIndex;
|
||||
}
|
||||
|
||||
private List<BizJson> getEnumValues(Class clazz) {
|
||||
List<BizJson> kvs = new ArrayList<BizJson>();
|
||||
IEnumDisplay[] items = (IEnumDisplay[]) clazz.getEnumConstants();
|
||||
|
||||
Reference in New Issue
Block a user