refactor(接口测试): 统一修改时间控制器最大值

This commit is contained in:
wxg0103 2024-04-03 19:36:39 +08:00 committed by Craftsman
parent 218e13b582
commit 7d4e6c340c
17 changed files with 82 additions and 28 deletions

View File

@ -58,7 +58,6 @@ public class ApiScenarioBatchOperationController {
return apiScenarioService.batchGCOperation(request, true, new LogInsertModule(SessionUtils.getUserId(), "/api/scenario/batch-operation/delete-gc", HttpMethodConstants.POST.name()));
}
//需求补充回收站里的相关操作都不需要发通知
@PostMapping("/batch-operation/recover-gc")
@Operation(summary = "接口测试-接口场景批量操作-回收站列表-批量恢复")
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_DELETE)
@ -68,7 +67,6 @@ public class ApiScenarioBatchOperationController {
return apiScenarioService.batchGCOperation(request, false, new LogInsertModule(SessionUtils.getUserId(), "/api/scenario/batch-operation/recover-gc", HttpMethodConstants.POST.name()));
}
//需求补充回收站里的相关操作都不需要发通知
@PostMapping("/batch-operation/delete")
@Operation(summary = "接口测试-接口场景批量操作-场景列表操作-批量删除")
@RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_DELETE)

View File

@ -18,6 +18,7 @@ import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -111,7 +112,7 @@ public class ApiDefinitionLogService {
id,
null,
OperationLogType.DELETE.name(),
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
OperationLogModule.API_TEST_MANAGEMENT_RECYCLE,
apiDefinition.getName());
dto.setMethod(HttpMethodConstants.GET.name());
@ -128,7 +129,7 @@ public class ApiDefinitionLogService {
* @return
*/
public void batchDelLog(List<String> ids, String userId, String projectId) {
saveBatchLog(projectId, ids, userId, OperationLogType.DELETE.name(), false);
saveBatchLog(projectId, ids, userId, OperationLogType.DELETE.name(), false, null);
}
/**
@ -137,7 +138,7 @@ public class ApiDefinitionLogService {
* @return
*/
public void batchUpdateLog(List<String> ids, String userId, String projectId) {
saveBatchLog(projectId, ids, userId, OperationLogType.UPDATE.name(), true);
saveBatchLog(projectId, ids, userId, OperationLogType.UPDATE.name(), true, null);
}
public LogDTO copyLog(ApiDefinitionCopyRequest request) {
@ -160,7 +161,7 @@ public class ApiDefinitionLogService {
}
public void batchMoveLog(List<String> ids, String userId, String projectId) {
saveBatchLog(projectId, ids, userId, OperationLogType.UPDATE.name(), false);
saveBatchLog(projectId, ids, userId, OperationLogType.UPDATE.name(), false, null);
}
public LogDTO followLog(String id) {
@ -198,7 +199,7 @@ public class ApiDefinitionLogService {
request.getId(),
null,
OperationLogType.RECOVER.name(),
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
OperationLogModule.API_TEST_MANAGEMENT_RECYCLE,
apiDefinition.getName());
dto.setHistory(false);
dto.setMethod(HttpMethodConstants.POST.name());
@ -216,14 +217,14 @@ public class ApiDefinitionLogService {
* @return
*/
public void batchRecoverLog(List<String> ids, String userId, String projectId) {
saveBatchLog(projectId, ids, userId, OperationLogType.RECOVER.name(), false);
saveBatchLog(projectId, ids, userId, OperationLogType.RECOVER.name(), false, OperationLogModule.API_TEST_MANAGEMENT_RECYCLE);
}
/**
* 删除回收站接口定义接口日志
*/
public void batchTrashDelLog(List<String> ids, String userId, String projectId) {
saveBatchLog(projectId, ids, userId, OperationLogType.DELETE.name(), false);
saveBatchLog(projectId, ids, userId, OperationLogType.DELETE.name(), false, OperationLogModule.API_TEST_MANAGEMENT_RECYCLE);
}
private ApiDefinitionDTO getOriginalValue(String id) {
@ -239,13 +240,17 @@ public class ApiDefinitionLogService {
private void saveBatchLog(String projectId, List<String> ids, String userId, String operationType, boolean isHistory) {
private void saveBatchLog(String projectId, List<String> ids, String userId, String operationType, boolean isHistory, String logModule) {
if (StringUtils.isBlank(logModule)) {
logModule = OperationLogModule.API_TEST_MANAGEMENT_DEFINITION;
}
List<LogDTO> dtoList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(ids)) {
Project project = projectMapper.selectByPrimaryKey(projectId);
ApiDefinitionExample example = new ApiDefinitionExample();
example.createCriteria().andIdIn(ids);
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(example);
String finalLogModule = logModule;
apiDefinitions.forEach(item -> {
ApiDefinitionDTO apiDefinitionDTO = new ApiDefinitionDTO();
CommonBeanFactory.getBean(ApiDefinitionService.class).handleBlob(item.getId(), apiDefinitionDTO);
@ -256,7 +261,7 @@ public class ApiDefinitionLogService {
item.getId(),
userId,
operationType,
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
finalLogModule,
item.getName());
dto.setHistory(isHistory);

View File

@ -24,6 +24,7 @@ import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -73,7 +74,7 @@ public class ApiTestCaseLogService {
id,
null,
OperationLogType.DELETE.name(),
OperationLogModule.API_TEST_MANAGEMENT_CASE,
OperationLogModule.API_TEST_MANAGEMENT_RECYCLE,
apiTestCase.getName());
dto.setMethod(HttpMethodConstants.GET.name());
dto.setOriginalValue(JSON.toJSONBytes(apiTestCase));
@ -179,7 +180,7 @@ public class ApiTestCaseLogService {
.projectId(project.getId())
.organizationId(project.getOrganizationId())
.type(OperationLogType.DELETE.name())
.module(OperationLogModule.API_TEST_MANAGEMENT_CASE)
.module(OperationLogModule.API_TEST_MANAGEMENT_RECYCLE)
.method(HttpMethodConstants.POST.name())
.sourceId(item.getId())
.content(item.getName())
@ -193,18 +194,18 @@ public class ApiTestCaseLogService {
}
public void batchToGcLog(List<ApiTestCase> apiTestCases, String operator, String projectId) {
saveBatchLog(projectId, apiTestCases, operator, OperationLogType.DELETE.name(), false);
saveBatchLog(projectId, apiTestCases, operator, OperationLogType.DELETE.name(), false, null);
}
public void batchEditLog(List<ApiTestCase> apiTestCases, String operator, String projectId) {
saveBatchLog(projectId, apiTestCases, operator, OperationLogType.UPDATE.name(), true);
saveBatchLog(projectId, apiTestCases, operator, OperationLogType.UPDATE.name(), true, null);
}
public void batchRecoverLog(List<ApiTestCase> apiTestCases, String operator, String projectId) {
saveBatchLog(projectId, apiTestCases, operator, OperationLogType.RECOVER.name(), false);
saveBatchLog(projectId, apiTestCases, operator, OperationLogType.RECOVER.name(), false, OperationLogModule.API_TEST_MANAGEMENT_RECYCLE);
}
private void saveBatchLog(String projectId, List<ApiTestCase> apiTestCases, String operator, String operationType, boolean isHistory) {
private void saveBatchLog(String projectId, List<ApiTestCase> apiTestCases, String operator, String operationType, boolean isHistory, String logModule) {
Project project = projectMapper.selectByPrimaryKey(projectId);
//取出apiTestCases所有的id为新的list
List<String> caseId = apiTestCases.stream().map(ApiTestCase::getId).distinct().toList();
@ -219,6 +220,10 @@ public class ApiTestCaseLogService {
//blobList按id生成新的map key为id value为ApiTestCaseBlob
Map<String, ApiTestCaseBlob> blobMap = blobList.stream().collect(Collectors.toMap(ApiTestCaseBlob::getId, a -> a));
List<LogDTO> logs = new ArrayList<>();
if (StringUtils.isBlank(logModule)) {
logModule = OperationLogModule.API_TEST_MANAGEMENT_CASE;
}
String finalLogModule = logModule;
apiTestCases.forEach(item -> {
ApiTestCaseLogDTO apiTestCaseDTO = new ApiTestCaseLogDTO();
BeanUtils.copyBean(apiTestCaseDTO, caseMap.get(item.getId()));
@ -229,7 +234,7 @@ public class ApiTestCaseLogService {
.projectId(project.getId())
.organizationId(project.getOrganizationId())
.type(operationType)
.module(OperationLogModule.API_TEST_MANAGEMENT_CASE)
.module(finalLogModule)
.method(HttpMethodConstants.POST.name())
.path(OperationLogAspect.getPath())
.sourceId(item.getId())

View File

@ -18,6 +18,7 @@ import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@ -171,7 +172,7 @@ public class ApiScenarioLogService {
apiScenario.getId(),
null,
OperationLogType.DELETE.name(),
OperationLogModule.API_SCENARIO_MANAGEMENT_SCENARIO,
OperationLogModule.API_TEST_SCENARIO_RECYCLE,
apiScenario.getName());
dto.setOriginalValue(JSON.toJSONBytes(apiScenario));
return dto;
@ -185,23 +186,27 @@ public class ApiScenarioLogService {
apiScenario.getId(),
null,
OperationLogType.RESTORE.name(),
OperationLogModule.API_SCENARIO_MANAGEMENT_SCENARIO,
OperationLogModule.API_TEST_SCENARIO_RECYCLE,
apiScenario.getName());
dto.setOriginalValue(JSON.toJSONBytes(apiScenario));
return dto;
}
public void saveBatchOperationLog(ApiScenarioBatchOperationResponse response, String projectId, String operationType, LogInsertModule logInsertModule) {
public void saveBatchOperationLog(ApiScenarioBatchOperationResponse response, String projectId, String operationType, LogInsertModule logInsertModule, String logModule) {
if (StringUtils.isBlank(logModule)) {
logModule = OperationLogModule.API_SCENARIO_MANAGEMENT_SCENARIO;
}
Project project = projectMapper.selectByPrimaryKey(projectId);
//取出apiTestCases所有的id为新的list
List<LogDTO> logs = new ArrayList<>();
String finalLogModule = logModule;
response.getSuccessData().forEach(item -> {
LogDTO dto = LogDTOBuilder.builder()
.projectId(project.getId())
.organizationId(project.getOrganizationId())
.type(operationType)
.module(OperationLogModule.API_SCENARIO_MANAGEMENT_SCENARIO)
.module(finalLogModule)
.method(logInsertModule.getRequestMethod())
.path(logInsertModule.getRequestUrl())
.sourceId(item.getId())

View File

@ -2202,7 +2202,7 @@ public class ApiScenarioService extends MoveNodeService {
long moveTime = System.currentTimeMillis();
ApiScenarioBatchOperationResponse response =
ApiScenarioBatchOperationUtils.executeWithBatchOperationResponse(scenarioIds, sublist -> move(sublist, request, moveTime, logInsertModule.getOperator()));
apiScenarioLogService.saveBatchOperationLog(response, request.getProjectId(), OperationLogType.UPDATE.name(), logInsertModule);
apiScenarioLogService.saveBatchOperationLog(response, request.getProjectId(), OperationLogType.UPDATE.name(), logInsertModule, null);
return response;
}
@ -2216,7 +2216,7 @@ public class ApiScenarioService extends MoveNodeService {
request.setSelectIds(scenarioIds);
ApiScenarioBatchOperationResponse response =
ApiScenarioBatchOperationUtils.executeWithBatchOperationResponse(scenarioIds, sublist -> copyAndInsert(sublist, request, logInsertModule.getOperator()));
apiScenarioLogService.saveBatchOperationLog(response, request.getProjectId(), OperationLogType.COPY.name(), logInsertModule);
apiScenarioLogService.saveBatchOperationLog(response, request.getProjectId(), OperationLogType.COPY.name(), logInsertModule, null);
return response;
}
@ -2429,7 +2429,7 @@ public class ApiScenarioService extends MoveNodeService {
scenarioIds,
sublist -> operationGC(sublist, isDeleteOperation, deleteTime, logInsertModule.getOperator()));
apiScenarioLogService.saveBatchOperationLog(response, request.getProjectId(),
isDeleteOperation ? OperationLogType.DELETE.name() : OperationLogType.RECOVER.name(), logInsertModule);
isDeleteOperation ? OperationLogType.DELETE.name() : OperationLogType.RECOVER.name(), logInsertModule,OperationLogModule.API_TEST_SCENARIO_RECYCLE );
return response;
}
@ -2464,7 +2464,7 @@ public class ApiScenarioService extends MoveNodeService {
ApiScenarioBatchOperationResponse response = ApiScenarioBatchOperationUtils.executeWithBatchOperationResponse(
scenarioIds,
sublist -> delete(sublist, request.getProjectId(), logInsertModule.getOperator()));
apiScenarioLogService.saveBatchOperationLog(response, request.getProjectId(), OperationLogType.DELETE.name(), logInsertModule);
apiScenarioLogService.saveBatchOperationLog(response, request.getProjectId(), OperationLogType.DELETE.name(), logInsertModule, OperationLogModule.API_TEST_SCENARIO_RECYCLE);
return response;
}

View File

@ -31,6 +31,7 @@ public class CleanHistoryJob {
private OperationLogBlobMapper operationLogBlobMapper;
private static final int DEFAULT_LIMIT = 10;
private static final int DEFAULT_LIMIT_MAX = 100001;
/**
* 清理变更历史 每天凌晨两点执行
@ -42,6 +43,9 @@ public class CleanHistoryJob {
Optional.ofNullable(parameter).ifPresentOrElse(
p -> {
int limit = Integer.parseInt(p.getParamValue());
if (limit == DEFAULT_LIMIT_MAX) {
return;
}
doCleanupHistory(limit);
},
() -> {

View File

@ -24,8 +24,10 @@ public class OperationLogModule {
public static final String API_TEST_MANAGEMENT_MOCK = "API_TEST_MANAGEMENT_MOCK";
public static final String API_TEST_MANAGEMENT_CASE = "API_TEST_MANAGEMENT_CASE";
// 场景管理
public static final String API_SCENARIO_MANAGEMENT_SCENARIO = "API_TEST_SCENARIO";
public static final String API_SCENARIO_MANAGEMENT_SCENARIO = "API_SCENARIO_MANAGEMENT_SCENARIO";
public static final String API_SCENARIO_MANAGEMENT_MODULE = "API_SCENARIO_MANAGEMENT_MODULE";
public static final String API_TEST_SCENARIO_RECYCLE = "API_TEST_SCENARIO_RECYCLE";
public static final String API_TEST_MANAGEMENT_RECYCLE = "API_TEST_MANAGEMENT_RECYCLE";
public static final String API_REPORT = "API_TEST_REPORT";
public static final String AUTH_TITLE = "AUTH_TITLE";

View File

@ -242,6 +242,24 @@ public class SystemParameterControllerTests extends BaseTest {
cleanHistoryJob.cleanupLog();
cleanLogJob.cleanupLog();
updateSystemParameters = new ArrayList<>() {{
add(new SystemParameter() {{
setParamKey("cleanConfig.operation.log");
setParamValue("2D");
setType("text");
}});
add(new SystemParameter() {{
setParamKey("cleanConfig.operation.history");
setParamValue("100001");
setType("text");
}});
}};
this.requestPost(LOG_CONFIG_URL, updateSystemParameters);
this.requestGet(GET_LOG_CONFIG_URL);
cleanHistoryJob.cleanupLog();
cleanLogJob.cleanupLog();
//覆盖代码
List<SystemParameter> updateConfigMonth = new ArrayList<>() {{
add(new SystemParameter() {{

View File

@ -343,6 +343,7 @@
:step="100"
:min="0"
:precision="0"
:max="600000"
class="w-[160px]"
model-event="input"
/>

View File

@ -14,6 +14,7 @@
:disabled="props.disabled"
mode="button"
:step="100"
:max="600000"
:precision="0"
:min="0"
class="w-[160px]"
@ -32,6 +33,7 @@
mode="button"
:step="100"
:precision="0"
:max="600000"
:min="0"
class="w-[160px]"
/>

View File

@ -55,6 +55,7 @@
mode="button"
:step="100"
:min="0"
:max="600000"
class="w-[160px]"
@change="emit('change')"
/>

View File

@ -7,6 +7,7 @@
size="mini"
:step="1000"
:min="0"
:max="600000"
:precision="0"
model-event="input"
:disabled="props.disabled"

View File

@ -19,6 +19,7 @@
:min="0"
:step="100"
:precision="0"
:max="600000"
class="w-[180px]"
:disabled="isDisabled"
>
@ -30,6 +31,7 @@
v-model:model-value="form.responseTimeout"
:min="0"
:step="100"
:max="600000"
:precision="0"
class="w-[180px]"
:disabled="isDisabled"

View File

@ -78,6 +78,7 @@
mode="button"
:min="1"
:precision="0"
:max="10000"
:default-value="1"
/>
</a-form-item>
@ -89,6 +90,7 @@
:step="100"
:min="0"
:default-value="1000"
:max="600000"
/>
</a-form-item>
<a-button type="outline" class="w-[88px]" @click="testConnection">

View File

@ -40,7 +40,11 @@
<template v-else>
<div class="mb-[8px] mt-[16px] flex items-center">
<div class="text-[var(--color-text-000)]">{{ t('system.config.memoryCleanup.saveCount') }}</div>
<a-tooltip :content="t('system.config.memoryCleanup.saveCountTip')" position="right">
<a-tooltip position="right">
<template #content>
<div>{{ t('system.config.memoryCleanup.saveCountTip') }}</div>
<div>{{ t('system.config.memoryCleanup.numberTip') }}</div>
</template>
<icon-question-circle
class="ml-[4px] text-[var(--color-text-4)] hover:text-[rgb(var(--primary-5))]"
size="16"
@ -52,6 +56,7 @@
class="w-[130px]"
:disabled="saveLoading || !hasPermission"
:min="0"
:max="100001"
@blur="() => saveConfig()"
/>
</template>

View File

@ -204,4 +204,6 @@ export default {
'system.config.memoryCleanup.saveCount': 'Reserved quantity',
'system.config.memoryCleanup.saveCountTip':
'Effective for all projects in the system, the system will clear unset change history in the early morning',
'system.config.memoryCleanup.numberTip':
'The system defaults to a maximum of 100,000 records, and will keep all records if exceeded',
};

View File

@ -198,4 +198,5 @@ export default {
'system.config.memoryCleanup.setSuccess': '设置成功',
'system.config.memoryCleanup.saveCount': '保留条数',
'system.config.memoryCleanup.saveCountTip': '对系统内所有的项目生效,系统会在凌晨清除超出设置的变更历史记录',
'system.config.memoryCleanup.numberTip': '系统默认最大保留条数为100000条超过则为您保留全部记录',
};