Merge remote-tracking branch 'origin/develop' into develop

This commit is contained in:
shahaibo
2023-11-22 15:19:12 +08:00
9 changed files with 106 additions and 16 deletions

View File

@@ -31,4 +31,8 @@ public class ChatSendDTO {
@ApiModelProperty("消息") @ApiModelProperty("消息")
private String message; private String message;
@NotBlank(message = "gender.cannot.be.empty")
@ApiModelProperty("性别")
private String gender;
} }

View File

@@ -5,7 +5,6 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size; import javax.validation.constraints.Size;
import java.util.List; import java.util.List;
@@ -20,4 +19,8 @@ public class LibraryDeleteDTO {
private List<Long> libraryIds; private List<Long> libraryIds;
private Integer deleteModelConfirm; private Integer deleteModelConfirm;
@NotEmpty(message = "timeZone.cannot.be.empty")
@ApiModelProperty("时区")
private String timeZone;
} }

View File

@@ -2255,30 +2255,37 @@ public class PythonService {
.addHeader("Content-Type", "application/json") .addHeader("Content-Type", "application/json")
.build(); .build();
Response response = null; Response response = null;
String bodyString = null; String bodyString ;
try { try {
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content, SerializerFeature.WriteMapNullValue)); log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content, SerializerFeature.WriteMapNullValue));
response = client.newCall(request).execute(); response = client.newCall(request).execute();
bodyString = response.body().string();
} catch (IOException ioException) { } catch (IOException ioException) {
log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException)); log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));
} }
//去除限流 //去除限流
AccessLimitUtils.validateOut("generateSketchOrPrint"); AccessLimitUtils.validateOut("generateSketchOrPrint");
// 生成失败
if (Objects.isNull(response) || StringUtil.isNullOrEmpty(bodyString)) { // 判断是否生成失败
if (Objects.isNull(response) || Objects.isNull(response.body())) {
log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!"); log.error("PythonService##generateSketchOrPrint异常###{}", "response or body is empty!");
throw new BusinessException("generate exception!"); throw new BusinessException("generate.interface.error");
} else {
try {
bodyString = response.body().string();
} catch (IOException e) {
throw new BusinessException("generate.interface.error");
}
} }
JSONObject jsonObject = JSON.parseObject(bodyString); JSONObject jsonObject = JSON.parseObject(bodyString);
Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful"); Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful");
// Boolean result = Boolean.TRUE;
if (result && jsonObject.get("code").equals(200)) { if (result && jsonObject.get("code").equals(200)) {
return setGenerateImageList(jsonObject.getJSONObject("data")); return setGenerateImageList(jsonObject.getJSONObject("data"));
} }
log.info("generateSketchOrPrintPrint失败###{}", jsonObject); log.info("generateSketchOrPrintPrint失败###{}", jsonObject);
log.info("Generate Exception! Code : " + jsonObject.get("code"));
//生成失败 //生成失败
throw new BusinessException("Generate Exception! Code : " + jsonObject.get("code")); throw new BusinessException("generate.interface.error");
} }
public Response sendPostToModel(String content, String portAndRoute, String functionName) { public Response sendPostToModel(String content, String portAndRoute, String functionName) {

View File

@@ -1,7 +1,7 @@
package com.ai.da.service; package com.ai.da.service;
import com.ai.da.mapper.entity.Design;
import com.ai.da.mapper.entity.Generate; import com.ai.da.mapper.entity.Generate;
import com.ai.da.mapper.entity.GenerateDetail;
import com.ai.da.model.dto.GenerateLikeDTO; import com.ai.da.model.dto.GenerateLikeDTO;
import com.ai.da.model.dto.GenerateThroughImageTextDTO; import com.ai.da.model.dto.GenerateThroughImageTextDTO;
import com.ai.da.model.vo.GenerateCaptionVO; import com.ai.da.model.vo.GenerateCaptionVO;
@@ -9,6 +9,8 @@ import com.ai.da.model.vo.GenerateCollectionVO;
import com.ai.da.model.vo.GenerateLikeVO; import com.ai.da.model.vo.GenerateLikeVO;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
public interface GenerateService extends IService<Generate> { public interface GenerateService extends IService<Generate> {
GenerateCaptionVO generateCaption(Long sketchElementId); GenerateCaptionVO generateCaption(Long sketchElementId);
@@ -18,4 +20,8 @@ public interface GenerateService extends IService<Generate> {
GenerateLikeVO generateLike(GenerateLikeDTO generateLikeDTO); GenerateLikeVO generateLike(GenerateLikeDTO generateLikeDTO);
Boolean generateDislike(Long generateDetailId, String timeZone); Boolean generateDislike(Long generateDetailId, String timeZone);
void updateLikeStatusBatch(List<Long> generateDetailIdList, Byte hasLike, Long libraryId, String timeZone);
List<GenerateDetail> selectBatchByLibraryId(List<Long> libraryId);
} }

View File

@@ -139,6 +139,7 @@ public class ChatRobotServiceImpl implements ChatRobotService {
log.info("chatRobot请求python 参数:####{}", param); log.info("chatRobot请求python 参数:####{}", param);
RequestBody body = RequestBody.create(mediaType, param); RequestBody body = RequestBody.create(mediaType, param);
Request request = new Request.Builder() Request request = new Request.Builder()
// .url("http://127.0.0.1:5000/api/chat_stream_test")
.url("http://18.167.251.121:9991/api/chat_stream_test") .url("http://18.167.251.121:9991/api/chat_stream_test")
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate") // .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
.method("POST", body) .method("POST", body)
@@ -152,7 +153,7 @@ public class ChatRobotServiceImpl implements ChatRobotService {
} }
if (Objects.isNull(response)) { if (Objects.isNull(response)) {
log.error("PythonService##chatRobot异常###{}", "response is empty!"); log.error("PythonService##chatRobot异常###{}", "response is empty!");
throw new BusinessException("system error!"); throw new BusinessException("chat-bot.interface.exception");
} }
if (response.isSuccessful()) { if (response.isSuccessful()) {
try { try {
@@ -193,7 +194,9 @@ public class ChatRobotServiceImpl implements ChatRobotService {
} }
ChatRobotLibraryVO chatRobotLibraryVO = new ChatRobotLibraryVO(); ChatRobotLibraryVO chatRobotLibraryVO = new ChatRobotLibraryVO();
String bucketName = sysImage; String bucketName = sysImage;
String path = "images/female/" + array.getString(i); String prefix = getPrefix(array.getString(i));
String path = prefix;
// String path = prefix + array.getString(i);
QueryWrapper<Library> qw = new QueryWrapper<>(); QueryWrapper<Library> qw = new QueryWrapper<>();
qw.lambda().eq(Library::getUrl, bucketName + "/" + path); qw.lambda().eq(Library::getUrl, bucketName + "/" + path);
qw.lambda().eq(Library::getAccountId, chatSendDTO.getUser_id()); qw.lambda().eq(Library::getAccountId, chatSendDTO.getUser_id());
@@ -220,12 +223,14 @@ public class ChatRobotServiceImpl implements ChatRobotService {
} }
return chatRobotVO; return chatRobotVO;
} }
throw new BusinessException("ChatRobot response data is null!"); log.error("ChatRobot response data is null!");
throw new BusinessException("chat-bot.interface.exception");
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new BusinessException("chat-bot.interface.exception");
} }
} }
throw new BusinessException("ChatRobot exception!"); log.error("ChatRobot exception!");
throw new BusinessException("chat-bot.interface.exception");
} }
private void checkBalance(BigDecimal totalCost, Long userId) { private void checkBalance(BigDecimal totalCost, Long userId) {
@@ -309,4 +314,24 @@ public class ChatRobotServiceImpl implements ChatRobotService {
} }
} }
private String getPrefix(String minioPath){
String substring = minioPath.substring(minioPath.lastIndexOf("/") + 1, minioPath.lastIndexOf("_"));
String folder = minioPath.substring(0,minioPath.lastIndexOf("/"));
if ("mens_test".equals(substring)){
switch (folder){
case "bottom":
minioPath = minioPath.replace("bottom","bottoms");
break;
case "top":
minioPath = minioPath.replace("top","tops");
break;
case "outer":
minioPath = minioPath.replace("outer","outwear");
break;
}
return "images/male/" + minioPath;
}
return "images/female/" + minioPath;
}
} }

View File

@@ -25,6 +25,7 @@ import com.google.common.collect.Lists;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
@@ -399,6 +400,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public DesignSingleVO designSingleIncludeLayers(DesignSingleIncludeLayersDTO designSingleIncludeLayersDTO) { public DesignSingleVO designSingleIncludeLayers(DesignSingleIncludeLayersDTO designSingleIncludeLayersDTO) {
AuthPrincipalVo userInfo = UserContext.getUserHolder(); AuthPrincipalVo userInfo = UserContext.getUserHolder();
DesignItem designItem = selectById(designSingleIncludeLayersDTO.getDesignItemId()); DesignItem designItem = selectById(designSingleIncludeLayersDTO.getDesignItemId());
@@ -486,6 +488,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public ComposeLayersVO editLayersPositionAndScale(EditLayersPositionAndScaleVO positionAndScaleVO) throws IOException { public ComposeLayersVO editLayersPositionAndScale(EditLayersPositionAndScaleVO positionAndScaleVO) throws IOException {
ComposeLayersVO designItemLayer = positionAndScaleVO.getLayers(); ComposeLayersVO designItemLayer = positionAndScaleVO.getLayers();
// 1、校验designItem是是否存在 // 1、校验designItem是是否存在

View File

@@ -23,6 +23,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.minio.errors.MinioException; import io.minio.errors.MinioException;
import io.netty.util.internal.StringUtil; import io.netty.util.internal.StringUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
@@ -65,6 +66,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public GenerateCollectionVO generateThroughImageText(GenerateThroughImageTextDTO generateThroughImageTextDTO) { public GenerateCollectionVO generateThroughImageText(GenerateThroughImageTextDTO generateThroughImageTextDTO) {
// 1、获取用户信息 // 1、获取用户信息
AuthPrincipalVo userHolder = UserContext.getUserHolder(); AuthPrincipalVo userHolder = UserContext.getUserHolder();
@@ -161,6 +163,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public GenerateLikeVO generateLike(GenerateLikeDTO generateLikeDTO) { public GenerateLikeVO generateLike(GenerateLikeDTO generateLikeDTO) {
// 1、判断参数是否正确 // 1、判断参数是否正确
// 1.1 必须参数是否非空 // 1.1 必须参数是否非空
@@ -207,6 +210,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public Boolean generateDislike(Long generateDetailId, String timeZone) { public Boolean generateDislike(Long generateDetailId, String timeZone) {
// 1、确定generateDetail中是否有这条记录 // 1、确定generateDetail中是否有这条记录
GenerateDetail generateDetail = generateDetailMapper.selectById(generateDetailId); GenerateDetail generateDetail = generateDetailMapper.selectById(generateDetailId);
@@ -259,4 +263,23 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
generateDetail.setUpdateDate(DateUtil.getByTimeZone(timeZone)); generateDetail.setUpdateDate(DateUtil.getByTimeZone(timeZone));
generateDetailMapper.update(generateDetail, queryWrapper); generateDetailMapper.update(generateDetail, queryWrapper);
} }
public void updateLikeStatusBatch(List<Long> generateDetailIdList, Byte hasLike, Long libraryId, String timeZone){
QueryWrapper<GenerateDetail> queryWrapper = new QueryWrapper<>();
queryWrapper.in("id", generateDetailIdList);
GenerateDetail generateDetail = new GenerateDetail();
generateDetail.setIsLike(hasLike);
generateDetail.setLibraryId(libraryId);
generateDetail.setUpdateDate(DateUtil.getByTimeZone(timeZone));
generateDetailMapper.update(generateDetail, queryWrapper);
}
public List<GenerateDetail> selectBatchByLibraryId(List<Long> libraryId){
QueryWrapper<GenerateDetail> qw = new QueryWrapper<>();
qw.in("library_id",libraryId);
return generateDetailMapper.selectList(qw);
}
} }

View File

@@ -34,6 +34,7 @@ import lombok.extern.slf4j.Slf4j;
import okhttp3.*; import okhttp3.*;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
@@ -68,6 +69,8 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
@Resource @Resource
private ClassificationService classificationService; private ClassificationService classificationService;
@Resource @Resource
private GenerateService generateService;
@Resource
private MinioUtil minioUtil; private MinioUtil minioUtil;
@Value("${minio.bucketName.users}") @Value("${minio.bucketName.users}")
@@ -396,6 +399,7 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public void batchDeleteLibrary(LibraryDeleteDTO deleteDTO) { public void batchDeleteLibrary(LibraryDeleteDTO deleteDTO) {
List<Library> librarys = libraryMapper.selectBatchIds(deleteDTO.getLibraryIds()); List<Library> librarys = libraryMapper.selectBatchIds(deleteDTO.getLibraryIds());
if (CollectionUtils.isEmpty(librarys)) { if (CollectionUtils.isEmpty(librarys)) {
@@ -417,6 +421,19 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
checkModel(Sex.MALE.getValue(), maleModelIds, deleteDTO.getDeleteModelConfirm()); checkModel(Sex.MALE.getValue(), maleModelIds, deleteDTO.getDeleteModelConfirm());
} }
libraryMapper.deleteBatchIds(deleteDTO.getLibraryIds()); libraryMapper.deleteBatchIds(deleteDTO.getLibraryIds());
// 1、确定该libraryId是否被generateDetail引用
List<GenerateDetail> generateDetails = generateService.selectBatchByLibraryId(deleteDTO.getLibraryIds());
// 2、有则更新generateDetail表的is_like字段和library_id字段
if (!generateDetails.isEmpty()){
generateService.updateLikeStatusBatch(
generateDetails.stream().map(GenerateDetail::getId).collect(Collectors.toList()),
(byte)0,
0L,
deleteDTO.getTimeZone()
);
}
// for (Library library : librarys) { // for (Library library : librarys) {
// if (library.getUrl().startsWith(sysImage)) { // if (library.getUrl().startsWith(sysImage)) {
// continue; // continue;

View File

@@ -66,7 +66,7 @@ modelType.cannot.be.empty=modelType cannot be empty.
modelSex.cannot.be.empty=modelSex cannot be empty. modelSex.cannot.be.empty=modelSex cannot be empty.
templateId.cannot.be.empty=templateId cannot be empty. templateId.cannot.be.empty=templateId cannot be empty.
processId.cannot.be.empty=processId cannot be empty. processId.cannot.be.empty=processId cannot be empty.
timeZone.cannot.be.empty=timeZone cannot be empty. timeZone.cannot.be.empty=TimeZone cannot be empty.
userId.cannot.be.empty=userId cannot be empty. userId.cannot.be.empty=userId cannot be empty.
email.cannot.be.empty=email cannot be empty. email.cannot.be.empty=email cannot be empty.
operationType.cannot.be.empty=operationType cannot be empty. operationType.cannot.be.empty=operationType cannot be empty.
@@ -159,4 +159,6 @@ design.interface.exception=We encountered an error with the design interface. (P
processMannequins.interface.exception=We encountered an error uploading mannequins. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.) processMannequins.interface.exception=We encountered an error uploading mannequins. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.)
processSketchBoards.interface.exception=We encountered an error uploading sketchBoard. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.) processSketchBoards.interface.exception=We encountered an error uploading sketchBoard. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.)
designProcess.interface.exception=There's been an issue loading the progress bar. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.) designProcess.interface.exception=There's been an issue loading the progress bar. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.)
generate.interface.exception=We are currently experiencing a high volume of generating requests. (Please try again later. If the problem continues, reach out to us at help@aida.com.hk for support.) generate.interface.exception=We are currently experiencing a high volume of generating requests. (Please try again later. If the problem continues, reach out to us at help@aida.com.hk for support.)
generate.interface.error=We encountered an error with the generate interface. (Please try again later. If this issue persists, please contact us at help@aida.com.hk.)
chat-bot.interface.exception=We encountered an error with the chat robot interface.(Please try again later. If this issue persists, please contact us at help@aida.com.hk.)