From 95425d071762e641ac89ad56ad3a605f7686dbd6 Mon Sep 17 00:00:00 2001 From: lijh Date: Thu, 16 May 2024 17:17:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A3=85=E7=AE=B1=E9=9B=86=E6=88=90=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=89=B9=E6=AE=8A=E6=95=B0=E6=8D=AE=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=92=8C=E9=A3=9E=E4=B9=A6=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .project | 11 + com.connor.chint.wuhan/bin/.gitignore | 4 + .../connor/chint/yunpi/command/ZxjcBean.java | 260 +++ .../chint/yunpi/command/ZxjcCellEditor.java | 154 ++ .../chint/yunpi/command/ZxjcCommand.java | 18 + .../chint/yunpi/command/ZxjcController.java | 1457 +++++++++++++++++ .../connor/chint/yunpi/command/ZxjcFram.java | 224 +++ 7 files changed, 2128 insertions(+) create mode 100644 .project create mode 100644 com.connor.chint.wuhan/bin/.gitignore create mode 100644 com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcBean.java create mode 100644 com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcCellEditor.java create mode 100644 com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcCommand.java create mode 100644 com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcController.java create mode 100644 com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcFram.java diff --git a/.project b/.project new file mode 100644 index 0000000..0c566a1 --- /dev/null +++ b/.project @@ -0,0 +1,11 @@ + + + chint_wuhan + + + + + + + + diff --git a/com.connor.chint.wuhan/bin/.gitignore b/com.connor.chint.wuhan/bin/.gitignore new file mode 100644 index 0000000..fcae520 --- /dev/null +++ b/com.connor.chint.wuhan/bin/.gitignore @@ -0,0 +1,4 @@ +/com/ +/mes/ +/nc/ +/plm/ diff --git a/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcBean.java b/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcBean.java new file mode 100644 index 0000000..7431605 --- /dev/null +++ b/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcBean.java @@ -0,0 +1,260 @@ +package com.connor.chint.yunpi.command; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +//import com.connor.chint.sap2.sap.SAPPushBOMBean; +//import com.connor.chint.sap2.sap_by.SAPZZDialogController; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; + +public class ZxjcBean extends SAPPushBOMBean { + public static final String TYPE_FACTNO = "ZT2_FactoryNo"; + public static final String REL_PART_FACTNO = "ZT2_FactoryNumber"; + private int index; + public TCComponentItemRevision part; + public TCComponentItem factoryNo; + public TCComponentItemRevision zzDesignRev = null; + public TCComponent[] factoryNos; + public String materialNo; + //出厂编号 + public String ccbh; + public String getCcbh() { + return ccbh; + } + + public void setCcbh(String ccbh) { + this.ccbh = ccbh; + } + + public TCComponentItemRevision getZzDesignRev() { + return zzDesignRev; + } + + public void setZzDesignRev(TCComponentItemRevision zzDesignRev) { + this.zzDesignRev = zzDesignRev; + } + public String getMaterialNo() { + return materialNo; + } + + public void setMaterialNo(String materialNo) { + this.materialNo = materialNo; + } + public int getIndex() { + return index; + } + + public void setIndex(int index) { + this.index = index; + } + + public ZxjcBean(TCComponentItemRevision part, int index) { + this.index = index; + this.part = part; + try { + getZZDesign(this.part); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public ZxjcBean(TCComponentItemRevision part, int index,String dy) { + this.index = index; + this.part = part; +// try { +// getZZDesign(this.part); +// } catch (Exception e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } + } + private TCComponentItemRevision getZZDesign(TCComponentItemRevision part) throws Exception { + try { + TCComponent[] facts = part.getRelatedComponents(REL_PART_FACTNO); + int len = facts.length; + for (int i = 0; i < len; i++) { + String type = facts[i].getType(); + System.out.println(">> 找到子对象:" + facts[i] + "|" + type); + if (TYPE_FACTNO.equals(type)) { + // factNo = facts[i].getStringProperty("item_id");//出厂编码 + this.factoryNo = (TCComponentItem) facts[i]; + AIFComponentContext contexts[] = factoryNo.whereReferencedByTypeRelation( + new String[] { "ZT2_Design3DRevision" }, new String[] { "ZT2_FactoryNumber" }); + Map> items2 = new HashMap>( + 10); + for (int j = 0; j < contexts.length; j++) { + String type2 = contexts[j].getComponent().getType(); + String name = contexts[j].getComponent().getProperty("object_name"); + System.out.println(contexts[j] + "->type:" + type2); +// if (name.contains("总装")) { // || name.contains("变压器") + TCComponentItemRevision pRev = (TCComponentItemRevision) contexts[j].getComponent(); + TCComponentItem item = pRev.getItem(); + if (items2.containsKey(item)) { + items2.get(item).add(pRev); + } else { + List revs = new ArrayList(); + revs.add(pRev); + items2.put(item, revs); + } + /* + * zzDesignRev =(TCComponentItemRevision) contexts[j].getComponent(); + * if(isLastRev(zzDesignRev)) { //zztydh = + * contexts[j].getComponent().getProperty("item_id"); break; } zzDesignRev=null; + */ +// } + } + if (items2.size() > 0) { + List cZZRevs = new ArrayList(); + addLastRevisions(items2, cZZRevs); + if (cZZRevs.size() > 0) { + zzDesignRev = cZZRevs.get(0); + } + } + + break; + } + } + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return null; + } + + private void addLastRevisions(Map> items, + List cParts) throws TCException { + Iterator>> iterator = items.entrySet().iterator(); + while (iterator.hasNext()) { + Entry> it = iterator.next(); + List revs = it.getValue(); + // System.out.println("item["+it.getKey()+"]已发布版本个数:"+revs.size()); + if (revs.size() == 1) { + cParts.add(revs.get(0)); + continue; + } + if (revs.size() > 1) { + TCComponentItemRevision max_Rev = null; + String s = ""; + ; + int index = -1; + for (int j = 0, len2 = revs.size(); j < len2; j++) { + String item_id = revs.get(j).getProperty("item_revision_id"); + if (s.isEmpty()) { + s = item_id; + max_Rev = revs.get(j); + for (int k = 0; k < s.length(); k++) { + if (s.charAt(k) >= '0' && s.charAt(k) <= '9') { + index = k; + break; + } + } + } else { + String temp = item_id; + if (index != -1) { + if (temp.substring(0, index).compareTo(s.substring(0, index)) > 0) { + s = temp; + max_Rev = revs.get(j); + } else if (temp.substring(0, index).compareTo(s.substring(0, index)) == 0) { + String s1 = s.substring(index); + String temp1 = temp.substring(index); + int min = Math.min(s1.length(), temp1.length()); + for (int k = 0; k < min; k++) { + if (temp1.charAt(k) > s1.charAt(k)) { + s = temp; + max_Rev = revs.get(j); + break; + } + + } + + if (temp1.length() > min) { + s = temp; + max_Rev = revs.get(j); + } + + } + } else if (temp.compareTo(s) > 0) { + s = temp; + max_Rev = revs.get(j); + } + + } + } + cParts.add(max_Rev); + } + } + } + + + public Object[] getRowDataZxjc() throws Exception { + String name = part.getStringProperty("object_name"); + TCComponent[] facts = part.getRelatedComponents(REL_PART_FACTNO); + int len = facts == null ? 0 : facts.length; + System.out.println("获取出厂编号:" + part); + String factNo = ""; + for (int i = 0; i < len; i++) { + String type = facts[i].getType(); + System.out.println(">> 找到子对象:" + facts[i] + "|" + type); + factoryNos = facts; + if (TYPE_FACTNO.equals(type)) { + factNo = facts[i].getStringProperty("item_id"); + this.factoryNo = (TCComponentItem) facts[i]; + break; + } + } + //获取图纸id + String tzid = ""; + TCComponent tzRev = part.getRelatedComponent("TC_Is_Represented_By"); + if(tzRev != null) { + tzid = tzRev.getStringProperty("item_id"); + } + + //获取产成品数量 + String zt2_Quantity = part.getStringProperty("zt2_Quantity"); + String zt2_site = part.getStringProperty("zt2_Site"); + String zt2_tankNo = part.getStringProperty("zt2_TankNo"); + // return new Object[] {true,index,zt2_site,zt2_tankNo,name,this,factNo}; + return new Object[] { true, index, zt2_site, zt2_tankNo, name, this, factNo,tzid,zt2_Quantity}; + } + + + public Object[] getZYKGRowData() throws Exception { + String name = part.getStringProperty("object_name"); + String zt2_site = part.getStringProperty("zt2_Site"); + String zt2_tankNo = part.getStringProperty("zt2_TankNo"); + System.out.println("->" + Arrays.toString(new Object[] { true, index, zt2_site, zt2_tankNo, name, this, + getZt2_SapBomState(), getUserName(), getZDATE() })); + return new Object[] { true, index, zt2_site, zt2_tankNo, name, this, getZt2_SapBomState(), getUserName(), + getZDATE() }; + // return new Object[] {true,index,zt2_site,zt2_tankNo,name,this}; + } + + @Override + public String toString() { + try { + return part == null ? "" : part.getStringProperty("zt2_MaterialNo"); + } catch (Exception e) { + e.printStackTrace(); + } + return ""; + } + + public TCComponentItemRevision getPart() { + return part; + } + + public void setPart(TCComponentItemRevision part) { + this.part = part; + } + +} diff --git a/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcCellEditor.java b/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcCellEditor.java new file mode 100644 index 0000000..fafa090 --- /dev/null +++ b/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcCellEditor.java @@ -0,0 +1,154 @@ +package com.connor.chint.yunpi.command; + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.regex.Pattern; + +import javax.swing.AbstractCellEditor; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.table.TableCellEditor; +import javax.swing.text.JTextComponent; + +import com.connor.chint.sap2.util.KUtil; +import com.connor.chint.sap2.util.POIUtil; +import com.connor.chint.sap2.util.ProgressBar; +import com.teamcenter.rac.util.MessageBox; + +public class ZxjcCellEditor extends AbstractCellEditor implements TableCellEditor { + + private static final long serialVersionUID = -5118171189856914639L; + private JTable t_part; + private JTextComponent jtf; + private ZxjcFram dialog; + + + public ZxjcCellEditor(ZxjcFram dialog) { + this.dialog = dialog; + + } + + @Override + public Object getCellEditorValue() { + jtf.selectAll(); + return jtf.getText(); + } + + @Override + public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { + jtf = new JTextField(); + t_part = table; + jtf.setText(""); + final int selectRow = row; + final int col = column; + final String dh = (String) table.getValueAt(row, 2); + ProgressBar pb = new ProgressBar(dialog, new Dimension(300, 50)); + try { + + if (value != null) { + jtf.setText(String.valueOf(value)); + jtf.selectAll(); + + if (column == 1) { + jtf.setEditable(false); + } + + + jtf.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent e) { + + int code = e.getKeyCode(); + int i = jtf.getCaretPosition(); + final String text = jtf.getText(); + if (code == KeyEvent.VK_LEFT) { + System.out.println("触发修改2"); + if (KUtil.isEmpty(text) || i == 0) { + switch (col) { + case 2: + if (selectRow > 0) { + setTableEditting(selectRow - 1, 7); + } + break; + case 6: + Pattern pattern = Pattern.compile("[0-9]*"); + if (!pattern.matcher(text).matches() || POIUtil.getIntValue(text) < 1) { + MessageBox.post(dialog, "第" + (selectRow + 1) + "行数量请输入正整数", "", 2); + } else { + setTableEditting(selectRow, 3); + } + break; + case 3: + case 7: + setTableEditting(selectRow, col - 1); + break; + } + } + } else if (code == KeyEvent.VK_RIGHT) { + // 没有文本的时候 或者光标在最右边的时候 + if (KUtil.isEmpty(text) || i == text.length()) { + switch (col) { + case 3: + setTableEditting(selectRow, 6); + break; + case 7: + if (selectRow != t_part.getRowCount() - 1 && selectRow > 0) { + setTableEditting(selectRow + 1, 2); + } + break; + case 2: + setTableEditting(selectRow, col + 1); + break; + case 6: + // String value = (String) t_part.getValueAt(selectRow, col); + Pattern pattern = Pattern.compile("[0-9]*"); + if (!pattern.matcher(text).matches() || POIUtil.getIntValue(text) < 1) { + MessageBox.post(dialog, "第" + (selectRow + 1) + "行数量请输入正整数", "", 2); + } else { + setTableEditting(selectRow, col + 1); + } + break; + + } + } + } + } + }); + + } + } catch (Exception e) { + pb.disposeDialog(); + e.printStackTrace(); + MessageBox.post(dialog, "异常:" + e.getMessage(), "", 2); + return null; + } + + return jtf; + } + + public void setTableEditting(int row, int col) { + // t_part.clearSelection(); + t_part.changeSelection(row, col, false, false); + t_part.editCellAt(row, col, null); + // System.out.println("第一次:"+edit_row+";"+edit_col); + Component editor = t_part.getEditorComponent(); + if (editor != null) { + // editor.requestFocusInWindow(); + editor.requestFocus(); + Component c = editor.getComponentAt(0, 0); + if (c != null && c instanceof JTextComponent) { + JTextComponent jtc = (JTextComponent) c; + String value = jtc.getText(); + + if (!KUtil.isEmpty(value)) { + jtc.setCaretPosition(value.length()); + } + } + } + } + +} diff --git a/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcCommand.java b/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcCommand.java new file mode 100644 index 0000000..76528ab --- /dev/null +++ b/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcCommand.java @@ -0,0 +1,18 @@ +package com.connor.chint.yunpi.command; + +import com.connor.chint.yunpi.KCommand; +import com.teamcenter.rac.aif.AbstractAIFApplication; + +public class ZxjcCommand extends KCommand { + + public ZxjcCommand(AbstractAIFApplication app, String commandId, String actionInfo) { + super(app, commandId, actionInfo); + + try { + + this.setRunnable(new ZxjcFram(app)); + }catch(Exception e) { + e.printStackTrace(); + } + } +} diff --git a/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcController.java b/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcController.java new file mode 100644 index 0000000..bbef719 --- /dev/null +++ b/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcController.java @@ -0,0 +1,1457 @@ +package com.connor.chint.yunpi.command; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.sql.ResultSet; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; + +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +//import com.connor.chint.sap2.sap.SAPPushBOMBean; +//import com.connor.chint.sap2.sap_by.SAPBYOperation; +//import com.connor.chint.sap2.sap_zy.PartBean; +//import com.connor.chint.sap2.sap_zy.SAPZYDialogzt; +import com.connor.chint.sap2.util.BomToSapUtil; +import com.connor.chint.sap2.util.BomUtilWh; +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.SqlUtil; +import com.connor.chint.sap2.util.TXTUtil; +import com.squareup.okhttp.Credentials; +import com.squareup.okhttp.MediaType; +import com.squareup.okhttp.OkHttpClient; +import com.squareup.okhttp.Request; +import com.squareup.okhttp.RequestBody; +import com.squareup.okhttp.Response; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.ListOfValuesInfo; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentGroup; +import com.teamcenter.rac.kernel.TCComponentICO; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentListOfValues; +import com.teamcenter.rac.kernel.TCComponentMEProcessRevision; +import com.teamcenter.rac.kernel.TCComponentReleaseStatusType; +import com.teamcenter.rac.kernel.TCComponentUser; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCProperty; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.kernel.ics.ICSProperty; +import com.teamcenter.rac.kernel.ics.ICSPropertyDescription; +import com.teamcenter.rac.util.MessageBox; +import com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSData; + +import cn.hutool.json.JSONArray; + +public class ZxjcController { + + public static final String TYPE_REV_PART = "Part Revision"; + public TCComponent project; // 项目信息 + public String groupName; + public String zt2_ProjectNo; + public String wbs; + public AbstractAIFApplication app; + private TCSession session; + public List partList = new ArrayList<>(); + public ZxjcFram dialog; + private SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss"); + + public ZxjcController(ZxjcFram sapzyDialog, AbstractAIFApplication app) { + this.app = app; + this.session = (TCSession) app.getSession(); + } + + // 检查选定项目下是否存在产成品 + public boolean checkTargets() throws Exception { + InterfaceAIFComponent target = app.getTargetComponent(); + if (target == null || !(target instanceof TCComponent)) { + return false; + } + project = (TCComponent) target; + + zt2_ProjectNo = project.getProperty("zt2_ProjectNo"); + wbs = project.getProperty("zt2_WBSNo"); + System.out.println("检查对象:" + target); + List partRevList = KUtil.getCCPFromProject(project); + + for (TCComponentItemRevision rev : partRevList) { + String cType = rev.getType(); +// System.out.println(">> 找到子对象:" + cName + "|" + cType); + if (TYPE_REV_PART.equals(cType)) { + ZxjcBean bean = new ZxjcBean(rev, partList.size() + 1, ""); + SAPPushBOMBean.readUser(bean, rev, groupName, session); + bean.setPSPID(project.getProperty("zt2_ProjectNo")); + partList.add(bean); + } + } + if (partList.size() == 0) { + return false; + } + return true; + } + + public String sapState = ""; + private TCComponent released_Red; + private TCComponent released_Yellow; + private TCComponent released_Green; + + @SuppressWarnings("deprecation") + public void getSapState() throws TCException { + TCComponentListOfValues unitLov = KUtil.getLov(session, "zt2_SapState"); + if (unitLov != null) { + ListOfValuesInfo listOfValues = unitLov.getListOfValues(); + String[] realval = listOfValues.getStringListOfValues(); + for (int i = 0; i < realval.length; i++) { + String disval = listOfValues.getDisplayableValue(realval[i]); + System.out.println("显示值:" + disval + ";真实值:" + realval[i]); + if (disval.equals("已传")) { + sapState = realval[i]; + } + + } + + } + + TCComponentReleaseStatusType releaseType = (TCComponentReleaseStatusType) session + .getTypeComponent("ReleaseStatus"); + + released_Green = releaseType.create("ZT2_Green"); + released_Green.save(); + released_Green.unlock(); + released_Red = releaseType.create("ZT2_Red"); + released_Red.save(); + released_Red.unlock(); + released_Yellow = releaseType.create("ZT2_Yellow"); + released_Yellow.save(); + released_Yellow.unlock(); + } + + private SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); + + public static String getXML() { + String soapXML = "\r\n" + + " \r\n" + " \r\n" + " \r\n" + + " \r\n" + " \r\n" + ""; + return soapXML; + } + + public TCComponentItemRevision getPRevision(TCComponentItemRevision rev2) throws Exception { + + String zt2_MaterialNo = rev2.getStringProperty("zt2_MaterialNo"); + if (rev2.getType().equals("Part Revision")) { + String zt2_ifpbom = rev2.getProperty("zt2_ifpbom"); + if (zt2_ifpbom.equals("P")) { + return rev2; + } else { + TCComponent designRev = rev2.getRelatedComponent("TC_Is_Represented_By"); + 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")) { + TCComponentItemRevision[] revs = ((TCComponentItemRevision) matnr).getItem() + .getReleasedItemRevisions(); + System.out.println("getPRevision:" + matnr + " ==> " + Arrays.toString(revs)); + if (revs.length > 0)// lidy20240415 + return revs[0]; +// else +// return (TCComponentItemRevision) matnr; + } + } + } + } + } + return rev2; + + } + + public String getUserName(TCSession session) throws Exception { + TCComponentUser user = session.getUser(); + session.getUserName(); + return user.getTCProperty("user_name").getDisplayValue(); + } + + public void sendZxjc() throws Exception { + + System.out.println("pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp"); + // 获取选中的数据 + List selectedParts = getSelectedParts(); + StringBuilder msg = new StringBuilder(""); + // 图纸和产成品关系对应 + HashMap> tz_ccpMap = new HashMap>(); + + // 获取项目信息 + String cpxhValue = ""; + String project_object_name = project.getStringProperty("object_name"); + String project_zt2_ProjectNo = project.getStringProperty("zt2_ProjectNo"); + String project_zt2_WBSNo = project.getStringProperty("zt2_WBSNo"); + // 获取项目所有者的工厂 +// TCComponentGroup group = (TCComponentGroup) project.getRelatedComponent("owning_group"); +// String strGroup = group.getStringProperty("full_name"); + + // 遍历勾选中的产成品对象 + for (ZxjcBean bean : selectedParts) { + TCComponentItemRevision ccpRev = bean.part; + // 获取图纸 + TCComponentItemRevision tzRevTemp = (TCComponentItemRevision) ccpRev + .getRelatedComponent("TC_Is_Represented_By"); + + if (tzRevTemp != null) { + TCComponentItemRevision tzRev = tzRevTemp.getItem().getLatestItemRevision(); + if (tzRev != null) { + + // 可能存在一套图纸对应多个产成品 + System.out.println("tzRev==================" + tzRev.getUid()); + if (tz_ccpMap.containsKey(tzRev)) { + List ccpRevList = tz_ccpMap.get(tzRev); + ArrayList tempList = new ArrayList(); + tempList.add(ccpRev); + tempList.add(bean.getCcbh() == null ? "" : bean.getCcbh()); + System.out.println( + " bean.getCcbh()=====================================================================================" + + bean.getCcbh()); + ccpRevList.add(tempList); + tz_ccpMap.put((TCComponentItemRevision) tzRev, ccpRevList); + } else { + List ccpRevList = new ArrayList(); + ArrayList tempList = new ArrayList(); + tempList.add(ccpRev); + tempList.add(bean.getCcbh() == null ? "" : bean.getCcbh()); + ccpRevList.add(tempList); + tz_ccpMap.put(tzRev, ccpRevList); + } + + } + }else {//没有图纸的产成品 直接用产成品的bom + + + // 可能存在一套图纸对应多个产成品 + if (tz_ccpMap.containsKey(ccpRev)) { + List ccpRevList = tz_ccpMap.get(ccpRev); + ArrayList tempList = new ArrayList(); + tempList.add(ccpRev); + tempList.add(bean.getCcbh() == null ? "" : bean.getCcbh()); + System.out.println( + " bean.getCcbh()=====================================================================================" + + bean.getCcbh()); + ccpRevList.add(tempList); + tz_ccpMap.put((TCComponentItemRevision) ccpRev, ccpRevList); + } else { + List ccpRevList = new ArrayList(); + ArrayList tempList = new ArrayList(); + tempList.add(ccpRev); + tempList.add(bean.getCcbh() == null ? "" : bean.getCcbh()); + ccpRevList.add(tempList); + tz_ccpMap.put(ccpRev, ccpRevList); + } + + + } + } + + // 开始处理图纸 + + // 需要数据库查询拆分的图号 + List cfList = new ArrayList();// 需要拆分图纸 + + // insert数据库 + String[] prefs = session.getPreferenceService().getStringValues("CHINT_SRM_SQL_CONNECT"); + // String insertSql = "INSERT INTO CHINT_DRAWING_TO_SRM_TASK + // (\"tasksource\",\"factory\",\"flowid\",\"status\",\"msg\") values + // (?,?,?,?,?)"; + + try { + SqlUtil.SRMGetTCDataConnection(prefs); + + String sql = "SELECT drawingno FROM CHINT_BOM_DISASSEMBLY_RULE WHERE factory = '" + groupName + "'"; + + System.out.println("查询语句:" + sql.toString()); + ResultSet rs = SqlUtil.read(sql.toString()); + + while (rs.next()) { + String th = rs.getString(1); + System.out.println("th==" + th); + //如果包含*的图号 把*替换成0-9 + if(th != null) { + if(th.contains("*")) { + for (int i = 0; i < 10; i++) { + String replace = th.replace("*", i+""); + System.out.println("replace========================"+replace); + cfList.add(replace); + System.out.println("*****************************************************************"); + + } + continue; + } + cfList.add(th); + } + + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + SqlUtil.freeAll(); + } + + String a = ""; + for (int i = 0; i < cfList.size(); i++) { + a+=cfList.get(i)+"--"; + } + System.out.println("a==="+a); + // 遍历图纸 一套图纸传递一次 + System.out.println("tz_ccpMap.size=====================" + tz_ccpMap.size()); + for (Entry> map : tz_ccpMap.entrySet()) { + ArrayList tzBomsList = new ArrayList();// 图纸BOM对象 + HashMap> wlMap = new LinkedHashMap>(); + + // 获取图纸对象 + TCComponentItemRevision key = map.getKey(); + TCComponentItem tzItem = key.getItem(); + // 获取产品型号 (分类属性) + TCComponentICO[] icos = tzItem.getClassificationObjects();// 获取到其分类 + // 判断是否发送分类 + if (icos != null && icos.length > 0) { + System.out.println("发送过分类============"); + ICSProperty[] icsValues = icos[0].getICSProperties(true);// 获取到分类属性的值 + // ICSPropertyDescription[] icsDNames = icos[0].getICSPropertyDescriptors();// + // 获取分类属性的名称 + System.out.println("icos.size============" + icos.length); + System.out.println("icsValues.length============" + icsValues.length); + for (int i = 0; i < icsValues.length; i++) { + int flId = icsValues[i].getId(); + if (flId == 6094) { + System.out.println("flId================" + flId); + cpxhValue = icsValues[i].getValue(); + } + } + } + // 获取图纸号 + String tzId = key.getStringProperty("item_id"); + String tzObjectName = key.getStringProperty("object_name"); + // 获取topBomline + TCComponentBOMLine tzTopBomLine = getBOMLine(session, key); + // 获取图纸的子 + AIFComponentContext[] children = tzTopBomLine.getChildren(); + // 递归获取一套图纸 + for (int i = 0; i < children.length; i++) { + TCComponentBOMLine child_line = (TCComponentBOMLine) children[i].getComponent(); + // 递归方法 + dg(child_line, tzBomsList, cfList); + } + System.out.println("tzBoms.size=====================" + tzBomsList.size()); + // 根据图纸获取物料 排除重复物料 + + // 存在相同的物料 如果用j做序号不对 + int count = 1; + + // 获取流水号的首选项 + String[] lsmPref = session.getPreferenceService().getStringValues("CHINT_MATERIAL_VIRTUAL_RULE"); + // 获取对应组织的流水码 + String lsh = ""; + for (int i = 0; i < lsmPref.length; i++) { + String[] split = lsmPref[i].split(":"); + // 判断当前组织与首选项是否相同 + if (split[0].equals(groupName)) { + lsh = split[1]; + } + } + + for (int i = 0; i < tzBomsList.size(); i++) { + TCComponentBOMLine tcComponentBOMLine = tzBomsList.get(i); + String tzType = tcComponentBOMLine.getStringProperty("fnd0bl_line_object_type"); + if (tzType != null && tzType.equals("ZT2_Design3DRevision")) { + // 是否查到流水码 + boolean isCheck = false; + // 获取图纸的数量 + String tz_bl_quantity = tcComponentBOMLine.getStringProperty("bl_quantity"); + // 图纸bomline获取rev + TCComponentItemRevision tzItemRevision = tcComponentBOMLine.getItemRevision(); + // 获取图纸关系文件夹下的物料 + TCComponent[] wlRevs = tzItemRevision.getRelatedComponents("representation_for"); + System.out.println("wlRevs.size()======================" + wlRevs.length); + + //如果图纸下没有关联物料 + if(wlRevs == null || wlRevs.length < 1) { + TCComponentItemRevision wlRev = (TCComponentItemRevision) tzItemRevision; + String zt2_MaterialNo = ""; + zt2_MaterialNo = wlRev.getStringProperty("zt2_MaterialNo"); + + // 如果物料号为空,去数据库取 + String object_name = wlRev.getStringProperty("object_name"); + if (zt2_MaterialNo == null || zt2_MaterialNo.isEmpty()) { + + try { + + SqlUtil.SRMGetTCDataConnection(prefs); + + String selectSql = "SELECT drawingno,objectname FROM CHINT_MATERIAL_VIRTUAL WHERE objectname = '" + + object_name + "' AND factory = '" + groupName + + "' ORDER BY SEQ DESC FETCH FIRST 1 ROW ONLY"; + + System.out.println("查询语句:" + selectSql.toString()); + ResultSet rs = SqlUtil.read(selectSql.toString()); + String newCount = "";// 新流水码 + while (rs.next()) { + zt2_MaterialNo = rs.getString(1); + isCheck = true; + } + // 查到流水码 流水码+1 + +// if (isCheck) { +// +// // 正则表达式,匹配所有的字母和数字 +// Pattern pattern = Pattern.compile("(\\D+)(\\d+)"); +// Matcher matcher = pattern.matcher(zt2_MaterialNo); +// +// if (matcher.find()) { +// String alphaPart = matcher.group(1); // 字母部分 +// String numericPartStr = matcher.group(2); // 数字部分字符串 +// +// // 将数字部分转换为整数,加1,再转回字符串 +// int numericPartInt = Integer.parseInt(numericPartStr); +// numericPartInt++; // 加1 +// String newNumericPart = String.format("%0" + numericPartStr.length() + "d", +// numericPartInt); // 保持原数字的长度,前面补0 +// +// // 重新拼接字符串 +// newCount = alphaPart + newNumericPart; +// +// System.out.println("新组成的字符串: " + newCount); +// } else { +// System.out.println("未在字符串中找到符合模式的部分。"); +// } +// // 流水码+1 +// if (!newCount.isEmpty()) { +// String updateSql = "UPDATE CHINT_MATERIAL_VIRTUAL SET drawingno='" + newCount +// + "' WHERE objectname = '" + object_name + "'"; +// SqlUtil.update(updateSql); +// } +// +// } + } catch (Exception e) { + e.printStackTrace(); + } finally { + SqlUtil.freeAll(); + } + + } + // 获取首选项 CHINT_MATERIAL_VIRTUAL_RULE 获取流水码 匹配数据库获取的流水号前缀是否与首选项相同, + // 相同则流水号+1 否则重新创建流水号 + if (zt2_MaterialNo == null || zt2_MaterialNo.isEmpty()) { + + // 查询最大流水号 + SqlUtil.SRMGetTCDataConnection(prefs); + + String selectSql = "SELECT drawingno FROM CHINT_MATERIAL_VIRTUAL WHERE factory = '" + + groupName + "' ORDER BY SEQ DESC FETCH FIRST 1 ROW ONLY"; + + System.out.println("查询语句:" + selectSql.toString()); + ResultSet rs = SqlUtil.read(selectSql.toString()); + String maxLsh = ""; + while (rs.next()) { + maxLsh = rs.getString(1); + } + + if (lsmPref != null && lsmPref.length > 0 && !lsh.isEmpty()) { + + // 取流水号的前三位字母判断 + String subLsh = lsh.substring(0, 3); + if (maxLsh.isEmpty() || !maxLsh.contains(subLsh)) {// 数据库中查到的与首选项不匹配 生成新的流水码 + SqlUtil.SRMGetTCDataConnection(prefs); + String updateSql = "INSERT INTO CHINT_MATERIAL_VIRTUAL (factory,objectname,drawingno) VALUES ('" + + groupName + "','" + object_name + "','" + lsh + "')"; + SqlUtil.update(updateSql); + zt2_MaterialNo = lsh; + } else {// 首选项字母与数据库相同 + + // 正则表达式,匹配所有的字母和数字 + String newCount1 = "";// 新流水码 + Pattern pattern = Pattern.compile("(\\D+)(\\d+)"); + Matcher matcher = pattern.matcher(maxLsh); + + if (matcher.find()) { + String alphaPart = matcher.group(1); // 字母部分 + String numericPartStr = matcher.group(2); // 数字部分字符串 + + // 将数字部分转换为整数,加1,再转回字符串 + int numericPartInt = Integer.parseInt(numericPartStr); + numericPartInt++; // 加1 + String newNumericPart = String.format("%0" + numericPartStr.length() + "d", + numericPartInt); // 保持原数字的长度,前面补0 + + // 重新拼接字符串 + newCount1 = alphaPart + newNumericPart; + + System.out.println("新组成的字符串: " + newCount1); + } else { + System.out.println("未在字符串中找到符合模式的部分。"); + } + // 流水码+1 + SqlUtil.SRMGetTCDataConnection(prefs); + if (!newCount1.isEmpty()) { + String updateSql = "INSERT INTO CHINT_MATERIAL_VIRTUAL (factory,objectname,drawingno) VALUES ('" + + groupName + "','" + object_name + "','" + newCount1 + "')"; + SqlUtil.update(updateSql); + } + zt2_MaterialNo = newCount1; + } + } + + } else if (!zt2_MaterialNo.isEmpty() && isCheck) {// 数据中取到流水号 + if (lsmPref != null && lsmPref.length > 0 && !lsh.isEmpty()) { + + // 取流水号的前三位字母判断 + String subLsh = lsh.substring(0, 3); + if (!zt2_MaterialNo.contains(subLsh)) { // 查询最大流水号 + SqlUtil.SRMGetTCDataConnection(prefs); + + String selectSql = "SELECT drawingno FROM CHINT_MATERIAL_VIRTUAL WHERE factory = '" + + groupName + "' ORDER BY SEQ DESC FETCH FIRST 1 ROW ONLY"; + + System.out.println("查询语句:" + selectSql.toString()); + ResultSet rs = SqlUtil.read(selectSql.toString()); + String maxLsh = ""; + while (rs.next()) { + maxLsh = rs.getString(1); + } + + if (maxLsh.isEmpty() || !maxLsh.contains(subLsh)) {// 数据库中查到的与首选项不匹配 生成新的流水码 + SqlUtil.SRMGetTCDataConnection(prefs); + String updateSql = "INSERT INTO CHINT_MATERIAL_VIRTUAL (factory,objectname,drawingno) VALUES ('" + + groupName + "','" + object_name + "','" + lsh + "')"; + SqlUtil.update(updateSql); + zt2_MaterialNo = lsh; + } else {// 首选项字母与数据库相同 + + // 正则表达式,匹配所有的字母和数字 + String newCount1 = "";// 新流水码 + Pattern pattern = Pattern.compile("(\\D+)(\\d+)"); + Matcher matcher = pattern.matcher(maxLsh); + + if (matcher.find()) { + String alphaPart = matcher.group(1); // 字母部分 + String numericPartStr = matcher.group(2); // 数字部分字符串 + + // 将数字部分转换为整数,加1,再转回字符串 + int numericPartInt = Integer.parseInt(numericPartStr); + numericPartInt++; // 加1 + String newNumericPart = String.format("%0" + numericPartStr.length() + "d", + numericPartInt); // 保持原数字的长度,前面补0 + + // 重新拼接字符串 + newCount1 = alphaPart + newNumericPart; + + System.out.println("新组成的字符串: " + newCount1); + } else { + System.out.println("未在字符串中找到符合模式的部分。"); + } + // 流水码+1 + SqlUtil.SRMGetTCDataConnection(prefs); + if (!newCount1.isEmpty()) { + String updateSql = "INSERT INTO CHINT_MATERIAL_VIRTUAL (factory,objectname,drawingno) VALUES ('" + + groupName + "','" + object_name + "','" + newCount1 + "')"; + SqlUtil.update(updateSql); + } + zt2_MaterialNo = newCount1; + } + } + } + } + + // 因为bl_quantity字段需要数字累加,先判断map中是否存在该物料 + if (wlMap.containsKey(object_name + zt2_MaterialNo)) {// 存在就只获取物料数量 + + // 获取物料的数量 + List tempList = wlMap.get(object_name + zt2_MaterialNo); + String quantity = tempList.get(5); + // 数量相加 + int intQuantity = Integer.parseInt(quantity) + Integer.parseInt(tz_bl_quantity); + // 设置map的值 + wlMap.get(object_name + zt2_MaterialNo).set(5, intQuantity + ""); + } else { + // 获取物料属性 + String zt2_Specifications = wlRev.getStringProperty("zt2_Specifications"); + + // 获取物料item单位 + TCComponentItem item = wlRev.getItem(); + String zt2_unit = item.getProperty("zt2_unit"); + // 获取物料bomline上的属性 + + TCComponentBOMLine bomLine = tcComponentBOMLine; + // String bl_quantity = bomLine.getStringProperty("bl_quantity"); + String ZT2_Remark = bomLine.getStringProperty("ZT2_Remark"); + // 把值存在list里存入map + List fieldList = new ArrayList(); + fieldList.add(count + "");// 序号 + fieldList.add(object_name==null?"":object_name); + fieldList.add(zt2_Specifications==null?"":zt2_Specifications); + fieldList.add(zt2_MaterialNo==null?"":zt2_MaterialNo); + fieldList.add(zt2_unit==null?"":zt2_unit); + fieldList.add(tz_bl_quantity==null?"":tz_bl_quantity); + fieldList.add(ZT2_Remark==null?"":ZT2_Remark); + + if (zt2_MaterialNo != null && !zt2_MaterialNo.equals("")) { + wlMap.put(object_name + zt2_MaterialNo, fieldList); + count++; + } + + } + }else { + + for (int j = 0; j < wlRevs.length; j++) { + + TCComponentItemRevision wlRev = (TCComponentItemRevision) wlRevs[j]; + String zt2_MaterialNo = ""; + zt2_MaterialNo = wlRev.getStringProperty("zt2_MaterialNo"); + + // 如果物料号为空,去数据库取 + String object_name = wlRev.getStringProperty("object_name"); + if (zt2_MaterialNo == null || zt2_MaterialNo.isEmpty()) { + + try { + + SqlUtil.SRMGetTCDataConnection(prefs); + + String selectSql = "SELECT drawingno,objectname FROM CHINT_MATERIAL_VIRTUAL WHERE objectname = '" + + object_name + "' AND factory = '" + groupName + + "' ORDER BY SEQ DESC FETCH FIRST 1 ROW ONLY"; + + System.out.println("查询语句:" + selectSql.toString()); + ResultSet rs = SqlUtil.read(selectSql.toString()); + String newCount = "";// 新流水码 + while (rs.next()) { + zt2_MaterialNo = rs.getString(1); + isCheck = true; + } + // 查到流水码 流水码+1 + +// if (isCheck) { + // +// // 正则表达式,匹配所有的字母和数字 +// Pattern pattern = Pattern.compile("(\\D+)(\\d+)"); +// Matcher matcher = pattern.matcher(zt2_MaterialNo); + // +// if (matcher.find()) { +// String alphaPart = matcher.group(1); // 字母部分 +// String numericPartStr = matcher.group(2); // 数字部分字符串 + // +// // 将数字部分转换为整数,加1,再转回字符串 +// int numericPartInt = Integer.parseInt(numericPartStr); +// numericPartInt++; // 加1 +// String newNumericPart = String.format("%0" + numericPartStr.length() + "d", +// numericPartInt); // 保持原数字的长度,前面补0 + // +// // 重新拼接字符串 +// newCount = alphaPart + newNumericPart; + // +// System.out.println("新组成的字符串: " + newCount); +// } else { +// System.out.println("未在字符串中找到符合模式的部分。"); +// } +// // 流水码+1 +// if (!newCount.isEmpty()) { +// String updateSql = "UPDATE CHINT_MATERIAL_VIRTUAL SET drawingno='" + newCount +// + "' WHERE objectname = '" + object_name + "'"; +// SqlUtil.update(updateSql); +// } + // +// } + } catch (Exception e) { + e.printStackTrace(); + } finally { + SqlUtil.freeAll(); + } + + } + // 获取首选项 CHINT_MATERIAL_VIRTUAL_RULE 获取流水码 匹配数据库获取的流水号前缀是否与首选项相同, + // 相同则流水号+1 否则重新创建流水号 + if (zt2_MaterialNo == null || zt2_MaterialNo.isEmpty()) { + + // 查询最大流水号 + SqlUtil.SRMGetTCDataConnection(prefs); + + String selectSql = "SELECT drawingno FROM CHINT_MATERIAL_VIRTUAL WHERE factory = '" + + groupName + "' ORDER BY SEQ DESC FETCH FIRST 1 ROW ONLY"; + + System.out.println("查询语句:" + selectSql.toString()); + ResultSet rs = SqlUtil.read(selectSql.toString()); + String maxLsh = ""; + while (rs.next()) { + maxLsh = rs.getString(1); + } + + if (lsmPref != null && lsmPref.length > 0 && !lsh.isEmpty()) { + + // 取流水号的前三位字母判断 + String subLsh = lsh.substring(0, 3); + if (maxLsh.isEmpty() || !maxLsh.contains(subLsh)) {// 数据库中查到的与首选项不匹配 生成新的流水码 + SqlUtil.SRMGetTCDataConnection(prefs); + String updateSql = "INSERT INTO CHINT_MATERIAL_VIRTUAL (factory,objectname,drawingno) VALUES ('" + + groupName + "','" + object_name + "','" + lsh + "')"; + SqlUtil.update(updateSql); + zt2_MaterialNo = lsh; + } else {// 首选项字母与数据库相同 + + // 正则表达式,匹配所有的字母和数字 + String newCount1 = "";// 新流水码 + Pattern pattern = Pattern.compile("(\\D+)(\\d+)"); + Matcher matcher = pattern.matcher(maxLsh); + + if (matcher.find()) { + String alphaPart = matcher.group(1); // 字母部分 + String numericPartStr = matcher.group(2); // 数字部分字符串 + + // 将数字部分转换为整数,加1,再转回字符串 + int numericPartInt = Integer.parseInt(numericPartStr); + numericPartInt++; // 加1 + String newNumericPart = String.format("%0" + numericPartStr.length() + "d", + numericPartInt); // 保持原数字的长度,前面补0 + + // 重新拼接字符串 + newCount1 = alphaPart + newNumericPart; + + System.out.println("新组成的字符串: " + newCount1); + } else { + System.out.println("未在字符串中找到符合模式的部分。"); + } + // 流水码+1 + SqlUtil.SRMGetTCDataConnection(prefs); + if (!newCount1.isEmpty()) { + String updateSql = "INSERT INTO CHINT_MATERIAL_VIRTUAL (factory,objectname,drawingno) VALUES ('" + + groupName + "','" + object_name + "','" + newCount1 + "')"; + SqlUtil.update(updateSql); + } + zt2_MaterialNo = newCount1; + } + } + + } else if (!zt2_MaterialNo.isEmpty() && isCheck) {// 数据中取到流水号 + if (lsmPref != null && lsmPref.length > 0 && !lsh.isEmpty()) { + + // 取流水号的前三位字母判断 + String subLsh = lsh.substring(0, 3); + if (!zt2_MaterialNo.contains(subLsh)) { // 查询最大流水号 + SqlUtil.SRMGetTCDataConnection(prefs); + + String selectSql = "SELECT drawingno FROM CHINT_MATERIAL_VIRTUAL WHERE factory = '" + + groupName + "' ORDER BY SEQ DESC FETCH FIRST 1 ROW ONLY"; + + System.out.println("查询语句:" + selectSql.toString()); + ResultSet rs = SqlUtil.read(selectSql.toString()); + String maxLsh = ""; + while (rs.next()) { + maxLsh = rs.getString(1); + } + + if (maxLsh.isEmpty() || !maxLsh.contains(subLsh)) {// 数据库中查到的与首选项不匹配 生成新的流水码 + SqlUtil.SRMGetTCDataConnection(prefs); + String updateSql = "INSERT INTO CHINT_MATERIAL_VIRTUAL (factory,objectname,drawingno) VALUES ('" + + groupName + "','" + object_name + "','" + lsh + "')"; + SqlUtil.update(updateSql); + zt2_MaterialNo = lsh; + } else {// 首选项字母与数据库相同 + + // 正则表达式,匹配所有的字母和数字 + String newCount1 = "";// 新流水码 + Pattern pattern = Pattern.compile("(\\D+)(\\d+)"); + Matcher matcher = pattern.matcher(maxLsh); + + if (matcher.find()) { + String alphaPart = matcher.group(1); // 字母部分 + String numericPartStr = matcher.group(2); // 数字部分字符串 + + // 将数字部分转换为整数,加1,再转回字符串 + int numericPartInt = Integer.parseInt(numericPartStr); + numericPartInt++; // 加1 + String newNumericPart = String.format("%0" + numericPartStr.length() + "d", + numericPartInt); // 保持原数字的长度,前面补0 + + // 重新拼接字符串 + newCount1 = alphaPart + newNumericPart; + + System.out.println("新组成的字符串: " + newCount1); + } else { + System.out.println("未在字符串中找到符合模式的部分。"); + } + // 流水码+1 + SqlUtil.SRMGetTCDataConnection(prefs); + if (!newCount1.isEmpty()) { + String updateSql = "INSERT INTO CHINT_MATERIAL_VIRTUAL (factory,objectname,drawingno) VALUES ('" + + groupName + "','" + object_name + "','" + newCount1 + "')"; + SqlUtil.update(updateSql); + } + zt2_MaterialNo = newCount1; + } + } + } + } + + // 因为bl_quantity字段需要数字累加,先判断map中是否存在该物料 + if (wlMap.containsKey(object_name + zt2_MaterialNo)) {// 存在就只获取物料数量 + + // 获取物料的数量 + List tempList = wlMap.get(object_name + zt2_MaterialNo); + String quantity = tempList.get(5); + // 数量相加 + int intQuantity = Integer.parseInt(quantity) + Integer.parseInt(tz_bl_quantity); + // 设置map的值 + wlMap.get(object_name + zt2_MaterialNo).set(5, intQuantity + ""); + } else { + // 获取物料属性 + String object_desc = wlRev.getStringProperty("object_desc"); + if (object_desc == null || object_desc.isEmpty()) { + object_desc = object_name; + } + String zt2_Specifications = wlRev.getStringProperty("zt2_Specifications"); + + // 获取物料item单位 + TCComponentItem item = wlRev.getItem(); + String zt2_unit = item.getProperty("zt2_unit"); + // 获取物料bomline上的属性 + TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session + .getTypeComponent("BOMWindow"); + TCComponentBOMWindow window = bomWinType.create(null); + TCComponentBOMLine bomLine = window.setWindowTopLine(null, wlRev, null, null); + window.save(); + // String bl_quantity = bomLine.getStringProperty("bl_quantity"); + String ZT2_Remark = bomLine.getStringProperty("ZT2_Remark"); + window.delete(); + // 把值存在list里存入map + List fieldList = new ArrayList(); + fieldList.add(count + "");// 序号 + fieldList.add(object_desc==null?"":object_desc); + fieldList.add(zt2_Specifications==null?"":zt2_Specifications); + fieldList.add(zt2_MaterialNo==null?"":zt2_MaterialNo); + fieldList.add(zt2_unit==null?"":zt2_unit); + fieldList.add(tz_bl_quantity==null?"":tz_bl_quantity); + fieldList.add(ZT2_Remark==null?"":ZT2_Remark); + + if (zt2_MaterialNo != null && !zt2_MaterialNo.equals("")) { + wlMap.put(object_name + zt2_MaterialNo, fieldList); + count++; + } + + } + + } + } + + } else {// 如果不是图纸类型 + + // 获取图纸的数量 + String tz_bl_quantity = tcComponentBOMLine.getStringProperty("bl_quantity"); + // 物料bomline获取rev + TCComponentItemRevision wlRev = tcComponentBOMLine.getItemRevision(); + String zt2_MaterialNo = ""; + zt2_MaterialNo = wlRev.getStringProperty("zt2_MaterialNo"); + // 是否查到流水码 + boolean isCheck = false; + // 如果物料号为空,去数据库取 + String object_name = wlRev.getStringProperty("object_name"); + + if (zt2_MaterialNo == null || zt2_MaterialNo.isEmpty()) { + + try { + + SqlUtil.SRMGetTCDataConnection(prefs); + + String selectSql = "SELECT drawingno,objectname FROM CHINT_MATERIAL_VIRTUAL WHERE objectname = '" + + object_name + "' AND factory = '" + groupName + + "' ORDER BY SEQ DESC FETCH FIRST 1 ROW ONLY"; + + System.out.println("查询语句:" + selectSql.toString()); + ResultSet rs = SqlUtil.read(selectSql.toString()); + String newCount = "";// 新流水码 + while (rs.next()) { + zt2_MaterialNo = rs.getString(1); + isCheck = true; + } + // 查到流水码 流水码+1 + +// if (isCheck) { +// +// // 正则表达式,匹配所有的字母和数字 +// Pattern pattern = Pattern.compile("(\\D+)(\\d+)"); +// Matcher matcher = pattern.matcher(zt2_MaterialNo); +// +// if (matcher.find()) { +// String alphaPart = matcher.group(1); // 字母部分 +// String numericPartStr = matcher.group(2); // 数字部分字符串 +// +// // 将数字部分转换为整数,加1,再转回字符串 +// int numericPartInt = Integer.parseInt(numericPartStr); +// numericPartInt++; // 加1 +// String newNumericPart = String.format("%0" + numericPartStr.length() + "d", +// numericPartInt); // 保持原数字的长度,前面补0 +// +// // 重新拼接字符串 +// newCount = alphaPart + newNumericPart; +// +// System.out.println("新组成的字符串: " + newCount); +// } else { +// System.out.println("未在字符串中找到符合模式的部分。"); +// } +// // 流水码+1 +// if (!newCount.isEmpty()) { +// String updateSql = "UPDATE CHINT_MATERIAL_VIRTUAL SET drawingno='" + newCount +// + "' WHERE objectname = '" + object_name + "'"; +// SqlUtil.update(updateSql); +// } +// +// } + } catch (Exception e) { + e.printStackTrace(); + } finally { + SqlUtil.freeAll(); + } + + } + // 获取首选项 CHINT_MATERIAL_VIRTUAL_RULE 获取流水码 匹配数据库获取的流水号前缀是否与首选项相同, + // 相同则流水号+1 否则重新创建流水号 + if (zt2_MaterialNo == null || zt2_MaterialNo.isEmpty()) { + + // 查询最大流水号 + SqlUtil.SRMGetTCDataConnection(prefs); + + String selectSql = "SELECT drawingno FROM CHINT_MATERIAL_VIRTUAL WHERE factory = '" + groupName + + "' ORDER BY SEQ DESC FETCH FIRST 1 ROW ONLY"; + + System.out.println("查询语句:" + selectSql.toString()); + ResultSet rs = SqlUtil.read(selectSql.toString()); + String maxLsh = ""; + while (rs.next()) { + maxLsh = rs.getString(1); + } + + if (lsmPref != null && lsmPref.length > 0 && !lsh.isEmpty()) { + + // 取流水号的前三位字母判断 + String subLsh = lsh.substring(0, 3); + if (maxLsh.isEmpty() || !maxLsh.contains(subLsh)) {// 数据库中查到的与首选项不匹配 生成新的流水码 + SqlUtil.SRMGetTCDataConnection(prefs); + String updateSql = "INSERT INTO CHINT_MATERIAL_VIRTUAL (factory,objectname,drawingno) VALUES ('" + + groupName + "','" + object_name + "','" + lsh + "')"; + SqlUtil.update(updateSql); + zt2_MaterialNo = lsh; + } else {// 首选项字母与数据库相同 + + // 正则表达式,匹配所有的字母和数字 + String newCount1 = "";// 新流水码 + Pattern pattern = Pattern.compile("(\\D+)(\\d+)"); + Matcher matcher = pattern.matcher(maxLsh); + + if (matcher.find()) { + String alphaPart = matcher.group(1); // 字母部分 + String numericPartStr = matcher.group(2); // 数字部分字符串 + + // 将数字部分转换为整数,加1,再转回字符串 + int numericPartInt = Integer.parseInt(numericPartStr); + numericPartInt++; // 加1 + String newNumericPart = String.format("%0" + numericPartStr.length() + "d", + numericPartInt); // 保持原数字的长度,前面补0 + + // 重新拼接字符串 + newCount1 = alphaPart + newNumericPart; + + System.out.println("新组成的字符串: " + newCount1); + } else { + System.out.println("未在字符串中找到符合模式的部分。"); + } + // 流水码+1 + SqlUtil.SRMGetTCDataConnection(prefs); + if (!newCount1.isEmpty()) { + String updateSql = "INSERT INTO CHINT_MATERIAL_VIRTUAL (factory,objectname,drawingno) VALUES ('" + + groupName + "','" + object_name + "','" + newCount1 + "')"; + SqlUtil.update(updateSql); + } + zt2_MaterialNo = newCount1; + } + } + + } else if (!zt2_MaterialNo.isEmpty() && isCheck) {// 数据中取到流水号 + if (lsmPref != null && lsmPref.length > 0 && !lsh.isEmpty()) { + + // 取流水号的前三位字母判断 + String subLsh = lsh.substring(0, 3); + if (!zt2_MaterialNo.contains(subLsh)) { // 查询最大流水号 + SqlUtil.SRMGetTCDataConnection(prefs); + + String selectSql = "SELECT drawingno FROM CHINT_MATERIAL_VIRTUAL WHERE factory = '" + + groupName + "' ORDER BY SEQ DESC FETCH FIRST 1 ROW ONLY"; + + System.out.println("查询语句:" + selectSql.toString()); + ResultSet rs = SqlUtil.read(selectSql.toString()); + String maxLsh = ""; + while (rs.next()) { + maxLsh = rs.getString(1); + } + + if (maxLsh.isEmpty() || !maxLsh.contains(subLsh)) {// 数据库中查到的与首选项不匹配 生成新的流水码 + SqlUtil.SRMGetTCDataConnection(prefs); + String updateSql = "INSERT INTO CHINT_MATERIAL_VIRTUAL (factory,objectname,drawingno) VALUES ('" + + groupName + "','" + object_name + "','" + lsh + "')"; + SqlUtil.update(updateSql); + zt2_MaterialNo = lsh; + } else {// 首选项字母与数据库相同 + + // 正则表达式,匹配所有的字母和数字 + String newCount1 = "";// 新流水码 + Pattern pattern = Pattern.compile("(\\D+)(\\d+)"); + Matcher matcher = pattern.matcher(maxLsh); + + if (matcher.find()) { + String alphaPart = matcher.group(1); // 字母部分 + String numericPartStr = matcher.group(2); // 数字部分字符串 + + // 将数字部分转换为整数,加1,再转回字符串 + int numericPartInt = Integer.parseInt(numericPartStr); + numericPartInt++; // 加1 + String newNumericPart = String.format("%0" + numericPartStr.length() + "d", + numericPartInt); // 保持原数字的长度,前面补0 + + // 重新拼接字符串 + newCount1 = alphaPart + newNumericPart; + + System.out.println("新组成的字符串: " + newCount1); + } else { + System.out.println("未在字符串中找到符合模式的部分。"); + } + // 流水码+1 + SqlUtil.SRMGetTCDataConnection(prefs); + if (!newCount1.isEmpty()) { + String updateSql = "INSERT INTO CHINT_MATERIAL_VIRTUAL (factory,objectname,drawingno) VALUES ('" + + groupName + "','" + object_name + "','" + newCount1 + "')"; + SqlUtil.update(updateSql); + } + zt2_MaterialNo = newCount1; + } + } + } + } + + /* + * select * from CHINT_MATERIAL_VIRTUAL ORDER BY SEQ DESC FETCH FIRST 1 ROW + * ONLY; + * + * + * + * 表结构 sql CREATE SEQUENCE seq_CHINT_MATERIAL_VIRTUAL; + * + * CREATE TABLE CHINT_MATERIAL_VIRTUAL ( seq NUMBER(11) DEFAULT + * seq_CHINT_MATERIAL_VIRTUAL.nextval, factory VARCHAR2(20) , objectname + * VARCHAR2(20) , drawingno VARCHAR2(20) , PRIMARY KEY (seq) ) + * + */ + + // 因为bl_quantity字段需要数字累加,先判断map中是否存在该物料 + if (wlMap.containsKey(object_name + zt2_MaterialNo)) {// 存在就只获取物料数量 + + // 获取物料的数量 + List tempList = wlMap.get(object_name + zt2_MaterialNo); + String quantity = tempList.get(5); + // 数量相加 + int intQuantity = Integer.parseInt(quantity) + Integer.parseInt(tz_bl_quantity); + // 设置map的值 + wlMap.get(object_name + zt2_MaterialNo).set(5, intQuantity + ""); + } else { + // 获取物料属性 + String object_desc = wlRev.getStringProperty("object_desc"); + if (object_desc == null || object_desc.isEmpty()) { + object_desc = object_name; + } + String zt2_Specifications = wlRev.getStringProperty("zt2_Specifications"); + + System.out.println("zt2_Specifications==="+zt2_Specifications+"zt2_MaterialNo===="+zt2_MaterialNo); + // 获取物料item单位 + TCComponentItem item = wlRev.getItem(); + String zt2_unit = item.getProperty("zt2_unit"); + // 获取物料bomline上的属性 + // String bl_quantity = bomLine.getStringProperty("bl_quantity"); + String ZT2_Remark = tcComponentBOMLine.getStringProperty("ZT2_Remark"); + // 把值存在list里存入map + List fieldList = new ArrayList(); + fieldList.add(count + "");// 序号 + fieldList.add(object_desc==null?"":object_desc); + fieldList.add(zt2_Specifications==null?"":zt2_Specifications); + fieldList.add(zt2_MaterialNo==null?"":zt2_MaterialNo); + fieldList.add(zt2_unit==null?"":zt2_unit); + fieldList.add(tz_bl_quantity==null?"":tz_bl_quantity); + fieldList.add(ZT2_Remark==null?"":ZT2_Remark); + + if (zt2_MaterialNo != null && !zt2_MaterialNo.equals("")) { + wlMap.put(object_name + zt2_MaterialNo, fieldList); + count++; + } + + } + + } + } + System.out.println("wlMap.size()======================" + wlMap.size()); + // 拼接Json 发送接口 + JSONObject top = new JSONObject(); + // 产成品信息array + JSONArray ccpArray = new JSONArray(); + // 获取产成品revs + List ccp_revs = map.getValue(); + for (int j = 0; j < ccp_revs.size(); j++) { + JSONObject ccp_temp_Json = new JSONObject(); + TCComponentItemRevision ccp_rev = (TCComponentItemRevision) ccp_revs.get(j).get(0); + String zt2_MaterialNo = ccp_rev.getStringProperty("zt2_MaterialNo"); + String zt2_Quantity = ccp_rev.getStringProperty("zt2_Quantity"); + ccp_temp_Json.put("productno", zt2_MaterialNo); + ccp_temp_Json.put("ccpquantity", zt2_Quantity); + // 手动填写属性 + ccp_temp_Json.put("factoryno", ccp_revs.get(j).get(1)); + ccpArray.put(ccp_temp_Json); + } + + // 物料信息array + JSONArray wlArray = new JSONArray(); + // 循环wlmap拼接json + for (Entry> wlmap : wlMap.entrySet()) { + List tempWlList = wlmap.getValue(); + JSONObject wl_temp_Json = new JSONObject(); + wl_temp_Json.put("no", tempWlList.get(0)); + wl_temp_Json.put("materialno", tempWlList.get(3)); + wl_temp_Json.put("objectdesc", tempWlList.get(1)); + wl_temp_Json.put("specifications", tempWlList.get(2)); + wl_temp_Json.put("quantity", tempWlList.get(5)); + wl_temp_Json.put("unit", tempWlList.get(4)); + wl_temp_Json.put("remark", tempWlList.get(6)); + wlArray.put(wl_temp_Json); + } + + top.put("projectname", project_object_name); + top.put("projectno", project_zt2_ProjectNo); + top.put("wbsno", project_zt2_WBSNo); + top.put("factory", groupName); + top.put("producttype", cpxhValue); + //如果是备件包就不取id + top.put("drawingno", tzObjectName.contains("备件包")? "": tzId); + top.put("productnos", ccpArray); + top.put("lists", wlArray); + // + + System.out.println("top========" + top.toString()); + + // 发送接口 + String[] url = session.getPreferenceService().getStringValues("CHINT_ZXJC_URL"); + String strUrl = url[0]; + String resultStr = sendRequest(strUrl, top); + System.out.println("resultStr=======" + resultStr); + + + //飞书通知 + String userName = session.getUserName(); + String userId = session.getUser().getUserId(); + JSONObject msgJson = new JSONObject(); + msgJson.put("mobiles", new String[] {}); + userId+="@chint.com"; + msgJson.put("emails", new String[] {userId}); + msgJson.put("sms", false); + msgJson.put( + "content", + userName+"提交的"+project_zt2_ProjectNo+"项目的拆卸一览表信息已成功推送至装箱系统,请登陆装箱系统查阅。"); +// String result = okHttpCli.doPostJson(finalUrl, msgJson.toJSONString()); + + URL fsurl = new URL("http://10.128.10.170/api/feishu/Message/sendMessages"); + HttpURLConnection connection = (HttpURLConnection) fsurl.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); + connection.setRequestProperty("Accept", "application/json"); + connection.setDoOutput(true); + + + OutputStream outputStream = connection.getOutputStream(); + outputStream.write(msgJson.toString().getBytes("UTF-8")); + outputStream.flush(); + + int responseCode = connection.getResponseCode(); + if (responseCode == HttpURLConnection.HTTP_OK) { + + } else { + throw new RuntimeException("飞书发送失败 : " + responseCode); + } + + + System.out.println("msgJson.toString() ==>"+msgJson.toString()); + + + } + + } + + public String sendRequest(String apiUrl, JSONObject jsonToSend) throws Exception { + URL url = new URL(apiUrl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); + connection.setRequestProperty("Accept", "application/json"); + connection.setDoOutput(true); + + OutputStream outputStream = connection.getOutputStream(); + outputStream.write(jsonToSend.toString().getBytes("UTF-8")); + outputStream.flush(); + + int responseCode = connection.getResponseCode(); + if (responseCode == HttpURLConnection.HTTP_OK) { + try (BufferedReader br = new BufferedReader( + new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) { + + StringBuilder response = new StringBuilder(); + String line; + while ((line = br.readLine()) != null) { + response.append(line).append("\n"); + } + JSONObject resultJson = JSON.parseObject(response.toString()); + String msg = (String) resultJson.get("msg"); + + // 将响应内容解析为JSON对象 + return msg; + } + + } else { + throw new RuntimeException("Failed : HTTP error code : " + responseCode); + } + } + + public void dg(TCComponentBOMLine top, ArrayList tzBoms, List cfList) throws TCException { + String tzId = top.getStringProperty("bl_item_item_id"); + String object_name = top.getStringProperty("bl_rev_object_name"); + // 判断是否图纸类型 + + String[] tzIdSplit = tzId.split("-"); + // 判断是否拆分 如果图纸名称是备件包也可柴分 + if (cfList.contains(tzIdSplit[0]) || (object_name != null && object_name.contains("备件包"))) {// 拆 + AIFComponentContext[] children = top.getChildren(); + + for (int i = 0; i < children.length; i++) { + TCComponentBOMLine child_line = (TCComponentBOMLine) children[i].getComponent(); + dg(child_line, tzBoms, cfList); + } + + } else {// 不拆 + + tzBoms.add(top); + } + + } + + public static TCComponentBOMLine getBOMLine(TCSession session, TCComponentItemRevision revision) { + TCComponentBOMLine bomLine = null; + try { + TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow"); + TCComponentBOMWindow window = bomWinType.create(null); + bomLine = window.setWindowTopLine(null, revision, null, null); + window.save(); + } catch (TCException e) { + e.printStackTrace(); + } + return bomLine; + } + + public List getSelectedParts() throws Exception { + List selectedParts = new ArrayList<>(); + int rowCnt = dialog.t_part.getRowCount(); + for (int i = 0; i < rowCnt; i++) { + System.out.println(dialog.t_part.getValueAt(i, 0)); + if ("true".equals(dialog.t_part.getValueAt(i, 0).toString())) { + ZxjcBean bean = (ZxjcBean) dialog.t_part.getValueAt(i, 5); + // 设置出厂编号 + bean.setCcbh((String) dialog.t_part.getValueAt(i, 6)); + System.out.println("准备传递对象:" + bean); + if (bean != null) { + /* + * if(bean.factoryNo==null) { throw new Exception("对象<"+bean.part+">没有找到出厂编号"); + * } + */ + selectedParts.add(bean); + } + } + } + return selectedParts; + } + + 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_YB"); + String sapUrl = ""; + String momUrl = ""; + for (String stringValue : stringValues) { + if (stringValue.startsWith("SAP:1=")) { + sapUrl = stringValue.replaceAll("SAP: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 errBuffer = new StringBuffer(""); + if (sendSap.length() > 0) { + errBuffer.append("推送SAP异常:").append("\n"); + errBuffer.append(sendSap); + // new SAPMessageUtil("", "s:\n" + errBuffer.toString()); + } + if (sendMom.length() > 0) { + errBuffer.append("推送MOM异常:").append("\n"); + errBuffer.append(sendMom); + } +// if(errBuffer.length()>0) { +// new SAPMessageUtil("", "推送结果异常:\n" + errBuffer.toString()); +// } + return errBuffer; + } + + public StringBuffer sendSap(String url, String wsdlString, String txtPath) throws IOException { + + StringBuffer errBuffer = new StringBuffer(""); + 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") || 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(); + Response response = client.newCall(request).execute(); +// Document document = null; + + try { + String string = response.body().string(); +// System.out.println("response.body().string()==>"+string); + 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 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) { + // Auto-generated catch block + e.printStackTrace(); + } + + return errBuffer; +// if(errBuffer.length()>0) { +// new SAPMessageUtil("", "BOM物料异常:\n" + errBuffer.toString()); +// } + } + + public String sendJsonHttpPost(String url, String xmlContent, String txtPath) { + + CloseableHttpClient httpclient = HttpClients.createDefault(); + String responseInfo = null; + try { + HttpPost httpPost = new HttpPost(url); + // 设置请求头部 + httpPost.setHeader("Content-Type", "application/xml"); + + // 设置请求体 + StringEntity entityReq = new StringEntity(xmlContent, StandardCharsets.UTF_8); + + if (url.contains("10.128.11.12")) { + httpPost.addHeader("Authorization", "Basic MTQyODI0Mjg2NDU2ODMwNzcxNDpkREF3TWpveE1EQXg="); +// http://10.128.11.12:7788/gateway/chint/bop-sync + } else { + httpPost.addHeader("Authorization", "Basic MTcxNDkwNTkyNTc2MjUzNTQyNjpkREF3TWpveE1EQXg="); + } +// + httpPost.setEntity(entityReq); + + CloseableHttpResponse response = httpclient.execute(httpPost); + HttpEntity entity = response.getEntity(); + int status = response.getStatusLine().getStatusCode(); + String string = EntityUtils.toString(entity); + System.out.println("MOM status:" + status + "responseInfo:" + string); + TXTUtil.writeTXT(txtPath, "----------------BOM传递MOM结果--------------"); + TXTUtil.writeTXT(txtPath, "MOM status:" + status); + TXTUtil.writeTXT(txtPath, "responseInfo:" + string); + TXTUtil.writeTXT(txtPath, "----------BOM传递MOM结果-----------"); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + httpclient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + return responseInfo; + } + + public StringBuffer sendMom(String url, String wsdlString, String txtPath) throws IOException { + + StringBuffer errBuffer = new StringBuffer(""); + if (!url.contains("http")) { + return errBuffer; + } + sendJsonHttpPost(url, wsdlString, txtPath); // "http://10.128.11.12:7788/gateway/chint/bop-sync" + + return errBuffer; + + } + +} diff --git a/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcFram.java b/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcFram.java new file mode 100644 index 0000000..df105c0 --- /dev/null +++ b/com.connor.chint.wuhan/src/com/connor/chint/yunpi/command/ZxjcFram.java @@ -0,0 +1,224 @@ +package com.connor.chint.yunpi.command; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.BorderFactory; +import javax.swing.DefaultCellEditor; +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; + +//import com.connor.chint.sap2.sap_zy.SAPZYDialog; +import com.connor.chint.sap2.util.CheckBoxTableHeaderRenderer; +import com.connor.chint.sap2.util.KUtil; +import com.connor.chint.sap2.util.ProgressBar; +import com.connor.chint.sap2.util.SAPUtil; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +/** + * =============================================================================== + * Copyright (c) 2012-2024 CONNOR Unpublished - All Rights Reserved + * =============================================================================== + * File description: + * + * ZxjcFram.java + * + * 装箱集成:用户选中项目点击菜单,武汉工厂-拆卸一览表下发 ,弹出产成品清单,供用户选择,选择完成后, 点击下发按钮,支持数据组织并调用装箱系统接口。 + * + * =============================================================================== + * DATE Name Description of Change + * + * 2024-4-18 lijh modify 添加了代码注释 + * + * =============================================================================== + */ +public class ZxjcFram extends AbstractAIFDialog { + /** + * + */ + private static final long serialVersionUID = 1L; + private ZxjcController controller; +// private AbstractAIFApplication app; + private TCSession session; + + public ZxjcFram(AbstractAIFApplication app) { + super(false); + this.controller = new ZxjcController(this, app); +// this.app = app; + this.session = (TCSession) app.getSession(); + } + + private JButton b_cel; + private JButton b_qr; + protected DefaultTableModel tm_part; + protected JTable t_part; + public static final String[] HEADER = new String[] { "", "序号", "站点", "柜号", "物料名称", "物料编码", "出厂编号", "图号", "产成品数量" }; + public static final int[] HEADERWIDTH = new int[] { 50, 60, 60, 60, 120, 180, 180, 100, 100 }; + + @Override + public void run() { + try { + // 获取组ID + controller.groupName = SAPUtil.getGroupID(session); + System.out.println("当前组:" + controller.groupName); + // dba用户不允许使用改功能 +// if (KUtil.isEmpty(controller.groupName) || controller.groupName.equalsIgnoreCase("dba")) { +// MessageBox.post(this, "当前登录组不可使用该功能", "", MessageBox.INFORMATION); +// KUtil.setByPass(false); +// return; +// } + + // 判断目标对象下是否存在产成品 + if (!controller.checkTargets()) { + MessageBox.post(this, "没有找到产成品信息", "", MessageBox.INFORMATION); + return; + } + + // controller.getSapState(); + } catch (Exception e) { + KUtil.setByPass(false); + MessageBox.post(this, "检查选择对象时发生错误:" + e.getMessage(), "", MessageBox.ERROR); + e.printStackTrace(); + return; + } + initUI(); + try { + controller.dialog = this; + for (int i = 0; i < controller.partList.size(); i++) { + // 获取产成品数据 + tm_part.addRow(controller.partList.get(i).getRowDataZxjc()); + } + // 设置出厂编号列可编辑 +// ZxjcCellEditor editor = new ZxjcCellEditor(ZxjcFram.this); +// t_part.getColumnModel().getColumn(6).setCellEditor(editor); + } catch (Exception e) { + MessageBox.post(this, "读取产成品信息时发生错误:" + e.getMessage(), "", MessageBox.ERROR); + e.printStackTrace(); + return; + } + showDialog(); + } + + private void initUI() { + this.setTitle("拆卸一览表下发"); + this.setPreferredSize(new Dimension(800, 400)); + this.setMinimumSize(new Dimension(750, 400)); + this.setLayout(new BorderLayout()); + this.add(BorderLayout.CENTER, getTablePanel()); + this.add(BorderLayout.SOUTH, getBtnPanel()); + addListeners(); + } + + private void addListeners() { + + b_qr.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + new Thread(new Runnable() { + @Override + public void run() { + try { + t_part.revalidate(); + t_part.repaint(); + // 组织数据传递 + ProgressBar pb = new ProgressBar(ZxjcFram.this, new Dimension(300, 50)); + pb.startProgress(); + pb.setText("正在传递"); + controller.sendZxjc(); + pb.disposeDialog(); + //发送成功弹窗 + MessageBox.post("发送成功!","提示",2); + ZxjcFram.this.dispose(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + }).start(); + } + }); + + b_cel.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + dispose(); + } + }); + } + + private JPanel getBtnPanel() { + JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 30, 5)); + + b_cel = new JButton("取消"); + b_qr = new JButton("确认"); + panel.add(b_qr); + panel.add(b_cel); + + return panel; + } + + private JPanel getTablePanel() { + JPanel panel = new JPanel(new BorderLayout()); + tm_part = new DefaultTableModel(); + t_part = new JTable(tm_part) { + /** + * + */ + private static final long serialVersionUID = 1L; + + @Override + public boolean isCellEditable(int row, int column) { + if (column == 0 || column == 6) { + return true; + } + return false; + } + + @Override + public Class getColumnClass(int column) { // 设置选择列(第三列)类型 + if (column == 0) { + return Boolean.class; + } + return super.getColumnClass(column); + } + }; + tm_part.setDataVector(null, HEADER); + t_part.getTableHeader().setReorderingAllowed(false); // 设置列不可移动,否则会发生类型转换错误(第三列) + this.t_part.setRowHeight(23); + + TableColumnModel colModel = this.t_part.getColumnModel(); + int colCnt = HEADERWIDTH.length; + colModel.getColumn(0).setMaxWidth(HEADERWIDTH[0]); + for (int i = 0; i < colCnt; i++) { + colModel.getColumn(i).setPreferredWidth(HEADERWIDTH[i]); + } + + this.t_part.getTableHeader().setDefaultRenderer(new CheckBoxTableHeaderRenderer(t_part, 0, false)); + this.t_part.getTableHeader().setBackground(Color.blue); + + // 设置出厂编号可编辑 + TableColumn editableColumn = t_part.getColumnModel().getColumn(6); // 获取第3列 + editableColumn.setCellEditor(new DefaultCellEditor(new JTextField())); + +// ZxjcCellEditor editor = new ZxjcCellEditor(ZxjcFram.this); +// t_part.getColumnModel().getColumn(6).setCellEditor(editor); + + JScrollPane scroll = new JScrollPane(t_part); + panel.add(BorderLayout.CENTER, scroll); + panel.setBorder(BorderFactory.createLoweredBevelBorder()); + return panel; + } + +}