TASK:workspace、design模块代码;
This commit is contained in:
@@ -5,6 +5,7 @@ import com.ai.da.model.dto.*;
|
||||
import com.ai.da.model.vo.DesignCollectionVO;
|
||||
import com.ai.da.model.vo.DesignItemDetailVO;
|
||||
import com.ai.da.model.vo.DesignLikeVO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -21,7 +22,7 @@ public interface DesignService extends IService<Design> {
|
||||
* @param designDTO
|
||||
* @return
|
||||
*/
|
||||
DesignCollectionVO designCollection(DesignCollectionDTO designDTO);
|
||||
JSONObject designCollection(DesignCollectionDTO designDTO);
|
||||
|
||||
/**
|
||||
* redesign
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
|
||||
import com.ai.da.mapper.entity.TDesignPythonOutfitDetail;
|
||||
import com.ai.da.model.vo.TDesignPythonOutfitDetailVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* design item详情表 服务类
|
||||
*
|
||||
* @author Arcana
|
||||
* @since 2023-09-04
|
||||
*/
|
||||
public interface ITDesignPythonOutfitDetailService extends IService<TDesignPythonOutfitDetail> {
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page
|
||||
* @param tDesignPythonOutfitDetail
|
||||
* @return
|
||||
*/
|
||||
IPage<TDesignPythonOutfitDetailVO> selectTDesignPythonOutfitDetailPage(IPage<TDesignPythonOutfitDetailVO> page, TDesignPythonOutfitDetailVO tDesignPythonOutfitDetail);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
import com.ai.da.mapper.entity.TDesignPythonOutfit;
|
||||
import com.ai.da.model.vo.TDesignPythonOutfitVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
/**
|
||||
* design item表 存对应design的8张图片 服务类
|
||||
*
|
||||
* @author Arcana
|
||||
* @since 2023-09-04
|
||||
*/
|
||||
public interface ITDesignPythonOutfitService extends IService<TDesignPythonOutfit> {
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page
|
||||
* @param tDesignPythonOutfit
|
||||
* @return
|
||||
*/
|
||||
IPage<TDesignPythonOutfitVO> selectTDesignPythonOutfitPage(IPage<TDesignPythonOutfitVO> page, TDesignPythonOutfitVO tDesignPythonOutfit);
|
||||
|
||||
}
|
||||
36
src/main/java/com/ai/da/service/WorkspaceService.java
Normal file
36
src/main/java/com/ai/da/service/WorkspaceService.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.ai.da.service;
|
||||
|
||||
|
||||
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.vo.WorkspaceVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务类
|
||||
*
|
||||
* @author Arcana
|
||||
* @since 2023-08-01
|
||||
*/
|
||||
public interface WorkspaceService extends IService<Workspace> {
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page
|
||||
* @param workspace
|
||||
* @return
|
||||
*/
|
||||
IPage<WorkspaceVO> selectWorkspacePage(IPage<WorkspaceVO> page, WorkspaceVO workspace);
|
||||
|
||||
boolean saveOrUpdate(Workspace workspace);
|
||||
|
||||
IPage<Workspace> getPage(WorkspaceDTO query);
|
||||
|
||||
List<BizJson> getEnumValues(String enumName);
|
||||
}
|
||||
@@ -12,6 +12,8 @@ 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.*;
|
||||
@@ -22,6 +24,8 @@ import com.ai.da.python.vo.DesignPythonItemPrint;
|
||||
import com.ai.da.python.vo.DesignPythonObjects;
|
||||
import com.ai.da.service.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -74,15 +78,19 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
private SysFileService sysFileService;
|
||||
@Resource
|
||||
private TCollectionElementRelationService tCollectionElementRelationService;
|
||||
@Resource
|
||||
private ITDesignPythonOutfitService designPythonOutfitService;
|
||||
@Resource
|
||||
private ITDesignPythonOutfitDetailService designPythonOutfitDetailService;
|
||||
|
||||
// @Transactional
|
||||
@Override
|
||||
public DesignCollectionVO designCollection(DesignCollectionDTO designDTO) {
|
||||
public JSONObject designCollection(DesignCollectionDTO designDTO) {
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
//校验collection element
|
||||
ValidateElementVO elementVO =collectionElementService.validateElement(designDTO);
|
||||
//design
|
||||
return designOrRedesignOperate(designDTO,userInfo,null,elementVO);
|
||||
return designOrRedesignOperateNew(designDTO,userInfo,null,elementVO);
|
||||
}
|
||||
private void calculateLibraryAndSysFile(DesignCollectionDTO designDTO,ValidateElementVO elementVO,AuthPrincipalVo userInfo){
|
||||
//查询用户 sketch library
|
||||
@@ -180,16 +188,61 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
//缓存保存的文件 方便后面处理进度问题
|
||||
setDesignProcess(userInfo.getId(),pythonObjects);
|
||||
//design
|
||||
pythonService.design(pythonObjects);
|
||||
JSONObject responseJSONObject= pythonService.designNew(pythonObjects);
|
||||
//生成library
|
||||
generateLibrary(elementVO,designDTO.getTimeZone());
|
||||
//处理关联关系,修复element覆盖得情况
|
||||
List<CollectionElement> reLationelements =collectionElementService.getByOnlyCollectionId(collectionId);
|
||||
List<Long> reLationelementIds = reLationelements.stream().map(CollectionElement::getId).collect(Collectors.toList());
|
||||
handleCollectionElementRelation(collectionId,(null == collectionIdParam) ? false :true,reLationelementIds);
|
||||
//保存python返回信息
|
||||
// return savePythonDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone(),responseJSONObject);
|
||||
//保存designItem 和detail
|
||||
return saveDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone());
|
||||
}
|
||||
|
||||
private JSONObject designOrRedesignOperateNew(DesignCollectionDTO designDTO,AuthPrincipalVo userInfo,
|
||||
Long collectionIdParam,ValidateElementVO elementVO){
|
||||
if(CollectionUtil.isNotEmpty(designDTO.getSketchBoards())){
|
||||
//编辑sketchBoard
|
||||
collectionElementService.editSketchBoardsElement(elementVO,designDTO.getSketchBoards());
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(designDTO.getPrintBoards())){
|
||||
//编辑printBoard
|
||||
collectionElementService.editPrintBoardsElement(elementVO,designDTO.getPrintBoards());
|
||||
}
|
||||
//保存collection
|
||||
Long collectionId = (null == collectionIdParam) ?
|
||||
collectionService.saveCollection(userInfo.getId(),designDTO.getTimeZone(),designDTO.getMoodTemplateId()) : collectionIdParam;
|
||||
List<Long> elementIds =getElementId(elementVO);
|
||||
//批量关联element 到 collection
|
||||
collectionElementService.relationCollection(elementIds,collectionId);
|
||||
//library转化为collection(生成)
|
||||
saveCollectionElemntsByLibrarys(elementVO,collectionId);
|
||||
//保存颜色版
|
||||
List<CollectionElementVO> colorElementList = collectionElementService.saveColorBoard(designDTO.getColorBoards(),collectionId,designDTO.getTimeZone());
|
||||
//保存design
|
||||
Long designId = saveOne(designDTO,collectionId,userInfo.getId());
|
||||
//计算library
|
||||
calculateLibraryAndSysFile(designDTO,elementVO,userInfo);
|
||||
//组装design入参
|
||||
DesignPythonObjects pythonObjects =pythonService.covertDesignParam(designDTO.getSystemScale(),
|
||||
designDTO.getSingleOverall(),designDTO.getSwitchCategory(),elementVO);
|
||||
//缓存保存的文件 方便后面处理进度问题
|
||||
setDesignProcess(userInfo.getId(),pythonObjects);
|
||||
//design
|
||||
JSONObject responseJSONObject= pythonService.designNew(pythonObjects);
|
||||
//生成library
|
||||
generateLibrary(elementVO,designDTO.getTimeZone());
|
||||
//处理关联关系,修复element覆盖得情况
|
||||
List<CollectionElement> reLationelements =collectionElementService.getByOnlyCollectionId(collectionId);
|
||||
List<Long> reLationelementIds = reLationelements.stream().map(CollectionElement::getId).collect(Collectors.toList());
|
||||
handleCollectionElementRelation(collectionId,(null == collectionIdParam) ? false :true,reLationelementIds);
|
||||
//保存python返回信息
|
||||
return savePythonDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone(),responseJSONObject);
|
||||
//保存designItem 和detail
|
||||
// return saveDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone());
|
||||
}
|
||||
private void handleCollectionElementRelation(Long collectionId ,Boolean isEdit,List<Long> elementIds ){
|
||||
if (CollectionUtils.isEmpty(elementIds) || collectionId == null){
|
||||
return;
|
||||
@@ -260,6 +313,79 @@ 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
|
||||
,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 ->{
|
||||
DesignItem designItem = new DesignItem();
|
||||
designItem.setAccountId(userInfo.getId());
|
||||
designItem.setCollectionId(collectionId);
|
||||
designItem.setDesignId(designId);
|
||||
designItem.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
//生成的八张图片
|
||||
designItem.setDesignUrl(item.getBasic().getSave_name());
|
||||
designItem.setHasLike((byte)0);
|
||||
//生成designItem
|
||||
Long designItemId = designItemService.saveOne(designItem);
|
||||
//response
|
||||
designCollectionItems.add(new DesignCollectionItemVO(designItemId,designItem.getDesignUrl()));
|
||||
|
||||
List<DesignItemDetail> designItemDetails = Lists.newArrayList();
|
||||
item.getItems().forEach(detail ->{
|
||||
if(null == detail){
|
||||
return;
|
||||
}
|
||||
DesignItemDetail designItemDetail = CopyUtil.copyObject(detail,DesignItemDetail.class);
|
||||
designItemDetail.setAccountId(userInfo.getId());
|
||||
designItemDetail.setDesignId(designId);
|
||||
designItemDetail.setDesignItemId(designItemId);
|
||||
designItemDetail.setCollectionElementId(detail.getElementId());
|
||||
designItemDetail.setCreateDate(DateUtil.getByTimeZone(timeZone));
|
||||
if(SysFileLevel2TypeEnum.BODY.getRealName().equals(detail.getType())){
|
||||
designItemDetail.setPath(detail.getBody_path());
|
||||
//BODY不关联businessId
|
||||
designItemDetail.setBusinessId(0L);
|
||||
}
|
||||
designItemDetail.setIconPath(detail.getIcon());
|
||||
DesignPythonItemPrint printObject = detail.getPrint();
|
||||
designItemDetail.setPrintPath(Objects.isNull(printObject)? "" :printObject.getPath());
|
||||
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;
|
||||
}
|
||||
|
||||
private DesignCollectionVO saveDesignItemAndDetail(DesignPythonObjects pythonObjects
|
||||
,Long designId,Long collectionId,AuthPrincipalVo userInfo,String timeZone){
|
||||
DesignCollectionVO response = new DesignCollectionVO();
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.mapper.TDesignPythonOutfitDetailMapper;
|
||||
import com.ai.da.mapper.entity.TDesignPythonOutfitDetail;
|
||||
import com.ai.da.model.vo.TDesignPythonOutfitDetailVO;
|
||||
import com.ai.da.service.ITDesignPythonOutfitDetailService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
/**
|
||||
* design item详情表 服务实现类
|
||||
*
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-09-04
|
||||
*/
|
||||
@Service
|
||||
public class TDesignPythonOutfitDetailServiceImpl extends ServiceImpl<TDesignPythonOutfitDetailMapper, TDesignPythonOutfitDetail> implements ITDesignPythonOutfitDetailService {
|
||||
|
||||
@Override
|
||||
public IPage<TDesignPythonOutfitDetailVO> selectTDesignPythonOutfitDetailPage(IPage<TDesignPythonOutfitDetailVO> page, TDesignPythonOutfitDetailVO tDesignPythonOutfitDetail) {
|
||||
return page.setRecords(baseMapper.selectTDesignPythonOutfitDetailPage(page, tDesignPythonOutfitDetail));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.mapper.TDesignPythonOutfitMapper;
|
||||
import com.ai.da.mapper.entity.TDesignPythonOutfit;
|
||||
import com.ai.da.model.vo.TDesignPythonOutfitVO;
|
||||
import com.ai.da.service.ITDesignPythonOutfitService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
|
||||
/**
|
||||
* design item表 存对应design的8张图片 服务实现类
|
||||
*
|
||||
* @author SHAHAIBO
|
||||
* @since 2023-09-04
|
||||
*/
|
||||
@Service
|
||||
public class TDesignPythonOutfitServiceImpl extends ServiceImpl<TDesignPythonOutfitMapper, TDesignPythonOutfit> implements ITDesignPythonOutfitService {
|
||||
|
||||
@Override
|
||||
public IPage<TDesignPythonOutfitVO> selectTDesignPythonOutfitPage(IPage<TDesignPythonOutfitVO> page, TDesignPythonOutfitVO tDesignPythonOutfit) {
|
||||
return page.setRecords(baseMapper.selectTDesignPythonOutfitPage(page, tDesignPythonOutfit));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.ai.da.service.impl;
|
||||
|
||||
import com.ai.da.common.context.UserContext;
|
||||
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.vo.AuthPrincipalVo;
|
||||
import com.ai.da.model.vo.WorkspaceVO;
|
||||
import com.ai.da.service.WorkspaceService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 服务实现类
|
||||
*
|
||||
* @author Arcana
|
||||
* @since 2023-08-01
|
||||
*/
|
||||
@Service
|
||||
public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace> implements WorkspaceService {
|
||||
|
||||
@Resource
|
||||
private WorkspaceMapper workspaceMapper;
|
||||
|
||||
@Override
|
||||
public IPage<WorkspaceVO> selectWorkspacePage(IPage<WorkspaceVO> page, WorkspaceVO workspace) {
|
||||
return page.setRecords(baseMapper.selectWorkspacePage(page, workspace));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveOrUpdate(Workspace workspace) {
|
||||
AuthPrincipalVo userInfo = UserContext.getUserHolder();
|
||||
workspace.setUserName(userInfo.getUsername());
|
||||
if (null == workspace.getId()) {
|
||||
return workspaceMapper.insert(workspace) == 1;
|
||||
}else {
|
||||
return workspaceMapper.updateById(workspace) == 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<Workspace> getPage(WorkspaceDTO query) {
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BizJson> getEnumValues(String className) {
|
||||
Class clazz;
|
||||
try {
|
||||
clazz = Class.forName(IEnumDisplay.class.getPackage().getName() + "." + className);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(className + "-枚举类型未找到");
|
||||
}
|
||||
return getEnumValues(clazz);
|
||||
}
|
||||
|
||||
private List<BizJson> getEnumValues(Class clazz) {
|
||||
List<BizJson> kvs = new ArrayList<BizJson>();
|
||||
IEnumDisplay[] items = (IEnumDisplay[]) clazz.getEnumConstants();
|
||||
for (IEnumDisplay item : items) {
|
||||
kvs.add(new BizJson(item.getValue(), item.name(), null));
|
||||
}
|
||||
return kvs;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user