Skip to content

Commit a09e9df

Browse files
authored
[app-builder] add Database records scheduled cleaner (#204)
1 parent 398da20 commit a09e9df

35 files changed

+1472
-11
lines changed

app-builder/jane/plugins/aipp-plugin/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@
122122
<groupId>io.opentelemetry</groupId>
123123
<artifactId>opentelemetry-api</artifactId>
124124
</dependency>
125+
<dependency>
126+
<groupId>com.opencsv</groupId>
127+
<artifactId>opencsv</artifactId>
128+
</dependency>
125129
<dependency>
126130
<groupId>modelengine.jade.service</groupId>
127131
<artifactId>aipp-prompt-builder-service</artifactId>

app-builder/jane/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/mapper/AippChatMapper.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ List<QueryChatRsp> selectChatList(@Param("requestParam") QueryChatRequest reques
5858
* @param chatId 会话ID
5959
* @return 会话记录数目
6060
*/
61-
long getChatListCount(@Param("requestParam") QueryChatRequest request, @Param("chatId") String chatId, @Param("createBy") String createBy);
61+
long getChatListCount(@Param("requestParam") QueryChatRequest request, @Param("chatId") String chatId,
62+
@Param("createBy") String createBy);
6263

6364
/**
6465
* 查询会话
@@ -115,6 +116,7 @@ List<ChatDto> selectChat(@Param("chatId") String chatId, @Param("offset") Intege
115116

116117
/**
117118
* 根据instance id列表批量查询对话消息
119+
*
118120
* @param instanceIds instance id列表
119121
* @return 对应会话信息
120122
*/
@@ -178,4 +180,43 @@ List<ChatDto> selectChat(@Param("chatId") String chatId, @Param("offset") Intege
178180
*/
179181
List<QueryChatRsp> selectChatByCondition(@Param("condition") Map<String, String> condition,
180182
@Param("requestParam") QueryChatInfoRequest queryChatInfoRequest);
183+
184+
/**
185+
* 获取超期的对话唯一标识。
186+
*
187+
* @param expiredDays 表示超期时长的 {@code int}。
188+
* @param limit 表示查询数量的 {@code int}。
189+
* @return 表示对话唯一标识列表的 {@link List}{@code <}{@link String}{@code >}。
190+
*/
191+
List<String> getExpiredChatIds(int expiredDays, int limit);
192+
193+
/**
194+
* 根据对话标识列表强制删除对话。
195+
*
196+
* @param chatIds 表示对话唯一标识列表的 {@link List}{@code <}{@link String}{@code >}。
197+
*/
198+
void forceDeleteChat(List<String> chatIds);
199+
200+
/**
201+
* 根据对话标识列表强制删除对话和任务实例关系。
202+
*
203+
* @param chatIds 表示对话唯一标识列表的 {@link List}{@code <}{@link String}{@code >}。
204+
*/
205+
void deleteWideRelationshipByChatIds(List<String> chatIds);
206+
207+
/**
208+
* 根据对话唯一标识列表批量查询会话记录实体。
209+
*
210+
* @param chatIds 表示对话唯一标识列表的 {@link List}{@code <}{@link String}{@code >}。
211+
* @return 表示会话记录实体列表的 {@link List}{@code <}{@link ChatInfo}{@code >}。
212+
*/
213+
List<ChatInfo> selectByChatIds(@Param("chatIds") List<String> chatIds);
214+
215+
/**
216+
* 根据对话唯一标识列表批量查询会话记录和任务实例的关系。
217+
*
218+
* @param chatIds 表示对话唯一标识列表的 {@link List}{@code <}{@link String}{@code >}。
219+
* @return 表示会话记录和任务实例的关系的 {@link List}{@code <}{@link ChatAndInstanceMap}{@code >}。
220+
*/
221+
List<ChatAndInstanceMap> selectTaskInstanceRelationsByChatIds(@Param("chatIds") List<String> chatIds);
181222
}

app-builder/jane/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/mapper/AippLogMapper.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,28 @@ List<String> selectRecentInstanceIdByAippIds(List<String> aippIds, String aippTy
195195
* @param logIds 表示指定的历史记录 id 的 {@link List}{@code <}{@link Long}{@code >}。
196196
*/
197197
void deleteInstanceLogs(@Param("logIds") List<Long> logIds);
198+
199+
/**
200+
* 获取超期的调试对话记录唯一标识列表。
201+
*
202+
* @param expiredDays 表示超期时间的 {@code int}。
203+
* @param limit 表示查询条数的 {@code int}。
204+
* @return 表示历史会话记录的id列表的 {@link List}{@code <}{@link Long}{@code >}。
205+
*/
206+
List<Long> getExpireInstanceLogIds(String aippType, int expiredDays, int limit);
207+
208+
/**
209+
* 根据实例唯一标识列表强制删除会话记录。
210+
*
211+
* @param logIds 表示会话实例id列表的 {@link List}{@code <}{@link Long}{@code >}。
212+
*/
213+
void forceDeleteInstanceLogsByIds(List<Long> logIds);
214+
215+
/**
216+
* 根据日志唯一标识列表查询会话历史记录。
217+
*
218+
* @param logIds 标识日志唯一标识列表的 {@link List}{@code <}{@link Long}{@code >}。
219+
* @return 表示实例历史记录列表的 {@link List}{@code <}{@link AippInstLog}{@code >}。
220+
*/
221+
List<AippInstLog> selectByLogIds(@Param("logIds") List<Long> logIds);
198222
}

app-builder/jane/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/mapper/AppBuilderRuntimeInfoMapper.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,20 @@ public interface AppBuilderRuntimeInfoMapper {
3131
* @param appBuilderRuntimeInfoPO {@link AppBuilderRuntimeInfoPo} 对象.
3232
*/
3333
void insertOne(AppBuilderRuntimeInfoPo appBuilderRuntimeInfoPO);
34+
35+
/**
36+
* 获取超期的运行时信息唯一标识列表。
37+
*
38+
* @param expiredDays 表示超期时间的 {@code int}。
39+
* @param limit 表示查询条数的 {@code int}。
40+
* @return 表示运行时信息唯一标识列表的 {@link List}{@code <}{@link Long}{@code >}。
41+
*/
42+
List<Long> getExpiredRuntimeInfos(int expiredDays, int limit);
43+
44+
/**
45+
* 根据运行时信息唯一标识列表强制删除会话记录。
46+
*
47+
* @param runtimeInfoIds 表示运行时信息唯一标识列表的 {@link List}{@code <}{@link Long}{@code >}。
48+
*/
49+
void deleteRuntimeInfos(List<Long> runtimeInfoIds);
3450
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
package modelengine.fit.jober.aipp.repository;
8+
9+
import modelengine.fit.jober.aipp.entity.ChatAndInstanceMap;
10+
import modelengine.fit.jober.aipp.entity.ChatInfo;
11+
12+
import java.util.List;
13+
14+
/**
15+
* 应用对话的存储仓库。
16+
*
17+
* @author 杨祥宇
18+
* @since 2025-04-09
19+
*/
20+
public interface AippChatRepository {
21+
/**
22+
* 获取超期的对话唯一标识列表。
23+
*
24+
* @param expiredDays 表示超期时长的 {@code int}。
25+
* @param limit 表示查询数量的 {@code int}。
26+
* @return 表示对话唯一标识列表的 {@link List}{@code <}{@link String}{@code >}。
27+
*/
28+
List<String> getExpiredChatIds(int expiredDays, int limit);
29+
30+
/**
31+
* 根据对话标识列表强制删除对话。
32+
*
33+
* @param chatIds 表示对话唯一标识列表的 {@link List}{@code <}{@link String}{@code >}。
34+
*/
35+
void forceDeleteChat(List<String> chatIds);
36+
37+
/**
38+
* 根据对话唯一标识列表批量查询会话记录实体。
39+
*
40+
* @param chatIds 表示对话唯一标识列表的 {@link List}{@code <}{@link String}{@code >}。
41+
* @return 表示会话记录实体列表的 {@link List}{@code <}{@link ChatInfo}{@code >}。
42+
*/
43+
List<ChatInfo> selectByChatIds(List<String> chatIds);
44+
45+
/**
46+
* 根据对话唯一标识列表批量查询会话记录和任务实例的关系。
47+
*
48+
* @param chatIds 表示对话唯一标识列表的 {@link List}{@code <}{@link String}{@code >}。
49+
* @return 表示会话记录和任务实例的关系的 {@link List}{@code <}{@link ChatAndInstanceMap}{@code >}。
50+
*/
51+
List<ChatAndInstanceMap> selectTaskInstanceRelationsByChatIds(List<String> chatIds);
52+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
package modelengine.fit.jober.aipp.repository;
8+
9+
import modelengine.fit.jober.aipp.entity.AippInstLog;
10+
11+
import java.util.List;
12+
13+
/**
14+
* 应用实例历史记录的存储仓库。
15+
*
16+
* @author 杨祥宇
17+
* @since 2025-04-09
18+
*/
19+
public interface AippInstanceLogRepository {
20+
/**
21+
* 获取调试类型的应用过期历史记录。
22+
*
23+
* @param expiredDays 表示超期天数的 {@code int}。
24+
* @param limit 表示查询条数的 {@code int}。
25+
* @return 表示超期历史记录id的 {@link List}{@code <}{@link Long}{@code >}。
26+
*/
27+
List<Long> getExpireInstanceLogIds(String aippType, int expiredDays, int limit);
28+
29+
/**
30+
* 根据日志唯一标识列表强制删除历史记录。
31+
*
32+
* @param logIds 表示历史记录的唯一标识列表的 {@link List}{@code <}{@link Long}{@code >}。
33+
*/
34+
void forceDeleteInstanceLogs(List<Long> logIds);
35+
36+
/**
37+
* 根据日志唯一标识列表查询会话历史记录
38+
*
39+
* @param logIds 标识日志唯一标识列表的 {@link List}{@code <}{@link Long}{@code >}。
40+
* @return 表示实例历史记录列表的 {@link List}{@code <}{@link AippInstLog}{@code >}。
41+
*/
42+
List<AippInstLog> selectByLogIds(List<Long> logIds);
43+
}

app-builder/jane/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/repository/AppBuilderRuntimeInfoRepository.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,20 @@ public interface AppBuilderRuntimeInfoRepository {
3131
* @param info {@link AppBuilderRuntimeInfo} 运行时信息.
3232
*/
3333
void insertOne(AppBuilderRuntimeInfo info);
34+
35+
/**
36+
* 获取运行时信息过期历史记录。
37+
*
38+
* @param expiredDays 表示超期天数的 {@code int}。
39+
* @param limit 表示查询条数的 {@code int}。
40+
* @return 表示超期运行时信息id的 {@link List}{@code <}{@link Long}{@code >}。
41+
*/
42+
List<Long> getExpiredRuntimeInfos(int expiredDays, int limit);
43+
44+
/**
45+
* 根据运行时信息id列表强制删除历史记录。
46+
*
47+
* @param runtimeInfoIds 表示历史记录的id列表的 {@link List}{@code <}{@link Long}{@code >}。
48+
*/
49+
void deleteRuntimeInfos(List<Long> runtimeInfoIds);
3450
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
package modelengine.fit.jober.aipp.repository.impl;
8+
9+
import modelengine.fit.jober.aipp.entity.ChatAndInstanceMap;
10+
import modelengine.fit.jober.aipp.entity.ChatInfo;
11+
import modelengine.fit.jober.aipp.mapper.AippChatMapper;
12+
import modelengine.fit.jober.aipp.repository.AippChatRepository;
13+
import modelengine.fitframework.annotation.Component;
14+
import modelengine.fitframework.transaction.Transactional;
15+
import modelengine.fitframework.util.CollectionUtils;
16+
17+
import java.util.ArrayList;
18+
import java.util.List;
19+
20+
/**
21+
* {@link AippChatRepository} 对应实现类。
22+
*
23+
* @author 杨祥宇
24+
* @since 2025-04-09
25+
*/
26+
@Component
27+
public class AippChatRepositoryImpl implements AippChatRepository {
28+
private final AippChatMapper aippChatMapper;
29+
30+
/**
31+
* 表示用对话持久层构造 {@link AippChatRepositoryImpl} 的实例。
32+
*
33+
* @param aippChatMapper 表示对话持久层实例的 {@link AippChatMapper}。
34+
*/
35+
public AippChatRepositoryImpl(AippChatMapper aippChatMapper) {this.aippChatMapper = aippChatMapper;}
36+
37+
@Override
38+
public List<String> getExpiredChatIds(int expiredDays, int limit) {
39+
return this.aippChatMapper.getExpiredChatIds(expiredDays, limit);
40+
}
41+
42+
@Override
43+
@Transactional
44+
public void forceDeleteChat(List<String> chatIds) {
45+
if (CollectionUtils.isEmpty(chatIds)) {
46+
return;
47+
}
48+
this.aippChatMapper.forceDeleteChat(chatIds);
49+
this.aippChatMapper.deleteWideRelationshipByChatIds(chatIds);
50+
}
51+
52+
@Override
53+
public List<ChatInfo> selectByChatIds(List<String> chatIds) {
54+
if (CollectionUtils.isEmpty(chatIds)) {
55+
return new ArrayList<>();
56+
}
57+
return this.aippChatMapper.selectByChatIds(chatIds);
58+
}
59+
60+
@Override
61+
public List<ChatAndInstanceMap> selectTaskInstanceRelationsByChatIds(List<String> chatIds) {
62+
if (CollectionUtils.isEmpty(chatIds)) {
63+
return new ArrayList<>();
64+
}
65+
return this.aippChatMapper.selectTaskInstanceRelationsByChatIds(chatIds);
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
package modelengine.fit.jober.aipp.repository.impl;
8+
9+
import modelengine.fit.jober.aipp.entity.AippInstLog;
10+
import modelengine.fit.jober.aipp.mapper.AippLogMapper;
11+
import modelengine.fit.jober.aipp.repository.AippInstanceLogRepository;
12+
import modelengine.fitframework.annotation.Component;
13+
import modelengine.fitframework.util.CollectionUtils;
14+
15+
import java.util.List;
16+
17+
/**
18+
* {@link AippInstanceLogRepository} 对应实现类。
19+
*
20+
* @author 杨祥宇
21+
* @since 2025-04-09
22+
*/
23+
@Component
24+
public class AippInstanceLogRepositoryImpl implements AippInstanceLogRepository {
25+
private final AippLogMapper aippLogMapper;
26+
27+
/**
28+
* 表示用日志持久层构造 {@link AippInstanceLogRepositoryImpl} 的实例。
29+
*
30+
* @param aippLogMapper 表示日志持久层实例的 {@link AippLogMapper}。
31+
*/
32+
public AippInstanceLogRepositoryImpl(AippLogMapper aippLogMapper) {this.aippLogMapper = aippLogMapper;}
33+
34+
@Override
35+
public List<Long> getExpireInstanceLogIds(String aippType, int expiredDays, int limit) {
36+
return this.aippLogMapper.getExpireInstanceLogIds(aippType, expiredDays, limit);
37+
}
38+
39+
@Override
40+
public void forceDeleteInstanceLogs(List<Long> logIds) {
41+
if (CollectionUtils.isEmpty(logIds)) {
42+
return;
43+
}
44+
this.aippLogMapper.forceDeleteInstanceLogsByIds(logIds);
45+
}
46+
47+
@Override
48+
public List<AippInstLog> selectByLogIds(List<Long> logIds) {
49+
return this.aippLogMapper.selectByLogIds(logIds);
50+
}
51+
}

app-builder/jane/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/repository/impl/AppBuilderRuntimeInfoRepositoryImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import modelengine.fit.jober.aipp.repository.AppBuilderRuntimeInfoRepository;
1212
import modelengine.fit.jober.aipp.serializer.impl.AppBuilderRuntimeInfoSerializer;
1313
import modelengine.fitframework.annotation.Component;
14+
import modelengine.fitframework.util.CollectionUtils;
1415

1516
import java.util.List;
1617
import java.util.stream.Collectors;
@@ -44,4 +45,17 @@ public List<AppBuilderRuntimeInfo> selectByTraceId(String traceId) {
4445
public void insertOne(AppBuilderRuntimeInfo info) {
4546
this.mapper.insertOne(this.serializer.serialize(info));
4647
}
48+
49+
@Override
50+
public List<Long> getExpiredRuntimeInfos(int expiredDays, int limit) {
51+
return this.mapper.getExpiredRuntimeInfos(expiredDays, limit);
52+
}
53+
54+
@Override
55+
public void deleteRuntimeInfos(List<Long> runtimeInfoIds) {
56+
if (CollectionUtils.isEmpty(runtimeInfoIds)) {
57+
return;
58+
}
59+
this.mapper.deleteRuntimeInfos(runtimeInfoIds);
60+
}
4761
}

0 commit comments

Comments
 (0)