Persist front project requirement keyword

This commit is contained in:
王鹏
2026-05-23 16:49:02 +08:00
parent dfbae3387f
commit ecdc015c2f
13 changed files with 72 additions and 11 deletions

View File

@@ -296,6 +296,7 @@ async function loadProjectDraft(value) {
projectId.value = id
projectForm.projectName = project.projectName || ''
projectForm.projectDesc = project.projectDesc || ''
projectForm.keyword = project.requirementKeyword || projectForm.keyword || ''
projectForm.industryTemplate = project.industryTemplate || ''
appBlueprint.value = normalizeAppBlueprint(project.appBlueprint)
syncAppBlueprintJson()
@@ -314,6 +315,7 @@ async function ensureProject() {
const result = await createProject({
projectName: projectForm.projectName,
projectDesc: projectForm.projectDesc,
requirementKeyword: projectForm.keyword,
industryTemplate: projectForm.industryTemplate
})
const data = unwrap(result)
@@ -360,10 +362,9 @@ async function handleGenerateAppBlueprint() {
const id = await ensureProject()
const result = await generateAppBlueprint(id, {
projectName: projectForm.projectName,
projectDesc: projectForm.projectDesc || projectForm.keyword,
projectDesc: projectForm.projectDesc,
industryTemplate: projectForm.industryTemplate,
extraRequirements: projectForm.keyword,
appBlueprint: appBlueprintJson.value
extraRequirements: projectForm.keyword
})
appBlueprint.value = normalizeAppBlueprint(result)
syncAppBlueprintJson()
@@ -401,9 +402,10 @@ async function handleGenerateDatabase() {
const id = await ensureProject()
const result = await generateDatabase(id, {
projectName: projectForm.projectName,
projectDesc: projectForm.projectDesc || projectForm.keyword,
projectDesc: projectForm.projectDesc,
industryTemplate: projectForm.industryTemplate,
extraRequirements: projectForm.keyword
extraRequirements: projectForm.keyword,
appBlueprint: appBlueprintJson.value
})
database.value = normalizeDatabase(result)

View File

@@ -17,7 +17,7 @@
<el-table-column prop="projectName" label="项目名称" min-width="190">
<template #default="{ row }">
<div class="project-name">{{ row.projectName || '未命名项目' }}</div>
<div class="project-desc">{{ row.projectDesc || row.industryTemplate || '暂无描述' }}</div>
<div class="project-desc">{{ row.projectDesc || row.requirementKeyword || row.industryTemplate || '暂无描述' }}</div>
</template>
</el-table-column>
<el-table-column label="状态" width="140">

View File

@@ -14,6 +14,7 @@ public class FrontProject extends BaseEntity
private String packageName;
private String version;
private String projectDesc;
private String requirementKeyword;
private String industryTemplate;
private String frontFramework;
private String backFramework;
@@ -39,6 +40,8 @@ public class FrontProject extends BaseEntity
public void setVersion(String version) { this.version = version; }
public String getProjectDesc() { return projectDesc; }
public void setProjectDesc(String projectDesc) { this.projectDesc = projectDesc; }
public String getRequirementKeyword() { return requirementKeyword; }
public void setRequirementKeyword(String requirementKeyword) { this.requirementKeyword = requirementKeyword; }
public String getIndustryTemplate() { return industryTemplate; }
public void setIndustryTemplate(String industryTemplate) { this.industryTemplate = industryTemplate; }
public String getFrontFramework() { return frontFramework; }

View File

@@ -4,6 +4,7 @@ public class FrontProjectCreateRequest
{
private String projectName;
private String projectDesc;
private String requirementKeyword;
private String industryTemplate;
private String packageName;
private String version;
@@ -12,6 +13,8 @@ public class FrontProjectCreateRequest
public void setProjectName(String projectName) { this.projectName = projectName; }
public String getProjectDesc() { return projectDesc; }
public void setProjectDesc(String projectDesc) { this.projectDesc = projectDesc; }
public String getRequirementKeyword() { return requirementKeyword; }
public void setRequirementKeyword(String requirementKeyword) { this.requirementKeyword = requirementKeyword; }
public String getIndustryTemplate() { return industryTemplate; }
public void setIndustryTemplate(String industryTemplate) { this.industryTemplate = industryTemplate; }
public String getPackageName() { return packageName; }

View File

@@ -4,6 +4,7 @@ public class FrontProjectUpdateRequest
{
private String projectName;
private String projectDesc;
private String requirementKeyword;
private String industryTemplate;
private String packageName;
private String version;
@@ -12,6 +13,8 @@ public class FrontProjectUpdateRequest
public void setProjectName(String projectName) { this.projectName = projectName; }
public String getProjectDesc() { return projectDesc; }
public void setProjectDesc(String projectDesc) { this.projectDesc = projectDesc; }
public String getRequirementKeyword() { return requirementKeyword; }
public void setRequirementKeyword(String requirementKeyword) { this.requirementKeyword = requirementKeyword; }
public String getIndustryTemplate() { return industryTemplate; }
public void setIndustryTemplate(String industryTemplate) { this.industryTemplate = industryTemplate; }
public String getPackageName() { return packageName; }

View File

@@ -76,7 +76,7 @@ public class AiGenerateServiceImpl implements IAiGenerateService
String aiContent = deepSeekClient.chat(prompt);
AppBlueprintDesign blueprint = parseAppBlueprintResponse(aiContent);
normalizeAppBlueprint(blueprint);
markAppBlueprintGenerated(projectId, blueprint);
markAppBlueprintGenerated(projectId, blueprint, request);
generation.setResponsePayload(aiContent);
generation.setSuccess("1");
generation.setElapsedMs(System.currentTimeMillis() - start);
@@ -113,7 +113,7 @@ public class AiGenerateServiceImpl implements IAiGenerateService
validator.validate(response, maxTables(), maxColumnsPerTable());
businessBlueprintValidator.validate(response);
persistDatabase(userId, projectId, response);
markDatabaseGenerated(projectId, response, confirmedAppBlueprint);
markDatabaseGenerated(projectId, response, confirmedAppBlueprint, request);
generation.setResponsePayload(aiContent);
generation.setSuccess("1");
generation.setElapsedMs(System.currentTimeMillis() - start);
@@ -1068,7 +1068,7 @@ public class AiGenerateServiceImpl implements IAiGenerateService
}
}
private void markDatabaseGenerated(Long projectId, DatabaseDesignResponse response, String confirmedAppBlueprint)
private void markDatabaseGenerated(Long projectId, DatabaseDesignResponse response, String confirmedAppBlueprint, GenerateDatabaseRequest request)
{
FrontProject project = new FrontProject();
project.setProjectId(projectId);
@@ -1078,17 +1078,23 @@ public class AiGenerateServiceImpl implements IAiGenerateService
{
project.setAppBlueprint(confirmedAppBlueprint);
}
project.setRequirementKeyword(request == null ? null : request.getExtraRequirements());
project.setProjectDesc(request == null ? null : request.getProjectDesc());
project.setIndustryTemplate(request == null ? null : request.getIndustryTemplate());
project.setBusinessBlueprint(JSON.toJSONString(response.getBusinessActions()));
frontProjectMapper.updateFrontProject(project);
}
private void markAppBlueprintGenerated(Long projectId, AppBlueprintDesign blueprint)
private void markAppBlueprintGenerated(Long projectId, AppBlueprintDesign blueprint, GenerateAppBlueprintRequest request)
{
FrontProject project = new FrontProject();
project.setProjectId(projectId);
project.setGenerateStatus("0");
project.setPreviewStatus("0");
project.setAppBlueprint(JSON.toJSONString(blueprint));
project.setRequirementKeyword(request == null ? null : request.getExtraRequirements());
project.setProjectDesc(request == null ? null : request.getProjectDesc());
project.setIndustryTemplate(request == null ? null : request.getIndustryTemplate());
frontProjectMapper.updateFrontProject(project);
}

View File

@@ -62,6 +62,7 @@ public class FrontProjectServiceImpl implements IFrontProjectService
project.setUserId(userId);
project.setProjectName(request.getProjectName());
project.setProjectDesc(request.getProjectDesc());
project.setRequirementKeyword(request.getRequirementKeyword());
project.setIndustryTemplate(request.getIndustryTemplate());
project.setPackageName(StringUtils.defaultIfEmpty(request.getPackageName(), "com.easycode.generated"));
project.setVersion(StringUtils.defaultIfEmpty(request.getVersion(), "1.0.0"));
@@ -110,6 +111,7 @@ public class FrontProjectServiceImpl implements IFrontProjectService
project.setUserId(userId);
project.setProjectName(request.getProjectName());
project.setProjectDesc(request.getProjectDesc());
project.setRequirementKeyword(request.getRequirementKeyword());
project.setIndustryTemplate(request.getIndustryTemplate());
project.setPackageName(request.getPackageName());
project.setVersion(request.getVersion());

View File

@@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="packageName" column="package_name" />
<result property="version" column="version" />
<result property="projectDesc" column="project_desc" />
<result property="requirementKeyword" column="requirement_keyword" />
<result property="industryTemplate" column="industry_template" />
<result property="frontFramework" column="front_framework" />
<result property="backFramework" column="back_framework" />
@@ -27,7 +28,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectFrontProjectVo">
select project_id, user_id, project_name, project_file_name, package_name, version, project_desc, industry_template, front_framework, back_framework, generate_status, preview_status, app_blueprint, er_diagram, business_blueprint, status, create_time, update_time, remark from front_project
select project_id, user_id, project_name, project_file_name, package_name, version, project_desc, requirement_keyword, industry_template, front_framework, back_framework, generate_status, preview_status, app_blueprint, er_diagram, business_blueprint, status, create_time, update_time, remark from front_project
</sql>
<select id="selectFrontProjectById" parameterType="Long" resultMap="FrontProjectResult">
@@ -62,6 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="packageName != null">package_name,</if>
<if test="version != null">version,</if>
<if test="projectDesc != null">project_desc,</if>
<if test="requirementKeyword != null">requirement_keyword,</if>
<if test="industryTemplate != null">industry_template,</if>
<if test="frontFramework != null">front_framework,</if>
<if test="backFramework != null">back_framework,</if>
@@ -81,6 +83,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="packageName != null">#{packageName},</if>
<if test="version != null">#{version},</if>
<if test="projectDesc != null">#{projectDesc},</if>
<if test="requirementKeyword != null">#{requirementKeyword},</if>
<if test="industryTemplate != null">#{industryTemplate},</if>
<if test="frontFramework != null">#{frontFramework},</if>
<if test="backFramework != null">#{backFramework},</if>
@@ -103,6 +106,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="packageName != null">package_name = #{packageName},</if>
<if test="version != null">version = #{version},</if>
<if test="projectDesc != null">project_desc = #{projectDesc},</if>
<if test="requirementKeyword != null">requirement_keyword = #{requirementKeyword},</if>
<if test="industryTemplate != null">industry_template = #{industryTemplate},</if>
<if test="frontFramework != null">front_framework = #{frontFramework},</if>
<if test="backFramework != null">back_framework = #{backFramework},</if>

View File

@@ -135,6 +135,22 @@ public class AiGenerateServiceImplTest
assertEquals("1", generationCaptor.getValue().getSuccess());
}
@Test
public void generateDatabasePersistsRequirementKeywordFromRequest()
{
when(frontProjectMapper.selectFrontProjectByUserAndId(7L, 10L)).thenReturn(project());
when(frontProjectTableMapper.selectTablesByProjectId(10L)).thenReturn(Collections.<FrontProjectTable>emptyList());
when(deepSeekClient.chat(anyString())).thenReturn(mockResponse());
GenerateDatabaseRequest request = request();
request.setExtraRequirements("library borrow return keyword");
service.generateDatabase(7L, 10L, request);
ArgumentCaptor<FrontProject> projectCaptor = ArgumentCaptor.forClass(FrontProject.class);
verify(frontProjectMapper).updateFrontProject(projectCaptor.capture());
assertEquals("library borrow return keyword", projectCaptor.getValue().getRequirementKeyword());
}
@Test
public void generateDatabaseIncludesConfirmedAppBlueprintConstraintsInPrompt()
{

View File

@@ -63,9 +63,12 @@ public class FrontProjectServiceImplTest
FrontProjectCreateRequest request = new FrontProjectCreateRequest();
request.setProjectName("车辆管理系统");
request.setRequirementKeyword("borrow return books");
FrontProject project = service.createProject(7L, request);
assertEquals(Long.valueOf(7L), project.getUserId());
assertEquals("borrow return books", project.getRequirementKeyword());
assertEquals("com.easycode.generated", project.getPackageName());
assertEquals("1.0.0", project.getVersion());
assertEquals("Vue3 + Element Plus", project.getFrontFramework());

View File

@@ -1294,6 +1294,7 @@ create table front_project (
package_name varchar(100) default 'com.easycode.generated' comment '包名',
version varchar(20) default '1.0.0' comment '版本号',
project_desc varchar(1000) default '' comment '项目描述',
requirement_keyword varchar(1000) default '' comment '需求关键词',
industry_template varchar(50) default '' comment '行业模板',
front_framework varchar(50) default 'Vue3 + Element Plus' comment '前台框架',
back_framework varchar(50) default 'Spring Boot + MyBatis' comment '后端框架',

View File

@@ -0,0 +1,17 @@
set @front_requirement_keyword_exists := (
select count(1)
from information_schema.columns
where table_schema = database()
and table_name = 'front_project'
and column_name = 'requirement_keyword'
);
set @front_requirement_keyword_sql := if(
@front_requirement_keyword_exists = 0,
'alter table front_project add column requirement_keyword varchar(1000) default '''' comment ''需求关键词'' after project_desc',
'select ''front_project.requirement_keyword already exists'''
);
prepare front_requirement_keyword_stmt from @front_requirement_keyword_sql;
execute front_requirement_keyword_stmt;
deallocate prepare front_requirement_keyword_stmt;

View File

@@ -37,6 +37,7 @@ create table front_project (
package_name varchar(100) default 'com.easycode.generated' comment '包名',
version varchar(20) default '1.0.0' comment '版本号',
project_desc varchar(1000) default '' comment '项目描述',
requirement_keyword varchar(1000) default '' comment '需求关键词',
industry_template varchar(50) default '' comment '行业模板',
front_framework varchar(50) default 'Vue3 + Element Plus' comment '前台框架',
back_framework varchar(50) default 'Spring Boot + MyBatis' comment '后端框架',