package com.app.hxqh.udmeter;

import psdi.mbo.Mbo;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSet;
import psdi.mbo.MboSetRemote;
import psdi.server.MXServer;
import psdi.util.MXApplicationException;
import psdi.util.MXException;

import java.rmi.RemoteException;

/**
 * ¼ÆÁ¿¹ÜÀí-Mbo
 * createby liuxq  2023-6-15
 */
public class UdMeterMbo extends Mbo implements MboRemote {

    public UdMeterMbo(MboSet ms) throws MXException, RemoteException {
        super(ms);
    }

    @Override
    public void add() throws MXException, RemoteException {
        super.add();
    }

    @Override
    public void init() throws MXException {
        super.init();
        try {

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void save() throws MXException, RemoteException {
        super.save();
        String app = getThisMboSet().getApp();
        if(toBeDeleted()){
            System.out.println("delete---------");
        }else if(app!=null ){
            String ASSETNUM = getString("ASSETNUM");
            String MEASUREUNITID = getString("MEASUREUNITID");
            MboSetRemote UDMETERSet = MXServer.getMXServer().getMboSet("UDMETER",MXServer.getMXServer().getSystemUserInfo());
            UDMETERSet.setWhere("ASSETNUM='"+ASSETNUM+"' AND MEASUREUNITID='"+MEASUREUNITID+"'");
            UDMETERSet.reset();
            if(UDMETERSet!=null && !UDMETERSet.isEmpty()){
                throw new MXApplicationException("UDMETER","ASSETNUM",new String[0]);
            }
        }
    }
}
