fix(UI自动化): 修复开源版任务中心报错问题

This commit is contained in:
zhangyong 2022-11-01 14:05:14 +08:00 committed by zhangyongfit2cloud
parent b82adc2412
commit 9183fdcb08
5 changed files with 56 additions and 22 deletions

View File

@ -0,0 +1,8 @@
package io.metersphere.base.mapper.ext;
import org.apache.ibatis.annotations.Param;
public interface BaseInformationSchemaTableMapper {
String checkExist(@Param("tableName") String tableName);
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.ext.BaseInformationSchemaTableMapper">
<select id="checkExist" resultType="java.lang.String">
select TABLE_NAME
from information_schema.TABLES
where TABLE_NAME = #{tableName}
</select>
</mapper>

View File

@ -8,7 +8,7 @@ import java.util.List;
public interface BaseTaskMapper { public interface BaseTaskMapper {
List<TaskCenterDTO> getTasks(@Param("request") TaskCenterRequest request); List<TaskCenterDTO> getTasks(@Param("request") TaskCenterRequest request, @Param("uiPermission") Boolean uiPermission);
int getRunningTasks(@Param("request") TaskCenterRequest request); int getRunningTasks(@Param("request") TaskCenterRequest request);

View File

@ -87,27 +87,29 @@
AND t.user_id = #{request.executor} AND t.user_id = #{request.executor}
</if> </if>
) )
UNION ALL <if test="uiPermission">
(SELECT t.id,t.name AS name ,'UI_SCENARIO' AS UNION ALL
executionModule,t.report_type, ifnull(t2.name,'LOCAL') AS actuator, t1.`name` AS executor,t.create_time AS (SELECT t.id,t.name AS name ,'UI_SCENARIO' AS
executionTime, t.trigger_mode AS triggerMode ,t.status AS executionStatus executionModule,t.report_type, ifnull(t2.name,'LOCAL') AS actuator, t1.`name` AS executor,t.create_time AS
FROM ui_scenario_report t INNER JOIN `user` t1 ON t.user_id = t1.id LEFT JOIN test_resource_pool t2 ON executionTime, t.trigger_mode AS triggerMode ,t.status AS executionStatus
t.actuator = t2.id FROM ui_scenario_report t INNER JOIN `user` t1 ON t.user_id = t1.id LEFT JOIN test_resource_pool t2 ON
WHERE to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) AND t.execute_type !='Debug' AND t.execute_type t.actuator = t2.id
!='Marge' AND t.project_id IN WHERE to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) AND t.execute_type !='Debug' AND t.execute_type
<foreach collection="request.projects" item="id" separator="," open="(" close=")"> !='Marge' AND t.project_id IN
#{id} <foreach collection="request.projects" item="id" separator="," open="(" close=")">
</foreach> #{id}
<if test="request.triggerMode != null and request.triggerMode != ''"> </foreach>
AND t.trigger_mode = #{request.triggerMode} <if test="request.triggerMode != null and request.triggerMode != ''">
AND t.trigger_mode = #{request.triggerMode}
</if>
<if test="request.executionStatus != null and request.executionStatus != ''">
AND t.status = #{request.executionStatus}
</if>
<if test="request.executor != null and request.executor != ''">
AND t.user_id = #{request.executor}
</if>
)
</if> </if>
<if test="request.executionStatus != null and request.executionStatus != ''">
AND t.status = #{request.executionStatus}
</if>
<if test="request.executor != null and request.executor != ''">
AND t.user_id = #{request.executor}
</if>
)
)tt ORDER BY tt.executionTime DESC )tt ORDER BY tt.executionTime DESC
</select> </select>

View File

@ -1,5 +1,6 @@
package io.metersphere.task.service; package io.metersphere.task.service;
import io.metersphere.base.mapper.ext.BaseInformationSchemaTableMapper;
import io.metersphere.base.mapper.ext.BaseScheduleMapper; import io.metersphere.base.mapper.ext.BaseScheduleMapper;
import io.metersphere.base.mapper.ext.BaseTaskMapper; import io.metersphere.base.mapper.ext.BaseTaskMapper;
import io.metersphere.commons.constants.MicroServiceName; import io.metersphere.commons.constants.MicroServiceName;
@ -30,6 +31,8 @@ public class TaskService {
@Resource @Resource
private BaseScheduleMapper baseScheduleMapper; private BaseScheduleMapper baseScheduleMapper;
@Resource @Resource
private BaseInformationSchemaTableMapper baseInformationSchemaTableMapper;
@Resource
private BaseCheckPermissionService baseCheckPermissionService; private BaseCheckPermissionService baseCheckPermissionService;
@Resource @Resource
private MicroService microService; private MicroService microService;
@ -38,6 +41,7 @@ public class TaskService {
private static final String PERF = "PERFORMANCE"; private static final String PERF = "PERFORMANCE";
private static final String UI = "UI_SCENARIO"; private static final String UI = "UI_SCENARIO";
private static final String UI_SCENARIO_REPORT = "ui_scenario_report";
public List<String> getOwnerProjectIds(String userId) { public List<String> getOwnerProjectIds(String userId) {
Set<String> userRelatedProjectIds = null; Set<String> userRelatedProjectIds = null;
@ -56,7 +60,7 @@ public class TaskService {
if (CollectionUtils.isEmpty(request.getProjects())) { if (CollectionUtils.isEmpty(request.getProjects())) {
return new ArrayList<>(); return new ArrayList<>();
} }
return baseTaskMapper.getTasks(request); return baseTaskMapper.getTasks(request,checkUiPermission());
} }
public int getRunningTasks(TaskCenterRequest request) { public int getRunningTasks(TaskCenterRequest request) {
@ -110,4 +114,15 @@ public class TaskService {
microService.postForData(MicroServiceName.API_TEST, "/api/automation/stop/batch", reportIds); microService.postForData(MicroServiceName.API_TEST, "/api/automation/stop/batch", reportIds);
} }
} }
private boolean checkUiPermission(){
try {
String uiScenarioReport = baseInformationSchemaTableMapper.checkExist(UI_SCENARIO_REPORT);
if(StringUtils.isNotEmpty(uiScenarioReport)){
return true;
}
}catch (Exception e){
}
return false;
}
} }