Commit 3df415ff by huangfusuper

批量接口查询

parent 61fdc56a
package com.byit.api;
import com.byit.dto.plugin.JobStatusResultDto;
import com.byit.service.ApiFlowStatusService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 工作流的状态查询
* @author huangfu
*/
@Api(tags = "工作流状态api")
@RestController
@RequestMapping("api/flow/status")
public class ApiFlowStatusController {
private final ApiFlowStatusService apiFlowStatusService;
public ApiFlowStatusController(ApiFlowStatusService apiFlowStatusService) {
this.apiFlowStatusService = apiFlowStatusService;
}
@PostMapping("findFlowResult")
public List<JobStatusResultDto> findFlowResult(String param){
return apiFlowStatusService.findJobStatus(param);
}
}
package com.byit.service;
import com.byit.dto.plugin.JobStatusResultDto;
import java.util.List;
/**
* 工作流状态查询接口
* @author huangfu
*/
public interface ApiFlowStatusService {
/**
* 工作流状态查询
* @param param 工作流参数
* @return 状态
*/
List<JobStatusResultDto> findJobStatus(String param);
}
package com.byit.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.byit.dto.FlowEntityCoreDto;
import com.byit.dto.FlowStatusCoreDto;
import com.byit.dto.plugin.JobStatusDto;
import com.byit.dto.plugin.JobStatusResultDto;
import com.byit.enums.TransferResultEnum;
import com.byit.job.exceptions.BusinessException;
import com.byit.job.utils.DateUtil;
import com.byit.mapper.RunRecordingMapper;
import com.byit.model.RunRecording;
import com.byit.model.Workspace;
import com.byit.service.ApiFlowStatusService;
import com.byit.service.WorkspaceService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 工作流状态查询接口
* @author huangfu
*/
@Service
public class ApiFlowStatusServiceImpl implements ApiFlowStatusService {
private final RunRecordingMapper runRecordingMapper;
private final WorkspaceService workspaceService;
public ApiFlowStatusServiceImpl(RunRecordingMapper runRecordingMapper, WorkspaceService workspaceService) {
this.runRecordingMapper = runRecordingMapper;
this.workspaceService = workspaceService;
}
@Override
public List<JobStatusResultDto> findJobStatus(String param) {
List<JobStatusResultDto> jobStatusResultDtos = new ArrayList<>();
if(StringUtils.isBlank(param)){
throw new BusinessException(TransferResultEnum.PARAM_ERROR);
}
//解析参数
List<JobStatusDto> jobStatusDto = JSON.parseArray(param, JobStatusDto.class);
//基于工作空间分组
Map<String, List<JobStatusDto>> stringListMap = jobStatusDto.stream().collect(Collectors.groupingBy(JobStatusDto::getWorkspaceName));
stringListMap.forEach((key,value) ->{
//设置查询条件
FlowStatusCoreDto flowStatusCoreDto = new FlowStatusCoreDto();
//查询对应的工作空间
Workspace byName = workspaceService.getByName(key);
if(byName != null){
flowStatusCoreDto.setWorkspaceId(byName.getWorkspaceId());
//获取子查询条件
List<FlowEntityCoreDto> flowEntityCoreDtos = value.stream().map(jobStatus -> {
FlowEntityCoreDto flowEntityCoreDto = new FlowEntityCoreDto();
flowEntityCoreDto.setFlowName(jobStatus.getJobName());
flowEntityCoreDto.setScheduleType(jobStatus.getScheduleType().getCode());
return flowEntityCoreDto;
}).collect(Collectors.toList());
flowStatusCoreDto.setFlowEntityCoreDtos(flowEntityCoreDtos);
//查询对应条件的实例
List<RunRecording> byFlowNameAndTypeAndWId = runRecordingMapper.findByFlowNameAndTypeAndWId(flowStatusCoreDto);
if(CollectionUtil.isNotEmpty(byFlowNameAndTypeAndWId)) {
//筛选当天数据
List<RunRecording> collect = byFlowNameAndTypeAndWId.stream().filter(byFlowName -> byFlowName.getTriggerTime() > DateUtil.getThisDayStartDate().getTime() && byFlowName.getTriggerTime() <= DateUtil.getThisDayEndDate().getTime()).collect(Collectors.toList());
if(CollectionUtil.isNotEmpty(collect)) {
collect.forEach(byFlowNameAndType ->{
JobStatusResultDto jobStatusResultDto = new JobStatusResultDto();
jobStatusResultDto.setFindDateTime(System.currentTimeMillis());
jobStatusResultDto.setEndTime(byFlowNameAndType.getEndTime().getTime());
jobStatusResultDto.setJobName(byFlowNameAndType.getFlowName());
jobStatusResultDto.setRunIng("4".equals(byFlowNameAndType.getFlowStatus()));
jobStatusResultDto.setStartDateTime(byFlowNameAndType.getStartTime().getTime());
jobStatusResultDtos.add(jobStatusResultDto);
});
}
}
}
});
return jobStatusResultDtos;
}
}
package com.byit.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
/**
* 工作流实体查询
* @author huangfu
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class FlowEntityCoreDto implements Serializable {
private String flowName;
private Integer scheduleType;
}
package com.byit.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.List;
/**
* 工作流状态查询核心条件
* @author huangfu
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class FlowStatusCoreDto implements Serializable {
private Integer workspaceId;
private List<FlowEntityCoreDto> flowEntityCoreDtos;
}
package com.byit.mapper; package com.byit.mapper;
import com.byit.dto.FlowConditionDto; import com.byit.dto.FlowConditionDto;
import com.byit.dto.FlowStatusCoreDto;
import com.byit.dto.StatisticsConditionDto; import com.byit.dto.StatisticsConditionDto;
import com.byit.dto.plugin.JobStatusDto;
import com.byit.dto.plugin.StatisticData; import com.byit.dto.plugin.StatisticData;
import com.byit.model.RunRecording; import com.byit.model.RunRecording;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -171,6 +173,14 @@ public interface RunRecordingMapper { ...@@ -171,6 +173,14 @@ public interface RunRecordingMapper {
@Param("scheduleStatusList")List<String> scheduleStatusList, @Param("scheduleStatusList")List<String> scheduleStatusList,
@Param("executeStatusList")List<String> executeStatusList); @Param("executeStatusList")List<String> executeStatusList);
/**
* 根据工作流名称 类型 工作空间名称 查询对应的示例
* @param flowStatusCoreDtos 工作流状态核心Dto
* @return 返回对应的示例
*/
List<RunRecording> findByFlowNameAndTypeAndWId(@Param("flowStatusCoreDtos") FlowStatusCoreDto flowStatusCoreDtos);
/** /**
* 获取运行实例 * 获取运行实例
* @param runId * @param runId
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment