fix(测试跟踪): 测试计划批量执行功能用例后,功能用例没有对应的变更记录

--bug=1028162 --user=陈建星 【测试跟踪】测试计划关联功能用例-批量编辑执行结果-功能用例变更记录没内容 https://www.tapd.cn/55049933/s/1398419
This commit is contained in:
jianxing 2023-07-27 15:53:55 +08:00 committed by jianxing
parent 9e9369d716
commit 3e80901b0e
5 changed files with 57 additions and 7 deletions

View File

@ -170,4 +170,6 @@ public interface ExtTestCaseMapper {
void clearLatestVersion(@Param("refId") String refId);
List<TestCaseTest> getTestCaseRelateList(@Param("testCaseId") String testCaseId);
List<TestCase> getTestCaseForLastResultLog(@Param("ids") List<String> ids);
}

View File

@ -1469,7 +1469,14 @@
SET latest = 0
where ref_id = #{refId}
</update>
<select id="getTestCaseForLastResultLog" resultType="io.metersphere.base.domain.TestCase">
select tc.id, tc.name, tc.last_execute_result
from test_case tc where tc.id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
and (tc.status is null or tc.status != 'Trash')
</select>
<select id="getTestCaseRelateList" resultType="io.metersphere.base.domain.TestCaseTest" parameterType="java.lang.String">
SELECT
test_case_test.test_case_id as testCaseId,

View File

@ -123,7 +123,7 @@ public class TestPlanTestCaseController {
@PostMapping("/edit")
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_PLAN_READ_RUN)
@MsAuditLog(module = OperLogModule.TRACK_TEST_CASE_REVIEW, type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#testPlanTestCase.id)", content = "#msClass.getLogDetails(#testPlanTestCase.id)", msClass = TestPlanTestCaseService.class)
@MsAuditLog(module = OperLogModule.TRACK_TEST_PLAN, type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#testPlanTestCase.id)", content = "#msClass.getLogDetails(#testPlanTestCase.id)", msClass = TestPlanTestCaseService.class)
public void editTestCase(@RequestBody TestPlanFuncCaseEditRequest testPlanTestCase) {
testPlanTestCaseService.editTestCase(testPlanTestCase);
}

View File

@ -481,7 +481,6 @@ public class TestPlanTestCaseService {
TestPlanTestCaseWithBLOBs planTestCaseWithBLOBs = testPlanTestCaseMapper.selectByPrimaryKey(id);
if (planTestCaseWithBLOBs != null) {
TestCase testCase = testCaseMapper.selectByPrimaryKey(planTestCaseWithBLOBs.getCaseId());
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(planTestCaseWithBLOBs.getPlanId());
List<DetailColumn> columns = new LinkedList<>();
DetailColumn executeStatusColumn = new DetailColumn("状态", "lastExecuteResult", StatusReference.statusMap.get(testCase.getLastExecuteResult()), null);
columns.add(executeStatusColumn);

View File

@ -27,9 +27,11 @@ import io.metersphere.excel.listener.TestCasePretreatmentListener;
import io.metersphere.excel.utils.EasyExcelExporter;
import io.metersphere.excel.utils.ExcelImportType;
import io.metersphere.i18n.Translator;
import io.metersphere.log.service.OperatingLogService;
import io.metersphere.log.utils.ReflexObjectUtil;
import io.metersphere.log.vo.DetailColumn;
import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.StatusReference;
import io.metersphere.log.vo.track.TestCaseReference;
import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.service.TestPlanTestCaseService;
@ -190,6 +192,8 @@ public class TestCaseService {
private ExtTestAnalysisMapper extTestAnalysisMapper;
@Resource
private PlatformPluginService platformPluginService;
@Resource
private OperatingLogService operatingLogService;
private ThreadLocal<Integer> importCreateNum = new ThreadLocal<>();
@ -268,6 +272,7 @@ public class TestCaseService {
/**
* 用例变更时调用插件的需求变更的方法
*
* @param request
* @param type
* @param project
@ -469,7 +474,7 @@ public class TestCaseService {
}
public TestCaseWithBLOBs editTestCase(EditTestCaseRequest testCase) {
return editTestCase(testCase, true);
return editTestCase(testCase, true);
}
/**
@ -1138,7 +1143,7 @@ public class TestCaseService {
errList = xmindParser.parse(multipartFile);
List<TestCaseWithBLOBs> testCase = xmindParser.getTestCase();
testCase.forEach(testCaseWithBLOBs -> {
testCaseWithBLOBs.setSteps(testCaseWithBLOBs.getSteps().replace("&amp;","&"));
testCaseWithBLOBs.setSteps(testCaseWithBLOBs.getSteps().replace("&amp;", "&"));
});
if (CollectionUtils.isEmpty(xmindParser.getNodePaths())
&& CollectionUtils.isEmpty(xmindParser.getTestCase())
@ -1282,7 +1287,7 @@ public class TestCaseService {
public void saveImportData(List<TestCaseWithBLOBs> testCases, TestCaseImportRequest request,
Map<String, List<CustomFieldResourceDTO>> testCaseCustomFieldMap) {
saveImportData( testCases, request, testCaseCustomFieldMap, null);
saveImportData(testCases, request, testCaseCustomFieldMap, null);
}
public void saveImportData(List<TestCaseWithBLOBs> testCases, TestCaseImportRequest request,
@ -1966,7 +1971,7 @@ public class TestCaseService {
}
if (StringUtils.isNotBlank(field.getValue())) {
Object value = JSON.parseObject(field.getValue());
if (value == null) {
if (value == null) {
continue;
}
Map<String, String> optionMap = customSelectValueMap.get(id);
@ -3001,6 +3006,7 @@ public class TestCaseService {
public void updateLastExecuteStatus(List<String> ids, String status) {
if (CollectionUtils.isNotEmpty(ids) && StringUtils.isNotBlank(status)) {
addBatchLastExecuteResultChangeLog(ids, status);
TestCaseExample example = new TestCaseExample();
example.createCriteria().andIdIn(ids);
TestCaseWithBLOBs testCase = new TestCaseWithBLOBs();
@ -3009,6 +3015,42 @@ public class TestCaseService {
}
}
/**
* 测试计划功能用例页面和脑图页面批量修改执行结果时记录下操作日志用例的变更日志需要查看
* @param ids
* @param status
*/
public void addBatchLastExecuteResultChangeLog(List<String> ids, String status) {
TestCaseExample testCaseExample = new TestCaseExample();
testCaseExample.createCriteria().andIdIn(ids);
List<TestCase> testCases = extTestCaseMapper.getTestCaseForLastResultLog(ids);
testCases.forEach(testCase -> {
try {
OperatingLogWithBLOBs log = new OperatingLogWithBLOBs();
log.setOperTitle(testCase.getName());
log.setOperContent(testCase.getName());
log.setId(UUID.randomUUID().toString());
log.setOperType(OperLogConstants.UPDATE.name());
log.setOperModule(OperLogModule.TRACK_TEST_PLAN);
log.setProjectId(SessionUtils.getCurrentProjectId());
List<DetailColumn> columns = new LinkedList<>();
DetailColumn executeStatusColumn = new DetailColumn("状态", "lastExecuteResult",
StatusReference.statusMap.get(testCase.getLastExecuteResult()), StatusReference.statusMap.get(status));
columns.add(executeStatusColumn);
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(testCase.getId()), testCase.getProjectId(), testCase.getName(),
SessionUtils.getUserId(), columns);
log.setOperContent(JSON.toJSONString(details));
log.setOperTime(System.currentTimeMillis());
log.setCreateUser(SessionUtils.getUserId());
log.setOperUser(SessionUtils.getUserId());
log.setSourceId(testCase.getId());
operatingLogService.create(log, log.getSourceId());
} catch (Exception e) {
LogUtil.error(e);
}
});
}
public void updateLastExecuteStatus(String id, String status) {
if (StringUtils.isNotBlank(id) && StringUtils.isNotBlank(status)) {
this.updateLastExecuteStatus(Arrays.asList(id), status);