@@ -27,12 +27,14 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController ;
import com.eip4.platform.auth.security.AuthPrincipal ;
import com.eip4.platform.flowgateway.aggregate.BusinessSummaryService ;
import com.eip4.platform.flowgateway.aggregate.TodoAggregator ;
import com.eip4.platform.flowgateway.aggregate.TodoItem ;
import com.eip4.platform.flowgateway.client.FlowableClient ;
import com.eip4.platform.flowgateway.client.ProcessInstanceDto ;
import com.eip4.platform.flowgateway.client.TraceNodeDto ;
import com.eip4.platform.flowgateway.writeback.StatusWriteback ;
import com.dsasp.server.common.workflow.service.ProcessCoreService ;
import io.swagger.v3.oas.annotations.Operation ;
import io.swagger.v3.oas.annotations.tags.Tag ;
@@ -66,13 +68,16 @@ public class TodoController {
private final TodoAggregator todoAggregator ;
private final FlowableClient flowableClient ;
private final StatusWriteback statusWriteback ;
private final BusinessSummaryService businessSummaryService ;
private final JdbcTemplate jdbcTemplate ;
public TodoController ( TodoAggregator todoAggregator , FlowableClient flowableClient ,
StatusWriteback statusWriteback , JdbcTemplate jdbcTemplate ) {
StatusWriteback statusWriteback , BusinessSummaryService businessSummaryService ,
JdbcTemplate jdbcTemplate ) {
this . todoAggregator = todoAggregator ;
this . flowableClient = flowableClient ;
this . statusWriteback = statusWriteback ;
this . businessSummaryService = businessSummaryService ;
this . jdbcTemplate = jdbcTemplate ;
}
@@ -117,6 +122,22 @@ public class TodoController {
return amisCrud ( rows , params ) ;
}
/** 转换页「流程管理/我的发起任务」兼容端点;列名对齐 VIEW_ACT_PROCESS_SEARCH。 */
@Operation ( summary = " 转换页我的发起任务数据(amis) " , description = " 返回老 VIEW_ACT_PROCESS 字段形态,底层走 Flowable startedBy 流程实例口径 " )
@GetMapping ( " /api/workflow/process/started-amis " )
public Map < String , Object > startedAmis ( @AuthenticationPrincipal AuthPrincipal principal ,
@RequestParam Map < String , String > params ) {
String userId = principal = = null ? trim ( params . get ( " INITUSERID " ) ) : principal . userId ( ) ;
List < ProcessInstanceDto > raw = flowableClient . started ( userId , 0 , LEGACY_TASK_FETCH_LIMIT ) ;
List < Map < String , Object > > rows = raw . stream ( )
. map ( this : : startedProcessRow )
. filter ( row - > matchesStartedFilters ( row , params ) )
. toList ( ) ;
resolveInitiatorDisplayNames ( rows ) ;
resolveAssigneeDisplayNames ( rows ) ;
return amisCrud ( rows , params ) ;
}
/** 转换页「流程管理/已办任务」兼容端点;列名对齐 VIEW_ACT_TASK_COMPLETE_SEARCH/VIEW_ACT_FTASK_COMPLETE_SEARCH。 */
@Operation ( summary = " 转换页已办任务数据(amis) " , description = " 返回老 VIEW_ACT_TASK 字段形态,底层走 /api/done 聚合口径 " )
@GetMapping ( " /api/workflow/tasks/done-amis " )
@@ -155,15 +176,43 @@ public class TodoController {
@Operation ( summary = " 发起流程 " , description = " 透传 flowable-service /process/start;按 processDefinitionKey 或 id 发起,可带 businessKey 与变量 " )
@PostMapping ( " /api/process/start " )
public ResponseEntity < ProcessInstanceDto > start ( @RequestBody GatewayRequests . StartRequest req ) {
public ResponseEntity < ProcessInstanceDto > start ( @AuthenticationPrincipal AuthPrincipal principal ,
@RequestBody GatewayRequests . StartRequest req ) {
Map < String , Object > body = new HashMap < > ( ) ;
body . put ( " processDefinitionKey " , req . processDefinitionKey ) ;
body . put ( " processDefinitionId " , req . processDefinitionId ) ;
body . put ( " businessKey " , req . businessKey ) ;
body . put ( " startUserId " , principal = = null ? req . startUserId : principal . userId ( ) ) ;
body . put ( " variables " , req . variables ) ;
return ResponseEntity . ok ( flowableClient . start ( body ) ) ;
}
@Operation ( summary = " 发起人撤回流程 " ,
description = " 透传 flowable-service /process/{processInstanceId}/withdraw; 成功后回写 SYS_DATASTATUS=5(重新提交)。 " )
@PostMapping ( " /api/workflow/process/{processInstanceId}/withdraw " )
public ResponseEntity < Map < String , Object > > withdraw ( @PathVariable String processInstanceId ,
@RequestBody ( required = false ) GatewayRequests . ApprovalActionRequest req ) {
Map < String , Object > engine = flowableClient . withdraw ( processInstanceId , req = = null ? null : req . comment ) ;
String businessKey = req ! = null & & notBlank ( req . businessKey )
? req . businessKey
: rowString ( engine , " businessKey " , " BUSINESSKEY " ) ;
String table = req = = null ? null : req . tableName ;
boolean written = false ;
if ( notBlank ( businessKey ) ) {
statusWriteback . updateStatus ( businessKey , table , ProcessCoreService . STATUS_RESUBMIT ) ;
written = true ;
}
Map < String , Object > resp = new LinkedHashMap < > ( ) ;
resp . put ( " status " , 0 ) ;
resp . put ( " msg " , " 撤回成功 " ) ;
resp . put ( " withdrawn " , true ) ;
resp . put ( " targetKey " , rowString ( engine , " targetKey " , " TARGETKEY " ) ) ;
resp . put ( " businessKey " , businessKey ) ;
resp . put ( " processInstanceId " , processInstanceId ) ;
resp . put ( " statusWritten " , written ) ;
return ResponseEntity . ok ( resp ) ;
}
@Operation ( summary = " 流程轨迹 " , description = " 返回流程实例的历史任务节点(含当前活动节点),按开始时间升序;包含办理人姓名/审批意见/办理结果 " )
@GetMapping ( " /api/flow/process/{processInstanceId}/trace " )
public ResponseEntity < List < TraceNodeDto > > trace ( @PathVariable String processInstanceId ) {
@@ -249,6 +298,36 @@ public class TodoController {
return row ;
}
private Map < String , Object > startedProcessRow ( ProcessInstanceDto pi ) {
Map < String , Object > row = new LinkedHashMap < > ( ) ;
String processId = trim ( pi . id ) ;
BusinessSummaryService . Summary summary = businessSummaryService . summarize ( pi . businessKey ) ;
Map < String , Object > fields = summary . fields ( ) = = null ? Map . of ( ) : summary . fields ( ) ;
row . put ( " VIEW_ACT_PROCESS_ID " , processId ) ;
row . put ( " TITLE " , titleOf ( pi , fields ) ) ;
row . put ( " PROCESSNAME " , firstNonBlank ( pi . processDefinitionName , processName ( pi . processDefinitionId ) ,
pi . processDefinitionKey ) ) ;
row . put ( " INITUSERID " , trim ( pi . startUserId ) ) ;
row . put ( " INITUSERID_DISPLAY__ " , trim ( pi . startUserId ) ) ;
int status = statusOf ( pi ) ;
row . put ( " WFSTATUS " , status ) ;
row . put ( " STARTTIME " , formatMillis ( pi . startTimeMillis ) ) ;
row . put ( " ENDTIME " , formatMillis ( pi . endTimeMillis ) ) ;
String assigneeIds = pi . activeTaskAssignees = = null ? " " : pi . activeTaskAssignees . stream ( )
. filter ( Objects : : nonNull )
. map ( String : : trim )
. filter ( s - > ! s . isBlank ( ) )
. distinct ( )
. collect ( java . util . stream . Collectors . joining ( " , " ) ) ;
row . put ( " ASSIGNEEIDS " , assigneeIds ) ;
row . put ( " ASSIGNEENAME " , assigneeIds ) ;
row . put ( " processInstanceId " , processId ) ;
row . put ( " businessKey " , pi . businessKey ) ;
row . put ( " businessTable " , summary . tableName ( ) ) ;
row . put ( " businessSummary " , fields ) ;
return row ;
}
private void resolveInitiatorDisplayNames ( List < Map < String , Object > > rows ) {
Set < String > userIds = new LinkedHashSet < > ( ) ;
for ( Map < String , Object > row : rows ) {
@@ -295,6 +374,65 @@ public class TodoController {
}
}
private void resolveAssigneeDisplayNames ( List < Map < String , Object > > rows ) {
Set < String > userIds = new LinkedHashSet < > ( ) ;
for ( Map < String , Object > row : rows ) {
String raw = trim ( Objects . toString ( row . get ( " ASSIGNEEIDS " ) , " " ) ) ;
if ( raw = = null | | raw . isBlank ( ) ) {
continue ;
}
for ( String part : raw . split ( " , " ) ) {
String id = trim ( part ) ;
if ( id ! = null & & ! id . isBlank ( ) ) {
userIds . add ( id ) ;
}
}
}
if ( userIds . isEmpty ( ) ) {
return ;
}
Map < String , String > displayById = new HashMap < > ( ) ;
List < String > ids = new ArrayList < > ( userIds ) ;
for ( int from = 0 ; from < ids . size ( ) ; from + = 200 ) {
List < String > batch = ids . subList ( from , Math . min ( from + 200 , ids . size ( ) ) ) ;
String placeholders = String . join ( " , " , Collections . nCopies ( batch . size ( ) , " ? " ) ) ;
try {
List < Map < String , Object > > matches = jdbcTemplate . queryForList (
" SELECT TRIM(VIEW_SYS_USER_ID) AS USER_ID, DISPLAYNAME AS DISPLAY_NAME "
+ " FROM VIEW_SYS_USER WHERE TRIM(VIEW_SYS_USER_ID) IN ( " + placeholders + " ) " ,
batch . toArray ( ) ) ;
if ( matches = = null ) {
continue ;
}
for ( Map < String , Object > match : matches ) {
String userId = rowString ( match , " USER_ID " , " user_id " , " ID " , " id " ) ;
String displayName = rowString ( match , " DISPLAY_NAME " , " display_name " , " DISPLAYNAME " , " displayname " ) ;
if ( userId ! = null & & ! userId . isBlank ( ) & & displayName ! = null & & ! displayName . isBlank ( ) ) {
displayById . put ( userId , displayName ) ;
}
}
} catch ( DataAccessException ignored ) {
return ;
}
}
for ( Map < String , Object > row : rows ) {
String raw = trim ( Objects . toString ( row . get ( " ASSIGNEEIDS " ) , " " ) ) ;
if ( raw = = null | | raw . isBlank ( ) ) {
continue ;
}
List < String > names = new ArrayList < > ( ) ;
for ( String part : raw . split ( " , " ) ) {
String id = trim ( part ) ;
if ( id ! = null & & ! id . isBlank ( ) ) {
names . add ( displayById . getOrDefault ( id , id ) ) ;
}
}
row . put ( " ASSIGNEENAME " , String . join ( " , " , names ) ) ;
}
}
private static boolean matchesLegacyFilters ( Map < String , Object > row , Map < String , String > params , boolean done ) {
return contains ( row , params , " TITLE " )
& & contains ( row , params , " PROCESSNAME " )
@@ -306,6 +444,16 @@ public class TodoController {
& & ( ! done | | equalsIfPresent ( row , params , " WFSTATUS " ) ) ;
}
private static boolean matchesStartedFilters ( Map < String , Object > row , Map < String , String > params ) {
return contains ( row , params , " TITLE " )
& & contains ( row , params , " PROCESSNAME " )
& & equalsIfPresent ( row , params , " INITUSERID " )
& & equalsIfPresent ( row , params , " WFSTATUS " )
& & contains ( row , params , " ASSIGNEENAME " )
& & inDateRange ( row . get ( " STARTTIME " ) , params . get ( " STARTTIME " ) )
& & inDateRange ( row . get ( " ENDTIME " ) , params . get ( " ENDTIME " ) ) ;
}
private static boolean contains ( Map < String , Object > row , Map < String , String > params , String key ) {
String needle = trim ( params . get ( key ) ) ;
if ( needle = = null | | needle . isBlank ( ) ) {
@@ -394,6 +542,39 @@ public class TodoController {
return item . taskName ;
}
private static String titleOf ( ProcessInstanceDto pi , Map < String , Object > summary ) {
if ( summary ! = null ) {
for ( String key : List . of ( " TITLE " , " NAME " , " SUBJECT " , " NO " , " SERIALNO " , " FORMNO " ) ) {
Object value = summary . get ( key ) ;
if ( value = = null ) {
value = summary . get ( key . toLowerCase ( ) ) ;
}
String s = trim ( Objects . toString ( value , " " ) ) ;
if ( s ! = null & & ! s . isBlank ( ) ) {
return s ;
}
}
}
if ( pi . businessKey ! = null & & ! pi . businessKey . isBlank ( ) ) {
return pi . businessKey ;
}
return firstNonBlank ( pi . processDefinitionName , pi . processDefinitionKey , pi . id ) ;
}
private int statusOf ( ProcessInstanceDto pi ) {
if ( pi . businessKey ! = null & & ! pi . businessKey . isBlank ( ) ) {
try {
Integer status = statusWriteback . getStatus ( pi . businessKey ) ;
if ( status ! = null ) {
return status ;
}
} catch ( RuntimeException ignored ) {
// 状态表不可读时按流程是否结束降级。
}
}
return pi . ended ? ProcessCoreService . STATUS_PASS : ProcessCoreService . STATUS_PROCESSING ;
}
private static String summaryString ( TodoItem item , String . . . keys ) {
if ( item . businessSummary = = null | | item . businessSummary . isEmpty ( ) ) {
return null ;
@@ -422,6 +603,16 @@ public class TodoController {
return null ;
}
private static String firstNonBlank ( String . . . values ) {
for ( String value : values ) {
String s = trim ( value ) ;
if ( s ! = null & & ! s . isBlank ( ) ) {
return s ;
}
}
return null ;
}
private static String processName ( String processDefinitionId ) {
String s = trim ( processDefinitionId ) ;
if ( s = = null | | s . isBlank ( ) ) {