Skip to content

Commit c581846

Browse files
committed
fix #123
1 parent a5ac8b3 commit c581846

File tree

21 files changed

+800
-60
lines changed

21 files changed

+800
-60
lines changed

example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/convert/FlowProcessConvertor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static FlowProcess convert(FlowProcessEntity entity){
1010
return null;
1111
}
1212
return new FlowProcess(entity.getProcessId(),
13-
entity.getCreateTime(),entity.getBackupId(),entity.getCreateOperatorId());
13+
entity.getCreateTime(),entity.getBackupId(),entity.getCreateOperatorId(), entity.getVoided());
1414
}
1515

1616

@@ -23,6 +23,7 @@ public static FlowProcessEntity convert(FlowProcess flowProcess){
2323
entity.setCreateTime(flowProcess.getCreateTime());
2424
entity.setBackupId(flowProcess.getBackupId());
2525
entity.setCreateOperatorId(flowProcess.getCreateOperatorId());
26+
entity.setVoided(flowProcess.isVoided());
2627
return entity;
2728
}
2829
}

example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/entity/FlowProcessEntity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,9 @@ public class FlowProcessEntity {
3333
*/
3434
private Long createOperatorId;
3535

36+
/**
37+
* 是否作废
38+
*/
39+
private Boolean voided;
40+
3641
}

example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/jpa/FlowProcessEntityRepository.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ public interface FlowProcessEntityRepository extends FastRepository<FlowProcessE
77

88
FlowProcessEntity getFlowProcessEntityByProcessId(String processId);
99

10-
1110
void deleteByProcessId(String processId);
1211

1312
}

example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/jpa/FlowRecordEntityRepository.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,68 +10,68 @@
1010

1111
public interface FlowRecordEntityRepository extends FastRepository<FlowRecordEntity, Long> {
1212

13-
13+
@Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.id = ?1")
1414
FlowRecordEntity getFlowRecordEntityById(long id);
1515

1616
void deleteByProcessId(String processId);
1717

18-
18+
@Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.preId = ?1")
1919
List<FlowRecordEntity> findFlowRecordEntityByPreId(long preId);
2020

21+
@Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.processId = ?1")
2122
List<FlowRecordEntity> findFlowRecordEntityByProcessId(String processId);
2223

23-
@Query(value = "select r from FlowRecordEntity r where r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.processId = ?1")
24+
@Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.processId = ?1")
2425
List<FlowRecordEntity> findTodoFlowRecordByProcessId(String processId);
2526

2627
@Query(value = "select r from FlowRecordEntity r" +
2728
" LEFT JOIN (select min(m.id) as id from FlowRecordEntity m where m.currentOperatorId = ?1 and m.flowType = 'TODO' and m.flowStatus = 'RUNNING' and m.mergeable = true ) debup " +
2829
"on r.id = debup.id" +
29-
" where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING'" +
30+
" where r.flowType!='DELETE' and r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING'" +
3031
" and (r.mergeable !=true or debup.id is NOT null ) order by r.id desc")
3132
Page<FlowRecordEntity> findTodoByOperatorId(long operatorId, PageRequest pageRequest);
3233

33-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.nodeCode = ?3" +
34+
@Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE'and r.currentOperatorId = ?1 and r.workCode = ?2 and r.nodeCode = ?3" +
3435
" and r.mergeable = true and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' order by r.id desc")
3536
List<FlowRecordEntity> findMergeFlowRecordById(long currentOperatorId,String workCode, String nodeCode);
3637

37-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' order by r.id desc")
38+
@Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE'and r.currentOperatorId = ?1 and r.workCode = ?2 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' order by r.id desc")
3839
Page<FlowRecordEntity> findTodoByOperatorIdAndWorkCode(long operatorId, String workCode, PageRequest pageRequest);
3940

40-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.read = false and r.flowStatus = 'RUNNING' order by r.id desc")
41+
@Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE'and r.currentOperatorId = ?1 and r.read = false and r.flowStatus = 'RUNNING' order by r.id desc")
4142
Page<FlowRecordEntity> findUnReadByOperatorId(long operatorId, PageRequest pageRequest);
4243

43-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.read = false and r.flowStatus = 'RUNNING' order by r.id desc")
44+
@Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE'and r.currentOperatorId = ?1 and r.workCode = ?2 and r.read = false and r.flowStatus = 'RUNNING' order by r.id desc")
4445
Page<FlowRecordEntity> findUnReadByOperatorIdAndWorkCode(long operatorId, String workCode, PageRequest pageRequest);
4546

46-
@Query(value = "select d from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'DONE' group by r.processId ) order by d.id desc")
47+
@Query(value = "select d from FlowRecordEntity d where d.flowType!='DELETE'and d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'DONE' group by r.processId ) order by d.id desc")
4748
Page<FlowRecordEntity> findDoneByOperatorId(long operatorId, PageRequest pageRequest);
4849

49-
@Query(value = "select d from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.flowType = 'DONE' group by r.processId) order by d.id desc")
50+
@Query(value = "select d from FlowRecordEntity d where d.flowType!='DELETE'and d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.flowType = 'DONE' group by r.processId) order by d.id desc")
5051
Page<FlowRecordEntity> findDoneByOperatorIdAndworkCode(long operatorId, String workCode, PageRequest pageRequest);
5152

52-
@Query(value = "select d from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.preId = 0 and r.nodeCode = 'start' group by r.processId) order by d.id desc")
53+
@Query(value = "select d from FlowRecordEntity d where d.flowType!='DELETE'and d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.preId = 0 and r.nodeCode = 'start' group by r.processId) order by d.id desc")
5354
Page<FlowRecordEntity> findInitiatedByOperatorId(long operatorId, PageRequest pageRequest);
5455

55-
@Query(value = "select d from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 group by r.processId) order by d.id desc")
56+
@Query(value = "select d from FlowRecordEntity d where d.flowType!='DELETE' and d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 group by r.processId) order by d.id desc")
5657
Page<FlowRecordEntity> findAllByOperatorId(long operatorId, PageRequest pageRequest);
5758

58-
@Query(value = "select d from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.preId = 0 and r.nodeCode = 'start' group by r.processId) order by d.id desc")
59+
@Query(value = "select d from FlowRecordEntity d where d.flowType!='DELETE' and d.id in (select max(r.id) from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.preId = 0 and r.nodeCode = 'start' group by r.processId) order by d.id desc")
5960
Page<FlowRecordEntity> findInitiatedByOperatorIdAndWorkCode(long operatorId, String workCode, PageRequest pageRequest);
6061

61-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?2 order by r.id desc")
62+
@Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?2 order by r.id desc")
6263
Page<FlowRecordEntity> findTimeoutTodoByOperatorId(long operatorId, long currentTime, PageRequest pageRequest);
6364

64-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode = ?2 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?3 order by r.id desc")
65+
@Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.currentOperatorId = ?1 and r.workCode = ?2 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.timeoutTime >0 and r.timeoutTime < ?3 order by r.id desc")
6566
Page<FlowRecordEntity> findTimeoutTodoByOperatorIdAndWorkCode(long operatorId, String workCode, long currentTime, PageRequest pageRequest);
6667

67-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0 order by r.id desc")
68+
@Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.currentOperatorId = ?1 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0 order by r.id desc")
6869
Page<FlowRecordEntity> findPostponedTodoByOperatorId(long operatorId, PageRequest pageRequest);
6970

70-
@Query(value = "select r from FlowRecordEntity r where r.currentOperatorId = ?1 and r.workCode =?2 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0 order by r.id desc")
71+
@Query(value = "select r from FlowRecordEntity r where r.flowType!='DELETE' and r.currentOperatorId = ?1 and r.workCode =?2 and r.flowType = 'TODO' and r.flowStatus = 'RUNNING' and r.postponedCount > 0 order by r.id desc")
7172
Page<FlowRecordEntity> findPostponedTodoByOperatorIdAndWorkCode(long operatorId, String workCode, PageRequest pageRequest);
7273

73-
74-
@Query(value = "select d from FlowRecordEntity d where d.id in (select max(r.id) from FlowRecordEntity r group by r.processId ) order by d.id desc")
74+
@Query(value = "select d from FlowRecordEntity d where d.flowType!='DELETE' and d.id in (select max(r.id) from FlowRecordEntity r group by r.processId ) order by d.id desc")
7575
Page<FlowRecordEntity> findAllFlowRecords(PageRequest pageRequest);
7676

7777
}

example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/repository/FlowProcessRepositoryImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,21 @@ public void save(FlowProcess flowProcess) {
2424
flowProcessEntityRepository.save( FlowProcessConvertor.convert(flowProcess));
2525
}
2626

27+
@Override
28+
public FlowProcess getFlowProcessByProcessId(String processId) {
29+
return FlowProcessConvertor.convert(flowProcessEntityRepository.getFlowProcessEntityByProcessId(processId));
30+
}
31+
2732
@Override
2833
public FlowWork getFlowWorkByProcessId(String processId) {
2934
FlowProcess flowProcess = FlowProcessConvertor.convert(flowProcessEntityRepository.getFlowProcessEntityByProcessId(processId));
3035
if(flowProcess==null){
3136
return null;
3237
}
38+
if(flowProcess.isVoided()){
39+
return null;
40+
}
41+
3342
FlowBackup flowBackup = flowBackupRepository.getFlowBackupById(flowProcess.getBackupId());
3443
if (flowBackup != null) {
3544
try {

example/example-infra/example-infra-flow/src/main/java/com/codingapi/example/infra/flow/repository/FlowRecordRepositoryImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ public FlowRecord getFlowRecordById(long id) {
4040

4141
@Override
4242
public List<FlowRecord> findFlowRecordByPreId(long preId) {
43-
return flowRecordEntityRepository.findFlowRecordEntityByPreId(preId).stream().map(item->FlowRecordConvertor.convert(item,flowOperatorRepository)).toList();
43+
return flowRecordEntityRepository.findFlowRecordEntityByPreId(preId).stream()
44+
.map(item->FlowRecordConvertor.convert(item,flowOperatorRepository))
45+
.filter(flowRecord -> !flowRecord.isDelete())
46+
.toList();
4447
}
4548

4649
@Override

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/em/FlowStatus.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ public enum FlowStatus {
1313
/**
1414
* 已完成
1515
*/
16-
FINISH;
16+
FINISH,
17+
/**
18+
* 已作废
19+
*/
20+
VOIDED;
1721

1822

1923
public static FlowStatus parser(String status) {

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/em/FlowType.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ public enum FlowType {
2424
/**
2525
* 等待执行
2626
*/
27-
WAITING;
27+
WAITING,
28+
/**
29+
* 删除
30+
*/
31+
DELETE;
2832

2933

3034
public static FlowType parser(String type){

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/event/FlowApprovalEvent.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public class FlowApprovalEvent implements ISyncEvent {
3838
public static final int STATE_SAVE = 10;
3939
// 删除
4040
public static final int STATE_DELETE = 11;
41+
// 退回
42+
public static final int STATE_BACK = 12;
43+
// 作废
44+
public static final int STATE_VOIDED = 13;
4145

4246
private final int state;
4347
private final IFlowOperator operator;
@@ -109,4 +113,16 @@ public boolean isRecall() {
109113
public boolean isFinish() {
110114
return state == STATE_FINISH;
111115
}
116+
117+
public boolean isDelete() {
118+
return state == STATE_DELETE;
119+
}
120+
121+
public boolean isVoided() {
122+
return state == STATE_VOIDED;
123+
}
124+
125+
public boolean isBack() {
126+
return state == STATE_BACK;
127+
}
112128
}

springboot-starter-flow/src/main/java/com/codingapi/springboot/flow/record/FlowProcess.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,24 @@ public class FlowProcess {
3232
*/
3333
private long createOperatorId;
3434

35+
/**
36+
* 是否作废
37+
*/
38+
private boolean voided;
39+
40+
/**
41+
* 作废流程
42+
*/
43+
public void voided(){
44+
this.voided = true;
45+
}
46+
3547

3648
public FlowProcess(long backupId, IFlowOperator createOperator) {
3749
this.processId = RandomGenerator.generateUUID();
3850
this.createTime = System.currentTimeMillis();
3951
this.backupId = backupId;
4052
this.createOperatorId = createOperator.getUserId();
53+
this.voided = false;
4154
}
4255
}

0 commit comments

Comments
 (0)