From 8a3e6833eed79c354da5557d0a97a5ef5ac1e1a4 Mon Sep 17 00:00:00 2001 From: xupei <1779019091@qq.com> Date: Tue, 21 Nov 2023 16:47:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?TASK:=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=9F=A5=E8=AF=A2=E7=94=B7=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ai/da/model/dto/ChatSendDTO.java | 4 +++ .../java/com/ai/da/python/PythonService.java | 21 +++++++---- .../da/service/impl/ChatRobotServiceImpl.java | 35 ++++++++++++++++--- src/main/resources/messages_en.properties | 4 ++- 4 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/ai/da/model/dto/ChatSendDTO.java b/src/main/java/com/ai/da/model/dto/ChatSendDTO.java index af2c4b9f..0c59658e 100644 --- a/src/main/java/com/ai/da/model/dto/ChatSendDTO.java +++ b/src/main/java/com/ai/da/model/dto/ChatSendDTO.java @@ -31,4 +31,8 @@ public class ChatSendDTO { @ApiModelProperty("消息") private String message; + @NotBlank(message = "gender.cannot.be.empty") + @ApiModelProperty("性别") + private String gender; + } diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index d9439a58..5a1080f9 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -2229,30 +2229,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) { diff --git a/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java b/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java index 593847e3..c1ca9644 100644 --- a/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/ChatRobotServiceImpl.java @@ -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 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; + } + } diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index df62602c..5fbaa235 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -158,4 +158,6 @@ attributeRetrieval.interface.exception=We encountered an error retrieving attrib design.interface.exception=We encountered an error with the design interface. (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.) 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.) \ No newline at end of file +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=I encountered an error.(Please try again later. If this issue persists, please contact us at help@aida.com.hk.) \ No newline at end of file From b9d502db42017573a92df0b7b8fb13f869ddf0ed Mon Sep 17 00:00:00 2001 From: xupei <1779019091@qq.com> Date: Tue, 21 Nov 2023 16:57:20 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=81=8A=E5=A4=A9=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=BA=BA=E5=BC=82=E5=B8=B8=E6=8F=90=E9=86=92=E8=AF=AD=E5=8F=A5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/messages_en.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 5d0f6e2f..22f3e78f 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -160,4 +160,4 @@ processMannequins.interface.exception=We encountered an error uploading mannequi 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.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=I encountered an error.(Please try again later. If this issue persists, please contact us at help@aida.com.hk.) \ No newline at end of file +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.) \ No newline at end of file From d9a5b0f326e2e67215cfeaa476cd346167bc9727 Mon Sep 17 00:00:00 2001 From: xupei <1779019091@qq.com> Date: Wed, 22 Nov 2023 11:18:51 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BB=8Elibrary=E5=88=A0=E9=99=A4generate?= =?UTF-8?q?=E7=9A=84=E5=9B=BE=E7=89=87=E6=97=B6=E9=9C=80=E8=A6=81=E5=8F=96?= =?UTF-8?q?=E6=B6=88=E8=AF=A5=E5=9B=BE=E7=89=87=E7=9A=84like=E6=A0=87?= =?UTF-8?q?=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ai/da/model/dto/LibraryDeleteDTO.java | 5 +++- .../com/ai/da/service/GenerateService.java | 8 ++++++- .../service/impl/DesignItemServiceImpl.java | 3 +++ .../da/service/impl/GenerateServiceImpl.java | 23 ++++++++++++++++++ .../da/service/impl/LibraryServiceImpl.java | 24 ++++++++++++++----- src/main/resources/messages_en.properties | 2 +- 6 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ai/da/model/dto/LibraryDeleteDTO.java b/src/main/java/com/ai/da/model/dto/LibraryDeleteDTO.java index b8858709..04334700 100644 --- a/src/main/java/com/ai/da/model/dto/LibraryDeleteDTO.java +++ b/src/main/java/com/ai/da/model/dto/LibraryDeleteDTO.java @@ -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 libraryIds; private Integer deleteModelConfirm; + + @NotEmpty(message = "timeZone.cannot.be.empty") + @ApiModelProperty("时区") + private String timeZone; } diff --git a/src/main/java/com/ai/da/service/GenerateService.java b/src/main/java/com/ai/da/service/GenerateService.java index 382ec8c8..0d92a07f 100644 --- a/src/main/java/com/ai/da/service/GenerateService.java +++ b/src/main/java/com/ai/da/service/GenerateService.java @@ -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 { GenerateCaptionVO generateCaption(Long sketchElementId); @@ -18,4 +20,8 @@ public interface GenerateService extends IService { GenerateLikeVO generateLike(GenerateLikeDTO generateLikeDTO); Boolean generateDislike(Long generateDetailId, String timeZone); + + void updateLikeStatusBatch(List generateDetailIdList, Byte hasLike, Long libraryId, String timeZone); + + List selectBatchByLibraryId(List libraryId); } diff --git a/src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java b/src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java index 6b5f8345..4fb2e1fc 100644 --- a/src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java @@ -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 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 i } @Override + @Transactional(rollbackFor = Exception.class) public GenerateLikeVO generateLike(GenerateLikeDTO generateLikeDTO) { // 1、判断参数是否正确 // 1.1 必须参数是否非空 @@ -207,6 +210,7 @@ public class GenerateServiceImpl extends ServiceImpl 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 i generateDetail.setUpdateDate(DateUtil.getByTimeZone(timeZone)); generateDetailMapper.update(generateDetail, queryWrapper); } + + public void updateLikeStatusBatch(List generateDetailIdList, Byte hasLike, Long libraryId, String timeZone){ + QueryWrapper 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 selectBatchByLibraryId(List libraryId){ + QueryWrapper qw = new QueryWrapper<>(); + qw.in("library_id",libraryId); + + return generateDetailMapper.selectList(qw); + } } diff --git a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java index b16a9dd0..bcfe020a 100644 --- a/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LibraryServiceImpl.java @@ -2,7 +2,6 @@ package com.ai.da.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.exceptions.ExceptionUtil; -import cn.hutool.system.UserInfo; import com.ai.da.common.config.FileProperties; import com.ai.da.common.config.exception.BusinessException; import com.ai.da.common.context.UserContext; @@ -14,7 +13,6 @@ import com.ai.da.common.utils.DateUtil; import com.ai.da.common.utils.MinioUtil; import com.ai.da.mapper.LibraryMapper; import com.ai.da.mapper.SysFileMapper; -import com.ai.da.mapper.WorkspaceMapper; import com.ai.da.mapper.entity.*; import com.ai.da.model.dto.*; import com.ai.da.model.enums.MannequinType; @@ -22,10 +20,7 @@ import com.ai.da.model.enums.ModelType; import com.ai.da.model.enums.Sex; import com.ai.da.model.vo.*; import com.ai.da.python.vo.ModelPathObject; -import com.ai.da.service.ClassificationService; -import com.ai.da.service.LibraryModelPointService; -import com.ai.da.service.LibraryService; -import com.ai.da.service.WorkspaceService; +import com.ai.da.service.*; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONException; import com.alibaba.fastjson.JSONObject; @@ -39,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; @@ -73,6 +69,8 @@ public class LibraryServiceImpl extends ServiceImpl impl @Resource private ClassificationService classificationService; @Resource + private GenerateService generateService; + @Resource private MinioUtil minioUtil; @Value("${minio.bucketName.users}") @@ -339,6 +337,7 @@ public class LibraryServiceImpl extends ServiceImpl impl } @Override + @Transactional(rollbackFor = Exception.class) public void batchDeleteLibrary(LibraryDeleteDTO deleteDTO) { List librarys = libraryMapper.selectBatchIds(deleteDTO.getLibraryIds()); if (CollectionUtils.isEmpty(librarys)) { @@ -360,6 +359,19 @@ public class LibraryServiceImpl extends ServiceImpl impl checkModel(Sex.MALE.getValue(), maleModelIds, deleteDTO.getDeleteModelConfirm()); } libraryMapper.deleteBatchIds(deleteDTO.getLibraryIds()); + + // 1、确定该libraryId是否被generateDetail引用 + List 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; diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 22f3e78f..14e7225d 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -66,7 +66,7 @@ modelType.cannot.be.empty=modelType cannot be empty. modelSex.cannot.be.empty=modelSex cannot be empty. templateId.cannot.be.empty=templateId 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. email.cannot.be.empty=email cannot be empty. operationType.cannot.be.empty=operationType cannot be empty.