package com.webclient.beans.pmexec;

import psdi.app.workorder.WO;
import psdi.app.workorder.WOSet;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.util.MXException;
import psdi.webclient.system.beans.DataBean;
import psdi.webclient.system.controller.WebClientEvent;

import java.rmi.RemoteException;

/**
 * 点检保养任务生成日常维修工单按钮
 * edit 2023-05-04
 */
public class SpotrunLinesDataBean extends DataBean {

    public int createwo() throws MXException, RemoteException {
        MboRemote appMbo=app.getAppBean().getMbo();
        MboRemote mbo=getMbo();
        String spotrunum=mbo.getString("SPOTRUNNUM");
        int spotrunlinenum=mbo.getInt("NUM");
        String userid = this.app.getBeanForApp().getMbo().getUserInfo().getPersonId();
        MboSetRemote woSet = mbo.getMboSet("$UDWORKORDER","UDWORKORDER","1=2");
        MboRemote workorderMbo = woSet.addAtEnd(11L);
        workorderMbo.setValue("CREATEBY", userid,11L);
        workorderMbo.setValue("LEAD", userid,11L);
        workorderMbo.setValue("DESCRIPTION", "点检保养任务-"+getString("DESCRIPTION"));
        workorderMbo.setValue("STATUS", "EDIT",11L);
        workorderMbo.setValue("ASSETNUM", getString("ASSETNUM"),11L);
        workorderMbo.setValue("LOCATION", getString("LOCATION"),11L);
        workorderMbo.setValue("GDLY", "PMEXEC",11L);
        workorderMbo.setValue("SPOTRUNNUM", spotrunum,11L);
        workorderMbo.setValue("SPOTRUNLINENUM", spotrunlinenum+"",11L);
        workorderMbo.setValue("APPNAME", "UDWORKORDER",11L);
        mbo.setValue("UDWORKORDERID", workorderMbo.getInt("UDWORKORDERID"), 2L);
        mbo.getThisMboSet().save();
        workorderMbo.getThisMboSet().save();

        String appName = "UDWORKORDER";
        StringBuffer newUrl = new StringBuffer(this.clientSession.getMaximoRequestURI());
        newUrl.append("?event=gotoapp&value=" +appName+"&uniqueid="+workorderMbo.getInt("UDWORKORDERID"));
        this.clientSession.getCurrentApp().put("forcereload", "true");
        this.clientSession.gotoApplink(newUrl.toString());
        return 1;
    }


}
