import groovy.sql.Sql
import java.sql.ResultSet
import java.sql.Timestamp
import org.compiere.util.DB
import org.compiere.util.Env
// MSSQL jdbc:sqlserver://" + dbHost + ":" + dbPort + ";databaseName=" + dbName + ";";
mssql =Sql.newInstance('jdbc:sqlserver://192.72.1.42:1433;databaseName=Origin','aaa','111111',
'com.microsoft.sqlserver.jdbc.SQLServerDriver' )
// PostgreSQL
postsql =Sql.newInstance('jdbc:postgresql://127.0.0.1/taya1028','adempiere','adempiere','org.postgresql.Driver' )
def ptable= postsql.dataSet("船期與貨況追蹤") //上傳
def isActive='Y'
def H_ID=1000000
def m_created = new Timestamp(System.currentTimeMillis());
def t_start = System.currentTimeMillis()
def id=0
def uu=' '
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");
mssql.eachRow( 'SELECT ShipmentID, InvoiceNo, 客戶單號, 料號, 船公司, 船名, 航次, 貨況追蹤.序號, 貨櫃號碼, 起運港, 結關日, 預定開航日, 實際開航日, 抵達港, 預計抵港日, 實際抵港日, 清關日 FROM 貨況追蹤' )
{
// select * from adempiere.AD_Sequence WHERE Name='船期與貨況追蹤'--1000346
postsql .query("select adempiere.nextid(1000321, 'N') as id , adempiere.generate_uuid() as uu ")
{ ResultSet rs -> if (rs.next()){ id = rs.getInt('id')
uu = rs.getString('uu') } }
postsql .query("SELECT p.packinglist_id, p.單號,p.單據日期,p.客戶_id,p.客戶英文全名,p.客戶全名,p.客戶送貨地址,p.傳真,p.電話, p.出口公司,p.起運港,p.抵達港,p.結關日,p.嘜頭_id,p.正嘜,p.側嘜, l.訂單_id,l.包裝編號,l.品號_id,l.品名,l.規格, o.訂單單號, o.客戶單號 FROM adempiere.packinglist p INNER JOIN adempiere.packinglistline l ON p.packinglist_id=l.packinglist_id INNER JOIN adempiere.訂單 o ON o.訂單_id=l.訂單_id WHERE p.單號='"+ it.InvoiceNo + "'")
{ ResultSet rs -> if (rs.next()){
id = rs.getInt('id')
uu = rs.getString('uu')
println " ${it.ShipmentID} ${it.InvoiceNo} "
ptable.add(
ad_client_id:client, ad_org_id:org, isactive: 'Y', created:m_created , createdby:uid, updated:m_created, updatedby:uid,
"船期與貨況追蹤_id":id, "船期與貨況追蹤_uu":uu,
ShipmentID:it.ShipmentID, InvoiceNo:it.InvoiceNo ,
"客戶單號":rs.getString('客戶單號'),
"料號":rs.getString('料號'),
packinglist_id:rs.getInt('packinglist_id'),
"船公司":it.船公司, "船名":it.船名, "航次":it.航次, // shippingorder:
"貨櫃號碼":it.貨櫃號碼, "起運港":it.起運港, "結關日":it.結關日,
"預定開航日":it.預定開航日, "實際開航日":it.實際開航日,
"抵達港":it.抵達港,
// "預計抵港日":it.預計抵港日,
"實際抵港日":it.實際抵港日,
"清關日":it.清關日
)
} }
}
def t_end = System.currentTimeMillis()
result="執行完成: " + (t_end - t_start)
沒有留言:
張貼留言