BPM 扩展接口

版本: 1.0 | 发布日期: 30/9/2019

通过该接口可以扩展的功能

  1. 扩展 参与人的来源和关系
  2. 扩展公式中的参数
  3. 扩展条件中的参数
  4. 送批之前添加操作
  5. 变更单批核之后添加操作
  6. 在代码层面监控流程中的事件

BpmHandler

public interface BpmHandler {

	/*return key,mess */
	public Map<String, String> extendDynamicPatorSource(String moduleName);

	public Map<String, String> extendDynamicPatorShip(String moduleName);

	/* return target user id*/
	public Set<Long> getExtendPatorSourceValue(String moduleName, SqlEntity data, String srcField);

	public Set<Long> getExtendPatorShipValue(String moduleName, SqlEntity data, String ship, long uid, long empId);

	public Set<Long> getExtendPatorShipValue(String moduleName, SqlEntity data, String ship, long uid, long empId, long reportingLineId);

	/*exclude lookup=user,employee field which default as source*/
	public Set<String> excludeDynamicPatorSource(String moduleName);

	/*return entity identify for bpm */
	public String getEntityIdentify(String moduleName, SqlEntity src);

	// such as ce01 business rule
	public List<DynamicField> extendDynamicField(String moduleName);

	public List<DynamicField> dynamicFieldCurrentValue(String moduleName, SqlEntity data);

	public boolean changeNoteApproved(String moduleName, SqlEntity origin, SqlEntity changeNote, String changeNoteCode);

	// return empty string means ok
	public String checkBeforeSubmit(String moduleName, SqlEntity data);
}

1. 扩展参与人的来源

bpm1 extendDynamicPatorSource

@Override
public Map<String, String> extendDynamicPatorSource(String moduleName) {
	Map<String, String> extendSource = new HashMap<String, String>();
	if ("employee".equals(moduleName) && CawLib.isApDebug()) {
		extendSource.put(e_source, "wf.extendA");
	}
	return extendSource;
}

getExtendPatorSourceValue

@Override
public Set<Long> getExtendPatorSourceValue(String moduleName, SqlEntity data, String srcField) {
	Set<Long> targetUser = new HashSet<Long>();
	if ("employee".equals(moduleName) && data.getModuleType().equals(moduleName) && CawLib.isApDebug()) {
		if (e_source.equals(srcField)) {
			Long publiserId = data.getMainData().getLong(1, "createUid");
			targetUser.add(publiserId);
		}
	}
	return targetUser;
}

2. 扩展参与人的关系

bpm2

extendDynamicPatorShip

@Override
public Map<String, String> extendDynamicPatorShip(String moduleName) {
	Map<String, String> extendSource = new HashMap<String, String>();
	if ("employee".equals(moduleName) && CawLib.isApDebug()) {
		extendSource.put(e_ship, "wf.extendShip");
	}
	return extendSource;
}

getExtendPatorShipValue

// Keep this method for backward compatibility
@Override
@Deprecated
public Set<Long> getExtendPatorShipValue(String moduleName, SqlEntity data, String ship, long uid, long empId) {
	Set<Long> targetUser = new HashSet<Long>();
	if ("employee".equals(moduleName) && data.getModuleType().equals(moduleName) && CawLib.isApDebug()) {
		if (e_ship.equals(ship)) {
			if (uid > 0) {
				targetUser.add(uid);
			} else if (empId > 0) {
				// found user id by employee id
			}
		}
	}
	return targetUser;
}

新的方法添加了一个新的参数 reportingLineId, 如果你同时实现了两个方法, 只有新的方法会被调用

public Set<Long> getExtendPatorShipValue(String moduleName, SqlEntity data, String ship, long uid, long empId, long reportingLineId);

3. 扩展条件中的参数

bpm3

4. 扩展公式中的参数

bpm4

extendDynamicField

@Override
public List<DynamicField> extendDynamicField(String moduleName) {
	List<DynamicField> ef = new ArrayList<DynamicField>();
	if ("employee".equals(moduleName) && CawLib.isApDebug()) {
		DynamicField f1 = new DynamicField("fA", "code", "messA");
		DynamicField f2 = new DynamicField("fB", "code", "messB");

		ef.add(f1);
		ef.add(f2);
	}
	return ef;
}

dynamicFieldCurrentValue

@Override
public List<DynamicField> dynamicFieldCurrentValue(String moduleName, SqlEntity data) {
	List<DynamicField> ef = new ArrayList<DynamicField>();
	if ("employee".equals(moduleName) && CawLib.isApDebug()) {
		DynamicField f1 = new DynamicField("fA", "code", "messA");
		DynamicField f2 = new DynamicField("fB", "code", "messB");
		f1.setValue("AAAAA");
		f2.setValue("BBBBB");

		ef.add(f1);
		ef.add(f2);
	}
	return ef;
}

5. 流程送批之前添加操作

如果返回的结果不是空白的字符串,送批会被中止,返回的字符串会以错误信息的形式显示给用户

@Override
public String checkBeforeSubmit(String moduleName, SqlEntity data) {
	if ("employee2".equals(moduleName) && CawLib.isApDebug()) {
		return CawGlobal.getMess("wf.actionFailInfo2");
	}
	return super.checkBeforeSubmit(moduleName, data);
}

6. 变更单批核之后添加操作

变更单批核之后,我们会用变更单替换原始单据,这个方法在替换操作之前被调用,返回的结果用于表示替换操作是否还要继续。 返回False表示替换操作停止

@Override
public boolean changeNoteApproved(String moduleName, SqlEntity origin, SqlEntity changeNote, String changeNoteCode) {
	return false;
}

Bpm Event Listener

在BPM的界面,用户可以对不同的事件设置不同的响应,如果你需要在代码层面捕捉到这些事件并作出响应,请看下面

@CawEventListener(eventTopic = WfTopic.BpmEvent)
public class AncmBpmEventListener extends CawListenerAdapter {

	@Override
	public void callEvent(Object param) {
		if (param == null || !(param instanceof WfPublishPara)) {
			return;
		}
		WfPublishPara msg = (WfPublishPara) param;
		if (!"ancm".equals(msg.getApvModule()) || !(WfInsState.ENDED).equals(msg.getWfInsState())) {
			return;
		}

		long ancmId = msg.getApvRecordId();
		CheckMsg ckmsg = AncmUtil.publishAncmBpm(ancmId);
		if (ckmsg != null) {
			CawLog.error(ckmsg.getInfo());
		}
	}
}