diff --git a/backend/src/main/java/io/metersphere/base/domain/CustomField.java b/backend/src/main/java/io/metersphere/base/domain/CustomField.java index 9df3ccd301..cd3e94a75d 100644 --- a/backend/src/main/java/io/metersphere/base/domain/CustomField.java +++ b/backend/src/main/java/io/metersphere/base/domain/CustomField.java @@ -30,5 +30,7 @@ public class CustomField implements Serializable { private String options; + private String defaultValue; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/controller/IssueTemplateController.java b/backend/src/main/java/io/metersphere/controller/IssueTemplateController.java index 5e170dedb8..04ece7cce2 100644 --- a/backend/src/main/java/io/metersphere/controller/IssueTemplateController.java +++ b/backend/src/main/java/io/metersphere/controller/IssueTemplateController.java @@ -24,7 +24,7 @@ public class IssueTemplateController { private IssueTemplateService issueTemplateService; @PostMapping("/add") - @MsAuditLog(module = "workspace_template_settings_issue", type = OperLogConstants.CREATE, content = "#msClass.getLogDetails(#request.id)", msClass = IssueTemplateService.class) + @MsAuditLog(module = "workspace_template_settings_issue", type = OperLogConstants.CREATE, content = "#msClass.getLogDetails(#request)", msClass = IssueTemplateService.class) public void add(@RequestBody UpdateIssueTemplateRequest request) { issueTemplateService.add(request); } @@ -42,7 +42,7 @@ public class IssueTemplateController { } @PostMapping("/update") - @MsAuditLog(module = "workspace_template_settings_issue", type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#request.id)", content = "#msClass.getLogDetails(#request.id)", msClass = IssueTemplateService.class) + @MsAuditLog(module = "workspace_template_settings_issue", type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#request.id)", content = "#msClass.getLogDetails(#request)", msClass = IssueTemplateService.class) public void update(@RequestBody UpdateIssueTemplateRequest request) { issueTemplateService.update(request); } diff --git a/backend/src/main/java/io/metersphere/log/vo/system/SystemReference.java b/backend/src/main/java/io/metersphere/log/vo/system/SystemReference.java index b78a4b6040..0344a2c305 100644 --- a/backend/src/main/java/io/metersphere/log/vo/system/SystemReference.java +++ b/backend/src/main/java/io/metersphere/log/vo/system/SystemReference.java @@ -101,6 +101,11 @@ public class SystemReference { issueFieldColumns.put("title", "标题"); issueFieldColumns.put("content", "缺陷内容"); issueFieldColumns.put("description", "描述"); + issueFieldColumns.put("scene", "使用场景"); + issueFieldColumns.put("type", "属性类型"); + issueFieldColumns.put("system", "系统字段"); + issueFieldColumns.put("remark", "字段备注"); + issueFieldColumns.put("defaultValue", "字段值"); projectColumns.put("name", "名称"); projectColumns.put("description", "描述"); diff --git a/backend/src/main/java/io/metersphere/service/IssueTemplateService.java b/backend/src/main/java/io/metersphere/service/IssueTemplateService.java index 6d630d51af..0120d0e9e3 100644 --- a/backend/src/main/java/io/metersphere/service/IssueTemplateService.java +++ b/backend/src/main/java/io/metersphere/service/IssueTemplateService.java @@ -2,6 +2,8 @@ package io.metersphere.service; import com.alibaba.fastjson.JSON; import io.metersphere.base.domain.*; +import io.metersphere.base.mapper.CustomFieldMapper; +import io.metersphere.base.mapper.CustomFieldTemplateMapper; import io.metersphere.base.mapper.IssueTemplateMapper; import io.metersphere.base.mapper.ext.ExtIssueTemplateMapper; import io.metersphere.commons.constants.TemplateConstants; @@ -25,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import java.util.UUID; @@ -47,6 +50,12 @@ public class IssueTemplateService extends TemplateBaseService { @Resource ProjectService projectService; + @Resource + CustomFieldMapper customFieldMapper; + + @Resource + CustomFieldTemplateMapper customFieldTemplateMapper; + public String add(UpdateIssueTemplateRequest request) { checkExist(request); IssueTemplate template = new IssueTemplate(); @@ -223,12 +232,39 @@ public class IssueTemplateService extends TemplateBaseService { } public String getLogDetails(String id) { + List columns = new LinkedList<>(); IssueTemplate templateWithBLOBs = issueTemplateMapper.selectByPrimaryKey(id); - if (templateWithBLOBs != null) { - List columns = ReflexObjectUtil.getColumns(templateWithBLOBs, SystemReference.issueFieldColumns); - OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(templateWithBLOBs.getId()), null, templateWithBLOBs.getName(), templateWithBLOBs.getCreateUser(), columns); - return JSON.toJSONString(details); + if(templateWithBLOBs==null){ + return null; } - return null; + CustomFieldTemplateExample example = new CustomFieldTemplateExample(); + example.createCriteria().andTemplateIdEqualTo(templateWithBLOBs.getId()); + example.createCriteria().andSceneEqualTo("ISSUE"); + List customFieldTemplates = customFieldTemplateMapper.selectByExample(example); + return getCustomFieldColums(columns, templateWithBLOBs, customFieldTemplates); + + } + + public String getLogDetails(UpdateIssueTemplateRequest request) { + List columns = new LinkedList<>(); + IssueTemplate templateWithBLOBs = issueTemplateMapper.selectByPrimaryKey(request.getId()); + if(templateWithBLOBs==null){ + return null; + } + List customFields = request.getCustomFields(); + return getCustomFieldColums(columns, templateWithBLOBs, customFields); + } + + private String getCustomFieldColums(List columns, IssueTemplate templateWithBLOBs, List customFields) { + for (CustomFieldTemplate customFieldTemplate : customFields) { + CustomField customField = customFieldMapper.selectByPrimaryKey(customFieldTemplate.getFieldId()); + customField.setDefaultValue(customFieldTemplate.getDefaultValue()); + List columnsField = ReflexObjectUtil.getColumns(customField, SystemReference.issueFieldColumns); + columns.addAll(columnsField); + } + List columnIssues = ReflexObjectUtil.getColumns(templateWithBLOBs, SystemReference.issueFieldColumns); + columns.addAll(columnIssues); + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(templateWithBLOBs.getId()), null, templateWithBLOBs.getName(), templateWithBLOBs.getCreateUser(), columns); + return JSON.toJSONString(details); } }