commit 4fd4bae3a3408660bca898d066f824c57b242880 Author: xiongcz Date: Tue Jun 3 18:25:22 2025 +0800 1 diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..e569049 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..35410ca --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# 默认忽略的文件 +/shelf/ +/workspace.xml +# 基于编辑器的 HTTP 客户端请求 +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/com.connor.bhdz.stoCapp.iml b/.idea/com.connor.bhdz.stoCapp.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/com.connor.bhdz.stoCapp.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..10ee7a7 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,18 @@ + + + + + oracle + true + false + oracle.jdbc.OracleDriver + jdbc:oracle:thin:@192.168.3.125:1521:TC12 + + + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..a77164b --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/git_toolbox_blame.xml b/.idea/git_toolbox_blame.xml new file mode 100644 index 0000000..7dc1249 --- /dev/null +++ b/.idea/git_toolbox_blame.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5d65af5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1e44437 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..3d6cb92 --- /dev/null +++ b/.project @@ -0,0 +1,28 @@ + + + com.connor.bhdz.stoCapp + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..0c68a61 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7759fad --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: StoCapp +Bundle-SymbolicName: com.connor.bhdz.stoCapp;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Vendor: CONNOR +Require-Bundle: org.eclipse.ui, + com.teamcenter.rac.aifrcp;bundle-version="12000.1.0", + com.teamcenter.rac.common;bundle-version="12000.1.0", + com.teamcenter.rac.kernel;bundle-version="12000.1.0", + com.teamcenter.rac.tcapps;bundle-version="12000.1.0", + com.teamcenter.rac.util;bundle-version="12000.1.0", + org.eclipse.core.runtime;bundle-version="3.12.0", + TcSoaWorkflowRac;bundle-version="12000.1.0" +Automatic-Module-Name: com.connor.bhdz.stoCapp +Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-ClassPath: ., + lib/ojdbc8.jar, + lib/hutool-all-5.8.33.jar +Export-Package: cn.hutool.core.collection, + com.connor.bhdz.pdm.drawingToCapp, + com.connor.bhdz.pdm.partToCapp diff --git a/bin/com/connor/bhdz/pdm/assets/Constants.class b/bin/com/connor/bhdz/pdm/assets/Constants.class new file mode 100644 index 0000000..5f85cf9 Binary files /dev/null and b/bin/com/connor/bhdz/pdm/assets/Constants.class differ diff --git a/bin/com/connor/bhdz/pdm/drawingToCapp/ConnOra.class b/bin/com/connor/bhdz/pdm/drawingToCapp/ConnOra.class new file mode 100644 index 0000000..63d5cf4 Binary files /dev/null and b/bin/com/connor/bhdz/pdm/drawingToCapp/ConnOra.class differ diff --git a/bin/com/connor/bhdz/pdm/drawingToCapp/DataBaseControl.class b/bin/com/connor/bhdz/pdm/drawingToCapp/DataBaseControl.class new file mode 100644 index 0000000..1536722 Binary files /dev/null and b/bin/com/connor/bhdz/pdm/drawingToCapp/DataBaseControl.class differ diff --git a/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressBar$1.class b/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressBar$1.class new file mode 100644 index 0000000..c463264 Binary files /dev/null and b/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressBar$1.class differ diff --git a/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressBar$TaskThread.class b/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressBar$TaskThread.class new file mode 100644 index 0000000..a424fc1 Binary files /dev/null and b/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressBar$TaskThread.class differ diff --git a/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressBar.class b/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressBar.class new file mode 100644 index 0000000..3d3532e Binary files /dev/null and b/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressBar.class differ diff --git a/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressBarThread.class b/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressBarThread.class new file mode 100644 index 0000000..6f5334f Binary files /dev/null and b/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressBarThread.class differ diff --git a/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressReporterDialog.class b/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressReporterDialog.class new file mode 100644 index 0000000..da03b84 Binary files /dev/null and b/bin/com/connor/bhdz/pdm/drawingToCapp/ProgressReporterDialog.class differ diff --git a/bin/com/connor/bhdz/pdm/drawingToCapp/SendDrawingToCappAction.class b/bin/com/connor/bhdz/pdm/drawingToCapp/SendDrawingToCappAction.class new file mode 100644 index 0000000..3e5456d Binary files /dev/null and b/bin/com/connor/bhdz/pdm/drawingToCapp/SendDrawingToCappAction.class differ diff --git a/bin/com/connor/bhdz/pdm/drawingToCapp/SendDrawingToCappHandler.class b/bin/com/connor/bhdz/pdm/drawingToCapp/SendDrawingToCappHandler.class new file mode 100644 index 0000000..5357bbd Binary files /dev/null and b/bin/com/connor/bhdz/pdm/drawingToCapp/SendDrawingToCappHandler.class differ diff --git a/bin/com/connor/bhdz/pdm/partToCapp/ConnOra.class b/bin/com/connor/bhdz/pdm/partToCapp/ConnOra.class new file mode 100644 index 0000000..a9992ce Binary files /dev/null and b/bin/com/connor/bhdz/pdm/partToCapp/ConnOra.class differ diff --git a/bin/com/connor/bhdz/pdm/partToCapp/ProgressBar$1.class b/bin/com/connor/bhdz/pdm/partToCapp/ProgressBar$1.class new file mode 100644 index 0000000..e09175c Binary files /dev/null and b/bin/com/connor/bhdz/pdm/partToCapp/ProgressBar$1.class differ diff --git a/bin/com/connor/bhdz/pdm/partToCapp/ProgressBar$TaskThread.class b/bin/com/connor/bhdz/pdm/partToCapp/ProgressBar$TaskThread.class new file mode 100644 index 0000000..3e31854 Binary files /dev/null and b/bin/com/connor/bhdz/pdm/partToCapp/ProgressBar$TaskThread.class differ diff --git a/bin/com/connor/bhdz/pdm/partToCapp/ProgressBar.class b/bin/com/connor/bhdz/pdm/partToCapp/ProgressBar.class new file mode 100644 index 0000000..8f2af9e Binary files /dev/null and b/bin/com/connor/bhdz/pdm/partToCapp/ProgressBar.class differ diff --git a/bin/com/connor/bhdz/pdm/partToCapp/ProgressBarThread.class b/bin/com/connor/bhdz/pdm/partToCapp/ProgressBarThread.class new file mode 100644 index 0000000..0e4552c Binary files /dev/null and b/bin/com/connor/bhdz/pdm/partToCapp/ProgressBarThread.class differ diff --git a/bin/com/connor/bhdz/pdm/partToCapp/SendPartToCappAction.class b/bin/com/connor/bhdz/pdm/partToCapp/SendPartToCappAction.class new file mode 100644 index 0000000..e21da38 Binary files /dev/null and b/bin/com/connor/bhdz/pdm/partToCapp/SendPartToCappAction.class differ diff --git a/bin/com/connor/bhdz/pdm/partToCapp/SendPartToCappHandler.class b/bin/com/connor/bhdz/pdm/partToCapp/SendPartToCappHandler.class new file mode 100644 index 0000000..03a3fa8 Binary files /dev/null and b/bin/com/connor/bhdz/pdm/partToCapp/SendPartToCappHandler.class differ diff --git a/build.properties b/build.properties new file mode 100644 index 0000000..feba62d --- /dev/null +++ b/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + lib/ojdbc8.jar,\ + lib/hutool-all-5.8.33.jar diff --git a/icons/sample.png b/icons/sample.png new file mode 100644 index 0000000..02c4b79 Binary files /dev/null and b/icons/sample.png differ diff --git a/icons/sample@2x.png b/icons/sample@2x.png new file mode 100644 index 0000000..c1224d1 Binary files /dev/null and b/icons/sample@2x.png differ diff --git a/lib/hutool-all-5.8.33.jar b/lib/hutool-all-5.8.33.jar new file mode 100644 index 0000000..abaa4c0 Binary files /dev/null and b/lib/hutool-all-5.8.33.jar differ diff --git a/lib/ojdbc8.jar b/lib/ojdbc8.jar new file mode 100644 index 0000000..4c92806 Binary files /dev/null and b/lib/ojdbc8.jar differ diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..79f9a14 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/com/connor/bhdz/pdm/assets/Constants.java b/src/com/connor/bhdz/pdm/assets/Constants.java new file mode 100644 index 0000000..fddbf51 --- /dev/null +++ b/src/com/connor/bhdz/pdm/assets/Constants.java @@ -0,0 +1,14 @@ +package com.connor.bhdz.pdm.assets; + +public final class Constants { + /** + * ʽspringip + */ + public static final String SPRING_ADDRESS = "10.41.72.70:8080"; + + /** + * زԻip192.168.3.125 + */ +// public static final String SPRING_ADDRESS = "192.168.3.125:8080"; + +} diff --git a/src/com/connor/bhdz/pdm/drawingToCapp/ConnOra.java b/src/com/connor/bhdz/pdm/drawingToCapp/ConnOra.java new file mode 100644 index 0000000..3e586b8 --- /dev/null +++ b/src/com/connor/bhdz/pdm/drawingToCapp/ConnOra.java @@ -0,0 +1,111 @@ +package com.connor.bhdz.pdm.drawingToCapp; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.soaictstubs.booleanSeq_tHolder; + +public class ConnOra { + static String driverClass = "oracle.jdbc.driver.OracleDriver"; // + private String url ;//= "jdbc:oracle:thin:@10.41.71.60:1521:orcl"; // port sid + private String user ;//= "system"; // ûݿû + private String password ;//= "Aa12345678"; // û¼ + + Connection conn=null; + ResultSet resultSet = null; + Statement statement; + + public ConnOra(TCSession session) throws TCException { + // TODO Auto-generated constructor stub + TCPreferenceService preferenceService = session.getPreferenceService(); + String[] values = preferenceService.getStringValues("BH_CAPP_Oracle"); + if (values.length != 4) { + System.out.println("δȷȡѡϢ"); + }else { +// this.url = "jdbc:oracle:thin:@"+values[0]+":"+values[1];//10.41.71.60 orcl + this.url = "jdbc:oracle:thin:@"+values[0]+":1521/"+values[1]; + this.user = values[2]; + this.password = values[3]; + System.out.println("ȡOracleݿϢɹ\n url = "+this.url+"\n user = "+this.user+"\n pw = "+this.password); + } + } + + public Connection getconn() throws SQLException { + System.out.println("...Oracle߿ʼִ"); + + try { + //Ƚ + Class.forName(driverClass);// + //ɹ + conn=DriverManager.getConnection(url, user, password); + System.out.println("ӳɹ"); + } catch (SQLException e) { + e.printStackTrace(); + } catch (ClassNotFoundException cnfe) { + cnfe.printStackTrace(); + } + return conn; //һ + } + + /** + * ѯ + * @param sql + * @return + * @throws SQLException + */ + public ResultSet query(String sql) throws SQLException { + System.out.println("ʼִquery"); + + conn = getconn(); + try { + System.out.println("ʼִ֯оsql䡤"); + statement = conn.createStatement(); + resultSet = statement.executeQuery(sql); + } catch (SQLException e) { + e.printStackTrace(); + } + return resultSet; + } + + public void closeConn() { + try { + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + /** + * ɾ or or + * @param sql + * @return + * @throws SQLException + */ + public boolean delOrUp(String sql) throws SQLException { + conn = getconn(); + boolean actResult = false; + try { + Statement statement = conn.createStatement(); + int i = statement.executeUpdate(sql); + if (i>0) { + actResult = true; + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return actResult; + } +} diff --git a/src/com/connor/bhdz/pdm/drawingToCapp/DataBaseControl.java b/src/com/connor/bhdz/pdm/drawingToCapp/DataBaseControl.java new file mode 100644 index 0000000..20c24a5 --- /dev/null +++ b/src/com/connor/bhdz/pdm/drawingToCapp/DataBaseControl.java @@ -0,0 +1,658 @@ +package com.connor.bhdz.pdm.drawingToCapp; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.Statement; +import java.text.DecimalFormat; +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.Vector; + +//import com.connor.dfl.plm.dfl027.ChangeOwnerbean; +//import com.connor.dfl.plm.dfl038.ChangeBean; +//import com.connor.dfl.plm.forms.ChangeOrderBean; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +public class DataBaseControl { + + /** ************************ݿ:*********************************** */ + /** + * kelsen .... + */ + Connection conn; + + ResultSet rs; + + PreparedStatement pstmt; + + Statement stmt; + + String strSQLQuery; + + public String str_Information = ""; + + private String strDriver = "oracle.jdbc.driver.OracleDriver"; + private String strUrl = ""; + private String strUserName = ""; + private String strPassword = ""; + + /** + * + */ + public DataBaseControl(String strDriver, String strUrl, String strUserName, + String strPassword) { + // this.strDriver ="oracle.jdbc.driver.OracleDriver";// + // this.strUrl = "jdbc:oracle:thin:@127.0.0.1:1521:tc";//· + // this.strUserName = "infodba";//ݿû + // this.strPassword = "infodba";//ݿ + + + this.strDriver = strDriver; // "oracle.jdbc.driver.OracleDriver";// + this.strUrl = strUrl; // "jdbc:oracle:thin:@127.0.0.1:1521:tceng";//· + this.strUserName = strUserName; // "infodba";//ݿû + this.strPassword = strPassword; // "infodba";//ݿ + + // + try { + Class.forName(strDriver);// ͨڴ + } catch (ClassNotFoundException cnfe) { + cnfe.printStackTrace(); + } + // try { + // Class.forName("org.objectweb.rmijdbc.Driver").newInstance(); + // } catch (InstantiationException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } catch (IllegalAccessException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } catch (ClassNotFoundException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // } + } + + /** + * + */ + public DataBaseControl(TCSession session) { + + String[] stringArray = session.getPreferenceService().getStringArray(4, + "DFL2_SQL_Connect"); + if (stringArray != null && stringArray.length == 3) { + strUrl = "jdbc:oracle:thin:@" + stringArray[0]; + strUserName = stringArray[1]; + strPassword = stringArray[2]; + } else { + MessageBox.post("δDFL2_SQL_Connectѡ޷Ϣ!", "", + MessageBox.ERROR); + } + + // + try { + Class.forName(strDriver);// ͨڴ + } catch (ClassNotFoundException cnfe) { + cnfe.printStackTrace(); + } + + } + /** + * + */ + public DataBaseControl(TCSession session,String connect) { + + String[] stringArray = session.getPreferenceService().getStringArray(4, + connect); + if (stringArray != null && stringArray.length == 3) { + strUrl = "jdbc:oracle:thin:@" + stringArray[0]; + strUserName = stringArray[1]; + strPassword = stringArray[2]; + } else { + MessageBox.post("δ"+connect+"ѡ޷Ϣ!", "", + MessageBox.ERROR); + } + + // + try { + Class.forName(strDriver);// ͨڴ + } catch (ClassNotFoundException cnfe) { + cnfe.printStackTrace(); + } + + } + + /** + * + * + * @param strSQLQuery + */ + public void dbModify(String strSQLQuery) { + + openDataBase(); + + try { + stmt = conn.createStatement(); + stmt.executeUpdate(strSQLQuery); + } catch (SQLException sqle2) { + sqle2.printStackTrace(); + } + + closeDataBase(); + } + + /** + * ѯ + * + * @param strSQLQuery + * @return + */ + public ResultSet dbQuery(String strSQLQuery) { + ResultSet rs_result = null; + if (conn == null) + openDataBase(); + try { + stmt = conn.createStatement(); + rs_result = stmt.executeQuery(strSQLQuery); + + } catch (SQLException sqle2) { + sqle2.printStackTrace(); + } + return rs_result; + } + + /** + * ѯ2 + * + * @param strSQLQuery + * @return + */ + public ResultSet dbQuery2(String strSQLQuery, Object[] strs) { + ResultSet rs_result = null; + if (conn == null) + openDataBase(); + try { + // stmt = conn.createStatement(); + PreparedStatement ps = conn.prepareStatement(strSQLQuery); + for (int i = 0; i < strs.length; i++) { + ps.setObject(i + 1, strs[i]); + } + rs_result = ps.executeQuery(); + + } catch (SQLException sqle2) { + sqle2.printStackTrace(); + } + return rs_result; + } + /** + * ѯ3 + * + * @param strSQLQuery + * @return + */ + public ResultSet dbQuery3(String strSQLQuery) { + ResultSet rs_result = null; + if (conn == null) + openDataBase(); + try { + stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); + rs_result = stmt.executeQuery(strSQLQuery); + + } catch (SQLException sqle2) { + sqle2.printStackTrace(); + } + return rs_result; + } + + + /** + * 2 + * + * @param strSQLQuery + */ + public void dbModify2(String strSQLQuery, Object[] strs) { + + openDataBase(); + + try { + // stmt = conn.createStatement(); + PreparedStatement ps = conn.prepareStatement(strSQLQuery); + for (int i = 0; i < strs.length; i++) { + ps.setObject(i + 1, strs[i]); + } + ps.executeUpdate(); + } catch (SQLException sqle2) { + sqle2.printStackTrace(); + } + + closeDataBase(); + } + + /** + * + * + */ + public void openDataBase() { + try { + // this.strUrl="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.29)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=tcprod)))"; + if (conn == null || conn.isClosed()) + conn = DriverManager.getConnection(strUrl, strUserName, + strPassword); + } catch (SQLException sqle) { + sqle.printStackTrace(); + MessageBox.post("ݿӴ" + sqle.getMessage(), "", 1); + } + } + + /** + * رݿ + * + */ + public void closeDataBase() { + try { + if (rs != null) { + try { + rs.close(); + } catch (SQLException sqlec) { + sqlec.printStackTrace(); + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException sqlec) { + sqlec.printStackTrace(); + } + } + if (conn != null && !conn.isClosed()) { + try { + conn.close(); + } catch (SQLException sqlecon) { + sqlecon.printStackTrace(); + } + + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * 䴫ݿвѯ ѯõĽÿһ¼װһHashMap,keyԱֶ + * ѯ¼VectorжٸHasnMapԪ + * + * @param strSQLQuery + * @return + * @author xuk + */ + public Vector orgQuery(String strSQLQuery) { + openDataBase(); + Vector v_result = new Vector(); + try { + ResultSet rs_get = dbQuery(strSQLQuery); + // System.out.println("RS_GET:"+rs_get); + if (rs_get != null) { + ResultSetMetaData metaData = rs_get.getMetaData(); + + int i_ColumnCount = metaData.getColumnCount(); + // System.out.println("i_ColumnCount:"+i_ColumnCount); + while (rs_get.next()) { + // System.out.println("BJZJ2"+rs_get.getString("BJZJ2"));; + HashMap hm_unit = new HashMap(); + for (int i = 1; i <= i_ColumnCount; i++) { + hm_unit.put(metaData.getColumnName(i), + rs_get.getString(i)); + // System.out.println("metaData.getColumnName(i):"+metaData.getColumnName(i)); + // System.out.println("rs_get.getString(i):"+rs_get.getString(i)); + } + v_result.add(hm_unit); + } + } else { + str_Information = "" + strSQLQuery + "" + "ѯĽΪ\n"; + } + } catch (Exception e) { + e.printStackTrace(); + } + return v_result; + } + + + public String getTaskIdea(String uid) + throws Exception { + openDataBase(); + String query = "select IDEA from PLM_Perform_Task where PUID= ?"; + // ѯidݿе + ResultSet rs = dbQuery2(query, new Object[] { uid}); + String taskIdea = ""; + if (rs.next()) { + taskIdea = rs.getString(1); + System.out.println("taskIdea=" + taskIdea); + } + + closeDataBase(); + + return taskIdea; + + } + public void setTaskIdea(String uid,String idea) + throws Exception { + openDataBase(); + String query = "select IDEA from PLM_Perform_Task where PUID= ?"; + // ѯidݿе + ResultSet rs = dbQuery2(query, new Object[] { uid}); + if(rs.next()) { + String upin = "update PLM_Perform_Task set IDEA= ? where PUID= ?"; + dbModify2(upin, new Object[] { idea, uid }); + }else { + String upin = "insert into PLM_Perform_Task(PUID,IDEA) values ( ? , ? )"; + dbModify2(upin, new Object[] { uid, idea }); + } + closeDataBase(); + + } + + /** + * ˮ + * + * @param type + * ˮ + * @param prefix + * ǰ׺ + * @param col + * ˮλ 4λ"0000" + * @return + * @throws Exception + */ + public String getNewCode(String type, String prefix, String col) + throws Exception { + openDataBase(); + String query = "select PREFIX,LSH from PLM_LSH where PLMTYPE= ? and PREFIX= ?"; + // ѯidݿе + ResultSet rs = dbQuery2(query, new Object[] { type, prefix }); + String lshstr = col; + String pre = ""; + String lsh = ""; + if (rs.next()) { + pre = rs.getString(1); + lsh = rs.getString(2); + System.out.println("sspre=" + pre); + System.out.println("sslsh=" + lsh); + if ("".equals(lsh)) { + throw new Exception("ˮΪգ"); + } + int ls = Integer.parseInt(lsh) + 1;// µˮ + lshstr = ls + ""; + if (col != null) { + DecimalFormat df = new DecimalFormat(col); + lshstr = df.format(ls); + } + String upin = "update PLM_LSH set LSH= ? where PLMTYPE= ? and PREFIX= ? "; + dbModify2(upin, new Object[] { lshstr, type, prefix }); + } else { + String upin = "insert into PLM_LSH(PLMTYPE,PREFIX,LSH) values ( ? , ? , ? )"; + dbModify2(upin, new Object[] { type, prefix, lshstr }); + + } + + closeDataBase(); + String newId = prefix + lshstr; + + return newId; + + } + + /* + * //ȡϢ public List getChangeMesg(String product,String + * time1,String time2) throws SQLException { List list = new + * ArrayList(); if("ȫ".equals(product)) { product = ""; } String + * sql = + * "select APPLYNAME,OBJECTCODE,APPLYDATE,PRODUCTNAME,PROJECTMODEL,CLIENTNAME,WAREHOUSECODE,NOTIFYEMERGENCYPROCEDURES,TZGGLX,PRODUCTDEPARTMENT,DUTYDEPARTMENT,DUTYMAN,CHANGETYPE,PRODUCTTYPE,ERRORTYPE,PRICEBOOKING,SALSECLASSIFY,ISNOTPRODUCTLOSS,XMJD,RECEIVECLASSIFY,DRAWINGTO,PROJECTCODE,CHANGEREASON,ACCOUNTSET,case when REASONDETAIL is null then changereason else REASONDETAIL end as REASONDETAIL from DFL_CHANGEFORM where PRODUCTDEPARTMENT like '%" + * +product+"%'";// SimpleDateFormat df = new + * SimpleDateFormat("yyyy-M-d HH:mm"); openDataBase(); + * System.out.println("sql============"+sql); ResultSet rs = dbQuery(sql); + * while(rs.next()){ try { String dateStr = rs.getString(3); + * System.out.println("date========"+rs.getString(3)); if(dateStr == null) { + * continue; } Date date = df.parse(rs.getString(3)); Date date1 = + * df.parse(time1); Date date2 = df.parse(time2); if(date.after(date2) && + * date.before(date1)) { System.out.println("date2========"+rs.getString(3)); } + * if(date.after(date1) && date.before(date2)) { ChangeBean bn = new + * ChangeBean(); bn.setApplyName(rs.getString(1)); + * bn.setApplyDate(rs.getString(3)); bn.setProjectCode(rs.getString(22)); + * bn.setClientNae(rs.getString(6)); bn.setProductName(rs.getString(4)); + * bn.setProjectModel(rs.getString(5)); bn.setChangeType(rs.getString(13)); + * bn.setProductType(rs.getString(14)); bn.setErrorType(rs.getString(15)); + * bn.setDutyDepartment(rs.getString(11)); bn.setDutyMan(rs.getString(12)); + * bn.setChangeReason(rs.getString(23)); bn.setSalseClassify(rs.getString(17)); + * bn.setPriceBooking(rs.getString(16)); + * bn.setIsNotProductLoss(rs.getString(18)); + * bn.setReceiveClassify(rs.getString(20)); + * bn.setWarehouseCode(rs.getString(7)); bn.setAccountSet(rs.getString(24)); + * bn.setNotifyEmergencyProcedures(rs.getString(8)); + * bn.setDrawingTo(rs.getString(21)); bn.setChangeListCode(rs.getString(2)); + * bn.setTZChangeType(rs.getString(9)); + * bn.setSUOSU_ProductDepartment(rs.getString(10)); + * bn.setProjectState(rs.getString(19)); bn.setReasonDetail(rs.getString(25)); + * list.add(bn); } } catch (ParseException e) { // TODO Auto-generated catch + * block e.printStackTrace(); } + * + * } closeDataBase(); return list; } + */ + /** + * ˮ + * + * @param type + * ˮ + * @param prefix + * ǰ׺ + * @param col + * ˮλ 4λ"0000" + * @return + * @throws Exception + */ + + /* + * public String getNewCode(String type,CodeBean selCodeBean) throws Exception { + * String prefix = selCodeBean.getCode(); String col = selCodeBean.getNum(); + * String min = selCodeBean.getMin(); String max = selCodeBean.getMax(); + * openDataBase(); String query = + * "select PREFIX,LSH from PLM_LSH where PLMTYPE= ? and PREFIX= ?"; // + * ѯidݿе ResultSet rs = dbQuery2(query, new Object[] { type, prefix }); + * String lshstr = col; String pre = ""; String lsh = ""; if (rs.next()) { pre = + * rs.getString(1); lsh = rs.getString(2); System.out.println("sspre=" + pre); + * System.out.println("sslsh=" + lsh); if ("".equals(lsh)) { throw new + * Exception("ˮΪգ"); } int ls = Integer.parseInt(lsh) + 1;// µˮ int minls + * = Integer.parseInt(min); int maxls = Integer.parseInt(max); if (minls>ls) { + * ls=minls; } if (ls>maxls) { System.out.println(":ˮѳֵ"); return + * "MAXERR"; } lshstr = ls + ""; if (col != null) { DecimalFormat df = new + * DecimalFormat(col); lshstr = df.format(ls); } String upin = + * "update PLM_LSH set LSH= ? where PLMTYPE= ? and PREFIX= ? "; + * dbModify2(upin, new Object[] { lshstr, type, prefix }); } else { if (col != + * null) { int minls = Integer.parseInt(min); DecimalFormat df = new + * DecimalFormat(col); lshstr = df.format(minls); } String upin = + * "insert into PLM_LSH(PLMTYPE,PREFIX,LSH) values ( ? , ? , ? )"; + * dbModify2(upin, new Object[] { type, prefix, lshstr }); } + * + * closeDataBase(); String newId = prefix + lshstr; + * + * return newId; + * + * } + */ + /** + * ȡˮ + * + */ + /* + * public String getMaxCode(String type,CodeBean selCodeBean)throws Exception { + * String prefix = selCodeBean.getCode(); String col = selCodeBean.getNum(); + * String min = selCodeBean.getMin(); String max = selCodeBean.getMax(); + * + * openDataBase(); //String query = + * "select * from (select * from pitem where pitem_id like '" + * +prefix+"%' order by pitem_id desc) where rownum<=1"; String query = + * "select LSH from PLM_LSH where PREFIX = prefix"; // ѯidݿе ResultSet + * rs = dbQuery(query); String lshstr = col; String lsh = ""; if (rs.next()) { + * lsh = rs.getString(0); System.out.println("sslsh=" + lsh); if + * ("".equals(lsh)) { throw new Exception("ˮΪգ"); } lsh = lsh.substring(6); + * int ls = Integer.parseInt(lsh) + 1;// µˮ lshstr = ls + ""; + * System.out.println("lshstr=" + lshstr); if (col != null) { DecimalFormat df = + * new DecimalFormat(col); lshstr = df.format(ls); } } String upin = + * "update PLM_LSH set LSH= ? where PLMTYPE= ? and PREFIX= ? "; + * dbModify2(upin, new Object[] { lshstr, type, prefix }); closeDataBase(); + * String newId = prefix + lshstr; return newId; } + */ + + /** + * ģ» + * @param v3 + * @param v16 + * @param time + * @param user + * @throws Exception + */ + public void setSqlConn(String v3, String v16, String time, String user) + throws Exception { + openDataBase(); + // WF_MJID varchar2(200),-- + // WF_YXJ varchar2(200),--» + // WF_DATE varchar2(200),--ϴ + // WF_USER varchar2(200),--ϴԱ + String query = "select WF_MJID from WF_MJ_XJ_T where WF_MJID = ? "; + // ѯidݿе + ResultSet rs = dbQuery2(query, new Object[] {v3}); + String wfmjid = ""; + if (rs.next()) { + System.out.println(""); + wfmjid = rs.getString(1); + System.out.println("wfmjid=" + wfmjid); + String upup = "UPDATE WF_MJ_XJ_T set WF_YXJ = ? ,WF_DATE= ?, WF_USER = ? WHERE WF_MJID = ? "; + dbModify2(upup, new Object[] {v16, time, user ,v3}); + + } else { + System.out.println(""); + System.out.println("wfmjid=" + v3); + String upin = "insert into WF_MJ_XJ_T(WF_MJID,WF_YXJ,WF_DATE,WF_USER) values ( ?,? , ? , ? )"; + dbModify2(upin, new Object[] {v3, v16, time, user}); + + } + + closeDataBase(); + + return ; + + } + + /** + * ôͿ + * + * @param value + * ѯ + * @param sql + * ѯ + * @return + * @throws Exception + */ + /* + * public List getRecord(String sql) throws Exception { + * List list=new ArrayList<>(); openDataBase(); // + * ѯidݿе ResultSet rs = dbQuery(sql); while (rs.next()) { + * ChangeOwnerbean bean = new ChangeOwnerbean(); + * bean.setZhangt(rs.getString(1)); bean.setId(rs.getString(2)); + * bean.setCustomerName(rs.getString(3)); bean.setSpec(rs.getString(4)); + * bean.setUnit(rs.getString(5)); bean.setCangk(rs.getString(6)); + * bean.setCangkName(rs.getString(7)); bean.setNum(rs.getString(8)); + * bean.setLocation(rs.getString(9)); list.add(bean); } closeDataBase(); return + * list; } + */ + // public List getRecord2(String value,String zhangT,String cangK,String sql) + // throws Exception { + // List list=new ArrayList<>(); + // openDataBase(); + // // ѯidݿе + // ResultSet rs = dbQuery2(sql, new Object[] {value,zhangT,cangK}); + // while (rs.next()) { + // ChangeOwnerbean bean = new ChangeOwnerbean(); + // bean.setId(rs.getString(1)); + // bean.setCustomerName(rs.getString(2)); + // bean.setSpec(rs.getString(3)); + // bean.setZhangt(rs.getString(4)); + // bean.setCangk(rs.getString(5)); + // bean.setNum(rs.getString(6)); + // bean.setUnit(rs.getString(7)); + // list.add(bean); + // } + // closeDataBase(); + // return list; + // } + + public String getNum(Object[] values) + throws Exception { + openDataBase(); + // ѯidݿе + String sql = "select NUM from DFL_OLD_ITEM where ITEM_ID= ? and ZHANGTAO= ? and WAREHOUSE= ?"; + String num = ""; + ResultSet rs = dbQuery2(sql, values); + if (rs.next()) { + num = rs.getString(1); + } + closeDataBase(); + return num; + } + + public double getNums(String sql) + throws Exception { + openDataBase(); + // ѯidݿе + double nums = 0; + ResultSet rs = dbQuery(sql); + if (rs.next()) { + nums = rs.getInt(1); + } + closeDataBase(); + return nums; + } + /** + * + * + * @param args + */ + public static void main(String args[]) { + try { + + String str_DataBaseDriver = "oracle.jdbc.driver.OracleDriver"; + String str_URL = "jdbc:oracle:thin:@localhost:1521:tc12"; + String str_UserName = "infodba"; + String str_Password = "infodba"; + DataBaseControl dbc = new DataBaseControl(str_DataBaseDriver, + str_URL, str_UserName, str_Password); + // dbc.openDataBase(); + System.out.println("ӳɹ"); + // dbc.stmt = dbc.conn.createStatement(); + // String sql = "select * from PLM_LSH"; + // Vector rs_result = dbc.orgQuery(sql); + // for (int i = 0; i < rs_result.size(); i++) { + // HashMap map = (HashMap) + // rs_result.get(i); + // + // for (Map.Entry entry: map.entrySet()) { + // System.out.println(entry.getKey()+"---"+entry.getValue()); + // } + // } + String newid = dbc.getNewCode("PLMITEMID", "pz", "0000"); + System.out.println(newid); + // dbc.closeDataBase(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/src/com/connor/bhdz/pdm/drawingToCapp/ProgressBar.java b/src/com/connor/bhdz/pdm/drawingToCapp/ProgressBar.java new file mode 100644 index 0000000..d72eacc --- /dev/null +++ b/src/com/connor/bhdz/pdm/drawingToCapp/ProgressBar.java @@ -0,0 +1,171 @@ +/** + * @file ProgressBar.java + * + * @brief Create progress bar + * + * @author Yanghui + * + * @history + * ================================================================ + * Date Name Description of Change + * 25-July-2008 Yanghui this class is used to create + * progress bar. + */ +package com.connor.bhdz.pdm.drawingToCapp; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.Timer; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.util.PropertyLayout; +import com.teamcenter.rac.util.Registry; + +/** + * @class ProgressBar + * @brief Create progress bar + * @author Yanghui + */ +public class ProgressBar extends AbstractAIFDialog implements ActionListener { + /** + * @var ProgressBar.progressbar + * @brief JProgressBar + */ + private JProgressBar progressbar; + + /** + * @var ProgressBar.label + * @brief label used to tips + */ + private JLabel label; + + /** + * @var ProgressBar.timer + * @brief timer used to timing operation + */ + private Timer timer; + + /** + * @var ProgressBar.bool + * @brief bool used to flag thread return + */ + private boolean bool = false; + + /** + * @var Progressbar.registry + * @brief Registry + */ + private Registry registry; + + /** + * @fn public ProgressBar() + * @brief constructor + * @param[in] null + */ + private String showLable = null ; + public ProgressBar(String showlable) { + super(true); + showLable = showlable; + this.setAlwaysOnTop(true); + } + + /** + * @fn public void setBool(boolean bool) + * @brief set bool value + * @param[in] bool + * @param[out] null + */ + public void setBool(boolean bool) { + this.bool = bool; + } + + /** + * @fn private void initUI() + * @brief createDialog method + * @param[in] null + * @param[out] null + */ + public void initUI() { + Container container = getContentPane(); + JPanel mainPanel = new JPanel(new PropertyLayout()); + this.label = new JLabel(showLable, JLabel.CENTER); + this.progressbar = new JProgressBar(); + this.progressbar.setOrientation(JProgressBar.HORIZONTAL); + this.progressbar.setMinimum(0); + this.progressbar.setMaximum(100); + this.progressbar.setValue(0); + this.progressbar.setPreferredSize(new Dimension(200, 15)); + this.progressbar.setBorderPainted(true); + this.timer = new Timer(50, (ActionListener) this); + this.timer.setRepeats(false); + mainPanel.add("1.1.center", new JLabel(" ")); + mainPanel.add("2.1.center", label); + mainPanel.add("3.1.center", progressbar); + mainPanel.add("4.1.center", new JLabel(" ")); + container.add(mainPanel); + pack(); + setLocation(500, 200); + TaskThread thread = new TaskThread(this); + thread.start(); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + bool = true; + } + }); + this.setVisible(true); + } + + /** + * @class TaskThread + * @brief Create progressbar + * + */ + class TaskThread extends Thread { + private ProgressBar bar; + + public TaskThread(ProgressBar bar) { + this.bar = bar; + } + + public void run() { + if (bool == false) { + // Set Status is running. + // session.setStatus(registry.getString("export Running")); + } + for (int i = 0; i < i + 1; i++) { + timer.start(); + int value = progressbar.getValue(); + if (value < 100) { + value = value + 5; + progressbar.setValue(value); + } else { + timer.stop(); + progressbar.setValue(0); + } + try { + sleep(100); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (bool == true) { + bar.setVisible(false); + bar.dispose(); + return; + + } + + } + } + } + + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + + } +} diff --git a/src/com/connor/bhdz/pdm/drawingToCapp/ProgressBarThread.java b/src/com/connor/bhdz/pdm/drawingToCapp/ProgressBarThread.java new file mode 100644 index 0000000..c7d7155 --- /dev/null +++ b/src/com/connor/bhdz/pdm/drawingToCapp/ProgressBarThread.java @@ -0,0 +1,41 @@ +/** + * @file ProgressBarThread.java + * + * @brief control progressBar. + * + * @author Yanghui + * + * @history + * ================================================================ + * Date Name Description of Change + * 08-Auguest-2008 Yanghui this class is used to control + * progress bar. + */ +package com.connor.bhdz.pdm.drawingToCapp; + +/** + * @class ProgressBarThread + * @brief Create progress bar thread + * @author Yanghui + */ +public class ProgressBarThread extends Thread { + + private ProgressBar bar; + + private String title; + + public ProgressBarThread(String title,String showLable) { + this.title = title; + bar = new ProgressBar(showLable); + } + + public void run() { + bar.setTitle(title); + bar.initUI(); + } + + public void setBool(boolean bool) { + bar.setBool(true); + bar.setAlwaysOnTop(false); + } +} diff --git a/src/com/connor/bhdz/pdm/drawingToCapp/ProgressReporterDialog.java b/src/com/connor/bhdz/pdm/drawingToCapp/ProgressReporterDialog.java new file mode 100644 index 0000000..4dc2550 --- /dev/null +++ b/src/com/connor/bhdz/pdm/drawingToCapp/ProgressReporterDialog.java @@ -0,0 +1,126 @@ +package com.connor.bhdz.pdm.drawingToCapp; + +import java.awt.BorderLayout; +import java.awt.Cursor; +import java.awt.Dimension; +import java.awt.Toolkit; + +import javax.swing.JLabel; +import javax.swing.JProgressBar; + +import com.teamcenter.rac.aif.AbstractAIFDialog; + +@SuppressWarnings("serial") +public class ProgressReporterDialog extends AbstractAIFDialog +{ + + private JLabel messageLabel; + + private JProgressBar progressBar; + + private boolean requestCanceling; + + private int percent; + + public ProgressReporterDialog() + { + super(false); + + setLayout(new BorderLayout()); + setAlwaysOnTop(true); + + initializeComponents(); + setTextPropertyForComponents(); + registerComponentsListeners(); + addComponents(); + + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + } + + private void initializeComponents() + { + messageLabel = new JLabel(" ", JLabel.LEFT); + progressBar = new JProgressBar(); + } + + private void setTextPropertyForComponents() + { + setTitle(""); + } + + private void registerComponentsListeners() + { + } + + private void addComponents() + { + add(messageLabel, BorderLayout.NORTH); + add(progressBar, BorderLayout.SOUTH); + } + + private void centerToClientScreen() + { + Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); + + int x = screen.width - getWidth(); + int y = screen.height - getHeight(); + + setLocation(x / 2, y / 2); + } + + public void reportProgressMessage(String message) + { + messageLabel.setText(message); + } + + public void setProgressPercent(int percent) + { + this.percent = percent; + } + + public void requestCanceling() + { + requestCanceling = true; + } + + public void run() + { + pack(); + setSize(400, getHeight()); + centerToClientScreen(); + setVisible(true); + + while (!requestCanceling) + { + if(percent > progressBar.getMaximum()) + { + percent = 0; + } + + progressBar.setValue(percent); + + percent += 5; + + try + { + Thread.sleep(100); + } + catch (InterruptedException e) + { + continue; + } + } + + dispose(); + } + + public int getProgess() + { + return progressBar.getValue(); + } + + public boolean isRequestCanceling() + { + return requestCanceling; + } +} diff --git a/src/com/connor/bhdz/pdm/drawingToCapp/SendDrawingToCappAction.java b/src/com/connor/bhdz/pdm/drawingToCapp/SendDrawingToCappAction.java new file mode 100644 index 0000000..fb08238 --- /dev/null +++ b/src/com/connor/bhdz/pdm/drawingToCapp/SendDrawingToCappAction.java @@ -0,0 +1,325 @@ +package com.connor.bhdz.pdm.drawingToCapp; + +import java.awt.Frame; +import java.io.File; +import java.io.IOException; +import java.nio.file.*; +import java.nio.file.StandardCopyOption; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.connor.bhdz.pdm.assets.Constants; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.common.actions.AbstractAIFAction; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentBOMLine; +import com.teamcenter.rac.kernel.TCComponentBOMWindow; +import com.teamcenter.rac.kernel.TCComponentBOMWindowType; +import com.teamcenter.rac.kernel.TCComponentDataset; +import com.teamcenter.rac.kernel.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentTcFile; +import com.teamcenter.rac.kernel.TCComponentUser; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpException; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; + +public class SendDrawingToCappAction extends AbstractAIFAction { + private AbstractAIFApplication application; + private TCSession session; + + public SendDrawingToCappAction(AbstractAIFApplication application, Frame frame, String paramString) { + super(application, frame, paramString); + this.application = application; + this.session = (TCSession) application.getSession(); + } + + public static boolean isReleased(TCComponent comp) throws Exception { + TCComponent[] status = comp.getReferenceListProperty("release_status_list"); + if (status == null || status.length == 0) { + return false; + } + return true; + } + + public static TCComponentItemRevision getLastReleaseRevison(TCComponentItem targetComp) throws Exception { + System.out.println("Get Last Released Revision: " + targetComp); + if (targetComp == null) { + return null; + } + List releaseRevisionList = new ArrayList<>(); + TCComponent[] comps = targetComp.getReferenceListProperty("revision_list"); + System.out.println(">> Revisions: " + Arrays.toString(comps)); + for (TCComponent comp : comps) { + if (isReleased(comp)) { + releaseRevisionList.add((TCComponentItemRevision) comp); + } + } + System.out.println(">> Released Revisions: " + releaseRevisionList); + return releaseRevisionList.size() == 0 ? null : releaseRevisionList.get(releaseRevisionList.size() - 1); + } + + /** + * Ϊspringboot׼ЯϢ + * urlû + * @return + */ + public Map readyParamMap() { + Map paramMap = new HashMap(); + TCPreferenceService preferenceService = session.getPreferenceService(); + String[] values = preferenceService.getStringValues("BH_CAPP_Oracle"); + if (values.length != 4) { + System.out.println("δȷȡѡϢ"); + }else { + paramMap.put("url", "jdbc:oracle:thin:@"+values[0]+":1521/"+values[1]); + paramMap.put("user", values[2]); + paramMap.put("password", values[3]); + } + + + return paramMap; + } + + @Override + public void run() {//TODO + ProgressBarThread thread = new ProgressBarThread("·", "·..."); + thread.start(); + + InterfaceAIFComponent[] components = application.getTargetComponents(); + + try { + for (InterfaceAIFComponent selectComponent : components) { + String itemID = "";//ID + String revID = "";//汾 + String sql = ""; + + + String toTaskRevId = "";//msgŰ汾ϢCеòѯtoTaskRevId"000022-A"ȡ汾 + + if (selectComponent instanceof TCComponentItem) { + //ѡжͼֽH8_drawingȡ"ѷ汾" + System.out.println("ǰѡж H8_drawing"); + TCComponentItem item = (TCComponentItem) selectComponent; + //ȡѷ汾 + TCComponentItemRevision latestItemRevision = getLastReleaseRevison(item); + if (latestItemRevision == null) { + System.out.println("ǰѡж󲻴ѷ汾޷·"); + MessageBox.post("ǰѡж󲻴ѷ汾޷·","ʾ",MessageBox.INFORMATION); + thread.setBool(true); + return; + } + revID = latestItemRevision.getProperty("item_revision_id");//Cеòѯݣȡ汾 + itemID = latestItemRevision.getProperty("item_id"); + toTaskRevId = itemID + "-" + revID; + + }else if (selectComponent instanceof TCComponentItemRevision) { + //TODO ѡжͼֽ汾H8_drawingRevision + System.out.println("ǰѡж H8_drawingRevision"); + TCComponentItemRevision revision = (TCComponentItemRevision)selectComponent; + String releaseDate = revision.getProperty("date_released"); + System.out.println("===>ȡǰ汾ķ״̬"+releaseDate); + if (releaseDate == null) { + System.out.println("ǰ汾δ"); + MessageBox.post("ǰ汾δ޷·","ʾ",MessageBox.INFORMATION); + thread.setBool(true); + return; + } + revID = revision.getProperty("item_revision_id"); + itemID = revision.getProperty("item_id"); + toTaskRevId = itemID + "-" + revID; + + }else { + MessageBox.post("erro select!","tip",MessageBox.INFORMATION); + thread.setBool(true); + return; + } + //֯msgTask + String tasksource = "ֶ·"; + String userName = session.getUser().getUserName(); + String userId = session.getUser().getUserId(); + String status = "δʼ"; + String starttime = getCurrentTime(); + //жtaskǷѾͬ + Map paramMap = new HashMap(); + //ƥspringbootеIJѯ + paramMap.put("MSG", toTaskRevId); + Integer result = sendRequest("getByMSG",paramMap); + if (result > 0) {//ظݣ + System.out.println("TASKظݣ¡"); + Map paramMapU = new HashMap(); + paramMapU.put("TASKSOURCE",tasksource); + paramMapU.put("USERNAME",userName); + paramMapU.put("USERID",userId); + paramMapU.put("STATUS",status); + paramMapU.put("STARTTIME",starttime); + paramMapU.put("MSG",toTaskRevId); + Integer resultU = sendRequest("updateTask",paramMapU); + if (resultU == -1){ + System.out.println("springbootʧܣupdateTask"); + } + + }else {//ظݣ + System.out.println("TASKظݣ롤"); + Map paramMapI = new HashMap(); + paramMapI.put("TASKSOURCE",tasksource); + paramMapI.put("USERNAME",userName); + paramMapI.put("USERID",userId); + paramMapI.put("STATUS",status); + paramMapI.put("MSG",toTaskRevId); + paramMapI.put("STARTTIME",starttime); + Integer resultI = sendRequest("insertTask",paramMapI); + if (resultI == -1){ + System.out.println("springbootʧܣinsertTask"); + } + System.out.println("1"); + } + System.out.println("2"); + } + System.out.println("deal end!"); + } catch (Exception e) { + // TODO: handle exception + System.out.println("===>·ʧ"); + MessageBox.post("·ʧ","ʾ",MessageBox.INFORMATION); + e.printStackTrace(); + } + + MessageBox.post("·ɹ","ʾ",MessageBox.INFORMATION); + + thread.setBool(true); + + } + /** + * 첽 + * @return -1 ʾʧ + */ + private Integer sendRequest(String way,Map param){ + System.out.println("ʼ÷SpringBoot󡤡"); + Integer resultInteger = 0; + + String urlString = "http://"+Constants.SPRING_ADDRESS+"/drawing/"+way; + try {//ʽУspringcurlipַ10.41.72.70ҵIJԻip192.168.3.125 + String url = StrUtil.format(urlString);//springbootڷipַ + System.out.println(""+urlString); + // POST + HttpResponse response = HttpRequest.post(url) + .header("Content-Type", "application/json") // ΪJSON + .body(JSONUtil.toJsonStr(param)) // ΪJSONַ + .timeout(20*1000) // óʱʱ + .execute(); + System.out.println("SpringBootִݿĽΪ"+response.body()+"\n ЯϢΪ"+param.toString()); + resultInteger = Integer.parseInt(response.body()); + int statusCode = response.getStatus(); + if (statusCode < 200 && statusCode > 300) { + System.out.println("Ӧ쳣: ȡϢΪ!"); + return -1; + } + + } catch (HttpException e) { + // Ƿdzʱ쳣 + if (e.getMessage().contains("Read timed out") || e.getMessage().contains("Connect timed out")) { + System.out.println("ʱ: " + e.getMessage()); + return -2; // ʹòͬķֵʶʱ + } else { + // ͵HttpException + System.out.println("зHttpException: " + e.getMessage()); + return -1; + } + } catch (Exception e) { + // 쳣 + System.out.println("з쳣: " + e.getMessage()); + e.printStackTrace(); // ӡջϢԱ + return -1; + } + + return resultInteger; + } + + /** + * FileļStringļ· + * @param file ļ + * @param savePath · + */ + public static void saveFileToFileFolder(File file, String savePath) { + System.out.println("ʼִsaveFileToFileFolder"); + // ַ·תΪ Path + Path saveFolderPath = Paths.get(savePath); + + try { + // 鲢Ŀļ + Files.createDirectories(saveFolderPath); + + // Ŀļ + clearDirectory(saveFolderPath); + + // Ŀļ· + Path targetFilePath = saveFolderPath.resolve(file.getName()); + + // ļƵĿļ + Files.copy(file.toPath(), targetFilePath); + + System.out.println("ļѳɹ浽: " + targetFilePath); + } catch (IOException e) { + e.printStackTrace(); + System.err.println("ļʱ: " + e.getMessage()); + } + } + + /** + * ļļ + * @param directory + * @throws IOException + */ + private static void clearDirectory(Path directory) throws IOException { + if (Files.exists(directory)) { + File[] files = directory.toFile().listFiles(); + if (files != null) { + for (File file : files) { + Files.delete(file.toPath()); + } + } + } + } + + + /** + * ȡǰʱ䣬ʽΪ"yyyy-MM-dd HH-mm-ss" + * @return String + */ + private String getCurrentTime() { + // ȡǰʱ + LocalDateTime now = LocalDateTime.now(); + + // Զʱʽ + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss"); + + // ʽǰʱ + String formattedDate = now.format(formatter); + + return formattedDate; + + } + +} diff --git a/src/com/connor/bhdz/pdm/drawingToCapp/SendDrawingToCappHandler.java b/src/com/connor/bhdz/pdm/drawingToCapp/SendDrawingToCappHandler.java new file mode 100644 index 0000000..ceaae6a --- /dev/null +++ b/src/com/connor/bhdz/pdm/drawingToCapp/SendDrawingToCappHandler.java @@ -0,0 +1,72 @@ +package com.connor.bhdz.pdm.drawingToCapp; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.util.MessageBox; + +public class SendDrawingToCappHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); +// жѡУǷзH8_drawing͵ͼֽ + InterfaceAIFComponent[] components = app.getTargetComponents(); + try { + if (components != null && components.length > 0) { + //ÿһѡж + for (InterfaceAIFComponent component : components) { + TCComponentItem item;//ѡжitem + String componentType = "";//ѡж + if (component instanceof TCComponentItemRevision) { + TCComponentItemRevision rev = (TCComponentItemRevision) component; + item = rev.getItem(); + componentType = "rev"; + + }else if (component instanceof TCComponentItem) { + item = (TCComponentItem) component; + componentType = "item"; + }else { + MessageBox.post("ѡͼֽ","ʾ",MessageBox.INFORMATION); + return null; + } + //жѡжǷH8_drawing + String typeString = item.getStringProperty("object_type"); + System.out.println("ǰѡжitem=="+typeString); + //жѡеĶǷȫH8_drawingǷnull + if (!typeString.equals("H8_drawing") && !typeString.equals("H8_frockItem") && !typeString.equals("H8_standardParts") && !typeString.equals("H8_Component")) { + MessageBox.post("ѡͼֽ","ʾ",MessageBox.INFORMATION); + return null; + } + } + } + // + System.out.println(""); + + + System.out.println("ʼ·"); +// ȫH8_drawing͵Ķ󣬲תaction + SendDrawingToCappAction ac = new SendDrawingToCappAction(app, null, null); + Thread thread = new Thread(ac); + thread.start(); + + System.out.println("·ɣʼرս"); + } catch (TCException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } finally { + + } + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/com/connor/bhdz/pdm/partToCapp/ConnOra.java b/src/com/connor/bhdz/pdm/partToCapp/ConnOra.java new file mode 100644 index 0000000..3ac269a --- /dev/null +++ b/src/com/connor/bhdz/pdm/partToCapp/ConnOra.java @@ -0,0 +1,111 @@ +package com.connor.bhdz.pdm.partToCapp; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCPreferenceService; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.soaictstubs.booleanSeq_tHolder; + +public class ConnOra { + static String driverClass = "oracle.jdbc.driver.OracleDriver"; // + private String url ;//= "jdbc:oracle:thin:@10.41.71.60:1521:orcl"; // port sid + private String user ;//= "system"; // ûݿû + private String password ;//= "Aa12345678"; // û¼ + + Connection conn=null; + ResultSet resultSet = null; + Statement statement; + + public ConnOra(TCSession session) throws TCException { + // TODO Auto-generated constructor stub + TCPreferenceService preferenceService = session.getPreferenceService(); + String[] values = preferenceService.getStringValues("BH_CAPP_Oracle"); + if (values.length != 4) { + System.out.println("δȷȡѡϢ"); + }else { + this.url = "jdbc:oracle:thin:@"+values[0]+":1521/"+values[1];//10.41.71.60 orcl + this.user = values[2]; + this.password = values[3]; + System.out.println("ȡOracleݿϢɹ\n url = "+this.url+"\n user = "+this.user+"\n pw = "+this.password); + + } + } + + + public Connection getconn() throws SQLException { + System.out.println("...Oracle߿ʼִ"); + + try { + //Ƚ + Class.forName(driverClass);// + //ɹ + conn=DriverManager.getConnection(url, user, password); + System.out.println("ӳɹ"); + } catch (SQLException e) { + e.printStackTrace(); + } catch (ClassNotFoundException cnfe) { + cnfe.printStackTrace(); + } + return conn; //һ + } + + /** + * ѯ + * @param sql + * @return + * @throws SQLException + */ + public ResultSet query(String sql) throws SQLException { + System.out.println("ʼִquery"); + + conn = getconn(); + try { + System.out.println("ʼִ֯оsql䡤"); + statement = conn.createStatement(); + resultSet = statement.executeQuery(sql); + } catch (SQLException e) { + e.printStackTrace(); + } + return resultSet; + } + + public void closeConn() { + try { + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + /** + * ɾ or or + * @param sql + * @return + * @throws SQLException + */ + public boolean delOrUp(String sql) throws SQLException { + conn = getconn(); + boolean actResult = false; + try { + Statement statement = conn.createStatement(); + int i = statement.executeUpdate(sql); + if (i>0) { + actResult = true; + } + } catch (SQLException e) { + e.printStackTrace(); + } finally { + try { + conn.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + return actResult; + } +} diff --git a/src/com/connor/bhdz/pdm/partToCapp/ProgressBar.java b/src/com/connor/bhdz/pdm/partToCapp/ProgressBar.java new file mode 100644 index 0000000..946c12d --- /dev/null +++ b/src/com/connor/bhdz/pdm/partToCapp/ProgressBar.java @@ -0,0 +1,171 @@ +/** + * @file ProgressBar.java + * + * @brief Create progress bar + * + * @author Yanghui + * + * @history + * ================================================================ + * Date Name Description of Change + * 25-July-2008 Yanghui this class is used to create + * progress bar. + */ +package com.connor.bhdz.pdm.partToCapp; +import java.awt.Container; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.Timer; +import com.teamcenter.rac.aif.AbstractAIFDialog; +import com.teamcenter.rac.util.PropertyLayout; +import com.teamcenter.rac.util.Registry; + +/** + * @class ProgressBar + * @brief Create progress bar + * @author Yanghui + */ +public class ProgressBar extends AbstractAIFDialog implements ActionListener { + /** + * @var ProgressBar.progressbar + * @brief JProgressBar + */ + private JProgressBar progressbar; + + /** + * @var ProgressBar.label + * @brief label used to tips + */ + private JLabel label; + + /** + * @var ProgressBar.timer + * @brief timer used to timing operation + */ + private Timer timer; + + /** + * @var ProgressBar.bool + * @brief bool used to flag thread return + */ + private boolean bool = false; + + /** + * @var Progressbar.registry + * @brief Registry + */ + private Registry registry; + + /** + * @fn public ProgressBar() + * @brief constructor + * @param[in] null + */ + private String showLable = null ; + public ProgressBar(String showlable) { + super(true); + showLable = showlable; + this.setAlwaysOnTop(true); + } + + /** + * @fn public void setBool(boolean bool) + * @brief set bool value + * @param[in] bool + * @param[out] null + */ + public void setBool(boolean bool) { + this.bool = bool; + } + + /** + * @fn private void initUI() + * @brief createDialog method + * @param[in] null + * @param[out] null + */ + public void initUI() { + Container container = getContentPane(); + JPanel mainPanel = new JPanel(new PropertyLayout()); + this.label = new JLabel(showLable, JLabel.CENTER); + this.progressbar = new JProgressBar(); + this.progressbar.setOrientation(JProgressBar.HORIZONTAL); + this.progressbar.setMinimum(0); + this.progressbar.setMaximum(100); + this.progressbar.setValue(0); + this.progressbar.setPreferredSize(new Dimension(200, 15)); + this.progressbar.setBorderPainted(true); + this.timer = new Timer(50, (ActionListener) this); + this.timer.setRepeats(false); + mainPanel.add("1.1.center", new JLabel(" ")); + mainPanel.add("2.1.center", label); + mainPanel.add("3.1.center", progressbar); + mainPanel.add("4.1.center", new JLabel(" ")); + container.add(mainPanel); + pack(); + setLocation(500, 200); + TaskThread thread = new TaskThread(this); + thread.start(); + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + bool = true; + } + }); + this.setVisible(true); + } + + /** + * @class TaskThread + * @brief Create progressbar + * + */ + class TaskThread extends Thread { + private ProgressBar bar; + + public TaskThread(ProgressBar bar) { + this.bar = bar; + } + + public void run() { + if (bool == false) { + // Set Status is running. + // session.setStatus(registry.getString("export Running")); + } + for (int i = 0; i < i + 1; i++) { + timer.start(); + int value = progressbar.getValue(); + if (value < 100) { + value = value + 5; + progressbar.setValue(value); + } else { + timer.stop(); + progressbar.setValue(0); + } + try { + sleep(100); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (bool == true) { + bar.setVisible(false); + bar.dispose(); + return; + + } + + } + } + } + + public void actionPerformed(ActionEvent arg0) { + // TODO Auto-generated method stub + + } +} diff --git a/src/com/connor/bhdz/pdm/partToCapp/ProgressBarThread.java b/src/com/connor/bhdz/pdm/partToCapp/ProgressBarThread.java new file mode 100644 index 0000000..e4c913e --- /dev/null +++ b/src/com/connor/bhdz/pdm/partToCapp/ProgressBarThread.java @@ -0,0 +1,41 @@ +/** + * @file ProgressBarThread.java + * + * @brief control progressBar. + * + * @author Yanghui + * + * @history + * ================================================================ + * Date Name Description of Change + * 08-Auguest-2008 Yanghui this class is used to control + * progress bar. + */ +package com.connor.bhdz.pdm.partToCapp; + +/** + * @class ProgressBarThread + * @brief Create progress bar thread + * @author Yanghui + */ +public class ProgressBarThread extends Thread { + + private ProgressBar bar; + + private String title; + + public ProgressBarThread(String title,String showLable) { + this.title = title; + bar = new ProgressBar(showLable); + } + + public void run() { + bar.setTitle(title); + bar.initUI(); + } + + public void setBool(boolean bool) { + bar.setBool(true); + bar.setAlwaysOnTop(false); + } +} diff --git a/src/com/connor/bhdz/pdm/partToCapp/SendPartToCappAction.java b/src/com/connor/bhdz/pdm/partToCapp/SendPartToCappAction.java new file mode 100644 index 0000000..3c092df --- /dev/null +++ b/src/com/connor/bhdz/pdm/partToCapp/SendPartToCappAction.java @@ -0,0 +1,294 @@ +package com.connor.bhdz.pdm.partToCapp; + +import java.awt.Frame; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.connor.bhdz.pdm.assets.Constants; +import com.connor.bhdz.pdm.drawingToCapp.ConnOra; +import com.connor.bhdz.pdm.drawingToCapp.ProgressBarThread; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.common.actions.AbstractAIFAction; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +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.TCComponentForm; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentUser; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; + +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.http.HttpException; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; + +public class SendPartToCappAction extends AbstractAIFAction { + private AbstractAIFApplication application; + private TCSession session; + + protected SendPartToCappAction(AbstractAIFApplication application, Frame frame, String param) { + super(application, frame, param); + this.application = application; + this.session = (TCSession) application.getSession(); + } + + /** + * ȡǰʱ䣬ʽΪ"yyyy-MM-dd HH-mm-ss" + * @return String + */ + private String getCurrentTime() { + System.out.println("getCurrentTimeʼִ"); + // ȡǰʱ + LocalDateTime now = LocalDateTime.now(); + + // Զʱʽ + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss"); + + // ʽǰʱ + String formattedDate = now.format(formatter); + + return formattedDate; + + } + + + /** + * BOMУ֯BOMԴ洢ݿBOM + * @param bomLine bom + * @throws TCException + * @throws SQLException + */ +// private void throwBom(TCComponentBOMLine bomLine) throws TCException, SQLException { +// // TODO Auto-generated method stub +// //ȡBOMϢ +// TCComponentItem item = bomLine.getItem(); +// TCComponentItemRevision itemRevision = bomLine.getItemRevision(); +// String parent = item.getProperty("item_id");//ͼ +// String parentversion = itemRevision.getProperty("item_revision_id");//ϰ汾 +// String parentname = item.getProperty("object_name");// +// +// //BOMȡϢ +// if (bomLine.hasChildren()) { +// AIFComponentContext[] childrens = bomLine.getChildren(); +// for (AIFComponentContext children : childrens) { +// TCComponentBOMLine bomLineChild = (TCComponentBOMLine) children.getComponent(); +// TCComponentItem childItem = bomLineChild.getItem(); +// TCComponentItemRevision childItemRevision = bomLineChild.getItemRevision(); +// //Ϣݿ +//// savePart(childItemRevision); +// //֯Ϣ͸Ϣһ𱣴Ϊһ +// String sub = childItem.getProperty("item_id");//ϱ +// String subversion = childItemRevision.getProperty("item_revision_id");//汾 +// String subname = childItem.getProperty("object_name");// +// bomLineChild.lock(); +// String lineno = bomLineChild.getProperty("bl_sequence_no");//к +// String quantity = bomLineChild.getProperty("bl_quantity");// +// bomLineChild.unlock(); +// String user = session.getUser().getUserName();//·Ա +// //TODO ݸ汾IDȷΨһԣѯǷѾڸBOMݣѴֻ桱ʱ䡱Ϊǰʱ䣻򱣴桰·ʱ䡱͡ʱ䡱Ϊǰʱ䣩 +// if (true/**/) { +// String issuedtime = getCurrentTime(); +// String updatetime = getCurrentTime(); +// //TODO ݵBOMݿ +// +// }else { +// String updatetime = getCurrentTime(); +// //TODO ݵBOMݿ +// +// } +// throwBom(bomLineChild); +// } +// } +// } + + public static boolean isReleased(TCComponent comp) throws Exception { + TCComponent[] status = comp.getReferenceListProperty("release_status_list"); + if (status == null || status.length == 0) { + return false; + } + return true; + } + public static TCComponentItemRevision getLastReleaseRevison(TCComponentItem targetComp) throws Exception { + System.out.println("Get Last Released Revision: " + targetComp); + if (targetComp == null) { + return null; + } + List releaseRevisionList = new ArrayList<>(); + TCComponent[] comps = targetComp.getReferenceListProperty("revision_list"); + System.out.println(">> Revisions: " + Arrays.toString(comps)); + for (TCComponent comp : comps) { + if (isReleased(comp)) { + releaseRevisionList.add((TCComponentItemRevision) comp); + } + } + System.out.println(">> Released Revisions: " + releaseRevisionList); + return releaseRevisionList.size() == 0 ? null : releaseRevisionList.get(releaseRevisionList.size() - 1); + } + + + + @Override + public void run() { + ProgressBarThread thread = new ProgressBarThread("·", "·..."); + thread.start(); + + InterfaceAIFComponent[] components = application.getTargetComponents(); + try { + for (InterfaceAIFComponent selectComponent : components) { + String itemID = "";//ID + String revID = "";//汾 + String sql = ""; + String toTaskRevId = "";//msg + if (selectComponent instanceof TCComponentItem) { + //ѡж϶H8_wuliao + TCComponentItem item = (TCComponentItem) selectComponent; + //ȡѷ汾-latestReleasedRev + TCComponentItemRevision latestItemRevision = getLastReleaseRevison(item); + if (latestItemRevision == null) { + System.out.println("ǰѡж󲻴ѷ汾޷·"); + MessageBox.post("ǰѡж󲻴ѷ汾޷·","ʾ",MessageBox.INFORMATION); + thread.setBool(true); + return; + } + revID = latestItemRevision.getProperty("item_revision_id");//Cеòѯݣȡ汾 + itemID = latestItemRevision.getProperty("item_id"); + toTaskRevId = itemID + "-" + revID; + + }else if (selectComponent instanceof TCComponentItemRevision) { + //TODO ѡжϰ汾H8_PartRevision + System.out.println("ǰѡж H8_drawingRevision"); + TCComponentItemRevision revision = (TCComponentItemRevision)selectComponent; + String releaseDate = revision.getProperty("date_released"); + System.out.println("===>ȡǰ汾ķ״̬"+releaseDate); + if (releaseDate == null) { + System.out.println("ǰ汾δ"); + MessageBox.post("ǰ汾δ޷·","ʾ",MessageBox.INFORMATION); + thread.setBool(true); + return; + } + revID = revision.getProperty("item_revision_id"); + itemID = revision.getProperty("item_id"); + toTaskRevId = itemID + "-" + revID; + + }else { + MessageBox.post("erro select!","tip",MessageBox.INFORMATION); + return; + + } + //֯msgTask + String tasksource = "ֶ·"; + String userName = session.getUser().getUserName(); + String userId = session.getUser().getUserId(); + String status = "δʼ"; + String starttime = getCurrentTime(); + //жtaskǷѾͬ + + Map paramMap = new HashMap(); + //ƥspringbootеIJѯ + paramMap.put("MSG", toTaskRevId); + Integer result = sendRequest("getByMSG",paramMap); + if (result > 0) {//ظݣ + System.out.println("TASKظݣ¡"); + Map paramMapU = new HashMap(); + paramMapU.put("TASKSOURCE",tasksource); + paramMapU.put("USERNAME",userName); + paramMapU.put("USERID",userId); + paramMapU.put("STATUS",status); + paramMapU.put("STARTTIME",starttime); + paramMapU.put("MSG",toTaskRevId); + Integer resultU = sendRequest("updateTask",paramMapU); + if (resultU == -1){ + System.out.println("springbootʧܣupdateTask"); + } + }else {//ظݣ + System.out.println("TASKظݣ롤"); + Map paramMapI = new HashMap(); + paramMapI.put("TASKSOURCE",tasksource); + paramMapI.put("USERNAME",userName); + paramMapI.put("USERID",userId); + paramMapI.put("STATUS",status); + paramMapI.put("MSG",toTaskRevId); + paramMapI.put("STARTTIME",starttime); + Integer resultI = sendRequest("insertTask",paramMapI); + if (resultI == -1){ + System.out.println("springbootʧܣinsertTask"); + } + System.out.println("1"); + } + System.out.println("2"); + } + System.out.println("deal end!"); + } catch (Exception e) { + // TODO: handle exception + System.out.println("===>·ʧ"); + MessageBox.post("·ʧ","ʾ",MessageBox.INFORMATION); + e.printStackTrace(); + } + MessageBox.post("·ɹ","ʾ",MessageBox.INFORMATION); + + thread.setBool(true); + } + + /** + * 첽 + * @return -1 ʾʧ + */ + private Integer sendRequest(String way,Map param){ + System.out.println("ʼ÷SpringBoot󡤡"); + Integer resultInteger = 0; + String urlString = "http://"+Constants.SPRING_ADDRESS+"/part/"+way; + try {//Իip192.168.3.125 + String url = StrUtil.format(urlString);//springbootڷipַ + System.out.println(urlString); + // POST + HttpResponse response = HttpRequest.post(url) + .header("Content-Type", "application/json") // ΪJSON + .body(JSONUtil.toJsonStr(param)) // ΪJSONַ + .timeout(20*1000) // óʱʱ + .execute(); + System.out.println("SpringBootִݿĽΪ"+response.body()+"\n ЯϢΪ"+param.toString()); + resultInteger = Integer.parseInt(response.body()); + int statusCode = response.getStatus(); + if (statusCode < 200 && statusCode > 300) { + System.out.println("Ӧ쳣: ȡϢΪ!"); + return -1; + } + + } catch (HttpException e) { + // Ƿdzʱ쳣 + if (e.getMessage().contains("Read timed out") || e.getMessage().contains("Connect timed out")) { + System.out.println("ʱ: " + e.getMessage()); + return -2; // ʹòͬķֵʶʱ + } else { + // ͵HttpException + System.out.println("зHttpException: " + e.getMessage()); + return -1; + } + } catch (Exception e) { + // 쳣 + System.out.println("з쳣: " + e.getMessage()); + e.printStackTrace(); // ӡջϢԱ + return -1; + } + + return resultInteger; + } + +} diff --git a/src/com/connor/bhdz/pdm/partToCapp/SendPartToCappHandler.java b/src/com/connor/bhdz/pdm/partToCapp/SendPartToCappHandler.java new file mode 100644 index 0000000..7b4e6f3 --- /dev/null +++ b/src/com/connor/bhdz/pdm/partToCapp/SendPartToCappHandler.java @@ -0,0 +1,65 @@ +package com.connor.bhdz.pdm.partToCapp; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; + +import com.connor.bhdz.pdm.drawingToCapp.ProgressReporterDialog; +import com.teamcenter.rac.aif.AbstractAIFApplication; +import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; +import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.util.MessageBox; + +public class SendPartToCappHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent arg0) throws ExecutionException { + AbstractAIFApplication app = AIFUtility.getCurrentApplication(); +// жѡУǷзH8_wuliao͵϶ + InterfaceAIFComponent[] components = app.getTargetComponents(); + try { + if (components != null && components.length > 0) { + //ÿһѡж + for (InterfaceAIFComponent component : components) { + TCComponentItem item; + String componentType = ""; + if (component instanceof TCComponentItemRevision) { + TCComponentItemRevision rev = (TCComponentItemRevision) component; + item = rev.getItem(); + componentType = "rev"; + + }else if (component instanceof TCComponentItem) { + item = (TCComponentItem) component; + componentType = "item"; + }else { + MessageBox.post("ѡ϶","ʾ",MessageBox.INFORMATION); + return null; + } + //жѡжǷH8_drawing + String typeString = item.getStringProperty("object_type"); + System.out.println("ǰѡжitem=="+typeString); + + if (!typeString.equals("H8_wuliao")) { + MessageBox.post("ѡ϶","ʾ",MessageBox.INFORMATION); return null; } + + } + } + System.out.println("ýȵ"); + + + System.out.println("ʼ·"); + //ȫH8_drawing͵Ķ󣬲תaction + SendPartToCappAction ac = new SendPartToCappAction(app, null, null); + new Thread(ac).start(); + System.out.println("·ɣرսȵ"); + + } catch (TCException e) { + e.printStackTrace(); + } + return null; + } + +}