package com.app.hxqh.assetdispo;

import psdi.mbo.*;
import psdi.util.MXException;

import java.rmi.RemoteException;

/**
 * 选择固定资产编号
 * createby liuxq 2023-6-17
 */
public class FldAssetGDZCNum extends MAXTableDomain {

    public FldAssetGDZCNum(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 sdgdzcnum=mbo.getString("SDGDZCBM");
        String siteid=mbo.getString("SITEID");
        MboSetRemote assetSet=mbo.getMboSet("$ASSET", "ASSET", "SDGDZCBM='"+sdgdzcnum+"' AND SITEID='"+siteid+"' ");
        if(null!=assetSet && !assetSet.isEmpty()){
            if(assetSet.count()==1){
                String assetnum=assetSet.getMbo(0).getString("ASSETNUM");
                mbo.setValue("ASSETNUM", assetnum, 11L);
            }
        }else{
            mbo.setValueNull("ASSETNUM", 2L);
        }
    }

    public MboSetRemote getList() throws RemoteException, MXException {
        MboRemote mbo = getMboValue().getMbo();
        String sql="BUKRS=(SELECT COMPANY FROM site WHERE siteid='"+mbo.getString("SITEID")+"') ";
        setListCriteria(sql);
        return super.getList();
    }
}