Skip to content

Commit 7fa8b5a

Browse files
committed
fix bug
1 parent fe137f4 commit 7fa8b5a

File tree

2 files changed

+304
-160
lines changed

2 files changed

+304
-160
lines changed
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
package com.codingapi.springboot.flow.service;
2+
3+
import com.codingapi.springboot.flow.bind.BindDataSnapshot;
4+
import com.codingapi.springboot.flow.bind.IBindData;
5+
import com.codingapi.springboot.flow.domain.FlowNode;
6+
import com.codingapi.springboot.flow.domain.FlowWork;
7+
import com.codingapi.springboot.flow.domain.Opinion;
8+
import com.codingapi.springboot.flow.record.FlowRecord;
9+
import com.codingapi.springboot.flow.repository.FlowBindDataRepository;
10+
import com.codingapi.springboot.flow.repository.FlowProcessRepository;
11+
import com.codingapi.springboot.flow.repository.FlowRecordRepository;
12+
import com.codingapi.springboot.flow.user.IFlowOperator;
13+
import lombok.Getter;
14+
15+
/**
16+
* 流程记录服务(流程内部服务)
17+
*/
18+
class FlowRecordService2 {
19+
20+
private final long recordId;
21+
private final IFlowOperator currentOperator;
22+
private IBindData bindData;
23+
private Opinion opinion;
24+
25+
private final FlowRecordRepository flowRecordRepository;
26+
private final FlowProcessRepository flowProcessRepository;
27+
private final FlowBindDataRepository flowBindDataRepository;
28+
29+
@Getter
30+
private FlowWork flowWork;
31+
@Getter
32+
private FlowNode flowNode;
33+
@Getter
34+
private FlowRecord flowRecord;
35+
36+
public FlowRecordService2(FlowRecordRepository flowRecordRepository,
37+
FlowProcessRepository flowProcessRepository,
38+
FlowBindDataRepository flowBindDataRepository,
39+
40+
long recordId,
41+
IFlowOperator currentOperator) {
42+
this.flowRecordRepository = flowRecordRepository;
43+
this.flowProcessRepository = flowProcessRepository;
44+
this.flowBindDataRepository = flowBindDataRepository;
45+
46+
this.currentOperator = currentOperator;
47+
this.recordId = recordId;
48+
}
49+
50+
public void bindBindData(IBindData bindData){
51+
this.bindData = bindData;
52+
}
53+
54+
public void bindOpinion(Opinion opinion){
55+
this.opinion = opinion;
56+
}
57+
58+
59+
/**
60+
* 校验流程记录是否已提交状态
61+
*/
62+
public void verifyFlowRecordSubmitState() {
63+
flowRecord.submitStateVerify();
64+
}
65+
66+
/**
67+
* 校验流程是否当前操作者可操作的
68+
*/
69+
public void verifyFlowRecordCurrentOperator() {
70+
if(!currentOperator.isFlowManager()) {
71+
flowRecord.matcherOperator(currentOperator);
72+
}
73+
}
74+
75+
/**
76+
* 校验流程是否已审批
77+
*/
78+
public void verifyFlowRecordNotDone() {
79+
if (flowRecord.isDone()) {
80+
throw new IllegalArgumentException("flow record is done");
81+
}
82+
}
83+
84+
85+
/**
86+
* 校验流程是否已审批
87+
*/
88+
public void verifyFlowRecordIsDone() {
89+
if (!flowRecord.isDone()) {
90+
throw new IllegalArgumentException("flow record is not done");
91+
}
92+
}
93+
94+
95+
96+
/**
97+
* 校验流程是否未审批
98+
*/
99+
public void verifyFlowRecordNotTodo() {
100+
if (flowRecord.isTodo()) {
101+
throw new IllegalArgumentException("flow record is todo");
102+
}
103+
}
104+
105+
/**
106+
* 校验流程是未审批
107+
*/
108+
public void verifyFlowRecordIsTodo() {
109+
if (!flowRecord.isTodo()) {
110+
throw new IllegalArgumentException("flow record is not todo");
111+
}
112+
}
113+
114+
/**
115+
* 校验流程是否已完成
116+
*/
117+
public void verifyFlowRecordIsFinish() {
118+
if (!flowRecord.isFinish()) {
119+
throw new IllegalArgumentException("flow record is not finish");
120+
}
121+
}
122+
123+
/**
124+
* 校验流程是否已完成
125+
*/
126+
public void verifyFlowRecordNotFinish() {
127+
if (flowRecord.isFinish()) {
128+
throw new IllegalArgumentException("flow record is finish");
129+
}
130+
}
131+
132+
/**
133+
* 校验流程节点是否可编辑
134+
*/
135+
public void verifyFlowNodeEditableState(boolean editable) {
136+
// 流程节点不可编辑时,不能保存
137+
if (flowNode.isEditable() == editable) {
138+
throw new IllegalArgumentException("flow node is not editable");
139+
}
140+
}
141+
142+
143+
/**
144+
* 校验转办人员不能是当前操作者
145+
*/
146+
public void verifyTargetOperatorIsNotCurrentOperator(IFlowOperator targetOperator) {
147+
if(currentOperator.getUserId() == targetOperator.getUserId()){
148+
throw new IllegalArgumentException("current operator is target operator");
149+
}
150+
}
151+
152+
153+
/**
154+
* 获取流程记录对象
155+
*/
156+
public void loadFlowRecord() {
157+
FlowRecord flowRecord = flowRecordRepository.getFlowRecordById(recordId);
158+
if (flowRecord == null) {
159+
throw new IllegalArgumentException("flow record not found");
160+
}
161+
this.flowRecord = flowRecord;
162+
}
163+
164+
/**
165+
* 获取流程设计对象
166+
*/
167+
public void loadFlowWork() {
168+
FlowWork flowWork = flowProcessRepository.getFlowWorkByProcessId(flowRecord.getProcessId());
169+
if (flowWork == null) {
170+
throw new IllegalArgumentException("flow work not found");
171+
}
172+
flowWork.enableValidate();
173+
this.flowWork = flowWork;
174+
}
175+
176+
177+
/**
178+
* 获取流程节点对象
179+
*/
180+
public void loadFlowNode() {
181+
FlowNode flowNode = flowWork.getNodeByCode(flowRecord.getNodeCode());
182+
if (flowNode == null) {
183+
throw new IllegalArgumentException("flow node not found");
184+
}
185+
this.flowNode = flowNode;
186+
}
187+
188+
189+
/**
190+
* 保存流程表单数据
191+
*/
192+
public void saveSnapshot() {
193+
if(bindData==null){
194+
throw new IllegalArgumentException("bind data is null");
195+
}
196+
BindDataSnapshot snapshot = new BindDataSnapshot(flowRecord.getSnapshotId(), bindData);
197+
flowBindDataRepository.update(snapshot);
198+
}
199+
200+
201+
/**
202+
* 更新流程记录
203+
*/
204+
public void updateFlowRecord() {
205+
if(opinion==null){
206+
throw new IllegalArgumentException("opinion is null");
207+
}
208+
flowRecord.setOpinion(opinion);
209+
flowRecordRepository.update(flowRecord);
210+
}
211+
212+
213+
/**
214+
* 标记流程为已读状态
215+
*/
216+
public void flagReadFlowRecord() {
217+
if (currentOperator != null) {
218+
if(flowRecord.isOperator(currentOperator)) {
219+
if (!flowRecord.isRead()) {
220+
flowRecord.read();
221+
flowRecordRepository.update(flowRecord);
222+
}
223+
}
224+
}
225+
}
226+
227+
}

0 commit comments

Comments
 (0)