package com.app.hxqh.udtransfer;

import psdi.mbo.MAXTableDomain;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.mbo.MboValue;
import psdi.server.MXServer;
import psdi.util.MXException;

import java.rmi.RemoteException;

/**
 * 资产修改-选择固定资产编号
 */
public class FldGDZCBHNum extends MAXTableDomain {

    public FldGDZCBHNum(MboValue mbv) throws MXException,RemoteException {
        super(mbv);
        String thisAttr = getMboValue().getAttributeName();
        setRelationship("UDGDZC", "");
        String[] FromStr = { "ANLN1" };
        String[] ToStr = { thisAttr };
        setLookupKeyMapInOrder(ToStr, FromStr);
    }

    public void init() throws RemoteException, MXException {
        super.init();
    }
    public void action() throws RemoteException, MXException {
        super.action();
        MboRemote mbo=getMboValue().getMbo();
        String ANLN1 = mbo.getString("ANLN1"); //固定资产编号
        String siteid = mbo.getString("SITEID");//地点
        String orgid = mbo.getString("ORGID");//组织
        MboSetRemote assetSet = MXServer.getMXServer().getMboSet("ASSET",MXServer.getMXServer().getSystemUserInfo());
        assetSet.setWhere("ORGID='"+orgid+"' AND SITEID='"+siteid+"' and SDGDZCBM='"+ANLN1+"'");
        assetSet.reset();
        if(assetSet!=null && !assetSet.isEmpty()){
            int size = assetSet.getSize();
            if(size==1){
                //只有一对一关联的情况下，才赋值设备编号，否则不赋值
                MboRemote assetMbo = assetSet.getMbo(0);
                String ASSETNUM = assetMbo.getString("ASSETNUM");
                mbo.setValue("ASSETNUM", ASSETNUM);
            }
        }
    }

    public MboSetRemote getList() throws RemoteException, MXException {
        MboRemote mbo = getMboValue().getMbo();
        MboRemote ownerMbo=mbo.getOwner();
        String siteid = mbo.getString("SITEID");//地点
        String orgid = mbo.getString("ORGID");//组织
        String company = "";//公司
        MboSetRemote siteSet = MXServer.getMXServer().getMboSet("SITE",MXServer.getMXServer().getSystemUserInfo());
        siteSet.setWhere("ORGID='"+orgid+"' AND SITEID='"+siteid+"'");
        siteSet.reset();
        if(siteSet!=null && !siteSet.isEmpty()){
            MboRemote siteMbo = siteSet.getMbo(0);
            company = siteMbo.getString("COMPANY");//公司
        }
        String sql = " BUKRS='"+company+"'";
        setListCriteria(sql);
        return super.getList();
    }
}