feat: add framework script editor actions
Some checks failed
ci / build-test-parity (push) Has been cancelled
Some checks failed
ci / build-test-parity (push) Has been cancelled
This commit is contained in:
@@ -56,4 +56,11 @@ public final class GatewayRequests {
|
||||
public String processInstanceId;
|
||||
public String tableName;
|
||||
}
|
||||
|
||||
/** 流程监控高级处理脚本请求。 */
|
||||
public static class AdvancedScriptRequest {
|
||||
public String script;
|
||||
public String businessKey;
|
||||
public String tableName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,11 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
@@ -35,6 +38,8 @@ 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 com.dsasp.server.core.service.script.FlowScriptBindings;
|
||||
import com.dsasp.server.core.service.script.ScriptingEnginesManager;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -60,6 +65,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@RestController
|
||||
public class TodoController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TodoController.class);
|
||||
|
||||
private static final int DEFAULT_AMIS_PER_PAGE = 10;
|
||||
private static final int LEGACY_TASK_FETCH_LIMIT = 1_000;
|
||||
private static final DateTimeFormatter LEGACY_DATE_TIME =
|
||||
@@ -254,6 +261,61 @@ public class TodoController {
|
||||
return ResponseEntity.ok(resp);
|
||||
}
|
||||
|
||||
@Operation(summary = "流程监控高级处理脚本",
|
||||
description = "流程监控页专用:按老系统语义给 Groovy 绑定 processid/businessKey 后执行;失败返回 AMIS status=1。")
|
||||
@PostMapping("/api/workflow/process/{processInstanceId}/advanced-script")
|
||||
public ResponseEntity<Map<String, Object>> runProcessAdvancedScript(
|
||||
@AuthenticationPrincipal AuthPrincipal principal,
|
||||
@PathVariable String processInstanceId,
|
||||
@RequestBody(required = false) GatewayRequests.AdvancedScriptRequest req) {
|
||||
String script = req == null ? null : trim(req.script);
|
||||
if (script == null || script.isBlank()) {
|
||||
return ResponseEntity.ok(amisFail("请输入高级处理脚本"));
|
||||
}
|
||||
ProcessInstanceDto pi = flowableClient.processInstance(processInstanceId);
|
||||
if (pi == null) {
|
||||
return ResponseEntity.ok(amisFail("未找到流程实例"));
|
||||
}
|
||||
String businessKey = firstNonBlank(req == null ? null : req.businessKey, pi.businessKey);
|
||||
Map<String, Object> bindMap = new LinkedHashMap<>();
|
||||
bindMap.put("processid", processInstanceId);
|
||||
bindMap.put("processInstanceId", processInstanceId);
|
||||
bindMap.put("businessKey", businessKey);
|
||||
bindMap.put("tableName", req == null ? null : req.tableName);
|
||||
if (principal != null) {
|
||||
bindMap.put("currentUserId", principal.userId());
|
||||
bindMap.put("currentUserName", principal.name());
|
||||
}
|
||||
|
||||
Properties ctx = new Properties();
|
||||
if (principal != null) {
|
||||
putIfNotBlank(ctx, "CURRENTUSER", principal.userId());
|
||||
putIfNotBlank(ctx, "CURRENTUSERID", principal.userId());
|
||||
putIfNotBlank(ctx, "CURRENTUSERNAME", principal.name());
|
||||
putIfNotBlank(ctx, "CURRENTDEPART", principal.depart());
|
||||
putIfNotBlank(ctx, "CURRENTORG", principal.org());
|
||||
}
|
||||
|
||||
try {
|
||||
String key = "process-monitor:" + processInstanceId + ":" + Integer.toHexString(script.hashCode());
|
||||
ScriptingEnginesManager.getScriptingEnginesManager()
|
||||
.evaluateGroovy(key, script, new FlowScriptBindings(bindMap, ctx));
|
||||
log.info("流程监控高级处理脚本执行成功: processInstanceId={}, businessKey={}, user={}",
|
||||
processInstanceId, businessKey, principal == null ? "" : principal.userId());
|
||||
Map<String, Object> resp = amisOk("执行成功");
|
||||
resp.put("processInstanceId", processInstanceId);
|
||||
resp.put("businessKey", businessKey);
|
||||
return ResponseEntity.ok(resp);
|
||||
} catch (Throwable ex) {
|
||||
if (ex instanceof VirtualMachineError || ex instanceof ThreadDeath) {
|
||||
throw ex;
|
||||
}
|
||||
log.warn("流程监控高级处理脚本执行失败: processInstanceId={}, businessKey={}, user={}, error={}",
|
||||
processInstanceId, businessKey, principal == null ? "" : principal.userId(), ex.getMessage());
|
||||
return ResponseEntity.ok(amisFail("执行失败:" + safeScriptError(ex)));
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "流程轨迹", description = "返回流程实例的历史任务节点(含当前活动节点),按开始时间升序;包含办理人姓名/审批意见/办理结果")
|
||||
@GetMapping("/api/flow/process/{processInstanceId}/trace")
|
||||
public ResponseEntity<List<TraceNodeDto>> trace(@PathVariable String processInstanceId) {
|
||||
@@ -654,6 +716,34 @@ public class TodoController {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Map<String, Object> amisOk(String msg) {
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("status", 0);
|
||||
resp.put("msg", msg);
|
||||
return resp;
|
||||
}
|
||||
|
||||
private static Map<String, Object> amisFail(String msg) {
|
||||
Map<String, Object> resp = new LinkedHashMap<>();
|
||||
resp.put("status", 1);
|
||||
resp.put("msg", msg);
|
||||
return resp;
|
||||
}
|
||||
|
||||
private static void putIfNotBlank(Properties props, String key, String value) {
|
||||
if (notBlank(value)) {
|
||||
props.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
private static String safeScriptError(Throwable ex) {
|
||||
String msg = ex.getMessage();
|
||||
if (msg == null || msg.isBlank()) {
|
||||
msg = ex.getClass().getSimpleName();
|
||||
}
|
||||
return msg.replaceAll("[\\r\\n\\t]+", " ").strip();
|
||||
}
|
||||
|
||||
private static String processName(String processDefinitionId) {
|
||||
String s = trim(processDefinitionId);
|
||||
if (s == null || s.isBlank()) {
|
||||
|
||||
Reference in New Issue
Block a user