2014年6月28日 星期六

iDempiere Oracle HIS SAP 系統轉換 groovy:H_Search_IPD2



groovy:H_Search_IPD2


import groovy.sql.Sql
import java.sql.Timestamp
import java.sql.PreparedStatement
import java.sql.ResultSet
import java.sql.Types
import org.compiere.util.Env
import org.compiere.util.DB

int client=Env.getContextAsInt(A_Ctx, "AD_Client_ID");
int org=Env.getContextAsInt(A_Ctx, "AD_Org_ID");
int uid=Env.getContextAsInt(A_Ctx, "#AD_User_ID");

def t_start= System.currentTimeMillis()
String ss= DB.getSQLValueString(null,"select value from h_search where h_search_id = ?", A_Record_ID );
DB.executeUpdateEx( "delete from h_searchline where h_search_id="+A_Record_ID+ " " , A_TrxName);

def postsql = Sql.newInstance('jdbc:postgresql://127.0.0.1/ad20140605','adempiere','adempiere','org.postgresql.Driver' )
def ptable= postsql.dataSet("H_TableName")   //上傳
//192.168.170.119
//  OPD
// def informix = Sql.newInstance( 'jdbc:informix-sqli://192.168.170.211:1534/hisopddb:informixserver=hisopdsrv;CLIENT_LOCALE=zh_tw.big5;,'informix','db@w94u6', 'com.informix.jdbc.IfxDriver' );
// IPD
// def informix = Sql.newInstance( 'jdbc:informix-sqli://192.168.170.211:1534/hisipddb:informixserver=hisipdsrv;CLIENT_LOCALE=zh_tw.big5;','informix','db@w94u6', 'com.informix.jdbc.IfxDriver' );
def informix = Sql.newInstance( 'jdbc:informix-sqli://192.168.170.119:1534/hisipddb:informixserver=hisipdsrv;CLIENT_LOCALE=zh_tw.big5;','informix','db@w94u6', 'com.informix.jdbc.IfxDriver' );

def metadata = informix.connection.metaData
String[] tableTypes = ["TABLE"]
ResultSet rs = metadata.getTables(null, null, null, tableTypes );  //"userlist"
// getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types)
// "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
String tblName = null;
while(rs.next()){
   tblName = rs.getString('TABLE_NAME');
   println ">>>>>> "+tblName
   ResultSet tblMetadata = metadata.getColumns(null, '%', tblName, null);
// ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern)  throws SQLException
   while(tblMetadata.next()){
      String TABLE_SCHEM= tblMetadata.getString("TABLE_SCHEM");
      String TABLE_NAME = tblMetadata.getString("TABLE_NAME");
      String COLUMN_NAME= tblMetadata.getString("COLUMN_NAME");
      println TABLE_SCHEM +"."+TABLE_NAME+"."+COLUMN_NAME;
      postsql.query("select adempiere.nextid(1000002, 'N') as id , adempiere.generate_uuid() as uu ")
      { ResultSet rsuu -> if (rsuu.next()){
                 id = rsuu.getInt('id')
                 uu = rsuu.getString('uu')  }   }

      ptable.add(
      ad_client_id:client, ad_org_id:org,  isactive: 'Y', createdby:uid,  updatedby:uid,
      h_tablename_id:id, h_tablename_uu:uu,
      value:TABLE_NAME,
      name:COLUMN_NAME,
      description:" [OPD] "+TABLE_SCHEM+"."+TABLE_NAME+"."+COLUMN_NAME
      )

   } // while(tblMetadata.next())
} // while(rs.next())
def t_end = System.currentTimeMillis()
result="執行完成: " + (t_end - t_start)

沒有留言:

張貼留言