package weaver.interfaces.workflow.action.javacode; import com.api.formmode.page.util.Util; import com.icbc.api.internal.apache.http.E; import weaver.conn.RecordSet; import weaver.interfaces.workflow.action.Action; import weaver.general.BaseBean; import weaver.soa.workflow.request.RequestInfo; import java.util.*; /** * Online custom action interface * 增加平行流程已协办部门 */ public class Action20231013103613 extends BaseBean implements Action { /** * After selecting aciton after the process path node, this method will be executed after the node is submitted. */ @Override public String execute(RequestInfo request) { String requestId = request.getRequestid(); String tablename = request.getRequestManager().getBillTableName(); RecordSet rs = new RecordSet(); try { rs.executeQuery("select MAINREQUESTID from workflow_requestbase where requestid = ?" , requestId); //查询主流程 String mainrequestid = ""; if(rs.next()){ mainrequestid = Util.null2String(rs.getString("MAINREQUESTID")); } //查询平行流程request ArrayList siblingRequestIds = new ArrayList<>(); rs.executeQuery("select requestid from workflow_requestbase where MAINREQUESTID = ?" , mainrequestid); while(rs.next()){ String siblingRequestId = Util.null2String(rs.getString("requestid")); siblingRequestIds.add(siblingRequestId); } writeLog("平行流程"+siblingRequestIds); //当前流程的协办部门 rs.execute("select * from " + tablename + " where requestid = " + requestId); rs.next(); String xbbm = rs.getString("xbbm"); // HashMap xbbmMap = new HashMap<>(); rs.execute("select * from " + tablename + " where requestid in (" + String.join(",",siblingRequestIds)+" )"); while ( rs.next()){ String mainid = rs.getString("id"); String ycfxbbm = rs.getString("ycfxbbm"); String newycfxbbm = mergeWithoutDuplicates(xbbm, ycfxbbm); xbbmMap.put(mainid,newycfxbbm); } writeLog("修改平行流程"+xbbmMap); xbbmMap.forEach((key,value) ->{ rs.executeUpdate("update "+ tablename +" set ycfxbbm = ? where id = ?",value,key); }); }catch (Exception e){ boolean error = true; if (error) { request.getRequestManager().setMessageid("90001"); request.getRequestManager().setMessagecontent("System Abnormal Termination Process Submission!"); } } return Action.SUCCESS; } // public static String mergeWithoutDuplicates(String a, String b) { // if (b == null || b.isEmpty()) { // return a; // } // // String[] idsA = a.split(","); // String[] idsB = b.split(","); // // for (String idA : idsA) { // boolean exists = false; // for (String idB : idsB) { // if (idA.equals(idB)) { // exists = true; // break; // } // } // if (!exists) { // b += "," + idA; // } // } // return b; // } public static void main(String[] args) { String a = "1,2,3,4,5"; String b = "3,4,5,6,7"; b = mergeWithoutDuplicates(a, b); System.out.println(b); // 输出: 3,4,5,6,7,1,2 } public static String mergeWithoutDuplicates(String a, String b) { Set setB = new HashSet<>(); StringBuilder result = new StringBuilder(b); if (b != null && !b.isEmpty()) { for (String id : b.split(",")) { setB.add(id.trim()); } } for (String idA : a.split(",")) { idA = idA.trim(); if (!setB.contains(idA)) { if (result.length() > 0) { result.append(","); } result.append(idA); } } return result.toString(); } }