From 3e0dbd6f94193087de16ae6552a65f0f2a183d0d Mon Sep 17 00:00:00 2001
From: yuanhung <yuanhung@ximple.com.tw>
Date: Thu, 18 Aug 2016 11:47:48 +0800
Subject: [PATCH] bugfix

---
 xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/DMMSNddUpdateJob.java |  166 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 157 insertions(+), 9 deletions(-)

diff --git a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/DMMSNddUpdateJob.java b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/DMMSNddUpdateJob.java
index 22aaf35..b1d979d 100644
--- a/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/DMMSNddUpdateJob.java
+++ b/xdgnjobs/ximple-spatialjob/src/main/java/com/ximple/eofms/jobs/DMMSNddUpdateJob.java
@@ -309,6 +309,7 @@
       String[] tmpArray;
       String sTemp;
       List<String> arraySQLVals= new ArrayList<String>();
+      List<String> arraySQLValsForTyphoon= new ArrayList<String>();
       boolean bActiveCheckDBSchedule=true;
 
 
@@ -317,7 +318,7 @@
 
           return;
       }
-      String strStep0SQLNDD_rt="truncate table ndd.typhoon_tr";
+      String strStep0SQLNDD_rt="truncate table ndd.typhoon_rt";
 
       logger.info("begin nddxml to postsql");
       logger.info("getftpfile...");
@@ -328,6 +329,7 @@
       for(int iRow=0;iRow<xmls.length;iRow++)
       {
           arraySQLVals.clear();
+          arraySQLValsForTyphoon.clear();
           tmpArray= xmls[iRow].split("\n");
           for(int iLine=0;iLine<tmpArray.length;iLine++)
           {
@@ -375,6 +377,7 @@
                       affectCustomersEver="0";
                   }
                   arraySQLVals.add(String.format("(%s,%s,%s,%s,%s,%s,%s",typhoonID,department,county,district,neighbor,affectCustomers,affectCustomersEver));
+                  arraySQLValsForTyphoon.add(String.format("%s,%s,%s,%s,%s",county,district,neighbor,affectCustomers,affectCustomersEver));
                   // insert into nddcanton_history (project_id,department_id,county_id,district_id,neighbor_id,affectcustomers,affectcustomersever
                   //yy,mm,dd,tt
               }
@@ -393,26 +396,27 @@
           t1=        t1.substring(t1.length()-2);
           String insertDBSQL=" insert into ndd.nddcanton_history (project_id,department_id,county_id,district_id,neighbor_id,affectcustomers,affectcustomersever"+
                   ",yy,mm,dd,tt,ts_ser) values ";
-          String strStep1SQLNDD_rt="insert into  ndd.typhoon_tr(dts,county_id,district_id,neighbor_id,c0,c1)";
+          String strStep1SQLNDD_rt="insert into  ndd.typhoon_rt(dts,county_id,district_id,neighbor_id,c0,c1)";
 
 
           sqlExec(postsql,strStep0SQLNDD_rt,new String[]{});
 
           for(int j=0;j<arraySQLVals.size();j++)
           {
-              sqlExec(postsql,strStep1SQLNDD_rt+
-                      String.format(" values('%s',%s,%s,%s,%s,%s )",
-                              yy+mm+dd+"."+t0+t1,county,district,neighbor,affectCustomers,affectCustomersEver
-                              ),new String[]{}
-              );
+
               sqlExec(postsql,insertDBSQL + arraySQLVals.get(j)+
                       String.format(",%s,%s,%s,'%s%s',%s)",
                       yy,mm,dd,t0,t1,
                       yy+mm+dd+"."+t0+t1
                       )  ,
                       new String[]{});
-
+              sqlExec(postsql,strStep1SQLNDD_rt+
+                      String.format(" values('%s',%s )",
+                              yy+mm+dd+"."+t0+t1,arraySQLValsForTyphoon.get(j)
+                      ),new String[]{}
+              );
           }
+
 
           String strSQLUpdateCurr="update ndd.currdata set yy='%s',mm='%s',dd='%s',tt='%s%s' where sr=1";
           sqlExec(postsql,
@@ -622,6 +626,149 @@
                     )  ,
                     new String[]{});
 
+            logger.info(String.format("next xml"));
+        }
+        logger.info(String.format("done"));
+
+
+
+
+    }
+
+    private void doJob3(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 county="";
+        String district="";
+        String neighbor="";
+        String affectCustomers="";
+        String affectCustomersEver="";
+        String[] tmpArray;
+        String sTemp;
+        List<String> arraySQLVals= new ArrayList<String>();
+        List<String> arraySQLValsForTyphoon= new ArrayList<String>();
+        boolean bActiveCheckDBSchedule=true;
+
+
+        if(!jobOnLine(postsql, "nddcanton")&& bActiveCheckDBSchedule)
+        {
+
+            return;
+        }
+        String strStep0SQLNDD_rt="truncate table ndd.typhoon_rt";
+
+        logger.info("begin nddroad to postsql");
+        logger.info("getftpfile...");
+        String[] xmls= getNDDStrings(info, "*NDSExt.xml") ;
+
+
+        logger.info(String.format("total %d file(s)",xmls.length));
+        for(int iRow=0;iRow<xmls.length;iRow++)
+        {
+            arraySQLVals.clear();
+            arraySQLValsForTyphoon.clear();
+            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=sTemp;
+                }
+
+                sTemp= findValue(tmpArray[iLine],"county ufid");
+                if(sTemp.length()>0)
+                {
+                    county=sTemp;
+                }
+                sTemp= findValue(tmpArray[iLine],"district ufid");
+                if(sTemp.length()>0)
+                {
+                    district=sTemp;
+                }
+                sTemp= findValue(tmpArray[iLine],"neighbor ufid");
+                if(sTemp.length()>0)
+                {
+                    neighbor=sTemp;
+                    sTemp= findValue(tmpArray[iLine],"affectCustomers");
+                    if(sTemp.length()>0)
+                    {
+                        affectCustomers=sTemp;
+                    }
+                    else
+                    {
+                        affectCustomers="0";
+                    }
+
+                    sTemp= findValue(tmpArray[iLine],"affectCustomersEver");
+                    if(sTemp.length()>0)
+                    {
+                        affectCustomersEver=sTemp;
+                    }
+                    else
+                    {
+                        affectCustomersEver="0";
+                    }
+                    arraySQLVals.add(String.format("(%s,%s,%s,%s,%s,%s,%s",typhoonID,department,county,district,neighbor,affectCustomers,affectCustomersEver));
+                    arraySQLValsForTyphoon.add(String.format("%s,%s,%s,%s,%s",county,district,neighbor,affectCustomers,affectCustomersEver));
+                    // insert into nddcanton_history (project_id,department_id,county_id,district_id,neighbor_id,affectcustomers,affectcustomersever
+                    //yy,mm,dd,tt
+                }
+
+            }
+            //!!
+            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);
+            String insertDBSQL=" insert into ndd.nddcanton_history (project_id,department_id,county_id,district_id,neighbor_id,affectcustomers,affectcustomersever"+
+                    ",yy,mm,dd,tt,ts_ser) values ";
+            String strStep1SQLNDD_rt="insert into  ndd.typhoon_rt(dts,county_id,district_id,neighbor_id,c0,c1)";
+
+
+            sqlExec(postsql,strStep0SQLNDD_rt,new String[]{});
+
+            for(int j=0;j<arraySQLVals.size();j++)
+            {
+
+                sqlExec(postsql,insertDBSQL + arraySQLVals.get(j)+
+                                String.format(",%s,%s,%s,'%s%s',%s)",
+                                        yy,mm,dd,t0,t1,
+                                        yy+mm+dd+"."+t0+t1
+                                )  ,
+                        new String[]{});
+                sqlExec(postsql,strStep1SQLNDD_rt+
+                        String.format(" values('%s',%s )",
+                                yy+mm+dd+"."+t0+t1,arraySQLValsForTyphoon.get(j)
+                        ),new String[]{}
+                );
+            }
+
+
+            String strSQLUpdateCurr="update ndd.currdata set yy='%s',mm='%s',dd='%s',tt='%s%s' where sr=1";
+            sqlExec(postsql,
+                    String.format(strSQLUpdateCurr,
+                            yy,mm,dd,t0,t1
+                    )  ,
+                    new String[]{});
             logger.info(String.format("next xml"));
         }
         logger.info(String.format("done"));
@@ -2426,7 +2573,8 @@
             ByteArrayOutputStream bos = new ByteArrayOutputStream();
             if(filelist.length>0)
             {
-                if(ftpClient.retrieveFile(filePath+fileName,bos))
+                //if(ftpClient.retrieveFile(filelist[0],bos))
+                 if(ftpClient.retrieveFile(filePath+fileName,bos))
                 {
                     result= bos.toByteArray() ;  //negative numbers   can use (b)&0xff
                     bos.close();

--
Gitblit v0.0.0-SNAPSHOT