diff --git a/backend/src/main/java/io/metersphere/controller/IssueTemplateController.java b/backend/src/main/java/io/metersphere/controller/IssueTemplateController.java index 4b6d78e2da..34cd014410 100644 --- a/backend/src/main/java/io/metersphere/controller/IssueTemplateController.java +++ b/backend/src/main/java/io/metersphere/controller/IssueTemplateController.java @@ -68,11 +68,11 @@ public class IssueTemplateController { @PostMapping("/copy") public void copy(@RequestBody CopyIssueTemplateRequest request) { - issueTemplateService.copy(request); + List copyRecords = issueTemplateService.copy(request); // 目标项目操作日志 - if (CollectionUtils.isNotEmpty(request.getTargetProjectIds())) { - request.getTargetProjectIds().forEach(targetProjectId -> { - issueTemplateService.copyIssueTemplateLog(targetProjectId); + if (CollectionUtils.isNotEmpty(copyRecords)) { + copyRecords.forEach(copyRecord -> { + issueTemplateService.copyIssueTemplateLog(copyRecord.getProjectId(), copyRecord.getName()); }); } } diff --git a/backend/src/main/java/io/metersphere/service/IssueTemplateService.java b/backend/src/main/java/io/metersphere/service/IssueTemplateService.java index 575103c4f5..7290f973d5 100644 --- a/backend/src/main/java/io/metersphere/service/IssueTemplateService.java +++ b/backend/src/main/java/io/metersphere/service/IssueTemplateService.java @@ -1,6 +1,7 @@ package io.metersphere.service; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtCustomFieldMapper; @@ -74,6 +75,8 @@ public class IssueTemplateService extends TemplateBaseService { @Resource WorkspaceMapper workspaceMapper; + private static final String CUSTOM_FIELD_TYPE = "select"; + public String add(UpdateIssueTemplateRequest request) { checkExist(request); IssueTemplate template = new IssueTemplate(); @@ -325,12 +328,12 @@ public class IssueTemplateService extends TemplateBaseService { return issueTemplateCopyDto; } - public void copy(CopyIssueTemplateRequest request) { + public List copy(CopyIssueTemplateRequest request) { if (CollectionUtils.isEmpty(request.getTargetProjectIds())) { - MSException.throwException("target project not checked"); + MSException.throwException("cannot copy, target project not checked"); } if (request.getId() == null) { - MSException.throwException("source project is empty"); + MSException.throwException("copy error, source project is empty"); } List issueTemplateRecords = new ArrayList<>(); List customFieldRecords = new ArrayList<>(); @@ -397,9 +400,18 @@ public class IssueTemplateService extends TemplateBaseService { if (sourceCustomField.getSystem()) { // 系统字段 String options; - if (StringUtils.equals("select", sourceCustomField.getType())) { - options = StringUtils.replace(tarCustomField.getOptions(), "]", ",") + StringUtils.replace(sourceCustomField.getOptions(), "[", ""); + if (StringUtils.equals(CUSTOM_FIELD_TYPE, sourceCustomField.getType())) { + // 下拉框选项 + List sourceOptions = JSONObject.parseArray(sourceCustomField.getOptions(), JSONObject.class); + sourceOptions.removeIf(sourceOption -> StringUtils.contains(tarCustomField.getOptions(), sourceOption.get("text").toString())); + if (CollectionUtils.isNotEmpty(sourceOptions)) { + String appendSourceOption = JSONObject.toJSONString(sourceOptions); + options = StringUtils.replace(tarCustomField.getOptions(), "]", ",") + StringUtils.replace(appendSourceOption, "[", ""); + } else { + options = tarCustomField.getOptions(); + } } else { + // 普通值 options = "[]"; } tarCustomField.setOptions(options); @@ -439,6 +451,7 @@ public class IssueTemplateService extends TemplateBaseService { if (CollectionUtils.isNotEmpty(customFieldRecords)) { extCustomFieldMapper.batchInsert(customFieldRecords); } + return issueTemplateRecords; } public String getLogDetails(String id, List newCustomFieldTemplates) { @@ -507,15 +520,15 @@ public class IssueTemplateService extends TemplateBaseService { return permissionsByUserGroups; } - @MsAuditLog(module = OperLogModule.PROJECT_TEMPLATE_MANAGEMENT, type = OperLogConstants.COPY, content = "#msClass.getLogDetails(#targetProjectId)", msClass = IssueTemplateService.class) - public void copyIssueTemplateLog(String targetProjectId) { + @MsAuditLog(module = OperLogModule.PROJECT_TEMPLATE_MANAGEMENT, type = OperLogConstants.COPY, content = "#msClass.getLogDetails(#targetProjectId, #targetProjectName)", msClass = IssueTemplateService.class) + public void copyIssueTemplateLog(String targetProjectId, String targetProjectName) { } - public String getLogDetails(String targetProjectId) { + public String getLogDetails(String targetProjectId, String targetProjectName) { if (targetProjectId == null) { return null; } - OperatingLogDetails details = new OperatingLogDetails(targetProjectId, targetProjectId, "缺陷模板复制", null, null); + OperatingLogDetails details = new OperatingLogDetails(targetProjectId, targetProjectId, targetProjectName, null, null); return JSON.toJSONString(details); } } diff --git a/frontend/src/business/components/project/template/IssueTemplateCopy.vue b/frontend/src/business/components/project/template/IssueTemplateCopy.vue index 35c6b091a2..dfaf5119d7 100644 --- a/frontend/src/business/components/project/template/IssueTemplateCopy.vue +++ b/frontend/src/business/components/project/template/IssueTemplateCopy.vue @@ -6,8 +6,8 @@ {{$t('custom_field.copy_issue_template_model_tips1')}} {{$t('custom_field.copy_issue_template_model_tips2')}} - - + +
{{$t('custom_field.target_project')}} @@ -59,7 +59,6 @@ export default { copyData: null, copyProjects: [], copyModelVal: "0", - preCopyModelVal: "", defaultProps: { children: 'children', label: 'name', @@ -81,8 +80,9 @@ export default { this.initCopyProjects(); }, checkModelChanged(val) { - this.copyModelVal = (val == 'null' || !val) ? this.preCopyModelVal : val; - this.preCopyModelVal = this.copyModelVal; + if (val !== "null") { + this.copyModelVal = this.copyModelVal !== val ? val : this.copyModelVal; + } }, initCopyProjects() { let issueTemplateId = this.copyData.id;