fix(功能用例): 尝试修复功能用例脑图保存立即查看报错问题

This commit is contained in:
guoyuqi 2024-07-02 09:46:09 +08:00 committed by Craftsman
parent 581b5dfca5
commit 117a0c3d33
7 changed files with 65 additions and 33 deletions

View File

@ -0,0 +1 @@
select database();

View File

@ -0,0 +1,12 @@
-- set innodb lock wait timeout
SET SESSION innodb_lock_wait_timeout = 7200;
DROP TABLE IF EXISTS functional_mind_insert_relation;
-- set innodb lock wait timeout to default
SET SESSION innodb_lock_wait_timeout = DEFAULT;

View File

@ -0,0 +1,8 @@
-- set innodb lock wait timeout
SET SESSION innodb_lock_wait_timeout = 7200;
DROP TABLE IF EXISTS functional_minder_extra_node;
-- set innodb lock wait timeout to default
SET SESSION innodb_lock_wait_timeout = DEFAULT;

View File

@ -65,7 +65,7 @@ public class FunctionalCaseMinderController {
@Operation(summary = "用例管理-功能用例-脑图用例跟根据模块ID查询列表") @Operation(summary = "用例管理-功能用例-脑图用例跟根据模块ID查询列表")
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_MINDER) @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_MINDER)
@CheckOwner(resourceId = "#request.getReviewId()", resourceType = "case_review") @CheckOwner(resourceId = "#request.getReviewId()", resourceType = "case_review")
public List<FunctionalMinderTreeDTO> getReviewMindFunctionalCase(@Validated @RequestBody FunctionalCaseReviewMindRequest request) { public Pager<List<FunctionalMinderTreeDTO>> getReviewMindFunctionalCase(@Validated @RequestBody FunctionalCaseReviewMindRequest request) {
String userId = StringUtils.EMPTY; String userId = StringUtils.EMPTY;
if (request.isViewFlag()) { if (request.isViewFlag()) {
userId = SessionUtils.getUserId(); userId = SessionUtils.getUserId();
@ -74,15 +74,16 @@ public class FunctionalCaseMinderController {
if (request.isViewStatusFlag()) { if (request.isViewStatusFlag()) {
viewStatusUserId = SessionUtils.getUserId(); viewStatusUserId = SessionUtils.getUserId();
} }
return functionalCaseMinderService.getReviewMindFunctionalCase(request, false, userId, viewStatusUserId); Page<Object> page = PageHelper.startPage(request.getCurrent(), 100 );
return PageUtils.setPageInfo(page, functionalCaseMinderService.getReviewMindFunctionalCase(request, false, userId, viewStatusUserId));
} }
@PostMapping("/plan/list") @PostMapping("/plan/list")
@Operation(summary = "测试计划-功能用例-脑图用例跟根据模块ID查询列表") @Operation(summary = "测试计划-功能用例-脑图用例跟根据模块ID查询列表")
@RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_MINDER) @RequiresPermissions(PermissionConstants.FUNCTIONAL_CASE_READ_MINDER)
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public List<FunctionalMinderTreeDTO> getPlanFunctionalCaseMinderTree(@Validated @RequestBody FunctionalCasePlanMindRequest request) { public Pager<List<FunctionalMinderTreeDTO>> getPlanFunctionalCaseMinderTree(@Validated @RequestBody FunctionalCasePlanMindRequest request) { Page<Object> page = PageHelper.startPage(request.getCurrent(), 100 );
return functionalCaseMinderService.getPlanMindFunctionalCase(request, false); return PageUtils.setPageInfo(page, functionalCaseMinderService.getPlanMindFunctionalCase(request, false));
} }
} }

View File

@ -35,7 +35,6 @@ import io.metersphere.system.mapper.CustomFieldMapper;
import io.metersphere.system.mapper.UserMapper; import io.metersphere.system.mapper.UserMapper;
import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.service.CommonNoticeSendService; import io.metersphere.system.service.CommonNoticeSendService;
import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils; import org.apache.commons.collections4.MapUtils;
@ -752,7 +751,7 @@ public class FunctionalCaseMinderService {
private MindAdditionalNode buildNode(FunctionalCaseMinderEditRequest request, String userId, MindAdditionalNodeRequest mindAdditionalNodeRequest, MindAdditionalNodeMapper additionalNodeMapper) { private MindAdditionalNode buildNode(FunctionalCaseMinderEditRequest request, String userId, MindAdditionalNodeRequest mindAdditionalNodeRequest, MindAdditionalNodeMapper additionalNodeMapper) {
MindAdditionalNode mindAdditionalNode = new MindAdditionalNode(); MindAdditionalNode mindAdditionalNode = new MindAdditionalNode();
mindAdditionalNode.setId(IDGenerator.nextStr()); mindAdditionalNode.setId(mindAdditionalNodeRequest.getId());
if (mindAdditionalNodeRequest.getName().length()>255) { if (mindAdditionalNodeRequest.getName().length()>255) {
mindAdditionalNodeRequest.setName(mindAdditionalNodeRequest.getName().substring(0,249)); mindAdditionalNodeRequest.setName(mindAdditionalNodeRequest.getName().substring(0,249));
} }
@ -930,7 +929,7 @@ public class FunctionalCaseMinderService {
@NotNull @NotNull
private FunctionalCaseModule buildModule(FunctionalCaseMinderEditRequest request, String userId, FunctionalCaseModuleEditRequest functionalCaseModuleEditRequest) { private FunctionalCaseModule buildModule(FunctionalCaseMinderEditRequest request, String userId, FunctionalCaseModuleEditRequest functionalCaseModuleEditRequest) {
FunctionalCaseModule functionalCaseModule = new FunctionalCaseModule(); FunctionalCaseModule functionalCaseModule = new FunctionalCaseModule();
functionalCaseModule.setId(IDGenerator.nextStr()); functionalCaseModule.setId(functionalCaseModuleEditRequest.getId());
if (StringUtils.isBlank(functionalCaseModuleEditRequest.getName())) { if (StringUtils.isBlank(functionalCaseModuleEditRequest.getName())) {
throw new MSException(Translator.get("api_definition_module.name.not_blank")); throw new MSException(Translator.get("api_definition_module.name.not_blank"));
} }
@ -1101,8 +1100,6 @@ public class FunctionalCaseMinderService {
private FunctionalCase addCase(FunctionalCaseMinderEditRequest request, String userId, FunctionalCaseChangeRequest functionalCaseChangeRequest, FunctionalCaseMapper caseMapper, Map<String, String> sourceIdAndInsertModuleIdMap) { private FunctionalCase addCase(FunctionalCaseMinderEditRequest request, String userId, FunctionalCaseChangeRequest functionalCaseChangeRequest, FunctionalCaseMapper caseMapper, Map<String, String> sourceIdAndInsertModuleIdMap) {
FunctionalCase functionalCase = new FunctionalCase(); FunctionalCase functionalCase = new FunctionalCase();
BeanUtils.copyBean(functionalCase, functionalCaseChangeRequest); BeanUtils.copyBean(functionalCase, functionalCaseChangeRequest);
String caseId = IDGenerator.nextStr();
functionalCase.setId(caseId);
if (StringUtils.isNotBlank(sourceIdAndInsertModuleIdMap.get(functionalCaseChangeRequest.getModuleId()))) { if (StringUtils.isNotBlank(sourceIdAndInsertModuleIdMap.get(functionalCaseChangeRequest.getModuleId()))) {
functionalCase.setModuleId(sourceIdAndInsertModuleIdMap.get(functionalCaseChangeRequest.getModuleId())); functionalCase.setModuleId(sourceIdAndInsertModuleIdMap.get(functionalCaseChangeRequest.getModuleId()));
} }
@ -1117,7 +1114,7 @@ public class FunctionalCaseMinderService {
functionalCase.setNum(functionalCaseService.getNextNum(request.getProjectId())); functionalCase.setNum(functionalCaseService.getNextNum(request.getProjectId()));
functionalCase.setReviewStatus(FunctionalCaseReviewStatus.UN_REVIEWED.name()); functionalCase.setReviewStatus(FunctionalCaseReviewStatus.UN_REVIEWED.name());
functionalCase.setPos(LIMIT_POS); functionalCase.setPos(LIMIT_POS);
functionalCase.setRefId(caseId); functionalCase.setRefId(functionalCaseChangeRequest.getId());
functionalCase.setLastExecuteResult(ExecStatus.PENDING.name()); functionalCase.setLastExecuteResult(ExecStatus.PENDING.name());
functionalCase.setLatest(true); functionalCase.setLatest(true);
functionalCase.setCreateUser(userId); functionalCase.setCreateUser(userId);

View File

@ -381,11 +381,12 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
request.setReviewId("TEST_MINDER_REVIEW_ID_GYQ"); request.setReviewId("TEST_MINDER_REVIEW_ID_GYQ");
request.setCurrent(1); request.setCurrent(1);
MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_REVIEW_LIST_URL, request); MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_REVIEW_LIST_URL, request);
String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); Pager<List<FunctionalMinderTreeDTO>> tableData = JSON.parseObject(JSON.toJSONString(
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
List<FunctionalMinderTreeDTO> baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); Pager.class);
Assertions.assertNotNull(baseTreeNodes);
Assertions.assertEquals(1, baseTreeNodes.size()); Assertions.assertNotNull(tableData.getList());
Assertions.assertEquals(1, tableData.getList().size());
request = new FunctionalCaseReviewMindRequest(); request = new FunctionalCaseReviewMindRequest();
request.setProjectId("project-case-minder-test"); request.setProjectId("project-case-minder-test");
request.setModuleId("TEST_MINDER_MODULE_ID_GYQ4"); request.setModuleId("TEST_MINDER_MODULE_ID_GYQ4");
@ -394,11 +395,11 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
request.setViewStatusFlag(true); request.setViewStatusFlag(true);
request.setCurrent(1); request.setCurrent(1);
mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_REVIEW_LIST_URL, request); mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_REVIEW_LIST_URL, request);
contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); tableData = JSON.parseObject(JSON.toJSONString(
resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); Pager.class);
Assertions.assertNotNull(baseTreeNodes); Assertions.assertNotNull(tableData.getList());
Assertions.assertEquals(1, baseTreeNodes.size()); Assertions.assertEquals(1, tableData.getList().size());
} }
@Test @Test
@ -410,12 +411,11 @@ public class FunctionalCaseMinderControllerTest extends BaseTest {
request.setPlanId("TEST_MINDER_PLAN_ID_1"); request.setPlanId("TEST_MINDER_PLAN_ID_1");
request.setCurrent(1); request.setCurrent(1);
MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_PLAN_LIST_URL, request); MvcResult mvcResultPage = this.requestPostWithOkAndReturn(FUNCTIONAL_CASE_PLAN_LIST_URL, request);
String contentAsString = mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8); Pager<List<FunctionalMinderTreeDTO>> tableData = JSON.parseObject(JSON.toJSONString(
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); JSON.parseObject(mvcResultPage.getResponse().getContentAsString(StandardCharsets.UTF_8), ResultHolder.class).getData()),
List<FunctionalMinderTreeDTO> baseTreeNodes = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), FunctionalMinderTreeDTO.class); Pager.class);
Assertions.assertNotNull(baseTreeNodes); Assertions.assertNotNull(tableData.getList());
Assertions.assertEquals(2, baseTreeNodes.size()); Assertions.assertEquals(2, tableData.getList().size());
System.out.println(baseTreeNodes);
} }
} }

View File

@ -675,18 +675,31 @@ export const getHashParameters = (): Record<string, string> => {
return params; return params;
}; };
let lastTimestamp = 0;
let sequence = 0;
/** /**
* id * id
* @returns * @returns
*/ */
export const getGenerateId = () => { export const getGenerateId = () => {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => { let timestamp = new Date().getTime();
// eslint-disable-next-line no-bitwise if (timestamp === lastTimestamp) {
const r = (Math.random() * 16) | 0; sequence++;
// eslint-disable-next-line no-bitwise if (sequence >= 100000) {
const v = c === 'x' ? r : (r & 0x3) | 0x8; // 如果超过999则重置为0等待下一秒
return v.toString(16); sequence = 0;
}); while (timestamp <= lastTimestamp) {
timestamp = new Date().getTime();
}
}
} else {
sequence = 0;
}
lastTimestamp = timestamp;
return timestamp.toString() + sequence.toString().padStart(5, '0');
}; };
/** /**