Skip to content

Commit e20d39c

Browse files
committed
[app-builder] 应用发布后允许重命名
1 parent 4772daf commit e20d39c

File tree

5 files changed

+71
-15
lines changed

5 files changed

+71
-15
lines changed

app-builder/plugins/aipp-plugin/src/main/java/modelengine/fit/jober/aipp/domains/appversion/service/impl/AppVersionServiceImpl.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,24 @@ public AppVersion update(String appId, AppBuilderAppDto appDto, OperationContext
333333
if (appVersion.isPublished()) {
334334
throw new AippException(AippErrCode.APP_HAS_ALREADY);
335335
}
336-
List<AppTask> tasks = appVersion.getPublishedTasks(context);
337-
if (CollectionUtils.isNotEmpty(tasks) && !StringUtils.equals(tasks.get(0).getEntity().getName(),
338-
appDto.getName())) {
339-
throw new AippException(AippErrCode.APP_NAME_HAS_PUBLISHED);
340-
}
336+
337+
// 检查名称是否发生变化
338+
String oldName = appVersion.getData().getName();
339+
String newName = appDto.getName();
340+
boolean nameChanged = !StringUtils.equals(oldName, newName);
341+
341342
this.validateAppName(appDto.getName(), context);
343+
344+
// 如果名称发生变化,更新所有草稿态任务的name字段
345+
if (nameChanged) {
346+
List<AppTask> previewTasks = this.appTaskService.getPreviewTasks(
347+
appVersion.getData().getAppSuiteId(), context);
348+
for (AppTask previewTask : previewTasks) {
349+
previewTask.getEntity().setName(newName);
350+
this.appTaskService.updateTask(previewTask, context);
351+
}
352+
}
353+
342354
appVersion.getData().setName(appDto.getName());
343355
appVersion.getData().setUpdateBy(context.getOperator());
344356
appVersion.getData().setUpdateAt(LocalDateTime.now());

app-builder/plugins/aipp-plugin/src/main/resources/mapper/AppBuilderAppMapper.xml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
select
9191
<include refid="Base_Column_List"/>
9292
from (
93-
SELECT DISTINCT ON ( "name" ) * FROM app_builder_app where tenant_id = #{tenantId} and is_deleted = 0
93+
SELECT DISTINCT ON ( "app_suite_id" ) * FROM app_builder_app where tenant_id = #{tenantId} and is_deleted = 0
9494
<if test="cond.type != null">
9595
and type = #{cond.type}
9696
</if>
@@ -104,7 +104,6 @@
104104
</when>
105105
<when test="cond.state == 'inactive'">
106106
and state = #{cond.state}
107-
and (attributes ->> 'latest_version') is null
108107
</when>
109108
</choose>
110109
</if>
@@ -130,7 +129,7 @@
130129
and (user_group_id = #{cond.userGroupId} or user_group_id = '*')
131130
</if>
132131
ORDER BY
133-
"name", update_at DESC
132+
"app_suite_id", update_at DESC
134133
) as sub
135134
WHERE <include refid="appTypeCondition"/>
136135
ORDER BY update_at DESC offset #{offset} limit #{limit}
@@ -176,7 +175,7 @@
176175
<select id="countByTenantId" resultType="long">
177176
select count(*) from (
178177
select
179-
DISTINCT ON (name) *
178+
DISTINCT ON (app_suite_id) *
180179
from app_builder_app
181180
where tenant_id = #{tenantId} and is_deleted = 0
182181
<if test="cond.type != null">
@@ -189,7 +188,6 @@
189188
</when>
190189
<when test="cond.state == 'inactive'">
191190
and state != 'active'
192-
and (attributes ->> 'latest_version') is null
193191
</when>
194192
</choose>
195193
</if>
@@ -211,6 +209,7 @@
211209
<if test='cond.userGroupId != null'>
212210
and (user_group_id = #{cond.userGroupId} or user_group_id = '*')
213211
</if>
212+
ORDER BY app_suite_id, update_at DESC
214213
) as latest_records WHERE <include refid="appTypeCondition"/>;
215214
</select>
216215

app-builder/plugins/aipp-plugin/src/test/java/modelengine/fit/jober/aipp/domains/appversion/AppVersionServiceTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ public void testUpdateVersion() {
513513
doNothing().when(this.uploadedFileManageService).changeRemovable(anyString(), anyInt());
514514
doNothing().when(this.appBuilderAppMapper).updateOne(any());
515515

516+
// Mock getPreviewTasks to return empty list (no name change in this test)
517+
when(this.appTaskService.getPreviewTasks(anyString(), any())).thenReturn(Collections.emptyList());
518+
516519
// when.
517520
OperationContext context = new OperationContext();
518521
context.setOperator("zy");
@@ -533,6 +536,50 @@ public void testUpdateVersion() {
533536
verify(this.uploadedFileManageService, times(2)).changeRemovable(anyString(), anyInt());
534537
}
535538

539+
@Test
540+
@DisplayName("测试 update version with name change")
541+
public void testUpdateVersionWithNameChange() {
542+
// given.
543+
AppBuilderAppPo data = AppBuilderAppPo.builder()
544+
.appSuiteId("app_1")
545+
.name("oldAppName")
546+
.state(AppState.IMPORTING.getName())
547+
.build();
548+
AppVersion appVersion = mock(AppVersion.class);
549+
when(this.appBuilderAppMapper.selectWithId(anyString())).thenReturn(data);
550+
when(this.appVersionFactory.create(any(), any())).thenReturn(appVersion);
551+
when(appVersion.getData()).thenReturn(data);
552+
when(appVersion.getIcon()).thenReturn("icon1");
553+
doNothing().when(appVersion).putAttributes(any());
554+
555+
doNothing().when(this.appBuilderAppMapper).updateOne(any());
556+
doNothing().when(this.uploadedFileManageService).changeRemovable(anyString(), anyInt());
557+
558+
// Mock preview tasks
559+
AppTask previewTask = mock(AppTask.class);
560+
when(previewTask.getEntity()).thenReturn(AppTask.asEntity());
561+
when(this.appTaskService.getPreviewTasks(eq("app_1"), any())).thenReturn(List.of(previewTask));
562+
doNothing().when(this.appTaskService).updateTask(any(), any());
563+
564+
// when.
565+
OperationContext context = new OperationContext();
566+
context.setOperator("zy");
567+
this.appVersionService.update("app_version_1", AppBuilderAppDto.builder()
568+
.name("newAppName")
569+
.type(AppTypeEnum.APP.code())
570+
.appType(NORMAL.name())
571+
.state(AppState.INACTIVE.getName())
572+
.version("1.0.0")
573+
.build(), context);
574+
575+
// then.
576+
assertEquals("newAppName", data.getName());
577+
assertEquals("zy", data.getUpdateBy());
578+
// Verify that preview task was updated
579+
verify(this.appTaskService, times(1)).getPreviewTasks(eq("app_1"), any());
580+
verify(this.appTaskService, times(1)).updateTask(eq(previewTask), any());
581+
}
582+
536583
@Test
537584
@DisplayName("测试 update 通过graph")
538585
public void testUpdateByGraph() {

app-builder/plugins/task-new/src/main/resources/mapper/MetaMapper.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
<update id="updateOne" parameterType="modelengine.fit.task_new.po.MetaPo">
3030
update task_new
3131
<set>
32+
<if test="name != null">
33+
name = #{name},
34+
</if>
3235
<if test="version != null">
3336
version = #{version},
3437
</if>

app-builder/services/aipp-service/src/main/java/modelengine/fit/jober/aipp/common/exception/AippErrCode.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,6 @@ public enum AippErrCode implements ErrorCode, RetCode {
212212
*/
213213
INVALID_OPERATION(90002913, "系统错误,应用信息为空,请联系管理员。"),
214214

215-
/**
216-
* 该应用已经成功发布过,无法修改应用名称
217-
*/
218-
APP_NAME_HAS_PUBLISHED(90002914, "该应用已经成功发布过,无法修改应用名称。"),
219-
220215
/**
221216
* 禁止使用更低的版本号
222217
*/

0 commit comments

Comments
 (0)