fix(项目设置): 字段重名校验

--bug=1035580 --user=陈建星 【项目管理】模版管理-新建字段,创建test字段提示已存在 https://www.tapd.cn/55049933/s/1461953
This commit is contained in:
AgAngle 2024-02-18 21:29:20 +08:00 committed by Craftsman
parent 3697ddd90c
commit af93df7862
6 changed files with 16 additions and 0 deletions

View File

@ -312,6 +312,7 @@ public class ProjectTemplateService extends BaseTemplateService {
Template originTemplate = super.getWithCheck(template.getId());
checkProjectTemplateEnable(originTemplate.getScopeId(), originTemplate.getScene());
template.setScopeId(originTemplate.getScopeId());
template.setScene(originTemplate.getScene());
checkProjectResourceExist(originTemplate);
return super.update(template, request.getCustomFields(), request.getSystemFields());
}

View File

@ -189,6 +189,7 @@ public class BaseCustomFieldService {
CustomFieldExample example = new CustomFieldExample();
example.createCriteria()
.andScopeIdEqualTo(customField.getScopeId())
.andSceneEqualTo(customField.getScene())
.andNameEqualTo(customField.getName());
if (CollectionUtils.isNotEmpty(customFieldMapper.selectByExample(example))) {
throw new MSException(CUSTOM_FIELD_EXIST);

View File

@ -248,6 +248,7 @@ public class BaseTemplateService {
TemplateExample example = new TemplateExample();
example.createCriteria()
.andScopeIdEqualTo(template.getScopeId())
.andSceneEqualTo(template.getScene())
.andNameEqualTo(template.getName());
if (CollectionUtils.isNotEmpty(templateMapper.selectByExample(example))) {
throw new MSException(TEMPLATE_EXIST);
@ -262,6 +263,7 @@ public class BaseTemplateService {
example.createCriteria()
.andScopeIdEqualTo(template.getScopeId())
.andIdNotEqualTo(template.getId())
.andSceneEqualTo(template.getScene())
.andNameEqualTo(template.getName());
if (CollectionUtils.isNotEmpty(templateMapper.selectByExample(example))) {
throw new MSException(TEMPLATE_EXIST);

View File

@ -100,6 +100,7 @@ public class OrganizationTemplateService extends BaseTemplateService {
Template originTemplate = super.getWithCheck(template.getId());
checkOrganizationTemplateEnable(originTemplate.getScopeId(), originTemplate.getScene());
template.setScopeId(originTemplate.getScopeId());
template.setScene(originTemplate.getScene());
checkOrgResourceExist(originTemplate);
updateRefProjectTemplate(template, request.getCustomFields(), request.getSystemFields());
template.setRefId(null);
@ -122,6 +123,7 @@ public class OrganizationTemplateService extends BaseTemplateService {
template.setId(projectTemplate.getId());
template.setScopeId(projectTemplate.getScopeId());
template.setRefId(orgTemplate.getId());
template.setScene(orgTemplate.getScene());
List<TemplateCustomFieldRequest> refCustomFields = getRefTemplateCustomFieldRequest(projectTemplate.getScopeId(), customFields);
super.update(template, refCustomFields, systemFields);
});

View File

@ -117,8 +117,13 @@ public class OrganizationCustomFieldControllerTests extends BaseTest {
}
assertRefCustomField(customField);
// 不同scene不校验重名
request.setScene(TemplateScene.TEST_PLAN.name());
this.requestPostWithOkAndReturn(DEFAULT_ADD, request);
// @校验是否开启组织模板
changeOrgTemplateEnable(false);
request.setScene(TemplateScene.FUNCTIONAL.name());
assertErrorCode(this.requestPost(DEFAULT_ADD, request), ORGANIZATION_TEMPLATE_PERMISSION);
changeOrgTemplateEnable(true);

View File

@ -118,7 +118,12 @@ public class OrganizationTemplateControllerTests extends BaseTest {
assertTemplateCustomFields(request, template);
assertRefTemplate(template, request);
// 不同scene不校验重名
request.setScene(TemplateScene.TEST_PLAN.name());
this.requestPostWithOkAndReturn(DEFAULT_ADD, request);
// @@重名校验异常
request.setScene(scene);
assertErrorCode(this.requestPost(DEFAULT_ADD, request), TEMPLATE_EXIST);
// @校验是否开启组织模板