20240820分发代码上传

master
李冬阳 10 months ago
parent f4b5b5cb20
commit 167f989baf

@ -51,5 +51,8 @@
<classpathentry kind="lib" path="lib/guava-31.1-jre.jar"/>
<classpathentry kind="lib" path="lib/hutool-all-5.8.8.jar"/>
<classpathentry kind="lib" path="lib/swingx-1.6.1.jar"/>
<classpathentry kind="lib" path="poi/axiom-api-1.2.7.jar"/>
<classpathentry kind="lib" path="poi/axis2-kernel-1.4.1.jar"/>
<classpathentry kind="lib" path="json_lib/jfxrt.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -79,7 +79,8 @@ Bundle-ClassPath: .,
poi/okhttp-2.7.4.jar,
poi/okio-1.13.0.jar,
lib/json-org.jar,
lib/commons-dbcp2-2.8.0.jar
lib/commons-dbcp2-2.8.0.jar,
json_lib/jfxrt.jar
Export-Package: com.connor.chint.sap2,
com.connor.chint.sap2.assignfactoryno,
com.connor.chint.sap2.bombuilder,

@ -31,7 +31,8 @@ bin.includes = plugin.xml,\
lib/mysql-connector-java-8.0.12.jar,\
poi/okhttp-2.7.4.jar,\
poi/okio-1.13.0.jar,\
lib/json-org.jar
lib/json-org.jar,\
json_lib/jfxrt.jar
src.includes = icons/,\
poi/jacob-1.20-x64.dll,\
poi/jacob-1.20-x86.dll,\

@ -64,6 +64,7 @@
<command name="自动更新型号和工作号" id="com.connor.chint.sap2.commands.SetPropertyCommand"/>
<command name="变压器采购清单" id="com.connor.chint.sap2.commands.PPartsReportCommand"/>
<command name="部件采购单BOM编制" id="com.chint.plm.modules.transformer.bomsetup.BomSetupCommand"/>
<command name="创建框架BOM" id="com.connor.chint.sap2.createKjBom.CreateKjBomCommand"/>
<!--中压设备-->
<command name="创建工程图" id="com.connor.chint.sap2.commands.CreateEDCommand"/>
<command name="申请项目产成品" id="com.connor.chint.sap2.commands.ZYProjectAppendixCommand#M008"/>
@ -111,7 +112,7 @@
<!--物料管理-->
<command name="物料编码申请" id="com.connor.chint.sap2.commands.MaterialNoCommand"/>
<command name="物料请购SAP" id="com.connor.chint.sap2.commands.WLQGSAPCommand"/>
<command name="自制件编码批量申请" id="com.connor.chint.sap2.commands.SelfMPartNoBatchCommand"/>
<command name="自制件编码批量申请" id="com.connor.chint.sap2.commands.SelfMPartNoBatchCommand"/><!--物料编码批量申请-->
<command name="工程图批量申请物料编码" id="com.connor.chint.sap2.commands.SelfMPartNoBatchCommand#GCT"/>
<command name="外购件编码批量申请" id="com.connor.chint.sap2.commands.SelfMPartNoBatchCommand#M007_2"/>
@ -306,6 +307,7 @@
<command name="项目计划管理" id="com.connor.chint.sap2.commands.OpenPiCommand"/>
<command name="互感器成本BOM导出" id="com.chint.plm.costbomreport.BomCostReportCmd"/>
<command name="创建RDM研发项目" id="com.chint.plm.rdmCreate.RdmCreateHandler"/>
</extension>
<extension point="org.eclipse.ui.handlers">
<handler commandId="com.connor.chint.sap2.commands.OpenPiCommand" class="com.connor.chint.sap2.KHandler"/>
@ -418,6 +420,7 @@
<handler commandId="com.connor.chint.sap2.commands.SetPropertyCommand" class="com.connor.chint.sap2.KHandler"/>
<handler commandId="com.connor.chint.sap2.commands.PPartsReportCommand" class="com.connor.chint.sap2.KHandler"/>
<handler commandId="com.chint.plm.modules.transformer.bomsetup.BomSetupCommand" class="com.connor.chint.sap2.KHandler"/>
<handler commandId="com.connor.chint.sap2.createKjBom.CreateKjBomCommand" class="com.connor.chint.sap2.KHandler"/>
<!--中压-->
<handler commandId="com.connor.chint.sap2.commands.SpecStatementCommand#M008_Part2" class="com.connor.chint.sap2.KHandler"/>
@ -621,6 +624,7 @@
<!--右键物料描述复制-->
<handler commandId="com.connor.chint.sap2.commands.CopyObjectDescCommand" class="com.connor.chint.sap2.KHandler"/>
<handler commandId="com.chint.plm.rdmCreate.RdmCreateHandler" class="com.chint.plm.rdmCreate.RdmCreateHandler"/>
</extension>
<extension point="org.eclipse.ui.bindings">
@ -675,6 +679,27 @@
</and>
</visibleWhen>
</command>
<command commandId = "com.chint.plm.rdmCreate.RdmCreateHandler" id = "com.chint.plm.rdmCreate.RdmCreateHandler">
<visibleWhen>
<and>
<or>
<reference definitionId="com.teamcenter.rac.ui.inMainPerspective"/>
<reference definitionId="com.teamcenter.rac.pse.inMainView"/>
</or>
<with
variable="rac_command_suppression">
<not>
<iterate
operator="or">
<equals
value="com.chint.plm.rdmCreate.RdmCreateHandler">
</equals>
</iterate>
</not>
</with>
</and>
</visibleWhen>
</command>
<command commandId="com.connor.chint.sap2.commands.OpenPiCommand" id="com.connor.chint.sap2.commands.OpenPiCommand">
<visibleWhen>
<and>
@ -2037,6 +2062,24 @@
</and>
</visibleWhen>
</command>
<!--
<command commandId = "com.connor.chint.sap2.createKjBom.CreateKjBomCommand" id = "com.connor.chint.sap2.menu.cgdexport">
<visibleWhen>
<and>
<with
variable="rac_command_suppression">
<not>
<iterate
operator="or">
<equals
value="com.connor.chint.sap2.createKjBom.CreateKjBomCommand">
</equals>
</iterate>
</not>
</with>
</and>
</visibleWhen>
</command>-->
</menuContribution>

@ -0,0 +1,135 @@
package com.chint.plm.rdmCreate;
import com.sun.javafx.util.Logging;
import com.teamcenter.rac.util.MessageBox;
import java.awt.Window;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.stage.Stage;
//import sun.util.logging.PlatformLogger;
public abstract class KFXPanel extends Application {
protected Scene scene;
protected KFXPanelController aifController;
protected Parent root;
protected String cssForm;
protected Window parentDialog;
static {
Platform.setImplicitExit(false);
// Logging.getCSSLogger().setLevel(Platform.class...STYLESHEET_CASPIAN....Level.OFF);
}
public KFXPanel(Window dialog, String fxmlName) {
setParentDialog(dialog);
initUI(fxmlName);
initData();
}
public KFXPanel(Window dialog, Class<?> c, String css) {
setParentDialog(dialog);
this.cssForm = c.getResource(css).toExternalForm();
initUI();
initData();
}
public void setParentDialog(Window dialog) {
this.parentDialog = dialog;
}
public Window getParentDialog() {
return this.parentDialog;
}
public Parent getRoot() {
return this.root;
}
public KFXPanelController getController() {
return this.aifController;
}
public Scene getScene() {
if (this.scene == null) {
this.scene = new Scene(this.root);
this.scene.setFill(null);
}
return this.scene;
}
public void initData() {
try {
this.aifController.initData(this);
} catch (Exception e) {
e.printStackTrace();
post(this.parentDialog, e.getMessage(), "", 1);
}
}
protected void initUI(String fxmlName) {
try {
FXMLLoader fxmlLoader = new FXMLLoader();
String resource = fxmlName;// "SearchSapResultPanel.fxml";
fxmlLoader.setLocation(getClass().getResource(resource));
this.root = (Parent) fxmlLoader.load();
this.aifController = (KFXPanelController) fxmlLoader.getController();
if (this.cssForm != null)
this.root.getStylesheets().add(this.cssForm);
} catch (Exception e) {
e.printStackTrace();
post(this.parentDialog, e.getMessage(), "", 1);
}
}
protected void initUI() {
try {
FXMLLoader fxmlLoader = new FXMLLoader();
String resource = "SearchSapResultPanel.fxml";
fxmlLoader.setLocation(getClass().getResource(resource));
this.root = (Parent) fxmlLoader.load();
this.aifController = (KFXPanelController) fxmlLoader.getController();
if (this.cssForm != null)
this.root.getStylesheets().add(this.cssForm);
} catch (Exception e) {
e.printStackTrace();
post(this.parentDialog, e.getMessage(), "", 1);
}
}
public static void post(Window dialog, final String msg, final String title, int msgType) {
if (dialog == null) {
Platform.runLater(new Runnable() {
public void run() {
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setTitle(title);
alert.setHeaderText("");
alert.setContentText(msg);
alert.showAndWait();
}
});
} else {
MessageBox.post(dialog, msg, title, msgType);
}
}
// protected Stage primaryStage;
public void start(Stage primaryStage) throws Exception {
initUI();
initData();
// this.primaryStage = primaryStage;
primaryStage.setScene(getScene());
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}

@ -0,0 +1,27 @@
package com.chint.plm.rdmCreate;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.layout.AnchorPane;
public abstract class KFXPanelController {
@FXML
protected AnchorPane coverPane;
public abstract void initData(KFXPanel paramKFXPanel) throws Exception;
public void setCoverVisible(final boolean visible) {
if (this.coverPane != null) {
Platform.runLater(new Runnable() {
public void run() {
KFXPanelController.this.coverPane.setVisible(visible);
}
});
try {
Thread.sleep(10L);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

@ -0,0 +1,29 @@
package com.chint.plm.rdmCreate;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.UIUtilities;
import javax.swing.JFrame;
public abstract class KFrame extends JFrame {
// protected KDialogController controller;
public KFrame() {
try {
// if (!this.controller.init())
// return;
initUI();
showFrame();
} catch (Exception e) {
e.printStackTrace();
MessageBox.post(this, e);
}
}
public void showFrame() {
pack();
UIUtilities.centerToScreen(this);
setVisible(true);
}
protected abstract void initUI() throws Exception;
}

@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<Pane fx:id="pane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="840.0" prefWidth="1270.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.chint.plm.rdmCreate.RdmCreateController">
<children>
<TitledPane fx:id="titlePane" animated="false" layoutY="-1.0" prefHeight="105.0" prefWidth="1272.0" text="创建研发项目">
<content>
<AnchorPane fx:id="anchorPane1" minHeight="0.0" minWidth="0.0" prefHeight="67.0" prefWidth="1270.0">
<children>
<GridPane fx:id="gridTop" layoutX="197.0" layoutY="18.0" prefHeight="49.0" prefWidth="839.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Button fx:id="cjButton" mnemonicParsing="false" onAction="#cjbutton" prefHeight="41.0" prefWidth="136.0" text="创建" GridPane.halignment="CENTER" />
<Button fx:id="gbxmButton" mnemonicParsing="false" onAction="#gbxmButton" prefHeight="43.0" prefWidth="135.0" text="关闭项目" GridPane.columnIndex="2" GridPane.halignment="CENTER" />
</children>
</GridPane>
</children>
</AnchorPane>
</content>
</TitledPane>
<Pane fx:id="pane1" layoutY="109.0" prefHeight="726.0" prefWidth="309.0">
<children>
<AnchorPane fx:id="anchorPane2" minHeight="0.0" minWidth="0.0" prefHeight="726.0" prefWidth="309.0">
<children>
<GridPane fx:id="grid" layoutX="20.0" layoutY="41.0" prefHeight="457.0" prefWidth="253.0">
<children>
<Label prefHeight="20.0" prefWidth="82.0" text="内部订单号" />
<Label text="项目定义" GridPane.rowIndex="1" />
<Label text="集团项目号" GridPane.rowIndex="2" />
<Label text="项目名称" GridPane.rowIndex="3" />
<Label text="项目经理" GridPane.rowIndex="4" />
<Label text="工厂" GridPane.rowIndex="5" />
<Label text="推送者" GridPane.rowIndex="6" />
<Label text="推送时间早于" GridPane.rowIndex="7" />
<Label text="推送时间晚于" GridPane.rowIndex="8" />
<Label text="状态" GridPane.rowIndex="9" />
<TextField fx:id="f0" GridPane.columnIndex="1" />
<TextField fx:id="f1" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="f2" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField fx:id="f3" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<TextField fx:id="f4" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<TextField fx:id="f6" GridPane.columnIndex="1" GridPane.rowIndex="6" />
<DatePicker fx:id="f7" GridPane.columnIndex="1" GridPane.rowIndex="7" />
<DatePicker fx:id="f8" GridPane.columnIndex="1" GridPane.rowIndex="8" />
<ComboBox fx:id="f5" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<ComboBox fx:id="f9" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="9" />
<Button fx:id="cxButton" mnemonicParsing="false" onAction="#cxButton" prefHeight="30.0" prefWidth="88.0" text="查询" GridPane.columnIndex="1" GridPane.rowIndex="11" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="122.0" minWidth="10.0" prefWidth="93.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="160.0" minWidth="10.0" prefWidth="160.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
</AnchorPane>
</children>
</Pane>
<Pane fx:id="pane2" layoutX="318.0" layoutY="108.0" prefHeight="733.0" prefWidth="949.0">
<children>
<AnchorPane fx:id="anchorPane3" minHeight="0.0" minWidth="0.0" prefHeight="726.0" prefWidth="949.0">
<children>
<ScrollPane fx:id="scrollpane" prefHeight="726.0" prefWidth="941.0">
<content>
<AnchorPane fx:id="anchorPane4" minHeight="0.0" minWidth="0.0" prefHeight="707.0" prefWidth="922.0">
<children>
<TableView fx:id="table" prefHeight="711.0" prefWidth="927.0" />
</children>
</AnchorPane>
</content>
</ScrollPane>
</children>
</AnchorPane>
</children>
</Pane>
</children>
</Pane>

@ -0,0 +1,200 @@
package com.chint.plm.rdmCreate;
import java.sql.Date;
import java.text.SimpleDateFormat;
import javafx.beans.property.BooleanProperty;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextArea;
public class RdmCreateBean {
private TextArea ordernumber = new TextArea();
private TextArea projectno = new TextArea();
private TextArea rdmprojectno = new TextArea();
private TextArea projectname = new TextArea();
private TextArea projectleader = new TextArea();
private TextArea factory = new TextArea();
private TextArea pushuser = new TextArea();
private TextArea pushdate = new TextArea();
private TextArea status = new TextArea();
private TextArea createdate = new TextArea();
private TextArea projectleaderid = new TextArea();
private TextArea pushuserid = new TextArea();
private CheckBox checkBox = new CheckBox();
public CheckBox getCheckBox() {
return checkBox;
}
public void setCheckBox(CheckBox checkBox) {
this.checkBox = checkBox;
}
public RdmCreateBean(String ordernumber, String projectno, String rdmprojectno, String projectname,
String projectleader, String factory, String pushuser, Date pushdate, String status, Date createdate,
String projectleaderid, String pushuserid) {
super();
this.checkBox.setSelected(false);
this.ordernumber.setText(ordernumber);
this.ordernumber.setEditable(false);
this.ordernumber.setPrefSize(200, 40);
this.projectno.setText(projectno);
this.projectno.setEditable(false);
this.projectno.setPrefSize(200, 40);
this.rdmprojectno.setText(rdmprojectno);
this.rdmprojectno.setEditable(false);
this.rdmprojectno.setPrefSize(200, 40);
this.projectname.setText(projectname);
this.projectname.setEditable(false);
this.projectname.setPrefSize(200, 40);
this.projectleader.setText(projectleader);
this.projectleader.setEditable(false);
this.projectleader.setPrefSize(200, 40);
this.factory.setText(factory);
this.factory.setEditable(false);
this.factory.setPrefSize(200, 40);
this.pushuser.setText(pushuser);
this.pushuser.setEditable(false);
this.pushuser.setPrefSize(200, 40);
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-M-dd");
this.pushdate.setText(sdf2.format(pushdate));
this.pushdate.setEditable(false);
this.pushdate.setPrefSize(200, 40);
this.status.setText(status);
this.status.setEditable(false);
this.status.setPrefSize(200, 40);
this.createdate.setText(sdf2.format(createdate));
this.createdate.setEditable(false);
this.createdate.setPrefSize(200, 40);
this.projectleaderid.setText(projectleaderid);
this.projectleaderid.setEditable(false);
this.projectleaderid.setPrefSize(200, 40);
this.pushuserid.setText(pushuserid);
this.pushuserid.setEditable(false);
this.pushuserid.setPrefSize(200, 40);
}
public void setOrdernumber(TextArea ordernumber) {
this.ordernumber = ordernumber;
}
public void setProjectno(TextArea projectno) {
this.projectno = projectno;
}
public void setRdmprojectno(TextArea rdmprojectno) {
this.rdmprojectno = rdmprojectno;
}
public void setProjectname(TextArea projectname) {
this.projectname = projectname;
}
public void setProjectleader(TextArea projectleader) {
this.projectleader = projectleader;
}
public void setFactory(TextArea factory) {
this.factory = factory;
}
public void setPushuser(TextArea pushuser) {
this.pushuser = pushuser;
}
public void setPushdate(TextArea pushdate) {
this.pushdate = pushdate;
}
public void setStatus(TextArea status) {
this.status = status;
}
public void setCreatedate(TextArea createdate) {
this.createdate = createdate;
}
public void setProjectleaderid(TextArea projectleaderid) {
this.projectleaderid = projectleaderid;
}
public void setPushuserid(TextArea pushuserid) {
this.pushuserid = pushuserid;
}
public TextArea getOrdernumber() {
return ordernumber;
}
public TextArea getProjectno() {
return projectno;
}
public TextArea getRdmprojectno() {
return rdmprojectno;
}
public TextArea getProjectname() {
return projectname;
}
public TextArea getProjectleader() {
return projectleader;
}
public TextArea getFactory() {
return factory;
}
public TextArea getPushuser() {
return pushuser;
}
public TextArea getPushdate() {
return pushdate;
}
public TextArea getStatus() {
return status;
}
public TextArea getCreatedate() {
return createdate;
}
public TextArea getProjectleaderid() {
return projectleaderid;
}
public TextArea getPushuserid() {
return pushuserid;
}
}

@ -0,0 +1,716 @@
package com.chint.plm.rdmCreate;
/**
* ===============================================================================
* Copyright (c) 2012-2024 CONNOR lijh. Unpublished - All Rights Reserved
* ===============================================================================
* File description:
*
* GZXQController.java
*
* ===============================================================================
* DATE Name Description of Change
*
* 2024-06-13 ljh create
* ===============================================================================
*/
import java.awt.Component;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.connor.chint.sap2.util.KUtil;
import com.connor.chint.sap2.util.SAPUtil;
import com.connor.chint.sap2.util.SqlUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentContextList;
import com.teamcenter.rac.kernel.TCComponentGroup;
import com.teamcenter.rac.kernel.TCComponentGroupType;
import com.teamcenter.rac.kernel.TCComponentProject;
import com.teamcenter.rac.kernel.TCComponentProjectType;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCComponentUserType;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.DatePicker;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.SplitPane;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
public class RdmCreateController extends KFXPanelController {
private Connection conn;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
private String PlanTime;//
private String lineSeparator = System.lineSeparator();// 换行符
private String[] prefs = null;
private double paneWidth;
private double paneHight;
@FXML
private Button cxButton;
@FXML
private TextField f0;
@FXML
private TextField f1;
@FXML
private AnchorPane anchorPane1;
@FXML
private TextField f2;
@FXML
private AnchorPane anchorPane2;
@FXML
private TextField f3;
@FXML
private TextField f4;
@FXML
private AnchorPane anchorPane3;
@FXML
private GridPane gridTop;
@FXML
private ComboBox<String> f5;
@FXML
private AnchorPane anchorPane4;
@FXML
private TextField f6;
@FXML
private TitledPane titlePane;
@FXML
private DatePicker f7;
@FXML
private DatePicker f8;
@FXML
private ComboBox<String> f9;
// @FXML
// private SplitPane splitPane;
@FXML
private Button cjButton;
@FXML
private GridPane grid;
@FXML
private Button gbxmButton;
@FXML
private Pane pane;
@FXML
private TableView<RdmCreateBean> table;
@FXML
private Pane pane1;
@FXML
private Pane pane2;
@FXML
private ScrollPane scrollpane;
// table的列
private TableColumn<String, TextField> tc_1 = new TableColumn<String, TextField>("序号");
private String f7Str;
private String f8Str;
private RdmCreateFrame frame;
protected AbstractAIFApplication app;
private TCSession session;
/**
*
*/
@Override
public void initData(KFXPanel paramKFXPanel) throws Exception {
// TODO Auto-generated method stub
//连接数据库 根据条件查询
this.app = AIFUtility.getCurrentApplication();
this.session = (TCSession) app.getSession();
this.prefs = session.getPreferenceService().getStringValues("CHINT_SRM_SQL_CONNECT");
System.out.println("===============开始连接tc数据库===============");
frame = (RdmCreateFrame) paramKFXPanel.getParentDialog();
addWindListener(frame);
initCombox();
frame.setMaximumSize(frame.getMaximumSize());
System.out.println("frame==>" + frame);
//初始化第一列勾选框
TableColumn checkboxColumn = new TableColumn<>("");
checkboxColumn.setCellValueFactory(new PropertyValueFactory<RdmCreateBean, TextArea>("checkBox"));
checkboxColumn.prefWidthProperty().bind(table.widthProperty().multiply(0.03));
table.getColumns().add(checkboxColumn);
//根据首选项初始化table
String[] chint_tcproject_result_rule = session.getPreferenceService().getStringValues("CHINT_TCPROJECT_RESULT_RULE");
if(chint_tcproject_result_rule == null || chint_tcproject_result_rule.length <= 0) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("提示");
alert.setHeaderText("请正确配置“CHINT_TCPROJECT_RESULT_RULE”首选项");
//alert.setContentText("导入完成");
alert.showAndWait();
return;
}
for (int i = 0; i < chint_tcproject_result_rule.length; i++) {
String[] split = chint_tcproject_result_rule[i].split(":");
if(split.length == 3) {
TableColumn tempColume = new TableColumn<RdmCreateBean, TextArea>(split[0]);
tempColume.setSortable(false);
tempColume.setCellValueFactory(new PropertyValueFactory<RdmCreateBean, TextArea>(split[1]));
tempColume.prefWidthProperty().bind(table.widthProperty().multiply(Double.parseDouble(split[2])));
table.getColumns().add(tempColume);
}
}
//设置文本框的高度
// jTextField1.setPrefHeight(30);
// 表格列绑定bean对象
// tc_1.setSortable(false);
// 列绑定bean对象
// tc_1.setCellValueFactory(new PropertyValueFactory<GzxqBean, TextArea>("xh"));
//设置table列宽度
// tc_1.prefWidthProperty().bind(table.widthProperty().multiply(0.04));
// //设置是否可编辑
// tc_1.setEditable(false);
// tc_2.setEditable(false);
// tc_3.setEditable(false);
// tc_4.setEditable(false);
// tc_5.setEditable(false);
// tc_6.setEditable(false);
// tc_7.setEditable(false);
// tc_8.setEditable(true);
// tc_9.setEditable(true);
// tc_10.setEditable(false);
//把代码中定义的table列加入tableView
// table.getColumns().addAll(tc_1, tc_2, tc_3, tc_4, tc_5, tc_6, tc_7,
// tc_8, tc_9, tc_10);
// tableView.setMaxHeight(pageNum);
}
// 初始化下拉框内容
private void initCombox() {
// TODO Auto-generated method stub
SqlUtil.SRMGetTCDataConnection(prefs);
String groupSql = "SELECT PNAME FROM ppom_group WHERE RPARENTU=(SELECT PUID FROM ppom_group WHERE PNAME='CHINT') order by PNAME ASC";
List<String> gcList = new ArrayList<String>();
ResultSet res;
try {
res = SqlUtil.read(groupSql);
//处理查询数据结果集
while (res.next()) {
gcList.add(res.getString(1));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
f5.getItems().addAll(gcList);
List<String> ztList = new ArrayList<String>();
ztList.add("未创建");
ztList.add("已创建");
ztList.add("已变更");
ztList.add("已更新");
ztList.add("已关闭");
f9.getItems().addAll(ztList);
}
/**
* @param frame
* @function
*/
private void addWindListener(RdmCreateFrame frame) {
// TODO Auto-generated method stub
frame.addComponentListener(new ComponentListener() {
@Override
public void componentShown(ComponentEvent e) {
// TODO Auto-generated method stub
}
/**
* pane
*/
@Override
public void componentResized(ComponentEvent e) {
// TODO Auto-generated method stub
// System.out.println("==============");
Component component = e.getComponent();
System.out.println("component==>" + component);
double width = component.getSize().getWidth();
double hight = component.getSize().getHeight();
paneWidth = pane.getWidth();
paneHight = pane.getHeight();
double widthxs = width/paneWidth;
double hightxs = hight/paneHight;
System.out.println("Widthxs============"+widthxs);
// // double width = primaryStage.getWidth();
System.out.println("width=============>" + width);
System.out.println("pane==========="+pane.getWidth());
pane.setPrefWidth(width * 0.98);
pane.setPrefHeight(hight * 0.98);
System.out.println("pane==========="+pane.getWidth());
//anchorPane1.setPrefWidth(width * 0.98);
//anchorPane2.setPrefWidth(width * 0.98);
System.out.println("anchorPane3==========="+anchorPane3.getWidth());
anchorPane3.setPrefWidth(anchorPane3.getWidth() * widthxs);
anchorPane3.setPrefHeight(anchorPane3.getHeight() * hightxs);
System.out.println("anchorPane3==========="+anchorPane3.getWidth());
anchorPane4.setPrefWidth(anchorPane4.getWidth() * widthxs);
anchorPane4.setPrefHeight(anchorPane4.getHeight() * hightxs);
System.out.println("scrollpane==========="+scrollpane.getWidth());
scrollpane.setPrefWidth(scrollpane.getWidth() * widthxs);
scrollpane.setPrefHeight(scrollpane.getHeight() * hightxs);
System.out.println("scrollpane==========="+scrollpane.getWidth());
System.out.println("pane2==========="+pane2.getWidth());
pane2.setPrefWidth(pane2.getWidth() * widthxs);
pane2.setPrefHeight(pane2.getHeight() * hightxs);
System.out.println("pane2==========="+pane2.getWidth());
if(width == 1308.0) {
titlePane.setPrefWidth(width * 1.0);
System.out.println("111111111111111111111111111111111111111111111111111111111111111111111");
}else {
titlePane.setPrefWidth(width * 0.929);
}
//grid.setPrefWidth(width * 0.98);
//gridTop.setPrefWidth(width * 0.98);
System.out.println("table==========="+table.getWidth());
table.setPrefWidth(table.getWidth() * widthxs);
table.setPrefHeight(table.getHeight() * hightxs);
System.out.println("table==========="+table.getWidth());
// bpane.setPrefWidth(width * 0.98);
// titlePaneCondition.setPrefWidth(width * 0.98);
// titlePaneResult.setPrefWidth(width * 0.98);
// gridPaneCondition.setPrefWidth(width * 0.97);
// gridPaneCondition.setPrefWidth(width * 0.97);
// tablePane.setPrefWidth(width * 0.98);
// tableView.setPrefWidth(width * 0.97);
// gridPaneResult.setPrefWidth(width * 0.97);
// refTable.setPrefWidth(width * 0.97);
}
@Override
public void componentMoved(ComponentEvent e) {
// TODO Auto-generated method stub
}
@Override
public void componentHidden(ComponentEvent e) {
// TODO Auto-generated method stub
}
});
}
//创建项目
@FXML
void cjbutton(ActionEvent event) throws Exception {
SqlUtil.SRMGetTCDataConnection(prefs);
ObservableList<RdmCreateBean> items = table.getItems();
int count = 0;
TCComponentUserType userType = (TCComponentUserType)this.session
.getTypeComponent("User");
TCComponentGroupType groupType = (TCComponentGroupType) session.getTypeComponent("Group");
StringBuffer sbInfo = new StringBuffer();
for (int i = 0; i < items.size(); i++) {
RdmCreateBean rdmCreateBean = items.get(i);
boolean selected = rdmCreateBean.getCheckBox().isSelected();
if(selected) {
count++;
List<TCComponentUser> members = new ArrayList();//指派的用户id
List<String> exitUserName = new ArrayList();//存在的用户名称
List<String> notExitUserName = new ArrayList();//不存在的用户名称
//判断tc是否已经创建过项目
Map<String, String> field = new HashMap<String, String>();
String ordernumber = rdmCreateBean.getOrdernumber().getText();
String id = ordernumber+"-"+rdmCreateBean.getProjectno().getText();
System.out.println("id="+id);
field.put("ordernumber", ordernumber);
TCComponentContextList contxt = KUtil.query(session, "chint_query_tcproject", field);
if(contxt == null || contxt.getListCount() == 0) {
//去数据库中查询要指派的人员
String selectSql = "SELECT USERID,\"USER\",FACTORY FROM CHINT_RDM_PROJECT_PDTTEAMS WHERE ordernumber ='"+ordernumber+"'";
System.out.println("selectSql==="+selectSql);
ResultSet res = SqlUtil.read(selectSql);
//处理查询数据结果集
while (res.next()) {
TCComponentUser userT = null;
try {
System.out.println("res.getString(1)=="+res.getString(1));
userT = userType.find(res.getString(1));
}catch (Exception e) {
// TODO: handle exception
notExitUserName.add(res.getString(2));//找不到人报错
System.out.println("res.getString(2)=="+res.getString(2));
continue;
}
if (userT != null) {
// TCComponentGroup group = groupType.find(res.getString(3));
// KUtil.setByPass(true);
// userT.setDefaultGroup(group);
// KUtil.setByPass(false);
members.add(userT);
exitUserName.add(res.getString(2));
System.out.println("111");
}else {
notExitUserName.add(res.getString(2));
System.out.println("222");
}
}
// //如果没有人可以指派 会报错
// if(members.size() <= 0) {
// sbInfo.append("项目创建失败:内部订单号:"+ordernumber+"项目ID为"+id+lineSeparator);
// sbInfo.append("失败原因:当前创建人,要加到项目小组成员并设置成项目管理员。"+lineSeparator);
// sbInfo.append(lineSeparator);
// continue;
// }
TCComponentProjectType projecttype = (TCComponentProjectType) session
.getTypeComponent("TC_Project");
TCComponentProject proj=null;
TCComponentUser user = session.getUser();
// proj = projecttype.create(id, id, "",
// new TCComponent[] {user}, user, new TCComponentUser[] {user});
//把自己加进去
members.add(user);
exitUserName.add(session.getUserName());
proj = projecttype.create(id,
id, "",
(TCComponent[])members.toArray(
new TCComponent[members.size()]), user,//把人员指派到项目
(TCComponentUser[])members.toArray(
new TCComponentUser[members.size()]));
//设置属性
proj.setProperties(new String[] {"zt2_ordernumber","zt2_projectno","zt2_rdmprojectno","zt2_projectname","zt2_projectleader","zt2_projectleaderid","zt2_factory","zt2_pushuser","zt2_pushuserid"},
new String[] {rdmCreateBean.getOrdernumber().getText(),rdmCreateBean.getProjectno().getText(),rdmCreateBean.getRdmprojectno().getText(),rdmCreateBean.getProjectname().getText(),rdmCreateBean.getProjectleader().getText(),rdmCreateBean.getProjectleaderid().getText(),rdmCreateBean.getFactory().getText(),rdmCreateBean.getPushuser().getText(),rdmCreateBean.getPushuserid().getText()});
String pushDate = rdmCreateBean.getPushdate().getText();
if(pushDate != null && !pushDate.isEmpty()) {
Date parse = sdf.parse(pushDate);
proj.setDateProperty("zt2_pushdate", parse);
}
//创建完项目 修改数据库中的状态
String updateSql = "UPDATE CHINT_RDM_PROJECT SET status = '已创建' WHERE ordernumber = '"+rdmCreateBean.getOrdernumber().getText()+"'";
System.out.println("updateSql==="+updateSql);
try {
SqlUtil.update(updateSql);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
//输出项目创建的信息
sbInfo.append("项目已创建完成:内部订单号:"+ordernumber+"项目ID为"+id+lineSeparator);
if(exitUserName.size() > 0) {
sbInfo.append("人员已指派");
for (int j = 0; j < exitUserName.size(); j++) {
sbInfo.append(exitUserName.get(j)+",");
}
}
if(notExitUserName.size() > 0) {
sbInfo.append("人员未指派");
for (int j = 0; j < notExitUserName.size(); j++) {
sbInfo.append(notExitUserName.get(j)+",");
}
}
sbInfo.append(lineSeparator);
sbInfo.append(lineSeparator);
}else {
//获取查询查到的项目
TCComponentProject proj = (TCComponentProject)contxt.get(0).getComponent();
//设置属性
proj.setProperties(new String[] {"zt2_ordernumber","zt2_projectno","zt2_rdmprojectno","zt2_projectname","zt2_projectleader","zt2_projectleaderid","zt2_factory","zt2_pushuser","zt2_pushuserid"},
new String[] {rdmCreateBean.getOrdernumber().getText(),rdmCreateBean.getProjectno().getText(),rdmCreateBean.getRdmprojectno().getText(),rdmCreateBean.getProjectname().getText(),rdmCreateBean.getProjectleader().getText(),rdmCreateBean.getProjectleaderid().getText(),rdmCreateBean.getFactory().getText(),rdmCreateBean.getPushuser().getText(),rdmCreateBean.getPushuserid().getText()});
String pushDate = rdmCreateBean.getPushdate().getText();
if(pushDate != null && !pushDate.isEmpty()) {
Date parse = sdf.parse(pushDate);
proj.setDateProperty("zt2_pushdate", parse);
}
//创建完项目 修改数据库中的状态
String updateSql = "UPDATE CHINT_RDM_PROJECT SET status = '已更新' WHERE ordernumber = '"+rdmCreateBean.getOrdernumber().getText()+"'";
System.out.println("updateSql==="+updateSql);
sbInfo.append("项目已更新完成:内部订单号:"+ordernumber+"项目ID为"+id+lineSeparator);
sbInfo.append(lineSeparator);
try {
SqlUtil.update(updateSql);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
}
if(count == 0) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("提示");
alert.setHeaderText("请勾选数据!");
//alert.setContentText("导入完成");
alert.showAndWait();
}else {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("提示");
alert.setHeaderText(sbInfo.toString());
//alert.setContentText("导入完成");
alert.showAndWait();
}
}
//关闭项目
@FXML
void gbxmButton(ActionEvent event) throws SQLException {
SqlUtil.SRMGetTCDataConnection(prefs);
ObservableList<RdmCreateBean> items = table.getItems();
int count = 0;
for (int i = 0; i < items.size(); i++) {
RdmCreateBean rdmCreateBean = items.get(i);
boolean selected = rdmCreateBean.getCheckBox().isSelected();
if(selected) {
String updateSql = "UPDATE CHINT_RDM_PROJECT SET status = '已关闭' WHERE ordernumber = '"+rdmCreateBean.getOrdernumber().getText()+"'";
System.out.println("updateSql==="+updateSql);
try {
SqlUtil.update(updateSql);
count++;
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
if(count == 0) {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("提示");
alert.setHeaderText("请勾选数据!");
//alert.setContentText("导入完成");
alert.showAndWait();
}else {
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("提示");
alert.setHeaderText("项目关闭完成!");
//alert.setContentText("导入完成");
alert.showAndWait();
}
}
//查询
@FXML
void cxButton(ActionEvent event) throws ParseException {
SqlUtil.SRMGetTCDataConnection(prefs);
f7Str = f7.getEditor().getText();
f8Str = f8.getEditor().getText();
String selectedFactory = f5.getSelectionModel().getSelectedItem();
String selectedStatus = f9.getSelectionModel().getSelectedItem();
ArrayList fieldList = new ArrayList();
System.out.println("======================清除");
table.getItems().clear();
List<RdmCreateBean> quotations = new ArrayList<RdmCreateBean>();
String factory = "";
// 拼接查询语句
String sql = "select ordernumber,projectno,rdmprojectno,projectname,projectleader,factory,pushuser,pushdate,status,createdate,projectleaderid,pushuserid from CHINT_RDM_PROJECT where 1=1 ";
if(f0.getText()!=null && !"".equals(f0.getText().trim())) {
sql += "and ordernumber = \'" + f0.getText() +"\'";
}
if(f1.getText()!=null && !"".equals(f1.getText().trim())) {
sql += "and projectno = \'" + f1.getText() +"\'";
}
if(f2.getText()!=null && !"".equals(f2.getText().trim())) {
sql += "and rdmprojectno = \'" + f2.getText() +"\'";
}
if(f3.getText()!=null && !"".equals(f3.getText().trim())) {
sql += "and projectname = \'" + f3.getText() +"\'";
}
if(f4.getText()!=null && !"".equals(f4.getText().trim())) {
sql += "and projectleader = \'" + f4.getText() +"\'";
}
if(selectedFactory != null && !selectedFactory.isEmpty()) {
sql += "and factory like \'%" + selectedFactory +"%\'";
}
if(f6.getText()!=null && !"".equals(f6.getText().trim())) {
sql += "and pushuser = \'" + f6.getText() +"\'";
}
if(f7Str !=null && !"".equals(f7Str)) {
Date date = sdf.parse(f7Str);
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
fieldList.add(sqlDate);
//sql += "and pushdate <= \'" + sqlDate +"\'";
sql += "and pushdate <= ?";
}
if(f8Str !=null && !"".equals(f8Str)) {
Date date = sdf.parse(f8Str);
java.sql.Date sqlDate = new java.sql.Date(date.getTime());
fieldList.add(sqlDate);
//sql += "and pushdate >= \'" + sqlDate +"\'";
sql += "and pushdate >= ?";
}
if(selectedStatus != null && !selectedStatus.isEmpty()) {
sql += "and status = \'" + selectedStatus +"\'";
}
System.out.println("sql:"+sql);
try {
ResultSet res = SqlUtil.read(sql,fieldList.toArray(new java.sql.Date[0]));
//处理查询数据结果集
while (res.next()) {
RdmCreateBean rdmCreateBean = new RdmCreateBean(
res.getString("ordernumber") != null ? res.getString("ordernumber") : "",
res.getString("projectno") != null ? res.getString("projectno") : "",
res.getString("rdmprojectno") != null ? res.getString("rdmprojectno") : "",
res.getString("projectname") != null ? res.getString("projectname") : "",
res.getString("projectleader") != null ? res.getString("projectleader") : "",
res.getString("factory") != null ? res.getString("factory") : "",
res.getString("pushuser") != null ? res.getString("pushuser") : "",
res.getDate("pushdate"),
res.getString("status") != null ? res.getString("status") : "",
res.getDate("createdate"),
res.getString("projectleaderid") != null ? res.getString("projectleaderid") : "",
res.getString("pushuserid") != null ? res.getString("pushuserid") : "");
System.out.println("rdmCreateBean==="+rdmCreateBean);
quotations.add(rdmCreateBean);
}
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
if(quotations.size() > 0) {
//组织界面数据
ObservableList<RdmCreateBean> data = FXCollections.observableArrayList(quotations);
table.getItems().clear();
table.setItems(data);
}else {
//未查到数据
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("提示");
alert.setHeaderText("未查到数据!");
//alert.setContentText("导入完成");
alert.showAndWait();
}
}
}

@ -0,0 +1,25 @@
package com.chint.plm.rdmCreate;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javafx.embed.swing.JFXPanel;
public class RdmCreateFrame extends KFrame {
public RdmCreateFrame() {
super();
}
@Override
protected void initUI() throws Exception {
this.setTitle("´´½¨RDMÑз¢ÏîÄ¿");
this.setLayout(new BorderLayout());
this.setPreferredSize(new Dimension(1300, 900));
JFXPanel panel = new JFXPanel();
panel.setScene(new RdmCreatePanel(this).getScene());
this.add(BorderLayout.CENTER, panel);
}
}

@ -0,0 +1,79 @@
package com.chint.plm.rdmCreate;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.HashMap;
import org.apache.log4j.chainsaw.Main;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import com.connor.chint.sap2.util.SAPUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
/**
*
* @author admin
* 2023/11/16
*/
public class RdmCreateHandler extends AbstractHandler{
@Override
public Object execute(ExecutionEvent arg0) {
// TODO Auto-generated method stub
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession)app.getSession();
try {
new Thread() {
@Override
public void run() {
// NewJFrame newJFrame = new NewJFrame(session);
// int width2 = newJFrame.getWidth();
// int height2 = newJFrame.getHeight();
// Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸
// int screenWidth = screenSize.width; // 获取屏幕宽度
// int screenHeight = screenSize.height; // 获取屏幕高度
// int x = (screenWidth - width2) / 2; // 计算Frame的左上角x坐标
// int y = (screenHeight - height2) / 2; // 计算Frame的左上角y坐标
// newJFrame.setTitle("工装需求查询");
// // this.getContentPane().setBackground(Color.red);
// newJFrame.getContentPane().setBackground(new java.awt.Color(255, 255, 255));
// newJFrame.setSize(1240, height2); // 设置Frame的大小
// newJFrame.setLocation(x, y); // 设置Frame的位置
// newJFrame.setResizable(false);
// newJFrame.setDefaultCloseOperation(2); // 设置窗口关闭时的默认操作
// newJFrame.setVisible(true);
String groupID = "";
try {
groupID = SAPUtil.getGroupID(session);
} catch (TCException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("groupID==="+groupID);
//Project Administration
if(!groupID.equals("Project Administration")) {
MessageBox.post("请切换至项目管理组执行此功能。", "提示", MessageBox.INFORMATION);
return;
}
new RdmCreateFrame();
}
}.start();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void main(String[] args) {
new RdmCreateFrame();
}
}

@ -0,0 +1,13 @@
package com.chint.plm.rdmCreate;
import java.awt.Window;
public class RdmCreatePanel extends KFXPanel {
public RdmCreatePanel(Window dialog) {
super(dialog, "RdmCreate.fxml");
// TODO Auto-generated constructor stub
}
}

@ -0,0 +1,40 @@
package com.connor.chint.sap2.createKjBom;
import java.util.Objects;
import com.teamcenter.rac.kernel.TCComponentBOMLine;
public class BomBean {
String revName;
TCComponentBOMLine bomLine;
public BomBean(String revName, TCComponentBOMLine bomLine) {
super();
this.revName = revName;
this.bomLine = bomLine;
}
@Override
public int hashCode() {
return Objects.hash(revName);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BomBean other = (BomBean) obj;
return other.revName.contains(revName);
}
public BomBean(String revName) {
super();
this.revName = revName;
}
@Override
public String toString() {
return "BomBean [revName=" + revName + ", bomLine=" + bomLine + "]\n";
}
}

@ -0,0 +1,34 @@
package com.connor.chint.sap2.createKjBom;
public class CBean {
String cId;
String folderName;
String piName;
public String getcId() {
return cId;
}
public void setcId(String cId) {
this.cId = cId;
}
public String getFolderName() {
return folderName;
}
public void setFolderName(String folderName) {
this.folderName = folderName;
}
public String getPiName() {
return piName;
}
public void setPiName(String piName) {
this.piName = piName;
}
public CBean(String cId, String folderName, String piName) {
super();
this.cId = cId;
this.folderName = folderName;
this.piName = piName;
}
}

@ -0,0 +1,42 @@
package com.connor.chint.sap2.createKjBom;
/**
* @copyRight
* @author E-mail:hub@connor.net.cn
* @date 2017-7-3 11:47:03
* @version v1.0
* @parameter
* @since
* @return
*/
public class ClassProperty {
private int propertyID;
private String value;
public ClassProperty() {
}
public ClassProperty(int propertyID, String value) {
this.propertyID = propertyID;
this.value = value;
}
public int getPropertyID() {
return propertyID;
}
public void setPropertyID(int propertyID) {
this.propertyID = propertyID;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

@ -0,0 +1,58 @@
package com.connor.chint.sap2.createKjBom;
import java.util.ArrayList;
import java.util.List;
import com.connor.chint.sap2.KCommand;
import com.connor.chint.sap2.util.ChintPreferenceUtil;
import com.connor.chint.sap2.util.SAPUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class CreateKjBomCommand extends KCommand {
// private boolean top = true;
// private TCComponentBOMLine line;
public CreateKjBomCommand(AbstractAIFApplication app, String commandId, String actionInfo) {
super(app, commandId, actionInfo);
// InterfaceAIFComponent targetComponent = app.getTargetComponent();
try {
TCSession session = (TCSession)app.getSession();
String groupID = SAPUtil.getGroupID(session);//
String[] prefs = ChintPreferenceUtil.getPreferences("CHINT_kjbomTemp", session);
List<KjBean> kjList = new ArrayList<KjBean>();
for(String pref : prefs) {
// 1ZDB300000P-xxx|1ZDB300000P=2-组件布置图;1ZDB400000T=3-铁心图纸&H铁心
if(!pref.startsWith(groupID))
continue;
String[] split = pref.substring(groupID.length() + 1).split("\\|");
String kjBomId = split[0];
KjBean bean = new KjBean(kjBomId);
String[] split2 = split[1].split(";");
for(String s : split2) {
String[] split3 = s.split("=");
if(split3[1].contains("&")) {
String[] split4 = split3[1].split("&");
CBean cb = new CBean(split3[0],split4[0],split4[1]);
bean.cbeans.add(cb);
}else {
CBean cb = new CBean(split3[0],split3[1],"");
bean.cbeans.add(cb);
}
}
kjList.add(bean);
}
if(kjList.size() == 0) {
MessageBox.post("首选项中未找到配置,请登陆正确组", "", MessageBox.WARNING);
return;
}
this.setRunnable(new KjBomDialog(app, "", kjList));
}catch(Exception e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,28 @@
package com.connor.chint.sap2.createKjBom;
import java.util.ArrayList;
import java.util.List;
public class KjBean {
public String kjBs;
public String kjbomId;
public List<CBean> cbeans = new ArrayList<CBean>();
public String getKjbomId() {
return kjbomId;
}
public void setKjbomId(String kjbomId) {
this.kjbomId = kjbomId;
}
public KjBean(String kjbomId) {
super();
this.kjbomId = kjbomId;
String[] split = kjbomId.split("-");
kjBs = split[1];
}
@Override
public String toString() {
return kjbomId;
}
}

@ -0,0 +1,172 @@
package com.connor.chint.sap2.createKjBom;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import com.connor.chint.sap2.util.KUtil;
import com.connor.chint.sap2.util.MyProgressBarCompent;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.util.MessageBox;
public class KjBomDialog extends AbstractAIFDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
private List<KjBean> kjList;
// private AbstractAIFApplication app;
private KjController controller;
public KjBomDialog(AbstractAIFApplication app, String actionInfo,List<KjBean> beanList) {
// Auto-generated constructor stub
super(false);
// KUtil.setByPass(true);
// this.app = app;
this.kjList = beanList;
this.controller = new KjController(app);
}
@Override
public void run() {
// Auto-generated method stub
try {
if (!controller.checkProject()) {
MessageBox.post(this, "请选择项目文件夹对象", "", MessageBox.INFORMATION);
return;
}
initUI();
showDialog();
/*
* if(!controller.isAllHave) { MessageBox.post(this,
* "项目中"+controller.name+"方案未同步WBS,请手动执行", "",MessageBox.INFORMATION); }else {
* b_syn.setVisible(false); }
*/
} catch (Exception e) {
MessageBox.post(this, "申请方案编码时发生错误:" + e.getMessage(), "", MessageBox.ERROR);
e.printStackTrace();
return;
}
}
private JButton okButton;
private JButton celButton;
private JComboBox<KjBean> kjCombox;
public void initUI() {
this.setTitle("创建框架BOM");
this.setPreferredSize(new Dimension(400,150));
JPanel p1 = new JPanel(new BorderLayout());
p1.setBorder(new TitledBorder(new EtchedBorder(), "框架BOM模板"));
kjCombox = new JComboBox<KjBean>();
for(KjBean bean:kjList) {
kjCombox.addItem(bean);
}
p1.add(kjCombox);
JPanel rootPanel = new JPanel(new FlowLayout());
this.okButton = new JButton("确认");
this.celButton = new JButton("取消");
rootPanel.add(okButton);
rootPanel.add(celButton);
this.setLayout(new BorderLayout());
this.add(p1, BorderLayout.NORTH);
this.add(rootPanel, BorderLayout.CENTER);
// dialog.add(tablePanel, BorderLayout.CENTER);
this.add(rootPanel, BorderLayout.SOUTH);
this.pack();
this.setLocationRelativeTo(null);
this.setVisible(true);
addListeners();
}
private void addListeners() {
// Auto-generated method stub
celButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Auto-generated method stub
dispose();
}
});
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Auto-generated method stub
//开始创建框架BOM
//1.遍历原有框架BOM获取项目代号 、 检查项目结构文件夹、检查id是否唯一
//2.根据项目找到组件布置图 拆分BOM
//3.根据云派信息转换所有权
new Thread() {
@Override
public void run() {
MyProgressBarCompent comp = null;
KUtil.setByPass(true);
try {
comp = new MyProgressBarCompent("", "正在创建框架BOM......");
int selectedIndex = kjCombox.getSelectedIndex();
KjBean kjBean = kjList.get(selectedIndex);
StringBuilder build = new StringBuilder("");
String tempId = kjBean.getKjbomId();
boolean checkFolder = controller.checkFolder(tempId, kjBean, build);
if(!checkFolder) {
comp.setVisible(false);
dispose();
MessageBox.post(build.toString(), "",2);
return;
}
if(controller.byqCCPFromProject.size()>1) {
Object[] options = {"是","否"};
int response = JOptionPane.showOptionDialog(null, "项目产成品存在多台变压器,请确认是否为同一工程图号", "选择",JOptionPane.YES_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if(response == -1 || response==1)
{
return;
}
}
// List<CBean> cbeans = kjBean.cbeans;
boolean createKjBom = controller.createKjBom(kjBean,comp);
comp.setVisible(false);
if(!createKjBom) {
dispose();
return;
}else {
dispose();
MessageBox.post("框架BOM创建完成。", "提示",2);
}
} catch (Exception e1) {
// Auto-generated catch block
e1.printStackTrace();
}finally {
KUtil.setByPass(false);
}
if(comp!=null) {
comp.setVisible(false);
}
dispose();
}
}.start();
}
});
}
}

@ -0,0 +1,864 @@
package com.connor.chint.sap2.createKjBom;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.JOptionPane;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.connor.chint.sap2.util.BomToSapUtil;
import com.connor.chint.sap2.util.ChintPreferenceUtil;
import com.connor.chint.sap2.util.KUtil;
import com.connor.chint.sap2.util.MyProgressBarCompent;
import com.connor.chint.sap2.util.SAPUtil;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
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.TCAccessControlService;
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.TCComponentContextList;
import com.teamcenter.rac.kernel.TCComponentFolder;
import com.teamcenter.rac.kernel.TCComponentGroup;
import com.teamcenter.rac.kernel.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCComponentRevisionRule;
import com.teamcenter.rac.kernel.TCComponentUser;
import com.teamcenter.rac.kernel.TCPreferenceService;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.kernel.TCTypeService;
import com.teamcenter.rac.ui.common.RACUIUtil;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSAllLevelsOutput;
import com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSData;
import com.teamcenter.services.rac.structuremanagement._2014_10.Structure.CloneStructureInputInfo;
import com.teamcenter.services.rac.structuremanagement._2014_10.Structure.CloneStructureResponse;
import com.teamcenter.services.rac.structuremanagement._2014_10.Structure.CloneStructureSaveAsIn;
public class KjController {
private AbstractAIFApplication app;
private TCSession session;
private TCComponent project;
private String wbsNo = "";
private String projectDh = "";
private String projectId = "";
//存放已经存在的框架BOM的ID
Map<TCComponentItemRevision,TCComponentItem> oldkjIdMap = new HashMap<TCComponentItemRevision,TCComponentItem>();
//存放框架BOM对应的另存ID
Map<TCComponentItemRevision,String> kjIdMap = new HashMap<TCComponentItemRevision,String>();
private List<TCComponentBOMLine> copyLines = new ArrayList<TCComponentBOMLine>();
private String kjBs;
// public
// private TCComponentItemType ccomponentitemtype;
Map<String, String> idName = new HashMap<String, String>();
//存放 ID-文件夹
private Map<String, TCComponentFolder> fMap = new HashMap<>();
private Map<String, TCComponentUser> nameUser = new HashMap<>();
private TCComponentItem tqqgdItem;
protected List<TCComponentItemRevision> byqCCPFromProject;
public KjController(AbstractAIFApplication app) {
// Auto-generated constructor stub
this.app = app;
this.session = (TCSession) app.getSession();
}
public boolean checkProject() throws Exception {
InterfaceAIFComponent target = app.getTargetComponent();
if (target == null || !(target instanceof TCComponent)) {
return false;
}
String type = target.getType();
if (type.equals("ZT2_ProjectItem")) {
project = (TCComponent) target;
projectId = project.getStringProperty("item_id");
projectDh = project.getProperty("zt2_ProjectCode");
wbsNo = project.getProperty("zt2_WBSNo");
System.out.println("WBS号:" + wbsNo);
return true;
}
return false;
}
protected boolean checkFolder(String kjBomId, KjBean kjBean, StringBuilder errBuff) throws Exception {
boolean flag = true;
try {
//获取首选项里的文件夹名称、判断当前项目是否存在
fMap.clear();
Map<String, TCComponentFolder> fodlers = new HashMap<>();
TCComponentFolder xmzxFolder = KUtil.getXMZXFolderFromProject(project);
byqCCPFromProject = getByqCCPFromProject(project, session);
AIFComponentContext[] childFolders = xmzxFolder.getChildren();
TCComponentFolder bztFolder = null;
TCComponentFolder dcsjFolder = null;
for(AIFComponentContext context : childFolders) {
InterfaceAIFComponent c = context.getComponent();
if(c instanceof TCComponentFolder) {
String cName = c.getProperty("object_name");
if(cName.equals("2-组件布置图")) {
bztFolder = (TCComponentFolder)c;
}else if(cName.equals("1-电磁设计")) {
dcsjFolder = (TCComponentFolder)c;
}
fodlers.put(cName, (TCComponentFolder)c);
}
}
if(bztFolder!=null) {
AIFComponentContext[] children = bztFolder.getChildren();
for(AIFComponentContext cont : children) {
InterfaceAIFComponent component = cont.getComponent();
String type = component.getType();
if(type.equals("ZT2_Requisition")) {
tqqgdItem = (TCComponentItem)component;
}
}
}
TCComponentItem dcsjItem = null;;
if(dcsjFolder != null) {
AIFComponentContext[] children = dcsjFolder.getChildren();
for(AIFComponentContext cont : children) {
InterfaceAIFComponent component = cont.getComponent();
String type = component.getType();
if(type.equals("ZT2_MainMat")) {
dcsjItem = (TCComponentItem)component;
}
}
}
if(dcsjItem == null) {
errBuff.append("当前项目中未创建物主材采购单,不允许创建框架BOM.\n");
flag = false;
}else {
TCComponentItemRevision latestItemRevision = dcsjItem.getLatestItemRevision();
if(!KUtil.isTCM(latestItemRevision)){
errBuff.append("当前项目中主材采购单版本未发布,不允许创建框架BOM.\n");flag = false;
}
if(!KUtil.isTCM(KUtil.getRevBOMView(latestItemRevision))) {
errBuff.append("当前项目中主材采购单BOM视图版本未发布,不允许创建框架BOM.\n");flag = false;
}
}
if(tqqgdItem == null) {
errBuff.append("当前项目中未创建物料提前请购单,不允许创建框架BOM.\n");flag = false;
}else {
TCComponentItemRevision latestItemRevision = tqqgdItem.getLatestItemRevision();
if(!KUtil.isTCM(latestItemRevision)){
errBuff.append("当前项目中物料提前请购单版本未发布,不允许创建框架BOM.\n");flag = false;
}
if(!KUtil.isTCM(KUtil.getRevBOMView(latestItemRevision))) {
errBuff.append("当前项目中物料提前请购单BOM视图版本未发布,不允许创建框架BOM.\n");flag = false;
}
}
OkHttpClient client = new OkHttpClient();
String preference = ChintPreferenceUtil.getPreference("CHINT_PIUrl", session);
Request request = new Request.Builder()
.url(preference + "/api/open/task/getTaskInfo/" + projectId)
.build();
Response response = client.newCall(request).execute();
String string = response.body().string();
System.out.println(string);
JSONObject parseObject = JSON.parseObject(string);
JSONArray datas = parseObject.getJSONArray("data");
idName.clear();
if(datas!=null) {
for(int t=0;t<datas.size();t++) {
JSONObject jsonObject = datas.getJSONObject(t);
String string2 = jsonObject.getString("userid");
if(string2!=null && !string2.equals("")) {
idName.put(jsonObject.getString("taskname"),string2);
}
System.out.println(jsonObject.getString("taskname")+"====="+string2);
}
}
System.out.println(idName.toString());
List<CBean> beanList = kjBean.cbeans;
// ZT2_Requisition
for(CBean bean : beanList) {
String piName = bean.piName;
String folderName = bean.folderName;
if(idName.containsKey(piName)) {
String userId = idName.get(piName);
TCComponent userName = getUserName(userId,session);
if(userName!=null) {
nameUser.put(bean.cId,(TCComponentUser) userName);
}
}
if(!fodlers.containsKey(folderName)) {
errBuff.append("项目执行下没有找到名称为:"+folderName+"的文件夹");
return false;
}else {
fMap.put(bean.cId, fodlers.get(folderName));
}
}
System.out.println(nameUser.toString());
} catch (Exception e) {
// Auto-generated catch block
e.printStackTrace();
}
return flag;
}
private static TCComponent getUserName(String userID, TCSession session) throws Exception {
Map<String, String> fields = new HashMap<>();
fields.put("用户 ID", userID);
TCComponentContextList quertList = KUtil.query(session, "__WEB_find_user", fields);
if (quertList.getListCount() > 0) {
// System.out.println("user:"+quertList.get(0).getComponent());
return (TCComponent)quertList.get(0).getComponent();
}
return null;
}
private String objectToJson(List<ClassProperty> props) {
String str = null;
try {
net.sf.json.JSONArray json = net.sf.json.JSONArray.fromObject(props);// 将java对象转换为json对象
str = json.toString();// 将json对象转换为字符串
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("JSON =>" + str);
return str;
}
@SuppressWarnings("deprecation")
protected boolean createKjBom(KjBean bean, MyProgressBarCompent comp) throws Exception {
StringBuilder builder = new StringBuilder("");
TCComponentItemType ccomponentitemtype = (TCComponentItemType)session.getTypeComponent("ZT2_Design3D");
TCComponentItem newItem = ccomponentitemtype.find(bean.getKjbomId());
TCComponentItemRevision kjBomRev = newItem.getLatestItemRevision();
TCTypeService service = session.getTypeService();
TCComponentBOMWindowType winType = (TCComponentBOMWindowType) service.getTypeComponent("BOMWindow");
TCComponentBOMWindow window = winType.create(null);
TCComponentBOMLine kjBomLine = window.setWindowTopLine(newItem, kjBomRev, null, null);
kjBs = bean.kjBs;
kjIdMap.clear();
oldkjIdMap.clear();
Map<String, ExpandPSData[]> bomLineTreeNodeSOA = BomToSapUtil.getBomLineTreeNodeSOA(kjBomLine);
builder.setLength(0);
// 遍历获取BOM结构 判断ID是否存在
String item_id = kjBomRev.getProperty("item_id");
String replaceAll = item_id.replaceAll(kjBs, projectDh);
kjIdMap.put(kjBomRev, replaceAll);
Map<String, TCComponentItem> findMap = new HashMap<String, TCComponentItem>();
//遍历获取BOM新ID
List<TCComponentBOMLine> useLines = new ArrayList<TCComponentBOMLine>();
createId(kjBomLine, bomLineTreeNodeSOA, builder, ccomponentitemtype, findMap, useLines, 1);
System.out.println("kjIdMap==>" + kjIdMap.toString());
System.out.println("builder==>" + builder.toString());
if(builder.length() > 0) {
// MessageBox.post(builder.toString(), "提示",2);
String[] msgs = builder.toString().split("");
builder.setLength(0);
for(int i = 0; i < msgs.length; i++) {
builder.append(msgs[i]).append("");
if(i % 4 == 3) {
builder.append("\n");
}
}
Object[] options = { "是", "否" };
comp.setVisible(false);
builder.append("是否要继续生成.");
int response = JOptionPane.showOptionDialog(null, builder.toString(), "选择", JOptionPane.YES_OPTION,
JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if(response == -1 || response == 1) {
window.close();
return false;
}
} //else
{
comp = new MyProgressBarCompent("", "正在创建框架BOM......");
//开始克隆BOM
cloneOrUpdate(session, kjBomLine, copyLines, useLines);
//添加到文件夹
System.out.println("oldkjIdMap==>" + oldkjIdMap.toString());
for(TCComponentItemRevision rev : oldkjIdMap.keySet()) {
TCComponentItem find = oldkjIdMap.get(rev);
String id = find.getProperty("item_id");
String[] split = id.split("-");
System.out.println("id1==>" + id);
if(fMap.containsKey(split[0])) {
TCComponentFolder tcComponentFolder = fMap.get(split[0]);
try {
tcComponentFolder.add("contents", find);
}catch(Exception e) {
if(!e.getMessage().contains("存在于目标文件夹中"))
e.printStackTrace();
}
}
}
System.out.println("nameUser==>" + nameUser.toString());
System.out.println("fMap==>" + fMap.toString());
for(TCComponentItemRevision rev : kjIdMap.keySet()) {
String id = kjIdMap.get(rev);
TCComponentItem[] finds = ccomponentitemtype.findItems(id);
if(finds == null || finds.length == 0) {
System.out.println(id + "对象未找到");
continue;
}
TCComponentItem find = finds[0];
String[] split = id.split("-");
System.out.println("id2==>" + split[0]);
if(fMap.containsKey(split[0])) {
TCComponentFolder tcComponentFolder = fMap.get(split[0]);
try {
tcComponentFolder.add("contents", find);
}catch(Exception e) {
if(!e.getMessage().contains("存在于目标文件夹中"))
e.printStackTrace();
}
}
if(nameUser.containsKey(split[0])) {
TCComponentUser tcComponentUser = nameUser.get(split[0]);
try {
changeOwners(find,tcComponentUser);
} catch (Exception e) {
// Auto-generated catch block
e.printStackTrace();
}
}
}
TCComponentItem find = ccomponentitemtype.findItems(replaceAll)[0];
System.out.println("find==>" + find);
if(findMap.size()>0) {
// window.lock();
TCComponentBOMLine newTopline = window.setWindowTopLine(find, find.getLatestItemRevision(),null, null);
Map<String, ExpandPSData[]> bomLineTreeNodeSOA2 = BomToSapUtil.getBomLineTreeNodeSOA(newTopline);
updateKjBom( findMap , bomLineTreeNodeSOA2,newTopline.getUid());
newTopline.save();
window.save();
window.refresh();
// window.unlock();
// window.close();
}
String groupId = SAPUtil.getGroupID(session);
TCComponentBOMLine newTopline = window.setWindowTopLine(find, find.getLatestItemRevision(),null, null);
//如果存在已经有的框架BOM对象遍历BOM然后替换再进行下面操作
System.out.println("byqCCPFromProject==>" + byqCCPFromProject.toString());
if(byqCCPFromProject.size()>0) {
try {
if(groupId.equals("M005")) {
for(TCComponentItemRevision ccp : byqCCPFromProject) {
AIFComponentContext[] factorys = KUtil.getPseudoFolder(ccp, "ZT2_FactoryNumber").getChildren();
if(factorys.length > 0) {
for(AIFComponentContext f : factorys) {
find.getLatestItemRevision().add("ZT2_FactoryNumber", (TCComponent) f.getComponent());
}
}else {
find.getLatestItemRevision().add("representation_for", ccp);
}
}
}else
find.getLatestItemRevision().add("representation_for", byqCCPFromProject);
}catch(Exception e) {
if(!e.getMessage().contains("存在于目标文件夹中"))
e.printStackTrace();
}
}
List<ClassProperty> propList = new ArrayList<ClassProperty>();
//TODO 读取CHINT_kjbomTemp_FL首选项根据组织、图纸母号找到对应的分类库 ICM230101
String prefId = groupId + ":" + bean.kjbomId, classID = "";
String[] prefs = ChintPreferenceUtil.getPreferences("CHINT_kjbomTemp_FL", session);
for(String pref : prefs) {
if(!pref.startsWith(prefId))
continue;
classID = pref.substring(pref.indexOf("|") + 1);
}
if(classID.isEmpty()) {
MessageBox.post(prefId + "未找到对应分类库", "提示", MessageBox.WARNING);
}else
sendToClass(find.getUid(), classID, objectToJson(propList));
List<TCComponentBOMLine> listBoms = listBoms(newTopline);
//存放名称对应的BOM行
List<BomBean> bomBeans = new ArrayList<>();
for(TCComponentBOMLine listBom : listBoms) {
String name = listBom.getItemRevision().getProperty("object_name");
bomBeans.add(new BomBean(name, listBom));
}
System.out.println("bomBeans==>" + bomBeans.toString());
// Map<String,List<TCComponentBOMLine>> remarkMap = new HashMap<String,List<TCComponentBOMLine>>();
//拆分BOM逻辑获取物料提前请购单的BOM
if(tqqgdItem != null) {
TCComponentBOMWindow window2 = winType.create(null);
TCComponentBOMLine qgdBomline = window2.setWindowTopLine(tqqgdItem, tqqgdItem.getLatestItemRevision(), null, null);
AIFComponentContext[] children = qgdBomline.getChildren();
//遍历物料提前请购单 根据备注添加BOM到对应位置
// lidy20240710创建框架BOM中功能中的从提前请购组件BOM中抓取成分搭建进生成的框架BOM
//需要将抓取的物料明细在复制后增加注释信息BOM行属性数据来源bl_occ_zt2_wlsource写入“提前请购单”
for(int i = 0; i < children.length; i++) {
TCComponentBOMLine wlLine = (TCComponentBOMLine) children[i].getComponent();
TCComponentItem item = wlLine.getItem();
if(item.getType().equals("ZT2_MainMat")) {
AIFComponentContext[] children2 = wlLine.getChildren();
for(AIFComponentContext c2 : children2) {
TCComponentBOMLine wlLine2 = (TCComponentBOMLine) c2.getComponent();
String object_name = wlLine2.getProperty("ZT2_Remark");
String objName = wlLine2.getItem().getProperty("object_name");
System.out.println(object_name);
System.out.println(objName + "gg");
if(!object_name.equals("") && bomBeans.contains(new BomBean(object_name))) {
BomBean bomBean = bomBeans.get(bomBeans.indexOf(new BomBean(object_name)));
if(checkSource(bomBean.bomLine, wlLine2))
continue;
bomBean.bomLine.add(wlLine2, false).setProperty("bl_occ_zt2_wlsource", "提前请购单");
bomBean.bomLine.save();
}else if(object_name.equals("") && objName.contains("硅钢条料")) {
if(bomBeans.contains(new BomBean("硅钢片"))) {
BomBean bomBean = bomBeans.get(bomBeans.indexOf(new BomBean("硅钢片")));
if(checkSource(bomBean.bomLine, wlLine2))
continue;
bomBean.bomLine.add(wlLine2, false).setProperty("bl_occ_zt2_wlsource", "提前请购单");
bomBean.bomLine.save();
}
}else {
if(checkSource(newTopline, wlLine2))
continue;
TCComponentBOMLine add = newTopline.add(wlLine2, false);
add.setProperty("bl_occ_zt2_wlsource", "提前请购单");
System.out.println(add);
newTopline.save();
}
}
}else {
String object_name = wlLine.getProperty("ZT2_Remark");
System.out.println(object_name);
String objName = wlLine.getItem().getProperty("object_name");
if(!object_name.equals("") && bomBeans.contains(new BomBean(object_name))) {
BomBean bomBean = bomBeans.get(bomBeans.indexOf(new BomBean(object_name)));
if(checkSource(bomBean.bomLine, wlLine))
continue;
bomBean.bomLine.add(wlLine, false).setProperty("bl_occ_zt2_wlsource", "提前请购单");
bomBean.bomLine.save();
}else if(object_name.equals("") && objName.equals("硅钢条料")) {
if(bomBeans.contains(new BomBean("硅钢片"))) {
BomBean bomBean = bomBeans.get(bomBeans.indexOf(new BomBean("硅钢片")));
if(checkSource(bomBean.bomLine, wlLine))
continue;
bomBean.bomLine.add(wlLine, false).setProperty("bl_occ_zt2_wlsource", "提前请购单");
bomBean.bomLine.save();
}
}else {
if(checkSource(newTopline, wlLine))
continue;
TCComponentBOMLine add = newTopline.add(wlLine, false);
add.setProperty("bl_occ_zt2_wlsource", "提前请购单");
System.out.println(add);
newTopline.save();
}
}
}
window2.close();
newTopline.window().save();
}
changePrivilege(session, find);
}
window.close();
comp.setVisible(false);
return true;
}
private static void changePrivilege(TCSession session, TCComponent dataset) throws Exception {
KUtil.setByPass(true);
TCAccessControlService accessControlService = session.getTCAccessControlService();
TCComponentUser user = session.getUser();
accessControlService.grantPrivilege(dataset, user, new String[]{"WRITE","READ"});
// KUtil.setByPass(false);
}
@SuppressWarnings("deprecation")
private void updateKjBom(Map<String, TCComponentItem> findMap, Map<String, ExpandPSData[]> bomLineTreeNodeSOA, String uid) throws Exception {
// Auto-generated method stub
ExpandPSData[] expandPSDatas = bomLineTreeNodeSOA.get(uid);
for(ExpandPSData expandPSData : expandPSDatas) {
TCComponentBOMLine bomLine = expandPSData.bomLine;
TCComponentItemRevision itemRevOfBOMLine = expandPSData.itemRevOfBOMLine;
String itemId = itemRevOfBOMLine.getProperty("item_id");
System.out.println("findMap===>" + findMap.toString());
System.out.println("itemId===>" + itemId.toString());
if(findMap.containsKey(itemId)) {
TCComponentItem tcItem = findMap.get(itemId);
System.out.println("tcItem===>" + tcItem.toString());
TCComponentItemRevision lastRev = tcItem.getLatestItemRevision();
bomLine.replace(tcItem, lastRev, null);
bomLine.save();
// bomLine.unlock();
}
updateKjBom(findMap, bomLineTreeNodeSOA, bomLine.getUid());//ExpandPSData[] expandPSDatas2 = bomLineTreeNodeSOA.get(bomLine.getUid());
}
}
@SuppressWarnings("deprecation")
private static void changeOwners(TCComponentItem item, TCComponentUser user) throws Exception {
TCComponent[] revs = item.getRelatedComponents("revision_list");
TCComponentItemRevision rev;
TCComponentGroup group = (TCComponentGroup) user.getRelatedComponent("default_group");
TCComponent bom = null;
TCComponent[] datasets;
for (int i = 0, len = revs.length; i < len; i++) {
rev = (TCComponentItemRevision) revs[i];
bom = rev.getRelatedComponent("structure_revisions");
datasets = rev.getRelatedComponents("IMAN_specification");
for (int m = 0, len2 = datasets.length; m < len2; m++) {
datasets[m].lock();
datasets[m].changeOwner(user, group);
datasets[m].save();
datasets[m].unlock();
}
if (bom != null) {
bom.lock();
bom.changeOwner(user, group);
bom.save();
bom.unlock();
}
rev.lock();
rev.changeOwner(user, group);
rev.save();
rev.unlock();
}
bom = item.getRelatedComponent("bom_view_tags");
if (bom != null) {
bom.lock();
bom.changeOwner(user, group);
bom.save();
bom.unlock();
}
item.lock();
item.changeOwner(user, group);
item.save();
item.unlock();
}
private void sendToClass(String wsoPUID, String classID, String json) {
// AbstractAIFApplication app;
// app=AIFUtility.getCurrentApplication();
// TCSession session;
// session=(TCSession) app.getSession();
try {
TCPreferenceService preferenceService = session.getPreferenceService();
// String account=preferenceService.getStringValue("Autocode_PriverUser_ID");
String url = preferenceService.getStringValue("Autocode_SendClassServer_URL");
ServiceClient sc = new ServiceClient();
Options opts = new Options();
// url = "http://10.201.5.203:19090/ErpWebService.asmx?WSDL";
EndpointReference end = new EndpointReference(url);
opts.setTo(end);
opts.setAction("SendToClass");
sc.setOptions(opts);
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace omNs = fac.createOMNamespace("http://tempuri.org/", "");
OMElement method = fac.createOMElement("SendToClass", omNs);
OMElement value = fac.createOMElement("wsoPuiid", omNs);
value.setText(wsoPUID);
OMElement value1 = fac.createOMElement("classID", omNs);
value1.setText(classID);
OMElement value2 = fac.createOMElement("JsonContainer", omNs);
// "[{\"value\":\"1\",\"propertyID\":-500003},{\"value\":\"1\",\"propertyID\":-500011}]"
value2.setText(json);
method.addChild(value);
method.addChild(value1);
method.addChild(value2);
OMElement res = sc.sendReceive(method);
res.getFirstElement().getText();
System.out.println(res.getFirstElement().getText());
} catch (Exception e) {
e.printStackTrace();
}
}
private void createId(TCComponentBOMLine pLine, Map<String, ExpandPSData[]> bomLineTreeNodeSOA,
StringBuilder builder, TCComponentItemType ccomponentitemtype,
Map<String, TCComponentItem> findMap, List<TCComponentBOMLine> useLines, int type) throws Exception {
ExpandPSData[] expandPSDatas = bomLineTreeNodeSOA.get(pLine.getUid());
if(type != 0) {
copyLines.add(pLine);
}
for(ExpandPSData expandPSData : expandPSDatas) {
TCComponentBOMLine cLine = expandPSData.bomLine;
TCComponentItemRevision cRev = expandPSData.itemRevOfBOMLine;
if(cRev.getType().contains("ZT2_Design3D")) {
String item_id = cRev.getProperty("item_id");
String replaceAll = item_id.replaceAll(kjBs, projectDh);
/*if(type == 0) {
useLines.add(cLine);
oldkjIdMap.put(cRev, cLine.getItem());
createId(cLine, bomLineTreeNodeSOA, builder, ccomponentitemtype, findMap, useLines, 0);
}else {
}*/
TCComponentItem[] finds = ccomponentitemtype.findItems(replaceAll);
if(finds != null && finds.length > 0) {
builder.append("当前ID已经存在:").append(replaceAll).append("");
findMap.put(item_id, finds[0]);
useLines.add(cLine);
oldkjIdMap.put(cRev, finds[0]);
createId(cLine, bomLineTreeNodeSOA, builder, ccomponentitemtype, findMap, useLines, 0);
}else {
kjIdMap.put(cRev, replaceAll);
createId(cLine, bomLineTreeNodeSOA, builder, ccomponentitemtype, findMap, useLines, 1);
}
}else {
copyLines.add(cLine);
}
}
}
//批量复制
private void cloneOrUpdate(TCSession session, TCComponentBOMLine parentLine,
List<TCComponentBOMLine> bomLines, List<TCComponentBOMLine> useLines) {
com.teamcenter.services.rac.structuremanagement.StructureService service =
com.teamcenter.services.rac.structuremanagement.StructureService.getService(session);
// idMapAdd.clear();
CloneStructureInputInfo[] infos = new CloneStructureInputInfo[1];
infos[0] = new CloneStructureInputInfo();
// infos[0].bomline = puid;
infos[0].cadOptions = new String[] { "PartFamilyMaster" };
try {
infos[0].defaultFolder = session.getUser().getNewStuffFolder();
infos[0].cloneFlags = 2;
com.teamcenter.services.rac.structuremanagement._2014_10.Structure.CloneStructureProjectInfo projectInfo
= new com.teamcenter.services.rac.structuremanagement._2014_10.Structure.CloneStructureProjectInfo();
projectInfo.assign = false;
projectInfo.validate = false;
infos[0].projects = projectInfo;
TCComponentRevisionRule revisionRule = parentLine.window().getRevisionRule();
infos[0].revRule = revisionRule;
TCComponentItemRevision[] revs = new TCComponentItemRevision[] { parentLine.getItemRevision() };
infos[0].topItemRevs = revs;
System.out.println("Save class Partial bomLine -- " + bomLines.size());
List<CloneStructureSaveAsIn> saveList = new ArrayList<CloneStructureSaveAsIn>();
for(TCComponentBOMLine subLine : bomLines) {
// for(int i = 0; i < bomLines.size(); i++) {
// TCComponentBOMLine subLine = bomLines.get(i);
TCComponentItem item = subLine.getItem();
CloneStructureSaveAsIn dataMap = null;
if(item.getType().equals("ZT2_Design3D")) {
// subLine.replace
dataMap = getDataMap(subLine, 0, session);
}else {
dataMap = getDataMap(subLine, 1, session);
}
saveList.add(dataMap);
}
for(TCComponentBOMLine subLine : useLines) {
CloneStructureSaveAsIn dataMap = getDataMap(subLine, 1, session);
saveList.add(dataMap);
}
com.teamcenter.services.rac.structuremanagement._2014_10.Structure.CloneStructureDefaultNaming naming =
new com.teamcenter.services.rac.structuremanagement._2014_10.Structure.CloneStructureDefaultNaming();
CloneStructureSaveAsIn[] array = saveList.toArray(new CloneStructureSaveAsIn[saveList.size()]);
infos[0].dataMap = array;
naming.autogen = true;
infos[0].defaultName = naming;
infos[0].topLines = new TCComponentBOMLine[] { parentLine };
// TCComponentBOMLine.get
// puid.getr
} catch (Exception e1) {
// Auto-generated catch block
e1.printStackTrace();
}
CloneStructureResponse cloneStructure = service.cloneStructure(infos);
// infos[0].
// cloneStructureExpandOrUpdate.serviceData;
if (cloneStructure.serviceData.sizeOfPartialErrors() > 0) {
for (int i = 0; i < cloneStructure.serviceData.sizeOfPartialErrors(); i++) {
System.out.println("Save class Partial Error -- " + cloneStructure.serviceData
.getPartialError(i).getMessages()[0]);
}
}
try {
System.out.println("Save class Partial Error -- " + cloneStructure.serviceData.sizeOfUpdatedObjects());
if(cloneStructure.serviceData.sizeOfUpdatedObjects()>0) {
TCComponent updatedObject = cloneStructure.serviceData.getUpdatedObject(0);
System.out.println(session.componentToString(updatedObject) + " >> " + updatedObject);
}
// for(int i = 0; i < cloneStructure.serviceData.sizeOfCreatedObjects(); i++) {
// TCComponent plainObject = cloneStructure.serviceData.getCreatedObject(i);
// System.out.println(session.componentToString(plainObject));
// }
// for(int i = 0; i < cloneStructure.serviceData.sizeOfPlainObjects(); i++) {
// TCComponent plainObject = cloneStructure.serviceData.getPlainObject(i);
// System.out.println(session.componentToString(plainObject));
// }
} catch (Exception e) {
// Auto-generated catch block
e.printStackTrace();
}
}
private CloneStructureSaveAsIn getDataMap(TCComponentBOMLine child, int type, TCSession session) throws Exception {
TCComponentItemRevision rev = child.getItemRevision();
CloneStructureSaveAsIn dataMap = new CloneStructureSaveAsIn();
Map<String, String[]> newItemRevinfo = new HashMap<>();
dataMap.cloneOperationType = type;
// dataMap.newItemRevinfo =
dataMap.origItemRevComp = rev;
newItemRevinfo.put("sequence_limit", new String[] { "3" });
newItemRevinfo.put("fnd0CheckoutOnSaveAs", new String[] { "false" });
newItemRevinfo.put("item_revision_id", new String[] { "" });
newItemRevinfo.put("sequence_id", new String[] { "1" });
newItemRevinfo.put("object_name", new String[] { rev.getStringProperty("object_name") });
if(type == 0) {
com.teamcenter.services.rac.structuremanagement._2014_10.Structure.DeepCopyData[] copys =
new com.teamcenter.services.rac.structuremanagement._2014_10.Structure.DeepCopyData[1];
com.teamcenter.services.rac.structuremanagement._2014_10.Structure.DeepCopyData copy =
new com.teamcenter.services.rac.structuremanagement._2014_10.Structure.DeepCopyData();
copy.attachedObject = rev.getItem();
copy.copyAction = "CopyAsObject";
copy.copyRelations = true;
copy.isRequired = true;
copy.isTargetPrimary = true;
copy.operationInputTypeName = "";
copy.propertyName = "items_tag";
copy.propertyType = "Reference";
Map<String, String[]> operationInputs = new HashMap<>();
operationInputs.put("fnd0CheckoutOnSaveAs", new String[] { "false" });
operationInputs.put("is_configuration_item", new String[] { "false" });
String zt2Unit = rev.getItem().getTCProperty("zt2_unit").getStringValue();
// rev.getItem().get("zt2_unit");
operationInputs.put("zt2_unit", new String[] { zt2Unit });
String newId = "";
try {
newId = kjIdMap.get(rev);
// newId
}catch(Exception e) {
e.printStackTrace();
}
operationInputs.put("item_id", new String[] { newId }); // 获取规则
copy.operationInputs = operationInputs;
copys[0] = copy;
dataMap.deepCopyDataOverride = copys;
}
dataMap.newItemRevinfo = newItemRevinfo;
return dataMap;
}
/**
* BOMBOMBOMBOMBOM
*
* @param parent
* @param target
* @return BOMtrue
* @throws Exception
*/
private boolean checkSource(TCComponentBOMLine parent, TCComponentBOMLine target) throws Exception {
String id = target.getProperty("bl_item_item_id");
for(AIFComponentContext c : parent.getChildren()) {
TCComponentBOMLine child = (TCComponentBOMLine) c.getComponent();
if(child.getProperty("bl_item_item_id").equals(id) && child.getProperty("bl_occ_zt2_wlsource").equals("提前请购单"))
return true;
}
return false;
}
private List<TCComponentItemRevision> getByqCCPFromProject(TCComponent targetComp, TCSession session) throws Exception {
List<TCComponentItemRevision> ccpRevList = new ArrayList<TCComponentItemRevision>();
TCComponent[] refs = targetComp.getRelatedComponents("IMAN_reference");
int len = refs == null ? 0 : refs.length;
TCComponentFolder projStart = null;
System.out.println("查找项目启动文件夹:" + targetComp);
for (int i = 0; i < len; i++) {
String cName = refs[i].getProperty("object_name");
System.out.println(">> 找到子对象:" + cName);
if ((refs[i] instanceof TCComponentFolder) && cName.contains("项目启动")) {
projStart = (TCComponentFolder) refs[i];
break;
}
}
if (projStart == null) {
return null;
}
TCComponentFolder ccpFolder = null;
AIFComponentContext[] cFolders = projStart.getChildren();
len = cFolders == null ? 0 : cFolders.length;
for (int i = 0; i < len; i++) {
InterfaceAIFComponent c = cFolders[i].getComponent();
String cName = c.getProperty("object_name");
if ((c instanceof TCComponentFolder) && cName.contains("产成品")) {
ccpFolder = (TCComponentFolder) c;
break;
}
}
String[] preferences = ChintPreferenceUtil.getPreferences("CHINT_NO_KJTOPROD_M060", session);
AIFComponentContext[] ccpContexts = ccpFolder.getChildren();
for(AIFComponentContext context:ccpContexts) {
InterfaceAIFComponent component = context.getComponent();
String property = component.getProperty("object_name");
if(property.contains("变压器")) {
boolean flag = false;
for(String preference:preferences) {
if(property.contains(preference)) {
flag = true;
break;
}
}
if(component instanceof TCComponentItem && !flag) {
TCComponentItemRevision latestItemRevision = ((TCComponentItem)component).getLatestItemRevision();
ccpRevList.add(latestItemRevision);
}
}
}
return ccpRevList;
}
private List<TCComponentBOMLine> listBoms(TCComponentBOMLine bomLine) {
// List<String> bomLineNodes = list;
// 预定义BOM父子对map及ItemRev map
List<TCComponentBOMLine> listBoms = new ArrayList<>();
try {
// TCComponentItemRevision object = bomLine.getItemRevision();
// String object_type = object.getType();
com.teamcenter.services.rac.cad._2007_01.StructureManagement structureService = com.teamcenter.services.rac.cad.StructureManagementService
.getService(RACUIUtil.getTCSession());
com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSAllLevelsInfo levelInfo = new com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSAllLevelsInfo();
com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSAllLevelsPref levelPref = new com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSAllLevelsPref();
levelInfo.parentBomLines = new TCComponentBOMLine[] { bomLine }; // 输入顶层BOMLine对象
levelInfo.excludeFilter = "None";
levelPref.expItemRev = false;
levelPref.info = new com.teamcenter.services.rac.cad._2007_01.StructureManagement.RelationAndTypesFilter[0];
// 使用以下方法展开完整的BOM行
com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSAllLevelsResponse levelResp = structureService
.expandPSAllLevels(levelInfo, levelPref);
if (levelResp.output.length > 0) {
// 将BOM构建成uid父子对关系
for (ExpandPSAllLevelsOutput data : levelResp.output) {
TCComponentBOMLine parentBomLine = (TCComponentBOMLine) data.parent.bomLine;
listBoms.add(parentBomLine);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return listBoms;
}
}

@ -1,25 +1,23 @@
package com.connor.chint.sap2.dy.createBOMDifference;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.connor.chint.sap2.util.ChintPreferenceUtil;
import com.connor.chint.sap2.util.SAPUtil;
import com.connor.chint.sap2.util.SqlUtil;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
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.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.services.rac.cad._2007_01.StructureManagement;
import com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSAllLevelsOutput;
import com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSData;
/**
*
@ -28,197 +26,271 @@ import com.teamcenter.rac.kernel.TCSession;
*
*/
public class CreateBOMDifference_GKController {
private static HashMap<String, ArrayList<Object[]>> oldStBomMap;
private static HashMap<String, ArrayList<Object[]>> newStBomMap;
private static HashMap<String, Boolean> shitiMap;
private static HashMap<String, ExpandPSData[]> bomMap;
public static final String SQL_Process = "select nvl(a.rprimary_objectu,'-1') from PIMANRELATION a "
+ "left join PIMANTYPE b on a.rrelation_typeu=b.puid "
+ "left join PWORKSPACEOBJECT c on c.puid =a.rprimary_objectu "
+ "where a.rsecondary_objectu =? and b.ptype_name='IMAN_METarget' and c.pobject_type='MEProcessRevision' ";
@SuppressWarnings("deprecation")
public static void getRevMap(TCSession session, TCComponent[] oldComponents, TCComponent[] newComponents,
List<BOMCompareBean> beans) throws TCException {
List<BOMCompareBean> beans) throws Exception {
Map<TCComponentItem, BOMDifferenceBean> map_item_beans = new HashMap<>();
oldStBomMap = new HashMap<>();
newStBomMap = new HashMap<>();
shitiMap = new HashMap<>();
bomMap = new HashMap<>();
StructureManagement structureService = com.teamcenter.services.rac.cad.StructureManagementService.getService(session);
// HashMap<TCComponentItem, BOMDifferenceBean> map_item_beans = new HashMap<>();
HashMap<String, BOMDifferenceBean> map_item_beans = new HashMap<>();
ArrayList<BOMDifferenceBean> kjBeans = new ArrayList<>();
String[] prefs = ChintPreferenceUtil.getPreferences("database_tc", session);
if (SqlUtil.getTCDataConnection(prefs) == null) {
throw new Exception("无法连接数据库,请检查首选项<database_tc>配置。");
}
for (TCComponent comp : oldComponents) {
TCComponentItemRevision rev = (TCComponentItemRevision) comp;
TCComponentItem item = rev.getItem();
BOMDifferenceBean bean = map_item_beans.get(item);
String id = item.getProperty("item_id");
BOMDifferenceBean bean = map_item_beans.get(id);
if (bean == null) {
bean = new BOMDifferenceBean();
bean.setItem(item);
bean.setOldRev(rev);
if(rev.getProperty("zt2_DrawingNo").equals("高开框架BOM")) {
bean.setKj(true);
kjBeans.add(bean);
}else if(isShiti(rev)) {
bean.setKj(false);
kjBeans.add(bean);
}
}
map_item_beans.put(item, bean);
map_item_beans.put(id, bean);
}
for (TCComponent comp : newComponents) {
TCComponentItemRevision rev = (TCComponentItemRevision) comp;
TCComponentItem item = rev.getItem();
BOMDifferenceBean bean = map_item_beans.get(item);
String id = item.getProperty("item_id");
BOMDifferenceBean bean = map_item_beans.get(id);
if (bean == null) {
bean = new BOMDifferenceBean();
bean.setItem(item);
bean.setNewRev(rev);
if(rev.getProperty("zt2_DrawingNo").equals("高开框架BOM")) {
bean.setKj(true);
kjBeans.add(bean);
}else if(isShiti(rev)) {
bean.setKj(false);
kjBeans.add(bean);
}
} else {
bean.setNewRev(rev);
}
map_item_beans.put(item, bean);
map_item_beans.put(id, bean);
}
try {
String[] prefs = ChintPreferenceUtil.getPreferences("database_tc", session);
if (SqlUtil.getTCDataConnection(prefs) == null) {
throw new Exception("无法连接数据库,请检查首选项<database_tc>配置。");
if(kjBeans.size() == 0) {
throw new Exception("关系下未找到框架层对象");
}
TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
TCComponentBOMWindow win = bomWinType.create(null);
// win.lock();
TCComponentBOMWindow win2 = bomWinType.create(null);
// win2.lock();
List<BOMCompareBean> compares;
List<TCComponentItem> items = new ArrayList<>();
List<TCComponentItem> item_compares = new ArrayList<>();
HashMap<TCComponentItem, BOMDifferenceBean> map_childs = new HashMap<>();
HashMap<String, List<BOMCompareBean>> map_compares = new HashMap<>();
// for (Entry<String, BOMDifferenceBean> entry : map_item_beans.entrySet()) {
// BOMDifferenceBean bean = entry.getValue();
for(BOMDifferenceBean kjBean : kjBeans) {
TCComponentItemRevision oldKjRev = kjBean.getOldRev(), newKjRev = kjBean.getNewRev();
if(kjBean.isKj() && (oldKjRev == null || newKjRev == null)) {
throw new Exception("更改前后关系下框架层对象不匹配");
}
TCComponentBOMLine oldKjLine = win.setWindowTopLine(oldKjRev.getItem(), oldKjRev, null, null);
TCComponentBOMLine newKjLine = win2.setWindowTopLine(newKjRev.getItem(), newKjRev, null, null);
getBomLineTreeNodeSOA(oldKjRev, structureService, bomWinType);
getBomLineTreeNodeSOA(newKjRev, structureService, bomWinType);
oldStBomMap.clear();
newStBomMap.clear();
//TODO recycleBom
System.out.println("recycleBom------" + oldKjLine + ">>" + newKjLine);
recycleBom(oldKjRev.toString(), oldKjRev.toString(), true, bomWinType, map_item_beans, 1.0, structureService);
System.out.println("oldBomMap------" + printBomMap(oldStBomMap));
recycleBom(newKjRev.toString(), newKjRev.toString(), false, bomWinType, map_item_beans, 1.0, structureService);
System.out.println("newBomMap------" + printBomMap(newStBomMap));
TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
TCComponentBOMWindow win = bomWinType.create(null);
win.lock();
TCComponentBOMWindow win2 = bomWinType.create(null);
win2.lock();
List<BOMCompareBean> compares;
List<TCComponentItem> items = new ArrayList<>();
List<TCComponentItem> item_compares = new ArrayList<>();
Map<TCComponentItem, BOMDifferenceBean> map_childs = new HashMap<>();
Map<TCComponentItem, List<BOMCompareBean>> map_compares = new HashMap<>();
TCComponentItem item = kjBean.getItem();
System.out.println("框架------" + item + " old:" + kjBean.getOldRev() + "; new:" + kjBean.getNewRev());
for (Entry<TCComponentItem, BOMDifferenceBean> entry : map_item_beans.entrySet()) {
BOMDifferenceBean bean = entry.getValue();
TCComponentItem item = entry.getKey();
System.out.println("遍历------" + item + " old:" + bean.getOldRev() + "; new:" + bean.getNewRev());
if (item_compares.indexOf(item) != -1) {
System.out.println("已读取,跳过");
continue;
}
System.out.println("未读取,遍历BOM---");
if (bean.getOldRev() != null && bean.getNewRev() != null) {
win.setWindowTopLine(entry.getKey(), bean.getOldRev(), null, null);
win2.setWindowTopLine(entry.getKey(), bean.getNewRev(), null, null);
win.refresh();
win2.refresh();
BOMDifferenceBean parentBean;
if (map_childs.containsKey(item)) {
parentBean = map_childs.get(item);
parentBean.setOldBOMLine(win.getTopBOMLine());
parentBean.setNewBOMLine(win2.getTopBOMLine());
} else {
parentBean = new BOMDifferenceBean();
parentBean.setOldQuantity(1);
parentBean.setNewQuantity(1);
parentBean.setOldBOMLine(win.getTopBOMLine());
parentBean.setNewBOMLine(win2.getTopBOMLine());
String zt2_MaterialNo = "";
String object_desc = "";
String object_name = "";
TCComponentItemRevision parentRev = null;
parentRev = SAPUtil.getSAPPart(parentBean.getNewBOMLine(), session);
if (parentRev != null) {
zt2_MaterialNo = parentRev.getProperty("zt2_MaterialNo");
object_desc = parentRev.getProperty("object_desc");
object_name = parentRev.getProperty("object_name");
}
parentBean.setZt2_MaterialNo_Parent(zt2_MaterialNo);
parentBean.setObject_desc_Parent(object_desc);
parentBean.setObject_name_Parent(object_name);
parentBean.setParentPartRev(parentRev);
}
System.out.println("oldLine:" + win.getTopBOMLine()+"; newLine:" + win2.getTopBOMLine());
parentBean.setItem(item);
compares = new ArrayList<>();
bomCompare_M006(parentBean, session, parentBean.getOldQuantity(), parentBean.getNewQuantity(),
compares, true, false, item_compares, map_item_beans, map_childs, 0);
map_compares.put(item, compares);
// map_childs.remove(item);
items.add(item);
BOMDifferenceBean parentBean;
if (map_childs.containsKey(item)) {
parentBean = map_childs.get(item);
parentBean.setOldBOMLine(oldKjLine);
parentBean.setNewBOMLine(newKjLine);
parentBean.setOldRev(oldKjRev);
parentBean.setNewRev(newKjRev);
} else {
parentBean = new BOMDifferenceBean();
parentBean.setOldQuantity(1);
parentBean.setNewQuantity(1);
parentBean.setOldBOMLine(oldKjLine);
parentBean.setNewBOMLine(newKjLine);
parentBean.setOldRev(oldKjRev);
parentBean.setNewRev(newKjRev);
String zt2_MaterialNo = "";
String object_desc = "";
String object_name = "";
TCComponentItemRevision parentRev = null;
parentRev = SAPUtil.getSAPPart(parentBean.getNewBOMLine(), session);
if (parentRev != null) {
zt2_MaterialNo = parentRev.getProperty("zt2_MaterialNo");
object_desc = parentRev.getProperty("object_desc");
object_name = parentRev.getProperty("object_name");
}
System.out.println("比较结束");
parentBean.setZt2_MaterialNo_Parent(zt2_MaterialNo);
parentBean.setObject_desc_Parent(object_desc);
parentBean.setObject_name_Parent(object_name);
parentBean.setParentPartRev(parentRev);
}
// System.out.println("oldLine:" + win.getTopBOMLine()+"; newLine:" + win2.getTopBOMLine());
parentBean.setItem(item);
compares = new ArrayList<>();
bomCompare_M006(parentBean, session, parentBean.getOldQuantity(), parentBean.getNewQuantity(),
compares, true, false, item_compares, map_item_beans, map_childs, 0);
map_compares.put(kjBean.getId(), compares);
// map_childs.remove(item);
items.add(item);
System.out.println("比较结束");
}
/*
List<TCComponentItem> keys = new ArrayList<>(map_childs.keySet());
BOMDifferenceBean bean2;
for (int i = 0, len = keys.size(); i < len; i++) {
TCComponentItem item = keys.get(i);
BOMDifferenceBean bean = map_childs.get(item);
bean2 = map_item_beans.get(item.getProperty("item_id"));
bean.setOldRev(bean2.getOldRev());
bean.setNewRev(bean2.getNewRev());
System.out.println("子项遍历------" + item + " old:" + bean.getOldRev() + "; new:" + bean.getNewRev());
if (bean.getOldRev() != null && bean.getNewRev() != null) {
win.setWindowTopLine(item, bean.getOldRev(), null, null);
win2.setWindowTopLine(item, bean.getNewRev(), null, null);
win.refresh();
win2.refresh();
BOMDifferenceBean parentBean = map_childs.get(item);
parentBean.setOldBOMLine(win.getTopBOMLine());
parentBean.setNewBOMLine(win2.getTopBOMLine());
System.out.println("子项--------" + parentBean);
System.out.println("oldLine:" + win.getTopBOMLine()+"; newLine:" + win2.getTopBOMLine());
parentBean.setItem(item);
compares = new ArrayList<>();
bomCompare_M006(parentBean, session, parentBean.getOldQuantity(), parentBean.getNewQuantity(),
compares, true, true, item_compares, map_item_beans, map_childs, 0);
map_compares.put(item, compares);
List<TCComponentItem> keys = new ArrayList<>(map_childs.keySet());
BOMDifferenceBean bean2;
for (int i = 0, len = keys.size(); i < len; i++) {
TCComponentItem item = keys.get(i);
BOMDifferenceBean bean = map_childs.get(item);
bean2 = map_item_beans.get(item);
bean.setOldRev(bean2.getOldRev());
bean.setNewRev(bean2.getNewRev());
System.out.println("子项遍历------" + item + " old:" + bean.getOldRev() + "; new:" + bean.getNewRev());
if (bean.getOldRev() != null && bean.getNewRev() != null) {
win.setWindowTopLine(item, bean.getOldRev(), null, null);
win2.setWindowTopLine(item, bean.getNewRev(), null, null);
win.refresh();
win2.refresh();
BOMDifferenceBean parentBean = map_childs.get(item);
parentBean.setOldBOMLine(win.getTopBOMLine());
parentBean.setNewBOMLine(win2.getTopBOMLine());
System.out.println("子项--------" + parentBean);
System.out.println("oldLine:" + win.getTopBOMLine()+"; newLine:" + win2.getTopBOMLine());
parentBean.setItem(item);
compares = new ArrayList<>();
bomCompare_M006(parentBean, session, parentBean.getOldQuantity(), parentBean.getNewQuantity(),
compares, true, true, item_compares, map_item_beans, map_childs, 0);
map_compares.put(item, compares);
items.add(item);
}
System.out.println("比较结束");
items.add(item);
}
System.out.println("读取变更----开始");
for (Entry<TCComponentItem, List<BOMCompareBean>> entry : map_compares.entrySet()) {
System.out.println("变更对象:" + entry.getKey());
compares = entry.getValue();
if (compares != null) {
for (int i = 0, len = compares.size(); i < len; i++) {
System.out.println(i + "-----" + compares.get(i));
System.out.println("比较结束");
}*/
System.out.println("读取变更----开始");
HashMap<String, Integer> idList = new HashMap<>();
ArrayList<String> parentList = new ArrayList<>();
for (String id : map_compares.keySet()) {
// String id = entry.getKey();
System.out.println("变更对象:" + id);
// if(!id.startsWith("@"))
// continue;
compares = map_compares.get(id);
if (compares != null) {
for (int i = 0, len = compares.size(); i < len; i++) {
BOMCompareBean compare = compares.get(i);
System.out.println(i + "-----" + compare);
String cid = compare.getId();
if(idList.containsKey(cid)) {
if(!parentList.contains(compare.getParentId())) {
BOMCompareBean bean = beans.get(idList.get(cid));
bean.addNum_Old(compare.getNum_Old());
bean.addNum_New(compare.getNum_New());
parentList.add(compare.getParentId());
}
continue;
}
beans.addAll(compares);
parentList.add(compare.getParentId());
idList.put(cid, beans.size());
beans.add(compare);
}
}
System.out.println("读取变更----结束");
win.unlock();
win.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
}
// for(int i = beans.size() - 1; i >= 0; i--) {
// BOMCompareBean bean = beans.get(i);
// if(bean.getNum_Old() != null && bean.getNum_New() != null) {
// if(bean.getNum_Old().equals(bean.getNum_New()))
// beans.remove(i);
// else if(!bean.getNum_Old().isEmpty() && !bean.getNum_New().isEmpty())
// bean.setChangeType("物料数量变更");
// }
// }
System.out.println("读取变更----结束");
win.unlock();
win.close();
// win2.unlock();
// win2.close();
}
/**
*
*
*
* @param revType
* @param rev
* @param con
* @throws SQLException
*/
public static boolean isVirtual(TCComponentItemRevision rev) throws SQLException {
public static boolean isShiti(TCComponentItemRevision rev) throws Exception {
/**
* ,
*/
ResultSet rs = SqlUtil.read(SQL_Process, new Object[] { rev.getUid() });
String puid = "";
String uid = rev.getUid();
if(shitiMap.containsKey(uid))
return shitiMap.get(uid);
ResultSet rs = SqlUtil.read(SQL_Process, new Object[] { uid });
// String puid = "";
if (rs.next()) {
puid = rs.getString(1);
// puid = rs.getString(1);
shitiMap.put(uid, true);
SqlUtil.free();
System.out.println(puid + "-----实体图纸:" + rev);
// System.out.println(puid + "-----实体图纸:" + rev);
return true;
}
System.out.println(puid + "-----虚拟图纸:" + rev);
// System.out.println(puid + "-----虚拟图纸:" + rev);
shitiMap.put(uid, false);
SqlUtil.free();
return false;
}
public static void bomCompare_M006(BOMDifferenceBean parentBean, TCSession session, double parent_quantity_old,
double parent_quantity_new, List<BOMCompareBean> beans, boolean isAddVis, boolean isRepeat,
List<TCComponentItem> item_compares, Map<TCComponentItem, BOMDifferenceBean> map_item_beans,
Map<TCComponentItem, BOMDifferenceBean> map_childs, int level) throws TCException, SQLException {
List<TCComponentItem> item_compares, HashMap<String, BOMDifferenceBean> map_item_beans,
HashMap<TCComponentItem, BOMDifferenceBean> map_childs, int level) throws Exception {
if (level > 0 && map_item_beans.containsKey(parentBean.getItem())) {
System.out.println("包含父子项-------:" + parentBean.getItem() + "||" + parentBean);
TCComponentItem patentItem = parentBean.getItem();
/*String id = patentItem.getProperty("item_id");
if (level > 0 && map_item_beans.containsKey(id)) {
System.out.println("包含父子项-------:" + id + "||" + parentBean);
BOMDifferenceBean bomDifferenceBean = map_item_beans.get(parentBean.getItem());
BOMDifferenceBean bomDifferenceBean = map_item_beans.get(id);
double oldQuantity = bomDifferenceBean.getOldQuantity();
double newQuantity = bomDifferenceBean.getNewQuantity();
System.out.println("已经存在?-------:" + newQuantity + "||" + oldQuantity);
@ -229,60 +301,75 @@ public class CreateBOMDifference_GKController {
bomDifferenceBean.setOldQuantity(parentBean.getOldQuantity()+oldQuantity);
bomDifferenceBean.setNewQuantity(parentBean.getNewQuantity()+newQuantity);
// }
map_item_beans.put(parentBean.getItem(), bomDifferenceBean);
map_item_beans.put(id, bomDifferenceBean);
map_childs.put(parentBean.getItem(), parentBean);
return;
}
*/
// if (item_compares.indexOf(parentBean.getItem()) != -1 && !isRepeat) {
// System.out.println("已添加过" + parentBean.getItem());
// return;
// }
System.out.println("未添加过:" + parentBean.getItem());
item_compares.add(parentBean.getItem());
TCComponentBOMLine parentLine_old = parentBean.getOldBOMLine();
TCComponentBOMLine parentLine_new = parentBean.getNewBOMLine();
System.out.println("未添加过:" + patentItem);
item_compares.add(patentItem);
// TCComponentBOMLine parentLine_old = parentBean.getOldBOMLine();
// TCComponentBOMLine parentLine_new = parentBean.getNewBOMLine();
TCComponentItemRevision parentLine_old = parentBean.getOldRev();
TCComponentItemRevision parentLine_new = parentBean.getNewRev();
System.out.println("比较:" + parentLine_old + "--" + parent_quantity_old + "||" + parentLine_new + "--"
+ parent_quantity_new);
BOMDifferenceBean bean;
Map<TCComponentItem, BOMDifferenceBean> map_child_beans = new HashMap<>();
HashMap<String, BOMDifferenceBean> map_child_beans = new HashMap<>();
TCComponentItemRevision oldPartRev = null;
TCComponentItemRevision newPartRev = null;
// 物料数量
String bl_quantity;
// String bl_quantity;
double quantity;
String rev_object_type;
if (parentLine_new != null) {
TCComponentItem item = null;
TCComponentItemRevision rev = null;
TCComponentBOMLine line;
AIFComponentContext[] childs_new = parentLine_new.getChildren();
for (int i = 0, len = childs_new.length; i < len; i++) {
line = (TCComponentBOMLine) childs_new[i].getComponent();
rev = line.getItemRevision();
item = rev.getItem();
bean = map_child_beans.get(item);
newPartRev = SAPUtil.getSAPPart(line, session);
if (newPartRev == null) {
continue;
}
bl_quantity = line.getProperty("bl_quantity");
if (bl_quantity == null || bl_quantity.trim().length() == 0) {
bl_quantity = "1";
}
quantity = Double.parseDouble(bl_quantity) * parent_quantity_new;
if (bean == null) {
bean = new BOMDifferenceBean();
bean.setItem(item);
rev_object_type = rev.getType();
bean.setRev_object_type(rev_object_type);
bean.setNewPartRev(newPartRev);
// AIFComponentContext[] childs_new = parentLine_new.getChildren();
// for (int i = 0, len = childs_new.length; i < len; i++) {
String revS = parentLine_new.toString();
if(newStBomMap.containsKey(revS)) {
for(Object[] c : newStBomMap.get(revS)) {
// line = (TCComponentBOMLine) childs_new[i].getComponent();
line = (TCComponentBOMLine) c[0];
rev = (TCComponentItemRevision) c[1];
// bom = (TCComponentBOMLine) c[2];
item = rev.getItem();
String id = item.getProperty("item_id");
bean = map_child_beans.get(id);
newPartRev = SAPUtil.getSAPPart(line, session);
// System.out.println("newPartRev" + rev + "==" + line + ">>" + newPartRev);
if (newPartRev == null) {
continue;
}
// bl_quantity = line.getProperty("bl_quantity");
// if (bl_quantity == null || bl_quantity.trim().length() == 0) {
// bl_quantity = "1";
// }
// quantity = Double.parseDouble(bl_quantity) * parent_quantity_new;
quantity = (double) c[3];
// System.out.println(revS + "==>" + rev + "*" + quantity);
if (bean == null) {
bean = new BOMDifferenceBean();
bean.setItem(item);
rev_object_type = rev.getType();
bean.setRev_object_type(rev_object_type);
bean.setNewPartRev(newPartRev);
}
bean.setNewRev(rev);
// bean.setNewBOMLine(bom);
bean.addNewQuantity(quantity);
map_child_beans.put(id, bean);
}
bean.setNewRev(rev);
bean.setNewBOMLine(line);
bean.addNewQuantity(quantity);
map_child_beans.put(item, bean);
}else {
System.out.println("newBomMap未添加过:" + revS);
}
}
@ -290,34 +377,47 @@ public class CreateBOMDifference_GKController {
TCComponentItem item = null;
TCComponentItemRevision rev = null;
TCComponentBOMLine line;
AIFComponentContext[] childs_old = parentLine_old.getChildren();
for (int i = 0, len = childs_old.length; i < len; i++) {
line = (TCComponentBOMLine) childs_old[i].getComponent();
rev = line.getItemRevision();
item = rev.getItem();
bean = map_child_beans.get(item);
oldPartRev = SAPUtil.getSAPPart(line, session);
if (oldPartRev == null) {
continue;
}
bl_quantity = line.getProperty("bl_quantity");
if (bl_quantity == null || bl_quantity.trim().length() == 0) {
bl_quantity = "1";
}
quantity = Double.parseDouble(bl_quantity) * parent_quantity_old;
// ExpandPSData[] bom;
// AIFComponentContext[] childs_old = parentLine_old.getChildren();
// for (int i = 0, len = childs_old.length; i < len; i++) {
String revS = parentLine_old.toString();
if(oldStBomMap.containsKey(revS)) {
for(Object[] c : oldStBomMap.get(revS)) {
// line = (TCComponentBOMLine) childs_old[i].getComponent();
// rev = line.getItemRevision();
line = (TCComponentBOMLine) c[0];
rev = (TCComponentItemRevision) c[1];
// bom = (ExpandPSData[]) c[2];
item = rev.getItem();
String id = item.getProperty("item_id");
bean = map_child_beans.get(id);
oldPartRev = SAPUtil.getSAPPart(line, session);
// System.out.println("oldPartRev" + rev + "==" + line + ">>" + newPartRev);
if (oldPartRev == null) {
continue;
}
// bl_quantity = line.getProperty("bl_quantity");
// if (bl_quantity == null || bl_quantity.trim().length() == 0) {
// bl_quantity = "1";
// }
// quantity = Double.parseDouble(bl_quantity) * parent_quantity_old;
quantity = (double) c[3];
// System.out.println(revS + "==>" + rev + "*" + quantity);
if (bean == null) {
bean = new BOMDifferenceBean();
bean.setItem(item);
rev_object_type = rev.getType();
bean.setRev_object_type(rev_object_type);
if (bean == null) {
bean = new BOMDifferenceBean();
bean.setItem(item);
rev_object_type = rev.getType();
bean.setRev_object_type(rev_object_type);
}
bean.setOldRev(rev);
// bean.setOldBOMLine(bom);
bean.setOldPartRev(oldPartRev);
bean.addOldQuantity(quantity);
map_child_beans.put(id, bean);
}
bean.setOldRev(rev);
bean.setOldBOMLine(line);
bean.setOldPartRev(oldPartRev);
bean.addOldQuantity(quantity);
map_child_beans.put(item, bean);
}else {
System.out.println("oldBomMap未添加过:" + revS);
}
}
@ -344,8 +444,10 @@ public class CreateBOMDifference_GKController {
object_desc_Parent = parentBean.getObject_name_Parent();
}
for (Entry<TCComponentItem, BOMDifferenceBean> entry : map_child_beans.entrySet()) {
bean = entry.getValue();
// for (Entry<TCComponentItem, BOMDifferenceBean> entry : map_child_beans.entrySet()) {
// bean = entry.getValue();
for (String id : map_child_beans.keySet()) {
bean = map_child_beans.get(id);
oldPartRev = bean.getOldPartRev();
newPartRev = bean.getNewPartRev();
System.out.println(bean.getItem() + " BOMDifferenceBean:" + bean);
@ -361,19 +463,21 @@ public class CreateBOMDifference_GKController {
// 物料删除 若变更项不为虚拟项则记录
if ("ZT2_Design3DRevision".equals(bean.getRev_object_type())) {
zt2_Source = bean.getOldRev().getProperty("zt2_Source");
if (bean.getOldBOMLine().getChildrenCount() == 0 || "外购".equals(zt2_Source)) {
// if (bean.getOldBOMLine().getChildrenCount() == 0 || "外购".equals(zt2_Source)) {
if (bomMap.get(rev.toString()).length == 0 || "外购".equals(zt2_Source)) {
// 到此为止,不继续展开
compareBean = new BOMCompareBean("物料删除", zt2_MaterialNo_Parent, object_desc_Parent,
zt2_MaterialNo_Old, object_desc_Old, num_Old, "", "", "");
beans.add(compareBean);
} else if ("自制".equals(zt2_Source)) {
// 实体层
if (isVirtual(rev)) {
if (isShiti(rev)) {
compareBean = new BOMCompareBean("物料删除", zt2_MaterialNo_Parent, object_desc_Parent,
zt2_MaterialNo_Old, object_desc_Old, num_Old, "", "", "");
beans.add(compareBean);
bomCompare_M006(bean, session, 1, 1, beans, false, isRepeat, item_compares, map_item_beans,
map_childs, level + 1);
//TODO 删除的实体件不显示子项删除
// bomCompare_M006(bean, session, 1, 1, beans, false, isRepeat, item_compares, map_item_beans,
// map_childs, level + 1);
} else {
// 虚拟层
bean.setParentPartRev(oldPartRev);
@ -405,18 +509,20 @@ public class CreateBOMDifference_GKController {
System.out.println("**物料新增**:" + rev);
if ("ZT2_Design3DRevision".equals(bean.getRev_object_type())) {
zt2_Source = bean.getNewRev().getProperty("zt2_Source");
if (bean.getNewBOMLine().getChildrenCount() == 0 || "外购".equals(zt2_Source)) {
// if (bean.getNewBOMLine().getChildrenCount() == 0 || "外购".equals(zt2_Source)) {
if (bomMap.get(rev.toString()).length == 0 || "外购".equals(zt2_Source)) {
compareBean = new BOMCompareBean("物料新增", zt2_MaterialNo_Parent, object_desc_Parent, "", "", "",
zt2_MaterialNo_New, object_desc_New, num_New);
beans.add(compareBean);
System.out.println(bean.getItem() + "--新增--" + compareBean);
} else if ("自制".equals(zt2_Source)) {
if (isVirtual(rev)) {
if (isShiti(rev)) {
compareBean = new BOMCompareBean("物料新增", zt2_MaterialNo_Parent, object_desc_Parent, "", "",
"", zt2_MaterialNo_New, object_desc_New, num_New);
beans.add(compareBean);
bomCompare_M006(bean, session, 1, 1, beans, isAddVis, isRepeat, item_compares,
map_item_beans, map_childs, level + 1);
//TODO 新增的实体件不显示子项新增
// bomCompare_M006(bean, session, 1, 1, beans, isAddVis, isRepeat, item_compares,
// map_item_beans, map_childs, level + 1);
} else {
bean.setZt2_MaterialNo_Parent(zt2_MaterialNo_Parent);
bean.setObject_desc_Parent(object_desc_Parent);
@ -467,22 +573,24 @@ public class CreateBOMDifference_GKController {
if ("ZT2_Design3DRevision".equals(bean.getRev_object_type())) {
zt2_Source = bean.getNewRev().getProperty("zt2_Source");
if (bean.getNewBOMLine().getChildrenCount() == 0 || "外购".equals(zt2_Source)) {
// if (bean.getNewBOMLine().getChildrenCount() == 0 || "外购".equals(zt2_Source)) {
if (bomMap.get(rev.toString()).length == 0 || "外购".equals(zt2_Source)) {
if (compareBean != null) {
System.out.println(bean.getItem() + "--数量变化新增(实)--" + compareBean);
beans.add(compareBean);
}
} else if ("自制".equals(zt2_Source)) {
// 实体层
if (isVirtual(rev)) {
if (isShiti(rev)) {
bean.setZt2_MaterialNo_Parent(zt2_MaterialNo_New);
bean.setObject_desc_Parent(object_desc_New);
if (compareBean != null) {
System.out.println(bean.getItem() + "--数量变化新增(实)--" + compareBean);
beans.add(compareBean);
}
bomCompare_M006(bean, session, 1, 1, beans, isAddVis, isRepeat, item_compares,
map_item_beans, map_childs, level + 1);
//TODO 实体件不显示子项数量变化
// bomCompare_M006(bean, session, 1, 1, beans, isAddVis, isRepeat, item_compares,
// map_item_beans, map_childs, level + 1);
} else {
if (compareBean != null && isAddVis) {
@ -523,18 +631,19 @@ public class CreateBOMDifference_GKController {
System.out.println("物料变更");
if ("ZT2_Design3DRevision".equals(bean.getRev_object_type())) {
zt2_Source = bean.getNewRev().getProperty("zt2_Source");
if (bean.getNewBOMLine().getChildrenCount() == 0 || "外购".equals(zt2_Source)) {
// if (bean.getNewBOMLine().getChildrenCount() == 0 || "外购".equals(zt2_Source)) {
if (bomMap.get(rev.toString()).length == 0 || "外购".equals(zt2_Source)) {
if (compareBean != null) {
System.out.println(bean.getItem() + "--物料变更(实)--" + compareBean);
beans.add(compareBean);
}
} else if ("自制".equals(zt2_Source)) {
// 实体层
if (isVirtual(rev)) {
if (isShiti(rev)) {
bean.setZt2_MaterialNo_Parent(zt2_MaterialNo_New);
bean.setObject_desc_Parent(object_desc_New);
bomCompare_M006(bean, session, 1, 1, beans, isAddVis, isRepeat, item_compares,
map_item_beans, map_childs, level + 1);
// bomCompare_M006(bean, session, 1, 1, beans, isAddVis, isRepeat, item_compares,
// map_item_beans, map_childs, level + 1);
} else {
// 虚拟层
bean.setZt2_MaterialNo_Parent(zt2_MaterialNo_Parent);
@ -553,5 +662,127 @@ public class CreateBOMDifference_GKController {
}
}
}
/**
* BOMBOMMap
* @param parent BOM
* @param uid object_string//UID
* @param isOld or
* @param bomWinType BOM
* @param map_item_beans
* @param count
*/
private static void recycleBom(String parent, String uid, boolean isOld, TCComponentBOMWindowType bomWinType,
HashMap<String, BOMDifferenceBean> map_item_beans, Double count, StructureManagement structureService) throws Exception {
// if(isOld && oldBomMap.containsKey(uid) || !isOld && newBomMap.containsKey(uid))
// return;
// System.out.println("recycleBom:" + parent + "==" + parent.getChildren().length);
// for(AIFComponentContext c : parent.getChildren()) {
for(ExpandPSData data : bomMap.get(parent)) {
TCComponentBOMLine line = data.bomLine;//(TCComponentBOMLine) c.getComponent(), bom;
System.out.println("recycleBom:" + uid + "==" + parent + ">>" + line);
ExpandPSData[] bom = new ExpandPSData[0];
TCComponentItemRevision rev;
String id = data.itemRevOfBOMLine.getProperty("item_id");
if(map_item_beans.containsKey(id)) {
//由于BOM可能为非精确因此变更前后关系下的对象版本代替现有版本
if(isOld)
rev = map_item_beans.get(id).getOldRev();
else
rev = map_item_beans.get(id).getNewRev();
getBomLineTreeNodeSOA(rev, structureService, bomWinType);
bom = bomMap.get(rev.toString());
}else {
rev = data.itemRevOfBOMLine;
if(bomMap.containsKey(rev.toString()))
bom = bomMap.get(rev.toString());
}
boolean part = !rev.getType().equals("ZT2_Design3DRevision");
String bl_quantity = line.getProperty("bl_quantity");
Double qty = (bl_quantity.isEmpty() ? 1 : Double.parseDouble(bl_quantity)) * count;
if((part && bom.length == 0) || rev.getProperty("zt2_Source").equals("外购")) {
// System.out.println("bom:" + uid + "==" + bom);
//外购就是实体不用看工艺BOM也不需要展开处理
if(isOld) {
if(!oldStBomMap.containsKey(uid))
oldStBomMap.put(uid, new ArrayList<>());
oldStBomMap.get(uid).add(new Object[] { line, rev, bom, qty });
}else {
if(!newStBomMap.containsKey(uid))
newStBomMap.put(uid, new ArrayList<>());
newStBomMap.get(uid).add(new Object[] { line, rev, bom, qty });
}
}else if(!part && isShiti(rev)) {
if(isOld) {
if(!oldStBomMap.containsKey(uid))
oldStBomMap.put(uid, new ArrayList<>());
oldStBomMap.get(uid).add(new Object[] { line, rev, bom, qty });
// System.out.println("oldBomMap:" + uid + "==" + bom);
//如果图纸或物料的实体件只有变更后一个版本,则当前数据不需要作为变更差异父件,即不体现。
if(!map_item_beans.containsKey(id) || map_item_beans.get(id).getNewRev() != null)
recycleBom(rev.toString(), rev.toString(), isOld, bomWinType, map_item_beans, 1.0, structureService);
}else {
if(!newStBomMap.containsKey(uid))
newStBomMap.put(uid, new ArrayList<>());
newStBomMap.get(uid).add(new Object[] { line, rev, bom, qty });
// System.out.println("newBomMap:" + uid + "==" + bom);
//如果图纸或物料的实体件只有变更后一个版本,则当前数据不需要作为变更差异父件,即不体现。
if(!map_item_beans.containsKey(id) || map_item_beans.get(id).getOldRev() != null)
recycleBom(rev.toString(), rev.toString(), isOld, bomWinType, map_item_beans, 1.0, structureService);
}
}else {
// System.out.println("bom:" + uid + "==" + bom);
//虚拟BOM进行消层
recycleBom(rev.toString(), uid, isOld, bomWinType, map_item_beans, qty, structureService);
}
}
}
/**
* BomMap
* @param map BomMap
* @return BomMap
*/
private static String printBomMap(HashMap<String, ArrayList<Object[]>> map) {
StringBuilder str = new StringBuilder("");
for(String s : map.keySet()) {
str.append(s).append("=[");
for(Object[] bojs : map.get(s)) {
str.append(bojs[1]).append("*").append(bojs[3]).append(";");
}
str.append("]\n");
}
return str.toString();
}
/**
* SOABOMbomMapStructureManagement
* @param bomLine BOM
* @param structureService StructureManagement
*/
private static void getBomLineTreeNodeSOA(TCComponentItemRevision rev, StructureManagement structureService, TCComponentBOMWindowType bomWinType) throws Exception {
if(bomMap.containsKey(rev.toString()))
return;
TCComponentBOMWindow win = bomWinType.create(null);
TCComponentBOMLine bomLine = win.setWindowTopLine(rev.getItem(), rev, null, null);
// 调用SOA方法批量展开BOM
// com.teamcenter.services.rac.cad._2007_01.StructureManagement structureService = com.teamcenter.services.rac.cad.StructureManagementService.getService(RACUIUtil.getTCSession());
com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSAllLevelsInfo levelInfo = new com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSAllLevelsInfo();
com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSAllLevelsPref levelPref = new com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSAllLevelsPref();
levelInfo.parentBomLines = new TCComponentBOMLine[] { bomLine }; //输入顶层BOMLine对象
levelInfo.excludeFilter = "None";//zt2_BOMMaterial
levelPref.expItemRev = false;
levelPref.info = new com.teamcenter.services.rac.cad._2007_01.StructureManagement.RelationAndTypesFilter[0];
// levelPref.info[0].relationName = "";
//使用以下方法展开完整的BOM行
com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSAllLevelsResponse levelResp = structureService.expandPSAllLevels(levelInfo, levelPref);
if (levelResp.output.length > 0) {
//将BOM构建成uid父子对关系
for (ExpandPSAllLevelsOutput data : levelResp.output) {
ExpandPSData[] children = data.children;
TCComponentItemRevision parentBomLine = data.parent.itemRevOfBOMLine;
bomMap.put(parentBomLine.toString(), children);
}
}else {
bomMap.put(rev.toString(), new ExpandPSData[0]);
}
win.close();
}
}

@ -19,6 +19,7 @@ import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableColumnModel;
import com.connor.chint.sap2.util.ChintPreferenceUtil;
import com.connor.chint.sap2.util.KUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFDialog;
@ -27,6 +28,11 @@ import com.teamcenter.rac.util.MessageBox;
public class AProjectNoDialog extends AbstractAIFDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
private AProjectNoController controller;
private JButton assign;
private JButton b_ok;
@ -35,21 +41,21 @@ public class AProjectNoDialog extends AbstractAIFDialog {
public static final String[] HEADER = new String[] { "产品代号", "产品特征号", "年代号", "顺序号" };
public static final int[] HEADERWIDTH = new int[] { 180, 180, 180, 180 };
private AbstractAIFApplication app;
// private AbstractAIFApplication app;
private TCSession session;
public AProjectNoDialog(AbstractAIFApplication app) {
super(false);
this.app = app;
// this.app = app;
this.session = (TCSession) app.getSession();
this.controller = new AProjectNoController(app, this);
}
public AProjectNoDialog(Frame paramFrame, AbstractAIFApplication app) {
// TODO Auto-generated constructor stub
// Auto-generated constructor stub
super(paramFrame, false);
this.app = app;
// this.app = app;
this.session = (TCSession) app.getSession();
this.controller = new AProjectNoController(app, this);
}
@ -107,7 +113,7 @@ public class AProjectNoDialog extends AbstractAIFDialog {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
// Auto-generated method stub
try {
String cpdh = (String) tm_part.getValueAt(0, 0);
String cptzz = (String) tm_part.getValueAt(0, 1);
@ -140,7 +146,7 @@ public class AProjectNoDialog extends AbstractAIFDialog {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
// Auto-generated method stub
try {
String flowNo = (String) tm_part.getValueAt(0, 3);
String cpdh = (String) tm_part.getValueAt(0, 0);
@ -174,7 +180,7 @@ public class AProjectNoDialog extends AbstractAIFDialog {
@Override
public void tableChanged(TableModelEvent e) {
// TODO Auto-generated method stub
// Auto-generated method stub
int col = e.getColumn();
int row = e.getFirstRow();
if (col < 2) {
@ -226,25 +232,33 @@ public class AProjectNoDialog extends AbstractAIFDialog {
for (int i = 0; i < colCnt; i++) {
colModel.getColumn(i).setPreferredWidth(HEADERWIDTH[i]);
}
String[] prefs = ChintPreferenceUtil.getPreferences("CHINT_M006_PROJNO", session);
JComboBox<String> com = new JComboBox<String>();
com.addItem("");
com.addItem("H");
com.addItem("CB");
com.addItem("GW");
for(String s : prefs[0].split(";")) {
com.addItem(s);
}
// com.addItem("H");
// com.addItem("CB");
// com.addItem("GW");
t_part.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(com));
JComboBox<String> com2 = new JComboBox<String>();
com2.addItem("");
com2.addItem("G");
com2.addItem("F");
com2.addItem("E");
com2.addItem("D");
String cpdhs[] = new String[] { "", "H", "CB", "GW" };
String cptzhs[] = new String[] { "", "G", "F", "E", "D" };
for(String s : prefs[1].split(";")) {
com2.addItem(s);
}
// com2.addItem("G");
// com2.addItem("F");
// com2.addItem("E");
// com2.addItem("D");
// String cpdhs[] = new String[] { "", "H", "CB", "GW" };
// String cptzhs[] = new String[] { "", "G", "F", "E", "D" };
t_part.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(com2));
tm_part.addRow(new Vector<String>());
JScrollPane scroll = new JScrollPane(t_part);
scroll.setPreferredSize(new Dimension(452, 48));
scroll.setPreferredSize(new Dimension(452, 120));//48
@SuppressWarnings("deprecation")
int year = new Date().getYear();
year = year % 100;
tm_part.setValueAt("" + year, 0, 2);
@ -253,9 +267,9 @@ public class AProjectNoDialog extends AbstractAIFDialog {
return panel;
}
private void setCompEnabled(boolean b) {
assign.setEnabled(b);
b_ok.setEnabled(b);
}
// private void setCompEnabled(boolean b) {
// assign.setEnabled(b);
// b_ok.setEnabled(b);
// }
}

@ -214,15 +214,15 @@ public class GetDesignDsCommand extends KCommand{
esbMap.put("xmzx", replaceAll);
esbMap.put("project", projectUid);
esbMap.put("wbsno", project.getStringProperty("zt2_WBSNo"));
esbMap.put("path",pathList);
esbMap.put("path", pathList);
String jsonString = JSON.toJSONString(esbMap);
System.out.println("jsonString==>" + jsonString);
if(actionInfo.equals("BOM")) {
WebApiUtil.httpSapRequest(values+"/connor/Clone/createBOM","POST",
jsonString,1);
WebApiUtil.httpSapRequest(values + "/connor/Clone/createBOM", "POST",
jsonString, 1);
}else {
WebApiUtil.httpSapRequest(values+"/connor/Clone/createDesignDateset","POST",
jsonString,1);
WebApiUtil.httpSapRequest(values + "/connor/Clone/createDesignDateset", "POST",
jsonString, 1);
}
}else {

@ -0,0 +1,115 @@
package com.connor.chint.sap2.materialno;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import com.connor.chint.sap2.util.ChintPreferenceUtil;
import com.connor.chint.sap2.util.SqlUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFDialog;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class FactoryChooseDialog extends AbstractAIFDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
private boolean update;
public FactoryChooseDialog(AbstractAIFApplication app, TCSession session, String groupID) {
super(true);
try {
String[] database = ChintPreferenceUtil.getPreferences("database_tc", session);
if (SqlUtil.getTCDataConnection(database) == null) {
MessageBox.post("数据库连接失败,请检查首选项<database_tc>", "", 2);
return;
}
String user = session.getUser().getUserId();
update = false;
String sql = "select \"factory\" from CHINT_MATERIAL_APPLY_RULE where \"userid\"='" + user + "'";
System.out.println("sql:\n" + sql);
ResultSet rs = SqlUtil.read(sql);
String defaultGroup = "";
if(rs.next()) {
defaultGroup = rs.getString(1);
update = true;
}
String[] applys = ChintPreferenceUtil.getPreferences("CHINT_MATERIAL_APPLY_LIST", session);
JComboBox<String> j_Group = new JComboBox<>();
j_Group.setSize(new Dimension(150, 30));
j_Group.setPreferredSize(new Dimension(130, 30));
j_Group.addItem("");
for(String s : applys) {
j_Group.addItem(s);
}
j_Group.setSelectedItem(defaultGroup);
JButton okBtn = new JButton("确定");
okBtn.setSize(new Dimension(100, 30));
okBtn.setPreferredSize(new Dimension(90, 30));
okBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
String groupID = j_Group.getSelectedItem().toString();
if(groupID.isEmpty()) {
MessageBox.post(FactoryChooseDialog.this, "请选择组织", "", MessageBox.WARNING);
return;
}
String sql = "insert into CHINT_MATERIAL_APPLY_RULE values ('" + user + "','" + groupID + "')";
if(update)
sql = "update CHINT_MATERIAL_APPLY_RULE set \"factory\"='" + groupID + "' where \"userid\"='" + user + "'";
System.out.println("sql:\n" + sql);
SqlUtil.write(sql);
SqlUtil.freeAll();
groupID = groupID.substring(0, groupID.indexOf(":"));
System.out.println("groupID:" + groupID);
//TODO
// new Thread(new MaterialNoDialog(app, session, groupID)).start();
dispose();
}
});
JButton cancelBtn = new JButton("取消");
cancelBtn.setSize(new Dimension(100, 30));
cancelBtn.setPreferredSize(new Dimension(90, 30));
cancelBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
SqlUtil.freeAll();
dispose();
}
});
JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
panel.add(new JLabel("请选择组织:"));
panel.add(j_Group);
JPanel btnPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
btnPanel.add(okBtn);
btnPanel.add(cancelBtn);
this.setPreferredSize(new Dimension(500, 300));
this.setMinimumSize(new Dimension(400, 200));
this.setLayout(new BorderLayout());
this.add(BorderLayout.CENTER, panel);
this.add(BorderLayout.SOUTH, btnPanel);
setDefaultLookAndFeelDecorated(true);
Dimension screen = getToolkit().getScreenSize();
setLocation((screen.width - getSize().width) / 2, (screen.height - getSize().height) / 2);
this.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
MessageBox.post("错误:" + e, "", MessageBox.ERROR);
}
}
}

@ -773,6 +773,34 @@ public class MaterialNoDialog extends AbstractAIFDialog {
data.element("GoodsUsed", "3");
break;
}
// if(true)
//TODO 先组织数据,创建对象,写入数据库,调接口,判断是否保留物料和数据库
System.out.println("开始创建物料");
TCComponentItemRevision rev = createMaterial(goodsName, unitCode, companyCode, spec, teRe, uom,
t_pmcp.getCode());
System.out.println("创建物料结束:" + rev);
uid = rev.getUid();
TXTUtil.writeTXT(txtPath, "申请物料[CODE=" + code + ";PUID[" + uid + "]");
Object params[] = new Object[15];
params[0] = code;
params[1] = uid;
params[2] = t_pmcp.getCode();
params[3] = goodsCode;
params[4] = goodsName;
params[5] = unitCode;
params[6] = companyCode;
params[7] = bpNo;
params[8] = spec;
params[9] = teRe;
params[10] = state;
params[11] = user;
params[12] = time;
params[13] = condition;
params[14] = "";
checkData(params[0], params[1]);
System.out.println("执行的sql语句:" + sql + "\n" + Arrays.toString(params));
SqlUtil.write(sql, params);
JSONArray datas = new JSONArray();
datas.add(data);
@ -789,36 +817,18 @@ public class MaterialNoDialog extends AbstractAIFDialog {
TXTUtil.writeTXT(txtPath, "Json:" + obj.toString());
TXTUtil.writeTXT(txtPath, "返回结果:" + req);
// if(true)
if (req.indexOf(state1) != -1) {
if (req.indexOf(state1) == -1) {
System.out.println("删除对象:" + rev.getItem());
rev.getItem().delete();
//rev.delete();
String delete = "delete from chint_material where \"Code\"='" + code + "'";
SqlUtil.delete(delete);
System.out.println("删除记录结束:" + delete);
MessageBox.post("物料申请失败,提示:" + req, "", MessageBox.INFORMATION);
}else {
System.out.println("更新记录");
// TCComponentItemRevision partRev = null;
System.out.println("开始创建物料");
TCComponentItemRevision rev = createMaterial(goodsName, unitCode, companyCode, spec, teRe, uom,
t_pmcp.getCode());
uid = rev.getUid();
TXTUtil.writeTXT(txtPath, "申请物料[CODE=" + code + ";PUID[" + uid + "]");
System.out.println("创建物料结束");
Object params[] = new Object[15];
params[0] = code;
params[1] = uid;
params[2] = t_pmcp.getCode();
params[3] = goodsCode;
params[4] = goodsName;
params[5] = unitCode;
params[6] = companyCode;
params[7] = bpNo;
params[8] = spec;
params[9] = teRe;
params[10] = state;
params[11] = user;
params[12] = time;
params[13] = condition;
params[14] = "";
//TODO
checkData(params[0], params[1]);
System.out.println("执行的sql语句:" + sql + "\n" + Arrays.toString(params));
SqlUtil.write(sql, params);
checkData(params[0], params[1]);
newStuff.add("contents", rev.getItem());
if (!KUtil.isEmpty(design_ID)) {
@ -927,10 +937,6 @@ public class MaterialNoDialog extends AbstractAIFDialog {
if(!userId.equals("")) {
sendMsg(build.toString(),userId);
}
} else {
MessageBox.post("物料申请失败,提示:" + req, "", MessageBox.INFORMATION);
System.out.println("删除记录");
System.out.println("删除记录结束");
}
}
@ -1153,6 +1159,34 @@ public class MaterialNoDialog extends AbstractAIFDialog {
break;
}
//TODO 先组织数据,创建对象,写入数据库,调接口,判断是否保留物料和数据库
TCComponentItemRevision parent = null;
System.out.println("开始创建物料");
parent = createMaterial(goodsName, unitCode, companyCode, spec, teRe, uom, t_pmcp.getCode());
newStuff.add("contents", parent.getItem());
uid = parent.getUid();
TXTUtil.writeTXT(txtPath, "申请物料[CODE=" + code + ";PUID[" + uid + "]");
System.out.println("创建物料结束");
Object params[] = new Object[15];
params[0] = code;
params[1] = uid;
params[2] = t_pmcp.getCode();
params[3] = goodsCode;
params[4] = goodsName;
params[5] = unitCode;
params[6] = companyCode;
params[7] = bpNo;
params[8] = spec;
params[9] = teRe;
params[10] = state;
params[11] = user;
params[12] = time;
params[13] = condition;
params[14] = "";
System.out.println("执行的sql语句:" + sql);
SqlUtil.write(sql, params);
System.out.println("更新结束");
JSONArray datas = new JSONArray();
datas.add(data);
System.out.println("feature:" + feature);
@ -1169,41 +1203,18 @@ public class MaterialNoDialog extends AbstractAIFDialog {
// String sql2 = "delete from chint_material where \"Code\"=?";
String state1 = "\"State\":\"1\"";
// String state2 = "\"State\":\"-1\"";
TCComponentItemRevision parent = null;
TCComponentItemRevision child = null;
TXTUtil.writeTXT(txtPath, "Json:" + obj.toString());
TXTUtil.writeTXT(txtPath, "返回结果:" + req);
if (req.indexOf(state1) != -1) {
System.out.println("更新记录");
// TCComponentItemRevision partRev = null;
System.out.println("开始创建物料");
parent = createMaterial(goodsName, unitCode, companyCode, spec, teRe, uom, t_pmcp.getCode());
newStuff.add("contents", parent.getItem());
uid = parent.getUid();
TXTUtil.writeTXT(txtPath, "申请物料[CODE=" + code + ";PUID[" + uid + "]");
System.out.println("创建物料结束");
Object params[] = new Object[15];
params[0] = code;
params[1] = uid;
params[2] = t_pmcp.getCode();
params[3] = goodsCode;
params[4] = goodsName;
params[5] = unitCode;
params[6] = companyCode;
params[7] = bpNo;
params[8] = spec;
params[9] = teRe;
params[10] = state;
params[11] = user;
params[12] = time;
params[13] = condition;
params[14] = "";
System.out.println("执行的sql语句:" + sql);
SqlUtil.write(sql, params);
System.out.println("更新结束");
} else {
System.out.println("删除记录");
System.out.println("删除记录结束");
System.out.println("删除记录:" + parent.getItem());
parent.getItem().delete();
// parent.delete();
String delete = "delete from chint_material where \"Code\"='" + code + "'";
SqlUtil.delete(delete);
System.out.println("删除记录结束:" + delete);
MessageBox.post("物料申请失败,提示:" + req, "", MessageBox.INFORMATION);
return;
@ -1233,6 +1244,33 @@ public class MaterialNoDialog extends AbstractAIFDialog {
datas2.add(data2);
code = KUtil.getCode();
//TODO 先组织数据,创建对象,写入数据库,调接口,判断是否保留物料和数据库
TCComponentItemRevision child = null;
System.out.println("开始创建物料");
child = createMaterial(goodsName, unitCode, companyCode, spec, teRe2, uom, t_pmcp.getCode());
newStuff.add("contents", child.getItem());
uid = child.getUid();
TXTUtil.writeTXT(txtPath, "申请物料[CODE=" + code + ";PUID[" + uid + "]");
System.out.println("创建物料结束");
params = new Object[15];
params[0] = code;
params[1] = uid;
params[2] = t_pmcp.getCode();
params[3] = goodsCode;
params[4] = goodsName;
params[5] = unitCode;
params[6] = companyCode;
params[7] = bpNo;
params[8] = spec;
params[9] = teRe2;
params[10] = state;
params[11] = user;
params[12] = time;
params[13] = condition;
params[14] = "";
System.out.println("执行的sql语句:" + sql);
SqlUtil.write(sql, params);
JSONObject obj2 = new JSONObject();
obj2.element("Code", code);
obj2.element("Data", datas2);
@ -1245,33 +1283,15 @@ public class MaterialNoDialog extends AbstractAIFDialog {
if (req.indexOf(state1) != -1) {
System.out.println("更新记录");
// TCComponentItemRevision partRev = null;
System.out.println("开始创建物料");
child = createMaterial(goodsName, unitCode, companyCode, spec, teRe2, uom, t_pmcp.getCode());
newStuff.add("contents", child.getItem());
uid = child.getUid();
TXTUtil.writeTXT(txtPath, "申请物料[CODE=" + code + ";PUID[" + uid + "]");
System.out.println("创建物料结束");
Object params[] = new Object[15];
params[0] = code;
params[1] = uid;
params[2] = t_pmcp.getCode();
params[3] = goodsCode;
params[4] = goodsName;
params[5] = unitCode;
params[6] = companyCode;
params[7] = bpNo;
params[8] = spec;
params[9] = teRe2;
params[10] = state;
params[11] = user;
params[12] = time;
params[13] = condition;
params[14] = "";
System.out.println("执行的sql语句:" + sql);
SqlUtil.write(sql, params);
System.out.println("更新结束");
} else {
System.out.println("删除记录:" + child.getItem());
child.getItem().delete();
// child.delete();
String delete = "delete from chint_material where \"Code\"='" + code + "'";
SqlUtil.delete(delete);
System.out.println("删除记录结束:" + delete);
MessageBox.post("子件申请失败,提示:" + req, "", MessageBox.INFORMATION);
return;
}

@ -23,6 +23,7 @@ import com.connor.chint.sap2.util.BomToSapUtil;
import com.connor.chint.sap2.util.ChintPreferenceUtil;
import com.connor.chint.sap2.util.KUtil;
import com.connor.chint.sap2.util.ProgressBar;
import com.connor.chint.sap2.util.SAPUtil;
import com.connor.chint.sap2.util.SqlUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
@ -51,7 +52,7 @@ public class CreateProcZYDialogController {
private String group;
// private TCComponentGroup login_group = null;
private Map<String, TCComponent> mepMap = new HashMap<>();
private Map<String, TCComponentItemRevision> mepMap = new HashMap<>();
public CreateProcZYDialogController(CreateProcZYDialog createProcBYDialog, AbstractAIFApplication app) {
this.dialog = createProcBYDialog;
@ -196,7 +197,15 @@ public class CreateProcZYDialogController {
System.out.println("[ZT2_ClassificationNo=" + zt2_ClassificationCode + "]");
noList.add(zt2_ClassificationCode);
// ²éѯ²úÆ·¹¤ÒÕ
TCComponentItemRevision cpgy = (TCComponentItemRevision) getMeproces(comp.getUid(), session);
String uid = comp.getUid();
TCComponentItemRevision cpgy;// = (TCComponentItemRevision) getMeproces(comp.getUid(), session);
if(mepMap.containsKey(uid))
cpgy = mepMap.get(uid);
else {
cpgy = (TCComponentItemRevision) SAPUtil.getMeprocesYh(uid, group, session);
mepMap.put(uid, cpgy);
}
BYProcBean bean = new BYProcBean(procBeanList.size() + 1, comp, bzgys, cpgy, tlgx, topLine, cptlgx, parentRev);
zt2_ClassificationCode = comp.getProperty("zt2_ClassificationCode");
@ -524,7 +533,15 @@ public class CreateProcZYDialogController {
}
}
}*/
TCComponent meop = getMeproces(parent.getItemRevision().getUid(), session);
// TCComponent meop = getMeproces(parent.getItemRevision().getUid(), session);
String uid = parent.getItemRevision().getUid();
TCComponentItemRevision meop;// = (TCComponentItemRevision) getMeproces(comp.getUid(), session);
if(mepMap.containsKey(uid))
meop = mepMap.get(uid);
else {
meop = (TCComponentItemRevision) SAPUtil.getMeprocesYh(uid, group, session);
mepMap.put(uid, meop);
}
if(meop != null) {
flag = true;
if(!lists.contains(meop) && (meop instanceof TCComponentItemRevision))
@ -534,39 +551,6 @@ public class CreateProcZYDialogController {
getGX(parent, lists);
}
}
private TCComponent getMeproces(String uid, TCSession session) throws Exception {
//TODO getMeproces
if(mepMap.containsKey(uid)) {
return mepMap.get(uid);
}
// String sql = SAPUtil.sqlRef.replace("\\?", "'" + uid + "'");
String sql = "select P.puid as supItemUID,V.puid as supRevUID,P.pitem_id as supItemID,ITRO.Pobject_Name as supItemName,"
+ "V.Pitem_Revision_Id as supRevID,cP.pitem_id as subItemID,cV.puid as subRevUID,RT.partifactname as °æ±¾Óë°æ±¾¹ØÏµ "
+ "from PWORKSPACEOBJECT ITRO,PIMANRELATION R,PIMANTYPE RT,PITEMREVISION V,PITEM P,PITEMREVISION cV,PITEM cP,PWORKSPACEOBJECT cITRO,PPOM_APPLICATION_OBJECT g "
+ "where g.puid=V.puid and V.Puid = R.Rprimary_Objectu and r.rrelation_typeu = RT.puid and P.Puid = V.Ritems_Tagu and ITRO.Puid = V.Puid "
+ "and R.Rsecondary_Objectu = cV.Puid and cP.Puid = cV.Ritems_Tagu and cV.Puid = cITRO.Puid and ITRO.Pactive_Seq<>0 "
+ "and cITRO.Pactive_Seq<>0 and RT.partifactname='IMAN_METarget' and g.ROWNING_GROUPU='" + group + "' and cV.PUID = '" + uid + "'";
try {
ResultSet read = SqlUtil.read(sql);//SAPUtil.sqlRef, new Object[] { uid }
// boolean next = read.next();
while (read.next()) {
String string = read.getString("supRevUID");
TCComponent mpComp = session.stringToComponent(string);
// TCComponent mpComp = SAPUtil.getSameGroupProcYH(meops, session);
if(mpComp != null) {
mepMap.put(uid, mpComp);
// SqlUtil.free();
return mpComp;
}
}
// SqlUtil.free();
}catch(Exception e) {
System.out.println("sql==>" + sql);
e.printStackTrace();
}
return null;
}
public void assignProcess(ProgressBar pb) throws Exception {
if (this.procBeanList.size() == 0) {

@ -18,8 +18,6 @@ import javax.swing.table.TableColumnModel;
import com.connor.chint.sap2.create_proc.CreateProcBean;
import com.connor.chint.sap2.create_proc.CreateProcController;
import com.connor.chint.sap2.sap_zy.PartBean;
import com.connor.chint.sap2.sap_zy.SAPZYDialogzt;
import com.connor.chint.sap2.util.ConfirmDialogUtil;
import com.connor.chint.sap2.util.KUtil;
import com.connor.chint.sap2.util.MyProgressBarCompent;
@ -42,9 +40,14 @@ import plm.xi.com.chintelectric.SI_PUSH_BOM_PLM_OUT_SYNServiceLocator;
public class SAPZZDialog extends AbstractAIFDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
private SAPZZDialogController controller;
private JButton b_check;
private JButton b_bom;
private JButton b_qr3;// 异步传递;
protected DefaultTableModel tm_part;
protected JTable t_part;
@ -54,7 +57,7 @@ public class SAPZZDialog extends AbstractAIFDialog {
public static final String[] HEADER = new String[] { "", "序号", "出厂编号", "物料编码", "总装图样代号", "BOM确认状态", "确认人", "确认时间" };
public static final int[] HEADERWIDTH = new int[] { 50, 60, 120, 180, 180, 100, 100, 100 };
private AbstractAIFApplication app;
// private AbstractAIFApplication app;
private TCSession session;
protected JButton pushBOM_btn; // BOM确认
protected String materialCode = "";
@ -62,7 +65,7 @@ public class SAPZZDialog extends AbstractAIFDialog {
public SAPZZDialog(AbstractAIFApplication app) {
super(false);
this.controller = new SAPZZDialogController(this, app);
this.app = app;
// this.app = app;
this.session = (TCSession) app.getSession();
}
@ -140,6 +143,7 @@ public class SAPZZDialog extends AbstractAIFDialog {
b_bom.setEnabled(b);
t_part.setEnabled(b);
pushBOM_btn.setEnabled(b);
b_qr3.setEnabled(b);
}
private void addListeners() {
@ -273,12 +277,34 @@ public class SAPZZDialog extends AbstractAIFDialog {
}
});
b_qr3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new Thread(new Runnable() {
@Override
public void run() {
// String selectedItem = (String) comb.getSelectedItem();
try {
controller.sendToSapYHAsyn("产成品BOM传递", false);
} catch (Exception e) {
// Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
});
}
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)
@ -314,8 +340,11 @@ public class SAPZZDialog extends AbstractAIFDialog {
b_check = new JButton("检查");
b_bom = new JButton("BOM传递");
pushBOM_btn = new JButton("BOM确认");
b_qr3 = new JButton("异步传递");
panel.add(b_check);
panel.add(b_bom);
//TODO
// panel.add(b_qr3);
// panel.add(pushBOM_btn);
// 变压器BOM确认调整
JPanel panelt = new JPanel(new BorderLayout());

@ -1,15 +1,21 @@
package com.connor.chint.sap2.sap_by;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson2.JSONArray;
import com.connor.chint.sap2.sap.SAPPushBOMBean;
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.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
@ -191,6 +197,7 @@ public class SAPZZDialogController {
dialog.t_part.repaint();
}
@SuppressWarnings("deprecation")
public void sendToSap() throws Exception {
List<ZZPartBean> selectedParts = getSelectedParts();
int len = selectedParts == null ? 0 : selectedParts.size();
@ -281,5 +288,83 @@ public class SAPZZDialogController {
}
return selectedParts;
}
// 获取传递BOM中最大的序列
private int 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;
}
// 第二次优化异步传递
protected void sendToSapYHAsyn(String ban, boolean isCheckProduct) throws Exception {
List<ZZPartBean> selectedParts = getSelectedParts();
MyProgressBarCompent my = new MyProgressBarCompent("", "智能电气BOM传递SAP......");
try {
String strs[] = session.getPreferenceService().getStringValues("database_tc");
if (SqlUtil.getTCDataConnection(strs) == null) {
MessageBox.post("数据库连接失败,请检查首选项<database_tc>", "", 2);
return;
}
String groupID2 = SAPUtil.getGroupID();
String userId = session.getUser().getUserId();
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");
int code = getCode();
JSONArray array = new JSONArray();
StringBuilder uids = new StringBuilder("");
for (int i = 0; i < selectedParts.size(); i++) {
String uid = selectedParts.get(i).part.getUid();
array.add(uid);
uids.append(uid).append(":");
}
// obj.put("uid", array);
// OkHttpClient client = new OkHttpClient();
String substring = uids.substring(0, uids.length() - 1);
// 新增字段 项目UID执行人改成定时执行不调用接口
String serverHostname = session.getServerHostname();
System.out.println("serverHostname===>" + serverHostname);
String sql = "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')" + ",?,?,'等待组织','未处理',?,?,'未返回',?,?,?)"; // to_date(?,'yyyy-mm-ddhh24:mi:ss')
SqlUtil.write(sql, new String[] { code + "", groupID2, userName, dataTime, zt2_WBSNo, object_name,
ban.replaceAll("方案传递", ""), substring, project.getUid(), serverHostname, userId });
// MediaType mediaType = MediaType.parse("application/json");
// RequestBody body = RequestBody.create(mediaType, obj.toString());
//// String preference = ChintPreferenceUtil.getPreference("CHINT_PIUrl", session);
// Request request = new Request.Builder().url("http://10.128.10.203:8081/plm/sendBomXB") // http://10.128.10.203:8081/plm/sendBomXB
// .method("POST", body)
// // .addHeader("Cookie", "")
//// .addHeader("Authorization", "Bearer "+token)
// // .addHeader("Connection", "keep-alive")
// .addHeader("Content-Type", "application/json").build();
// Response response = client.newCall(request).execute();
// // response.body().byteStream()
// // System.out.println(response.body().string());
// String string = response.body().string();
// System.out.println("string==>" + string);
// JSONObject parseObject = JSON.parseObject(string);
//
// my.setVisible(false);
// System.out.println("parseObject==>" + parseObject);
MessageBox.post(dialog, "传递请求已记录,请等待飞书通知.", "", MessageBox.INFORMATION);
} catch (Exception e) {
MessageBox.post(dialog, "发生错误:" + e.getMessage(), "", MessageBox.ERROR);
e.printStackTrace();
my.setVisible(false);
} finally {
SqlUtil.freeAll();
my.setVisible(false);
}
}
}

@ -5449,7 +5449,7 @@ public class SAPUtil {
}
/*
* TODO
*
*/
public static void recurSAP2(TCComponentBOMLine line, TCComponentItemRevision rev, TCComponentItemRevision partRev,
boolean isStruct, TCSession session, String groupName, String now, String txtPath,
@ -6505,5 +6505,56 @@ public class SAPUtil {
}
return null;
}
/**
*
*
* @param uid
* @param group
* @param session session
* @return
* @throws Exception
*/
public static TCComponent getMeprocesYh(String uid, String group, TCSession session) throws Exception {
// String sql = SAPUtil.sqlRef.replace("\\?", "'" + uid + "'");
String sql = "select P.puid as supItemUID,V.puid as supRevUID,P.pitem_id as supItemID,ITRO.Pobject_Name as supItemName,"
+ "V.Pitem_Revision_Id as supRevID,cP.pitem_id as subItemID,cV.puid as subRevUID,RT.partifactname as 版本与版本关系 "
+ "from PWORKSPACEOBJECT ITRO,PIMANRELATION R,PIMANTYPE RT,PITEMREVISION V,PITEM P,PITEMREVISION cV,PITEM cP,PWORKSPACEOBJECT cITRO,PPOM_APPLICATION_OBJECT g "
+ "where g.puid=V.puid and V.Puid = R.Rprimary_Objectu and r.rrelation_typeu = RT.puid and P.Puid = V.Ritems_Tagu and ITRO.Puid = V.Puid "
+ "and R.Rsecondary_Objectu = cV.Puid and cP.Puid = cV.Ritems_Tagu and cV.Puid = cITRO.Puid and ITRO.Pactive_Seq<>0 "
+ "and cITRO.Pactive_Seq<>0 and RT.partifactname='IMAN_METarget' and g.ROWNING_GROUPU='" + group + "' and cV.PUID = '" + uid + "'";
try {
ResultSet read = SqlUtil.read(sql);//SAPUtil.sqlRef, new Object[] { uid }
// boolean next = read.next();
while (read.next()) {
String string = read.getString("supRevUID");
TCComponent mpComp = session.stringToComponent(string);
// TCComponent mpComp = SAPUtil.getSameGroupProcYH(meops, session);
if(mpComp != null) {
// mepMap.put(uid, mpComp);
// SqlUtil.free();
return mpComp;
}
}
// SqlUtil.free();
}catch(Exception e) {
System.out.println("sql==>" + sql);
e.printStackTrace();
}
return null;
}
/**
*
*
* @param array
* @param str
* @return
*/
public static boolean contains(Object[] array, Object str) {
for(Object s : array) {
// System.out.println("contains:"+s+"="+str);
if(s.equals(str))
return true;
}
return false;
}
}

@ -872,4 +872,46 @@ public class SqlUtil {
}
return connection;
}
public static Connection SRMGetTCDataConnection(String[] prefs) {
// System.out.println("getTCDataConnection(String[] prefs)");
String driver = reg.getString("SQL.TCDATA.DRIVER");
String url = reg.getString("SQL.TCDATA.URL");
String user = reg.getString("SQL.TCDATA.USER");
String password = reg.getString("SQL.TCDATA.PASSWORD");
if (prefs != null) {
url = "jdbc:oracle:thin:@" + prefs[5] + ":" + prefs[3] + ":" + prefs[4];
user = prefs[1];
password = prefs[2];
}
// System.out.println("连接数据库信息:");
// System.out.println("DRIVER: " + driver);
// System.out.println("URL: " + url);
// System.out.println("USER: " + user);
if (connection != null) {
try {
connection.close();
} catch (Exception e1) {
e1.printStackTrace();
}
connection = null;
}
try {
// 加载驱动程序
Class.forName(driver);
// 1.getConnection()方法连接MySQL数据库
connection = DriverManager.getConnection(url, user, password);
connection.setAutoCommit(false);
} catch (ClassNotFoundException e) {
// 数据库驱动类异常处理
System.out.println("未找到数据库驱动");
e.printStackTrace();
} catch (SQLException e) {
// 数据库连接失败异常处理
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}
}

Loading…
Cancel
Save