feat(性能测试): 完成性能测试操作日志

This commit is contained in:
fit2-zhao 2021-05-19 11:41:42 +08:00 committed by fit2-zhao
parent 112827ce04
commit 316e6fb775
17 changed files with 195 additions and 19 deletions

View File

@ -1,8 +1,9 @@
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
import java.io.Serializable;
@Data
public class LoadTest implements Serializable {
private String id;
@ -25,5 +26,7 @@ public class LoadTest implements Serializable {
private Integer num;
private String createUser;
private static final long serialVersionUID = 1L;
}

View File

@ -773,6 +773,76 @@ public class LoadTestExample {
addCriterion("num not between", value1, value2, "num");
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<String> values) {
addCriterion("create_user in", values, "createUser");
return (Criteria) this;
}
public Criteria andCreateUserNotIn(List<String> 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 {

View File

@ -1,11 +1,10 @@
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import java.io.Serializable;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)

View File

@ -12,6 +12,7 @@
<result column="test_resource_pool_id" jdbcType="VARCHAR" property="testResourcePoolId" />
<result column="user_id" jdbcType="VARCHAR" property="userId" />
<result column="num" jdbcType="INTEGER" property="num" />
<result column="create_user" jdbcType="VARCHAR" property="createUser" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.LoadTestWithBLOBs">
<result column="load_configuration" jdbcType="LONGVARCHAR" property="loadConfiguration" />
@ -77,7 +78,7 @@
</sql>
<sql id="Base_Column_List">
id, project_id, `name`, description, create_time, update_time, `status`, test_resource_pool_id,
user_id, num
user_id, num, create_user
</sql>
<sql id="Blob_Column_List">
load_configuration, advanced_configuration
@ -134,13 +135,13 @@
insert into load_test (id, project_id, `name`,
description, create_time, update_time,
`status`, test_resource_pool_id, user_id,
num, load_configuration, advanced_configuration
)
num, create_user, load_configuration,
advanced_configuration)
values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{description,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT},
#{status,jdbcType=VARCHAR}, #{testResourcePoolId,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR},
#{num,jdbcType=INTEGER}, #{loadConfiguration,jdbcType=LONGVARCHAR}, #{advancedConfiguration,jdbcType=LONGVARCHAR}
)
#{num,jdbcType=INTEGER}, #{createUser,jdbcType=VARCHAR}, #{loadConfiguration,jdbcType=LONGVARCHAR},
#{advancedConfiguration,jdbcType=LONGVARCHAR})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.LoadTestWithBLOBs">
insert into load_test
@ -175,6 +176,9 @@
<if test="num != null">
num,
</if>
<if test="createUser != null">
create_user,
</if>
<if test="loadConfiguration != null">
load_configuration,
</if>
@ -213,6 +217,9 @@
<if test="num != null">
#{num,jdbcType=INTEGER},
</if>
<if test="createUser != null">
#{createUser,jdbcType=VARCHAR},
</if>
<if test="loadConfiguration != null">
#{loadConfiguration,jdbcType=LONGVARCHAR},
</if>
@ -260,6 +267,9 @@
<if test="record.num != null">
num = #{record.num,jdbcType=INTEGER},
</if>
<if test="record.createUser != null">
create_user = #{record.createUser,jdbcType=VARCHAR},
</if>
<if test="record.loadConfiguration != null">
load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR},
</if>
@ -283,6 +293,7 @@
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
user_id = #{record.userId,jdbcType=VARCHAR},
num = #{record.num,jdbcType=INTEGER},
create_user = #{record.createUser,jdbcType=VARCHAR},
load_configuration = #{record.loadConfiguration,jdbcType=LONGVARCHAR},
advanced_configuration = #{record.advancedConfiguration,jdbcType=LONGVARCHAR}
<if test="_parameter != null">
@ -300,7 +311,8 @@
`status` = #{record.status,jdbcType=VARCHAR},
test_resource_pool_id = #{record.testResourcePoolId,jdbcType=VARCHAR},
user_id = #{record.userId,jdbcType=VARCHAR},
num = #{record.num,jdbcType=INTEGER}
num = #{record.num,jdbcType=INTEGER},
create_user = #{record.createUser,jdbcType=VARCHAR}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
@ -335,6 +347,9 @@
<if test="num != null">
num = #{num,jdbcType=INTEGER},
</if>
<if test="createUser != null">
create_user = #{createUser,jdbcType=VARCHAR},
</if>
<if test="loadConfiguration != null">
load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR},
</if>
@ -355,6 +370,7 @@
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
user_id = #{userId,jdbcType=VARCHAR},
num = #{num,jdbcType=INTEGER},
create_user = #{createUser,jdbcType=VARCHAR},
load_configuration = #{loadConfiguration,jdbcType=LONGVARCHAR},
advanced_configuration = #{advancedConfiguration,jdbcType=LONGVARCHAR}
where id = #{id,jdbcType=VARCHAR}
@ -369,7 +385,8 @@
`status` = #{status,jdbcType=VARCHAR},
test_resource_pool_id = #{testResourcePoolId,jdbcType=VARCHAR},
user_id = #{userId,jdbcType=VARCHAR},
num = #{num,jdbcType=INTEGER}
num = #{num,jdbcType=INTEGER},
create_user = #{createUser,jdbcType=VARCHAR}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -0,0 +1,21 @@
package io.metersphere.log.vo.performance;
import java.util.LinkedHashMap;
import java.util.Map;
public class PerformanceReference {
public static Map<String, String> performanceColumns = new LinkedHashMap<>();
public static Map<String, String> reportColumns = new LinkedHashMap<>();
static {
performanceColumns.clear();
reportColumns.clear();
performanceColumns.put("name", "用例名称");
performanceColumns.put("status", "状态");
performanceColumns.put("loadConfiguration", "压力配置");
performanceColumns.put("advancedConfiguration", "高级配置");
performanceColumns.put("description", "描述");
reportColumns.put("name","报告名称");
}
}

View File

@ -4,11 +4,13 @@ import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.LoadTestReportLog;
import io.metersphere.base.domain.LoadTestReportWithBLOBs;
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.dto.LogDetailDTO;
import io.metersphere.dto.ReportDTO;
import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.performance.base.*;
import io.metersphere.performance.controller.request.DeleteReportRequest;
import io.metersphere.performance.controller.request.RenameReportRequest;
@ -46,6 +48,7 @@ public class PerformanceReportController {
@PostMapping("/delete/{reportId}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
@MsAuditLog(module = "performance_test_report", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#reportId)", msClass = PerformanceReportService.class)
public void deleteReport(@PathVariable String reportId) {
performanceReportService.deleteReport(reportId);
}
@ -129,6 +132,7 @@ public class PerformanceReportController {
@PostMapping("/batch/delete")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER}, logical = Logical.OR)
@MsAuditLog(module = "performance_test_report", type = OperLogConstants.BATCH_DEL, beforeEvent = "#msClass.getLogDetails(#reportRequest.ids)", msClass = PerformanceReportService.class)
public void deleteReportBatch(@RequestBody DeleteReportRequest reportRequest) {
performanceReportService.deleteReportBatch(reportRequest);
}
@ -144,6 +148,7 @@ public class PerformanceReportController {
}
@PostMapping("rename")
@MsAuditLog(module = "performance_test_report", type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#request.id)", title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = PerformanceReportService.class)
public void renameReport(@RequestBody RenameReportRequest request) {
performanceReportService.renameReport(request);
}

View File

@ -5,6 +5,7 @@ import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.FileMetadata;
import io.metersphere.base.domain.LoadTest;
import io.metersphere.base.domain.Schedule;
import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
@ -14,6 +15,7 @@ import io.metersphere.controller.request.ScheduleRequest;
import io.metersphere.dto.DashboardTestDTO;
import io.metersphere.dto.LoadTestDTO;
import io.metersphere.dto.ScheduleDao;
import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.performance.dto.LoadTestExportJmx;
import io.metersphere.performance.request.*;
import io.metersphere.performance.service.PerformanceTestService;
@ -30,6 +32,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;
@RestController
@RequestMapping(value = "performance")
@ -68,15 +71,18 @@ public class PerformanceTestController {
}
@PostMapping(value = "/save", consumes = {"multipart/form-data"})
@MsAuditLog(module = "performance_test", type = OperLogConstants.CREATE, title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = PerformanceTestService.class)
public String save(
@RequestPart("request") SaveTestPlanRequest request,
@RequestPart(value = "file") List<MultipartFile> files
) {
request.setId(UUID.randomUUID().toString());
checkPermissionService.checkProjectOwner(request.getProjectId());
return performanceTestService.save(request, files);
}
@PostMapping(value = "/edit", consumes = {"multipart/form-data"})
@MsAuditLog(module = "performance_test", type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#request.id)", title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = PerformanceTestService.class)
public String edit(
@RequestPart("request") EditTestPlanRequest request,
@RequestPart(value = "file", required = false) List<MultipartFile> files
@ -124,12 +130,14 @@ public class PerformanceTestController {
}
@PostMapping("/delete")
@MsAuditLog(module = "performance_test", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#request.id)", msClass = PerformanceTestService.class)
public void delete(@RequestBody DeleteTestPlanRequest request) {
checkPermissionService.checkPerformanceTestOwner(request.getId());
performanceTestService.delete(request);
}
@PostMapping("/run")
@MsAuditLog(module = "performance_test", type = OperLogConstants.EXECUTE, content = "#msClass.getLogDetails(#request.id)", msClass = PerformanceTestService.class)
public String run(@RequestBody RunTestPlanRequest request) {
return performanceTestService.run(request);
}
@ -170,6 +178,7 @@ public class PerformanceTestController {
}
@PostMapping(value = "/copy")
@MsAuditLog(module = "performance_test", type = OperLogConstants.COPY, content = "#msClass.getLogDetails(#request.id)", msClass = PerformanceTestService.class)
public void copy(@RequestBody SaveTestPlanRequest request) {
performanceTestService.copy(request);
}

View File

@ -15,6 +15,10 @@ import io.metersphere.controller.request.OrderRequest;
import io.metersphere.dto.LogDetailDTO;
import io.metersphere.dto.ReportDTO;
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.performance.PerformanceReference;
import io.metersphere.performance.base.*;
import io.metersphere.performance.controller.request.DeleteReportRequest;
import io.metersphere.performance.controller.request.RenameReportRequest;
@ -24,6 +28,7 @@ import io.metersphere.performance.engine.Engine;
import io.metersphere.performance.engine.EngineFactory;
import io.metersphere.service.FileService;
import io.metersphere.service.TestResourceService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
@ -37,7 +42,9 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
@ -364,4 +371,26 @@ public class PerformanceReportService {
record.setName(request.getName());
loadTestReportMapper.updateByPrimaryKeySelective(record);
}
public String getLogDetails(String id) {
LoadTestReportWithBLOBs loadTest = loadTestReportMapper.selectByPrimaryKey(id);
if (loadTest != null) {
List<DetailColumn> columns = ReflexObjectUtil.getColumns(loadTest, PerformanceReference.reportColumns);
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(loadTest.getId()), loadTest.getProjectId(), loadTest.getName(), null, columns);
return JSON.toJSONString(details);
}
return null;
}
public String getLogDetails(List<String> ids) {
LoadTestReportExample example = new LoadTestReportExample();
example.createCriteria().andIdIn(ids);
List<LoadTestReport> loadTests = loadTestReportMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(loadTests)) {
List<String> names = loadTests.stream().map(LoadTestReport::getName).collect(Collectors.toList());
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(ids), loadTests.get(0).getProjectId(), String.join(",", names), null, new LinkedList<>());
return JSON.toJSONString(details);
}
return null;
}
}

View File

@ -1,5 +1,6 @@
package io.metersphere.performance.service;
import com.alibaba.fastjson.JSON;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtLoadTestMapper;
@ -20,6 +21,10 @@ import io.metersphere.dto.LoadTestDTO;
import io.metersphere.dto.ScheduleDao;
import io.metersphere.i18n.Translator;
import io.metersphere.job.sechedule.PerformanceTestJob;
import io.metersphere.log.utils.ReflexObjectUtil;
import io.metersphere.log.vo.DetailColumn;
import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.performance.PerformanceReference;
import io.metersphere.performance.dto.LoadTestExportJmx;
import io.metersphere.performance.engine.Engine;
import io.metersphere.performance.engine.EngineFactory;
@ -204,7 +209,8 @@ public class PerformanceTestService {
final LoadTestWithBLOBs loadTest = new LoadTestWithBLOBs();
loadTest.setUserId(SessionUtils.getUser().getId());
loadTest.setId(UUID.randomUUID().toString());
loadTest.setId(request.getId());
loadTest.setCreateUser(SessionUtils.getUserId());
loadTest.setName(request.getName());
loadTest.setProjectId(request.getProjectId());
loadTest.setCreateTime(System.currentTimeMillis());
@ -466,6 +472,7 @@ public class PerformanceTestService {
loadTestFileMapper.insert(loadTestFile);
});
}
request.setId(copy.getId());
}
public void updateSchedule(Schedule request) {
@ -614,4 +621,14 @@ public class PerformanceTestService {
example.createCriteria().andTestIdEqualTo(testId);
return loadTestReportMapper.countByExample(example);
}
public String getLogDetails(String id) {
LoadTest loadTest = loadTestMapper.selectByPrimaryKey(id);
if (loadTest != null) {
List<DetailColumn> columns = ReflexObjectUtil.getColumns(loadTest, PerformanceReference.performanceColumns);
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(loadTest.getId()), loadTest.getProjectId(), loadTest.getName(), loadTest.getCreateUser(), columns);
return JSON.toJSONString(details);
}
return null;
}
}

@ -1 +1 @@
Subproject commit 9a95a444a4f0a477427f94bd107571430d85e766
Subproject commit e435fe1d01a2495481efa58daf3875be07b2ac9b

View File

@ -70,3 +70,4 @@ ALTER TABLE test_plan_api_scenario ADD create_user VARCHAR(100) NULL;
ALTER TABLE test_plan_load_case ADD create_user VARCHAR(100) NULL;
ALTER TABLE test_case_report ADD create_user VARCHAR(100) NULL;
ALTER TABLE project ADD create_user VARCHAR(100) NULL;
ALTER TABLE load_test ADD create_user VARCHAR(100) NULL;

View File

@ -77,7 +77,7 @@
<table tableName="test_case_review_scenario"/>
<table tableName="test_plan"/>
<table tableName="test_case_test"/>-->
<table tableName="test_case_report"></table>
<table tableName="load_test"></table>
<!-- <table tableName="custom_field"></table>-->
<!-- <table tableName="test_case"></table>-->
<!-- <table tableName="test_case"></table>-->

View File

@ -230,4 +230,6 @@ track_test_case=Test case
track_test_case_review=Case review
track_test_plan=Test plan
track_bug=Defect management
track_report=Report
track_report=Report
performance_test=Performance test
performance_test_report=Performance test report

View File

@ -229,4 +229,6 @@ track_test_case=测试用例
track_test_case_review=用例评审
track_test_plan=测试计划
track_bug=缺陷管理
track_report=报告
track_report=报告
performance_test=性能测试
performance_test_report=性能测试报告

View File

@ -192,7 +192,6 @@ license_valid_license_error=授權驗證失敗
license_valid_license_code=授權碼已經存在
import_xmind_count_error=思維導圖導入用例數量不能超過 500 條
import_xmind_not_found=未找到测试用例
test_review_task_notice=測試評審任務通知
test_track.length_less_than=標題過長,字數必須小於
# check owner
@ -231,4 +230,6 @@ track_test_case=測試用例
track_test_case_review=用例評審
track_test_plan=測試計劃
track_bug=缺陷管理
track_report=報告
track_report=報告
performance_test=性能測試
performance_test_report=性能測試報告

View File

@ -13,7 +13,7 @@
</div>
<div>
<p class="tip">{{ this.$t('report.test_log_details') }} </p>
<div v-if="detail && detail.operType !== 'CREATE' && detail.operType !=='DELETE' && detail && detail.details && detail.details.columns && detail.details.columns.length >0 ">
<div v-if="detail && detail.operType !== 'CREATE' && detail.operType !=='DELETE' && detail.operType !=='COPY' && detail && detail.details && detail.details.columns && detail.details.columns.length >0 ">
<div v-if="detail && detail.details && detail.details.columns" style="margin-left: 20px">
<el-table :data="detail.details.columns">
<el-table-column prop="columnTitle" :label="$t('operating_log.change_field')"/>

@ -1 +1 @@
Subproject commit 097d3a5a00beaa660d34525765d93b35e63f52c0
Subproject commit e50f0463826ac4d7837ea3a237333827774a1b19