diff --git a/com.connor.chint.wuhan/src/com/chint/plm/createKjBom/KjController.java b/com.connor.chint.wuhan/src/com/chint/plm/createKjBom/KjController.java index 1d13bfc..b18010b 100644 --- a/com.connor.chint.wuhan/src/com/chint/plm/createKjBom/KjController.java +++ b/com.connor.chint.wuhan/src/com/chint/plm/createKjBom/KjController.java @@ -1,6 +1,7 @@ package com.chint.plm.createKjBom; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -627,6 +628,8 @@ public class KjController { //批量复制 private void cloneOrUpdate(TCSession session, TCComponentBOMLine parentLine, List bomLines, List useLines) { + System.out.println("cloneOrUpdate==>" + bomLines); + System.out.println("useLines==>" + useLines); com.teamcenter.services.rac.structuremanagement.StructureService service = com.teamcenter.services.rac.structuremanagement.StructureService.getService(session); // idMapAdd.clear(); @@ -656,6 +659,10 @@ public class KjController { // for(int i = 0; i < bomLines.size(); i++) { // TCComponentBOMLine subLine = bomLines.get(i); TCComponentItem item = subLine.getItem(); +// String name = item.getProperty("object_name"); +// if(name.equals("箱底焊装") || name.equals("箱沿焊装")) {//TODO +// continue; +// } CloneStructureSaveAsIn dataMap = null; if(item.getType().equals("ZT2_Design3D")) { // subLine.replace @@ -687,8 +694,8 @@ public class KjController { // cloneStructureExpandOrUpdate.serviceData; if (cloneStructure.serviceData.sizeOfPartialErrors() > 0) { for (int i = 0; i < cloneStructure.serviceData.sizeOfPartialErrors(); i++) { - System.out.println("Save class Partial Error -- " + cloneStructure.serviceData - .getPartialError(i).getMessages()[0]); + System.out.println(i + "Save class Partial Error -- " + Arrays.toString(cloneStructure.serviceData + .getPartialError(i).getMessages())); } } try { diff --git a/com.connor.chint.wuhan/src/com/connor/plm/txdp/TXDPFram.java b/com.connor.chint.wuhan/src/com/connor/plm/txdp/TXDPFram.java index 9538162..7b5f898 100644 --- a/com.connor.chint.wuhan/src/com/connor/plm/txdp/TXDPFram.java +++ b/com.connor.chint.wuhan/src/com/connor/plm/txdp/TXDPFram.java @@ -7,94 +7,92 @@ 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.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.ChintPreferenceUtil; +import com.connor.chint.sap2.util.KUtil; import com.connor.chint.sap2.util.SAPUtil; import com.connor.chint.sap2.util.SqlUtil; +import com.squareup.okhttp.MediaType; +import com.squareup.okhttp.OkHttpClient; +import com.squareup.okhttp.Request; +import com.squareup.okhttp.Request.Builder; +import com.squareup.okhttp.RequestBody; +import com.squareup.okhttp.Response; +import com.teamcenter.rac.aif.kernel.AIFComponentContext; import com.teamcenter.rac.kernel.TCComponent; import com.teamcenter.rac.kernel.TCComponentDataset; -import com.teamcenter.rac.kernel.TCComponentGroup; -import com.teamcenter.rac.kernel.TCException; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; +import com.teamcenter.rac.kernel.TCComponentItemType; import com.teamcenter.rac.kernel.TCSession; -import com.teamcenter.rac.kernel.TCUserService; -import com.teamcenter.rac.util.DateButton; import com.teamcenter.rac.util.MessageBox; import com.teamcenter.rac.util.PropertyLayout; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + public class TXDPFram extends JFrame implements ActionListener { +/** + * + */ + private static final long serialVersionUID = 1L; private TCSession session; + private TCComponent target; + private String type; protected DefaultTableModel tm_part; - private static ArrayList dateConnList = new ArrayList(); +// private static ArrayList dateConnList = new ArrayList(); private String[] prefs; - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); +// private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); private JTextField pathJTextField = new JTextField(30); private JButton outputButton = new JButton("选择"); + private JTextField gctTextField = new JTextField(30); private JTextField xjjTextField = new JTextField(30); private JTextField edmTextField = new JTextField(30); - private Workbook workbook; - public TXDPFram(TCSession session) { - // TODO Auto-generated constructor stub + private Workbook workbook; + private int totalClass; + // 创建DecimalFormat对象,指定格式模式 + private DecimalFormat df = new DecimalFormat("#.00"); + + public TXDPFram(TCSession session, TCComponent target, String type) { + // Auto-generated constructor stub this.session = session; + this.target = target; + this.type = type; prefs = session.getPreferenceService().getStringValues("CHINT_SRM_SQL_CONNECT"); initUI(); } - private String sqlString = ""; +// private String sqlString = ""; private void initUI() { - // TODO Auto-generated method stub + // Auto-generated method stub try { this.setTitle("铁心数据导入界面"); this.setLayout(new BorderLayout()); @@ -137,7 +135,7 @@ public class TXDPFram extends JFrame implements ActionListener { } - private List compList = new ArrayList(); +// private List compList = new ArrayList(); @Override public void actionPerformed(ActionEvent e) { @@ -148,33 +146,159 @@ 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); + String gcth = gctTextField.getText(); + String lower_clamp_width = xjjTextField.getText(); + String yoke_section_distance = edmTextField.getText(); + if(pathJTextFieldStr.isEmpty()) { + if(gcth.isEmpty()) { + MessageBox.post("请选择需要导入的Excel或填写工程图号。", "提示", MessageBox.WARNING); + return; + } + if(lower_clamp_width.isEmpty()) { + MessageBox.post("请填写 “下夹件宽度” 后再导入!", "提示", MessageBox.WARNING); + return; + } + if(yoke_section_distance.isEmpty()) { + MessageBox.post("请填写 “轭断面距离” 后导入!", "提示", MessageBox.WARNING); + return; + } + try { + SqlUtil.SRMGetTCDataConnection(prefs); + String selectSql = "select distinct \"numtotalclass\",\"factory\",\"producttype\"," + + "\"productmodel\",\"core_filmthick_ness\",\"half_stack\" " + + "from CHINT_IRON_CORE_SUM where \"drawingno\"='" + gcth + "'"; + System.out.println("selectSql=======" + selectSql); + ResultSet rs = SqlUtil.read(selectSql); + boolean notFound = true, mom = false; + JSONObject json = new JSONObject(); + while(rs.next()) { + notFound = false; + if(rs.getString(3).equals("三柱")) { + mom = true; + String stack = rs.getString(6); + if(!stack.isEmpty()) { + Double oil = Double.parseDouble(stack); + stack = deleteZero(oil * 2); + } + json.put("NumTotalClass", rs.getString(1)); + json.put("ProductDrawingNumber", gcth); + json.put("ProductType", rs.getString(4)); + json.put("Thickness", rs.getString(5)); + json.put("StackThickness", stack); + json.put("LowerClampWidth", lower_clamp_width); + json.put("YokeEndFace", yoke_section_distance); + json.put("factory", rs.getString(2)); + } + } + if(notFound) { + MessageBox.post("数据库中无此图样代号,请联系电算人员上传!", "提示", MessageBox.WARNING); + return; + } + + String updateSql = "update CHINT_IRON_CORE_SUM set \"lower_clamp_width\"='" + lower_clamp_width + + "',\"yoke_section_distance\"='" + yoke_section_distance + "' where \"drawingno\"='" + + gcth + "'"; + System.out.println("updateSql=======" + updateSql); + SqlUtil.update(updateSql); + if(mom) { + String[] pref = ChintPreferenceUtil.getPreference("CHINT_GetCoreLaminationStacK", session) + .split("="); + if(pref[0].equals("MOM:1")) { + JSONArray classParameter = new JSONArray(); + selectSql = "select distinct a.\"class_number\",a.\"thickness_perstage\"," + + "a.\"yoke_offset\",a.\"oil_passage\",a.\"jetthickness\",a.\"number_pieces\"," + + "decode(b.\"d\",'',b.\"a\",b.\"d\") as 中柱d,b.\"b\" as 中柱b,c.\"b\" as 边柱b," + + "d.\"c\" as 轭c,d.\"b\" as 轭b " + + "from CHINT_IRON_CORE_SUM_DETIALS a,CHINT_IRON_CORE_DETIALS b," + + "CHINT_IRON_CORE_DETIALS c,CHINT_IRON_CORE_DETIALS d " + + "where a.\"drawingno\"=b.\"drawingno\" and a.\"class_number\"=b.\"class_number\" " + + "and b.\"classification\"='中柱' and a.\"drawingno\"=c.\"drawingno\" " + + "and a.\"class_number\"=c.\"class_number\" and c.\"classification\"='边柱' " + + "and a.\"drawingno\"=d.\"drawingno\" and a.\"class_number\"=d.\"class_number\" " + + "and d.\"classification\"='轭' and a.\"producttype\"='三柱' and a.\"drawingno\"='" + + gcth + "' order by to_number(a.\"class_number\")"; + System.out.println("selectSql=======" + selectSql); + rs = SqlUtil.read(selectSql); + while(rs.next()) { + JSONObject js = new JSONObject(); + String oil_passage = rs.getString(4); + if(oil_passage.isEmpty()) { + js.put("OilTunnel", "0"); + }else { + js.put("OilTunnel", "1"); + } + js.put("bJet", "0"); + js.put("ClassNumber", rs.getString(1)); + js.put("ClassThickness", rs.getString(2)); + js.put("OilTunnelThickness", oil_passage); + js.put("OutDistance", rs.getString(3)); + js.put("JetThickness", rs.getString(5)); + js.put("ActualLayersEach", rs.getString(6)); + js.put("LengthM", rs.getString(7)); + js.put("WidthM", rs.getString(8)); + js.put("WidthLeft", rs.getString(9)); + js.put("LengthDown", rs.getString(10)); + js.put("WidthDown", rs.getString(11)); + + classParameter.add(js); + } + json.put("ClassParameter", classParameter); + System.out.println("json==>" + json); + OkHttpClient client = new OkHttpClient(); + MediaType mediaType = MediaType.parse("application/json"); + RequestBody body = RequestBody.create(mediaType, json.toString()); + Builder builder = new Request.Builder() + .url(pref[1]) + .method("POST", body) + .addHeader("Content-Type", "application/json"); + if (pref[1].contains("10.128.11.12")) { + builder.addHeader("Authorization", "Basic MTQyODI0Mjg2NDU2ODMwNzcxNDpkREF3TWpveE1EQXg="); + } else { + builder.addHeader("Authorization", "Basic MTcxNDkwNTkyNTc2MjUzNTQyNjpkREF3TWpveE1EQXg="); + } + Request request = builder.build(); + Response response = client.newCall(request).execute(); + String string = response.body().string(); + System.out.println("response==>" + string); + JSONObject result = JSONObject.fromObject(string); + if(!result.get("status").equals("S")) { + MessageBox.post("MOM系统接收数据失败,请联系管理员\n错误码:" + result.get("code") + + "返回信息:" + result.get("msg"), "提示", MessageBox.WARNING); + return; + } + } + } + MessageBox.post("导入成功!", "提示", MessageBox.INFORMATION); + } catch (Exception e2) { + e2.printStackTrace(); + MessageBox.post("错误:" + e2, "提示", MessageBox.ERROR); + } finally { + SqlUtil.free(); + } return; } FileInputStream input = null; try { SqlUtil.SRMGetTCDataConnection(prefs); -// -// -// + if(!pathJTextFieldStr.contains(".xlsx")) { - MessageBox.post("请选择.xlsx格式的Excel。", "提示", 2); + MessageBox.post("请选择.xlsx格式的Excel。", "提示", MessageBox.WARNING); return; } - //判断是否填写宽度和距离 - 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); +// if(lower_clamp_width.isEmpty()) { +// MessageBox.post("请填写 “下夹件宽度” 后再导入!", "提示", MessageBox.WARNING); +// return; +// } +// if(yoke_section_distance.isEmpty()) { +// MessageBox.post("请填写 “轭断面距离” 后导入!", "提示", MessageBox.WARNING); +// return; +// } + String factory = SAPUtil.getGroupID(session); + File file = new File(pathJTextFieldStr); + String name = file.getName(); + name = name.substring(0, name.lastIndexOf(".")); + input = new FileInputStream(file); workbook = new XSSFWorkbook(input); int numberOfSheets = workbook.getNumberOfSheets(); @@ -190,13 +314,18 @@ public class TXDPFram extends JFrame implements ActionListener { } if(producttype.equals("三柱")) { + String[] pref = ChintPreferenceUtil.getPreference("CHINT_GetCoreLaminationStacK", session) + .split("="); + JSONObject json = new JSONObject(); + JSONArray classParameter = new JSONArray(); + LinkedHashMap map = new LinkedHashMap<>(); - 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("轭剪切单"); + 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("轭剪切单"); int lastRowNum = sheet0.getLastRowNum(); System.out.println("lastRowNum==================="+lastRowNum); //组织数据输入表 @@ -209,44 +338,99 @@ public class TXDPFram extends JFrame implements ActionListener { 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\",\"half_stack\",\"cross_sectional_area_face\") VALUES('"+ - xjjTextField.getText()+"','"+ - edmTextField.getText()+"','"+ - drawingno+"','"+ - producttype+"','"+ - getCellValue(row2.getCell(3))+"','"+ - getCellValue(row2.getCell(7))+"','"+ - getCellValue(row3.getCell(10))+"','"+ - getCellValue(row4.getCell(3))+"','"+ - getCellValue(row4.getCell(5))+"','"+ - getCellValue(row4.getCell(7))+"','"+ - getCellValue(row4.getCell(10))+"','"+ - getCellValue(row5.getCell(3))+"','"+ - getCellValue(row5.getCell(5))+"','"+ - getCellValue(row5.getCell(7))+"','"+ - getCellValue(row5.getCell(10))+"','"+ - getCellValue(row6.getCell(3))+"','"+ - getCellValue(row6.getCell(4))+"','"+ - getCellValue(row6.getCell(5))+"','"+ - getCellValue(row6.getCell(7))+"','"+ - getCellValue(row6.getCell(10))+"','"+ - getCellValue(row35.getCell(8))+"','"+ - getCellValue(row35.getCell(9))+"')"; + //导入前以图样代号进行判断,如果数据库里已经有drawingno数据,需要将现有的drawingno的数据全部删除,重新导入 + String deleteSql = "delete from CHINT_IRON_CORE_SUM where \"drawingno\"='" + drawingno + "'"; + System.out.println("deleteSql1=======" + deleteSql); + SqlUtil.delete(deleteSql); + deleteSql = "delete from CHINT_IRON_CORE_SUM_DETIALS where \"drawingno\"='" + drawingno + "'"; + System.out.println("deleteSql2=======" + deleteSql); + SqlUtil.delete(deleteSql); + deleteSql = "delete from CHINT_IRON_CORE_DETIALS where \"drawingno\"='" + drawingno + "'"; + System.out.println("deleteSql3=======" + deleteSql); + SqlUtil.delete(deleteSql); + + String numtotalclass = ""; + //根据数据导输入sheet页,找到每级厚有数据的最后一行,获取对应的级号的数字 + for(int i = 8; i < sheet0.getLastRowNum(); i++) { + String h = getCellValue(sheet0.getRow(i).getCell(3)); + if(h.isEmpty()) { + numtotalclass = getCellValue(sheet0.getRow(i - 1).getCell(2)); + totalClass = Integer.parseInt(numtotalclass); + break; + } + } + if(lower_clamp_width.isEmpty()) { + //下夹件宽度:轭片宽最大值-轭片偏距最大值+50 + double epkMax = getMax(sheet0, 7, 8, 8 + totalClass); + double eppjMax = getMax(sheet0, 5, 8, 8 + totalClass); + lower_clamp_width = deleteZero(epkMax - eppjMax + 50); + } + if(yoke_section_distance.isEmpty()) { + //轭断面距离:轭片偏距最大值 + yoke_section_distance = deleteZero(getMax(sheet0, 5, 8, 8 + totalClass)); + } + + String productmodel = getCellValue(row2.getCell(3)); + String core_filmthick_ness = getCellValue(row5.getCell(3)); + String half_stack = getCellValue(row35.getCell(8)); + String stack = half_stack; + if(!stack.isEmpty()) { + Double oil = Double.parseDouble(stack); + stack = deleteZero(oil * 2); + } + + json.put("NumTotalClass", numtotalclass); + json.put("ProductDrawingNumber", drawingno); + json.put("ProductType", productmodel); + json.put("Thickness", core_filmthick_ness); + json.put("StackThickness", stack); + json.put("LowerClampWidth", lower_clamp_width); + json.put("YokeEndFace", yoke_section_distance); + json.put("factory", factory); + + 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\"," + + "\"numtotalclass\",\"factory\") VALUES('"+ + lower_clamp_width + "','" + //lower_clamp_width + yoke_section_distance + "','" + //yoke_section_distance + drawingno + "','" + //drawingno + producttype + "','" + //producttype + productmodel + "','" + //productmodel + getCellValue(row2.getCell(7)) + "','" + //workcode + getCellValue(row3.getCell(10)) + "','" + //core_angle_weight + getCellValue(row4.getCell(3)) + "','" + //core_netdiameter + getCellValue(row4.getCell(5)) + "','" + //mo + getCellValue(row4.getCell(7)) + "','" + //hw + getCellValue(row4.getCell(10)) + "','" + //core_cross_secarea + core_filmthick_ness + "','" + //core_filmthick_ness + getCellValue(row5.getCell(5)) + "','" + //lamination_coefficient + getCellValue(row5.getCell(7)) + "','" + //material_code + getCellValue(row5.getCell(10)) + "','" + //reference_cross_sectional_area + getCellValue(row6.getCell(3)) + "','" + //stepping_eccentricity_1 + getCellValue(row6.getCell(4)) + "','" + //stepping_eccentricity_2 + getCellValue(row6.getCell(5)) + "','" + //stepping_eccentricity_3 + getCellValue(row6.getCell(7)) + "','" + //step_mode + getCellValue(row6.getCell(10)) + "','" + //net_core_weight + half_stack + "','" + //half_stack + getCellValue(row35.getCell(9)) + "','" + //cross_sectional_area_face + numtotalclass + "','" + //numtotalclass + factory + "')";//factory - System.out.println("insertSqlT1======="+insertSqlT1); + System.out.println("insertSqlT1=======" + insertSqlT1); SqlUtil.update(insertSqlT1); - //table2 for (int i = 8; i < sheet0.getLastRowNum(); i++) { //判断该行是否为空数据 @@ -258,124 +442,201 @@ public class TXDPFram extends JFrame implements ActionListener { if(cellValue == null || cellValue.isEmpty()) { break; }else { + JSONObject js = new JSONObject(); + String class_number = getCellValue(row.getCell(2)); + String thickness_perstage = getCellValue(row.getCell(3)); + String oil_passage = getCellValue(row.getCell(6)); + String yoke_offset = getCellValue(row.getCell(5)); + String number_pieces = getCellValue(row.getCell(10)); + String jetthickness = getCellValue(row.getCell(11)); + String passage = oil_passage; + if(oil_passage.isEmpty()) { + js.put("OilTunnel", "0"); + }else { + Double oil = Double.parseDouble(passage); + passage = deleteZero(oil * 2); + js.put("OilTunnel", "1"); + } + String jet = jetthickness.isEmpty() ? "0" : "1"; + js.put("bJet", jet); + js.put("ClassNumber", class_number); + js.put("ClassThickness", thickness_perstage); + js.put("OilTunnelThickness", passage); + js.put("OutDistance", yoke_offset); + js.put("JetThickness", jet); + js.put("ActualLayersEach", number_pieces); - String insertSqlT2 = "INSERT INTO CHINT_IRON_CORE_SUM_DETIALS(\"drawingno\",\"producttype\",\"class_number\",\"thickness_perstage\",\"main_column_width\",\"yoke_offset\",\"oil_passage\",\"yoke_width\",\"cumulative_stage_thickness\",\"cross_sectional_area\",\"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))+"')"; - System.out.println("insertSqlT2======="+insertSqlT2); + String insertSqlT2 = "INSERT INTO CHINT_IRON_CORE_SUM_DETIALS(\"drawingno\"," + + "\"producttype\",\"class_number\",\"thickness_perstage\"," + + "\"main_column_width\",\"yoke_offset\",\"oil_passage\",\"yoke_width\"," + + "\"cumulative_stage_thickness\",\"cross_sectional_area\"," + + "\"number_pieces\",\"jetthickness\") VALUES('"+ + drawingno + "','" + + producttype + "','" + + class_number + "','" + + thickness_perstage + "','" + + getCellValue(row.getCell(4)) + "','" + + yoke_offset + "','" + + oil_passage + "','" + + getCellValue(row.getCell(7)) + "','" + + getCellValue(row.getCell(8)) + "','" + + getCellValue(row.getCell(9)) + "','" + + jet + "','" + + number_pieces + "')"; + System.out.println("insertSqlT2=======" + insertSqlT2); SqlUtil.update(insertSqlT2); + //classParameter.add(js); + map.put(class_number, js); } } - } - - - - - - + //json.put("ClassParameter", classParameter); } - //中柱 - 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)); - System.out.println("cellValue2================================================"+cellValue2); - 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); - } - } +// System.out.println("map=======" + map); + //中柱 + if(sheet1 != null) { + getJqd(sheet1, drawingno, producttype, map); + } + + if(sheet2 != null) { + getJqd(sheet2, drawingno, producttype, map); + } + + if(sheet3 != null) { + getJqd(sheet3, drawingno, producttype, map); + } + + //边柱 + 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)); + System.out.println("cellValue2===================="+cellValue2); + if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0") + || cellValue2.equals("宽度-")) { + break; + }else { + String class_number = getCellValue(row.getCell(1)); + if(Integer.parseInt(class_number) > totalClass) + continue; + String b = getCellValue(row.getCell(7)); + 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+"','"+ + class_number+"','"+ + getCellValue(row.getCell(2))+"','"+ + getCellValue(row.getCell(3))+"','"+ + getCellValue(row.getCell(4))+"','"+ + getCellValue(row.getCell(5))+"','"+ + getCellValue(row.getCell(6))+"','"+ + b+"','"+ + getCellValue(row.getCell(8))+"','"+ + getCellValue(row.getCell(9))+"','"+ + "边柱"+"')"; + System.out.println("insertSqlBz======="+insertSqlBz); + SqlUtil.update(insertSqlBz); - } - - } - - - //轭 - 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))+"','"+ - "轭"+"')"; - System.out.println("insertSqlE======="+insertSqlE); - SqlUtil.update(insertSqlE); - } - } + JSONObject js = map.get(class_number); + js.put("WidthLeft", b); +// System.out.println("js=======" + js); + } + } + } + } + + //轭 + 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 class_number = getCellValue(row.getCell(1)); + if(Integer.parseInt(class_number) > totalClass) + continue; + String b = getCellValue(row.getCell(7)); + String d = getCellValue(row.getCell(8)); + String a = getCellValue(row.getCell(9)); + String c = getCellValue(row.getCell(10)); + 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+"','"+ + class_number+"','"+ + getCellValue(row.getCell(2))+"','"+ + getCellValue(row.getCell(3))+"','"+ + getCellValue(row.getCell(4))+"','"+ + getCellValue(row.getCell(5))+"','"+ + getCellValue(row.getCell(6))+"','"+ + b+"','"+ + d+"','"+ + a+"','"+ + c+"','"+ + "轭"+"')"; + System.out.println("insertSqlE======="+insertSqlE); + SqlUtil.update(insertSqlE); + JSONObject js = map.get(class_number); + js.put("LengthDown", c);//d.isEmpty() ? a : d); + js.put("WidthDown", b); + } + } + } + } + uploadFile(name, pathJTextFieldStr); + //TODO 主动推送铁心叠片数据到MOM系统 + if(pref[0].equals("MOM:1")) { + for(String class_number : map.keySet()) { + JSONObject js = map.get(class_number); + classParameter.add(js); + } + json.put("ClassParameter", classParameter); + System.out.println("json==>" + json); + OkHttpClient client = new OkHttpClient(); + MediaType mediaType = MediaType.parse("application/json"); + RequestBody body = RequestBody.create(mediaType, json.toString()); + Builder builder = new Request.Builder() + .url(pref[1]) + .method("POST", body) + .addHeader("Content-Type", "application/json"); + if (pref[1].contains("10.128.11.12")) { + builder.addHeader("Authorization", "Basic MTQyODI0Mjg2NDU2ODMwNzcxNDpkREF3TWpveE1EQXg="); + } else { + builder.addHeader("Authorization", "Basic MTcxNDkwNTkyNTc2MjUzNTQyNjpkREF3TWpveE1EQXg="); + } + Request request = builder.build(); + Response response = client.newCall(request).execute(); + String string = response.body().string(); + System.out.println("response==>" + string); + JSONObject result = JSONObject.fromObject(string); + if(result.get("status").equals("S")) { + MessageBox.post("导入成功!", "提示", MessageBox.INFORMATION); + }else { + MessageBox.post("MOM系统接收数据失败,请联系管理员\n错误码:" + result.get("code") + + "返回信息:" + result.get("msg"), "提示", MessageBox.WARNING); + } + }else { + MessageBox.post("导入成功!", "提示", MessageBox.INFORMATION); } - - } }else if(producttype.equals("五柱")) { Sheet sheet0 = workbook.getSheet("数据输入"); Sheet sheet1 = workbook.getSheet("中柱剪切单1"); @@ -396,22 +657,54 @@ public class TXDPFram extends JFrame implements ActionListener { 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数据,需要将现有的drawingno的数据全部删除,重新导入 + String deleteSql = "delete from CHINT_IRON_CORE_SUM where \"drawingno\"='" + drawingno + "'"; + System.out.println("deleteSql1=======" + deleteSql); + SqlUtil.delete(deleteSql); + deleteSql = "delete from CHINT_IRON_CORE_SUM_DETIALS where \"drawingno\"='" + drawingno + "'"; + System.out.println("deleteSql2=======" + deleteSql); + SqlUtil.delete(deleteSql); + deleteSql = "delete from CHINT_IRON_CORE_DETIALS where \"drawingno\"='" + drawingno + "'"; + System.out.println("deleteSql3=======" + deleteSql); + SqlUtil.delete(deleteSql); + + String numtotalclass = ""; + //根据数据导输入sheet页,找到每级厚有数据的最后一行,获取对应的级号的数字 + for(int i = 8; i < sheet0.getLastRowNum(); i++) { + String h = getCellValue(sheet0.getRow(i).getCell(3)); + if(h.isEmpty()) { + numtotalclass = getCellValue(sheet0.getRow(i - 1).getCell(2)); + totalClass = Integer.parseInt(numtotalclass); + break; + } + } + if(lower_clamp_width.isEmpty()) { + //下夹件宽度:轭片宽最大值-轭片偏距最大值+50 + double epkMax = getMax(sheet0, 6, 8, 8 + totalClass); + double eppjMax = getMax(sheet0, 7, 8, 8 + totalClass); + lower_clamp_width = deleteZero(epkMax - eppjMax + 50); + } + if(yoke_section_distance.isEmpty()) { + //轭断面距离:轭片偏距最大值 + yoke_section_distance = deleteZero(getMax(sheet0, 7, 8, 8 + totalClass)); + } + + 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\"," + + "\"numtotalclass\",\"factory\") VALUES('"+ + lower_clamp_width+"','"+ + yoke_section_distance+"','"+ drawingno+"','"+ producttype+"','"+ getCellValue(row2.getCell(3))+"','"+ @@ -434,13 +727,13 @@ public class TXDPFram extends JFrame implements ActionListener { getCellValue(row39.getCell(9))+"','"+ getCellValue(row39.getCell(10))+"','"+ getCellValue(row39.getCell(11))+"','"+ - getCellValue(row39.getCell(12))+"')"; + getCellValue(row39.getCell(12))+"','"+ + numtotalclass + "','" + //numtotalclass + factory + "')";//factory System.out.println("5insertSqlT1======="+insertSqlT1); SqlUtil.update(insertSqlT1); - - //table2 for (int i = 8; i < sheet0.getLastRowNum(); i++) { //判断该行是否为空数据 @@ -452,8 +745,15 @@ public class TXDPFram extends JFrame implements ActionListener { if(cellValue == null || cellValue.isEmpty()) { break; }else { + String jet = getCellValue(row.getCell(14)).isEmpty() ? "0" : "1"; - 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('"+ + 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\",\"jetthickness\") " + + "VALUES('"+ drawingno+"','"+ producttype+"','"+ getCellValue(row.getCell(2))+"','"+ @@ -467,35 +767,25 @@ public class TXDPFram extends JFrame implements ActionListener { getCellValue(row.getCell(10))+"','"+ getCellValue(row.getCell(11))+"','"+ getCellValue(row.getCell(12))+"','"+ - getCellValue(row.getCell(13))+"')"; + getCellValue(row.getCell(13))+"','"+ + jet+"')"; System.out.println("5insertSqlT2======="+insertSqlT2); SqlUtil.update(insertSqlT2); } } - } - - - - - - - } //中柱 if(sheet1 != null) { - - getJqd(sheet1,drawingno,producttype); + getJqd(sheet1,drawingno,producttype, null); } if(sheet2 != null) { - - getJqd(sheet2,drawingno,producttype); + getJqd(sheet2,drawingno,producttype, null); } if(sheet3 != null) { - - getJqd(sheet3,drawingno,producttype); + getJqd(sheet3,drawingno,producttype, null); } //边柱 @@ -508,11 +798,15 @@ public class TXDPFram extends JFrame implements ActionListener { }else { String cellValue = getCellValue(row.getCell(1)); String cellValue2 = getCellValue(row.getCell(2)); - if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0") || cellValue2.equals("宽度-")) { + 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('"+ + 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))+"','"+ @@ -529,9 +823,7 @@ public class TXDPFram extends JFrame implements ActionListener { SqlUtil.update(insertSqlBz); } } - } - } @@ -546,12 +838,15 @@ public class TXDPFram extends JFrame implements ActionListener { }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("宽度-")) { + 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('"+ + String insertSqlE = "INSERT INTO CHINT_IRON_CORE_DETIALS(\"drawingno\"," + + "\"producttype\",\"class_number\",\"material_code\",\"slice_number\"," + + "\"weight\",\"pkup\",\"pkdn\",\"b\",\"a\",\"c\",\"d\",\"classification\") " + + "VALUES('"+ drawingno+"','"+ producttype+"','"+ getCellValue(row.getCell(1))+"','"+ @@ -569,9 +864,7 @@ public class TXDPFram extends JFrame implements ActionListener { SqlUtil.update(insertSqlE); } } - } - } //轭2 @@ -584,11 +877,14 @@ public class TXDPFram extends JFrame implements ActionListener { }else { String cellValue = getCellValue(row.getCell(1)); String cellValue2 = getCellValue(row.getCell(2)); - if(cellValue == null || cellValue.isEmpty() || cellValue2.equals("宽度-0") || cellValue2.equals("宽度-")) { + 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('"+ + String insertSqlE = "INSERT INTO CHINT_IRON_CORE_DETIALS(\"drawingno\"," + + "\"producttype\",\"class_number\",\"material_code\",\"slice_number\"," + + "\"weight\",\"pkup\",\"pkdn\",\"b\",\"a\",\"c\",\"d\",\"classification\") " + + "VALUES('"+ drawingno+"','"+ producttype+"','"+ getCellValue(row.getCell(1))+"','"+ @@ -606,22 +902,23 @@ public class TXDPFram extends JFrame implements ActionListener { SqlUtil.update(insertSqlE); } } - } - } + + uploadFile(name, pathJTextFieldStr); + MessageBox.post("导入成功!", "提示", MessageBox.INFORMATION); }else { - MessageBox.post("模板sheet页数有问题,判断不出是三柱还是五柱!", "提示", 2); + MessageBox.post("模板sheet页数有问题,判断不出是三柱还是五柱!", "提示", MessageBox.WARNING); return; } - - } catch (IOException e2) { + } catch (Exception e2) { e2.printStackTrace(); + MessageBox.post("错误:" + e2, "提示", MessageBox.ERROR); + } finally { + SqlUtil.free(); } - MessageBox.post("导入成功!", "提示", 2); } - } @@ -642,7 +939,7 @@ public class TXDPFram extends JFrame implements ActionListener { // 查询部分 private JPanel getTopPanel() { - // TODO Auto-generated method stub + // Auto-generated method stub JPanel topPanel = new JPanel(); topPanel.setLayout(new PropertyLayout()); topPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); @@ -652,10 +949,12 @@ public class TXDPFram extends JFrame implements ActionListener { topPanel.add("2.1.left.center", new JLabel("文件存放位置:")); topPanel.add("2.2.left.center", pathJTextField); topPanel.add("2.3.left.center", outputButton); - topPanel.add("3.1.left.center", new JLabel("下夹件宽度:")); - topPanel.add("3.2.left.center",xjjTextField ); - topPanel.add("4.1.left.center", new JLabel("轭断面距离:")); - topPanel.add("4.2.left.center", edmTextField); + topPanel.add("3.1.left.center", new JLabel("工程图号:")); + topPanel.add("3.2.left.center",gctTextField ); + topPanel.add("4.1.left.center", new JLabel("下夹件宽度:")); + topPanel.add("4.2.left.center",xjjTextField ); + topPanel.add("5.1.left.center", new JLabel("轭断面距离:")); + topPanel.add("5.2.left.center", edmTextField); // 注册输出按钮的点击事件监听器 outputButton.addActionListener(new ActionListener() { @Override @@ -677,56 +976,68 @@ public class TXDPFram extends JFrame implements ActionListener { return topPanel; } - public String getCellValue(Cell cell) { + private 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()); + int col = cell.getColumnIndex(); + System.out.println("cellType="+cellType+"===cell.getRowIndex()="+cell.getRowIndex() + +"===cell.getColumnIndex()="+col); 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 ""; } - + return ""; + } if (numericCellValue == Math.floor(numericCellValue) && !Double.isInfinite(numericCellValue)) { long integerPart = (long) numericCellValue; - return integerPart+""; + return integerPart + ""; }else { - return numericCellValue+""; + return numericCellValue + ""; } - - }else if(cellType == 2) { - // 检查单元格是否是公式类型 - // 创建FormulaEvaluator + // 检查单元格是否是公式类型 + // 创建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; - } - } - + // 评估公式 + CellValue valueEval = evaluator.evaluate(cell); +// if(col == 4) +// System.out.println("valueEval.getCellType()======="+valueEval.getCellType() +// +"==="+valueEval.getStringValue()+"==="+valueEval.getNumberValue()); + if(valueEval.getCellType() == 1) { + return valueEval.getStringValue(); + }else if(valueEval.getCellType() == 0) {//num + double numericCellValue = valueEval.getNumberValue();//#.## + if(col == 4 && numericCellValue < 0) + numericCellValue = -numericCellValue; + // 格式化数字 + String formattedNumber = deleteZero(numericCellValue); + if(numericCellValue == 0.0) { + return ""; + } + return formattedNumber; + } + } } return ""; } + /** + * 格式化数字并去掉末尾的.00 + * + * @param num 数字 + * @return 格式化后的字符串 + */ + private String deleteZero(double num) { + String str = df.format(num); + if(str.endsWith(".00")) + str = str.substring(0, str.length() - 3); + return str; + } - public void getJqd(Sheet sheet,String drawingno,String producttype) { + private void getJqd(Sheet sheet, String drawingno, String producttype, HashMap map) { //table2 for (int i = 2; i < sheet.getLastRowNum(); i+=6) { @@ -735,46 +1046,62 @@ public class TXDPFram extends JFrame implements ActionListener { if(row == null) { break; }else { - - String cellValue = getCellValue(row.getCell(1)); String cellValue2 = getCellValue(row.getCell(2)); - System.out.println("cellValue2================================================"+cellValue2); + System.out.println("cellValue2================================================" + cellValue2); 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('"+ - 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))+"','"+ - getCellValue(row.getCell(11))+"','"+ - "中柱"+"')"; - System.out.println("insertSqlZz======="+insertSqlZz); - SqlUtil.update(insertSqlZz); - - List initialElements = Arrays.asList(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))); - ArrayList list = new ArrayList<>(initialElements); - getJqdRow(sheet,list,i+1); - getJqdRow(sheet,list,i+2); - getJqdRow(sheet,list,i+3); - getJqdRow(sheet,list,i+4); - getJqdRow(sheet,list,i+5); - - } + String class_number = getCellValue(row.getCell(1)); + if(Integer.parseInt(class_number) > totalClass) + continue; + String b = getCellValue(row.getCell(7)); + String d = getCellValue(row.getCell(8)); + String a = getCellValue(row.getCell(10)); + + 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('"+ + drawingno + "','" + + producttype + "','" + + class_number + "','" + + getCellValue(row.getCell(2)) + "','" + + getCellValue(row.getCell(3)) + "','" + + getCellValue(row.getCell(4)) + "','" + + getCellValue(row.getCell(5)) + "','" + + getCellValue(row.getCell(6)) + "','" + + b + "','" + + d + "','" + + getCellValue(row.getCell(9)) + "','" + + a + "','" + + getCellValue(row.getCell(11)) + "','" + + "中柱" + "')"; + System.out.println("insertSqlZz=======" + insertSqlZz); + SqlUtil.update(insertSqlZz); + + List initialElements = Arrays.asList(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))); + ArrayList list = new ArrayList<>(initialElements); + getJqdRow(sheet, list, i + 1); + getJqdRow(sheet, list, i + 2); + getJqdRow(sheet, list, i + 3); + getJqdRow(sheet, list, i + 4); + getJqdRow(sheet, list, i + 5); + // + if(map != null) { + JSONObject js = map.get(class_number); + js.put("LengthM", d.isEmpty() ? a : d); + js.put("WidthM", b); + } + } } } } - public void getJqdRow(Sheet sheet,ArrayList list,int i){ + private void getJqdRow(Sheet sheet,ArrayList list,int i){ Row row = sheet.getRow(i); 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('"+ list.get(0)+"','"+ @@ -794,4 +1121,71 @@ public class TXDPFram extends JFrame implements ActionListener { System.out.println("insertSqlZz======="+insertSqlZz); SqlUtil.update(insertSqlZz); } + /** + * 在当前选择的文件夹下创建铁心剪切单对象(首选项:CHINT_IRON_TYPE控制,单值,填写创建的对象类型,例如Document),将excel数据上传到版本下 + * 更新的话需要选到之前创建的item 或者itemrevision 上传,如果最新的版本没有发布的,那就直接在当前版本上更新,如果最新版本发布了,就需要升版,再把excel上传。 + * + * @param name 文件名称,用作对象和数据集名称 + * @param pathJTextFieldStr 文件路径 + */ + private void uploadFile(String name, String pathJTextFieldStr) throws Exception { + TCComponentItemRevision targetRev = null; + TCComponentItem targetItem = null; + if(target instanceof TCComponentItem) { + targetItem = ((TCComponentItem)target); + targetRev = targetItem.getLatestItemRevision(); + }else if(target instanceof TCComponentItemRevision) { + targetRev = (TCComponentItemRevision) target; + targetItem = targetRev.getItem(); + }else { + for(AIFComponentContext c : target.getChildren()) { + TCComponent comp = (TCComponent) c.getComponent(); + if(comp.isTypeOf(type)) { + targetItem = ((TCComponentItem)comp); + targetRev = targetItem.getLatestItemRevision(); + break; + } + } + if(targetRev == null) { + TCComponentItemType itemType = (TCComponentItemType) session.getTypeComponent(type); + targetItem = itemType.create(itemType.getNewID(), null, type, name, "", null); + targetRev = targetItem.getLatestItemRevision(); + target.add("contents", targetItem); + } + } + if(KUtil.isTCM(targetRev)) { + targetRev = targetRev.saveAs(null); + } + for (TCComponent d : targetRev.getRelatedComponents("IMAN_specification")) { + if(d.isTypeOf("MSExcelX")) { + targetRev.remove("IMAN_specification", d); + d.delete(); + break; + } + } + TCComponentDataset dataset = KUtil.createDataset(name, + new String[] { pathJTextFieldStr }, session, "MSExcelX", "excel"); + targetRev.add("IMAN_specification", dataset); + } + /** + * 获取Excel某列最大值 + * + * @param sheet 所在sheet页 + * @param col 列号 + * @param start 起始行 + * @param end 终止行 + * @return 最大值 + */ + private double getMax(Sheet sheet, int col, int start, int end) throws Exception { + double max = 0; + for(int i = start; i < end; i++) { + String str = getCellValue(sheet.getRow(i).getCell(col)); + if(str.isEmpty()) + continue; + double val = Double.parseDouble(str); + if(val > max) + max = val; + } + return max; + } } diff --git a/com.connor.chint.wuhan/src/com/connor/plm/txdp/TXDPHandler.java b/com.connor.chint.wuhan/src/com/connor/plm/txdp/TXDPHandler.java index 49ab851..1b523f1 100644 --- a/com.connor.chint.wuhan/src/com/connor/plm/txdp/TXDPHandler.java +++ b/com.connor.chint.wuhan/src/com/connor/plm/txdp/TXDPHandler.java @@ -3,40 +3,55 @@ import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; +import com.connor.chint.sap2.util.ChintPreferenceUtil; import com.teamcenter.rac.aif.AbstractAIFApplication; import com.teamcenter.rac.aifrcp.AIFUtility; +import com.teamcenter.rac.kernel.TCComponent; +import com.teamcenter.rac.kernel.TCComponentFolder; +import com.teamcenter.rac.kernel.TCComponentItem; +import com.teamcenter.rac.kernel.TCComponentItemRevision; import com.teamcenter.rac.kernel.TCSession; +import com.teamcenter.rac.util.MessageBox; -public class TXDPHandler extends AbstractHandler{ - +public class TXDPHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent arg0) throws ExecutionException { AbstractAIFApplication app = AIFUtility.getCurrentApplication(); TCSession session = (TCSession) app.getSession(); try { - - - + String type = ChintPreferenceUtil.getPreference("CHINT_IRON_TYPE", session); + if(type == null || type.isEmpty()) { + MessageBox.post("首选项CHINT_IRON_TYPE配置不正确", "提示", MessageBox.WARNING); + return null; + } + TCComponent target = (TCComponent) app.getTargetComponent(); + if(target instanceof TCComponentItem && !target.isTypeOf(type)) { + MessageBox.post("请选择文件夹或铁心剪切单进行导入", "提示", MessageBox.WARNING); + return null; + }else if(target instanceof TCComponentItemRevision + && !((TCComponentItemRevision)target).getItem().isTypeOf(type)) { + MessageBox.post("请选择文件夹或铁心剪切单进行导入", "提示", MessageBox.WARNING); + return null; + }else if(!(target instanceof TCComponentFolder)) { + MessageBox.post("请选择文件夹或铁心剪切单进行导入", "提示", MessageBox.WARNING); + return null; + } new Thread() { @Override public void run() { - try { - new TXDPFram(session); + new TXDPFram(session, target, type); } catch (Exception e) { - // TODO Auto-generated catch block + // Auto-generated catch block e.printStackTrace(); } - } }.start(); - } catch (Exception e) { - // TODO: handle exception + // : handle exception e.printStackTrace(); } - return null; } }