diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index c6651c55f2..7917a3f2b9 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -168,20 +168,35 @@ public class TestPlanService { public int editTestPlan(TestPlanDTO testPlan) { editTestPlanProject(testPlan); - testPlan.setUpdateTime(System.currentTimeMillis()); checkTestPlanExist(testPlan); - //进行中状态,写入实际开始时间 - if (TestPlanStatus.Underway.name().equals(testPlan.getStatus())) { - testPlan.setActualStartTime(System.currentTimeMillis()); - } else if (TestPlanStatus.Completed.name().equals(testPlan.getStatus())) { - //已完成,写入实际完成时间 - testPlan.setActualEndTime(System.currentTimeMillis()); - + TestPlan res = testPlanMapper.selectByPrimaryKey(testPlan.getId()); // 先查一次库 + if (!res.getStatus().equals(testPlan.getStatus())) { // 若有改变才更新时间 + res.setUpdateTime(System.currentTimeMillis()); + if (TestPlanStatus.Underway.name().equals(testPlan.getStatus())) { + if (res.getStatus().equals(TestPlanStatus.Prepare.name())) { + res.setActualStartTime(System.currentTimeMillis()); + } // 未开始->进行中,写入实际开始时间 + else if (res.getStatus().equals(TestPlanStatus.Completed.name())) { + res.setActualEndTime(null); + } // 已完成->进行中,结束时间置空 + } + else if (!res.getStatus().equals(TestPlanStatus.Prepare.name()) && + testPlan.getStatus().equals(TestPlanStatus.Prepare.name())) { + res.setActualStartTime(null); + res.setActualEndTime(null); + } // 非未开始->未开始,时间都置空 + else if (TestPlanStatus.Completed.name().equals(testPlan.getStatus()) && + !TestPlanStatus.Completed.name().equals(res.getStatus())) { + //已完成,写入实际完成时间 + res.setActualEndTime(System.currentTimeMillis()); + } + res.setStatus(testPlan.getStatus()); } + List userIds = new ArrayList<>(); userIds.add(testPlan.getPrincipal()); AddTestPlanRequest testPlans = new AddTestPlanRequest(); - int i = testPlanMapper.updateByPrimaryKeySelective(testPlan); + int i = testPlanMapper.updateByPrimaryKey(res); // 更新 if (!StringUtils.isBlank(testPlan.getStatus())) { BeanUtils.copyBean(testPlans, getTestPlan(testPlan.getId())); String context = getTestPlanContext(testPlans, NoticeConstants.Event.UPDATE); diff --git a/frontend/src/business/components/track/plan/components/TestPlanList.vue b/frontend/src/business/components/track/plan/components/TestPlanList.vue index b6f68ba8c7..80fa8678ba 100644 --- a/frontend/src/business/components/track/plan/components/TestPlanList.vue +++ b/frontend/src/business/components/track/plan/components/TestPlanList.vue @@ -257,7 +257,17 @@ export default { statusChange(param) { this.$post('/test/plan/edit', param, () => { for (let i = 0; i < this.tableData.length; i++) { - if (this.tableData[i].id == param.id) { + if (this.tableData[i].id == param.id) { // 手动修改当前状态后,前端结束时间先用当前时间,等刷新后变成后台数据(相等) + if (this.tableData[i].status !== "Completed" && param.status === "Completed") { + this.tableData[i].actualEndTime = new Date(); + } // 非完成->已完成,结束时间=null + else if (this.tableData[i].status !== "Underway" && param.status === "Underway") { + this.tableData[i].actualStartTime = new Date(); + this.tableData[i].actualEndTime = ""; + } // 非进行中->进行中,结束时间=null + else if (this.tableData[i].status !== "Prepare" && param.status === "Prepare") { + this.tableData[i].actualStartTime = this.tableData[i].actualEndTime = ""; + } // 非未开始->未开始,结束时间=null this.tableData[i].status = param.status; break; }