18 changed files with 257 additions and 23 deletions
@ -0,0 +1,22 @@ |
|||
package org.dromara.workflow.api.domain; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class FlowDepartVo { |
|||
|
|||
|
|||
private Long id; |
|||
|
|||
/** |
|||
* 流程类型 |
|||
*/ |
|||
private String flowType; |
|||
|
|||
/** |
|||
* 流程编码 |
|||
*/ |
|||
private String flowCode; |
|||
|
|||
|
|||
} |
@ -0,0 +1,74 @@ |
|||
package org.dromara.business.controller; |
|||
|
|||
import cn.hutool.core.collection.ListUtil; |
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|||
import io.swagger.v3.oas.annotations.Operation; |
|||
import io.swagger.v3.oas.annotations.tags.Tag; |
|||
import lombok.RequiredArgsConstructor; |
|||
import org.apache.dubbo.config.annotation.DubboReference; |
|||
import org.dromara.business.domain.BusinessAlert; |
|||
import org.dromara.business.mapper.BusinessAlertMapper; |
|||
import org.dromara.business.service.IBusinessAlertService; |
|||
import org.dromara.business.utils.BatchProcessorUtil; |
|||
import org.dromara.common.core.domain.R; |
|||
import org.dromara.common.core.utils.StringUtils; |
|||
import org.dromara.common.web.core.BaseController; |
|||
import org.dromara.system.api.domain.vo.RemoteAiLabelPostVo; |
|||
import org.dromara.workflow.api.RemoteWorkflowService; |
|||
import org.dromara.workflow.api.domain.RemoteStartProcess; |
|||
import org.dromara.workflow.api.domain.RemoteStartProcessReturn; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RequestParam; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.List; |
|||
import java.util.concurrent.CompletableFuture; |
|||
import java.util.concurrent.ExecutorService; |
|||
import java.util.concurrent.Executors; |
|||
import java.util.concurrent.TimeUnit; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@RequiredArgsConstructor |
|||
@RestController |
|||
@RequestMapping("/fix") |
|||
@Tag(name = "fix") |
|||
public class FixController extends BaseController { |
|||
|
|||
@DubboReference(timeout = 30000) |
|||
RemoteWorkflowService remoteWorkflowService; |
|||
|
|||
private final BusinessAlertMapper baseMapper; |
|||
|
|||
@Operation(summary ="生成流程",description = "生成流程") |
|||
@GetMapping("startFlow") |
|||
public R<Void> startFlow(@RequestParam String flowCode) { |
|||
LambdaQueryWrapper<BusinessAlert> wrapper = new LambdaQueryWrapper<>(); |
|||
wrapper.eq(BusinessAlert::getHandleType,"verify"); |
|||
wrapper.in(BusinessAlert::getLabelEn,"plough","towns"); |
|||
List<BusinessAlert> businessAlerts = baseMapper.selectList(wrapper); |
|||
|
|||
List<BusinessAlert> alertList = ListUtil.sub(businessAlerts, 0, 10); |
|||
|
|||
List<RemoteStartProcess> flowList = alertList.stream() |
|||
.map(alert -> { |
|||
RemoteStartProcess remoteStartProcess = new RemoteStartProcess(); |
|||
remoteStartProcess.setFlowCode(flowCode); |
|||
remoteStartProcess.setBusinessId(alert.getId()); |
|||
return remoteStartProcess; |
|||
}) |
|||
.collect(Collectors.toList()); |
|||
|
|||
// 分批处理
|
|||
int startIndex = 0; // 从第 0 条开始
|
|||
int batchSize = 5; // 每批处理 5 条
|
|||
boolean flag = BatchProcessorUtil.processBatches(flowList, batchSize, startIndex, batch -> { |
|||
//批量新增部门区域数据
|
|||
remoteWorkflowService.startWorkFlowBatch(batch); |
|||
}); |
|||
|
|||
|
|||
return toAjax(flag); |
|||
} |
|||
|
|||
} |
@ -1,7 +1,15 @@ |
|||
package org.dromara.workflow.mapper; |
|||
|
|||
import jakarta.validation.constraints.NotNull; |
|||
import org.apache.ibatis.annotations.Param; |
|||
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; |
|||
import org.dromara.workflow.domain.FlowDepart; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
public interface FlwDepartMapper extends BaseMapperPlus<FlowDepart, FlowDepart> { |
|||
FlowDepart getFlowDepart(@Param("deptId") Long deptId); |
|||
|
|||
Integer checkFlowDepart(@Param("deptIds") List<Long> departIds); |
|||
} |
|||
|
@ -0,0 +1,39 @@ |
|||
package org.dromara.workflow.utils; |
|||
|
|||
import java.util.List; |
|||
import java.util.function.Consumer; |
|||
|
|||
/** |
|||
* 分批处理工具类 |
|||
*/ |
|||
public class BatchProcessorUtil { |
|||
|
|||
/** |
|||
* 分批处理数据 |
|||
* |
|||
* @param dataList 数据集合 |
|||
* @param batchSize 每批处理的数据量 |
|||
* @param startIndex 起始位置 |
|||
* @param batchHandler 每批数据的处理逻辑 |
|||
* @return 下一次的起始位置 |
|||
*/ |
|||
public static <T> boolean processBatches(List<T> dataList, int batchSize, int startIndex, Consumer<List<T>> batchHandler) { |
|||
if (dataList == null || dataList.isEmpty()) { |
|||
return true; // 数据为空,直接返回当前起始位置
|
|||
} |
|||
|
|||
int totalSize = dataList.size(); |
|||
while (startIndex < totalSize) { |
|||
int endIndex = Math.min(startIndex + batchSize, totalSize); |
|||
List<T> batch = dataList.subList(startIndex, endIndex); |
|||
|
|||
// 处理当前批次的数据
|
|||
batchHandler.accept(batch); |
|||
|
|||
// 更新起始位置
|
|||
startIndex = endIndex; |
|||
} |
|||
|
|||
return startIndex >= totalSize; // 返回下一次的起始位置
|
|||
} |
|||
} |
Loading…
Reference in new issue