package com.app.hxqh.udworkorder;

import psdi.mbo.MboRemote;
import psdi.mbo.MboValue;
import psdi.mbo.MboValueAdapter;
import psdi.util.MXApplicationException;
import psdi.util.MXException;

import java.rmi.RemoteException;
import java.util.Date;

/**
 * 日常维修工单-实际开始时间
 * edit 2023-10-5
 */
public class FldACTSTART extends MboValueAdapter {

    public FldACTSTART(MboValue mbv) throws MXException {
        super(mbv);
    }

    public void action() throws MXException, RemoteException {
        super.action();
        MboRemote mbo=getMboValue().getMbo();
        Date actfinsh=mbo.getDate("ACTFINISH");//	实际完成时间
        Date actstart=mbo.getDate("ACTSTART");// 实际开始时间
        if(null==actstart || null==actfinsh){
            mbo.setValueNull("ESTDUR", 2L);
        }else{
            long minutesDifference=(actfinsh.getTime()-actstart.getTime())/ (60 * 1000);
            if(minutesDifference<=0){
                throw new MXApplicationException("actstar","actstar1",new String[0]);
            }else{
                mbo.setValue("ESTDUR", minutesDifference, 2L);
                mbo.setValue("SHUTDURA", minutesDifference, 2L);
            }
        }
    }
}
