TASK:模块化;

This commit is contained in:
shahaibo
2025-03-30 15:56:03 +08:00
parent 2cfd342ef8
commit 48c7182f98
18 changed files with 538 additions and 12 deletions

View File

@@ -7,8 +7,10 @@ import com.ai.da.model.vo.*;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import io.minio.errors.MinioException;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@@ -86,9 +88,19 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
Boolean brandDNASaveOrUpdate(BrandDNADTO brandDNADTO);
String brandDNAUpload(MultipartFile file, Long brandId) throws IOException;
Library brandDNAUpload(MultipartFile file, Long brandId) throws IOException;
PageBaseResponse<BrandDNAVO> brandDNAPage(BrandDNAQueryDTO brandDNAQueryDTO);
BrandDNAGenerateVO brandDNAGenerate(String prompt);
IPage<ThreeDLayoutVO> getThreeDLayoutPage(ThreeDLayoutQueryDTO threeDLayoutQueryDTO);
ThreeDVO getLayoutDetail(Long threeDSimpleId);
ThreeDSizeVO getThreeDSize(Long threeDSimpleId);
void getThreeDGlb(Long threeDSimpleId, HttpServletResponse response) throws MinioException, IOException;
void downloadZip(Long threeDSimpleId, String sizeType, String size, HttpServletResponse response) throws MinioException, IOException;
}

View File

@@ -32,6 +32,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.base.Function;
import com.google.gson.Gson;
import io.minio.errors.MinioException;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
@@ -42,6 +43,7 @@ import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.time.LocalDateTime;
import java.time.ZoneId;
@@ -115,6 +117,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
private BrandDNAMapper brandDNAMapper;
@Resource
private BrandRelLibraryMapper brandRelLibraryMapper;
@Resource
private ThreeDLayoutMapper threeDLayoutMapper;
@Resource
private ThreeDPatternLayoutMapper threeDPatternLayoutMapper;
@Resource
private ThreeDDetailMapper threeDDetailMapper;
@Resource
private ThreeDSimpleMapper threeDSimpleMapper;
@Override
public void deleteUserGroup(Long userGroupId) {
@@ -1963,7 +1973,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}
@Override
public String brandDNAUpload(MultipartFile file, Long brandId) throws IOException {
public Library brandDNAUpload(MultipartFile file, Long brandId) throws IOException {
AuthPrincipalVo userHolder = UserContext.getUserHolder();
String path = userHolder.getId().toString() + "/brandLogo";
String upload = minioUtil.upload("aida-users", path, file);
@@ -1974,13 +1984,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
library.setUrl(upload);
library.setMd5(MD5Utils.encryptFile(file.getInputStream()));
library.setCreateDate(new Date());
libraryMapper.insert(library);
BrandRelLibrary brandRelLibrary = new BrandRelLibrary();
brandRelLibrary.setLibraryId(library.getId());
brandRelLibrary.setBrandId(brandId);
brandRelLibraryMapper.insert(brandRelLibrary);
return upload;
return library;
}
@Override
@@ -2011,4 +2022,123 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
vo.setMinioUrl(minioUtil.getPreSignedUrl(vo.getBrandLogo(), 24 * 60));
return vo;
}
@Override
public IPage<ThreeDLayoutVO> getThreeDLayoutPage(ThreeDLayoutQueryDTO query) {
// AuthPrincipalVo authPrincipalVo = UserContext.getUserHolder();
// 分页数据
QueryWrapper<ThreeDLayout> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(ThreeDLayout::getType, "front");
queryWrapper.lambda().eq(ThreeDLayout::getGender, "female");
IPage<ThreeDLayout> page = threeDLayoutMapper.selectPage(
new Page<>(query.getPage(), query.getSize()), queryWrapper);
if (CollectionUtils.isEmpty(page.getRecords())) {
return new Page<>();
}
IPage<ThreeDLayoutVO> convert = page.convert((Function<ThreeDLayout, ThreeDLayoutVO>) threeDLayout -> {
if (threeDLayout != null) {
ThreeDLayoutVO threeDLayoutVO = CopyUtil.copyObject(threeDLayout, ThreeDLayoutVO.class);
threeDLayoutVO.setUrl(minioUtil.getPreSignedUrl(threeDLayoutVO.getUrl(), 24 * 60));
return threeDLayoutVO;
}
return null;
});
return convert;
}
@Override
public ThreeDVO getLayoutDetail(Long threeDSimpleId) {
ThreeDVO result = new ThreeDVO();
QueryWrapper<ThreeDLayout> qw = new QueryWrapper<>();
qw.lambda().eq(ThreeDLayout::getThreeDSimpleId, threeDSimpleId);
List<ThreeDLayout> threeDLayoutList = threeDLayoutMapper.selectList(qw);
result.setThreeDLayoutList(threeDLayoutList);
QueryWrapper<ThreeDPatternLayout> threeDPatternLayoutQueryWrapper = new QueryWrapper<>();
threeDPatternLayoutQueryWrapper.lambda().eq(ThreeDPatternLayout::getThreeDSimpleId, threeDSimpleId);
List<ThreeDPatternLayout> threeDPatternLayoutList = threeDPatternLayoutMapper.selectList(threeDPatternLayoutQueryWrapper);
if (CollectionUtil.isNotEmpty(threeDPatternLayoutList)) {
result.setThreeDPatternLayout(threeDPatternLayoutList.get(0));
}
return result;
}
@Override
public ThreeDSizeVO getThreeDSize(Long threeDSimpleId) {
ThreeDSizeVO result = new ThreeDSizeVO();
QueryWrapper<ThreeDDetail> threeDDetailQueryWrapper = new QueryWrapper<>();
threeDDetailQueryWrapper.lambda().eq(ThreeDDetail::getThreeDSimpleId, threeDSimpleId);
List<ThreeDDetail> threeDDetailList = threeDDetailMapper.selectList(threeDDetailQueryWrapper);
if (CollectionUtil.isNotEmpty(threeDDetailList)) {
// 以 sizeType 分组
Map<String, List<String>> sizeTypeMap = new HashMap<>();
for (ThreeDDetail detail : threeDDetailList) {
sizeTypeMap
.computeIfAbsent(detail.getSizeType(), k -> new ArrayList<>())
.add(detail.getSize());
}
result.setSizeTypeMap(sizeTypeMap);
}
return result;
}
@Override
public void getThreeDGlb(Long threeDSimpleId, HttpServletResponse response) throws MinioException, IOException {
ThreeDSimple threeDSimple = threeDSimpleMapper.selectById(threeDSimpleId);
if (ObjectUtils.isAllFieldNull(threeDSimple)) {
throw new BusinessException("3D file is not exist");
}
InputStream inputStream = minioUtil.download(threeDSimple.getUrl());
// 设置响应头
response.setContentType("model/gltf-binary"); // 确保 MIME 类型正确
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment; filename=\"" + threeDSimple.getName() + "\"");
// 将文件内容写入响应输出流
try {
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
response.getOutputStream().write(buffer, 0, bytesRead);
}
inputStream.close();
response.getOutputStream().flush();
} catch (Exception e) {
throw new RuntimeException("Failed to get 3D .glb file", e);
}
}
@Override
public void downloadZip(Long threeDSimpleId, String sizeType, String size, HttpServletResponse response) throws MinioException, IOException {
QueryWrapper<ThreeDDetail> qw = new QueryWrapper<>();
qw.lambda().eq(ThreeDDetail::getThreeDSimpleId, threeDSimpleId);
qw.lambda().eq(ThreeDDetail::getSizeType, sizeType);
qw.lambda().eq(ThreeDDetail::getSize, size);
ThreeDDetail threeDDetail = threeDDetailMapper.selectOne(qw);
if (ObjectUtils.isAllFieldNull(threeDDetail)) {
throw new BusinessException("3D file is not exist");
}
InputStream inputStream = minioUtil.download(threeDDetail.getUrl());
// 设置响应头
response.setContentType("application/zip"); // 确保 ZIP 格式
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
response.setHeader("Content-Disposition", "attachment; filename=\"" + threeDDetail.getName() + "\"");
// 将文件内容写入响应输出流
try {
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
response.getOutputStream().write(buffer, 0, bytesRead);
}
inputStream.close();
response.getOutputStream().flush();
} catch (Exception e) {
throw new RuntimeException("Failed to download ZIP file", e);
}
}
}