package psdi.webclient.beans.workorder;

import com.coolservlets.beans.jdbc.MXConnection;
import com.dbms.dbcon.DBCon;
import com.dbms.dbcon.QueryResult;
import com.dbms.dbcon.ResultRow;
import psdi.mbo.MboSetRemote;
import psdi.security.ConnectionKey;
import psdi.server.MXServer;
import psdi.util.MXException;
import psdi.util.MXSession;
import psdi.webclient.system.beans.DataBean;

import java.rmi.RemoteException;
import java.sql.Connection;

public class CustWorkorderAppBean extends WorkorderAppBean{
    String[] FldMain = {"location","assetnum","failure","problemcode","STOREROOMMTLSTATUS","istask","AVAILSTATUSDATE","apptrequired"};
    public void initializeApp() throws MXException, RemoteException {
        super.initializeApp();
    }
    public void initialize() throws MXException, RemoteException
    {
        super.initialize();
    }
    public synchronized boolean fetchRecordData() throws MXException, RemoteException
    {
        super.fetchRecordData();
        this.app.getAppBean().getMbo().setFlag(7L, false);//设置整个 mbo 所有字段不只读
        return true;
    }
    /**
     * 保存数据 2018-6-8 修改
     */
    public int SAVE()throws MXException, RemoteException{
        super.SAVE();
        return 1;
    }
    public int INSERT() throws MXException, RemoteException {
        super.INSERT();
        String appName = getMbo().getThisMboSet().getApp();
        String sPersonid = getMbo().getUserInfo().getPersonId();
        sPersonid =(sPersonid == null) ?"":sPersonid.trim();
        sPersonid = sPersonid.toUpperCase();
        setValue("reportedby", getMbo().getUserInfo().getUserName(),11L);
        setValue("WO18", getMbo().getUserInfo().getUserName(),11L);
        setValue("lead", getMbo().getUserInfo().getUserName(),11L);
        String sworktype = "PM";
        if(appName.equalsIgnoreCase("WOMAT")){
            sworktype = "LL";
            setValue("womattype", "WOL", 11L);
        }else{
            if(appName.equalsIgnoreCase("wodaily".toUpperCase())){
                sworktype = "PM";
            }
        }
        setValue("worktype", sworktype, 11L);
        getMbo().setFieldFlag("reportedby",7L,true);
        getMbo().setFieldFlag("WO18",7L,true);
        //ConnectionKey connectionKey = getMbo().getUserInfo().getConnectionKey();
        String LaborDept[] = null;
        try {
            MboSetRemote nPersonSets = getMbo().getMboSet("$PERSON_TEMP","PERSON");
            nPersonSets.setWhere("PERSONID ='" + sPersonid + "'");
            nPersonSets.reset();
            if(nPersonSets != null){
                if(!nPersonSets.isEmpty()){
                    String deptnum = nPersonSets.getMbo(0).getString("DEPARTMENT");
                    deptnum =(deptnum == null)?"":deptnum.trim();
                    String supervisor = nPersonSets.getMbo(0).getString("SUPERVISOR");
                    supervisor =(supervisor == null)?"":supervisor.trim();
                    setValue("HDDEPT", deptnum,11L);
                    setValue("HDONGROUP", deptnum,11L);
                    setValue("supervisor", supervisor,11L);
                    getMbo().setFieldFlag("HDDEPT",7L,true);
                    getMbo().setFieldFlag("HDONGROUP",7L,true);
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return 1;
    }
}
