|
|
@ -32,6 +32,7 @@ import com.connor.chint.sap2.util.KUtil;
|
|
|
|
import com.connor.chint.sap2.util.MyProgressBarCompent;
|
|
|
|
import com.connor.chint.sap2.util.MyProgressBarCompent;
|
|
|
|
import com.connor.chint.sap2.util.SAPMessageUtil;
|
|
|
|
import com.connor.chint.sap2.util.SAPMessageUtil;
|
|
|
|
import com.connor.chint.sap2.util.SAPUtil;
|
|
|
|
import com.connor.chint.sap2.util.SAPUtil;
|
|
|
|
|
|
|
|
import com.connor.chint.sap2.util.SqlUtil;
|
|
|
|
import com.connor.chint.sap2.util.TXTUtil;
|
|
|
|
import com.connor.chint.sap2.util.TXTUtil;
|
|
|
|
import com.squareup.okhttp.Credentials;
|
|
|
|
import com.squareup.okhttp.Credentials;
|
|
|
|
import com.squareup.okhttp.MediaType;
|
|
|
|
import com.squareup.okhttp.MediaType;
|
|
|
@ -73,6 +74,7 @@ public class BomSendSapController {
|
|
|
|
public List<PartBean> partList = new ArrayList<>();
|
|
|
|
public List<PartBean> partList = new ArrayList<>();
|
|
|
|
public BomSendSapWhFram dialog;
|
|
|
|
public BomSendSapWhFram dialog;
|
|
|
|
private SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
|
|
|
private SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
|
|
|
|
|
|
|
|
|
|
|
public BomSendSapController(BomSendSapWhFram sapzyDialog, AbstractAIFApplication app) {
|
|
|
|
public BomSendSapController(BomSendSapWhFram sapzyDialog, AbstractAIFApplication app) {
|
|
|
|
this.app = app;
|
|
|
|
this.app = app;
|
|
|
|
this.session = (TCSession) app.getSession();
|
|
|
|
this.session = (TCSession) app.getSession();
|
|
|
@ -141,18 +143,16 @@ public class BomSendSapController {
|
|
|
|
released_Yellow.save();
|
|
|
|
released_Yellow.save();
|
|
|
|
released_Yellow.unlock();
|
|
|
|
released_Yellow.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
private SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
|
|
|
|
|
|
|
|
|
|
|
|
public static String getXML() {
|
|
|
|
public static String getXML() {
|
|
|
|
String soapXML = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:chintelectric.com:xi:plm\">\r\n"
|
|
|
|
String soapXML = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:chintelectric.com:xi:plm\">\r\n"
|
|
|
|
+ " <soapenv:Header/>\r\n"
|
|
|
|
+ " <soapenv:Header/>\r\n" + " <soapenv:Body>\r\n" + " <urn:MT_MATERIAL_BOP_REQ>\r\n"
|
|
|
|
+ " <soapenv:Body>\r\n"
|
|
|
|
+ " </urn:MT_MATERIAL_BOP_REQ>\r\n" + " </soapenv:Body>\r\n" + "</soapenv:Envelope>";
|
|
|
|
+ " <urn:MT_MATERIAL_BOP_REQ>\r\n"
|
|
|
|
|
|
|
|
+ " </urn:MT_MATERIAL_BOP_REQ>\r\n"
|
|
|
|
|
|
|
|
+ " </soapenv:Body>\r\n"
|
|
|
|
|
|
|
|
+ "</soapenv:Envelope>";
|
|
|
|
|
|
|
|
return soapXML;
|
|
|
|
return soapXML;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public TCComponentItemRevision getPRevision(TCComponentItemRevision rev2) throws TCException {
|
|
|
|
public TCComponentItemRevision getPRevision(TCComponentItemRevision rev2) throws TCException {
|
|
|
|
|
|
|
|
|
|
|
|
String zt2_MaterialNo = rev2.getStringProperty("zt2_MaterialNo");
|
|
|
|
String zt2_MaterialNo = rev2.getStringProperty("zt2_MaterialNo");
|
|
|
@ -176,17 +176,48 @@ public class BomSendSapController {
|
|
|
|
return rev2;
|
|
|
|
return rev2;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getUserName(TCSession session) throws TCException {
|
|
|
|
public String getUserName(TCSession session) throws TCException {
|
|
|
|
TCComponentUser user = session.getUser();
|
|
|
|
TCComponentUser user = session.getUser();
|
|
|
|
session.getUserName();
|
|
|
|
session.getUserName();
|
|
|
|
return user.getTCProperty("user_name").getDisplayValue();
|
|
|
|
return user.getTCProperty("user_name").getDisplayValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void sendSap() {
|
|
|
|
public void sendSap() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String strs[] = session.getPreferenceService().getStringValues("database_tc");
|
|
|
|
|
|
|
|
if (SqlUtil.getTCDataConnection(strs) == null) {
|
|
|
|
|
|
|
|
MessageBox.post("数据库连接失败,请检查首选项<database_tc>", "", 2);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
List<PartBean> selectedParts = getSelectedParts();
|
|
|
|
List<PartBean> selectedParts = getSelectedParts();
|
|
|
|
|
|
|
|
// 记录SUM表信息
|
|
|
|
|
|
|
|
String userName = session.getUser().getProperty("user_name");
|
|
|
|
|
|
|
|
String dataTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
|
|
|
|
|
|
|
String zt2_WBSNo = project.getStringProperty("zt2_WBSNo");
|
|
|
|
|
|
|
|
String object_name = project.getStringProperty("object_name");
|
|
|
|
|
|
|
|
String userId = session.getUser().getUserId();
|
|
|
|
|
|
|
|
String code = BomUtilWh.getCode().toString();
|
|
|
|
|
|
|
|
StringBuilder productNosBuild = new StringBuilder("");
|
|
|
|
|
|
|
|
StringBuilder productUidsBuild = new StringBuilder("");
|
|
|
|
|
|
|
|
for (PartBean cppItem : selectedParts) {
|
|
|
|
|
|
|
|
String property = cppItem.part.getProperty(BomUtilWh.ZT2_MATERIALNO);
|
|
|
|
|
|
|
|
productNosBuild.append(property).append(";");
|
|
|
|
|
|
|
|
productUidsBuild.append(cppItem.part.getUid()).append(";");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String substring = productUidsBuild.toString().substring(0, productUidsBuild.length() - 1);
|
|
|
|
|
|
|
|
String serverHostname = session.getServerHostname();
|
|
|
|
|
|
|
|
SqlUtil.write(BomUtilWh.detailsSql, new String[] { code, "M060", userName, dataTime, zt2_WBSNo, object_name,
|
|
|
|
|
|
|
|
"产成品传递", substring, project.getUid(), serverHostname, userId });
|
|
|
|
|
|
|
|
SqlUtil.freeAll();
|
|
|
|
|
|
|
|
// 存在多个产成品时 下面的PBOM是一样的,只需要记录一次日志新的
|
|
|
|
|
|
|
|
boolean flag = true;
|
|
|
|
|
|
|
|
String batchNum = code + "-00001";
|
|
|
|
|
|
|
|
|
|
|
|
String now = format.format(new Date());
|
|
|
|
String now = format.format(new Date());
|
|
|
|
MyProgressBarCompent comp = null;
|
|
|
|
MyProgressBarCompent comp = null;
|
|
|
|
// try {
|
|
|
|
|
|
|
|
String txtName = format2.format(new Date()) + getUserName(session);
|
|
|
|
String txtName = format2.format(new Date()) + getUserName(session);
|
|
|
|
String txtPath = TXTUtil.createTxt(txtName);
|
|
|
|
String txtPath = TXTUtil.createTxt(txtName);
|
|
|
|
comp = new MyProgressBarCompent("", "正在进行项目BOM传递......");
|
|
|
|
comp = new MyProgressBarCompent("", "正在进行项目BOM传递......");
|
|
|
@ -194,8 +225,10 @@ public class BomSendSapController {
|
|
|
|
StringBuffer sendMessageAll = new StringBuffer("");
|
|
|
|
StringBuffer sendMessageAll = new StringBuffer("");
|
|
|
|
|
|
|
|
|
|
|
|
// 2024 1 22新增逻辑往CHINT_BOM_TO_SAP_SUM
|
|
|
|
// 2024 1 22新增逻辑往CHINT_BOM_TO_SAP_SUM
|
|
|
|
project.getProperty("zt2_WBSNo");
|
|
|
|
// project.getProperty("zt2_WBSNo");
|
|
|
|
// 产成品BOM组织时除了产成品不同,其他相同 BOM结构是一样的
|
|
|
|
// 产成品BOM组织时除了产成品不同,其他相同 BOM结构是一样的
|
|
|
|
|
|
|
|
// 记录产成品的物料编码
|
|
|
|
|
|
|
|
|
|
|
|
for (PartBean bean : selectedParts) {
|
|
|
|
for (PartBean bean : selectedParts) {
|
|
|
|
|
|
|
|
|
|
|
|
Document document = DocumentHelper.parseText(getXML());
|
|
|
|
Document document = DocumentHelper.parseText(getXML());
|
|
|
@ -222,8 +255,9 @@ public class BomSendSapController {
|
|
|
|
List<String> wbsList = new ArrayList<String>();
|
|
|
|
List<String> wbsList = new ArrayList<String>();
|
|
|
|
// 记录物料图纸关系的集合
|
|
|
|
// 记录物料图纸关系的集合
|
|
|
|
Map<String, TCComponentItemRevision> material_revs = new HashMap<>();
|
|
|
|
Map<String, TCComponentItemRevision> material_revs = new HashMap<>();
|
|
|
|
BomUtilWh.expandAllBomPart(bomLineTree, setWindowTopLine, rev2,
|
|
|
|
// 2024 1 24 新加字段 UID 和 BATCHNUMBER
|
|
|
|
groupName,wbsList,session,now,needTCM_meops,gy_meops,INTERGRATIONLIST,errMessage,txtPath,material_revs);
|
|
|
|
BomUtilWh.expandAllBomPart(bomLineTree, setWindowTopLine, rev2, groupName, wbsList, session, now,
|
|
|
|
|
|
|
|
needTCM_meops, gy_meops, INTERGRATIONLIST, errMessage, txtPath, material_revs, batchNum);
|
|
|
|
System.out.println("BOM全document===>" + document.asXML());
|
|
|
|
System.out.println("BOM全document===>" + document.asXML());
|
|
|
|
if (errMessage.length() > 0) {
|
|
|
|
if (errMessage.length() > 0) {
|
|
|
|
TXTUtil.writeTXT(txtPath, "----------------BOM异常--------------");
|
|
|
|
TXTUtil.writeTXT(txtPath, "----------------BOM异常--------------");
|
|
|
@ -235,7 +269,10 @@ public class BomSendSapController {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// new BomSendSapOp(session,document.asXML(),txtPath,gy_meops).executeOperation();
|
|
|
|
// new BomSendSapOp(session,document.asXML(),txtPath,gy_meops).executeOperation();
|
|
|
|
// 记录XML信息到CHINT_BOM_TO_SAP_DETIALS
|
|
|
|
// 记录XML信息到CHINT_BOM_TO_SAP_DETIALS
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
|
|
|
|
flag = false;
|
|
|
|
|
|
|
|
BomUtilWh.logXmlMsg(INTERGRATIONLIST, code, productNosBuild.toString(), batchNum, wbs, session);
|
|
|
|
|
|
|
|
}
|
|
|
|
sendMessageAll.append(SendToSap(txtPath, document.asXML()));
|
|
|
|
sendMessageAll.append(SendToSap(txtPath, document.asXML()));
|
|
|
|
win.close();
|
|
|
|
win.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -258,6 +295,8 @@ public class BomSendSapController {
|
|
|
|
} catch (Exception e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
SqlUtil.freeAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -289,7 +328,7 @@ public class BomSendSapController {
|
|
|
|
TXTUtil.writeTXT(txtPath, "----------BOM传递数据-----------");
|
|
|
|
TXTUtil.writeTXT(txtPath, "----------BOM传递数据-----------");
|
|
|
|
|
|
|
|
|
|
|
|
// 推送SAP
|
|
|
|
// 推送SAP
|
|
|
|
String[] stringValues = session.getPreferenceService().getStringValues("CHINT_WhBomUrl");
|
|
|
|
String[] stringValues = session.getPreferenceService().getStringValues("CHINT_WhBomUrl_YB");
|
|
|
|
String sapUrl = "";
|
|
|
|
String sapUrl = "";
|
|
|
|
String momUrl = "";
|
|
|
|
String momUrl = "";
|
|
|
|
for (String stringValue : stringValues) {
|
|
|
|
for (String stringValue : stringValues) {
|
|
|
@ -316,6 +355,7 @@ public class BomSendSapController {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
return errBuffer;
|
|
|
|
return errBuffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public StringBuffer sendSap(String url, String wsdlString, String txtPath) throws IOException {
|
|
|
|
public StringBuffer sendSap(String url, String wsdlString, String txtPath) throws IOException {
|
|
|
|
|
|
|
|
|
|
|
|
StringBuffer errBuffer = new StringBuffer("");
|
|
|
|
StringBuffer errBuffer = new StringBuffer("");
|
|
|
@ -327,20 +367,16 @@ public class BomSendSapController {
|
|
|
|
client.setReadTimeout(100, TimeUnit.SECONDS);
|
|
|
|
client.setReadTimeout(100, TimeUnit.SECONDS);
|
|
|
|
// Authenticator authenticator = client.setAuthenticator(new Au);
|
|
|
|
// Authenticator authenticator = client.setAuthenticator(new Au);
|
|
|
|
String credential = "";// Credentials.basic("shpodev", "sap@2019");
|
|
|
|
String credential = "";// Credentials.basic("shpodev", "sap@2019");
|
|
|
|
if(url.contains("192.168.0.184")) {
|
|
|
|
if (url.contains("192.168.0.184") || url.contains("gfpot01")) {
|
|
|
|
credential = Credentials.basic("shpodev", "sap@2019");
|
|
|
|
credential = Credentials.basic("po_rfc", "1qaz!QAZ");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
credential = Credentials.basic("shplm", "sap@2019");
|
|
|
|
credential = Credentials.basic("shplm", "sap@2019");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MediaType mediaType = MediaType.parse("application/xml");
|
|
|
|
MediaType mediaType = MediaType.parse("application/xml");
|
|
|
|
RequestBody body = RequestBody.create(mediaType, wsdlString);
|
|
|
|
RequestBody body = RequestBody.create(mediaType, wsdlString);
|
|
|
|
// http://192.168.0.184:50100/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_CHINT_ELECTRIC&receiverParty=&receiverService=&interface=SIO_MATERIAL_BOP_PLM_SYN&interfaceNamespace=urn:chintelectric.com:xi:plm
|
|
|
|
// http://192.168.0.184:50100/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_CHINT_ELECTRIC&receiverParty=&receiverService=&interface=SIO_MATERIAL_BOP_PLM_SYN&interfaceNamespace=urn:chintelectric.com:xi:plm
|
|
|
|
Request request = new Request.Builder()
|
|
|
|
Request request = new Request.Builder().url(url).method("POST", body).header("Authorization", credential)
|
|
|
|
.url(url)
|
|
|
|
.addHeader("Content-Type", "application/xml").build();
|
|
|
|
.method("POST", body)
|
|
|
|
|
|
|
|
.header("Authorization", credential)
|
|
|
|
|
|
|
|
.addHeader("Content-Type", "application/xml")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
Response response = client.newCall(request).execute();
|
|
|
|
Document document = null;
|
|
|
|
Document document = null;
|
|
|
|
|
|
|
|
|
|
|
@ -350,26 +386,26 @@ public class BomSendSapController {
|
|
|
|
TXTUtil.writeTXT(txtPath, "----------------BOM传递SAP结果--------------");
|
|
|
|
TXTUtil.writeTXT(txtPath, "----------------BOM传递SAP结果--------------");
|
|
|
|
TXTUtil.writeTXT(txtPath, string);
|
|
|
|
TXTUtil.writeTXT(txtPath, string);
|
|
|
|
TXTUtil.writeTXT(txtPath, "----------BOM传递SAP结果-----------");
|
|
|
|
TXTUtil.writeTXT(txtPath, "----------BOM传递SAP结果-----------");
|
|
|
|
document = DocumentHelper.parseText(string);
|
|
|
|
// document = DocumentHelper.parseText(string);
|
|
|
|
Element rootElement = document.getRootElement();
|
|
|
|
// Element rootElement = document.getRootElement();
|
|
|
|
Element bodys = rootElement.element("Body");
|
|
|
|
// Element bodys = rootElement.element("Body");
|
|
|
|
Element elements = bodys.element("MT_MATERIAL_BOP_RSP");
|
|
|
|
// Element elements = bodys.element("MT_MATERIAL_BOP_RSP");
|
|
|
|
// String attributeValue = elements.get(0).attributeValue("CODE");
|
|
|
|
//// String attributeValue = elements.get(0).attributeValue("CODE");
|
|
|
|
List<Element> ztable = elements.elements("ZTABLE_RETURN");
|
|
|
|
// List<Element> ztable = elements.elements("ZTABLE_RETURN");
|
|
|
|
for(Element zret:ztable) {
|
|
|
|
// for (Element zret : ztable) {
|
|
|
|
String status = zret.elementText("TYPE");
|
|
|
|
// String status = zret.elementText("TYPE");
|
|
|
|
if(status.equals("E")) {
|
|
|
|
// if (status.equals("E")) {
|
|
|
|
String attributeValue = zret.elementText("MESSAGE");
|
|
|
|
// String attributeValue = zret.elementText("MESSAGE");
|
|
|
|
String MATNR = zret.elementText("MATNR");
|
|
|
|
// String MATNR = zret.elementText("MATNR");
|
|
|
|
if(MATNR!=null) {
|
|
|
|
// if (MATNR != null) {
|
|
|
|
attributeValue = attributeValue+",ÔÚ"+MATNR+"BOMÖÐ";
|
|
|
|
// attributeValue = attributeValue + ",在" + MATNR + "BOM中";
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
// String gbk = new String(attributeValue.getBytes("GBK"), "UTF-8");
|
|
|
|
//// String gbk = new String(attributeValue.getBytes("GBK"), "UTF-8");
|
|
|
|
System.out.println(attributeValue);
|
|
|
|
// System.out.println(attributeValue);
|
|
|
|
errBuffer.append(attributeValue).append("\n");
|
|
|
|
// errBuffer.append(attributeValue).append("\n");
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
} catch (DocumentException e) {
|
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -379,6 +415,7 @@ public class BomSendSapController {
|
|
|
|
// new SAPMessageUtil("", "BOM物料异常:\n" + errBuffer.toString());
|
|
|
|
// new SAPMessageUtil("", "BOM物料异常:\n" + errBuffer.toString());
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String sendJsonHttpPost(String url, String xmlContent, String txtPath) {
|
|
|
|
public String sendJsonHttpPost(String url, String xmlContent, String txtPath) {
|
|
|
|
|
|
|
|
|
|
|
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
|
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
|
@ -420,8 +457,8 @@ public class BomSendSapController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return responseInfo;
|
|
|
|
return responseInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public StringBuffer sendMom(String url,String wsdlString,String txtPath) throws IOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public StringBuffer sendMom(String url, String wsdlString, String txtPath) throws IOException {
|
|
|
|
|
|
|
|
|
|
|
|
StringBuffer errBuffer = new StringBuffer("");
|
|
|
|
StringBuffer errBuffer = new StringBuffer("");
|
|
|
|
if (!url.contains("http")) {
|
|
|
|
if (!url.contains("http")) {
|
|
|
|