判断机器人返回图片地址是否实际存在

This commit is contained in:
2024-01-04 17:34:49 +08:00
parent 71f1a2671e
commit 9405b0d630

View File

@@ -162,6 +162,7 @@ public class ChatRobotServiceImpl implements ChatRobotService {
String responseBody = response.body().string(); String responseBody = response.body().string();
JSONObject responseObject = JSON.parseObject(responseBody); JSONObject responseObject = JSON.parseObject(responseBody);
JSONObject data = responseObject.getJSONObject("data"); JSONObject data = responseObject.getJSONObject("data");
log.info(String.valueOf(data));
if (null != data) { if (null != data) {
ChatRobot chatRobot = new ChatRobot(); ChatRobot chatRobot = new ChatRobot();
chatRobot.setResponseType(data.getString("response_type")); chatRobot.setResponseType(data.getString("response_type"));
@@ -200,20 +201,26 @@ public class ChatRobotServiceImpl implements ChatRobotService {
String prefix = getPrefix(array.getString(i),chatSendDTO.getGender()); String prefix = getPrefix(array.getString(i),chatSendDTO.getGender());
String path = prefix; String path = prefix;
// String path = prefix + array.getString(i); // String path = prefix + array.getString(i);
QueryWrapper<Library> qw = new QueryWrapper<>(); if (minioUtil.doesObjectExist(bucketName,path)){
qw.lambda().eq(Library::getUrl, bucketName + "/" + path); QueryWrapper<Library> qw = new QueryWrapper<>();
qw.lambda().eq(Library::getAccountId, chatSendDTO.getUser_id()); qw.lambda().eq(Library::getUrl, bucketName + "/" + path);
qw.lambda().last("limit 1"); qw.lambda().eq(Library::getAccountId, chatSendDTO.getUser_id());
List<Library> libraryList = libraryMapper.selectList(qw); qw.lambda().last("limit 1");
if (!CollectionUtils.isEmpty(libraryList)) { List<Library> libraryList = libraryMapper.selectList(qw);
chatRobotLibraryVO.setId(libraryList.get(0).getId()); if (!CollectionUtils.isEmpty(libraryList)) {
chatRobotLibraryVO.setId(libraryList.get(0).getId());
}
String aidaSysImage = minioUtil.getPresignedUrl(bucketName + "/" + path, 24 * 60);
chatRobotLibraryVO.setUrl(bucketName + "/" + path);
chatRobotLibraryVO.setPresignedUrl(aidaSysImage);
chatRobotLibraryVOList.add(chatRobotLibraryVO);
} }
String aidaSysImage = minioUtil.getPresignedUrl(bucketName + "/" + path, 24 * 60);
chatRobotLibraryVO.setUrl(bucketName + "/" + path);
chatRobotLibraryVO.setPresignedUrl(aidaSysImage);
chatRobotLibraryVOList.add(chatRobotLibraryVO);
} }
chatRobotVO.setChatRobotLibraryList(chatRobotLibraryVOList); if (!CollectionUtils.isEmpty(chatRobotLibraryVOList)){
chatRobotVO.setChatRobotLibraryList(chatRobotLibraryVOList);
}else {
chatRobotVO.setOutput("I'm sorry, but I can't process your current request. Please rephrase it differently.");
}
} }
} else { } else {
chatRobot.setSuccessful(0); chatRobot.setSuccessful(0);