20240808更新自制外购属性

main
李建辉 10 months ago
parent e3ee0e25b6
commit b897f349f2

@ -48,7 +48,6 @@ Require-Bundle: org.eclipse.ui,
com.teamcenter.rac.util;bundle-version="11000.2.0",
org.eclipse.osgi.services;bundle-version="3.3.100",
TcSoaCaeRac;bundle-version="11000.2.0",
com.teamcenter.rac.project;bundle-version="11000.2.0",
org.apache.poi.39;bundle-version="3.9.0"
Automatic-Module-Name: com.connor.chint.yunpi
Bundle-RequiredExecutionEnvironment: JavaSE-1.8,

@ -6,7 +6,9 @@
<!--工具条-->
<command name="SRM图纸下发查询" id="com.chint.plm.SearchSapResult9.PlclIDHandler"/>
<command name="SRM图纸下发" id="com.connor.plm.srm.SRMHandler"/>
<command name="更新图纸自制外购" id="com.connor.plm.txdp.GXTZHandler"/>
<command name="铁心数据管理" id="com.connor.plm.txdp.TXDPHandler"/>
<command name="标准工时维护" id="com.connor.plm.txdp.BZGSHandler"/>
<command name="获取售前资料" id="com.connor.plm.srm.FileIntegrationHandler"/>
<command name="DBOM转EBOM" id="com.connor.chint.yunpi.command.DbomToECommand"/>
<command name="EBOM转PBOM" id="com.connor.chint.yunpi.command.EbomToPCommand"/>
@ -46,6 +48,8 @@
<handler commandId="com.chint.plm.SearchSapResult9.PlclIDHandler" class="com.chint.plm.SearchSapResult9.PlclIDHandler"/>
<handler commandId="com.connor.plm.srm.SRMHandler" class="com.connor.plm.srm.SRMHandler"/>
<handler commandId="com.connor.plm.txdp.TXDPHandler" class="com.connor.plm.txdp.TXDPHandler"/>
<handler commandId="com.connor.plm.txdp.BZGSHandler" class="com.connor.plm.txdp.BZGSHandler"/>
<handler commandId="com.connor.plm.txdp.GXTZHandler" class="com.connor.plm.txdp.GXTZHandler"/>
<handler commandId="com.chint.plm.createbomdifference.BomCompareComd" class="com.connor.chint.yunpi.KHandler"/>
<handler commandId="com.chint.plm.createbomdifference.ExtractDiffComd" class="com.connor.chint.yunpi.KHandler"/>
<handler commandId="com.chint.plm.extractdraw.ExtractDrawComd" class="com.connor.chint.yunpi.KHandler"/>
@ -692,6 +696,50 @@
</visibleWhen>
</command>
<command commandId = "com.connor.plm.txdp.BZGSHandler" id = "com.connor.plm.txdp.BZGSHandler">
<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.connor.plm.txdp.BZGSHandler">
</equals>
</iterate>
</not>
</with>
</and>
</visibleWhen>
</command>
<command commandId = "com.connor.plm.txdp.GXTZHandler" id = "com.connor.plm.txdp.GXTZHandler">
<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.connor.plm.txdp.GXTZHandler">
</equals>
</iterate>
</not>
</with>
</and>
</visibleWhen>
</command>
<command commandId = "com.connor.plm.srm.FileIntegrationHandler" id = "com.connor.plm.srm.FileIntegrationHandler">
<visibleWhen>
<and>

@ -1144,6 +1144,11 @@ public class ApplyMatnrOp extends AbstractAIFOperation {
general_maps.put(rev, specs);
}
}
}else {//20240730增加查询查到的逻辑
if(comps!= null && comps.length > 0) {
partRevs.add(comps[0]);
}
}

@ -1147,6 +1147,11 @@ public class ApplyMatnrOp2 extends AbstractAIFOperation {
general_maps.put(rev, specs);
}
}
}else {//20240730增加查询查到的逻辑
if(comps!= null && comps.length > 0) {
partRevs.add(comps[0]);
}
}

@ -147,6 +147,8 @@ public class MySceneController extends KFXPanelController {
private String findLovString = "SELECT result FROM CHINT_CHECK_LOV_TEMPLATE where lovcode = ? ORDER BY code asc";
private String addMsgString = "INSERT INTO CHINT_CHECK_DETAILS (no,imcheckproject,ipcheckdetials,designresult,proofreadresult,design,proofread,"
+ "\"AUDIT\",checkno,modelversion,numberofchecks) VALUES (?,?,?,?,?,?,?,?,?,?,1)";
private String addMsgString1 = "INSERT INTO CHINT_CHECK_DETAILS (no,imcheckproject,ipcheckdetials,designresult,proofreadresult,design,proofread,"
+ "\"AUDIT\",checkno,modelversion,numberofchecks) VALUES (?,?,?,?,?,?,?,?,?,?,?)";
private String oldMsgString = "SELECT no,designresult,PROOFREADRESULT,design,proofread,\"AUDIT\" FROM CHINT_CHECK_DETAILS where checkno = ? and modelversion = ? and numberofchecks = ? ORDER BY no asc ";
private String updMsgString = "UPDATE CHINT_CHECK_DETAILS SET designresult = ?,proofreadresult = ?,design = ?,proofread = ?,\"AUDIT\" = ? where checkno = ? and no = ? and modelversion = ? and numberofchecks = ? ";
private String getTempString = "SELECT no,imcheckproject,ipcheckdetials,designresultrule,proofreadresultrule,designrule,proofreadrule,auditrule"
@ -260,7 +262,20 @@ public class MySceneController extends KFXPanelController {
shType = "2";
}
if(isFirst) {
SqlUtil.write(addMsgString, new String[] {String.valueOf(i),zdjc,zdhc,valYqz,valSjz,sjType,jdType,shType,code,version});
//update
String text = cb_jccs.getValue();
//20240805 增加非第一次检查次数逻辑
if(text != null && !text.isEmpty()) {
String substring = text.substring(1, 2);
System.out.println("text==="+substring);
SqlUtil.write(addMsgString1, new String[] {String.valueOf(i),zdjc,zdhc,valYqz,valSjz,sjType,jdType,shType,code,version,substring});
}else {
SqlUtil.write(addMsgString, new String[] {String.valueOf(i),zdjc,zdhc,valYqz,valSjz,sjType,jdType,shType,code,version});
}
}else {
//update
String text = cb_jccs.getValue();
@ -1259,6 +1274,7 @@ public class MySceneController extends KFXPanelController {
// String testTh = "TestTh00001";
if(checkno!=null) {
ResultSet read2 = SqlUtil.read(oldMsgString, new String[] {checkno,version,String.valueOf(selectedIndex+1)});
System.out.println(checkno+"-"+version+"-"+String.valueOf(selectedIndex+1));
System.out.println("version==>"+version);
while(read2.next()) {
isFirst = false;

@ -0,0 +1,368 @@
package com.connor.plm.txdp;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Month;
import java.time.YearMonth;
import java.time.temporal.ChronoUnit;
import java.time.temporal.WeekFields;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.connor.chint.sap2.util.SAPUtil;
import com.connor.chint.sap2.util.SqlUtil;
import com.teamcenter.rac.kernel.TCComponent;
import com.teamcenter.rac.kernel.TCComponentDataset;
import com.teamcenter.rac.kernel.TCException;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.DateButton;
import com.teamcenter.rac.util.MessageBox;
import com.teamcenter.rac.util.PropertyLayout;
public class BZGSFram extends JFrame implements ActionListener {
private TCSession session;
protected DefaultTableModel tm_part;
private static ArrayList<String> dateConnList = new ArrayList<String>();
private String[] prefs;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
StringBuilder insertSql = new StringBuilder();
private JTextField pathJTextField = new JTextField(30);
private JButton outputButton = new JButton("选择");
private Workbook workbook;
public BZGSFram(TCSession session) {
// TODO Auto-generated constructor stub
this.session = session;
prefs = session.getPreferenceService().getStringValues("CHINT_SRM_SQL_CONNECT");
initUI();
}
private String sqlString = "";
private void initUI() {
// TODO Auto-generated method stub
try {
this.setTitle("工时维护界面");
this.setLayout(new BorderLayout());
JPanel topPanel = getTopPanel();
JPanel btnPanel = getBtnPanel();
this.add(topPanel, BorderLayout.NORTH);
// this.add(pane,BorderLayout.CENTER);
this.add(btnPanel, BorderLayout.SOUTH);
this.setPreferredSize(new Dimension(550, 115));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); // 获取屏幕尺寸
int screenWidth = screenSize.width; // 获取屏幕宽度
int screenHeight = screenSize.height; // 获取屏幕高度
int x = (screenWidth - 550) / 2; // 计算Frame的左上角x坐标
int y = (screenHeight - 300) / 2; // 计算Frame的左上角y坐标
this.setLocation(x, y); // 设置Frame的位置
// this.setLocationRelativeTo(null);
this.createActionEvent();
this.pack();
// this.validate();
this.setVisible(true);
// this.setAlwaysOnTop(true);
} catch (Exception e) {
e.printStackTrace();
return;
}
}
// 添加监听
public void createActionEvent() {
this.btnIn.addActionListener(this);
}
private List<TCComponent> compList = new ArrayList<TCComponent>();
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Object source = e.getSource();
System.out.println("source==>+" + source);
if (this.btnIn.equals(source)) {
//导入的逻辑
String pathJTextFieldStr = pathJTextField.getText();
if(pathJTextFieldStr == null || pathJTextFieldStr.isEmpty()) {
MessageBox.post("请选择需要导入的Excel。", "提示", 2);
return;
}
FileInputStream input = null;
try {
SqlUtil.SRMGetTCDataConnection(prefs);
if(!pathJTextFieldStr.contains(".xlsx")) {
MessageBox.post("请选择.xlsx格式的Excel。", "提示", 2);
return;
}
File file = new File(pathJTextFieldStr);
input = new FileInputStream(file);
workbook = new XSSFWorkbook(input);
//获取sheet页
Sheet sheet0 = workbook.getSheet("工时规则表");
//excel每一列的字段和数据库对比 判断该列是否导入
LinkedHashMap<String, Integer> titleMap = new LinkedHashMap<String, Integer>();
Row row1 = sheet0.getRow(0);
for (int i = 0; i < 100; i++) {
Cell cell = row1.getCell(i);
if(cell == null || getCellValue(cell).isEmpty()) {
System.out.println("i==="+i);
break;
}else {
titleMap.put(getCellValue(cell), cell.getColumnIndex());
}
}
System.out.println("titleMap==="+titleMap.toString());
String selectTitleSql = "SELECT column_name FROM all_tab_columns WHERE owner = 'INFODBA' AND table_name = 'CHINT_WORKHOUR'";
System.out.println("selectTitleSql ========="+selectTitleSql);
ResultSet rs = SqlUtil.read(selectTitleSql.toString());
ArrayList<String> titleArray = new ArrayList<String>();
while (rs.next()) {
titleArray.add(rs.getString(1));
}
System.out.println("titleArray==="+titleArray.toString());
Iterator<Map.Entry<String, Integer>> iterator = titleMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, Integer> map = iterator.next();
if(!titleArray.contains(map.getKey())) {
iterator.remove();
System.out.println("被移除的key======================"+map.getKey());
}
}
//备份 将CHINT_WORKHOUR表中的数据全量拷贝至表CHINT_WORKHOUR_BACKUP中
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String newTime = simpleDateFormat.format(new Date());
String user = session.getUser().getStringProperty("object_string");
String saveSql = "INSERT INTO CHINT_WORKHOUR_BACKUP(\"COMPANYCODE\", \"PRODUCTTYPE\", \"PRODUCTXH\", \"JSASK\", \"GYNAME\", \"GYID\", \"GXNAME\", \"GXCODE\", \"ARTIFICIALTIME\", \"MACHINETIME\", \"READINESSTIME\", \"GXMARK\", \"BZTH\", \"ProCycle\", \"VOLTAGELEVEL\", \"USER\", \"CREATETIME\") " +
"SELECT \"COMPANYCODE\", \"PRODUCTTYPE\", \"PRODUCTXH\", \"JSASK\", \"GYNAME\", \"GYID\", \"GXNAME\", \"GXCODE\", \"ARTIFICIALTIME\", \"MACHINETIME\", \"READINESSTIME\", \"GXMARK\", \"BZTH\", \"ProCycle\", \"VOLTAGELEVEL\", '"+user+"', to_date('"+newTime+"','yyyy-mm-ddhh24:mi:ss')"+
"FROM CHINT_WORKHOUR_TEST";
System.out.println("saveSql ========="+saveSql);
SqlUtil.update(saveSql);
String groupID = SAPUtil.getGroupID(session);
//将当前用户登录组织的数据从CHINT_WORKHOUR表中删除
String deleteSql = "DELETE FROM CHINT_WORKHOUR_TEST WHERE COMPANYCODE ='"+groupID+"'";
SqlUtil.update(deleteSql);
//导入数据
//把导入的字段拼接
StringBuilder fieldStr = new StringBuilder();
//可以使用insert all into table(a) values(a) into table(a) values(a);
fieldStr.append("INSERT INTO CHINT_WORKHOUR_TEST(");
for (Map.Entry<String, Integer> map : titleMap.entrySet()) {
fieldStr.append("\"").append(map.getKey()).append("\",");
}
fieldStr.setLength(fieldStr.length() - 1);
fieldStr.append(") VALUES(");
// Integer[] values = (Integer[]) titleMap.values().toArray();
Integer[] values = titleMap.values().toArray(new Integer[0]);
for (int i = 2; i < sheet0.getLastRowNum()+1; i++) {
Row row = sheet0.getRow(i);
Cell cell = row.getCell(0);
if(getCellValue(cell).isEmpty()) {
break;
}else {
String insertSqlStr = getSql(fieldStr.toString(),row,values);
SqlUtil.update(insertSqlStr);
System.out.println("insertSqlStr==="+insertSqlStr);
}
}
// System.out.println("insertSql===="+insertSql.toString());
// SqlUtil.update(insertSql.toString());
} catch (Exception e2) {
e2.printStackTrace();
MessageBox.post("导入失败,请联系管理员!", "提示", 2);
}
MessageBox.post("导入成功!", "提示", 2);
}
}
private String getSql(String fieldStr, Row row, Integer[] values) {
// TODO Auto-generated method stub
StringBuilder tempInsertSql = new StringBuilder();
tempInsertSql.append(fieldStr);
for (int i = 0; i < values.length; i++) {
tempInsertSql.append("'").append(getCellValue(row.getCell(values[i]))).append("',");
}
tempInsertSql.setLength(tempInsertSql.length() - 1);
tempInsertSql.append(")");
System.out.println("tempInsertSql===="+tempInsertSql.toString());
insertSql.append(tempInsertSql).append(";");
return tempInsertSql.toString();
}
private JButton btnIn;
private JPanel getBtnPanel() {
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
btnIn = new JButton("导入");
topPanel.add("1.1.center", new JLabel(""));
topPanel.add("2.1.center", new JLabel(""));
topPanel.add("2.2.center", new JLabel(""));
topPanel.add("2.3.center", btnIn);
return topPanel;
}
// 查询部分
private JPanel getTopPanel() {
// TODO Auto-generated method stub
JPanel topPanel = new JPanel();
topPanel.setLayout(new PropertyLayout());
topPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
topPanel.add("1.1.left.center", new JLabel(""));
topPanel.add("2.1.left.center", new JLabel("文件存放位置:"));
topPanel.add("2.2.left.center", pathJTextField);
topPanel.add("2.3.left.center", outputButton);
// 注册输出按钮的点击事件监听器
outputButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// 创建文件选择器
JFileChooser fileChooser = new JFileChooser();
// 设置文件选择器只能选择文件夹
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
int result = fileChooser.showOpenDialog(topPanel);
if (result == JFileChooser.APPROVE_OPTION) {
// 获取用户选择的路径
String selectedPath = fileChooser.getSelectedFile().getPath();
// 输出用户选择的路径
System.out.println("用户选择的路径:" + selectedPath);
pathJTextField.setText(selectedPath);
}
}
});
return topPanel;
}
public String getCellValue(Cell cell) {
if(cell == null) {
return "";
}else {
int cellType = cell.getCellType();
System.out.println("cellType="+cellType+"===cell.getRowIndex()="+cell.getRowIndex()+"===cell.getColumnIndex()="+cell.getColumnIndex());
if(cellType == 1) {//string
return cell.getStringCellValue();
}else if(cellType == 3 || cellType == 0) {//num
double numericCellValue = cell.getNumericCellValue();
System.out.println("numericCellValue====================="+numericCellValue);
if(numericCellValue == 0.0) {
return ""; }
if (numericCellValue == Math.floor(numericCellValue) && !Double.isInfinite(numericCellValue)) {
long integerPart = (long) numericCellValue;
return integerPart+"";
}else {
return numericCellValue+"";
}
}else if(cellType == 2) {
// 检查单元格是否是公式类型
// 创建FormulaEvaluator
FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
// 评估公式
CellValue valueEval = evaluator.evaluate(cell);
//System.out.println("valueEval.getCellType()============================================"+valueEval.getCellType());
if(valueEval.getCellType() == 1) {
return valueEval.getStringValue();
}else if(valueEval.getCellType() == 0) {//num
double numericCellValue = valueEval.getNumberValue();
// 创建DecimalFormat对象指定格式模式
DecimalFormat df = new DecimalFormat("#.00");
// 格式化数字
String formattedNumber = df.format(numericCellValue);
if(numericCellValue == 0.0) {
return ""; }
return formattedNumber;
}
}
}
return "";
}
}

@ -0,0 +1,69 @@
package com.connor.plm.txdp;
import java.util.HashMap;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.connor.chint.sap2.util.SAPUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCSession;
import com.teamcenter.rac.util.MessageBox;
public class BZGSHandler extends AbstractHandler{
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
try {
//获取首选项判断用户是否可以使用该功能
String[] prefs = session.getPreferenceService().getStringValues("CHINT_WORKHOUR_ACL");
String userId = session.getUser().getUserId();
String groupID = SAPUtil.getGroupID(session);
HashMap<String, String> groupNamesMap = new HashMap<String, String>();
for (int i = 0; i < prefs.length; i++) {
String[] split = prefs[i].split(":");
groupNamesMap.put(split[0], split[1]);
}
System.out.println("groupNamesMap==="+groupNamesMap.toString());
String names = groupNamesMap.get(groupID);
System.out.println("names==="+names);
if(names == null || names.isEmpty()) {
MessageBox.post("您无权使用此功能,请联系管理员处理。", "提示", MessageBox.INFORMATION);
return null;
}else {
if(!names.contains(userId)) {
MessageBox.post("您无权使用此功能,请联系管理员处理。", "提示", MessageBox.INFORMATION);
return null;
}
}
new Thread() {
@Override
public void run() {
try {
new BZGSFram(session);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,44 @@
package com.connor.plm.txdp;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import com.connor.chint.yunpi.command.BomDcSapOp;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aifrcp.AIFUtility;
import com.teamcenter.rac.kernel.TCSession;
public class GXTZHandler extends AbstractHandler{
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
AbstractAIFApplication app = AIFUtility.getCurrentApplication();
TCSession session = (TCSession) app.getSession();
try {
new Thread() {
@Override
public void run() {
try {
new GXTZOp(app).executeOperation();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}.start();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,175 @@
package com.connor.plm.txdp;
import java.sql.ResultSet;
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 java.util.Map.Entry;
import javax.swing.JButton;
import javax.swing.JTextField;
import org.apache.poi.ss.usermodel.Workbook;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import com.connor.chint.sap2.util.BomToSapUtil;
import com.connor.chint.sap2.util.BomUtilWh;
import com.connor.chint.sap2.util.KUtil;
import com.connor.chint.sap2.util.MyProgressBarCompent;
import com.connor.chint.sap2.util.SAPMessageUtil;
import com.connor.chint.sap2.util.SAPUtil;
import com.connor.chint.sap2.util.SqlUtil;
import com.connor.chint.sap2.util.TXTUtil;
import com.teamcenter.rac.aif.AbstractAIFApplication;
import com.teamcenter.rac.aif.AbstractAIFOperation;
import com.teamcenter.rac.aif.kernel.AIFComponentContext;
import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent;
import com.teamcenter.rac.aifrcp.AIFUtility;
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.TCComponentItem;
import com.teamcenter.rac.kernel.TCComponentItemRevision;
import com.teamcenter.rac.kernel.TCComponentItemType;
import com.teamcenter.rac.kernel.TCComponentMEProcessRevision;
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 com.teamcenter.services.rac.cad._2007_01.StructureManagement.ExpandPSData;
public class GXTZOp extends AbstractAIFOperation {
private AbstractAIFApplication app;
private TCSession session;
private String groupName;
private String userName;
private String[] prefs;
public GXTZOp(AbstractAIFApplication app) {
// Auto-generated constructor stub
this.app = app;
this.session = (TCSession) app.getSession();
prefs = session.getPreferenceService().getStringValues("CHINT_SRM_SQL_CONNECT");
}
@Override
public void executeOperation() throws Exception {
// Auto-generated method stub
MyProgressBarCompent comp = null;
SqlUtil.SRMGetTCDataConnection(prefs);
try {
KUtil.setByPass(true);
groupName = SAPUtil.getGroupID(session);
userName = getUserName(session);
System.out.println(groupName + "------------------" + userName);
InterfaceAIFComponent target = app.getTargetComponent();
TCComponentItemRevision degignRev = null;
if (target != null && target.getType().equals("ZT2_Design3DRevision")) {
degignRev = (TCComponentItemRevision) target;
} else {
MessageBox.post("请选择图纸版本", "", MessageBox.INFORMATION);
return;
}
// sql查询获取对应组的图纸id
HashMap<String, String> sqlMap = new HashMap<String, String>();
String selectSql = "SELECT \"drawingno\",\"source\" FROM CHINT_DESIGN__SOURCE_RULE WHERE \"factory\" = '"
+ groupName + "'";
System.out.println("selectSql =========" + selectSql);
ResultSet rs = SqlUtil.read(selectSql);
while (rs.next()) {
sqlMap.put(rs.getString(1), rs.getString(2));
}
if (sqlMap.size() == 0) {
MessageBox.post("该组织未在数据库中获取到图纸", "", MessageBox.INFORMATION);
return;
}
System.out.println("sqlMap====" + sqlMap.toString());
comp = new MyProgressBarCompent("", "正在进行更新图纸自制外购....");
String lineSeparator = System.lineSeparator();// 换行符
StringBuffer errMessage = new StringBuffer("");
StringBuffer succMessage = new StringBuffer("");
succMessage.append("成功修改数据如下:").append(lineSeparator);
errMessage.append("无法修改数据如下:").append(lineSeparator);
String current_user_name = getUserName(session);
TCComponentBOMWindowType bomWinType = (TCComponentBOMWindowType) session.getTypeComponent("BOMWindow");
TCComponentBOMWindow win = bomWinType.create(null);
TCComponentBOMLine setWindowTopLine = win.setWindowTopLine(degignRev.getItem(), degignRev, null, null);
// soa获取bom子
List<TCComponentItemRevision> childLines = BomToSapUtil.getBomLineTreeNodeSOA2(setWindowTopLine);
System.out.println("childLines.size====" + childLines.size());
// 遍历逻辑
for (int i = 0; i < childLines.size(); i++) {
TCComponentItemRevision tcComponentItemRevision = childLines.get(i);
String[] properties = tcComponentItemRevision
.getProperties(new String[] { "item_id", "item_revision_id" });
String zt2_Source = tcComponentItemRevision.getStringProperty("zt2_Source");
for (Entry<String, String> map : sqlMap.entrySet()) {
String key = map.getKey();
if (properties[0].contains(key)) {
String value = map.getValue();
System.out.println("item_id========" + properties[0]);
if (!zt2_Source.equals(value)) {
// 判断是否发布
if (KUtil.isTCM(tcComponentItemRevision)) {
errMessage.append(properties[0] + "-" + properties[1] + "因发布无法更改,请手工处理");
errMessage.append(lineSeparator);
} else {
// 判断登录人是否owning_user
TCComponent owning_user = tcComponentItemRevision.getReferenceProperty("owning_user");
String user_name = owning_user.getProperty("user_name");
if (current_user_name.equals(user_name)) {
// 修改版本的值
tcComponentItemRevision.setProperty("zt2_Source", value);
succMessage.append(
properties[0] + "-" + properties[1] + "已从" + (zt2_Source.equals("S1")?"自制":"外购") + "改成" + (value.equals("S1")?"自制":"外购"));
succMessage.append(lineSeparator);
} else {
errMessage.append(properties[0] + "-" + properties[1] + "所有者为" + user_name
+ ",无法更改,请联系" + user_name);
errMessage.append(lineSeparator);
}
}
}
}
}
}
win.close();
if (comp != null) {
comp.setVisible(false);
}
MessageBox.post(succMessage.toString() + lineSeparator + errMessage.toString(), "项目BOM传递SAP", 2);
} catch (Exception e) {
e.printStackTrace();
} finally {
KUtil.setByPass(false);
}
}
public String getUserName(TCSession session) throws TCException {
TCComponentUser user = session.getUser();
session.getUserName();
return user.getTCProperty("user_name").getDisplayValue();
}
}

@ -18,6 +18,7 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.Month;
@ -145,33 +146,33 @@ public class TXDPFram extends JFrame implements ActionListener {
if (this.btnIn.equals(source)) {
//导入的逻辑
String pathJTextFieldStr = pathJTextField.getText();
// if(pathJTextFieldStr == null || pathJTextFieldStr.isEmpty()) {
// MessageBox.post("请选择需要导入的Excel。", "提示", 2);
// return;
// }
if(pathJTextFieldStr == null || pathJTextFieldStr.isEmpty()) {
MessageBox.post("请选择需要导入的Excel。", "提示", 2);
return;
}
FileInputStream input = null;
try {
SqlUtil.SRMGetTCDataConnection(prefs);
//
//
//
// if(!pathJTextFieldStr.contains(".xlsx")) {
// MessageBox.post("请选择.xlsx格式的Excel。", "提示", 2);
// return;
// }
//
// //判断是否填写宽度和距离
// if(xjjTextField == null || xjjTextField.getText().isEmpty()) {
// MessageBox.post("请填写 “下夹件宽度” 后再导入!", "提示", 2);
// return;
// }
//
// if(edmTextField == null || edmTextField.getText().isEmpty()) {
// MessageBox.post("请填写 “轭断面距离” 后导入!", "提示", 2);
// return;
// }
if(!pathJTextFieldStr.contains(".xlsx")) {
MessageBox.post("请选择.xlsx格式的Excel。", "提示", 2);
return;
}
File file = new File("D://a.xlsx");
//判断是否填写宽度和距离
if(xjjTextField == null || xjjTextField.getText().isEmpty()) {
MessageBox.post("请填写 “下夹件宽度” 后再导入!", "提示", 2);
return;
}
if(edmTextField == null || edmTextField.getText().isEmpty()) {
MessageBox.post("请填写 “轭断面距离” 后导入!", "提示", 2);
return;
}
File file = new File(pathJTextFieldStr);
input = new FileInputStream(file);
workbook = new XSSFWorkbook(input);
int numberOfSheets = workbook.getNumberOfSheets();
@ -204,12 +205,17 @@ public class TXDPFram extends JFrame implements ActionListener {
Row row4 = sheet0.getRow(4);
Row row5 = sheet0.getRow(5);
Row row6 = sheet0.getRow(6);
Row row35 = sheet0.getRow(35);
drawingno = getCellValue(row2.getCell(5));
if(drawingno == null || drawingno.isEmpty()) {
MessageBox.post("图纸代号不可为空!", "提示", 2);
return;
}
String insertSqlT1 = "INSERT INTO CHINT_IRON_CORE_SUM(\"lower_clamp_width\",\"yoke_section_distance\",\"drawingno\",\"producttype\",\"productmodel\",\"workcode\",\"core_angle_weight\",\"core_netdiameter\",\"mo\",\"hw\",\"core_cross_secarea\",\"core_filmthick_ness\",\"lamination_coefficient\",\"material_code\",\"reference_cross_sectional_area\",\"stepping_eccentricity_1\",\"stepping_eccentricity_2\",\"stepping_eccentricity_3\",\"step_mode\",\"net_core_weight\") VALUES('"+
String insertSqlT1 = "INSERT INTO CHINT_IRON_CORE_SUM(\"lower_clamp_width\",\"yoke_section_distance\",\"drawingno\",\"producttype\",\"productmodel\",\"workcode\",\"core_angle_weight\",\"core_netdiameter\",\"mo\",\"hw\",\"core_cross_secarea\",\"core_filmthick_ness\",\"lamination_coefficient\",\"material_code\",\"reference_cross_sectional_area\",\"stepping_eccentricity_1\",\"stepping_eccentricity_2\",\"stepping_eccentricity_3\",\"step_mode\",\"net_core_weight\",\"half_stack\",\"cross_sectional_area_face\") VALUES('"+
xjjTextField.getText()+"','"+
edmTextField.getText()+"','"+
drawingno+"','"+
@ -229,7 +235,9 @@ public class TXDPFram extends JFrame implements ActionListener {
getCellValue(row6.getCell(4))+"','"+
getCellValue(row6.getCell(5))+"','"+
getCellValue(row6.getCell(7))+"','"+
getCellValue(row6.getCell(10))+"')";
getCellValue(row6.getCell(10))+"','"+
getCellValue(row35.getCell(8))+"','"+
getCellValue(row35.getCell(9))+"')";
System.out.println("insertSqlT1======="+insertSqlT1);
@ -267,6 +275,12 @@ public class TXDPFram extends JFrame implements ActionListener {
}
}
}
//中柱
if(sheet1 != null) {
@ -295,7 +309,7 @@ public class TXDPFram extends JFrame implements ActionListener {
String cellValue = getCellValue(row.getCell(1));
String cellValue2 = getCellValue(row.getCell(2));
System.out.println("cellValue2================================================"+cellValue2);
if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0")) {
if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0") || cellValue2.equals("宽度-")) {
break;
}else {
@ -334,7 +348,7 @@ public class TXDPFram extends JFrame implements ActionListener {
String cellValue = getCellValue(row.getCell(1));
String cellValue2 = getCellValue(row.getCell(2));
System.out.println("cellValue2================================================"+cellValue2);
if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0")) {
if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0") || cellValue2.equals("宽度-")) {
break;
}else {
@ -361,7 +375,239 @@ public class TXDPFram extends JFrame implements ActionListener {
}
}else if(producttype.equals("五柱")) {
Sheet sheet0 = workbook.getSheet("数据输入");
Sheet sheet1 = workbook.getSheet("中柱剪切单1");
Sheet sheet2 = workbook.getSheet("中柱剪切单2");
Sheet sheet3 = workbook.getSheet("中柱剪切单3");
Sheet sheet4 = workbook.getSheet("边柱剪切单");
Sheet sheet5 = workbook.getSheet("轭剪切单1");
Sheet sheet6 = workbook.getSheet("轭剪切单2");
int lastRowNum = sheet0.getLastRowNum();
System.out.println("lastRowNum==================="+lastRowNum);
//组织数据输入表
if(sheet0 != null) {
//table1
Row row2 = sheet0.getRow(2);
Row row3 = sheet0.getRow(3);
Row row4 = sheet0.getRow(4);
Row row5 = sheet0.getRow(5);
Row row6 = sheet0.getRow(6);
Row row39 = sheet0.getRow(39);
drawingno = getCellValue(row2.getCell(6));
if(drawingno == null || drawingno.isEmpty()) {
MessageBox.post("图纸代号不可为空!", "提示", 2);
return;
}
String insertSqlT1 = "INSERT INTO CHINT_IRON_CORE_SUM(\"lower_clamp_width\",\"yoke_section_distance\",\"drawingno\",\"producttype\",\"productmodel\",\"workcode\",\"core_angle_weight\",\"core_netdiameter\",\"mo\",\"hw\",\"core_cross_sectional\",\"core_filmthick_ness\",\"lamination_coefficient\",\"material_code\",\"reference_cross_sectional_area\",\"stepping_eccentricity_1\",\"stepping_eccentricity_2\",\"stepping_eccentricity_3\",\"step_mode\",\"net_core_weight\",\"mo2\",\"half_stack\",\"cross_sectional_area_side\",\"cross_sectional_area_yoke\",\"cross_sectional_area_main\") VALUES('"+
xjjTextField.getText()+"','"+
edmTextField.getText()+"','"+
drawingno+"','"+
producttype+"','"+
getCellValue(row2.getCell(3))+"','"+
getCellValue(row2.getCell(8))+"','"+
getCellValue(row3.getCell(13))+"','"+
getCellValue(row4.getCell(3))+"','"+
getCellValue(row4.getCell(6))+"','"+
getCellValue(row4.getCell(8))+"','"+
getCellValue(row4.getCell(13))+"','"+
getCellValue(row5.getCell(3))+"','"+
getCellValue(row5.getCell(6))+"','"+
getCellValue(row5.getCell(8))+"','"+
getCellValue(row5.getCell(13))+"','"+
getCellValue(row6.getCell(3))+"','"+
getCellValue(row6.getCell(4))+"','"+
getCellValue(row6.getCell(5))+"','"+
getCellValue(row6.getCell(7))+"','"+
getCellValue(row6.getCell(13))+"','"+
getCellValue(row3.getCell(6))+"','"+
getCellValue(row39.getCell(9))+"','"+
getCellValue(row39.getCell(10))+"','"+
getCellValue(row39.getCell(11))+"','"+
getCellValue(row39.getCell(12))+"')";
System.out.println("5insertSqlT1======="+insertSqlT1);
SqlUtil.update(insertSqlT1);
//table2
for (int i = 8; i < sheet0.getLastRowNum(); i++) {
//判断该行是否为空数据
Row row = sheet0.getRow(i);
if(row == null) {
break;
}else {
String cellValue = getCellValue(row.getCell(3));
if(cellValue == null || cellValue.isEmpty()) {
break;
}else {
String insertSqlT2 = "INSERT INTO CHINT_IRON_CORE_SUM_DETIALS(\"drawingno\",\"producttype\",\"class_number\",\"thickness_perstage\",\"main_column_width\",\"side_column_width\",\"yoke_width\",\"yoke_offset\",\"oil_passage\",\"cumulative_stage_thickness\",\"cross_sectional_area_side\",\"cross_sectional_area_yoke\",\"cross_sectional_area_main\",\"number_pieces\") VALUES('"+
drawingno+"','"+
producttype+"','"+
getCellValue(row.getCell(2))+"','"+
getCellValue(row.getCell(3))+"','"+
getCellValue(row.getCell(4))+"','"+
getCellValue(row.getCell(5))+"','"+
getCellValue(row.getCell(6))+"','"+
getCellValue(row.getCell(7))+"','"+
getCellValue(row.getCell(8))+"','"+
getCellValue(row.getCell(9))+"','"+
getCellValue(row.getCell(10))+"','"+
getCellValue(row.getCell(11))+"','"+
getCellValue(row.getCell(12))+"','"+
getCellValue(row.getCell(13))+"')";
System.out.println("5insertSqlT2======="+insertSqlT2);
SqlUtil.update(insertSqlT2);
}
}
}
}
//中柱
if(sheet1 != null) {
getJqd(sheet1,drawingno,producttype);
}
if(sheet2 != null) {
getJqd(sheet2,drawingno,producttype);
}
if(sheet3 != null) {
getJqd(sheet3,drawingno,producttype);
}
//边柱
if(sheet4 != null) {
for (int i =2; i < sheet4.getLastRowNum(); i++) {
//判断该行是否为空数据
Row row = sheet4.getRow(i);
if(row == null) {
break;
}else {
String cellValue = getCellValue(row.getCell(1));
String cellValue2 = getCellValue(row.getCell(2));
if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0") || cellValue2.equals("宽度-")) {
break;
}else {
String insertSqlBz = "INSERT INTO CHINT_IRON_CORE_DETIALS(\"drawingno\",\"producttype\",\"class_number\",\"material_code\",\"slice_number\",\"weight\",\"pkup\",\"pkdn\",\"b\",\"a\",\"c\",\"classification\") VALUES('"+
drawingno+"','"+
producttype+"','"+
getCellValue(row.getCell(1))+"','"+
getCellValue(row.getCell(2))+"','"+
getCellValue(row.getCell(3))+"','"+
getCellValue(row.getCell(4))+"','"+
getCellValue(row.getCell(5))+"','"+
getCellValue(row.getCell(6))+"','"+
getCellValue(row.getCell(7))+"','"+
getCellValue(row.getCell(8))+"','"+
getCellValue(row.getCell(9))+"','"+
"边柱"+"')";
System.out.println("insertSqlBz======="+insertSqlBz);
SqlUtil.update(insertSqlBz);
}
}
}
}
//轭1
if(sheet5 != null) {
for (int i =2; i < sheet5.getLastRowNum(); i++) {
//判断该行是否为空数据
System.out.println("i-====================================="+i);
Row row = sheet5.getRow(i);
if(row == null) {
break;
}else {
String cellValue = getCellValue(row.getCell(1));
String cellValue2 = getCellValue(row.getCell(2));
System.out.println("cellValue2================================================"+cellValue2);
if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0") || cellValue2.equals("宽度-")) {
break;
}else {
String insertSqlE = "INSERT INTO CHINT_IRON_CORE_DETIALS(\"drawingno\",\"producttype\",\"class_number\",\"material_code\",\"slice_number\",\"weight\",\"pkup\",\"pkdn\",\"b\",\"d\",\"a\",\"c\",\"classification\") VALUES('"+
drawingno+"','"+
producttype+"','"+
getCellValue(row.getCell(1))+"','"+
getCellValue(row.getCell(2))+"','"+
getCellValue(row.getCell(3))+"','"+
getCellValue(row.getCell(4))+"','"+
getCellValue(row.getCell(5))+"','"+
getCellValue(row.getCell(6))+"','"+
getCellValue(row.getCell(7))+"','"+
getCellValue(row.getCell(8))+"','"+
getCellValue(row.getCell(9))+"','"+
getCellValue(row.getCell(10))+"','"+
"轭1"+"')";
System.out.println("insertSqlE1======="+insertSqlE);
SqlUtil.update(insertSqlE);
}
}
}
}
//轭2
if(sheet6 != null) {
for (int i =2; i < sheet6.getLastRowNum(); i++) {
//判断该行是否为空数据
Row row = sheet6.getRow(i);
if(row == null) {
break;
}else {
String cellValue = getCellValue(row.getCell(1));
String cellValue2 = getCellValue(row.getCell(2));
if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0") || cellValue2.equals("宽度-")) {
break;
}else {
String insertSqlE = "INSERT INTO CHINT_IRON_CORE_DETIALS(\"drawingno\",\"producttype\",\"class_number\",\"material_code\",\"slice_number\",\"weight\",\"pkup\",\"pkdn\",\"b\",\"d\",\"a\",\"c\",\"classification\") VALUES('"+
drawingno+"','"+
producttype+"','"+
getCellValue(row.getCell(1))+"','"+
getCellValue(row.getCell(2))+"','"+
getCellValue(row.getCell(3))+"','"+
getCellValue(row.getCell(4))+"','"+
getCellValue(row.getCell(5))+"','"+
getCellValue(row.getCell(6))+"','"+
getCellValue(row.getCell(7))+"','"+
getCellValue(row.getCell(8))+"','"+
getCellValue(row.getCell(9))+"','"+
getCellValue(row.getCell(10))+"','"+
"轭2"+"')";
System.out.println("insertSqlE2======="+insertSqlE);
SqlUtil.update(insertSqlE);
}
}
}
}
}else {
MessageBox.post("模板sheet页数有问题,判断不出是三柱还是五柱!", "提示", 2);
return;
@ -439,10 +685,18 @@ public class TXDPFram extends JFrame implements ActionListener {
return cell.getStringCellValue();
}else if(cellType == 3 || cellType == 0) {//num
double numericCellValue = cell.getNumericCellValue();
System.out.println("numericCellValue====================="+numericCellValue);
if(numericCellValue == 0.0) {
return ""; }
return cell.getNumericCellValue()+"";
if (numericCellValue == Math.floor(numericCellValue) && !Double.isInfinite(numericCellValue)) {
long integerPart = (long) numericCellValue;
return integerPart+"";
}else {
return numericCellValue+"";
}
}else if(cellType == 2) {
// 检查单元格是否是公式类型
// 创建FormulaEvaluator
@ -455,10 +709,14 @@ public class TXDPFram extends JFrame implements ActionListener {
}else if(valueEval.getCellType() == 0) {//num
double numericCellValue = valueEval.getNumberValue();
// 创建DecimalFormat对象指定格式模式
DecimalFormat df = new DecimalFormat("#.00");
// 格式化数字
String formattedNumber = df.format(numericCellValue);
if(numericCellValue == 0.0) {
return ""; }
return valueEval.getNumberValue()+"";
return formattedNumber;
}
}
@ -480,7 +738,7 @@ public class TXDPFram extends JFrame implements ActionListener {
String cellValue = getCellValue(row.getCell(1));
String cellValue2 = getCellValue(row.getCell(2));
System.out.println("cellValue2================================================"+cellValue2);
if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0")) {
if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0") || cellValue2.equals("宽度-")) {
break;
}else {
String insertSqlZz = "INSERT INTO CHINT_IRON_CORE_DETIALS(\"drawingno\",\"producttype\",\"class_number\",\"material_code\",\"slice_number\",\"weight\",\"pkup\",\"pkdn\",\"b\",\"d\",\"joint_number\",\"a\",\"c\",\"classification\") VALUES('"+

@ -16,6 +16,8 @@ public class TXDPHandler extends AbstractHandler{
TCSession session = (TCSession) app.getSession();
try {
new Thread() {
@Override
public void run() {

Loading…
Cancel
Save