Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BIGTOP-4235: Fix update in SQLBuilder #79

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ public static <Entity> String update(
}
Field field = ReflectionUtils.findField(entityClass, entry.getKey());
if (field != null) {
if (checkBaseField(field)) {
continue;
}
Column column = field.getAnnotation(Column.class);
if (column != null && !column.nullable() && value == null) {
continue;
Expand Down Expand Up @@ -248,6 +251,9 @@ public static <Entity> String update(
}
Field field = ReflectionUtils.findField(entityClass, entry.getKey());
if (field != null) {
if (checkBaseField(field)) {
continue;
}
Column column = field.getAnnotation(Column.class);
if (column != null && !column.nullable() && value == null) {
continue;
Expand Down Expand Up @@ -291,7 +297,10 @@ public static <Entity> String updateList(
primaryKey = keywordsFormat(entry.getValue(), DBType.MYSQL);
continue;
}

Field field = ReflectionUtils.findField(entityClass, entry.getKey());
if (field == null || checkBaseField(field)) {
continue;
}
StringBuilder caseClause = new StringBuilder();
caseClause
.append(keywordsFormat(entry.getValue(), DBType.MYSQL))
Expand All @@ -301,10 +310,6 @@ public static <Entity> String updateList(
if (ps == null || ps.getReadMethod() == null) {
continue;
}
Field field = ReflectionUtils.findField(entityClass, entry.getKey());
if (field == null || checkBaseField(field)) {
continue;
}
Object value = ReflectionUtils.invokeMethod(ps.getReadMethod(), entity);
PropertyDescriptor pkPs =
BeanUtils.getPropertyDescriptor(entityClass, tableMetaData.getPkProperty());
Expand Down Expand Up @@ -335,8 +340,12 @@ public static <Entity> String updateList(
.append("' THEN NULL ");
}
}
if (caseClause.toString().endsWith("CASE ")) {
caseClause.append("WHEN TRUE THEN ");
} else {
caseClause.append("ELSE ");
}
caseClause
.append("ELSE ")
.append(keywordsFormat(entry.getValue(), DBType.MYSQL))
.append(" ");
caseClause.append("END");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class ChatbotServiceImpl implements ChatbotService {

private AIAssistantFactory aiAssistantFactory;

public AIAssistantFactory getAiAssistantFactory() {
public AIAssistantFactory getAIAssistantFactory() {
if (aiAssistantFactory == null) {
aiAssistantFactory =
new GeneralAssistantFactory(new PersistentChatMemoryStore(chatThreadDao, chatMessageDao));
Expand All @@ -105,15 +105,15 @@ private PlatformType getPlatformType(String platformName) {

private AIAssistant buildAIAssistant(
PlatformAuthorizedDTO platformAuthorizedDTO, Long threadId, Map<String, String> configs) {
return getAiAssistantFactory()
return getAIAssistantFactory()
.create(
getPlatformType(platformAuthorizedDTO.getPlatformName()),
getAIAssistantConfig(platformAuthorizedDTO, configs),
threadId);
}

private Boolean testAuthorization(PlatformAuthorizedDTO platformAuthorizedDTO) {
AIAssistant aiAssistant = getAiAssistantFactory()
AIAssistant aiAssistant = getAIAssistantFactory()
.create(
getPlatformType(platformAuthorizedDTO.getPlatformName()),
getAIAssistantConfig(platformAuthorizedDTO, null));
Expand Down Expand Up @@ -215,10 +215,16 @@ public boolean deleteAuthorizedPlatform(Long platformId) {
authorizedPlatformPO.setIsDeleted(true);
platformAuthorizedDao.partialUpdateById(authorizedPlatformPO);
List<ChatThreadPO> chatThreadPOS = chatThreadDao.findAllByPlatformId(authorizedPlatformPO.getId());
if (chatThreadPOS.isEmpty()) {
return true;
}
chatThreadPOS.forEach(chatThread -> chatThread.setIsDeleted(true));
chatThreadDao.partialUpdateByIds(chatThreadPOS);
for (ChatThreadPO chatThreadPO : chatThreadPOS) {
List<ChatMessagePO> chatMessagePOS = chatMessageDao.findAllByThreadId(chatThreadPO.getId());
if (chatMessagePOS.isEmpty()) {
return true;
}
chatMessagePOS.forEach(chatMessage -> chatMessage.setIsDeleted(true));
chatMessageDao.partialUpdateByIds(chatMessagePOS);
}
Expand Down Expand Up @@ -265,6 +271,9 @@ public boolean deleteChatThreads(Long platformId, Long threadId) {
chatThreadPO.setIsDeleted(true);
chatThreadDao.partialUpdateById(chatThreadPO);
List<ChatMessagePO> chatMessagePOS = chatMessageDao.findAllByThreadId(threadId);
if (chatMessagePOS.isEmpty()) {
return true;
}
chatMessagePOS.forEach(chatMessage -> chatMessage.setIsDeleted(true));
chatMessageDao.partialUpdateByIds(chatMessagePOS);
return true;
Expand Down
Loading