Skip to content

Commit

Permalink
BIGTOP-4235: Fix update in SQLBuilder (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq authored Sep 26, 2024
1 parent d9c317f commit 31858b9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
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

0 comments on commit 31858b9

Please sign in to comment.