|
|
@@ -2,10 +2,7 @@ package com.uas.eis.core;
|
|
|
|
|
|
import com.uas.eis.config.SynaConfig;
|
|
|
import com.uas.eis.dao.BaseDao;
|
|
|
-import com.uas.eis.entity.Purchase;
|
|
|
-import com.uas.eis.entity.PurchaseChange;
|
|
|
-import com.uas.eis.entity.PurchaseChangeDetail;
|
|
|
-import com.uas.eis.entity.PurchaseDetail;
|
|
|
+import com.uas.eis.entity.*;
|
|
|
import io.xlate.edi.schema.EDISchemaException;
|
|
|
import io.xlate.edi.schema.Schema;
|
|
|
import io.xlate.edi.schema.SchemaFactory;
|
|
|
@@ -51,7 +48,17 @@ public class X12Converter {
|
|
|
.writeElement("^")
|
|
|
.writeEndSegment();
|
|
|
}
|
|
|
-
|
|
|
+ private void addGS(EDIStreamWriter writer,String type,String id,String rule) throws EDIStreamException {
|
|
|
+ writer.writeStartSegment("GS").writeElement(type)
|
|
|
+ .writeElement("WORLDSHINE") // GS02
|
|
|
+ .writeElement("SYNAPTICSD") // GS03
|
|
|
+ .writeElement(new SimpleDateFormat("yyyyMMdd").format(new Date())) // GS04 (日期)
|
|
|
+ .writeElement(new SimpleDateFormat("HHmm").format(new Date())) // GS05 (时间)
|
|
|
+ .writeElement(id) // GS06
|
|
|
+ .writeElement(rule) // T-运输数据协调委员会(TDCC),X-公认标准委员会
|
|
|
+ .writeElement("004010")//X12版本
|
|
|
+ .writeEndSegment(); // GS08
|
|
|
+ }
|
|
|
public String convertToX12(Purchase po,String ediId,SynaConfig synaConfig) throws EDISchemaException, EDIStreamException {
|
|
|
OutputStream stream=new ByteArrayOutputStream();
|
|
|
EDIStreamWriter writer = newEDIWriter(stream);
|
|
|
@@ -60,18 +67,11 @@ public class X12Converter {
|
|
|
|
|
|
startSegment(writer,ediId);
|
|
|
//PO
|
|
|
- writer.writeStartSegment("GS").writeElement("PO")
|
|
|
- .writeElement("WORLDSHINE") // GS02
|
|
|
- .writeElement("SYNAPTICSD") // GS03
|
|
|
- .writeElement(new SimpleDateFormat("yyyyMMdd").format(new Date())) // GS04 (日期)
|
|
|
- .writeElement(new SimpleDateFormat("HHmm").format(new Date())) // GS05 (时间)
|
|
|
- .writeElement(String.valueOf(po.getPu_id())) // GS06
|
|
|
- .writeElement("T") // T-运输数据协调委员会(TDCC),X-公认标准委员会
|
|
|
- .writeElement("004010")//X12版本
|
|
|
- .writeEndSegment(); // GS08
|
|
|
+ addGS(writer,"PO",String.valueOf(po.getPu_id()),"T");
|
|
|
+
|
|
|
int txCount = 1;
|
|
|
writer.writeStartSegment("ST").writeElement("850").writeElement("4221").writeEndSegment(); // 事务集控制编号
|
|
|
- txCount++; // 开始采购订单 (BEG)
|
|
|
+ txCount++;
|
|
|
|
|
|
writer.writeStartSegment("BEG")
|
|
|
.writeElement("00") // 事务集目的代码
|
|
|
@@ -161,16 +161,8 @@ public class X12Converter {
|
|
|
|
|
|
writer.startInterchange();
|
|
|
startSegment(writer,ediId);
|
|
|
+ addGS(writer,"PC",String.valueOf(pc.getPc_id()),"X");
|
|
|
|
|
|
- writer.writeStartSegment("GS").writeElement("PC")
|
|
|
- .writeElement("WORLDSHINE") // GS02
|
|
|
- .writeElement("SYNAPTICSD") // GS03
|
|
|
- .writeElement(new SimpleDateFormat("yyyyMMdd").format(new Date())) // GS04 (日期)
|
|
|
- .writeElement(new SimpleDateFormat("HHmm").format(new Date())) // GS05 (时间)
|
|
|
- .writeElement(String.valueOf(pc.getPc_id())) // String.valueOf(po.getPu_id())
|
|
|
- .writeElement("X") // T-运输数据协调委员会(TDCC),X-公认标准委员会
|
|
|
- .writeElement("004010")//X12版本
|
|
|
- .writeEndSegment(); // GS08
|
|
|
int txCount = 1;
|
|
|
writer.writeStartSegment("ST").writeElement("860").writeElement("0001").writeEndSegment(); // 事务集控制编号
|
|
|
txCount++;
|
|
|
@@ -260,4 +252,196 @@ public class X12Converter {
|
|
|
writer.close();
|
|
|
return stream.toString();
|
|
|
}
|
|
|
+ //867
|
|
|
+ public String convertToX12(POS pos, String ediId, SynaConfig synaConfig) throws EDISchemaException, EDIStreamException {
|
|
|
+ OutputStream stream=new ByteArrayOutputStream();
|
|
|
+ EDIStreamWriter writer = newEDIWriter(stream);
|
|
|
+ writer.startInterchange();
|
|
|
+ //开始
|
|
|
+ startSegment(writer,ediId);
|
|
|
+ addGS(writer,"PT",String.valueOf(pos.getPs_id()),"X");
|
|
|
+
|
|
|
+ int txCount = 1;
|
|
|
+ writer.writeStartSegment("ST").writeElement("867").writeElement("0001").writeEndSegment(); // 事务集控制编号
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("BPT")
|
|
|
+ .writeElement("00")
|
|
|
+ .writeElement(pos.getPs_code())
|
|
|
+ .writeElement(new SimpleDateFormat("yyyyMMdd").format(pos.getPs_date()))
|
|
|
+ .writeElement("02").writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("DTM")
|
|
|
+ .writeElement("090")
|
|
|
+ .writeElement(new SimpleDateFormat("yyyyMMdd").format(pos.getPs_fromdate()))//日期区间-开始
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("DTM")
|
|
|
+ .writeElement("091")
|
|
|
+ .writeElement(new SimpleDateFormat("yyyyMMdd").format(pos.getPs_enddate()))//日期区间-结束
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("N1")
|
|
|
+ .writeElement("DB")
|
|
|
+ .writeElement("WORLDSHINE TECHNOLOGY LIMITED")
|
|
|
+ .writeElement("91")
|
|
|
+ .writeElement("2973")
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("N3")
|
|
|
+ .writeElement("HK")
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ for(POSDetail pd:pos.getItems()){
|
|
|
+ /* SD: Ship and Debit Sales (MSSC in SYNA)
|
|
|
+ BS: Buy and Sales (MSST in SYNA)
|
|
|
+ RB: Return Order / RMA (MERT in SYNA)
|
|
|
+ * */
|
|
|
+ writer.writeStartSegment("PTD")
|
|
|
+ .writeElement(pd.getPd_transactionCode())//?
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ /*Disti Provided Bill To Country, please provide the TERRITORY_SHORT_NAME and TERRITORY_CODE as following mapping sheet.*/
|
|
|
+ writer.writeStartSegment("N1")
|
|
|
+ .writeElement("BT")
|
|
|
+ .writeElement(pd.getPd_billtocust())//Disti Provided Bill To Customer Ex:CSOT CHINA
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("N4")
|
|
|
+ .writeElement(pd.getPd_billtoCountryName())
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement(pd.getPd_billtoCountry())
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("N1")
|
|
|
+ .writeElement("ST")
|
|
|
+ .writeElement(pd.getPd_endCustomer())//Disti Provided End Customer: Actual end customer name which is sold by disti without code.
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ /*Disti Provided Ship To Country, please provide the TERRITORY_SHORT_NAME and TERRITORY_CODE as following mapping sheet.*/
|
|
|
+ writer.writeStartSegment("N4")
|
|
|
+ .writeElement(pd.getPd_ShipToCountryname())
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement(pd.getPd_ShipToCountry())
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("N1")
|
|
|
+ .writeElement("MA")
|
|
|
+ .writeElement(pd.getPd_endCustomer())//终端客户
|
|
|
+ .writeElement("92")
|
|
|
+ .writeElement(pd.getPd_resaleCustomerNumber())//新思中客户编号
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("N1")
|
|
|
+ .writeElement("BY")
|
|
|
+ .writeElement(pd.getPd_endCustomer())//终端客户
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ /*非必填 Actual end customer country which is sold by disti , please provide the TERRITORY_SHORT_NAME and TERRITORY_CODE as following mapping sheet.*/
|
|
|
+ writer.writeStartSegment("N4")
|
|
|
+ .writeElement(pd.getPd_endCustomerCountryName())//? Ex:China
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement(pd.getPd_endCustomerCountry())//? Ex:CN
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("QTY")
|
|
|
+ .writeElement("01")
|
|
|
+ .writeElement(String.valueOf(pd.getPd_qty()))
|
|
|
+ .writeElement("EA")
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("LIN")
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement("VP")
|
|
|
+ .writeElement(pd.getPd_orispeccode())
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ //Book Price
|
|
|
+ writer.writeStartSegment("UIT")
|
|
|
+ .writeElement("EA")
|
|
|
+ .writeElement(String.valueOf(pd.getPd_bookPrice()))
|
|
|
+ .writeElement("CA")
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ //resalePrice
|
|
|
+ writer.writeStartSegment("UIT")
|
|
|
+ .writeElement("EA")
|
|
|
+ .writeElement(String.valueOf(pd.getPd_resalePrice()))
|
|
|
+ .writeElement("RS")
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ //非必填 distiRequestedCost
|
|
|
+ writer.writeStartSegment("UIT")
|
|
|
+ .writeElement("EA")
|
|
|
+ .writeElement(String.valueOf(pd.getPd_distiRequestedCost()))
|
|
|
+ .writeElement("QT")
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("ITA")
|
|
|
+ .writeElement("R")
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement("09")
|
|
|
+ .writeElement(String.valueOf(pd.getPd_claimAmount()))
|
|
|
+ .writeElement(String.valueOf(pd.getPd_distiMarginRate()))//Disti Margin Rate
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("REF")
|
|
|
+ .writeElement("PD")
|
|
|
+ .writeElement(pd.getPd_quoteNumber())
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("REF")
|
|
|
+ .writeElement("DI")
|
|
|
+ .writeElement(pd.getPd_resaleInvoiceNum()+"/"+pd.getPd_resaleInvoiceLineNum())
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("DTM")
|
|
|
+ .writeElement("003")
|
|
|
+ .writeElement(new SimpleDateFormat("yyyyMMdd").format(pd.getPd_resaleInvoiceDate()))
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ }
|
|
|
+ writer.writeStartSegment("CUR")
|
|
|
+ .writeElement("BY")
|
|
|
+ .writeElement(pos.getPs_currency())
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ //结束
|
|
|
+ // 订单小计 (CTT)
|
|
|
+ writer.writeStartSegment("CTT")
|
|
|
+ .writeElement(String.valueOf(pos.getItems().size())).writeEndSegment();// 明细行数
|
|
|
+ txCount++;
|
|
|
+ // 结束事务集 (SE) - 需要手动计算段数量
|
|
|
+ writer.writeStartSegment("SE")
|
|
|
+ .writeElement(String.valueOf(txCount)) // 段数量 (ST到SE之间的段数,包括ST和SE)
|
|
|
+ .writeElement("0001").writeEndSegment(); // 事务集控制编号 (与ST中的一致)
|
|
|
+
|
|
|
+ writer.writeStartSegment("GE")
|
|
|
+ .writeElement("1")
|
|
|
+ .writeElement(String.valueOf(pos.getPs_id())) .writeEndSegment();
|
|
|
+ writer.writeStartSegment("IEA")
|
|
|
+ .writeElement("1")
|
|
|
+ .writeElement(ediId) .writeEndSegment();
|
|
|
+ writer.endInterchange();
|
|
|
+ writer.close();
|
|
|
+ return stream.toString();
|
|
|
+ }
|
|
|
}
|