diff --git a/backend/src/main/java/io/metersphere/api/controller/APIScenarioReportController.java b/backend/src/main/java/io/metersphere/api/controller/APIScenarioReportController.java index 94cf31ef14..f5267bbcfd 100644 --- a/backend/src/main/java/io/metersphere/api/controller/APIScenarioReportController.java +++ b/backend/src/main/java/io/metersphere/api/controller/APIScenarioReportController.java @@ -8,10 +8,12 @@ import io.metersphere.api.dto.QueryAPIReportRequest; import io.metersphere.api.dto.automation.APIScenarioReportResult; import io.metersphere.api.dto.automation.ExecuteType; import io.metersphere.api.service.ApiScenarioReportService; +import io.metersphere.commons.constants.OperLogConstants; import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.SessionUtils; +import io.metersphere.log.annotation.MsAuditLog; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.web.bind.annotation.*; @@ -47,11 +49,13 @@ public class APIScenarioReportController { } @PostMapping("/delete") + @MsAuditLog(module = "api_automation_report", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#request.id)", msClass = ApiScenarioReportService.class) public void delete(@RequestBody DeleteAPIReportRequest request) { apiReportService.delete(request); } @PostMapping("/batch/delete") + @MsAuditLog(module = "api_automation_report", type = OperLogConstants.BATCH_DEL, beforeEvent = "#msClass.getLogDetails(#reportRequest.ids)", msClass = ApiScenarioReportService.class) public void deleteAPIReportBatch(@RequestBody APIReportBatchRequest reportRequest) { apiReportService.deleteAPIReportBatch(reportRequest); } diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java index d1695856ef..b4b39c44ef 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -11,11 +11,13 @@ import io.metersphere.base.domain.ApiScenario; import io.metersphere.base.domain.ApiScenarioWithBLOBs; import io.metersphere.base.domain.Schedule; import io.metersphere.commons.constants.ApiRunMode; +import io.metersphere.commons.constants.OperLogConstants; import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.controller.request.ScheduleRequest; +import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest; import io.metersphere.track.request.testplan.FileOperationRequest; import org.apache.shiro.authz.annotation.Logical; @@ -58,7 +60,6 @@ public class ApiAutomationController { } - @PostMapping("/id/all") @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR) public List idAll(@RequestBody ApiScenarioBatchRequest request) { @@ -75,41 +76,49 @@ public class ApiAutomationController { } @PostMapping(value = "/create") + @MsAuditLog(module = "api_automation", type = OperLogConstants.CREATE, title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = ApiAutomationService.class) public ApiScenario create(@RequestPart("request") SaveApiScenarioRequest request, @RequestPart(value = "files") List bodyFiles) { return apiAutomationService.create(request, bodyFiles); } @PostMapping(value = "/update") + @MsAuditLog(module = "api_automation", type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#request.id)", title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = ApiAutomationService.class) public void update(@RequestPart("request") SaveApiScenarioRequest request, @RequestPart(value = "files") List bodyFiles) { apiAutomationService.update(request, bodyFiles); } @GetMapping("/delete/{id}") + @MsAuditLog(module = "api_automation", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#id)", msClass = ApiAutomationService.class) public void delete(@PathVariable String id) { apiAutomationService.delete(id); } @PostMapping("/deleteBatch") + @MsAuditLog(module = "api_automation", type = OperLogConstants.BATCH_DEL, beforeEvent = "#msClass.getLogDetails(#ids)", msClass = ApiAutomationService.class) public void deleteBatch(@RequestBody List ids) { apiAutomationService.deleteBatch(ids); } @PostMapping("/deleteBatchByCondition") + @MsAuditLog(module = "api_automation", type = OperLogConstants.BATCH_DEL, beforeEvent = "#msClass.getLogDetails(#request.ids)", msClass = ApiAutomationService.class) public void deleteBatchByCondition(@RequestBody ApiScenarioBatchRequest request) { apiAutomationService.deleteBatchByCondition(request); } @PostMapping("/removeToGc") + @MsAuditLog(module = "api_automation", type = OperLogConstants.GC, beforeEvent = "#msClass.getLogDetails(#ids)", msClass = ApiAutomationService.class) public void removeToGc(@RequestBody List ids) { apiAutomationService.removeToGc(ids); } @PostMapping("/removeToGcByBatch") + @MsAuditLog(module = "api_automation", type = OperLogConstants.BATCH_GC, beforeEvent = "#msClass.getLogDetails(#request.ids)", msClass = ApiAutomationService.class) public void removeToGcByBatch(@RequestBody ApiScenarioBatchRequest request) { apiAutomationService.removeToGcByBatch(request); } @PostMapping("/reduction") + @MsAuditLog(module = "api_automation", type = OperLogConstants.RESTORE, beforeEvent = "#msClass.getLogDetails(#ids)", msClass = ApiAutomationService.class) public void reduction(@RequestBody List ids) { apiAutomationService.reduction(ids); } @@ -140,12 +149,14 @@ public class ApiAutomationController { } @PostMapping(value = "/run/debug") + @MsAuditLog(module = "api_automation", type = OperLogConstants.DEBUG, title = "#request.scenarioName", project = "#request.projectId") public void runDebug(@RequestPart("request") RunDefinitionRequest request, @RequestPart(value = "files") List bodyFiles) { request.setExecuteType(ExecuteType.Debug.name()); apiAutomationService.debugRun(request, bodyFiles); } @PostMapping(value = "/run") + @MsAuditLog(module = "api_automation", type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.ids)", msClass = ApiAutomationService.class) public String run(@RequestBody RunScenarioRequest request) { request.setExecuteType(ExecuteType.Completed.name()); request.setTriggerMode(ApiRunMode.SCENARIO.name()); @@ -154,6 +165,7 @@ public class ApiAutomationController { } @PostMapping(value = "/run/jenkins") + @MsAuditLog(module = "api_automation", type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.id)", msClass = ApiAutomationService.class) public String runByJenkins(@RequestBody RunScenarioRequest request) { request.setExecuteType(ExecuteType.Saved.name()); request.setTriggerMode(ApiRunMode.API.name()); @@ -162,6 +174,7 @@ public class ApiAutomationController { } @PostMapping(value = "/run/batch") + @MsAuditLog(module = "api_automation", type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.ids)", msClass = ApiAutomationService.class) public String runBatch(@RequestBody RunScenarioRequest request) { request.setExecuteType(ExecuteType.Saved.name()); request.setTriggerMode(ApiRunMode.SCENARIO.name()); @@ -171,12 +184,14 @@ public class ApiAutomationController { @PostMapping("/batch/edit") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) + @MsAuditLog(module = "api_automation", type = OperLogConstants.BATCH_UPDATE, beforeEvent = "#msClass.getLogDetails(#request.ids)", content = "#msClass.getLogDetails(#request.ids)", msClass = ApiAutomationService.class) public void bathEdit(@RequestBody ApiScenarioBatchRequest request) { apiAutomationService.bathEdit(request); } @PostMapping("/batch/update/env") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) + @MsAuditLog(module = "api_automation", type = OperLogConstants.BATCH_UPDATE, beforeEvent = "#msClass.getLogDetails(#request.ids)", content = "#msClass.getLogDetails(#request.ids)", msClass = ApiAutomationService.class) public void batchUpdateEnv(@RequestBody ApiScenarioBatchRequest request) { apiAutomationService.batchUpdateEnv(request); } @@ -228,18 +243,21 @@ public class ApiAutomationController { @PostMapping(value = "/import", consumes = {"multipart/form-data"}) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) + @MsAuditLog(module = "api_automation", type = OperLogConstants.IMPORT, sourceId = "#request.id", title = "#request.name", project = "#request.projectId") public ScenarioImport scenarioImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ApiTestImportRequest request) { return apiAutomationService.scenarioImport(file, request); } @PostMapping(value = "/export") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) + @MsAuditLog(module = "api_automation", type = OperLogConstants.EXPORT, sourceId = "#request.id", title = "#request.name", project = "#request.projectId") public ApiScenrioExportResult export(@RequestBody ApiScenarioBatchRequest request) { return apiAutomationService.export(request); } @PostMapping(value = "/export/jmx") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) + @MsAuditLog(module = "api_automation", type = OperLogConstants.EXPORT, sourceId = "#request.id", title = "#request.name", project = "#request.projectId") public List exportJmx(@RequestBody ApiScenarioBatchRequest request) { return apiAutomationService.exportJmx(request); } diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java index f4a8e88b07..2606fc1f18 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java @@ -112,7 +112,7 @@ public class ApiDefinitionController { @GetMapping("/delete/{id}") @RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR) - @MsAuditLog(module = "api_definition", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#request.ids)", msClass = ApiDefinitionService.class) + @MsAuditLog(module = "api_definition", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#id)", msClass = ApiDefinitionService.class) public void delete(@PathVariable String id) { apiDefinitionService.delete(id); } @@ -171,7 +171,7 @@ public class ApiDefinitionController { } @PostMapping(value = "/run", consumes = {"multipart/form-data"}) - @MsAuditLog(module = "api_definition", type = OperLogConstants.EXECUTE, title = "#request.name", project = "#request.projectId") + @MsAuditLog(module = "api_definition", type = OperLogConstants.EXECUTE, sourceId = "#request.id", title = "#request.name", project = "#request.projectId") public String run(@RequestPart("request") RunDefinitionRequest request, @RequestPart(value = "files") List bodyFiles) { request.setReportId(null); return apiDefinitionService.run(request, bodyFiles); @@ -194,14 +194,14 @@ public class ApiDefinitionController { @PostMapping(value = "/import", consumes = {"multipart/form-data"}) @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) - @MsAuditLog(module = "api_definition", type = OperLogConstants.IMPORT, title = "#request.name", project = "#request.projectId") + @MsAuditLog(module = "api_definition", type = OperLogConstants.IMPORT, sourceId = "#request.id", title = "#request.name", project = "#request.projectId") public ApiDefinitionImport testCaseImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ApiTestImportRequest request) { return apiDefinitionService.apiTestImport(file, request); } @PostMapping(value = "/export/{type}") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) - @MsAuditLog(module = "api_definition", type = OperLogConstants.EXPORT, title = "#request.name", project = "#request.projectId") + @MsAuditLog(module = "api_definition", type = OperLogConstants.EXPORT, sourceId = "#request.id", title = "#request.name", project = "#request.projectId") public ApiExportResult export(@RequestBody ApiBatchRequest request, @PathVariable String type) { return apiDefinitionService.export(request, type); } diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiScenarioModuleController.java b/backend/src/main/java/io/metersphere/api/controller/ApiScenarioModuleController.java index 1b6282c8a5..463814a3f0 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiScenarioModuleController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiScenarioModuleController.java @@ -4,7 +4,9 @@ import io.metersphere.api.dto.automation.ApiScenarioModuleDTO; import io.metersphere.api.dto.automation.DragApiScenarioModuleRequest; import io.metersphere.api.service.ApiScenarioModuleService; import io.metersphere.base.domain.ApiScenarioModule; +import io.metersphere.commons.constants.OperLogConstants; import io.metersphere.commons.constants.RoleConstants; +import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.service.CheckPermissionService; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; @@ -31,12 +33,14 @@ public class ApiScenarioModuleController { @PostMapping("/add") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) + @MsAuditLog(module = "api_automation", type = OperLogConstants.CREATE, title = "#node.name", content = "#msClass.getLogDetails(#node)", msClass = ApiScenarioModuleService.class) public String addNode(@RequestBody ApiScenarioModule node) { return apiScenarioModuleService.addNode(node); } @PostMapping("/edit") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) + @MsAuditLog(module = "api_automation", type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#node)", title = "#node.name", content = "#msClass.getLogDetails(#node)", msClass = ApiScenarioModuleService.class) public int editNode(@RequestBody DragApiScenarioModuleRequest node) { return apiScenarioModuleService.editNode(node); } @@ -49,6 +53,7 @@ public class ApiScenarioModuleController { @PostMapping("/delete") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) + @MsAuditLog(module = "api_automation", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#nodeIds)", msClass = ApiScenarioModuleService.class) public int deleteNode(@RequestBody List nodeIds) { //nodeIds 包含删除节点ID及其所有子节点ID return apiScenarioModuleService.deleteNode(nodeIds); @@ -56,6 +61,7 @@ public class ApiScenarioModuleController { @PostMapping("/drag") @RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR) + @MsAuditLog(module = "api_automation", type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#node)", title = "#node.name", content = "#msClass.getLogDetails(#node)", msClass = ApiScenarioModuleService.class) public void dragNode(@RequestBody DragApiScenarioModuleRequest node) { apiScenarioModuleService.dragNode(node); } diff --git a/backend/src/main/java/io/metersphere/api/dto/ApiTestImportRequest.java b/backend/src/main/java/io/metersphere/api/dto/ApiTestImportRequest.java index 3764e9d0c7..94a518555e 100644 --- a/backend/src/main/java/io/metersphere/api/dto/ApiTestImportRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/ApiTestImportRequest.java @@ -7,6 +7,7 @@ import lombok.Setter; @Getter public class ApiTestImportRequest { private String name; + private String id; private String moduleId; private String modulePath; private String environmentId; diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioBatchRequest.java b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioBatchRequest.java index c1cde85378..877aac6f8b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioBatchRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioBatchRequest.java @@ -12,6 +12,8 @@ import java.util.Map; @Setter public class ApiScenarioBatchRequest extends ApiScenarioWithBLOBs { private List ids; + private String id; + private String name; private String projectId; private String environmentId; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 6e0186ac61..732e925c9c 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -35,6 +35,10 @@ import io.metersphere.i18n.Translator; import io.metersphere.job.sechedule.ApiScenarioTestJob; import io.metersphere.job.sechedule.SwaggerUrlImportJob; import io.metersphere.job.sechedule.TestPlanTestJob; +import io.metersphere.log.utils.ReflexObjectUtil; +import io.metersphere.log.vo.DetailColumn; +import io.metersphere.log.vo.OperatingLogDetails; +import io.metersphere.log.vo.definition.AutomationReference; import io.metersphere.service.ScheduleService; import io.metersphere.service.SystemParameterService; import io.metersphere.track.dto.TestPlanDTO; @@ -314,6 +318,8 @@ public class ApiAutomationService { scenario.setStepTotal(request.getStepTotal()); scenario.setUpdateTime(System.currentTimeMillis()); scenario.setDescription(request.getDescription()); + scenario.setCreateUser(SessionUtils.getUserId()); + scenario.setScenarioDefinition(JSON.toJSONString(request.getScenarioDefinition())); if (StringUtils.isNotEmpty(request.getStatus())) { scenario.setStatus(request.getStatus()); @@ -650,6 +656,7 @@ public class ApiAutomationService { report.setProjectId(projectId); report.setScenarioName(scenarioName); report.setScenarioId(scenarioId); + report.setCreateUser(SessionUtils.getUserId()); return report; } @@ -1513,6 +1520,12 @@ public class ApiAutomationService { } if (apiImport != null) { editScenario(request, apiImport); + if (CollectionUtils.isNotEmpty(apiImport.getData())) { + List names = apiImport.getData().stream().map(ApiScenarioWithBLOBs::getName).collect(Collectors.toList()); + List ids = apiImport.getData().stream().map(ApiScenarioWithBLOBs::getId).collect(Collectors.toList()); + request.setName(String.join(",", names)); + request.setId(JSON.toJSONString(ids)); + } } return apiImport; } @@ -1531,6 +1544,12 @@ public class ApiAutomationService { result.setData(getExportResult(request)); result.setProjectId(request.getProjectId()); result.setVersion(System.getenv("MS_VERSION")); + if (CollectionUtils.isNotEmpty(result.getData())) { + List names = result.getData().stream().map(ApiScenarioWithBLOBs::getName).collect(Collectors.toList()); + request.setName(String.join(",", names)); + List ids = result.getData().stream().map(ApiScenarioWithBLOBs::getId).collect(Collectors.toList()); + request.setId(JSON.toJSONString(ids)); + } return result; } @@ -1547,6 +1566,12 @@ public class ApiAutomationService { } } }); + if (CollectionUtils.isNotEmpty(apiScenarioWithBLOBs)) { + List names = apiScenarioWithBLOBs.stream().map(ApiScenarioWithBLOBs::getName).collect(Collectors.toList()); + request.setName(String.join(",", names)); + List ids = apiScenarioWithBLOBs.stream().map(ApiScenarioWithBLOBs::getId).collect(Collectors.toList()); + request.setId(JSON.toJSONString(ids)); + } return resList; } @@ -1779,4 +1804,26 @@ public class ApiAutomationService { List list = extApiScenarioMapper.listWithIds(request.getIds()); return list; } + + public String getLogDetails(String id) { + ApiScenarioWithBLOBs bloBs = apiScenarioMapper.selectByPrimaryKey(id); + if (bloBs != null) { + List columns = ReflexObjectUtil.getColumns(bloBs, AutomationReference.automationColumns); + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(id), bloBs.getProjectId(), bloBs.getName(), bloBs.getCreateUser(), columns); + return JSON.toJSONString(details); + } + return null; + } + + public String getLogDetails(List ids) { + if (CollectionUtils.isNotEmpty(ids)) { + ApiScenarioExample example = new ApiScenarioExample(); + example.createCriteria().andIdIn(ids); + List definitions = apiScenarioMapper.selectByExample(example); + List names = definitions.stream().map(ApiScenario::getName).collect(Collectors.toList()); + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(ids), definitions.get(0).getProjectId(), String.join(",", names), definitions.get(0).getCreateUser(), new LinkedList<>()); + return JSON.toJSONString(details); + } + return null; + } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index 125e40fd60..fde0990ff1 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -679,6 +679,8 @@ public class ApiDefinitionService { if (CollectionUtils.isNotEmpty(apiImport.getData())) { List names = apiImport.getData().stream().map(ApiDefinitionWithBLOBs::getName).collect(Collectors.toList()); request.setName(String.join(",", names)); + List ids = apiImport.getData().stream().map(ApiDefinitionWithBLOBs::getId).collect(Collectors.toList()); + request.setId(JSON.toJSONString(ids)); } return apiImport; } @@ -989,6 +991,8 @@ public class ApiDefinitionService { if (CollectionUtils.isNotEmpty(((MsApiExportResult) apiExportResult).getData())) { List names = ((MsApiExportResult) apiExportResult).getData().stream().map(ApiDefinitionWithBLOBs::getName).collect(Collectors.toList()); request.setName(String.join(",", names)); + List ids = ((MsApiExportResult) apiExportResult).getData().stream().map(ApiDefinitionWithBLOBs::getId).collect(Collectors.toList()); + request.setId(JSON.toJSONString(ids)); } return apiExportResult; } @@ -1076,7 +1080,7 @@ public class ApiDefinitionService { ApiDefinitionWithBLOBs bloBs = apiDefinitionMapper.selectByPrimaryKey(id); if (bloBs != null) { List columns = ReflexObjectUtil.getColumns(bloBs, DefinitionReference.definitionColumns); - OperatingLogDetails details = new OperatingLogDetails(id, bloBs.getProjectId(), bloBs.getCreateUser(), columns); + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(id), bloBs.getProjectId(), bloBs.getCreateUser(), columns); return JSON.toJSONString(details); } return null; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java index d078a2ec8b..aec351f202 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiModuleService.java @@ -18,7 +18,7 @@ import io.metersphere.i18n.Translator; import io.metersphere.log.utils.ReflexObjectUtil; import io.metersphere.log.vo.DetailColumn; import io.metersphere.log.vo.OperatingLogDetails; -import io.metersphere.log.vo.definition.DefinitionReference; +import io.metersphere.log.vo.definition.ModuleReference; import io.metersphere.service.NodeTreeService; import io.metersphere.service.ProjectService; import io.metersphere.track.service.TestPlanApiCaseService; @@ -422,8 +422,8 @@ public class ApiModuleService extends NodeTreeService { } } if (module != null) { - List columns = ReflexObjectUtil.getColumns(module, DefinitionReference.moduleColumns); - OperatingLogDetails details = new OperatingLogDetails(module.getId(), module.getProjectId(), module.getCreateUser(), columns); + List columns = ReflexObjectUtil.getColumns(module, ModuleReference.moduleColumns); + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(module.getId()), module.getProjectId(), module.getCreateUser(), columns); return JSON.toJSONString(details); } return null; diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java index bdc552bbad..ab74825a30 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioModuleService.java @@ -12,7 +12,12 @@ import io.metersphere.base.mapper.ApiScenarioModuleMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioModuleMapper; import io.metersphere.commons.constants.TestCaseConstants; import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.SessionUtils; import io.metersphere.i18n.Translator; +import io.metersphere.log.utils.ReflexObjectUtil; +import io.metersphere.log.vo.DetailColumn; +import io.metersphere.log.vo.OperatingLogDetails; +import io.metersphere.log.vo.definition.ModuleReference; import io.metersphere.service.NodeTreeService; import io.metersphere.service.ProjectService; import io.metersphere.track.service.TestPlanProjectService; @@ -98,6 +103,7 @@ public class ApiScenarioModuleService extends NodeTreeService ids) { + ApiScenarioModuleExample example = new ApiScenarioModuleExample(); + example.createCriteria().andIdIn(ids); + List nodes = apiScenarioModuleMapper.selectByExample(example); + if (org.apache.commons.collections.CollectionUtils.isNotEmpty(nodes)) { + List names = nodes.stream().map(ApiScenarioModule::getName).collect(Collectors.toList()); + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(ids), nodes.get(0).getProjectId(), String.join(",", names), nodes.get(0).getCreateUser(), new LinkedList<>()); + return JSON.toJSONString(details); + } + return null; + } + + public String getLogDetails(ApiScenarioModule node) { + ApiScenarioModule module = null; + if (StringUtils.isNotEmpty(node.getId())) { + module = apiScenarioModuleMapper.selectByPrimaryKey(node.getId()); + } + if (module == null && StringUtils.isNotEmpty(node.getName())) { + ApiScenarioModuleExample example = new ApiScenarioModuleExample(); + ApiScenarioModuleExample.Criteria criteria = example.createCriteria(); + criteria.andNameEqualTo(node.getName()).andProjectIdEqualTo(node.getProjectId()); + if (StringUtils.isNotEmpty(node.getParentId())) { + criteria.andParentIdEqualTo(node.getParentId()); + } else { + criteria.andParentIdIsNull(); + } + if (StringUtils.isNotEmpty(node.getId())) { + criteria.andIdNotEqualTo(node.getId()); + } + List list = apiScenarioModuleMapper.selectByExample(example); + if (org.apache.commons.collections.CollectionUtils.isNotEmpty(list)) { + module = list.get(0); + } + } + if (module != null) { + List columns = ReflexObjectUtil.getColumns(module, ModuleReference.moduleColumns); + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(module.getId()), module.getProjectId(), module.getCreateUser(), columns); + return JSON.toJSONString(details); + } + return null; + } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index a0d74bf9ed..c1e769f503 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -24,6 +24,10 @@ import io.metersphere.commons.constants.ReportTriggerMode; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; import io.metersphere.i18n.Translator; +import io.metersphere.log.utils.ReflexObjectUtil; +import io.metersphere.log.vo.DetailColumn; +import io.metersphere.log.vo.OperatingLogDetails; +import io.metersphere.log.vo.definition.ModuleReference; import io.metersphere.track.service.TestPlanReportService; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -627,4 +631,26 @@ public class ApiScenarioReportService { return new ArrayList<>(0); } } + + public String getLogDetails(String id) { + ApiScenarioReport bloBs = apiScenarioReportMapper.selectByPrimaryKey(id); + if (bloBs != null) { + List columns = ReflexObjectUtil.getColumns(bloBs, ModuleReference.moduleColumns); + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(id), bloBs.getProjectId(), bloBs.getName(), bloBs.getCreateUser(), columns); + return JSON.toJSONString(details); + } + return null; + } + + public String getLogDetails(List ids) { + if (org.apache.commons.collections.CollectionUtils.isNotEmpty(ids)) { + ApiScenarioReportExample example = new ApiScenarioReportExample(); + example.createCriteria().andIdIn(ids); + List reportList = apiScenarioReportMapper.selectByExample(example); + List names = reportList.stream().map(ApiScenarioReport::getName).collect(Collectors.toList()); + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(ids), reportList.get(0).getProjectId(), String.join(",", names), reportList.get(0).getCreateUser(), new LinkedList<>()); + return JSON.toJSONString(details); + } + return null; + } } diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index 855ba8823a..aa600a20ef 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -710,6 +710,15 @@ public class ApiTestCaseService { return list; } + public String getLogDetails(String id) { + ApiTestCaseWithBLOBs bloBs = apiTestCaseMapper.selectByPrimaryKey(id); + if (bloBs != null) { + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(id), bloBs.getProjectId(), bloBs.getName(), bloBs.getCreateUserId(), new LinkedList<>()); + return JSON.toJSONString(details); + } + return null; + } + public String getLogDetails(List ids) { ApiTestCaseExample example = new ApiTestCaseExample(); ApiTestCaseExample.Criteria criteria = example.createCriteria(); @@ -723,15 +732,6 @@ public class ApiTestCaseService { return null; } - public String getLogDetails(String id) { - ApiTestCaseWithBLOBs bloBs = apiTestCaseMapper.selectByPrimaryKey(id); - if (bloBs != null) { - OperatingLogDetails details = new OperatingLogDetails(id, bloBs.getProjectId(), bloBs.getName(), bloBs.getCreateUserId(), new LinkedList<>()); - return JSON.toJSONString(details); - } - return null; - } - public String getLogDetails(SaveApiTestCaseRequest request) { ApiTestCaseWithBLOBs bloBs = null; if (StringUtils.isNotEmpty(request.getId())) { @@ -748,7 +748,7 @@ public class ApiTestCaseService { } if (bloBs != null) { List columns = ReflexObjectUtil.getColumns(bloBs, DefinitionReference.caseColumns); - OperatingLogDetails details = new OperatingLogDetails(bloBs.getId(), bloBs.getProjectId(), bloBs.getCreateUserId(), columns); + OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(bloBs.getId()), bloBs.getProjectId(), bloBs.getCreateUserId(), columns); return JSON.toJSONString(details); } return null; diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java b/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java index b758cadce1..c09ceab1f2 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java @@ -1,8 +1,9 @@ package io.metersphere.base.domain; -import java.io.Serializable; import lombok.Data; +import java.io.Serializable; + @Data public class ApiScenario implements Serializable { private String id; @@ -47,5 +48,7 @@ public class ApiScenario implements Serializable { private String customNum; + private String createUser; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java index 1450f83426..39c31daeab 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java @@ -1533,6 +1533,76 @@ public class ApiScenarioExample { addCriterion("custom_num not between", value1, value2, "customNum"); return (Criteria) this; } + + public Criteria andCreateUserIsNull() { + addCriterion("create_user is null"); + return (Criteria) this; + } + + public Criteria andCreateUserIsNotNull() { + addCriterion("create_user is not null"); + return (Criteria) this; + } + + public Criteria andCreateUserEqualTo(String value) { + addCriterion("create_user =", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotEqualTo(String value) { + addCriterion("create_user <>", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserGreaterThan(String value) { + addCriterion("create_user >", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserGreaterThanOrEqualTo(String value) { + addCriterion("create_user >=", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserLessThan(String value) { + addCriterion("create_user <", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserLessThanOrEqualTo(String value) { + addCriterion("create_user <=", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserLike(String value) { + addCriterion("create_user like", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotLike(String value) { + addCriterion("create_user not like", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserIn(List values) { + addCriterion("create_user in", values, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotIn(List values) { + addCriterion("create_user not in", values, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserBetween(String value1, String value2) { + addCriterion("create_user between", value1, value2, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotBetween(String value1, String value2) { + addCriterion("create_user not between", value1, value2, "createUser"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModule.java b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModule.java index 82d9cbb204..811f3b80d1 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModule.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModule.java @@ -21,5 +21,7 @@ public class ApiScenarioModule implements Serializable { private Double pos; + private String createUser; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModuleExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModuleExample.java index d0eba1f079..49a21e784e 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModuleExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioModuleExample.java @@ -623,6 +623,76 @@ public class ApiScenarioModuleExample { addCriterion("pos not between", value1, value2, "pos"); return (Criteria) this; } + + public Criteria andCreateUserIsNull() { + addCriterion("create_user is null"); + return (Criteria) this; + } + + public Criteria andCreateUserIsNotNull() { + addCriterion("create_user is not null"); + return (Criteria) this; + } + + public Criteria andCreateUserEqualTo(String value) { + addCriterion("create_user =", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotEqualTo(String value) { + addCriterion("create_user <>", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserGreaterThan(String value) { + addCriterion("create_user >", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserGreaterThanOrEqualTo(String value) { + addCriterion("create_user >=", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserLessThan(String value) { + addCriterion("create_user <", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserLessThanOrEqualTo(String value) { + addCriterion("create_user <=", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserLike(String value) { + addCriterion("create_user like", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotLike(String value) { + addCriterion("create_user not like", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserIn(List values) { + addCriterion("create_user in", values, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotIn(List values) { + addCriterion("create_user not in", values, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserBetween(String value1, String value2) { + addCriterion("create_user between", value1, value2, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotBetween(String value1, String value2) { + addCriterion("create_user not between", value1, value2, "createUser"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioReport.java b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioReport.java index 730b5a0805..e092062ac2 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioReport.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioReport.java @@ -1,8 +1,7 @@ package io.metersphere.base.domain; -import lombok.Data; - import java.io.Serializable; +import lombok.Data; @Data public class ApiScenarioReport implements Serializable { @@ -28,6 +27,8 @@ public class ApiScenarioReport implements Serializable { private String scenarioId; + private String createUser; + private String description; private static final long serialVersionUID = 1L; diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioReportExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioReportExample.java index ab80d4fd01..33e8ba582a 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioReportExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioReportExample.java @@ -853,6 +853,76 @@ public class ApiScenarioReportExample { addCriterion("scenario_id not between", value1, value2, "scenarioId"); return (Criteria) this; } + + public Criteria andCreateUserIsNull() { + addCriterion("create_user is null"); + return (Criteria) this; + } + + public Criteria andCreateUserIsNotNull() { + addCriterion("create_user is not null"); + return (Criteria) this; + } + + public Criteria andCreateUserEqualTo(String value) { + addCriterion("create_user =", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotEqualTo(String value) { + addCriterion("create_user <>", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserGreaterThan(String value) { + addCriterion("create_user >", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserGreaterThanOrEqualTo(String value) { + addCriterion("create_user >=", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserLessThan(String value) { + addCriterion("create_user <", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserLessThanOrEqualTo(String value) { + addCriterion("create_user <=", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserLike(String value) { + addCriterion("create_user like", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotLike(String value) { + addCriterion("create_user not like", value, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserIn(List values) { + addCriterion("create_user in", values, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotIn(List values) { + addCriterion("create_user not in", values, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserBetween(String value1, String value2) { + addCriterion("create_user between", value1, value2, "createUser"); + return (Criteria) this; + } + + public Criteria andCreateUserNotBetween(String value1, String value2) { + addCriterion("create_user not between", value1, value2, "createUser"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml index 2770d13b74..528ff2f49d 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml @@ -23,6 +23,7 @@ + @@ -89,7 +90,7 @@ id, project_id, tags, user_id, api_scenario_module_id, module_path, `name`, `level`, `status`, principal, step_total, follow_people, schedule, create_time, update_time, - pass_rate, last_result, report_id, num, original_state, custom_num + pass_rate, last_result, report_id, num, original_state, custom_num, create_user scenario_definition, description @@ -150,7 +151,7 @@ schedule, create_time, update_time, pass_rate, last_result, report_id, num, original_state, custom_num, - scenario_definition, description + create_user, scenario_definition, description ) values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{tags,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{apiScenarioModuleId,jdbcType=VARCHAR}, #{modulePath,jdbcType=VARCHAR}, @@ -159,7 +160,7 @@ #{schedule,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{passRate,jdbcType=VARCHAR}, #{lastResult,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, #{num,jdbcType=INTEGER}, #{originalState,jdbcType=VARCHAR}, #{customNum,jdbcType=VARCHAR}, - #{scenarioDefinition,jdbcType=LONGVARCHAR}, #{description,jdbcType=LONGVARCHAR} + #{createUser,jdbcType=VARCHAR}, #{scenarioDefinition,jdbcType=LONGVARCHAR}, #{description,jdbcType=LONGVARCHAR} ) @@ -228,6 +229,9 @@ custom_num, + + create_user, + scenario_definition, @@ -299,6 +303,9 @@ #{customNum,jdbcType=VARCHAR}, + + #{createUser,jdbcType=VARCHAR}, + #{scenarioDefinition,jdbcType=LONGVARCHAR}, @@ -379,6 +386,9 @@ custom_num = #{record.customNum,jdbcType=VARCHAR}, + + create_user = #{record.createUser,jdbcType=VARCHAR}, + scenario_definition = #{record.scenarioDefinition,jdbcType=LONGVARCHAR}, @@ -413,6 +423,7 @@ num = #{record.num,jdbcType=INTEGER}, original_state = #{record.originalState,jdbcType=VARCHAR}, custom_num = #{record.customNum,jdbcType=VARCHAR}, + create_user = #{record.createUser,jdbcType=VARCHAR}, scenario_definition = #{record.scenarioDefinition,jdbcType=LONGVARCHAR}, description = #{record.description,jdbcType=LONGVARCHAR} @@ -441,7 +452,8 @@ report_id = #{record.reportId,jdbcType=VARCHAR}, num = #{record.num,jdbcType=INTEGER}, original_state = #{record.originalState,jdbcType=VARCHAR}, - custom_num = #{record.customNum,jdbcType=VARCHAR} + custom_num = #{record.customNum,jdbcType=VARCHAR}, + create_user = #{record.createUser,jdbcType=VARCHAR} @@ -509,6 +521,9 @@ custom_num = #{customNum,jdbcType=VARCHAR}, + + create_user = #{createUser,jdbcType=VARCHAR}, + scenario_definition = #{scenarioDefinition,jdbcType=LONGVARCHAR}, @@ -540,6 +555,7 @@ num = #{num,jdbcType=INTEGER}, original_state = #{originalState,jdbcType=VARCHAR}, custom_num = #{customNum,jdbcType=VARCHAR}, + create_user = #{createUser,jdbcType=VARCHAR}, scenario_definition = #{scenarioDefinition,jdbcType=LONGVARCHAR}, description = #{description,jdbcType=LONGVARCHAR} where id = #{id,jdbcType=VARCHAR} @@ -565,7 +581,8 @@ report_id = #{reportId,jdbcType=VARCHAR}, num = #{num,jdbcType=INTEGER}, original_state = #{originalState,jdbcType=VARCHAR}, - custom_num = #{customNum,jdbcType=VARCHAR} + custom_num = #{customNum,jdbcType=VARCHAR}, + create_user = #{createUser,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioModuleMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioModuleMapper.xml index 0bfb36a80b..3293573bbc 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioModuleMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioModuleMapper.xml @@ -10,6 +10,7 @@ + @@ -70,7 +71,7 @@ - id, project_id, `name`, parent_id, `level`, create_time, update_time, pos + id, project_id, `name`, parent_id, `level`, create_time, update_time, pos, create_user @@ -198,6 +207,9 @@ pos = #{record.pos,jdbcType=DOUBLE}, + + create_user = #{record.createUser,jdbcType=VARCHAR}, + @@ -212,7 +224,8 @@ `level` = #{record.level,jdbcType=INTEGER}, create_time = #{record.createTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT}, - pos = #{record.pos,jdbcType=DOUBLE} + pos = #{record.pos,jdbcType=DOUBLE}, + create_user = #{record.createUser,jdbcType=VARCHAR} @@ -241,6 +254,9 @@ pos = #{pos,jdbcType=DOUBLE}, + + create_user = #{createUser,jdbcType=VARCHAR}, + where id = #{id,jdbcType=VARCHAR} @@ -252,7 +268,8 @@ `level` = #{level,jdbcType=INTEGER}, create_time = #{createTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT}, - pos = #{pos,jdbcType=DOUBLE} + pos = #{pos,jdbcType=DOUBLE}, + create_user = #{createUser,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioReportMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioReportMapper.xml index d7642fe133..40b9f10ee1 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioReportMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioReportMapper.xml @@ -13,6 +13,7 @@ + @@ -77,7 +78,7 @@ id, project_id, `name`, create_time, update_time, `status`, user_id, trigger_mode, - execute_type, scenario_name, scenario_id + execute_type, scenario_name, scenario_id, create_user description @@ -134,13 +135,13 @@ insert into api_scenario_report (id, project_id, `name`, create_time, update_time, `status`, user_id, trigger_mode, execute_type, - scenario_name, scenario_id, description - ) + scenario_name, scenario_id, create_user, + description) values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{status,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{triggerMode,jdbcType=VARCHAR}, #{executeType,jdbcType=VARCHAR}, - #{scenarioName,jdbcType=VARCHAR}, #{scenarioId,jdbcType=VARCHAR}, #{description,jdbcType=LONGVARCHAR} - ) + #{scenarioName,jdbcType=VARCHAR}, #{scenarioId,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR}, + #{description,jdbcType=LONGVARCHAR}) insert into api_scenario_report @@ -178,6 +179,9 @@ scenario_id, + + create_user, + description, @@ -216,6 +220,9 @@ #{scenarioId,jdbcType=VARCHAR}, + + #{createUser,jdbcType=VARCHAR}, + #{description,jdbcType=LONGVARCHAR}, @@ -263,6 +270,9 @@ scenario_id = #{record.scenarioId,jdbcType=VARCHAR}, + + create_user = #{record.createUser,jdbcType=VARCHAR}, + description = #{record.description,jdbcType=LONGVARCHAR}, @@ -284,6 +294,7 @@ execute_type = #{record.executeType,jdbcType=VARCHAR}, scenario_name = #{record.scenarioName,jdbcType=VARCHAR}, scenario_id = #{record.scenarioId,jdbcType=VARCHAR}, + create_user = #{record.createUser,jdbcType=VARCHAR}, description = #{record.description,jdbcType=LONGVARCHAR} @@ -301,7 +312,8 @@ trigger_mode = #{record.triggerMode,jdbcType=VARCHAR}, execute_type = #{record.executeType,jdbcType=VARCHAR}, scenario_name = #{record.scenarioName,jdbcType=VARCHAR}, - scenario_id = #{record.scenarioId,jdbcType=VARCHAR} + scenario_id = #{record.scenarioId,jdbcType=VARCHAR}, + create_user = #{record.createUser,jdbcType=VARCHAR} @@ -339,6 +351,9 @@ scenario_id = #{scenarioId,jdbcType=VARCHAR}, + + create_user = #{createUser,jdbcType=VARCHAR}, + description = #{description,jdbcType=LONGVARCHAR}, @@ -357,6 +372,7 @@ execute_type = #{executeType,jdbcType=VARCHAR}, scenario_name = #{scenarioName,jdbcType=VARCHAR}, scenario_id = #{scenarioId,jdbcType=VARCHAR}, + create_user = #{createUser,jdbcType=VARCHAR}, description = #{description,jdbcType=LONGVARCHAR} where id = #{id,jdbcType=VARCHAR} @@ -371,7 +387,8 @@ trigger_mode = #{triggerMode,jdbcType=VARCHAR}, execute_type = #{executeType,jdbcType=VARCHAR}, scenario_name = #{scenarioName,jdbcType=VARCHAR}, - scenario_id = #{scenarioId,jdbcType=VARCHAR} + scenario_id = #{scenarioId,jdbcType=VARCHAR}, + create_user = #{createUser,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/log/annotation/MsAuditLog.java b/backend/src/main/java/io/metersphere/log/annotation/MsAuditLog.java index 974f028d5e..143f46762f 100644 --- a/backend/src/main/java/io/metersphere/log/annotation/MsAuditLog.java +++ b/backend/src/main/java/io/metersphere/log/annotation/MsAuditLog.java @@ -46,6 +46,12 @@ public @interface MsAuditLog { */ String title() default ""; + /** + * 资源ID + */ + String sourceId() default ""; + + /** * 操作内容 * diff --git a/backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java b/backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java index 019e6d3143..410872db43 100644 --- a/backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java +++ b/backend/src/main/java/io/metersphere/log/aspect/MsLogAspect.java @@ -160,6 +160,17 @@ public class MsLogAspect { msOperLog.setOperTitle(title); } } + // 资源ID + if (StringUtils.isNotEmpty(msLog.sourceId())) { + try { + String sourceId = msLog.sourceId(); + Expression titleExp = parser.parseExpression(sourceId); + sourceId = titleExp.getValue(context, String.class); + msOperLog.setSourceId(sourceId); + } catch (Exception e) { + } + } + // 操作内容 if (StringUtils.isNotEmpty(msLog.content())) { Expression expression = parser.parseExpression(msLog.content()); @@ -221,7 +232,6 @@ public class MsLogAspect { String path = request.getServletPath(); msOperLog.setOperPath(path); - operatingLogService.create(msOperLog); } } catch (Exception e) { diff --git a/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java b/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java index 9d3c06b42c..83f5b345b5 100644 --- a/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java +++ b/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java @@ -101,25 +101,25 @@ public class ReflexObjectUtil { StringBuilder oldValue = new StringBuilder(); for (Diff item : after) { if (item.getOperation().equals(Operation.ADD)) { - addBuff.append(item.getPath() + ":" + item.getValue()).append("/n"); + addBuff.append(item.getPath() + ":" + item.getValue()).append("\n"); } if (item.getOperation().equals(Operation.REMOVE)) { - removeBuff.append(item.getPath() + ":" + item.getValue()).append("/n"); + removeBuff.append(item.getPath() + ":" + item.getValue()).append("\n"); } if (item.getOperation().equals(Operation.REPLACE)) { - repBuff.append(item.getPath() + ":" + item.getValue()).append("/n"); - oldValue.append(item.getPath() + ":" + item.getSrcValue()).append("/n"); + repBuff.append(item.getPath() + ":" + item.getValue()).append("\n"); + oldValue.append(item.getPath() + ":" + item.getSrcValue()).append("\n"); } } StringBuilder newValue = new StringBuilder(); if (addBuff != null && addBuff.toString().length() > 0) { - newValue.append("添加:").append(addBuff).append("/n"); + newValue.append("添加:").append(addBuff).append("\n"); } if (removeBuff != null && removeBuff.toString().length() > 0) { - newValue.append("移除:").append(removeBuff).append("/n"); + newValue.append("移除:").append(removeBuff).append("\n"); } if (repBuff != null && repBuff.toString().length() > 0) { - newValue.append("修改:").append(repBuff).append("/n"); + newValue.append("修改:").append(repBuff).append("\n"); } DetailColumn column = new DetailColumn(); BeanUtils.copyBean(column, originalColumns.get(i)); diff --git a/backend/src/main/java/io/metersphere/log/vo/definition/AutomationReference.java b/backend/src/main/java/io/metersphere/log/vo/definition/AutomationReference.java new file mode 100644 index 0000000000..13dced9514 --- /dev/null +++ b/backend/src/main/java/io/metersphere/log/vo/definition/AutomationReference.java @@ -0,0 +1,27 @@ +package io.metersphere.log.vo.definition; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class AutomationReference { + public static Map automationColumns = new LinkedHashMap<>(); + + static { + automationColumns.clear(); + automationColumns.put("name", "场景名称"); + automationColumns.put("createUser", "创建人"); + automationColumns.put("method", "请求类型"); + automationColumns.put("modulePath", "模块"); + automationColumns.put("level", "场景级别"); + automationColumns.put("status", "场景状态"); + automationColumns.put("principal", "责任人"); + automationColumns.put("stepTotal", "步骤数"); + automationColumns.put("passRate", "通过率"); + automationColumns.put("lastResult", "最后执行结果"); + automationColumns.put("tags", "标签"); + automationColumns.put("scenarioDefinition", "场景步骤"); + automationColumns.put("description", "描述"); + // 需要深度对比的字段,可以支持多个req1,req2 + automationColumns.put("ms-dff-col", "scenarioDefinition"); + } +} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/log/vo/definition/DefinitionReference.java b/backend/src/main/java/io/metersphere/log/vo/definition/DefinitionReference.java index 15ba1a5e5e..41666c2db7 100644 --- a/backend/src/main/java/io/metersphere/log/vo/definition/DefinitionReference.java +++ b/backend/src/main/java/io/metersphere/log/vo/definition/DefinitionReference.java @@ -5,12 +5,10 @@ import java.util.Map; public class DefinitionReference { public static Map definitionColumns = new LinkedHashMap<>(); - public static Map moduleColumns = new LinkedHashMap<>(); public static Map caseColumns = new LinkedHashMap<>(); static { definitionColumns.clear(); - moduleColumns.clear(); caseColumns.clear(); definitionColumns.put("name", "接口名称"); definitionColumns.put("createUser", "创建人"); @@ -27,11 +25,6 @@ public class DefinitionReference { // 需要深度对比的字段,可以支持多个req1,req2 definitionColumns.put("ms-dff-col", "request,response"); - // 模块列数据 - moduleColumns.put("name", "模块名称"); - moduleColumns.put("createUser", "创建人"); - moduleColumns.put("protocol", "协议"); - moduleColumns.put("level", "模块级别"); // 用例列数据 caseColumns.put("name", "用例名称"); caseColumns.put("priority", "用例级别"); diff --git a/backend/src/main/java/io/metersphere/log/vo/definition/ModuleReference.java b/backend/src/main/java/io/metersphere/log/vo/definition/ModuleReference.java new file mode 100644 index 0000000000..947d9c62c9 --- /dev/null +++ b/backend/src/main/java/io/metersphere/log/vo/definition/ModuleReference.java @@ -0,0 +1,18 @@ +package io.metersphere.log.vo.definition; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class ModuleReference { + public static Map moduleColumns = new LinkedHashMap<>(); + + static { + moduleColumns.clear(); + // 模块列数据 + moduleColumns.put("name", "模块名称"); + moduleColumns.put("createUser", "创建人"); + moduleColumns.put("protocol", "协议"); + moduleColumns.put("level", "模块级别"); + + } +} diff --git a/backend/src/main/resources/db/migration/V83__v1.10_release.sql b/backend/src/main/resources/db/migration/V83__v1.10_release.sql index eb1b355c0e..5c12c5bff4 100644 --- a/backend/src/main/resources/db/migration/V83__v1.10_release.sql +++ b/backend/src/main/resources/db/migration/V83__v1.10_release.sql @@ -54,4 +54,7 @@ CREATE TABLE `operating_log` ( -- add all table create_user ALTER TABLE api_definition ADD create_user VARCHAR(100) NULL; -ALTER TABLE api_module ADD create_user VARCHAR(100) NULL; \ No newline at end of file +ALTER TABLE api_module ADD create_user VARCHAR(100) NULL; +ALTER TABLE api_scenario ADD create_user VARCHAR(100) NULL; +ALTER TABLE api_scenario_module ADD create_user VARCHAR(100) NULL; +ALTER TABLE api_scenario_report ADD create_user VARCHAR(100) NULL; diff --git a/backend/src/main/resources/i18n/messages_en_US.properties b/backend/src/main/resources/i18n/messages_en_US.properties index d172fe09f7..1615482b73 100644 --- a/backend/src/main/resources/i18n/messages_en_US.properties +++ b/backend/src/main/resources/i18n/messages_en_US.properties @@ -221,4 +221,13 @@ custom_field_already=A feild already exists under this workspace: template_already=A template already exists under this workspace: expect_name_exists=Expect name is exists ssl_password_error=The authentication password is wrong, please re-enter the password -ssl_file_error=Failed to load the certification file, please check the certification file \ No newline at end of file +ssl_file_error=Failed to load the certification file, please check the certification file +#log +api_definition=Api definition +api_automation=Api automation +api_automation_report=Test Report +track_test_case=Test case +track_test_case_review=Case review +track_test_plan=Test plan +track_bug=Defect management +track_report=Report \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_zh_CN.properties b/backend/src/main/resources/i18n/messages_zh_CN.properties index 03b2284b1d..6480788c5f 100644 --- a/backend/src/main/resources/i18n/messages_zh_CN.properties +++ b/backend/src/main/resources/i18n/messages_zh_CN.properties @@ -222,4 +222,11 @@ expect_name_exists=预期名称已存在 ssl_password_error=认证密码错误,请重新输入密码 ssl_file_error=认证文件加载失败,请检查认证文件 #log -api_definition=接口定义 \ No newline at end of file +api_definition=接口定义 +api_automation=接口自动化 +api_automation_report=测试报告 +track_test_case=测试用例 +track_test_case_review=用例评审 +track_test_plan=测试计划 +track_bug=缺陷管理 +track_report=报告 \ No newline at end of file diff --git a/backend/src/main/resources/i18n/messages_zh_TW.properties b/backend/src/main/resources/i18n/messages_zh_TW.properties index 5ab63a2eec..ffef048088 100644 --- a/backend/src/main/resources/i18n/messages_zh_TW.properties +++ b/backend/src/main/resources/i18n/messages_zh_TW.properties @@ -222,4 +222,13 @@ custom_field_already=工作空間下已存在該字段: template_already=工作空間下已存在該模板: expect_name_exists=預期名稱已存在 ssl_password_error=認證密碼錯誤,請重新輸入密碼 -ssl_file_error=認證文件加載失敗,請檢查認證文件 \ No newline at end of file +ssl_file_error=認證文件加載失敗,請檢查認證文件 +#log +api_definition=接口定義 +api_automation=接口自動化 +api_automation_report=測試報告 +track_test_case=測試用例 +track_test_case_review=用例評審 +track_test_plan=測試計劃 +track_bug=缺陷管理 +track_report=報告 \ No newline at end of file diff --git a/frontend/src/business/components/settings/operatinglog/LogDetail.vue b/frontend/src/business/components/settings/operatinglog/LogDetail.vue index 118a25a7fd..3a16151a36 100644 --- a/frontend/src/business/components/settings/operatinglog/LogDetail.vue +++ b/frontend/src/business/components/settings/operatinglog/LogDetail.vue @@ -13,7 +13,7 @@

{{ this.$t('report.test_log_details') }}

-
+
@@ -22,7 +22,7 @@
-
+
{{detail.operTitle}} {{getType(detail.operType)}} {{$t('api_test.home_page.detail_card.success')}}