Skip to content

Commit f2f9dbe

Browse files
Add batch summary support
1 parent b925ba7 commit f2f9dbe

17 files changed

Lines changed: 924 additions & 7 deletions

File tree

modules/flowable-batch-service-api/src/main/java/org/flowable/batch/api/BatchService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ public interface BatchService {
5353

5454
Batch completeBatch(String batchId, String status);
5555

56+
BatchSummary calculateBatchSummary(String batchId);
57+
5658
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/* Licensed under the Apache License, Version 2.0 (the "License");
2+
* you may not use this file except in compliance with the License.
3+
* You may obtain a copy of the License at
4+
*
5+
* http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*/
13+
package org.flowable.batch.api;
14+
15+
import java.util.Date;
16+
17+
public class BatchSummary {
18+
19+
protected String batchId;
20+
protected String batchType;
21+
protected Date createTime;
22+
protected String status;
23+
protected Date completeTime;
24+
protected String tenantId;
25+
protected long totalBatchParts;
26+
protected long completedBatchParts;
27+
protected long successBatchParts;
28+
protected long failedBatchParts;
29+
30+
public String getBatchId() {
31+
return batchId;
32+
}
33+
34+
public void setBatchId(String batchId) {
35+
this.batchId = batchId;
36+
}
37+
38+
public String getBatchType() {
39+
return batchType;
40+
}
41+
42+
public void setBatchType(String batchType) {
43+
this.batchType = batchType;
44+
}
45+
46+
public Date getCreateTime() {
47+
return createTime;
48+
}
49+
50+
public void setCreateTime(Date createTime) {
51+
this.createTime = createTime;
52+
}
53+
54+
public String getStatus() {
55+
return status;
56+
}
57+
58+
public void setStatus(String status) {
59+
this.status = status;
60+
}
61+
62+
public Date getCompleteTime() {
63+
return completeTime;
64+
}
65+
66+
public void setCompleteTime(Date completeTime) {
67+
this.completeTime = completeTime;
68+
}
69+
70+
public String getTenantId() {
71+
return tenantId;
72+
}
73+
74+
public void setTenantId(String tenantId) {
75+
this.tenantId = tenantId;
76+
}
77+
78+
public long getTotalBatchParts() {
79+
return totalBatchParts;
80+
}
81+
82+
public void setTotalBatchParts(long totalBatchParts) {
83+
this.totalBatchParts = totalBatchParts;
84+
}
85+
86+
public long getCompletedBatchParts() {
87+
return completedBatchParts;
88+
}
89+
90+
public void setCompletedBatchParts(long completedBatchParts) {
91+
this.completedBatchParts = completedBatchParts;
92+
}
93+
94+
public long getSuccessBatchParts() {
95+
return successBatchParts;
96+
}
97+
98+
public void setSuccessBatchParts(long successBatchParts) {
99+
this.successBatchParts = successBatchParts;
100+
}
101+
102+
public long getFailedBatchParts() {
103+
return failedBatchParts;
104+
}
105+
106+
public void setFailedBatchParts(long failedBatchParts) {
107+
this.failedBatchParts = failedBatchParts;
108+
}
109+
}

modules/flowable-batch-service/src/main/java/org/flowable/batch/service/impl/BatchServiceImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.flowable.batch.api.BatchPart;
2020
import org.flowable.batch.api.BatchQuery;
2121
import org.flowable.batch.api.BatchService;
22+
import org.flowable.batch.api.BatchSummary;
2223
import org.flowable.batch.service.BatchServiceConfiguration;
2324
import org.flowable.batch.service.impl.persistence.entity.BatchEntity;
2425
import org.flowable.batch.service.impl.persistence.entity.BatchEntityManager;
@@ -115,6 +116,19 @@ public Batch completeBatch(String batchId, String status) {
115116
return getBatchEntityManager().completeBatch(batchId, status);
116117
}
117118

119+
@Override
120+
public BatchSummary calculateBatchSummary(String batchId) {
121+
BatchEntity batch = getBatchEntityManager().findById(batchId);
122+
BatchSummary batchSummary = getBatchPartEntityManager().findBatchPartCountSummaryByBatchId(batchId);
123+
batchSummary.setBatchId(batch.getId());
124+
batchSummary.setBatchType(batch.getBatchType());
125+
batchSummary.setCreateTime(batch.getCreateTime());
126+
batchSummary.setStatus(batch.getStatus());
127+
batchSummary.setCompleteTime(batch.getCompleteTime());
128+
batchSummary.setTenantId(batch.getTenantId());
129+
return batchSummary;
130+
}
131+
118132
public Batch createBatch(BatchBuilder batchBuilder) {
119133
return getBatchEntityManager().createBatch(batchBuilder);
120134
}

modules/flowable-batch-service/src/main/java/org/flowable/batch/service/impl/persistence/entity/BatchPartEntityManager.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,25 @@
1616

1717
import org.flowable.batch.api.BatchPart;
1818
import org.flowable.batch.api.BatchPartQuery;
19+
import org.flowable.batch.api.BatchSummary;
1920
import org.flowable.common.engine.impl.persistence.entity.EntityManager;
2021

2122
public interface BatchPartEntityManager extends EntityManager<BatchPartEntity> {
22-
23+
2324
List<BatchPart> findBatchPartsByBatchId(String batchId);
24-
25+
2526
List<BatchPart> findBatchPartsByBatchIdAndStatus(String batchId, String status);
26-
27+
2728
List<BatchPart> findBatchPartsByScopeIdAndType(String scopeId, String scopeType);
2829

2930
List<BatchPart> findBatchPartsByQueryCriteria(BatchPartQuery batchPartQuery);
3031

3132
long findBatchPartCountByQueryCriteria(BatchPartQuery batchPartQuery);
3233

34+
BatchSummary findBatchPartCountSummaryByBatchId(String batchId);
35+
3336
BatchPartEntity createBatchPart(BatchEntity parentBatch, String status, String scopeId, String subScopeId, String scopeType);
34-
37+
3538
BatchPartEntity completeBatchPart(String batchPartId, String status, String resultJson);
3639

3740
void deleteBatchPartEntityAndResources(BatchPartEntity batchPartEntity);

modules/flowable-batch-service/src/main/java/org/flowable/batch/service/impl/persistence/entity/BatchPartEntityManagerImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.flowable.batch.api.BatchPart;
1919
import org.flowable.batch.api.BatchPartQuery;
20+
import org.flowable.batch.api.BatchSummary;
2021
import org.flowable.batch.service.BatchServiceConfiguration;
2122
import org.flowable.batch.service.impl.BatchPartQueryImpl;
2223
import org.flowable.batch.service.impl.persistence.entity.data.BatchPartDataManager;
@@ -56,6 +57,11 @@ public long findBatchPartCountByQueryCriteria(BatchPartQuery batchPartQuery) {
5657
return dataManager.findBatchPartCountByQueryCriteria((BatchPartQueryImpl) batchPartQuery);
5758
}
5859

60+
@Override
61+
public BatchSummary findBatchPartCountSummaryByBatchId(String batchId) {
62+
return dataManager.findBatchPartCountSummaryByBatchId(batchId);
63+
}
64+
5965
@Override
6066
public BatchPartEntity createBatchPart(BatchEntity parentBatch, String status, String scopeId, String subScopeId, String scopeType) {
6167
BatchPartEntity batchPartEntity = dataManager.create();

modules/flowable-batch-service/src/main/java/org/flowable/batch/service/impl/persistence/entity/data/BatchPartDataManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@
1515
import java.util.List;
1616

1717
import org.flowable.batch.api.BatchPart;
18+
import org.flowable.batch.api.BatchSummary;
1819
import org.flowable.batch.service.impl.BatchPartQueryImpl;
1920
import org.flowable.batch.service.impl.persistence.entity.BatchPartEntity;
2021
import org.flowable.common.engine.impl.persistence.entity.data.DataManager;
2122

2223
public interface BatchPartDataManager extends DataManager<BatchPartEntity> {
2324

2425
List<BatchPart> findBatchPartsByBatchId(String batchId);
25-
26+
2627
List<BatchPart> findBatchPartsByBatchIdAndStatus(String batchId, String status);
27-
28+
2829
List<BatchPart> findBatchPartsByScopeIdAndType(String scopeId, String scopeType);
2930

3031
List<BatchPart> findBatchPartsByQueryCriteria(BatchPartQueryImpl batchPartQuery);
3132

3233
long findBatchPartCountByQueryCriteria(BatchPartQueryImpl batchPartQuery);
34+
35+
BatchSummary findBatchPartCountSummaryByBatchId(String batchId);
3336
}

modules/flowable-batch-service/src/main/java/org/flowable/batch/service/impl/persistence/entity/data/impl/MybatisBatchPartDataManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.List;
1717

1818
import org.flowable.batch.api.BatchPart;
19+
import org.flowable.batch.api.BatchSummary;
1920
import org.flowable.batch.service.BatchServiceConfiguration;
2021
import org.flowable.batch.service.impl.BatchPartQueryImpl;
2122
import org.flowable.batch.service.impl.persistence.entity.BatchPartEntity;
@@ -82,6 +83,13 @@ public long findBatchPartCountByQueryCriteria(BatchPartQueryImpl batchPartQuery)
8283
return (Long) getDbSqlSession().selectOne("selectBatchPartCountByQueryCriteria", batchPartQuery);
8384
}
8485

86+
@Override
87+
public BatchSummary findBatchPartCountSummaryByBatchId(String batchId) {
88+
HashMap<String, Object> params = new HashMap<>();
89+
params.put("batchId", batchId);
90+
return (BatchSummary) getDbSqlSession().selectOne("selectBatchPartCountSummaryByBatchId", params);
91+
}
92+
8593
@Override
8694
protected IdGenerator getIdGenerator() {
8795
return batchServiceConfiguration.getIdGenerator();

modules/flowable-batch-service/src/main/resources/org/flowable/batch/service/db/mapping/entity/BatchPart.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,23 @@
162162
inner join ${prefix}FLW_RU_BATCH BATCH_ on RES.BATCH_ID_ = BATCH_.ID_
163163
</sql>
164164

165+
<resultMap id="batchSummaryMap" type="org.flowable.batch.api.BatchSummary">
166+
<result property="totalBatchParts" column="TOTAL_COUNT_"/>
167+
<result property="completedBatchParts" column="COMPLETED_COUNT_"/>
168+
<result property="successBatchParts" column="SUCCESS_COUNT_"/>
169+
<result property="failedBatchParts" column="FAILED_COUNT_"/>
170+
</resultMap>
171+
172+
<select id="selectBatchPartCountSummaryByBatchId" parameterType="map" resultMap="batchSummaryMap">
173+
SELECT
174+
COUNT(*) as TOTAL_COUNT_,
175+
COALESCE(SUM(CASE WHEN RES.COMPLETE_TIME_ IS NOT NULL THEN 1 ELSE 0 END), 0) as COMPLETED_COUNT_,
176+
COALESCE(SUM(CASE WHEN RES.STATUS_ = 'completed' OR RES.STATUS_ = 'success' THEN 1 ELSE 0 END), 0) as SUCCESS_COUNT_,
177+
COALESCE(SUM(CASE WHEN RES.STATUS_ = 'failed' OR RES.STATUS_ = 'fail' THEN 1 ELSE 0 END), 0) as FAILED_COUNT_
178+
FROM ${prefix}FLW_RU_BATCH_PART RES
179+
WHERE RES.BATCH_ID_ = #{batchId, jdbcType=NVARCHAR}
180+
</select>
181+
165182
<sql id="commonSelectBatchPartsByQueryCriteriaSql">
166183
<where>
167184
<if test="id != null">

modules/flowable-engine/src/main/java/org/flowable/engine/ManagementService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.flowable.batch.api.BatchPartBuilder;
2424
import org.flowable.batch.api.BatchPartQuery;
2525
import org.flowable.batch.api.BatchQuery;
26+
import org.flowable.batch.api.BatchSummary;
2627
import org.flowable.common.engine.api.FlowableIllegalArgumentException;
2728
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
2829
import org.flowable.common.engine.api.lock.LockManager;
@@ -446,6 +447,8 @@ public interface ManagementService {
446447

447448
void deleteBatch(String batchId);
448449

450+
BatchSummary getBatchSummary(String batchId);
451+
449452
/** get the list of properties. */
450453
Map<String, String> getProperties();
451454

modules/flowable-engine/src/main/java/org/flowable/engine/impl/ManagementServiceImpl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.flowable.batch.api.BatchPartBuilder;
2424
import org.flowable.batch.api.BatchPartQuery;
2525
import org.flowable.batch.api.BatchQuery;
26+
import org.flowable.batch.api.BatchSummary;
2627
import org.flowable.batch.service.BatchPartBuilderImpl;
2728
import org.flowable.batch.service.impl.BatchBuilderImpl;
2829
import org.flowable.batch.service.impl.BatchPartQueryImpl;
@@ -58,6 +59,7 @@
5859
import org.flowable.engine.impl.cmd.GetBatchDocumentCmd;
5960
import org.flowable.engine.impl.cmd.GetBatchPartCmd;
6061
import org.flowable.engine.impl.cmd.GetBatchPartDocumentCmd;
62+
import org.flowable.engine.impl.cmd.GetBatchSummaryCmd;
6163
import org.flowable.engine.impl.cmd.GetEventLogEntriesCmd;
6264
import org.flowable.engine.impl.cmd.GetTableNameCmd;
6365
import org.flowable.engine.impl.cmd.HandleHistoryCleanupTimerJobCmd;
@@ -388,6 +390,11 @@ public void deleteBatch(String batchId) {
388390
commandExecutor.execute(new DeleteBatchCmd(batchId));
389391
}
390392

393+
@Override
394+
public BatchSummary getBatchSummary(String batchId) {
395+
return commandExecutor.execute(new GetBatchSummaryCmd(batchId));
396+
}
397+
391398
@Override
392399
public Map<String, String> getProperties() {
393400
return commandExecutor.execute(new GetPropertiesCmd(configuration.getEngineCfgKey()));

0 commit comments

Comments
 (0)