fix(项目设置): 更改性能测试脚本预警的方式

更改性能测试脚本预警的方式
This commit is contained in:
song-tianyang 2023-05-22 15:01:38 +08:00 committed by 建国
parent 1454d14bc7
commit 9b7de47b07
9 changed files with 69 additions and 33 deletions

View File

@ -98,7 +98,7 @@ public class PerformanceTestController {
checkPermissionService.checkProjectOwner(request.getProjectId()); checkPermissionService.checkProjectOwner(request.getProjectId());
LoadTest loadTest = performanceTestService.save(request, files); LoadTest loadTest = performanceTestService.save(request, files);
//检查并发送审核脚本的通知 //检查并发送审核脚本的通知
performanceTestService.checkAndSendReviewMessage(new ArrayList<>(request.getUpdatedFileList()), files, request.getId(), request.getName(), request.getProjectId()); performanceTestService.checkAndSendReviewMessage(new ArrayList<>(request.getUpdatedFileList()), files, loadTest);
return loadTest; return loadTest;
} }
@ -120,7 +120,7 @@ public class PerformanceTestController {
checkPermissionService.checkPerformanceTestOwner(request.getId()); checkPermissionService.checkPerformanceTestOwner(request.getId());
LoadTest loadTest = performanceTestService.edit(request, files); LoadTest loadTest = performanceTestService.edit(request, files);
//检查并发送审核脚本的通知 //检查并发送审核脚本的通知
performanceTestService.checkAndSendReviewMessage(new ArrayList<>(request.getUpdatedFileList()), files, request.getId(), request.getName(), request.getProjectId()); performanceTestService.checkAndSendReviewMessage(new ArrayList<>(request.getUpdatedFileList()), files, loadTest);
return loadTest; return loadTest;
} }

View File

@ -1173,32 +1173,42 @@ public class PerformanceTestService {
return this.list(request2); return this.list(request2);
} }
private boolean checkLoadTest(LoadTest loadTest) {
return loadTest != null && StringUtils.isNoneBlank(loadTest.getId(), loadTest.getName(), loadTest.getProjectId(), loadTest.getCreateUser());
}
//检查并发送脚本审核的通知 //检查并发送脚本审核的通知
public void checkAndSendReviewMessage(List<FileMetadata> fileMetadataList, List<MultipartFile> files, String loadTestId, String loadTestName, String projectId) { public void checkAndSendReviewMessage(List<FileMetadata> fileMetadataList, List<MultipartFile> files, LoadTest loadTest) {
if (checkLoadTest(loadTest)) {
String projectId = loadTest.getProjectId();
ProjectApplication reviewLoadTestScript = projectApplicationService.getProjectApplication( ProjectApplication reviewLoadTestScript = projectApplicationService.getProjectApplication(
projectId, ProjectApplicationType.PERFORMANCE_REVIEW_LOAD_TEST_SCRIPT.name()); projectId, ProjectApplicationType.PERFORMANCE_REVIEW_LOAD_TEST_SCRIPT.name());
if (BooleanUtils.toBoolean(reviewLoadTestScript.getTypeValue())) { if (BooleanUtils.toBoolean(reviewLoadTestScript.getTypeValue())) {
ProjectApplication loadTestScriptReviewerConfig = projectApplicationService.getProjectApplication(
projectId, ProjectApplicationType.PERFORMANCE_SCRIPT_REVIEWER.name());
if (StringUtils.isNotEmpty(loadTestScriptReviewerConfig.getTypeValue()) && projectService.isProjectMember(projectId, loadTestScriptReviewerConfig.getTypeValue())) {
boolean isSend = this.isSendScriptReviewMessage(fileMetadataList, files); boolean isSend = this.isSendScriptReviewMessage(fileMetadataList, files);
if (isSend) { if (isSend) {
String sendUser = loadTest.getCreateUser();
ProjectApplication loadTestScriptReviewerConfig = projectApplicationService.getProjectApplication(projectId, ProjectApplicationType.PERFORMANCE_SCRIPT_REVIEWER.name());
if (StringUtils.isNotEmpty(loadTestScriptReviewerConfig.getTypeValue())) {
sendUser = loadTestScriptReviewerConfig.getTypeValue();
}
if (projectService.isProjectMember(projectId, loadTestScriptReviewerConfig.getTypeValue())) {
Notification notification = new Notification(); Notification notification = new Notification();
notification.setTitle("性能测试通知"); notification.setTitle("性能测试通知");
notification.setOperator(SessionUtils.getUserId()); notification.setOperator(SessionUtils.getUserId());
notification.setOperation(NoticeConstants.Event.REVIEW); notification.setOperation(NoticeConstants.Event.REVIEW);
notification.setResourceId(loadTestId); notification.setResourceId(loadTest.getId());
notification.setResourceName(loadTestName); notification.setResourceName(loadTest.getName());
notification.setResourceType(NoticeConstants.TaskType.PERFORMANCE_TEST_TASK); notification.setResourceType(NoticeConstants.TaskType.PERFORMANCE_TEST_TASK);
notification.setType(NotificationConstants.Type.SYSTEM_NOTICE.name()); notification.setType(NotificationConstants.Type.SYSTEM_NOTICE.name());
notification.setStatus(NotificationConstants.Status.UNREAD.name()); notification.setStatus(NotificationConstants.Status.UNREAD.name());
notification.setCreateTime(System.currentTimeMillis()); notification.setCreateTime(System.currentTimeMillis());
notification.setReceiver(loadTestScriptReviewerConfig.getTypeValue()); notification.setReceiver(sendUser);
notificationService.sendAnnouncement(notification); notificationService.sendAnnouncement(notification);
} }
} }
} }
} }
}
private boolean isSendScriptReviewMessage(List<FileMetadata> fileMetadataList, List<MultipartFile> files) { private boolean isSendScriptReviewMessage(List<FileMetadata> fileMetadataList, List<MultipartFile> files) {
List<FileContent> fileContentList = new ArrayList<>(); List<FileContent> fileContentList = new ArrayList<>();

View File

@ -4,7 +4,9 @@ import com.alibaba.fastjson.JSON;
import com.google.common.base.CaseFormat; import com.google.common.base.CaseFormat;
import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.api.tcp.TCPPool; import io.metersphere.api.tcp.TCPPool;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.Project;
import io.metersphere.base.domain.ProjectApplication;
import io.metersphere.base.domain.ProjectApplicationExample;
import io.metersphere.base.mapper.ProjectApplicationMapper; import io.metersphere.base.mapper.ProjectApplicationMapper;
import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.commons.constants.ProjectApplicationType; import io.metersphere.commons.constants.ProjectApplicationType;
@ -214,7 +216,10 @@ public class ProjectApplicationService {
String projectId = conf.getProjectId(); String projectId = conf.getProjectId();
String type = conf.getType(); String type = conf.getType();
String value = conf.getTypeValue(); String value = conf.getTypeValue();
if (StringUtils.isBlank(projectId) || StringUtils.isBlank(type) || StringUtils.isEmpty(value)) {
//性能测试审核人允许value值为空
if (!StringUtils.equals(type, ProjectApplicationType.PERFORMANCE_SCRIPT_REVIEWER.name())
&& (StringUtils.isBlank(projectId) || StringUtils.isBlank(type) || StringUtils.isEmpty(value))) {
LogUtil.error("create or update project config error. project id or conf type or value is blank."); LogUtil.error("create or update project config error. project id or conf type or value is blank.");
return; return;
} }

View File

@ -33,18 +33,24 @@
> >
<el-col :span="2"> <el-col :span="2">
<div class="icon-title"> <div class="icon-title">
{{ row.resourceName.substring(0, 1) }} {{ $t("commons.system_notification_logo") }}
</div> </div>
</el-col> </el-col>
<el-col :span="22"> <el-col :span="22">
<span class="operation"> <span class="operation">
<span>{{ getResource(row) }}:</span> <span>{{ getResource(row) }}:</span>
<span <el-popover
placement="top-start"
width="200"
trigger="hover"
:content="row.resourceName">
<span slot="reference"
@click="clickResource(row)" @click="clickResource(row)"
style="color: #783887; cursor: pointer" style="color: #783887; cursor: pointer"
> >
{{ row.resourceName }} {{ getShortResourceName(row.resourceName) }}
</span> </span>
</el-popover>
<span> {{ $t("project.config.contains_script_review") }} </span> <span> {{ $t("project.config.contains_script_review") }} </span>
</span> </span>
</el-col> </el-col>
@ -168,6 +174,9 @@ export default {
let element = document.getElementById(id); let element = document.getElementById(id);
element.parentNode.removeChild(element); element.parentNode.removeChild(element);
}, },
getShortResourceName(resourceName) {
return resourceName.length > 7 ? resourceName.substring(0, 7) + "..." : resourceName;
},
isReviewNotice(row) { isReviewNotice(row) {
return row.operation === "REVIEW"; return row.operation === "REVIEW";
}, },

View File

@ -196,6 +196,7 @@
:reviewers="userInProject" :reviewers="userInProject"
:reviewer.sync="config.performanceScriptReviewer" :reviewer.sync="config.performanceScriptReviewer"
:reviewerSwitch.sync="config.performanceReviewLoadTestScript" :reviewerSwitch.sync="config.performanceReviewLoadTestScript"
:placeholder="$t('commons.creator')"
@reviewerChange=" @reviewerChange="
switchChange( switchChange(
'PERFORMANCE_SCRIPT_REVIEWER', 'PERFORMANCE_SCRIPT_REVIEWER',
@ -297,9 +298,11 @@ export default {
created() { created() {
this.init(); this.init();
this.getResourcePools(); this.getResourcePools();
this.selectUserInProject();
this.isXpack = !!hasLicense(); this.isXpack = !!hasLicense();
}, },
activated() {
this.selectUserInProject();
},
computed: { computed: {
projectId() { projectId() {
return getCurrentProjectID(); return getCurrentProjectID();

View File

@ -23,12 +23,13 @@
{{ $t("commons.reviewers") }} {{ $t("commons.reviewers") }}
</span> </span>
<el-select <el-select
clearable
v-model="reviewerSelect" v-model="reviewerSelect"
@change="reviewerChange" @change="reviewerChange"
size="mini" size="mini"
style="margin-left: 5px" style="margin-left: 5px"
filterable filterable
:placeholder="$t('api_test.definition.api_principal')" :placeholder="placeholder"
> >
<el-option <el-option
v-for="item in reviewers" v-for="item in reviewers"
@ -41,7 +42,6 @@
</template> </template>
<template #append> <template #append>
<el-switch <el-switch
:disabled="!reviewerSelect || reviewerSelect===''"
v-model="reviewerSwitchSelect" v-model="reviewerSwitchSelect"
@change="switchChange" @change="switchChange"
></el-switch> ></el-switch>
@ -61,6 +61,12 @@ export default {
reviewers: Array, reviewers: Array,
reviewer: String, reviewer: String,
reviewerSwitch: Boolean, reviewerSwitch: Boolean,
placeholder: {
type: String,
default() {
return this.$t('api_test.definition.api_principal');
}
}
}, },
setup() { setup() {
return {}; return {};

View File

@ -13,6 +13,7 @@ export default {
xmindFile: "Xmind", xmindFile: "Xmind",
default: "default", default: "default",
sort_default: "Default", sort_default: "Default",
system_notification_logo: "Sys",
please_select_import_mode: 'Please select import mode', please_select_import_mode: 'Please select import mode',
please_select_import_module: 'Please select import module', please_select_import_module: 'Please select import module',
pass_rate: 'Pass Rate', pass_rate: 'Pass Rate',

View File

@ -13,6 +13,7 @@ export default {
xmindFile: "思维导图.xmind", xmindFile: "思维导图.xmind",
default: "默认值", default: "默认值",
sort_default: "默认排序", sort_default: "默认排序",
system_notification_logo: "系",
please_select_import_mode: '请选择导入模式', please_select_import_mode: '请选择导入模式',
please_select_import_module: '请选择导入模块', please_select_import_module: '请选择导入模块',
pass_rate: '通过率', pass_rate: '通过率',

View File

@ -13,6 +13,7 @@ export default {
xmindFile: "思維導圖.xmind", xmindFile: "思維導圖.xmind",
default: "默認值", default: "默認值",
sort_default: "默認排序", sort_default: "默認排序",
system_notification_logo: "系",
please_select_import_mode: '請選擇導入模式', please_select_import_mode: '請選擇導入模式',
please_select_import_module: '請選擇導入模塊', please_select_import_module: '請選擇導入模塊',
pass_rate: '通過率', pass_rate: '通過率',