
package psdi.workflow.woreq;

import java.rmi.RemoteException;
import java.util.Properties;

import psdi.common.role.*;
import psdi.mbo.*;
import psdi.server.MXServer;
import psdi.util.MXApplicationException;
import psdi.util.MXException;

public class PlantEqpmntRole extends CustomRoleAdapter
        implements CustomRoleInterface {

    public PlantEqpmntRole() {
    }

    public MboRemote evaluateCustomRole(MaxRole roleMbo, MboRemote currentMbo) throws MXException, RemoteException {
        //获得当前Mbo 下的班组
        String sdeptnum = currentMbo.getString("wopm2");//班组代码
        sdeptnum = (sdeptnum == null) ? "" : sdeptnum.trim();
        MboSetRemote depts = roleMbo.getMboSet("$dept", "dept");
        depts.setWhere("deptnum ='" + sdeptnum + "'");
        depts.reset();
        MboRemote deptmbo = depts.getMbo(0);
        String supnum = deptmbo.getString("SUPNUM");//车间代码
        supnum = (supnum == null) ? "" : supnum.trim();
        depts.setWhere("deptnum ='" + supnum + "'");
        depts.reset();
        deptmbo = depts.getMbo(0);
        supnum = deptmbo.getString("SUPNUM");//工厂代码
        supnum = (supnum == null) ? "" : supnum.trim();
        depts.setWhere("SUPNUM ='" + supnum + "' and DEPTTYPE ='E'");
        depts.reset();
        deptmbo = depts.getMbo(0);
        String deptnum = deptmbo.getString("DEPTNUM");//设备部部门代码
        deptnum = (deptnum == null)?"":deptnum.trim();
        MboRemote persongroup = null;
        MboSetRemote persongroups = roleMbo.getMboSet("$persongroup", "persongroup");
        //persongroups.setWhere("PERSONGROUP ='DEPTDIR03'");
        persongroups.setWhere("ROLETYPE ='PLANTEQP' and DEPTNUM='" + deptnum + "'");
        persongroups.reset();
        persongroup = persongroups.getMbo(0);
        if (persongroup == null)
            throw new MXApplicationException("", "PLANTEQP" + " 组,不在人员组中，请与系统管理员联系！");
        else
            //返回一个人员组的 MboRemote
            return persongroup;
    }
}