Skip to content
Open
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 @@ -333,12 +333,24 @@ public AppVersion update(String appId, AppBuilderAppDto appDto, OperationContext
if (appVersion.isPublished()) {
throw new AippException(AippErrCode.APP_HAS_ALREADY);
}
List<AppTask> tasks = appVersion.getPublishedTasks(context);
if (CollectionUtils.isNotEmpty(tasks) && !StringUtils.equals(tasks.get(0).getEntity().getName(),
appDto.getName())) {
throw new AippException(AippErrCode.APP_NAME_HAS_PUBLISHED);
}

// 检查名称是否发生变化
String oldName = appVersion.getData().getName();
String newName = appDto.getName();
boolean nameChanged = !StringUtils.equals(oldName, newName);

this.validateAppName(appDto.getName(), context);

// 如果名称发生变化,更新所有草稿态任务的name字段
if (nameChanged) {
List<AppTask> previewTasks = this.appTaskService.getPreviewTasks(
appVersion.getData().getAppSuiteId(), context);
for (AppTask previewTask : previewTasks) {
previewTask.getEntity().setName(newName);
this.appTaskService.updateTask(previewTask, context);
}
}

appVersion.getData().setName(appDto.getName());
appVersion.getData().setUpdateBy(context.getOperator());
appVersion.getData().setUpdateAt(LocalDateTime.now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
select
<include refid="Base_Column_List"/>
from (
SELECT DISTINCT ON ( "name" ) * FROM app_builder_app where tenant_id = #{tenantId} and is_deleted = 0
SELECT DISTINCT ON ( "app_suite_id" ) * FROM app_builder_app where tenant_id = #{tenantId} and is_deleted = 0
<if test="cond.type != null">
and type = #{cond.type}
</if>
Expand All @@ -104,7 +104,6 @@
</when>
<when test="cond.state == 'inactive'">
and state = #{cond.state}
and (attributes ->> 'latest_version') is null
</when>
</choose>
</if>
Expand All @@ -130,7 +129,7 @@
and (user_group_id = #{cond.userGroupId} or user_group_id = '*')
</if>
ORDER BY
"name", update_at DESC
"app_suite_id", update_at DESC
) as sub
WHERE <include refid="appTypeCondition"/>
ORDER BY update_at DESC offset #{offset} limit #{limit}
Expand Down Expand Up @@ -176,7 +175,7 @@
<select id="countByTenantId" resultType="long">
select count(*) from (
select
DISTINCT ON (name) *
DISTINCT ON (app_suite_id) *
from app_builder_app
where tenant_id = #{tenantId} and is_deleted = 0
<if test="cond.type != null">
Expand All @@ -189,7 +188,6 @@
</when>
<when test="cond.state == 'inactive'">
and state != 'active'
and (attributes ->> 'latest_version') is null
</when>
</choose>
</if>
Expand All @@ -211,6 +209,7 @@
<if test='cond.userGroupId != null'>
and (user_group_id = #{cond.userGroupId} or user_group_id = '*')
</if>
ORDER BY app_suite_id, update_at DESC
) as latest_records WHERE <include refid="appTypeCondition"/>;
</select>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ public void testUpdateVersion() {
doNothing().when(this.uploadedFileManageService).changeRemovable(anyString(), anyInt());
doNothing().when(this.appBuilderAppMapper).updateOne(any());

// Mock getPreviewTasks to return empty list (no name change in this test)
when(this.appTaskService.getPreviewTasks(anyString(), any())).thenReturn(Collections.emptyList());

// when.
OperationContext context = new OperationContext();
context.setOperator("zy");
Expand All @@ -533,6 +536,50 @@ public void testUpdateVersion() {
verify(this.uploadedFileManageService, times(2)).changeRemovable(anyString(), anyInt());
}

@Test
@DisplayName("测试 update version with name change")
public void testUpdateVersionWithNameChange() {
// given.
AppBuilderAppPo data = AppBuilderAppPo.builder()
.appSuiteId("app_1")
.name("oldAppName")
.state(AppState.IMPORTING.getName())
.build();
AppVersion appVersion = mock(AppVersion.class);
when(this.appBuilderAppMapper.selectWithId(anyString())).thenReturn(data);
when(this.appVersionFactory.create(any(), any())).thenReturn(appVersion);
when(appVersion.getData()).thenReturn(data);
when(appVersion.getIcon()).thenReturn("icon1");
doNothing().when(appVersion).putAttributes(any());

doNothing().when(this.appBuilderAppMapper).updateOne(any());
doNothing().when(this.uploadedFileManageService).changeRemovable(anyString(), anyInt());

// Mock preview tasks
AppTask previewTask = mock(AppTask.class);
when(previewTask.getEntity()).thenReturn(AppTask.asEntity());
when(this.appTaskService.getPreviewTasks(eq("app_1"), any())).thenReturn(List.of(previewTask));
doNothing().when(this.appTaskService).updateTask(any(), any());

// when.
OperationContext context = new OperationContext();
context.setOperator("zy");
this.appVersionService.update("app_version_1", AppBuilderAppDto.builder()
.name("newAppName")
.type(AppTypeEnum.APP.code())
.appType(NORMAL.name())
.state(AppState.INACTIVE.getName())
.version("1.0.0")
.build(), context);

// then.
assertEquals("newAppName", data.getName());
assertEquals("zy", data.getUpdateBy());
// Verify that preview task was updated
verify(this.appTaskService, times(1)).getPreviewTasks(eq("app_1"), any());
verify(this.appTaskService, times(1)).updateTask(eq(previewTask), any());
}

@Test
@DisplayName("测试 update 通过graph")
public void testUpdateByGraph() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<update id="updateOne" parameterType="modelengine.fit.task_new.po.MetaPo">
update task_new
<set>
<if test="name != null">
name = #{name},
</if>
<if test="version != null">
version = #{version},
</if>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,6 @@ public enum AippErrCode implements ErrorCode, RetCode {
*/
INVALID_OPERATION(90002913, "系统错误,应用信息为空,请联系管理员。"),

/**
* 该应用已经成功发布过,无法修改应用名称
*/
APP_NAME_HAS_PUBLISHED(90002914, "该应用已经成功发布过,无法修改应用名称。"),

/**
* 禁止使用更低的版本号
*/
Expand Down