Skip to content
Merged

Dev #81

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.codingapi.example.handler;

import com.codingapi.flow.event.FlowRecordUrgeEvent;
import com.codingapi.springboot.framework.event.IHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MyFlowRecordUrgeEventHandler implements IHandler<FlowRecordUrgeEvent> {

@Override
public void handler(FlowRecordUrgeEvent event) {
log.info("催办 event:{}",event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public class UrgeInterval {
public UrgeInterval(FlowRecord flowRecord) {
this.processId = flowRecord.getProcessId();
this.recordId = flowRecord.getId();
this.createTime = flowRecord.getCreateTime();
this.createTime = System.currentTimeMillis();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static FlowStateException nodeNotSupportRevoke() {
*
* @return exception
*/
public static FlowStateException recordNotSupportUrge() {
return new FlowStateException("record.notSupportUrge", "record not support urge");
public static FlowStateException recordLimitUrgeError() {
return new FlowStateException("record.urge.limit", "record urge limit error");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public long getTimeoutTime() {
/**
* 是否可合并
*/
public boolean isMergeable() {
public boolean isEnableMergeable() {
List<INodeStrategy> strategies = this.strategies;
for (INodeStrategy strategy : strategies) {
if (strategy instanceof RecordMergeStrategy) {
Expand All @@ -48,6 +48,19 @@ public boolean isMergeable() {
return false;
}

/**
* 是否支持撤回
*/
public boolean isEnableRevoke(){
List<INodeStrategy> strategies = this.strategies;
for (INodeStrategy strategy : strategies) {
if (strategy instanceof RevokeStrategy) {
return ((RevokeStrategy) strategy).isEnable();
}
}
return false;
}

/**
* 是否按顺序执行的审批策略
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void fillNewRecord(FlowSession session, FlowRecord flowRecord) {
NodeStrategyManager nodeStrategyManager = this.strategyManager();
flowRecord.setTitle(nodeStrategyManager.generateTitle(session));
flowRecord.setTimeoutTime(nodeStrategyManager.getTimeoutTime());
flowRecord.setMergeable(nodeStrategyManager.isMergeable());
flowRecord.setMergeable(nodeStrategyManager.isEnableMergeable());
flowRecord.newRecord();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class FlowContent {
/**
* 流程按钮
*/
private List<Map<String,Object>> actions;
private List<Map<String, Object>> actions;

/**
* 是否可合并
Expand Down Expand Up @@ -130,6 +130,44 @@ public class FlowContent {
*/
private List<NodeOption> nodes;

/**
* 支持撤销
*/
private boolean revoke;

/**
* 支持催办
*/
private boolean urge;


/**
* 设置操作动作按钮
*
*/
public void setOperationAction(Workflow workflow, FlowRecord flowRecord) {
if (flowRecord == null) {
this.revoke = false;
this.urge = false;
} else {
if (flowRecord.isFinish()) {
this.revoke = false;
this.urge = false;
}

if (flowRecord.isTodo()) {
this.revoke = false;
this.urge = false;
}

if (flowRecord.isDone() && !flowRecord.isFinish()) {
IFlowNode node = workflow.getFlowNode(flowRecord.getNodeId());
this.revoke = node.strategyManager().isEnableRevoke();
this.urge = workflow.strategyManager().isEnableUrge();
}
}
}


public void pushCurrentNode(IFlowNode currentNode) {
ActionManager actionManager = currentNode.actionManager();
Expand All @@ -141,7 +179,7 @@ public void pushCurrentNode(IFlowNode currentNode) {
this.nodeName = currentNode.getName();
this.nodeType = currentNode.getType();
this.fieldPermissions = strategyManager.getFieldPermissions();
Map<String,Object> nodeData = currentNode.toMap();
Map<String, Object> nodeData = currentNode.toMap();
this.view = (String) nodeData.get("view");
}

Expand All @@ -162,7 +200,7 @@ public void pushRecords(FlowRecord record, List<FlowRecord> mergeRecords) {
this.title = record.getTitle();

this.todos = new ArrayList<>();
for (FlowRecord item : mergeRecords){
for (FlowRecord item : mergeRecords) {
Body body = new Body();
body.setRecordId(item.getId());
body.setTitle(item.getTitle());
Expand All @@ -173,9 +211,9 @@ public void pushRecords(FlowRecord record, List<FlowRecord> mergeRecords) {
}
}

public void pushHistory(Workflow workflow,List<FlowRecord> historyRecords) {
public void pushHistory(Workflow workflow, List<FlowRecord> historyRecords) {
this.histories = new ArrayList<>();
for (FlowRecord item : historyRecords){
for (FlowRecord item : historyRecords) {
IFlowNode node = workflow.getFlowNode(item.getNodeId());
History history = new History();
history.setRecordId(item.getId());
Expand All @@ -193,18 +231,18 @@ public void pushHistory(Workflow workflow,List<FlowRecord> historyRecords) {

public void pushCurrentOperator(IFlowOperator currentOperator) {
this.currentOperator = new FlowOperator(currentOperator);
this.createOperator = new FlowOperator(currentOperator);
this.createOperator = new FlowOperator(currentOperator);
}


@Data
public static class History{
public static class History {
/**
* 流程编号
*/
private long recordId;
/**
* 流程标题
* 流程标题
*/
private String title;

Expand Down Expand Up @@ -246,15 +284,15 @@ public static class History{
@Data
public static class Body {
/**
* 流程记录编号
* 流程记录编号
*/
private long recordId;
/**
* 流程标题
* 流程标题
*/
private String title;
/**
* 表单数据
* 表单数据
*/
private Map<String, Object> data;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public class FlowRecord {
private long timeoutTime;
/**
* 是否可合并
* {@link FlowRecord#getMergeKey()}
* {@link FlowRecord#getTodoKey()}
*/
private boolean mergeable;
/**
Expand Down Expand Up @@ -247,7 +247,7 @@ public class FlowRecord {
* 数据合并的依据,当开启时值为固定值,否则为随机数据
* 相同的 {@link FlowRecord#currentOperatorId} {@link FlowRecord#workRuntimeId} {@link FlowRecord#nodeId}字段的数据合并到一条记录上。
*/
public String getMergeKey() {
public String getTodoKey() {
if (mergeable) {
return String.format("%s-%s-%s", currentOperatorId, workRuntimeId, nodeId);
} else {
Expand Down Expand Up @@ -461,7 +461,7 @@ public void notifyRecord(FlowSession flowSession) {
NodeStrategyManager nodeStrategyManager = currentNode.strategyManager();
this.setTitle(nodeStrategyManager.generateTitle(flowSession));
this.setTimeoutTime(nodeStrategyManager.getTimeoutTime());
this.setMergeable(nodeStrategyManager.isMergeable());
this.setMergeable(nodeStrategyManager.isEnableMergeable());
this.update(flowSession, true);
this.notify = true;
this.forwardOperatorId = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class FlowTodoRecord {

/**
* 合并记录id,当存在合并记录数据时待办记录数量不会增加,内容会更新至最新的待办数据信息。
* {@link FlowRecord#getMergeKey()}
* {@link FlowRecord#getTodoKey()}
*/
private String mergeKey;

Expand Down Expand Up @@ -126,7 +126,7 @@ public void update(FlowRecord flowRecord) {
this.createTime = flowRecord.getCreateTime();
this.createOperatorId = flowRecord.getCreateOperatorId();
this.createOperatorName = flowRecord.getCreateOperatorName();
this.mergeKey = flowRecord.getMergeKey();
this.mergeKey = flowRecord.getTodoKey();
this.mergeable = flowRecord.isMergeable();
this.recordId = flowRecord.getId();
this.timeoutTime = flowRecord.getTimeoutTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface FlowTodoRecordRepository {

void saveAll(List<FlowTodoRecord> margeRecords);

FlowTodoRecord getByMergeKey(String key);
FlowTodoRecord getByTodoKey(String key);

void delete(FlowTodoRecord margeRecord);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void saveTodoMargeRecords() {
List<FlowTodoRecord> flowTodoRecords = new ArrayList<>();
for (FlowRecord flowRecord : flowRecords) {
if (flowRecord.isTodo()) {
FlowTodoRecord todoMargeRecord = flowTodoRecordRepository.getByMergeKey(flowRecord.getMergeKey());
FlowTodoRecord todoMargeRecord = flowTodoRecordRepository.getByTodoKey(flowRecord.getTodoKey());
if (todoMargeRecord == null) {
todoMargeRecord = new FlowTodoRecord(flowRecord);
} else {
Expand Down Expand Up @@ -83,7 +83,7 @@ private void removeTodoMergeRecords() {
for (FlowRecord flowRecord : flowRecords) {
if (flowRecord.isDone()) {
if (flowRecord.isMergeable()) {
FlowTodoRecord todoMargeRecord = flowTodoRecordRepository.getByMergeKey(flowRecord.getMergeKey());
FlowTodoRecord todoMargeRecord = flowTodoRecordRepository.getByTodoKey(flowRecord.getTodoKey());
if (todoMargeRecord != null) {
List<FlowTodoMerge> margeRelations = flowTodoMergeRepository.findByTodoId(todoMargeRecord.getId());
if (margeRelations != null && !margeRelations.isEmpty()) {
Expand All @@ -101,7 +101,14 @@ private void removeTodoMergeRecords() {
}
}
} else {
FlowTodoRecord flowTodoRecord = flowTodoRecordRepository.getByMergeKey(flowRecord.getMergeKey());
FlowTodoRecord flowTodoRecord = flowTodoRecordRepository.getByTodoKey(flowRecord.getTodoKey());
if (flowTodoRecord != null) {
flowTodoRecordRepository.delete(flowTodoRecord);
}
}
}else {
if(flowRecord.isRevoked()){
FlowTodoRecord flowTodoRecord = flowTodoRecordRepository.getByTodoKey(flowRecord.getTodoKey());
if (flowTodoRecord != null) {
flowTodoRecordRepository.delete(flowTodoRecord);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void saveFlowRecord(FlowRecord flowRecord) {
* @return 流程合并记录
*/
public List<FlowRecord> getMergeRecord(String mergeKey){
FlowTodoRecord todoRecord = flowTodoRecordRepository.getByMergeKey(mergeKey);
FlowTodoRecord todoRecord = flowTodoRecordRepository.getByTodoKey(mergeKey);
List<FlowTodoMerge> todoMerges = flowTodoMergeRepository.findByTodoId(todoRecord.getId());
return this.findFlowRecordByIds(todoMerges.stream().map(FlowTodoMerge::getRecordId).toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ private void loadWorkflow(){

private void loadTodoFlowRecords(){
if(this.flowRecord!=null){
if(this.flowRecord.isMergeable()){
List<FlowRecord> margeRecords = flowRecordService.getMergeRecord(flowRecord.getMergeKey());
if(this.flowRecord.isMergeable() && this.flowRecord.isTodo()){
List<FlowRecord> margeRecords = flowRecordService.getMergeRecord(flowRecord.getTodoKey());
this.flowContent.pushRecords(this.flowRecord, margeRecords);
}else {
this.flowContent.pushRecords(this.flowRecord,List.of(this.flowRecord));
Expand Down Expand Up @@ -122,6 +122,8 @@ public FlowContent create() {
this.loadCurrentNode();
this.loadTodoFlowRecords();
this.loadHistoryRecords();

flowContent.setOperationAction(this.workflow,this.flowRecord);
return flowContent;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void urge() {
if (strategyManager.isEnableUrge()) {
UrgeStrategy urgeStrategy = strategyManager.getStrategy(UrgeStrategy.class);
if (!urgeStrategy.hasUrge(urgeInterval)) {
throw FlowStateException.recordNotSupportUrge();
throw FlowStateException.recordLimitUrgeError();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static UrgeStrategy fromMap(Map<String, Object> map) {
}

/**
* 是否有催办
* 是否可催办
*/
public boolean hasUrge(UrgeInterval urgeInterval) {
long interval = this.interval * 1000L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void delete(FlowTodoRecord margeRecord) {
}

@Override
public FlowTodoRecord getByMergeKey(String key) {
public FlowTodoRecord getByTodoKey(String key) {
return cacheByMageKey.get(key);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void mergeableRecords() {
assertEquals(count, bossRecordList.size());
assertEquals(count, bossRecordList.stream().filter(FlowRecord::isMergeable).toList().size());

List<String> mergeIdList = bossRecordList.stream().map(FlowRecord::getMergeKey).toList();
List<String> mergeIdList = bossRecordList.stream().map(FlowRecord::getTodoKey).toList();
Set<String> set = new HashSet<>(mergeIdList);
assertEquals(1,set.size());

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.codingapi.flow.api.controller;

import com.codingapi.flow.operator.IFlowOperator;
import com.codingapi.flow.pojo.request.FlowActionRequest;
import com.codingapi.flow.pojo.request.FlowCreateRequest;
import com.codingapi.flow.pojo.request.FlowDetailRequest;
import com.codingapi.flow.pojo.request.FlowProcessNodeRequest;
import com.codingapi.flow.pojo.request.*;
import com.codingapi.flow.pojo.response.FlowContent;
import com.codingapi.flow.pojo.response.ProcessNode;
import com.codingapi.flow.service.FlowService;
Expand Down Expand Up @@ -45,6 +42,21 @@ public SingleResponse<Long> create(@RequestBody FlowCreateRequest request) {
}


@PostMapping("/urge")
public Response urge(@RequestBody IdRequest request) {
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();
flowService.urge(new FlowUrgeRequest(request.getLongId(),current.getUserId()));
return Response.buildSuccess();
}

@PostMapping("/revoke")
public Response revoke(@RequestBody IdRequest request) {
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();
flowService.revoke(new FlowRevokeRequest(request.getLongId(),current.getUserId()));
return Response.buildSuccess();
}


@PostMapping("/action")
public Response action(@RequestBody FlowActionRequest request) {
IFlowOperator current = (IFlowOperator) UserContext.getInstance().current();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class FlowTodoRecordEntity {

/**
* 合并记录id,当存在合并记录数据时待办记录数量不会增加,内容会更新至最新的待办数据信息。
* {@link FlowRecord#getMergeKey()}
* {@link FlowRecord#getTodoKey()}
*/
private String mergeKey;

Expand Down
Loading