diff --git a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java index 0f7f45e728..74db2ff2d2 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiScenarioReportService.java @@ -296,6 +296,7 @@ public class ApiScenarioReportService { if (testPlanApiScenario != null) { if (report != null) { testPlanApiScenario.setLastResult(report.getStatus()); + report.setScenarioId(testPlanApiScenario.getApiScenarioId()); } else { testPlanApiScenario.setLastResult(status); } @@ -507,7 +508,7 @@ public class ApiScenarioReportService { report.setEndTime(System.currentTimeMillis()); testPlanUiScenario.setUpdateTime(System.currentTimeMillis()); testPlanUiScenarioMapper.updateByPrimaryKeySelective(testPlanUiScenario); - if(scenario == null){ + if (scenario == null) { scenario = uiScenarioMapper.selectByPrimaryKey(testPlanUiScenario.getUiScenarioId()); } updateUiScenario(requestResults, dto, errorSize, status, report, scenario); @@ -936,10 +937,10 @@ public class ApiScenarioReportService { if (StringUtils.isNotEmpty(dto.getRunMode()) && dto.getRunMode().startsWith("UI")) { try { errorSize = dto.getRequestResults().stream().filter(requestResult -> - StringUtils.isNotEmpty(requestResult.getResponseResult().getHeaders()) - && JSONArray.parseArray(requestResult.getResponseResult().getHeaders()) .stream().filter( - r -> ((JSONObject) r).containsKey("success") && !((JSONObject) r).getBoolean("success") - ).count() > 0) + StringUtils.isNotEmpty(requestResult.getResponseResult().getHeaders()) + && JSONArray.parseArray(requestResult.getResponseResult().getHeaders()).stream().filter( + r -> ((JSONObject) r).containsKey("success") && !((JSONObject) r).getBoolean("success") + ).count() > 0) .count(); } catch (Exception e) { // UI 返回的结果在 headers 里面,格式不符合规范的直接认定结果为失败 diff --git a/backend/src/main/java/io/metersphere/commons/utils/DateUtils.java b/backend/src/main/java/io/metersphere/commons/utils/DateUtils.java index dcf0897a0f..5d4c045544 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/DateUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/DateUtils.java @@ -16,6 +16,7 @@ public class DateUtils { SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_PATTERM); return dateFormat.parse(dateString); } + public static Date getTime(String timeString) throws Exception { SimpleDateFormat dateFormat = new SimpleDateFormat(TIME_PATTERN); return dateFormat.parse(timeString); @@ -45,30 +46,31 @@ public class DateUtils { SimpleDateFormat dateFormat = new SimpleDateFormat(TIME_PATTERN); return dateFormat.format(timeStamp); } + public static String getDataStr(long timeStamp) { SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_PATTERM); return dateFormat.format(timeStamp); } - public static Date dateSum (Date date,int countDays){ + public static Date dateSum(Date date, int countDays) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); - calendar.add(Calendar.DAY_OF_MONTH,countDays); + calendar.add(Calendar.DAY_OF_MONTH, countDays); return calendar.getTime(); } - public static Date dateSum (Date date,int countUnit,int calendarType){ + public static Date dateSum(Date date, int countUnit, int calendarType) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date); - calendar.add(calendarType,countUnit); + calendar.add(calendarType, countUnit); return calendar.getTime(); } /** - * 获取入参日期所在周的周一周末日期。 日期对应的时间为当日的零点 + * 获取入参日期所在周。 日期对应的时间为当日的零点 * * @return Map(2); key取值范围:firstTime/lastTime */ @@ -76,13 +78,9 @@ public class DateUtils { Map returnMap = new HashMap<>(); Calendar calendar = Calendar.getInstance(); - //Calendar默认一周的开始是周日。业务需求从周一开始算,所以要"+1" - int weekDayAdd = 1; - try { calendar.setTime(date); calendar.set(Calendar.DAY_OF_WEEK, calendar.getActualMinimum(Calendar.DAY_OF_WEEK)); - calendar.add(Calendar.DAY_OF_MONTH,weekDayAdd); //第一天的时分秒是 00:00:00 这里直接取日期,默认就是零点零分 Date thisWeekFirstTime = getDate(getDateString(calendar.getTime())); @@ -90,12 +88,11 @@ public class DateUtils { calendar.clear(); calendar.setTime(date); calendar.set(Calendar.DAY_OF_WEEK, calendar.getActualMaximum(Calendar.DAY_OF_WEEK)); - calendar.add(Calendar.DAY_OF_MONTH,weekDayAdd); //最后一天的时分秒应当是23:59:59。 处理方式是增加一天计算日期再-1 - calendar.add(Calendar.DAY_OF_MONTH,1); + calendar.add(Calendar.DAY_OF_MONTH, 1); Date nextWeekFirstDay = getDate(getDateString(calendar.getTime())); - Date thisWeekLastTime = getTime(getTimeString(nextWeekFirstDay.getTime()-1)); + Date thisWeekLastTime = getTime(getTimeString(nextWeekFirstDay.getTime() - 1)); returnMap.put("firstTime", thisWeekFirstTime); returnMap.put("lastTime", thisWeekLastTime); @@ -108,18 +105,20 @@ public class DateUtils { /** * 获取当前时间或者当前时间+- 任意天数 时间的时间戳 + * * @param countDays * @return */ - public static Long getTimestamp(int countDays){ + public static Long getTimestamp(int countDays) { Date now = new Date(); - return dateSum (now,countDays).getTime()/1000*1000; + return dateSum(now, countDays).getTime() / 1000 * 1000; } /** * 获取当天的起始时间Date - * @param time 指定日期 例: 2020-12-13 06:12:42 - * @return 当天起始时间 例: 2020-12-13 00:00:00 + * + * @param time 指定日期 例: 2020-12-13 06:12:42 + * @return 当天起始时间 例: 2020-12-13 00:00:00 * @throws Exception */ public static Date getDayStartTime(Date time) throws Exception {