MAXIMO部分AppBean類操作經驗

1,彈窗

  • 錯誤彈窗
throw new MXApplicationException("ticketsg", "invalidbg",new String[]{“測試”});

這種彈窗可以在Bean類或者Mbo類內可以使用;
這種方式需要在數據庫maxmessages表中先定義提示消息(第一個參數是msggroup的值,第二個參數是msgkey的值,第三個參數是提示消息中{0}、{1}的引用值);
如果不想做數據庫配置。可以寫成:

throw new MXApplicationException("系統", "這是錯誤提示消息");
  • 警告彈窗
throw new MXApplicationWariningException("ticketsg", "invalidbg",new String[]{“測試”});

這種彈窗可以在Bean類或者Mbo類內可以使用;
同上,這種方式也需要在數據庫maxmessages表中先定義提示消息。如果不想做數據庫配置,可以使用:

throw new MXApplicationException("system", "UserDefineMsg", new String[]{"自定義提示消息"});

這裏第三個參數就是彈窗的提示內容;

  • 確認彈窗
int userInput = MXApplicationYesNoCancelException.getUserInput("reloadid",MXServer.getMXServer(), this.getUserInfo());
switch (userInput) {
	case -1:
		Object params[] = {"確認要執行此操作嗎?"};
		throw new MXApplicationYesNoCancelException("reloadid", "system", "UserDefineYesOrNoMsg", params);
	case 2: 
	 	 //確認後的操作
}

Bean類可以使用,Mbo類可以彈窗但是不能正常執行選擇以後的代碼。
Case後面的值還可以使用:
MXApplicationYesNoCancelException.NULL,MXApplicationYesNoCancelException.YES和
MXApplicationYesNoCancelException.NO
爲了使用方便,可以封裝出一個方法,直接在AppBean類裏面調用:

/**
	 * 確認彈窗,在appbean內調用,不能在mbo內調用
	 * @author juong
	 * @throws MXException 
	 * @throws RemoteException
	 * @return 當用戶選擇"是"時返回true;當用戶選擇"否"時返回false,
	 */
	public boolean confirm () throws RemoteException, MXException{
		int userInput = MXApplicationYesNoCancelException.getUserInput("reloadid",MXServer.getMXServer(), this.getUserInfo());
	    switch (userInput) {
	      case -1:
	        Object params[] = {"確認要執行此操作嗎?"};
	        throw new MXApplicationYesNoCancelException("reloadid", "system", "UserDefineYesOrNoMsg", params);
	      case 2: 
	     	return true;
	    }
	    return false;
	}

2,跳轉到某個應用

WebClientEvent e = new WebClientEvent("gotoapp", sessionContext.getCurrentAppId(), "應用名", sessionContext);//第一個參數有:changeapp,gotoapp,execevent等
e.addParameter("uniqueid", String.valueOf(“應用關聯的mbo的id”));
WebClientEvent se = new WebClientEvent("execevent",	sessionContext.getCurrentAppId(), e, sessionContext);
app.put("returninputR/O", "true");//當第二個參數控制是否帶值返回,爲'false'爲有帶值返回,否則相反
Utility.sendEvent(se);

比如要跳轉到人員應用,應用名爲PERSON,人員表的主鍵id爲PERSONID=1001;

WebClientEvent e = new WebClientEvent("gotoapp", sessionContext.getCurrentAppId(), "PERSON", sessionContext);//第一個參數有:changeapp,gotoapp,execevent等
e.addParameter("uniqueid", String.valueOf(“1001”));
WebClientEvent se = new WebClientEvent("execevent",	sessionContext.getCurrentAppId(), e, sessionContext);
app.put("returninputR/O", "true");//當第二個參數控制是否帶值返回,爲'false'爲有帶值返回,否則相反
Utility.sendEvent(se);

3,在提示欄顯示“記錄已保存”

WebClientEvent event = sessionContext.getCurrentEvent();
Utility.showMessageBox(event, "system", "saverecord", null);
sessionContext.queueRefreshEvent();//刷新頁面

4,彈窗應用xml中定義的某個dialog

Utility.sendEvent(new WebClientEvent("xml中dialog的id屬性值", app.getCurrentPageId(), null, sessionContext));

5,關閉當前彈窗

Utility.sendEvent(new WebClientEvent("dialogcancel",app.getCurrentPageId(),null,sessionContext));

第一個參數除了dialogcancel外,還有dialogok和dialogclose
使用dialogok會執行Bean類的excute()方法。
6,保存頁面數據

app.getAppBean().save();

或者

DataBean appBean = Utility.getDataSource(sessionContext, app.getAppHandler());
appBean.save()

可以在頁面包含的任意一個Bean類使用,因爲app對象代表的就是當前頁面;
7,刷新頁面的某個表格

DataBean table = app.getDataBean("results_showlist2_sssss");//參數值爲xml內表格的id屬性值
table.getMboSet().setWhere("過濾條件");//如果不需要過濾條件的話就不要這句
table.getMboSet().reset();
table.refreshTable();

備忘:xml切換tab頁的事件屬性爲tabchangeevent=“fresh”,屬性值fresh是bean中定義的某個方法名。
8,發送工作流

/**
 * 啓動工作流和流程審批
 * @author 健新科技大佬傑哥
 * @date:  2018-9-14 下午4:34:44
 */
public class WorkFlowUtil {
	
	
	public static void sendWorkflow(MboRemote mbo,String actionid,String wfmemo) throws Exception {
		WFInstanceRemote wfinstance = (WFInstanceRemote) ((WorkFlowServiceRemote) MXServer
				.getMXServer().lookup("WORKFLOW")).getActiveInstances(mbo).getMbo(0);
		if (wfinstance != null&& wfinstance.getBoolean("active")) { // 已有工作流實例,完成任務分配
			forwardWF(mbo,wfinstance,actionid,wfmemo);
		}else{
			activateWF(mbo);//發送工作流
		}
	}

	/**
	 * 啓動新工作流實例
	 * @param mbo
	 * @throws RemoteException
	 * @throws MXException
	 */
	public static void activateWF(MboRemote mbo) throws Exception {
		String str = "objectname=:1 and enabled=1 and active=1";
		SqlFormat sqf = new SqlFormat(mbo.getUserInfo(), str);
		sqf.setObject(1, "WFPROCESS", "OBJECTNAME", mbo.getName());

		MboSetRemote wfprocessSet = mbo.getMboSet("$wfprocess", "WFPROCESS",
				sqf.format());
		if (wfprocessSet.count() > 0) {
			MboRemote wfprocess = wfprocessSet.getMbo(0);
			((WorkFlowServiceRemote) MXServer.getMXServer().lookup("WORKFLOW")).initiateWorkflow(wfprocess.getString("PROCESSNAME"), mbo);
		}else{
			throw new Exception("發送流程失敗,WFPROCESS工作流設計找不到對應的流程配置!");
		}
	}
	
	/**
	 * 流程審批
	 * @param mbo
	 * @param wfinstance
	 * @param wfuser
	 * @throws MXException
	 * @throws RemoteException
	 */
	public static void forwardWF(MboRemote mbo,WFInstanceRemote wfinstance,String actionid,String wfmemo) throws Exception {
		MboSetRemote wfassignmentSet = wfinstance.getMboSet("WFASSIGNMENT");
		wfassignmentSet.setQbeExactMatch(true);
		wfassignmentSet.setQbe("assigncode", mbo.getUserInfo().getUserName());
		wfassignmentSet.reset();

		if (wfassignmentSet.count() > 0) {
			MboRemote wfassignment = wfassignmentSet.getMbo(0);
			if(StringUtil.isEmptyString(actionid)){
				//獲取默認的
				WFActionRemote action = wfinstance.getActions().getAction(true);
				wfinstance.completeWorkflowAssignment(wfassignment.getInt("ASSIGNID"),action.getInt("actionid"), wfmemo);
			}else{
				//獲取傳過來的
				String[] split = actionid.split("-");
				if(split.length == 2){
					//如果同時有兩個actionid,就代表是選擇操作類型的節點,需要同時搞兩次completeWorkflowAssignment,注意第一次的時候,memo參數必須是yes
					wfinstance.completeWorkflowAssignment(wfassignment.getInt("ASSIGNID"),Integer.parseInt(split[0]), wfmemo);
					wfinstance.completeWorkflowAssignment(wfassignment.getInt("ASSIGNID"),Integer.parseInt(split[1]), wfmemo);
				}else{
					wfinstance.completeWorkflowAssignment(wfassignment.getInt("ASSIGNID"),Integer.parseInt(actionid), wfmemo);
				}
			}
		}else{
			throw new Exception("發送流程失敗,該工作流沒有任務分配此用戶!");
		}
	}
}

這是公司大佬寫的工具類,可以使用類裏面響應的方法發送工作流。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章