TASK:workspace、design模块代码;
This commit is contained in:
@@ -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