Compare commits

...

5 Commits

Author SHA1 Message Date
陈翼晖 c695e780f5 BOM 异步调整
1 year ago
陈翼晖 229291a55a test
1 year ago
陈翼晖 9995f40661 Merge branch 'master' of http://yunpi.tpddns.cn:3000/ZT_CODE/com.connor.chint.wuhan
1 year ago
陈翼晖 b1e80d13a8 提交
1 year ago
陈翼晖 f45270843e 武汉变更修改
1 year ago

@ -1,2 +1,3 @@
ERROR_NOT_CHANGE=\u8BF7\u9009\u62E9\u66F4\u6539\u901A\u77E5\u5355\u5BF9\u8C61
ERROR_NO_CHANGE=\u672A\u627E\u5230\u53D8\u66F4\u524D\u540E\u5BF9\u8C61,\u65E0\u6CD5\u63D0\u53D6\u5DEE\u5F02\u9879\uFF01
SUCC_CHANGE=\u63D0\u53D6\u5B8C\u6210

@ -70,7 +70,7 @@
<menuContribution locationURI="menu:com.connor.chint.sap2.menu.whgc?after=additions">
<!--<command commandId = "com.chint.plm.createbomdifference.ExtractDiffComd" id = "com.chint.plm.createbomdifference.ExtractDiffComd">
<!-- <command commandId = "com.chint.plm.createbomdifference.ExtractDiffComd" id = "com.chint.plm.createbomdifference.ExtractDiffComd">
<visibleWhen>
<and>
<or>

@ -26,6 +26,10 @@ import javafx.scene.control.ComboBox;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
/**
* @author cyh
* ID
*/
public class AssignIdController {
private String groupID;
private TCSession session;

@ -84,6 +84,12 @@ import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
* @author cyh
*
* ´´½¨¸ü¸ÄECNÒ³Ãæ
*
*/
public class CreateEcnController extends KFXPanelController {
@FXML
private TextField ecnId;
@ -674,6 +680,8 @@ public class CreateEcnController extends KFXPanelController {
String result = read.getString("result");
if (result.equals("·ñ")) {
refTableBean.setShNo(true);
}else {
refTableBean.setShYes(true);
}
i = i + 1;
}

@ -82,8 +82,8 @@ public class RefTableBean {
return shYes;
}
public void setShYes(CheckBox shYes) {
this.shYes = shYes;
public void setShYes(boolean shYes) {
this.shYes.setSelected(shYes);
}
public CheckBox getShNo() {

@ -33,6 +33,11 @@ import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
* @author cyh
*
*
*/
public class RelateEcnController {
@FXML

@ -74,7 +74,7 @@ public class ExtractDiffComd extends KCommand {
return;
}
readChangeDesign(oldComponents, newComponents, tar);
MessageBox.post(resource.getString("SUCC_CHANGE"), "", 2);
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -150,9 +150,10 @@ public class ExtractDiffComd extends KCommand {
ChangeDesignBean changeDesignBean = itemChangeMap.get(keyItem);
TCComponentItemRevision oldDesgin = changeDesignBean.getOldDesgin();
Map<String, PBomBean> materialOld = getMaterialByDesign(oldDesgin);
System.out.println("materialOld===>" + materialOld.toString());
TCComponentItemRevision newDesgin = changeDesignBean.getNewDesgin();
Map<String, PBomBean> materialNew = getMaterialByDesign(newDesgin);
System.out.println("materialOld===>" + materialOld.toString());
System.out.println("materialNew===>" + materialNew.toString());
// ±È½Ï±ä¸üǰºóÎïÁÏBOM
for (String materialNo : materialOld.keySet()) {
@ -316,6 +317,8 @@ public class ExtractDiffComd extends KCommand {
if (pbomMap.containsKey(materialNo)) {
PBomBean pBomBean = pbomMap.get(materialNo);
// ÊÇ·ñPBOM
System.out.println("matnrProps[1]===>" + matnrProps[1]);
System.out.println("matnrProps[2]===>" + matnrProps[2] + "pBomBean.getpRevision()"+pBomBean.getpRevision());
if (matnrProps[1].equals(Util.ZT_VAL_PBOM) && matnrProps[2].compareTo(pBomBean.getpRevision()) > 0) {
pBomBean.setpMaterial(represent);
pBomBean.setpRevision(matnrProps[2]);

@ -1,2 +1,3 @@
ERROR_NOT_CHANGE=\u8BF7\u9009\u62E9\u66F4\u6539\u901A\u77E5\u5355\u5BF9\u8C61
ERROR_NO_CHANGE=\u672A\u627E\u5230\u53D8\u66F4\u524D\u540E\u5BF9\u8C61,\u65E0\u6CD5\u63D0\u53D6\u5DEE\u5F02\u9879\uFF01
SUCC_CHANGE=\u63D0\u53D6\u5B8C\u6210

@ -1,5 +1,7 @@
package com.connor.chint.sap2.util;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -40,8 +42,26 @@ public class BomUtilWh {
public static final String WH_FACOTRY = "M060";
public static final String PARENTTCID = "PARENTTCID";
public static final String PARENTWLBM = "PARENTWLBM";
public static final String ZT2_WBSNO = "zt2_WBSNo";
public static final String ZT2_MATERIALNO = "zt2_MaterialNo";
public static final String SPLIT_MSG = "/";
public static final String UID = "UID";
public static final String detailsSql = "insert into CHINT_BOM_TO_SAP_SUM (code,factory,\"USER\",starttime,wbsno,projectno,taskstauts"
+ ",plmresult,transfer,keymsg,sapresult,PROJECTUID,SERVERHOST,USERID) values "
+ "(?,?,?,to_date(?,'yyyy-mm-ddhh24:mi:ss')" + ",?,?,'组织完成','未处理',?,?,'未返回',?,?,?)";
// 获取传递BOM中最大的序列
public static Integer getCode() throws SQLException {
String sql = "select Tab_SendBom_Sequence.nextval as sid from dual";
ResultSet rs = SqlUtil.read(sql);
Object objs[] = new Object[1];
int code = 0;
if (rs.next()) {
code = rs.getInt(1);
System.out.println("code:" + code);
}
SqlUtil.free();
return code;
}
/**
* BOMDETAILS
@ -51,21 +71,21 @@ public class BomUtilWh {
* @param productNos
* @function
*/
public static void logXmlMsg(Document interGrationList, String code, String productNos, String batchNo,
public static void logXmlMsg(Element interGrationList, String code, String productNos, String batchNo,
String wbsNo, TCSession session) {
String strs[] = session.getPreferenceService().getStringValues(DATABASE_TC);
SqlUtil.getTCDataConnection(strs);
try {
Element rootElement = interGrationList.getRootElement();
// 物料信息
Element element = rootElement.element(WLLIST);
Element element = interGrationList.element(WLLIST);
List<Element> elements = element.elements(WLCONTENTS);
for (Element content : elements) {
// 记录TCid UID 物料编码
String tcId = content.elementText(PARENTTCID);
Element bomContents = content.element("BOMCONTENTS");
String tcId = bomContents.elementText(PARENTTCID);
String[] split = tcId.split(SPLIT_MSG);
String parentMantrNo = content.elementText(PARENTWLBM);
String uid = content.elementText(UID);
String parentMantrNo = bomContents.elementText(PARENTWLBM);
String uid = bomContents.elementText(UID);
SqlUtil.write(logSql,
new String[] { code, batchNo, WH_FACOTRY, productNos, split[0], uid, parentMantrNo, wbsNo });
}
@ -1176,7 +1196,7 @@ public class BomUtilWh {
TCComponentItemRevision pRev, String groupName, List<String> wbsList, TCSession session, String now,
List<TCComponentMEProcessRevision> needTCM_meops, Map<String, TCComponent> gy_meops,
Element INTERGRATIONLIST, StringBuffer errMessage, List<TCComponentItem> cppRevision, String txtPath,
Map<String, TCComponentItemRevision> material_revs) {
Map<String, TCComponentItemRevision> material_revs, String batchNum) {
try {
String uid = pBomLine.getUid();
@ -1274,6 +1294,8 @@ public class BomUtilWh {
BOMCONTENTS.addElement("QUANTITY").setText(properties[3]);
BOMCONTENTS.addElement("QUIT")
.setText(pRev.getItem().getTCProperty("zt2_unit").getStringValue().toUpperCase());
BOMCONTENTS.addElement("UID").setText(pRev.getUid());
BOMCONTENTS.addElement("BATCHNUMBER").setText(batchNum);
Element SONLIST = BOMCONTENTS.addElement("SONLIST");
// 获取工艺信息 BOPLIST BOPCONTENTS ()二级工序下的辅料放到子件
String maxSeq = "10";
@ -1310,11 +1332,7 @@ public class BomUtilWh {
material_revs.put(properties2[2], rev2);
}
expandAllBomPart(expands, line2, rev2, groupName, wbsList, session, now, needTCM_meops, gy_meops,
INTERGRATIONLIST, errMessage, txtPath, material_revs);
// if (!KUtil.isEmpty(zt2_materialNo)) {
// material_revs.put(zt2_materialNo, part2Rev);
// }
INTERGRATIONLIST, errMessage, txtPath, material_revs, batchNum);
}
AIFComponentContext[] meops = pRev.whereReferencedByTypeRelation(new String[] { "MEProcessRevision" },
new String[] { "IMAN_METarget" });
@ -1530,7 +1548,7 @@ public class BomUtilWh {
TCComponentItemRevision pRev, String groupName, List<String> wbsList, TCSession session, String now,
List<TCComponentMEProcessRevision> needTCM_meops, Map<String, TCComponent> gy_meops,
Element INTERGRATIONLIST, StringBuffer errMessage, String txtPath,
Map<String, TCComponentItemRevision> material_revs) {
Map<String, TCComponentItemRevision> material_revs, String batchNum) {
try {
String uid = pBomLine.getUid();
@ -1621,6 +1639,10 @@ public class BomUtilWh {
BOMCONTENTS.addElement("QUANTITY").setText(properties[3]);
BOMCONTENTS.addElement("QUIT")
.setText(pRev.getItem().getTCProperty("zt2_unit").getStringValue().toUpperCase());
//新增字段UID和批次号
BOMCONTENTS.addElement("UID").setText(pRev.getUid());
BOMCONTENTS.addElement("BATCHNUMBER").setText(batchNum);
Element SONLIST = BOMCONTENTS.addElement("SONLIST");
// 获取工艺信息 BOPLIST BOPCONTENTS ()二级工序下的辅料放到子件
String maxSeq = "10";
@ -1665,7 +1687,7 @@ public class BomUtilWh {
material_revs.put(properties2[2], rev2);
}
expandAllBomPart(expands, line2, rev2, groupName, wbsList, session, now, needTCM_meops, gy_meops,
INTERGRATIONLIST, errMessage, txtPath, material_revs);
INTERGRATIONLIST, errMessage, txtPath, material_revs, batchNum);
}
AIFComponentContext[] meops = pRev.whereReferencedByTypeRelation(new String[] { "MEProcessRevision" },

@ -18,6 +18,7 @@ import com.connor.chint.sap2.util.MyProgressBarCompent;
import com.connor.chint.sap2.util.SAPMessageUtil;
import com.connor.chint.sap2.util.SAPMessageUtilFram;
import com.connor.chint.sap2.util.SAPUtil;
import com.connor.chint.sap2.util.SqlUtil;
import com.connor.chint.sap2.util.TXTUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFOperation;
@ -47,13 +48,14 @@ public class BomSapWhBjOp extends AbstractAIFOperation {
private String now;
private String groupName = "";
private TCComponentItemType ccomponentitemtype;
public BomSapWhBjOp(AbstractAIFApplication app) {
// TODO Auto-generated constructor stub
this.app = app;
this.session = (TCSession) app.getSession();
now = format.format(new Date());
try {
ccomponentitemtype = (TCComponentItemType)session.getTypeComponent("ZT2_Design3D");
ccomponentitemtype = (TCComponentItemType) session.getTypeComponent("ZT2_Design3D");
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -66,93 +68,103 @@ public class BomSapWhBjOp extends AbstractAIFOperation {
List<TCComponentItem> itemList = new ArrayList<>();
List<TCComponentItem> itemPList = new ArrayList<>();
String id = "1ZDB300000P-";
if(rev2.getType().equals("Part Revision")) {
if (rev2.getType().equals("Part Revision")) {
String desc = rev2.getStringProperty("object_desc");
String[] split = desc.split(" ");
if(split.length>=2) {
if (split.length >= 2) {
String[] split2 = split[1].split("-");
if(split2.length==2) {
if (split2.length == 2) {
id = id + split2[1];
}else if(split2.length==3) {
} else if (split2.length == 3) {
id = id + split2[2];
}
}
}else if(rev2.getType().equals("ZT2_Design3DRevision")) {
} else if (rev2.getType().equals("ZT2_Design3DRevision")) {
String desc = rev2.getStringProperty("item_id");
String[] split2 = desc.split("-");
if(split2.length==2) {
if (split2.length == 2) {
id = id + split2[1];
}else if(split2.length==3) {
} else if (split2.length == 3) {
id = id + split2[2];
}
}
System.out.print("id===>"+id);
System.out.print("id===>" + id);
TCComponentItem find = ccomponentitemtype.find(id);
TCComponentItemRevision zztRev = find.getLatestItemRevision();
TCComponent[] matnrs = zztRev.getRelatedComponents("representation_for");
for(TCComponent matnr:matnrs) {
String[] properties = matnr.getProperties(new String[]{"zt2_ifpbom"});
TCComponentItemRevision revItem = (TCComponentItemRevision)matnr;
for (TCComponent matnr : matnrs) {
String[] properties = matnr.getProperties(new String[] { "zt2_ifpbom" });
TCComponentItemRevision revItem = (TCComponentItemRevision) matnr;
TCComponentItem item = revItem.getItem();
if(properties[0].equals("P") && !itemPList.contains(item)) {
if (properties[0].equals("P") && !itemPList.contains(item)) {
itemPList.add(item);
}else if(!itemList.contains(item)){
} else if (!itemList.contains(item)) {
itemList.add(item);
}
}
if(itemPList.size()>0) {
if (itemPList.size() > 0) {
return itemPList;
}
return itemList;
}
public TCComponentItemRevision getPRevision(TCComponentItemRevision rev2) throws TCException {
String zt2_MaterialNo = rev2.getStringProperty("zt2_MaterialNo");
if(rev2.getType().equals("Part Revision")) {
if (rev2.getType().equals("Part Revision")) {
String zt2_ifpbom = rev2.getProperty("zt2_ifpbom");
if(zt2_ifpbom.equals("P")) {
if (zt2_ifpbom.equals("P")) {
return rev2;
}else {
} else {
TCComponent designRev = rev2.getRelatedComponent("TC_Is_Represented_By");
if(designRev!=null) {
if (designRev != null) {
TCComponent[] matnrs = designRev.getRelatedComponents("representation_for");
for(TCComponent matnr:matnrs) {
String[] properties = matnr.getProperties(new String[]{"zt2_ifpbom","zt2_MaterialNo"});
if(properties[1].equals(zt2_MaterialNo) && properties[0].equals("P")) {
return (TCComponentItemRevision)matnr;
for (TCComponent matnr : matnrs) {
String[] properties = matnr.getProperties(new String[] { "zt2_ifpbom", "zt2_MaterialNo" });
if (properties[1].equals(zt2_MaterialNo) && properties[0].equals("P")) {
return (TCComponentItemRevision) matnr;
}
}
}
}
}else if(rev2.getType().equals("ZT2_Design3DRevision")) {
} else if (rev2.getType().equals("ZT2_Design3DRevision")) {
TCComponent[] matnrs = rev2.getRelatedComponents("representation_for");
for(TCComponent matnr:matnrs) {
String[] properties = matnr.getProperties(new String[]{"zt2_ifpbom","zt2_MaterialNo"});
if(properties[0].equals("P")) {
return (TCComponentItemRevision)matnr;
for (TCComponent matnr : matnrs) {
String[] properties = matnr.getProperties(new String[] { "zt2_ifpbom", "zt2_MaterialNo" });
if (properties[0].equals("P")) {
return (TCComponentItemRevision) matnr;
}
}
return (TCComponentItemRevision)matnrs[0];
return (TCComponentItemRevision) matnrs[0];
}
return rev2;
}
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"
+ " <soapenv:Header/>\r\n"
+ " <soapenv:Body>\r\n"
+ " <urn:MT_MATERIAL_BOP_REQ>\r\n"
+ " </urn:MT_MATERIAL_BOP_REQ>\r\n"
+ " </soapenv:Body>\r\n"
+ "</soapenv:Envelope>";
+ " <soapenv:Header/>\r\n" + " <soapenv:Body>\r\n" + " <urn:MT_MATERIAL_BOP_REQ>\r\n"
+ " </urn:MT_MATERIAL_BOP_REQ>\r\n" + " </soapenv:Body>\r\n" + "</soapenv:Envelope>";
return soapXML;
}
@Override
public void executeOperation() throws Exception {
// TODO Auto-generated method stub
MyProgressBarCompent comp = null;
try {
String strs[] = session.getPreferenceService().getStringValues("database_tc");
if (SqlUtil.getTCDataConnection(strs) == null) {
MessageBox.post("数据库连接失败,请检查首选项<database_tc>", "", 2);
return;
}
String code = BomUtilWh.getCode().toString();
String batchNum = code + "-00001";
groupName = SAPUtil.getGroupID(session);
if (KUtil.isEmpty(groupName) || groupName.equalsIgnoreCase("dba")) {
MessageBox.post("当前登录组[" + groupName + "]不可使用该功能", "", MessageBox.INFORMATION);
@ -178,10 +190,33 @@ public class BomSapWhBjOp extends AbstractAIFOperation {
}
comp = new MyProgressBarCompent("", "正在进行部件BOM传递SAP....");
TCComponentItemRevision pRevision = getPRevision(degignRev); //获取PBOM
TCComponentItemRevision pRevision = getPRevision(degignRev); // 获取PBOM
List<TCComponentItem> cppRevision = getCPPPRevision(degignRev);
//获取产成品
System.out.println("cppRevision===>"+cppRevision.toString());
// 获取产成品
System.out.println("cppRevision===>" + cppRevision.toString());
//记录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(TCComponentItem cppItem:cppRevision) {
TCComponentItemRevision latestItemRevision = cppItem.getLatestItemRevision();
String property = latestItemRevision.getProperty(BomUtilWh.ZT2_MATERIALNO);
productNosBuild.append(property).append(";");
productUidsBuild.append(latestItemRevision.getUid()).append(";");
}
String substring = productUidsBuild.toString().substring(0, productUidsBuild.length() - 1);
String serverHostname = session.getServerHostname();
String wbsNo = cppRevision.get(0).getLatestItemRevision().getProperty(BomUtilWh.ZT2_WBSNO);
SqlUtil.write(BomUtilWh.detailsSql, new String[] { code, "M060", userName, dataTime, wbsNo,
"", "部件传递", substring, "", serverHostname, userId });
SqlUtil.freeAll();
List<String> wbsList = new ArrayList<String>();
StringBuffer errMessage = new StringBuffer("");
@ -191,7 +226,7 @@ public class BomSapWhBjOp extends AbstractAIFOperation {
TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
TCComponentBOMWindow win = bomWinType.create(null);
TCComponentBOMLine setWindowTopLine = win.setWindowTopLine(pRevision.getItem(), pRevision, null, null);
//优化项BOM全展开
// 优化项BOM全展开
System.out.println("BOM全展开");
Map<String, TCComponent> gy_meops = new HashMap<>(32);
@ -206,17 +241,25 @@ public class BomSapWhBjOp extends AbstractAIFOperation {
Map<String, ExpandPSData[]> bomLineTree = BomToSapUtil.getBomLineTreeNodeSOA(setWindowTopLine);
List<TCComponentMEProcessRevision> needTCM_meops = new ArrayList<TCComponentMEProcessRevision>();
Map<String, TCComponentItemRevision> material_revs = new HashMap<>();
BomUtilWh.expandAllBomPartBj(bomLineTree, setWindowTopLine, pRevision,
groupName,wbsList,session,now,needTCM_meops,gy_meops,INTERGRATIONLIST,errMessage,cppRevision,txtPath,material_revs);
System.out.println("BOM全document===>"+document.asXML());
if(errMessage.length()>0) {
BomUtilWh.expandAllBomPartBj(bomLineTree, setWindowTopLine, pRevision, groupName, wbsList, session, now,
needTCM_meops, gy_meops, INTERGRATIONLIST, errMessage, cppRevision, txtPath, material_revs, batchNum);
System.out.println("BOM全document===>" + document.asXML());
if (errMessage.length() > 0) {
TXTUtil.writeTXT(txtPath, "----------------BOM异常--------------");
TXTUtil.writeTXT(txtPath, errMessage.toString());
TXTUtil.writeTXT(txtPath, "----------BOM信息-----------");
// BomUtilWh.logXmlMsg(INTERGRATIONLIST, code, productNosBuild.toString(), batchNum, pRevision.getProperty(BomUtilWh.ZT2_WBSNO), session);
new SAPMessageUtilFram("", "BOM传递SAP异常:\n" + errMessage.toString()).show();
win.close();
}else {
new BomSendSapOp(session,document.asXML(),txtPath,gy_meops).executeOperation();
} else {
//记录产成品的物料编码
// StringBuilder productNosBuild = new StringBuilder("");
// for(TCComponentItem cppItem:cppRevision) {
// String property = cppItem.getLatestItemRevision().getProperty(BomUtilWh.ZT2_MATERIALNO);
// productNosBuild.append(property).append(";");
// }
BomUtilWh.logXmlMsg(INTERGRATIONLIST, code, productNosBuild.toString(), batchNum, wbsNo, session);
new BomSendSapOp(session, document.asXML(), txtPath, gy_meops).executeOperation();
win.close();
}
if (comp != null) {
@ -226,13 +269,15 @@ public class BomSapWhBjOp extends AbstractAIFOperation {
System.out.println("日志所挂对象:" + pRevision);
KUtil.setByPass(true);
TXTUtil.addTxttoTarget(pRevision, dataset);
MessageBox.post("BOM数据推送完成..","提示",2);
MessageBox.post("BOM数据推送完成..", "提示", 2);
} catch (Exception e) {
e.printStackTrace();
} finally {
KUtil.setByPass(false);
SqlUtil.freeAll();
}
}
public String getUserName(TCSession session) throws TCException {
TCComponentUser user = session.getUser();
session.getUserName();

@ -32,6 +32,7 @@ import com.connor.chint.sap2.util.KUtil;
import com.connor.chint.sap2.util.MyProgressBarCompent;
import com.connor.chint.sap2.util.SAPMessageUtil;
import com.connor.chint.sap2.util.SAPUtil;
import com.connor.chint.sap2.util.SqlUtil;
import com.connor.chint.sap2.util.TXTUtil;
import com.squareup.okhttp.Credentials;
import com.squareup.okhttp.MediaType;
@ -64,7 +65,7 @@ import com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSData
public class BomSendSapController {
public static final String TYPE_REV_PART = "Part Revision";
public TCComponent project; //项目信息
public TCComponent project; // 项目信息
public String groupName;
public String zt2_ProjectNo;
public String wbs;
@ -73,6 +74,7 @@ public class BomSendSapController {
public List<PartBean> partList = new ArrayList<>();
public BomSendSapWhFram dialog;
private SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd-HHmmss");
public BomSendSapController(BomSendSapWhFram sapzyDialog, AbstractAIFApplication app) {
this.app = app;
this.session = (TCSession) app.getSession();
@ -91,11 +93,11 @@ public class BomSendSapController {
System.out.println("检查对象:" + target);
List<TCComponentItemRevision> partRevList = KUtil.getCCPFromProject(project);
for(TCComponentItemRevision rev:partRevList) {
for (TCComponentItemRevision rev : partRevList) {
String cType = rev.getType();
// System.out.println(">> 找到子对象:" + cName + "|" + cType);
if (TYPE_REV_PART.equals(cType)) {
PartBean bean = new PartBean(rev, partList.size() + 1,"");
PartBean bean = new PartBean(rev, partList.size() + 1, "");
SAPPushBOMBean.readUser(bean, rev, groupName, session);
bean.setPSPID(project.getProperty("zt2_ProjectNo"));
partList.add(bean);
@ -141,33 +143,31 @@ public class BomSendSapController {
released_Yellow.save();
released_Yellow.unlock();
}
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"
+ " <soapenv:Header/>\r\n"
+ " <soapenv:Body>\r\n"
+ " <urn:MT_MATERIAL_BOP_REQ>\r\n"
+ " </urn:MT_MATERIAL_BOP_REQ>\r\n"
+ " </soapenv:Body>\r\n"
+ "</soapenv:Envelope>";
+ " <soapenv:Header/>\r\n" + " <soapenv:Body>\r\n" + " <urn:MT_MATERIAL_BOP_REQ>\r\n"
+ " </urn:MT_MATERIAL_BOP_REQ>\r\n" + " </soapenv:Body>\r\n" + "</soapenv:Envelope>";
return soapXML;
}
public TCComponentItemRevision getPRevision(TCComponentItemRevision rev2) throws TCException {
String zt2_MaterialNo = rev2.getStringProperty("zt2_MaterialNo");
if(rev2.getType().equals("Part Revision")) {
if (rev2.getType().equals("Part Revision")) {
String zt2_ifpbom = rev2.getProperty("zt2_ifpbom");
if(zt2_ifpbom.equals("P")) {
if (zt2_ifpbom.equals("P")) {
return rev2;
}else {
} else {
TCComponent designRev = rev2.getRelatedComponent("TC_Is_Represented_By");
if(designRev!=null) {
if (designRev != null) {
TCComponent[] matnrs = designRev.getRelatedComponents("representation_for");
for(TCComponent matnr:matnrs) {
String[] properties = matnr.getProperties(new String[]{"zt2_ifpbom","zt2_MaterialNo"});
if(properties[1].equals(zt2_MaterialNo) && properties[0].equals("P")) {
return (TCComponentItemRevision)matnr;
for (TCComponent matnr : matnrs) {
String[] properties = matnr.getProperties(new String[] { "zt2_ifpbom", "zt2_MaterialNo" });
if (properties[1].equals(zt2_MaterialNo) && properties[0].equals("P")) {
return (TCComponentItemRevision) matnr;
}
}
}
@ -176,27 +176,60 @@ public class BomSendSapController {
return rev2;
}
public String getUserName(TCSession session) throws TCException {
TCComponentUser user = session.getUser();
session.getUserName();
return user.getTCProperty("user_name").getDisplayValue();
}
public void sendSap() {
try {
String strs[] = session.getPreferenceService().getStringValues("database_tc");
if (SqlUtil.getTCDataConnection(strs) == null) {
MessageBox.post("数据库连接失败,请检查首选项<database_tc>", "", 2);
return;
}
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());
MyProgressBarCompent comp = null;
// try {
String txtName = format2.format(new Date()) + getUserName(session);
String txtPath = TXTUtil.createTxt(txtName);
comp = new MyProgressBarCompent("", "正在进行项目BOM传递......");
StringBuffer errMessageAll = new StringBuffer("");
StringBuffer sendMessageAll = new StringBuffer("");
//2024 1 22新增逻辑往CHINT_BOM_TO_SAP_SUM
project.getProperty("zt2_WBSNo");
//产成品BOM组织时除了产成品不同其他相同 BOM结构是一样的
for(PartBean bean : selectedParts) {
// 2024 1 22新增逻辑往CHINT_BOM_TO_SAP_SUM
// project.getProperty("zt2_WBSNo");
// 产成品BOM组织时除了产成品不同其他相同 BOM结构是一样的
// 记录产成品的物料编码
for (PartBean bean : selectedParts) {
Document document = DocumentHelper.parseText(getXML());
Element rootElement = document.getRootElement();
@ -213,30 +246,34 @@ public class BomSendSapController {
TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
TCComponentBOMWindow win = bomWinType.create(null);
TCComponentBOMLine setWindowTopLine = win.setWindowTopLine(rev2.getItem(), rev2, null, null);
//优化项BOM全展开
// 优化项BOM全展开
System.out.println("BOM全展开");
Map<String, TCComponent> gy_meops = new HashMap<>(32);
List<TCComponentMEProcessRevision> needTCM_meops = new ArrayList<TCComponentMEProcessRevision>();
//三种情况有PBOM传PDBOM没PBOM传EBOM没EBOM传图纸BOM
// 三种情况有PBOM传PDBOM没PBOM传EBOM没EBOM传图纸BOM
Map<String, ExpandPSData[]> bomLineTree = BomToSapUtil.getBomLineTreeNodeSOA(setWindowTopLine);
List<String> wbsList = new ArrayList<String>();
// 记录物料图纸关系的集合
Map<String, TCComponentItemRevision> material_revs = new HashMap<>();
BomUtilWh.expandAllBomPart(bomLineTree, setWindowTopLine, rev2,
groupName,wbsList,session,now,needTCM_meops,gy_meops,INTERGRATIONLIST,errMessage,txtPath,material_revs);
System.out.println("BOM全document===>"+document.asXML());
if(errMessage.length()>0) {
// 2024 1 24 新加字段 UID 和 BATCHNUMBER
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());
if (errMessage.length() > 0) {
TXTUtil.writeTXT(txtPath, "----------------BOM异常--------------");
TXTUtil.writeTXT(txtPath, errMessage.toString());
TXTUtil.writeTXT(txtPath, "----------BOM信息-----------");
errMessageAll.append(errMessage);
// new SAPMessageUtil("", "BOM传递SAP异常:\n" + errMessage.toString());
win.close();
}else {
} else {
// new BomSendSapOp(session,document.asXML(),txtPath,gy_meops).executeOperation();
//记录XML信息到CHINT_BOM_TO_SAP_DETIALS
sendMessageAll.append(SendToSap(txtPath,document.asXML()));
// 记录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()));
win.close();
}
TCComponentDataset dataset = TXTUtil.createDataset(txtPath, txtName, session);
@ -245,19 +282,21 @@ public class BomSendSapController {
TXTUtil.addTxttoTarget(rev2, dataset);
KUtil.setByPass(false);
}
if(comp!=null) {
if (comp != null) {
comp.setVisible(false);
}
if(errMessageAll.length()>0) {
if (errMessageAll.length() > 0) {
new SAPMessageUtil("", "BOM传递SAP异常:\n" + errMessageAll.toString());
}else if(sendMessageAll.length()>0) {
} else if (sendMessageAll.length() > 0) {
new SAPMessageUtil("", "BOM推送异常:\n" + sendMessageAll.toString());
}else {
MessageBox.post("BOM数据推送完成..","提示",2);
} else {
MessageBox.post("BOM数据推送完成..", "提示", 2);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
SqlUtil.freeAll();
}
}
@ -282,32 +321,32 @@ public class BomSendSapController {
return selectedParts;
}
public StringBuffer SendToSap(String txtPath,String wsdlString) throws IOException {
public StringBuffer SendToSap(String txtPath, String wsdlString) throws IOException {
// new BomSendSapOp(session,document.asXML(),txtPath,gy_meops).executeOperation();
TXTUtil.writeTXT(txtPath, "----------------BOM传递数据--------------");
TXTUtil.writeTXT(txtPath, wsdlString);
TXTUtil.writeTXT(txtPath, "----------BOM传递数据-----------");
//推送SAP
String[] stringValues = session.getPreferenceService().getStringValues("CHINT_WhBomUrl");
// 推送SAP
String[] stringValues = session.getPreferenceService().getStringValues("CHINT_WhBomUrl_YB");
String sapUrl = "";
String momUrl = "";
for(String stringValue:stringValues) {
if(stringValue.startsWith("SAP:1=")) {
for (String stringValue : stringValues) {
if (stringValue.startsWith("SAP:1=")) {
sapUrl = stringValue.replaceAll("SAP:1=", "");
}else if(stringValue.startsWith("MOM:1=")) {
} else if (stringValue.startsWith("MOM:1=")) {
momUrl = stringValue.replaceAll("MOM:1=", "");
}
}
StringBuffer sendSap = sendSap(sapUrl,wsdlString,txtPath);
StringBuffer sendMom = sendMom(momUrl,wsdlString,txtPath);
StringBuffer sendSap = sendSap(sapUrl, wsdlString, txtPath);
StringBuffer sendMom = sendMom(momUrl, wsdlString, txtPath);
StringBuffer errBuffer = new StringBuffer("");
if(sendSap.length()>0) {
if (sendSap.length() > 0) {
errBuffer.append("推送SAP异常:").append("\n");
errBuffer.append(sendSap);
//new SAPMessageUtil("", "s:\n" + errBuffer.toString());
// new SAPMessageUtil("", "s:\n" + errBuffer.toString());
}
if(sendMom.length()>0) {
if (sendMom.length() > 0) {
errBuffer.append("推送MOM异常:").append("\n");
errBuffer.append(sendMom);
}
@ -316,31 +355,28 @@ public class BomSendSapController {
// }
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("");
if(!url.contains("http")) {
if (!url.contains("http")) {
return errBuffer;
}
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(100, TimeUnit.SECONDS);
client.setReadTimeout(100, TimeUnit.SECONDS);
// Authenticator authenticator = client.setAuthenticator(new Au);
String credential = "";//Credentials.basic("shpodev", "sap@2019");
if(url.contains("192.168.0.184")) {
credential = Credentials.basic("shpodev", "sap@2019");
}else {
String credential = "";// Credentials.basic("shpodev", "sap@2019");
if (url.contains("192.168.0.184") || url.contains("gfpot01")) {
credential = Credentials.basic("po_rfc", "1qaz!QAZ");
} else {
credential = Credentials.basic("shplm", "sap@2019");
}
MediaType mediaType = MediaType.parse("application/xml");
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
Request request = new Request.Builder()
.url(url)
.method("POST", body)
.header("Authorization", credential)
.addHeader("Content-Type", "application/xml")
.build();
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
Request request = new Request.Builder().url(url).method("POST", body).header("Authorization", credential)
.addHeader("Content-Type", "application/xml").build();
Response response = client.newCall(request).execute();
Document document = null;
@ -350,26 +386,26 @@ public class BomSendSapController {
TXTUtil.writeTXT(txtPath, "----------------BOM传递SAP结果--------------");
TXTUtil.writeTXT(txtPath, string);
TXTUtil.writeTXT(txtPath, "----------BOM传递SAP结果-----------");
document = DocumentHelper.parseText(string);
Element rootElement = document.getRootElement();
Element bodys = rootElement.element("Body");
Element elements = bodys.element("MT_MATERIAL_BOP_RSP");
// String attributeValue = elements.get(0).attributeValue("CODE");
List<Element> ztable = elements.elements("ZTABLE_RETURN");
for(Element zret:ztable) {
String status = zret.elementText("TYPE");
if(status.equals("E")) {
String attributeValue = zret.elementText("MESSAGE");
String MATNR = zret.elementText("MATNR");
if(MATNR!=null) {
attributeValue = attributeValue+",在"+MATNR+"BOM中";
}
// String gbk = new String(attributeValue.getBytes("GBK"), "UTF-8");
System.out.println(attributeValue);
errBuffer.append(attributeValue).append("\n");
}
}
} catch (DocumentException e) {
// document = DocumentHelper.parseText(string);
// Element rootElement = document.getRootElement();
// Element bodys = rootElement.element("Body");
// Element elements = bodys.element("MT_MATERIAL_BOP_RSP");
//// String attributeValue = elements.get(0).attributeValue("CODE");
// List<Element> ztable = elements.elements("ZTABLE_RETURN");
// for (Element zret : ztable) {
// String status = zret.elementText("TYPE");
// if (status.equals("E")) {
// String attributeValue = zret.elementText("MESSAGE");
// String MATNR = zret.elementText("MATNR");
// if (MATNR != null) {
// attributeValue = attributeValue + ",在" + MATNR + "BOM中";
// }
//// String gbk = new String(attributeValue.getBytes("GBK"), "UTF-8");
// System.out.println(attributeValue);
// errBuffer.append(attributeValue).append("\n");
// }
// }
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@ -379,7 +415,8 @@ public class BomSendSapController {
// 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();
String responseInfo = null;
@ -391,10 +428,10 @@ public class BomSendSapController {
// 设置请求体
StringEntity entityReq = new StringEntity(xmlContent, StandardCharsets.UTF_8);
if(url.contains("10.128.11.12")) {
if (url.contains("10.128.11.12")) {
httpPost.addHeader("Authorization", "Basic MTQyODI0Mjg2NDU2ODMwNzcxNDpkREF3TWpveE1EQXg=");
// http://10.128.11.12:7788/gateway/chint/bop-sync
}else {
} else {
httpPost.addHeader("Authorization", "Basic MTcxNDkwNTkyNTc2MjUzNTQyNjpkREF3TWpveE1EQXg=");
}
//
@ -420,14 +457,14 @@ public class BomSendSapController {
}
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("");
if(!url.contains("http")) {
if (!url.contains("http")) {
return errBuffer;
}
String string = sendJsonHttpPost(url,wsdlString,txtPath); //"http://10.128.11.12:7788/gateway/chint/bop-sync"
String string = sendJsonHttpPost(url, wsdlString, txtPath); // "http://10.128.11.12:7788/gateway/chint/bop-sync"
return errBuffer;

@ -77,8 +77,8 @@ public class BomSendSapOp extends AbstractAIFOperation {
client.setReadTimeout(100, TimeUnit.SECONDS);
// Authenticator authenticator = client.setAuthenticator(new Au);
String credential = "";//Credentials.basic("shpodev", "sap@2019");
if(url.contains("192.168.0.184")) {
credential = Credentials.basic("shpodev", "sap@2019");
if(url.contains("192.168.0.184") || url.contains("gfpot01")) {
credential = Credentials.basic("po_rfc", "1qaz!QAZ");
}else {
credential = Credentials.basic("shplm", "sap@2019");
}
@ -100,25 +100,25 @@ public class BomSendSapOp extends AbstractAIFOperation {
TXTUtil.writeTXT(txtPath, "----------------BOM传递SAP结果--------------");
TXTUtil.writeTXT(txtPath, string);
TXTUtil.writeTXT(txtPath, "----------BOM传递SAP结果-----------");
document = DocumentHelper.parseText(string);
Element rootElement = document.getRootElement();
Element bodys = rootElement.element("Body");
Element elements = bodys.element("MT_MATERIAL_BOP_RSP");
// String attributeValue = elements.get(0).attributeValue("CODE");
List<Element> ztable = elements.elements("ZTABLE_RETURN");
for(Element zret:ztable) {
String status = zret.elementText("TYPE");
if(status.equals("E")) {
String attributeValue = zret.elementText("MESSAGE");
String MATNR = zret.elementText("MATNR");
if(MATNR!=null) {
attributeValue = attributeValue+",ÔÚ"+MATNR+"BOMÖÐ";
}
System.out.println(attributeValue);
errBuffer.append(attributeValue).append("\n");
}
}
} catch (DocumentException e) {
// document = DocumentHelper.parseText(string);
// Element rootElement = document.getRootElement();
// Element bodys = rootElement.element("Body");
// Element elements = bodys.element("MT_MATERIAL_BOP_RSP");
//// String attributeValue = elements.get(0).attributeValue("CODE");
// List<Element> ztable = elements.elements("ZTABLE_RETURN");
// for(Element zret:ztable) {
// String status = zret.elementText("TYPE");
// if(status.equals("E")) {
// String attributeValue = zret.elementText("MESSAGE");
// String MATNR = zret.elementText("MATNR");
// if(MATNR!=null) {
// attributeValue = attributeValue+",ÔÚ"+MATNR+"BOMÖÐ";
// }
// System.out.println(attributeValue);
// errBuffer.append(attributeValue).append("\n");
// }
// }
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@ -191,7 +191,7 @@ public class BomSendSapOp extends AbstractAIFOperation {
TXTUtil.writeTXT(txtPath, "----------BOM传递数据-----------");
//推送SAP
String[] stringValues = session.getPreferenceService().getStringValues("CHINT_WhBomUrl");
String[] stringValues = session.getPreferenceService().getStringValues("CHINT_WhBomUrl_YB");
String sapUrl = "";
String momUrl = "";
for(String stringValue:stringValues) {

Loading…
Cancel
Save