Skip to content
Merged

#13 #33

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
Expand Up @@ -123,7 +123,7 @@ public static class DataBody {
public DataBody(FormMeta formMeta) {
this.formMeta = formMeta;
this.data = new HashMap<>();
this.fieldTypes = formMeta.getMainFieldTypeMaps();
this.fieldTypes = formMeta.loadMainFieldTypeMaps();
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.codingapi.flow.form;

import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

Expand Down Expand Up @@ -91,7 +90,7 @@ public static FormMeta fromMap(Map<String, Object> map) {
/**
* 获取表单字段名称
*/
public List<String> getFieldNames() {
public List<String> loadFieldNames() {
return fields.stream().map(FormFieldMeta::getName).toList();
}

Expand All @@ -118,7 +117,7 @@ private void initFormFieldTypes(FormMeta form, Map<String, String> types) {
*
* @return 表单字段类型
*/
public Map<String, String> getAllFieldTypeMaps() {
public Map<String, String> loadAllFieldTypeMaps() {
Map<String, String> types = new HashMap<>();
List<FormMeta> forms = this.getSubForms();
if (forms == null) {
Expand All @@ -137,7 +136,7 @@ public Map<String, String> getAllFieldTypeMaps() {
*
* @return 表单字段类型
*/
public Map<String, String> getMainFieldTypeMaps() {
public Map<String, String> loadMainFieldTypeMaps() {
Map<String, String> types = new HashMap<>();
List<FormMeta> forms = new ArrayList<>();
forms.add(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

import com.codingapi.flow.action.IFlowAction;
import com.codingapi.flow.form.FormMeta;
import com.codingapi.flow.manager.NodeStrategyManager;
import com.codingapi.flow.manager.OperatorManager;
import com.codingapi.flow.node.IFlowNode;
import com.codingapi.flow.operator.IFlowOperator;
import com.codingapi.flow.record.FlowRecord;
import com.codingapi.flow.session.FlowSession;
import com.codingapi.flow.strategy.node.OperatorLoadStrategy;
import com.codingapi.flow.workflow.Workflow;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -48,7 +57,22 @@ public class FlowContent {
/**
* 发起者id
*/
private long createOperatorId;
private FlowOperator createOperator;

/**
* 当前审批者id
*/
private FlowOperator currentOperator;

/**
* 流程状态 | 运行中、已完成、异常、删除
*/
private int flowState;

/**
* 节点状态 | 待办、已办
*/
private int recordState;

/**
* 历史记录
Expand All @@ -60,6 +84,78 @@ public class FlowContent {
*/
private List<NextNode> nextNodes;

public void pushNextNodes(FlowSession flowSession, List<IFlowNode> nextNodes) {
List<NextNode> nextNodeList = new ArrayList<>();
for (IFlowNode node : nextNodes){
NextNode nextNode = new NextNode();
nextNode.setNodeId(node.getId());
nextNode.setNodeName(node.getName());
nextNode.setNodeType(node.getType());

NodeStrategyManager nodeStrategyManager = node.strategyManager();
OperatorManager operatorManager = nodeStrategyManager.loadOperators(flowSession);
nextNode.setOperators(operatorManager.getOperators().stream().map(FlowOperator::new).toList());

nextNodeList.add(nextNode);
}
this.nextNodes = nextNodeList;
}

public void pushCurrentNode(IFlowNode currentNode) {
this.actions = currentNode.actionManager().getActions();
Map<String,Object> nodeData = currentNode.toMap();
this.view = (String) nodeData.get("view");
}

public void pushWorkflow(Workflow workflow) {
this.form = workflow.getForm();
this.workflowCode = workflow.getCode();
}

public void pushRecords(FlowRecord record, List<FlowRecord> mergeRecords) {
this.recordId = record.getId();
this.createOperator = new FlowOperator(record.getCreateOperatorId(), record.getCreateOperatorName());
this.mergeable = record.isMergeable();
this.flowState = record.getFlowState();
this.recordState = record.getRecordState();

this.todos = new ArrayList<>();
for (FlowRecord item : mergeRecords){
Body body = new Body();
body.setRecordId(item.getId());
body.setTitle(item.getTitle());
body.setData(item.getFormData());
body.setRecordState(item.getRecordState());
body.setFlowState(item.getFlowState());
this.todos.add(body);
}
}

public void pushHistory(Workflow workflow,List<FlowRecord> historyRecords) {
this.histories = new ArrayList<>();
for (FlowRecord item : historyRecords){
IFlowNode node = workflow.getFlowNode(item.getNodeId());
History history = new History();
history.setRecordId(item.getId());
history.setTitle(item.getTitle());
history.setAdvice(item.getAdvice());
history.setSignKey(item.getSignKey());
history.setNodeName(node.getName());
history.setNodeId(item.getNodeId());
history.setNodeType(item.getNodeType());
history.setUpdateTime(item.getUpdateTime());
history.setCurrentOperatorId(item.getCurrentOperatorId());
history.setCurrentOperatorName(item.getCurrentOperatorName());
this.histories.add(history);
}
}

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


/**
* 流程图
*/
Expand All @@ -77,6 +173,11 @@ public static class NextNode{
* 节点类型
*/
private String nodeType;

/**
* 节点审批人
*/
private List<FlowOperator> operators;
}

@Data
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.codingapi.flow.pojo.response;

import com.codingapi.flow.operator.IFlowOperator;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
* 流程审批人
*/
@Data
@AllArgsConstructor
public class FlowOperator {

private long id;
private String name;

public FlowOperator(IFlowOperator flowOperator) {
this.id = flowOperator.getUserId();
this.name = flowOperator.getName();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.codingapi.flow.record;

import com.codingapi.flow.action.IFlowAction;
import com.codingapi.flow.context.RepositoryHolderContext;
import com.codingapi.flow.exception.FlowValidationException;
import com.codingapi.flow.form.FormData;
import com.codingapi.flow.manager.NodeStrategyManager;
import com.codingapi.flow.node.IFlowNode;
import com.codingapi.flow.operator.IFlowOperator;
Expand All @@ -14,6 +16,8 @@
import lombok.Setter;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -543,4 +547,29 @@ public void newRecord() {
public boolean isForward() {
return forwardOperatorId > 0;
}


/**
* 创建会话
* @param workflow 流程设计器
* @param currentOperator 当前操作人
* @param formData 表单数据
* @param advice 节点审批信息
* @return FlowSession
*/
public FlowSession createFlowSession( Workflow workflow,IFlowOperator currentOperator,FormData formData, FlowAdvice advice) {
List<FlowRecord> currentRecords = RepositoryHolderContext.getInstance().findCurrentNodeRecords(this.getFromId(), this.getNodeId());
IFlowNode currentNode = workflow.getFlowNode(nodeId);
return new FlowSession(
currentOperator,
workflow,
currentNode,
advice.getAction(),
formData,
this,
currentRecords,
this.workBackupId,
advice
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public interface FlowRecordRepository {
*/
FlowRecord get(long id);

/**
* 批量获取流程详细
* @param ids 流程id列表
* @return 批量流程记录
*/
List<FlowRecord> findByIds(List<Long> ids);

/**
* 保存流程
* 为何确保待办合并数据的一致性,保存流程需要通过 {@link com.codingapi.flow.context.RepositoryHolderContext#saveRecord(FlowRecord)} 保存
Expand Down Expand Up @@ -69,4 +76,13 @@ public interface FlowRecordRepository {
*/
List<FlowRecord> findAfterRecords(String processId, long fromId);


/**
* 查询所有之前的流程记录
* @param processId 流程id
* @param id 记录id
* @return 记录列表
*/
List<FlowRecord> findBeforeRecords(String processId,long id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import com.codingapi.flow.session.FlowSession;
import com.codingapi.flow.workflow.Workflow;

import java.util.List;

/**
* 节点动作服务
*/
Expand Down Expand Up @@ -78,8 +76,7 @@ public void action() {
formData.reset(request.getFormData());
FlowAdvice flowAdvice = request.toFlowAdvice(workflow, flowAction);

List<FlowRecord> currentRecords = RepositoryHolderContext.getInstance().findCurrentNodeRecords(flowRecord.getFromId(), flowRecord.getNodeId());
FlowSession session = new FlowSession(currentOperator, workflow, currentNode, flowAction, formData, flowRecord, currentRecords, workflowBackup.getId(), flowAdvice);
FlowSession session = flowRecord.createFlowSession(workflow,currentOperator,formData,flowAdvice);
// 验证会话
currentNode.verifySession(session);
// 执行动作
Expand Down
Loading