MAXIMO部分AppBean类操作经验

时间:2019-02-21
本文章向大家介绍MAXIMO部分AppBean类操作经验,主要包括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 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("发送流程失败,该工作流没有任务分配此用户!");
		}
	}
}

这是公司大佬写的工具类,可以使用类里面响应的方法发送工作流。