unknown
2014-04-08 6d9cbf0b9f65667c112e84c56eb3fec4a57f02ce
feeder xml
1 files modified
199 ■■■■■ changed files
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/DMMSNddUpdateJob.java 199 ●●●●● patch | view | raw | blame | history
xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/DMMSNddUpdateJob.java
@@ -411,6 +411,199 @@
  }
    private void doJob2(Connection postsql, String[] info)  throws SQLException
    {
        // double switch (if db = enable -->work)
        //Here is check
        Date dtnow = new Date();
        //get all file
        //dept,  count,dist,nei ,y,m,d,t,custom
        // HashMap<String>
        String typhoonName="";
        String typhoonID="";
        String department="";
        String department_id="";
        String substation="";
        String substation_ufid="";
        String substation_affectCustomers="";
        String substation_nopower="";
        String mxfmr_name="";
        String mxfmr_ufid="";
        String mxfmr_affectCustomers="";
        String mxfmr_nopower="";
        String feeder_name="";
        String feeder_id="";
        String feeder_affectCustomers="";
        String feeder_nopower="";
        String[] tmpArray;
        String sTemp;
        List<String> arraySQLVals= new ArrayList<String>();
        if(!jobOnLine(postsql, "nddfeeder"))
        {
            return;
        }
        String yy="0000"+String.valueOf( dtnow.getYear()+1900);
        String mm="00"+String.valueOf( dtnow.getMonth()+1);
        String dd="00"+String.valueOf( dtnow.getDate());
        String t0="00"+ String.valueOf( dtnow.getHours());
        String t1="00"+ String.valueOf( dtnow.getMinutes());
        yy=        yy.substring(yy.length()-4);
        mm=         mm.substring(mm.length()-2);
        dd=        dd.substring(dd.length()-2);
        t0=        t0.substring(t0.length()-2);
        t1=        t1.substring(t1.length()-2);
        logger.info("begin nddxml(feeder) to postsql");
        logger.info("getftpfile...");
        String[] xmls= getNDDStrings(info, "feeder_affect_customers.xml") ;
        logger.info(String.format("total %d file(s)",xmls.length));
        for(int iRow=0;iRow<xmls.length;iRow++)
        {
            tmpArray= xmls[iRow].split("\n");
            for(int iLine=0;iLine<tmpArray.length;iLine++)
            {
                sTemp= findValue(tmpArray[iLine],"typhoonName");
                if(sTemp.length()>0)
                {
                    typhoonName= sTemp;
                    typhoonID= getTyphoonIDByName(postsql,typhoonName);
                    //
                    sTemp= findValue(tmpArray[iLine],"Department id");
                    department_id=sTemp;
                    sTemp= findValue(tmpArray[iLine],"name");
                    department=sTemp;
                }
                sTemp= findValue(tmpArray[iLine],"Substation name");
                if(sTemp.length()>0)
                {
                    substation=sTemp;
                    sTemp= findValue(tmpArray[iLine],"ufid");
                    if(sTemp.length()>0)
                    {
                        substation_ufid=sTemp;
                    }
                    sTemp= findValue(tmpArray[iLine],"affectCustomers");
                    if(sTemp.length()>0)
                    {
                        substation_affectCustomers=sTemp;
                    }
                    sTemp= findValue(tmpArray[iLine],"noPowerAll");
                    if(sTemp.length()>0)
                    {
                        substation_nopower=sTemp;
                    }
                    //
                    arraySQLVals.add(String.format("(%s,%s,%s,%s,%s,'%s','%s','%s','%s',%s,%s,%s,%s,%s,'%s%s')",
                            typhoonID,
                            department_id,substation_ufid,"-1","-1",
                            department,substation," "," ",
                            substation_affectCustomers,substation_nopower,
                            yy,mm,dd,t0,t1));
                }
                sTemp= findValue(tmpArray[iLine],"Mxfmr name");
                if(sTemp.length()>0)
                {
                    mxfmr_name=sTemp;
                    sTemp= findValue(tmpArray[iLine],"ufid");
                    if(sTemp.length()>0)
                    {
                        mxfmr_ufid=sTemp;
                    }
                    sTemp= findValue(tmpArray[iLine],"affectCustomers");
                    if(sTemp.length()>0)
                    {
                        mxfmr_affectCustomers=sTemp;
                    }
                    sTemp= findValue(tmpArray[iLine],"noPowerAll");
                    if(sTemp.length()>0)
                    {
                        mxfmr_nopower=sTemp;
                    }
                    arraySQLVals.add(String.format("(%s,%s,%s,%s,%s,'%s','%s','%s','%s',%s,%s,%s,%s,%s,'%s%s')",
                            typhoonID,
                            department_id,substation_ufid,mxfmr_ufid,"-1",
                            department,substation,mxfmr_name," ",
                            mxfmr_affectCustomers,mxfmr_nopower,
                            yy,mm,dd,t0,t1));
                }
                sTemp= findValue(tmpArray[iLine],"Feeder name");
                if(sTemp.length()>0)
                {
                    feeder_name=sTemp;
                    sTemp= findValue(tmpArray[iLine],"id");
                    if(sTemp.length()>0)
                    {
                        feeder_id=sTemp;
                    }
                    sTemp= findValue(tmpArray[iLine],"affectCustomers");
                    if(sTemp.length()>0)
                    {
                        feeder_affectCustomers=sTemp;
                    }
                    sTemp= findValue(tmpArray[iLine],"noPowerAll");
                    if(sTemp.length()>0)
                    {
                        feeder_nopower=sTemp;
                    }
                    arraySQLVals.add(String.format("(%s,%s,%s,%s,%s,'%s','%s','%s','%s',%s,%s,%s,%s,%s,'%s%s')",
                            typhoonID,
                            department_id,substation_ufid,mxfmr_ufid,feeder_id,
                            department,substation,mxfmr_name,feeder_name,
                            feeder_affectCustomers,feeder_nopower,
                            yy,mm,dd,t0,t1));
                }
                    // insert into nddcanton_history (project_id,department_id,county_id,district_id,neighbor_id,affectcustomers,affectcustomersever
                    //yy,mm,dd,tt
            }
            //!!
            String insertDBSQL=
                    " insert into ndd.nddfeeder_history (project_id,department_id,substation_id,mxfmr_id,feeder_id,"+
                    "department_name,substation_name,mxfmr_name,feeder_name,"+
                    "affectCustomers,nopower"+
                    ",yy,mm,dd,tt) values ";
            for(int j=0;j<arraySQLVals.size();j++)
            {
                sqlExec(postsql,insertDBSQL + arraySQLVals.get(j)
                       ,
                        new String[]{});
            }
            String strSQLUpdateCurr="update ndd.currdata set yy='%s',mm='%s',dd='%s',tt='%s%s' where sr=2";
            sqlExec(postsql,
                    String.format(strSQLUpdateCurr,
                            yy,mm,dd,t0,t1
                    )  ,
                    new String[]{});
            logger.info(String.format("next xml"));
        }
        logger.info(String.format("done"));
    }
    /*
    private void doJob(Connection postsql,Connection orcl)  throws  SQLException
    {
@@ -545,6 +738,12 @@
                    pgProperties.get("ftppwd"),
                    pgProperties.get("ftpdir")
            });
            doJob2  (targetDataStore.getConnection(Transaction.AUTO_COMMIT),new String[]{
                    pgProperties.get("ftpurl"),
                    pgProperties.get("ftpuid"),
                    pgProperties.get("ftppwd"),
                    pgProperties.get("ftpdir")
            });
           // doJob( targetDataStore.getConnection(Transaction.AUTO_COMMIT),sourceDataStore.getConnection(Transaction.AUTO_COMMIT) );
        } catch (IOException ex) {