|
|
@@ -29,6 +29,7 @@ public class X12Converter {
|
|
|
writer.setControlSchema(controlSchema);
|
|
|
return writer;
|
|
|
}
|
|
|
+
|
|
|
private void startSegment(EDIStreamWriter writer,String ediId,SynaConfig synaConfig) throws EDIStreamException {
|
|
|
writer.writeStartSegment("ISA")
|
|
|
.writeElement("00")
|
|
|
@@ -52,6 +53,31 @@ public class X12Converter {
|
|
|
}
|
|
|
writer.writeElement("^").writeEndSegment();
|
|
|
}
|
|
|
+
|
|
|
+ private void startSegment_R(EDIStreamWriter writer,String ediId,SynaConfig synaConfig) throws EDIStreamException {
|
|
|
+ writer.writeStartSegment("ISA")
|
|
|
+ .writeElement("00")
|
|
|
+ .writeElement(" ")
|
|
|
+ .writeElement("00")
|
|
|
+ .writeElement(" ")
|
|
|
+ .writeElement("ZZ")
|
|
|
+ .writeElement("SYNAPTICST ")
|
|
|
+ .writeElement("ZZ")
|
|
|
+ .writeElement("WORLDSHINE ")
|
|
|
+ .writeElement(new SimpleDateFormat("yyMMdd").format(new Date())) // GS04 (日期)
|
|
|
+ .writeElement(new SimpleDateFormat("HHmm").format(new Date())) // GS05 (时间)
|
|
|
+ .writeElement("U")
|
|
|
+ .writeElement(X12_VERSION)
|
|
|
+ .writeElement(ediId)
|
|
|
+ .writeElement("0");
|
|
|
+ if(synaConfig.isProd()){
|
|
|
+ writer .writeElement("P");//T,表示测试数据;P,表示生产数据,这里是T
|
|
|
+ }else{
|
|
|
+ writer .writeElement("T");//T,表示测试数据;P,表示生产数据,这里是T
|
|
|
+ }
|
|
|
+ writer.writeElement("^").writeEndSegment();
|
|
|
+ }
|
|
|
+
|
|
|
private void addGS(EDIStreamWriter writer,String type,String id,String rule) throws EDIStreamException {
|
|
|
writer.writeStartSegment("GS").writeElement(type)
|
|
|
.writeElement("WORLDSHINE") // GS02
|
|
|
@@ -63,6 +89,19 @@ public class X12Converter {
|
|
|
.writeElement("004010")//X12版本
|
|
|
.writeEndSegment(); // GS08
|
|
|
}
|
|
|
+
|
|
|
+ private void addGS_R(EDIStreamWriter writer,String type,String id,String rule) throws EDIStreamException {
|
|
|
+ writer.writeStartSegment("GS").writeElement(type)
|
|
|
+ .writeElement("SYNAPTICSD") // GS02
|
|
|
+ .writeElement("WORLDSHINE") // 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);
|
|
|
@@ -456,4 +495,124 @@ public class X12Converter {
|
|
|
writer.close();
|
|
|
return stream.toString();
|
|
|
}
|
|
|
+ public String convertToX12(INV inv, String ediId, SynaConfig synaConfig) throws EDISchemaException, EDIStreamException {
|
|
|
+ OutputStream stream=new ByteArrayOutputStream();
|
|
|
+ EDIStreamWriter writer = newEDIWriter(stream);
|
|
|
+ writer.startInterchange();
|
|
|
+ //开始
|
|
|
+ startSegment_R(writer,ediId,synaConfig);
|
|
|
+ addGS_R(writer,"IB",String.valueOf(inv.getIs_id()),"X");
|
|
|
+
|
|
|
+ int txCount = 1;
|
|
|
+ writer.writeStartSegment("ST").writeElement("846").writeElement("4567").writeEndSegment(); // 事务集控制编号
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("BIA")
|
|
|
+ .writeElement("00")
|
|
|
+ .writeElement("DM")
|
|
|
+ .writeElement("KEY_OF_REPORT")
|
|
|
+ .writeElement(new SimpleDateFormat("yyyyMMdd").format(inv.getIs_date())).writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+
|
|
|
+ writer.writeStartSegment("CUR")
|
|
|
+ .writeElement("BY")
|
|
|
+ .writeElement(inv.getIs_currency())
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("DTM")
|
|
|
+ .writeElement("600")
|
|
|
+ .writeElement(new SimpleDateFormat("yyyyMMdd").format(inv.getIs_date()))
|
|
|
+ .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(INVDetail id:inv.getItems()){
|
|
|
+ writer.writeStartSegment("LIN")
|
|
|
+ .writeElement(String.valueOf(id.getId_detno()))
|
|
|
+ .writeElement("VP")
|
|
|
+ .writeElement(id.getId_orispeccode())
|
|
|
+ .writeElement("CP")
|
|
|
+ .writeElement( (id.getId_custprodcode()==null?"":id.getId_custprodcode()) ) .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("REF")
|
|
|
+ .writeElement("PR")
|
|
|
+ .writeElement(id.getId_quote()).writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("REF")
|
|
|
+ .writeElement("ZZ")
|
|
|
+ .writeElement(String.valueOf(id.getId_amount())).writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("QTY")
|
|
|
+ .writeElement("17")
|
|
|
+ .writeElement(String.valueOf(id.getId_qty()))
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("UIT")
|
|
|
+ .writeElement("EA")
|
|
|
+ .writeElement(String.valueOf(id.getId_price()))
|
|
|
+ .writeElement("CA")
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("N1")
|
|
|
+ .writeElement("MA")
|
|
|
+ .writeElement( (id.getId_odm()==null?"":id.getId_odm()) )
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("N1")
|
|
|
+ .writeElement("BY")
|
|
|
+ .writeElement( (id.getId_oem()==null?"":id.getId_oem()) )
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("N1")
|
|
|
+ .writeElement("DB")
|
|
|
+ .writeElement("WORLDSHINE TECHNOLOGY LIMITED")
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("N4")
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement(id.getId_distiregion())
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("N1")
|
|
|
+ .writeElement("WH")
|
|
|
+ .writeElement("NA")
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("N4")
|
|
|
+ .writeElement( (id.getId_stockcity()==null?"":id.getId_stockcity()) )
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement("")
|
|
|
+ .writeElement(id.getId_stockcountry())
|
|
|
+ .writeEndSegment();
|
|
|
+ txCount++;
|
|
|
+ }
|
|
|
+ //结束
|
|
|
+ // 订单小计 (CTT)
|
|
|
+ writer.writeStartSegment("CTT")
|
|
|
+ .writeElement(String.valueOf(inv.getItems().size())).writeEndSegment();// 明细行数
|
|
|
+ txCount++;
|
|
|
+ writer.writeStartSegment("SE")
|
|
|
+ .writeElement(String.valueOf(txCount)) // 段数量 (ST到SE之间的段数,包括ST和SE)
|
|
|
+ .writeElement("4567").writeEndSegment(); // 事务集控制编号 (与ST中的一致)
|
|
|
+
|
|
|
+ writer.writeStartSegment("GE")
|
|
|
+ .writeElement("1")
|
|
|
+ .writeElement(String.valueOf(inv.getIs_id())) .writeEndSegment();
|
|
|
+ writer.writeStartSegment("IEA")
|
|
|
+ .writeElement("1")
|
|
|
+ .writeElement(ediId) .writeEndSegment();
|
|
|
+ writer.endInterchange();
|
|
|
+ writer.close();
|
|
|
+ return stream.toString();
|
|
|
+ }
|
|
|
}
|