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("消息")
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 javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.util.List;
@@ -20,4 +19,8 @@ public class LibraryDeleteDTO {
private List<Long> libraryIds;
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")
.build();
Response response = null;
String bodyString = null;
String bodyString ;
try {
log.info("generateSketchOrPrint请求入参content###{}", JSON.toJSONString(content, SerializerFeature.WriteMapNullValue));
response = client.newCall(request).execute();
bodyString = response.body().string();
} catch (IOException ioException) {
log.error("PythonService##generateSketchOrPrint异常###{}", ExceptionUtil.getThrowableList(ioException));
}
//去除限流
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!");
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);
Boolean result = JSON.parseObject(JSON.toJSONString(response)).getBoolean("successful");
// Boolean result = Boolean.TRUE;
if (result && jsonObject.get("code").equals(200)) {
return setGenerateImageList(jsonObject.getJSONObject("data"));
}
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) {

View File

@@ -1,7 +1,7 @@
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.GenerateDetail;
import com.ai.da.model.dto.GenerateLikeDTO;
import com.ai.da.model.dto.GenerateThroughImageTextDTO;
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.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
public interface GenerateService extends IService<Generate> {
GenerateCaptionVO generateCaption(Long sketchElementId);
@@ -18,4 +20,8 @@ public interface GenerateService extends IService<Generate> {
GenerateLikeVO generateLike(GenerateLikeDTO generateLikeDTO);
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);
RequestBody body = RequestBody.create(mediaType, param);
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(accessPythonIp + ":10200/aifda/api/v1.0/generate")
.method("POST", body)
@@ -152,7 +153,7 @@ public class ChatRobotServiceImpl implements ChatRobotService {
}
if (Objects.isNull(response)) {
log.error("PythonService##chatRobot异常###{}", "response is empty!");
throw new BusinessException("system error!");
throw new BusinessException("chat-bot.interface.exception");
}
if (response.isSuccessful()) {
try {
@@ -193,7 +194,9 @@ public class ChatRobotServiceImpl implements ChatRobotService {
}
ChatRobotLibraryVO chatRobotLibraryVO = new ChatRobotLibraryVO();
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<>();
qw.lambda().eq(Library::getUrl, bucketName + "/" + path);
qw.lambda().eq(Library::getAccountId, chatSendDTO.getUser_id());
@@ -220,12 +223,14 @@ public class ChatRobotServiceImpl implements ChatRobotService {
}
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) {
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) {
@@ -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 lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException;
@@ -399,6 +400,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
}
@Override
@Transactional(rollbackFor = Exception.class)
public DesignSingleVO designSingleIncludeLayers(DesignSingleIncludeLayersDTO designSingleIncludeLayersDTO) {
AuthPrincipalVo userInfo = UserContext.getUserHolder();
DesignItem designItem = selectById(designSingleIncludeLayersDTO.getDesignItemId());
@@ -486,6 +488,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
}
@Override
@Transactional(rollbackFor = Exception.class)
public ComposeLayersVO editLayersPositionAndScale(EditLayersPositionAndScaleVO positionAndScaleVO) throws IOException {
ComposeLayersVO designItemLayer = positionAndScaleVO.getLayers();
// 1、校验designItem是是否存在

View File

@@ -23,6 +23,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.minio.errors.MinioException;
import io.netty.util.internal.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.IOException;
@@ -65,6 +66,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
}
@Override
@Transactional(rollbackFor = Exception.class)
public GenerateCollectionVO generateThroughImageText(GenerateThroughImageTextDTO generateThroughImageTextDTO) {
// 1、获取用户信息
AuthPrincipalVo userHolder = UserContext.getUserHolder();
@@ -161,6 +163,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
}
@Override
@Transactional(rollbackFor = Exception.class)
public GenerateLikeVO generateLike(GenerateLikeDTO generateLikeDTO) {
// 1、判断参数是否正确
// 1.1 必须参数是否非空
@@ -207,6 +210,7 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean generateDislike(Long generateDetailId, String timeZone) {
// 1、确定generateDetail中是否有这条记录
GenerateDetail generateDetail = generateDetailMapper.selectById(generateDetailId);
@@ -259,4 +263,23 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
generateDetail.setUpdateDate(DateUtil.getByTimeZone(timeZone));
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 org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -68,6 +69,8 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
@Resource
private ClassificationService classificationService;
@Resource
private GenerateService generateService;
@Resource
private MinioUtil minioUtil;
@Value("${minio.bucketName.users}")
@@ -396,6 +399,7 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
}
@Override
@Transactional(rollbackFor = Exception.class)
public void batchDeleteLibrary(LibraryDeleteDTO deleteDTO) {
List<Library> librarys = libraryMapper.selectBatchIds(deleteDTO.getLibraryIds());
if (CollectionUtils.isEmpty(librarys)) {
@@ -417,6 +421,19 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
checkModel(Sex.MALE.getValue(), maleModelIds, deleteDTO.getDeleteModelConfirm());
}
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) {
// if (library.getUrl().startsWith(sysImage)) {
// continue;