package com.sq.customization.dialogs; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Frame; 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.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.filechooser.FileNameExtensionFilter; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; 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.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.context.AnalysisContext; import com.alibaba.excel.event.AnalysisEventListener; import com.sq.customization.bean.CustRuleBean; import com.sq.customization.bean.DesignPartBean; import com.sq.customization.bean.SleeveBean; import com.sq.customization.bean.StandardPartBean; import com.sq.customization.bean.ToolBean; import com.sq.customization.util.ConditionChecker; import com.sq.customization.util.ExcelUtil; import com.sq.customization.util.ProgressCustomDialog; import com.sq.customization.util.RangChecker; import com.sq.customization.util.RangeAdjuster; import com.sq.customization.util.RangeCalculator; import com.sq.customization.util.StringConditionChecker; import com.sq.customization.util.TCUtil; import com.teamcenter.rac.aif.AbstractAIFDialog; import com.teamcenter.rac.aif.kernel.AIFComponentContext; import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; import com.teamcenter.rac.cme.kernel.bvr.TCComponentMfgBvrOperation; import com.teamcenter.rac.cme.kernel.bvr.TCComponentMfgBvrPart; import com.teamcenter.rac.cme.kernel.bvr.TCComponentMfgBvrPlantBOP; import com.teamcenter.rac.cme.kernel.bvr.TCComponentMfgBvrProcessLine; import com.teamcenter.rac.cme.kernel.bvr.TCComponentMfgBvrProcessStation; import com.teamcenter.rac.kernel.TCComponent; import com.teamcenter.rac.kernel.TCComponentBOMLine; import com.teamcenter.rac.kernel.TCComponentBOMWindow; import com.teamcenter.rac.kernel.TCComponentDataset; import com.teamcenter.rac.kernel.TCComponentItem; import com.teamcenter.rac.kernel.TCException; import com.teamcenter.rac.kernel.TCPreferenceService; import com.teamcenter.rac.kernel.TCSession; import com.teamcenter.rac.stylesheet.PropertyTextField; import com.teamcenter.rac.util.ButtonLayout; import com.teamcenter.rac.util.MessageBox; import com.teamcenter.rac.util.PropertyLayout; import com.teamcenter.rac.util.Registry; import com.teamcenter.schemas.soa._2006_03.exceptions.ServiceException; public class AutoTransToolDialog extends AbstractAIFDialog { private PropertyTextField text; private PropertyTextField dirtext; private PropertyTextField idtext; private PropertyTextField svppstext; private PropertyTextField FCCtext; private PropertyTextField FCCDEStext; private PropertyTextField dongtaitext; private PropertyTextField KCDStext; private JButton ok; private JButton cancel; private JButton directory; private JButton directory2; // private Registry registry = Registry.getRegistry(AutoTransToolDialog.class); private TCSession session; private InterfaceAIFComponent target; private Map no_load = new HashMap<>(); private Map op_nodesignmap = new HashMap<>(); private Map DesignPartBeanMap = new HashMap<>(); private List processrules = new ArrayList<>(); private List autotoolrules = new ArrayList<>(); private List Tightenrules = new ArrayList<>(); private List KCDSrules = new ArrayList<>(); private List TightenMethodrules = new ArrayList<>(); private List Torquerules = new ArrayList<>(); private Map> eleTool = new HashMap<>();//excel电动工具 private Map> batteryTool = new HashMap<>();//excel电池工具 private Map> pneumaticTool = new HashMap<>();//excel气动工具 private Map> manualTool = new HashMap<>();//excel手动工具 private Map StandardPartMap = new HashMap<>();//excel标准件 private Map> SleeveMap = new HashMap<>();//excel套筒 // private int times = 0; private int row_num = 1; private TCComponentBOMLine workline; public AutoTransToolDialog(Frame fm,InterfaceAIFComponent target,TCSession session,TCComponentBOMLine workline) { super(fm); this.target = target; this.session = session; this.workline = workline; op_nodesignmap.clear(); no_load.clear(); DesignPartBeanMap.clear(); processrules.clear(); autotoolrules.clear(); Tightenrules.clear(); TightenMethodrules.clear(); KCDSrules.clear(); Torquerules.clear(); eleTool.clear(); batteryTool.clear(); pneumaticTool.clear(); manualTool.clear(); StandardPartMap.clear(); SleeveMap.clear(); // times = 0; init(); } private void init() { this.setTitle("自动匹配替换工具"); this.setPreferredSize(new Dimension(500,400)); this.centerToScreen(); this.setLayout(new BorderLayout()); JPanel northPane = new JPanel(new PropertyLayout(10,10,5,5,10,10)); northPane.add("1.1.left",new JLabel("零件号:")); idtext = new PropertyTextField(); idtext.setColumns(30); idtext.setRequired(true); northPane.add("1.2",idtext); northPane.add("2.1.left",new JLabel("短SVPPS:")); svppstext = new PropertyTextField(); svppstext.setColumns(30); svppstext.setRequired(true); northPane.add("2.2",svppstext); northPane.add("3.1.left",new JLabel("FCC:")); FCCtext = new PropertyTextField(); FCCtext.setColumns(30); FCCtext.setRequired(true); northPane.add("3.2",FCCtext); northPane.add("4.1.left",new JLabel("FFC中文描述:")); FCCDEStext = new PropertyTextField(); FCCDEStext.setColumns(30); FCCDEStext.setRequired(true); northPane.add("4.2",FCCDEStext); northPane.add("5.1.left",new JLabel("动态扭矩:")); dongtaitext = new PropertyTextField(); dongtaitext.setColumns(30); dongtaitext.setRequired(true); northPane.add("5.2",dongtaitext); northPane.add("6.1.left",new JLabel("KCDS:")); KCDStext = new PropertyTextField(); KCDStext.setColumns(30); KCDStext.setRequired(true); northPane.add("6.2",KCDStext); northPane.add("7.1.left",new JLabel("数据文件:")); text = new PropertyTextField(); text.setColumns(30); text.setRequired(true); text.setEnabled(false); northPane.add("7.2",text); directory = new JButton("..."); northPane.add("7.3",directory); northPane.add("8.1.left",new JLabel("导出路径:")); dirtext = new PropertyTextField(); dirtext.setColumns(30); dirtext.setRequired(true); dirtext.setEnabled(false); northPane.add("8.2",dirtext); directory2 = new JButton("..."); northPane.add("8.3",directory2); JPanel southpanel = new JPanel(new ButtonLayout()); ok = new JButton("确定"); cancel = new JButton("取消"); southpanel.add(ok); southpanel.add(cancel); this.add(BorderLayout.CENTER,northPane); this.add(BorderLayout.SOUTH,southpanel); this.setVisible(true); cancel.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { AutoTransToolDialog.this.dispose(); }}); directory2.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { JFileChooser filechooser = new JFileChooser(); filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); // FileNameExtensionFilter filter = new FileNameExtensionFilter( // "所有Excel文件(*.xlsx)", new String[] { "xlsx" }); // filechooser.setFileFilter(filter); int r = filechooser.showDialog(null, "选择"); if (r == 0) { dirtext.setText(filechooser.getSelectedFile().getAbsolutePath()); } else if (r == 1) { dirtext.setText(""); } }}); directory.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { JFileChooser filechooser = new JFileChooser(); filechooser.setFileSelectionMode(2); FileNameExtensionFilter filter = new FileNameExtensionFilter( "所有Excel文件(*.xlsx)", new String[] { "xlsx" }); filechooser.setFileFilter(filter); int r = filechooser.showDialog(null, "选择"); if (r == 0) { text.setText(filechooser.getSelectedFile().getAbsolutePath()); } else if (r == 1) { text.setText(""); } }}); ok.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { String path = text.getText(); String path2 = dirtext.getText(); if( path != null && path.length() > 0 && path2 != null && path2.length() > 0) { String idcol = idtext.getText(); String svppscol = svppstext.getText(); String fcccol = FCCtext.getText(); String fccdescol = FCCDEStext.getText(); String dongtaicol = dongtaitext.getText(); String kcdscol = KCDStext.getText(); final File excel = new File(path); if(!excel.exists()) { MessageBox.post(AutoTransToolDialog.this,"文件路径不存在", "Message", MessageBox.INFORMATION); return; } String[] rule_pref = session.getPreferenceService().getStringArray(TCPreferenceService.TC_preference_site, "cust_rule_excel"); if(rule_pref == null || rule_pref.length == 0) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_rule_excel", "Message", MessageBox.INFORMATION); return; } //电动工具 String[] cust_electric_excel = session.getPreferenceService().getStringArray(TCPreferenceService.TC_preference_site, "cust_electric_excel"); if(cust_electric_excel == null || cust_electric_excel.length == 0) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_electric_excel", "Message", MessageBox.INFORMATION); return; } //电池工具 String[] cust_battery_excel = session.getPreferenceService().getStringArray(TCPreferenceService.TC_preference_site, "cust_battery_excel"); if(cust_battery_excel == null || cust_battery_excel.length == 0) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_battery_excel", "Message", MessageBox.INFORMATION); return; } //气动工具 String[] cust_pneumatic_excel = session.getPreferenceService().getStringArray(TCPreferenceService.TC_preference_site, "cust_pneumatic_excel"); if(cust_pneumatic_excel == null || cust_pneumatic_excel.length == 0) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_pneumatic_excel", "Message", MessageBox.INFORMATION); return; } //手动 String[] cust_manual_excel = session.getPreferenceService().getStringArray(TCPreferenceService.TC_preference_site, "cust_manual_excel"); if(cust_manual_excel == null || cust_manual_excel.length == 0) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_manual_excel", "Message", MessageBox.INFORMATION); return; } //标准间 String[] cust_standardpart_excel = session.getPreferenceService().getStringArray(TCPreferenceService.TC_preference_site, "cust_standardpart_excel"); if(cust_standardpart_excel == null || cust_standardpart_excel.length == 0) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_standardpart_excel", "Message", MessageBox.INFORMATION); return; } //套筒 String[] cust_sleeve_excel = session.getPreferenceService().getStringArray(TCPreferenceService.TC_preference_site, "cust_sleeve_excel"); if(cust_sleeve_excel == null || cust_sleeve_excel.length == 0) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_sleeve_excel", "Message", MessageBox.INFORMATION); return; } try { TCComponentDataset dataset = (TCComponentDataset) session.stringToComponent(rule_pref[0]); File[] files = dataset.getFiles("excel"); if(files == null || files.length == 0 || !files[0].exists()) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_rule_excel对应的规则数据集中的文件", "Message", MessageBox.INFORMATION); return; } TCComponentDataset cust_electric_exceldataset = (TCComponentDataset) session.stringToComponent(cust_electric_excel[0]); File[] cust_electric_excelfiles = cust_electric_exceldataset.getFiles("excel"); if(cust_electric_excelfiles == null || cust_electric_excelfiles.length == 0 || !cust_electric_excelfiles[0].exists()) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_electric_excel对应的数据集中的文件", "Message", MessageBox.INFORMATION); return; } TCComponentDataset cust_battery_exceldataset = (TCComponentDataset) session.stringToComponent(cust_battery_excel[0]); File[] cust_battery_exceldatasetfiles = cust_battery_exceldataset.getFiles("excel"); if(cust_battery_exceldatasetfiles == null || cust_battery_exceldatasetfiles.length == 0 || !cust_battery_exceldatasetfiles[0].exists()) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_battery_excel对应的数据集中的文件", "Message", MessageBox.INFORMATION); return; } TCComponentDataset cust_pneumatic_exceldataset = (TCComponentDataset) session.stringToComponent(cust_pneumatic_excel[0]); File[] cust_pneumatic_excelfiles = cust_pneumatic_exceldataset.getFiles("excel"); if(cust_pneumatic_excelfiles == null || cust_pneumatic_excelfiles.length == 0 || !cust_pneumatic_excelfiles[0].exists()) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_pneumatic_excel对应的数据集中的文件", "Message", MessageBox.INFORMATION); return; } TCComponentDataset cust_manual_exceldataset = (TCComponentDataset) session.stringToComponent(cust_manual_excel[0]); File[] cust_manual_excelfiles = cust_manual_exceldataset.getFiles("excel"); if(cust_manual_excelfiles == null || cust_manual_excelfiles.length == 0 || !cust_manual_excelfiles[0].exists()) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_manual_excel对应的数据集中的文件", "Message", MessageBox.INFORMATION); return; } TCComponentDataset cust_standardpart_exceldataset = (TCComponentDataset) session.stringToComponent(cust_standardpart_excel[0]); File[] cust_standardpart_excelfiles = cust_standardpart_exceldataset.getFiles("excel"); if(cust_standardpart_excelfiles == null || cust_standardpart_excelfiles.length == 0 || !cust_standardpart_excelfiles[0].exists()) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_standardpart_excel对应的数据集中的文件", "Message", MessageBox.INFORMATION); return; } TCComponentDataset cust_sleeve_exceldataset = (TCComponentDataset) session.stringToComponent(cust_sleeve_excel[0]); File[] cust_sleeve_excelfiles = cust_sleeve_exceldataset.getFiles("excel"); if(cust_sleeve_excelfiles == null || cust_sleeve_excelfiles.length == 0 || !cust_sleeve_excelfiles[0].exists()) { MessageBox.post(AutoTransToolDialog.this,"请检查自定义首选项cust_sleeve_excel对应的数据集中的文件", "Message", MessageBox.INFORMATION); return; } final File excelfile = files[0]; final File electricfile = cust_electric_excelfiles[0]; final File batteryfile = cust_battery_exceldatasetfiles[0]; final File pneumaticfile = cust_pneumatic_excelfiles[0]; final File manualfile = cust_manual_excelfiles[0]; final File standardpartfile = cust_standardpart_excelfiles[0]; final File sleevefile = cust_sleeve_excelfiles[0]; if(isValidExcelColumn(idcol) && isValidExcelColumn(svppscol) && isValidExcelColumn(fcccol) && isValidExcelColumn(fccdescol) && isValidExcelColumn(dongtaicol) && isValidExcelColumn(kcdscol)) { op_nodesignmap.clear(); no_load.clear(); DesignPartBeanMap.clear(); processrules.clear(); autotoolrules.clear(); Tightenrules.clear(); TightenMethodrules.clear(); KCDSrules.clear(); Torquerules.clear(); eleTool.clear(); batteryTool.clear(); pneumaticTool.clear(); manualTool.clear(); StandardPartMap.clear(); SleeveMap.clear(); final int idcol2 = columnToNumber(idcol.toUpperCase()); final int svppscol2 = columnToNumber(svppscol.toUpperCase()); final int fcccol2 = columnToNumber(fcccol.toUpperCase()); final int fccdescol2 = columnToNumber(fccdescol.toUpperCase()); final int dongtaicol2 = columnToNumber(dongtaicol.toUpperCase()); final int kcdscol2 = columnToNumber(kcdscol.toUpperCase()); Thread thread = new Thread(){ public void run(){ ProgressCustomDialog.lbStatus.setText("正在创建 ...."); Workbook workbook = null; FileOutputStream outputStream = null; try { SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HHmmssSSS"); String time = fm.format(new Date()); outputStream = new FileOutputStream(path2+"/匹配工具表导出"+time+".xlsx"); workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet("Data"); // 创建表头 Row headerRow = sheet.createRow(0); headerRow.createCell(0).setCellValue("工序信息"); headerRow.createCell(1).setCellValue("紧固件号"); headerRow.createCell(2).setCellValue("SVPPS"); headerRow.createCell(3).setCellValue("FCC"); headerRow.createCell(4).setCellValue("动态扭矩"); headerRow.createCell(5).setCellValue("KCDS"); // headerRow.createCell(6).setCellValue("头部形式"); headerRow.createCell(6).setCellValue("头部尺寸"); headerRow.createCell(7).setCellValue("工具组合"); headerRow.createCell(8).setCellValue("工具"); headerRow.createCell(9).setCellValue("工具套筒"); //读取自定义的表 readRuleExcel(excelfile); readElectricfile(electricfile,1); readbatteryfile(batteryfile,1); readpneumaticfile(pneumaticfile,1); readmanualfile(manualfile,1); readstdPartfile(standardpartfile,1); readsleevefile(sleevefile,1); row_num = 1; //读取EXCEL readExcel(excel,2,idcol2,svppscol2,fcccol2,fccdescol2,dongtaicol2,kcdscol2); //先处理选中对象层级有design的工序,获取没有design的工序 opBOMLineData(target,sheet); if(op_nodesignmap.size() > 0) { TCComponentBOMLine parent = null; if(target instanceof TCComponentMfgBvrProcessStation) { TCComponentMfgBvrProcessStation station = (TCComponentMfgBvrProcessStation) target; String id = station.getProperty("bl_item_item_id"); no_load.put(id, id); parent = station.parent(); } else if(target instanceof TCComponentMfgBvrPlantBOP) { TCComponentMfgBvrPlantBOP plant = (TCComponentMfgBvrPlantBOP) target; String id = plant.getProperty("bl_item_item_id"); no_load.put(id, id); parent = plant.parent(); } else if(target instanceof TCComponentMfgBvrProcessLine) { TCComponentMfgBvrProcessLine line = (TCComponentMfgBvrProcessLine) target; String id = line.getProperty("bl_item_item_id"); no_load.put(id, id); parent = line.parent(); } if(parent != null) { System.out.println(parent.getClass()+parent.getProperty("bl_indented_title")); getparent(parent,sheet,parent); } if(op_nodesignmap.size() > 0) { System.out.println("整个结构没有匹配的紧固件"); for(String key:op_nodesignmap.keySet()) { TCComponentMfgBvrOperation op = op_nodesignmap.get(key); String bl_indented_title = op.getProperty("bl_indented_title"); Row row = sheet.createRow(row_num); row_num ++; Cell optitle_cell = row.createCell(0); optitle_cell.setCellValue(bl_indented_title); Cell des_cell = row.createCell(1); des_cell.setCellValue("无紧固件"); } } } } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } finally { try { workbook.write(outputStream); outputStream.flush(); if(outputStream != null)outputStream.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }; ProgressCustomDialog.show(thread, "执行中", null, null, null); AutoTransToolDialog.this.dispose(); } else { MessageBox.post(AutoTransToolDialog.this,"请填写正确的列,比如A,B,C..", "Message", MessageBox.INFORMATION); } } catch (TCException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } //session.queueOperation(operation); } else { MessageBox.post(AutoTransToolDialog.this,"请选择文件", "Message", MessageBox.INFORMATION); } }}); } public static int columnToNumber(String column) { int result = 0; for (int i = 0; i < column.length(); i++) { char c = column.charAt(i); result = result * 26 + (c - 'A' + 1); // 将字母转换为数字 } return result; } // 判断列名是否符合A-Z, AA, AB等格式,不区分大小写 public static boolean isValidExcelColumn(String column) { // 将输入字符串转为大写字母并匹配正则表达式 return column != null && column.toUpperCase().matches("[A-Z]+"); } //先处理选中对象层级有design的工序 private void opBOMLineData(InterfaceAIFComponent parent,Sheet sheet) throws Exception { AIFComponentContext[] children = parent.getChildren(); for(AIFComponentContext child:children) { InterfaceAIFComponent childcom = child.getComponent(); if(childcom instanceof TCComponentMfgBvrOperation) { TCComponentMfgBvrOperation op = (TCComponentMfgBvrOperation) childcom; String bl_rev_object_name = op.getProperty("bl_rev_object_name"); //先查询是否有资源,没资源的跳过 boolean iscontinue = true; AIFComponentContext[] design_children1 = op.getChildren(); for(AIFComponentContext designchild:design_children1) { InterfaceAIFComponent designchildcom = designchild.getComponent(); String bl_occ_type = designchildcom.getProperty("bl_occ_type"); if("MEResource".equalsIgnoreCase(bl_occ_type)) { iscontinue = false; break; } } if(!iscontinue) { continue; } if(bl_rev_object_name.contains("预紧") || bl_rev_object_name.contains("终紧") || bl_rev_object_name.contains("紧固")|| bl_rev_object_name.contains("拧紧") || bl_rev_object_name.contains("接地")|| bl_rev_object_name.contains("搭铁")) { String bl_indented_title = op.getProperty("bl_indented_title"); AIFComponentContext[] design_children = op.getChildren(); boolean hasdesign = false; Map idmap = new HashMap<>(); Map pipei_resource_map = new HashMap<>(); // Map> resource_map = new HashMap<>();//工序下挂接的资源 for(AIFComponentContext designchild:design_children) { InterfaceAIFComponent designchildcom = designchild.getComponent(); String bl_item_object_type = designchildcom.getProperty("bl_item_object_type"); String bl_occ_type = designchildcom.getProperty("bl_occ_type"); // if("MEResource".equalsIgnoreCase(bl_occ_type)) { // String Resource_name = designchildcom.getProperty("bl_rev_object_name"); // resource_map.computeIfAbsent(Resource_name, key2 -> new ArrayList<>()).add(designchildcom); // } if("Design Part".equalsIgnoreCase(bl_item_object_type)) { hasdesign = true; //获取符合的数据 Map> Tool = new HashMap<>(); Map> resourceTool = new HashMap<>(); //获取design String designid = designchildcom.getProperty("bl_item_item_id"); if(idmap.containsKey(designid)) { continue; } else { idmap.put(designid, designid); } String newname = bl_rev_object_name.replaceAll("预紧", "") .replaceAll("终紧", "") .replaceAll("紧固", "") .replaceAll("拧紧", ""); Row row = sheet.createRow(row_num); row_num ++; Cell optitle_cell = row.createCell(0); optitle_cell.setCellValue(bl_indented_title); Cell designid_cell = row.createCell(1); designid_cell.setCellValue(designid); String key = designid; System.out.println("看design是否匹配:"+key); if(DesignPartBeanMap.containsKey(key)) { System.out.println("找到匹配的,开始匹配规则"); DesignPartBean bean = DesignPartBeanMap.get(key); String fccdes = bean.getFCCDES(); if(!newname.contains(fccdes)) { continue; } String niuju = ""; String dongtai = bean.getDongtai(); if(dongtai.length() > 0) { if(dongtai.contains("N.M")) { String[] split = dongtai.split("N.M", -1); if(split!= null && split.length == 2) { niuju = split[0]; } } } Cell svpps_cell = row.createCell(2); svpps_cell.setCellValue(bean.getSVPPS()); Cell fcc_cell = row.createCell(3); fcc_cell.setCellValue(bean.getFCC()); Cell dongtai_cell = row.createCell(4); dongtai_cell.setCellValue(bean.getDongtai()); Cell kcds_cell = row.createCell(5); kcds_cell.setCellValue(bean.getKCDS()); //优先执行特殊工艺规则和电动工具新型号规则,若无匹配全量跑后续规则 boolean processrule = false; for(int i = 0; i< processrules.size(); i++) { CustRuleBean rulebean = processrules.get(i); String rule_svpps = rulebean.getSVPPS(); boolean is_ok = true; if(rule_svpps != null && rule_svpps.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_svpps, bean.getSVPPS()); if(!result) is_ok = false; } String rule_fcc = rulebean.getFCC(); if(rule_fcc != null && rule_fcc.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_fcc, bean.getFCC()); if(!result) is_ok = false; } String rule_dongtai = rulebean.getDongtai(); if(rule_dongtai != null && rule_dongtai.length() > 0) { if(dongtai.length() > 0) { if(dongtai.contains("N.M")) { String[] split = dongtai.split("N.M", -1); if(split!= null && split.length == 2) { niuju = split[0]; boolean result = ConditionChecker.checkCondition(rule_dongtai, split[1], split[0]); if(!result) is_ok = false; } } else { boolean result = ConditionChecker.checkCondition(rule_dongtai, dongtai,""); if(!result) is_ok = false; } } else { is_ok = false; } } String rule_FCCDESC = rulebean.getFCCDES(); if(rule_FCCDESC != null && rule_FCCDESC.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_FCCDESC, bl_rev_object_name); if(!result) is_ok = false; } if(is_ok) { //获取资源名称 processrule = true; String resourceName = rulebean.getResourceName(); // System.out.println("根据资源名称去电池工具里面找:"+resourceName); if(batteryTool.containsKey(resourceName)) { List tools = batteryTool.get(resourceName); for(ToolBean tool:tools) { String range = tool.getRange(); String resourceType = tool.getResourceType(); String outSize = tool.getOutSize(); boolean isWithinRange = false; if(range!= null && range.length() > 0 && niuju != null && niuju.length() > 0) { range = range.replace("|", "-"); String newrange = RangeCalculator.adjustRange(range); String newniuju = niuju; if(bl_rev_object_name.contains("预紧")) { newniuju = RangeAdjuster.adjustRange(niuju); } System.out.print("判断BOM表中扭矩是否符合:"+niuju+"新扭矩:"+newniuju+"资源名称:"+resourceName+" 扭矩范围:"+range+" 新扭矩范围:"+newrange+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" "); isWithinRange = RangChecker.isWithinRange(newniuju, newrange); if(isWithinRange) { System.out.println("新扭矩和新扭矩范围匹配"); } else { System.out.println("新扭矩和新扭矩范围不匹配"); } } else if((range == null || range.length() == 0) && (niuju == null || niuju.length() == 0)) { System.out.print("判断BOM表中扭矩是否符合:"+niuju+"资源名称:"+resourceName+" 扭矩范围:"+range+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" 匹配扭矩"); isWithinRange = true; } if(isWithinRange) { System.out.println("后续和套筒匹配"); Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(tool); } } } } } boolean autotoolrule = false; if(!processrule) { //执行电动工具规则 for(int i = 0; i< autotoolrules.size(); i++) { CustRuleBean rulebean = autotoolrules.get(i); String rule_svpps = rulebean.getSVPPS(); boolean is_ok = true; if(rule_svpps != null && rule_svpps.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_svpps, bean.getSVPPS()); if(!result) is_ok = false; } String rule_fcc = rulebean.getFCC(); if(rule_fcc != null && rule_fcc.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_fcc, bean.getFCC()); if(!result) is_ok = false; } String rule_FCCDESC = rulebean.getFCCDES(); if(rule_FCCDESC != null && rule_FCCDESC.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_FCCDESC, bl_rev_object_name); if(!result) is_ok = false; } if(is_ok) { //获取资源类型 autotoolrule = true; String resourceType = rulebean.getResourceType(); System.out.println("匹配上电动工具,资源型号:"+resourceType); if(eleTool.containsKey(resourceType)) { List tools = eleTool.get(resourceType); for(ToolBean tool:tools) { String range = tool.getRange(); String outSize = tool.getOutSize(); boolean isWithinRange = false; if(range!= null && range.length() > 0 && niuju != null && niuju.length() > 0) { range = range.replace("|", "-"); String newrange = RangeCalculator.adjustRange(range); String newniuju = niuju; if(bl_rev_object_name.contains("预紧")) { newniuju = RangeAdjuster.adjustRange(niuju); } System.out.print("判断BOM表中扭矩是否符合:"+niuju+"新扭矩:"+newniuju+" 扭矩范围:"+range+" 新扭矩范围:"+newrange+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" "); isWithinRange = RangChecker.isWithinRange(newniuju, newrange); if(isWithinRange) { System.out.println("新扭矩和新扭矩范围匹配"); } else { System.out.println("新扭矩和新扭矩范围不匹配"); } } else if((range == null || range.length() == 0) && (niuju == null || niuju.length() == 0)) { System.out.print("判断BOM表中扭矩是否符合:"+niuju+" 扭矩范围:"+range+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" 匹配扭矩"); isWithinRange = true; } if(isWithinRange) { System.out.println("后续和套筒匹配"); Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(tool); } } } } } } if(!autotoolrule) { Map resourcename = new HashMap<>(); //拧紧性质规则 //看读取哪个表 Map Tightenexcelname = new HashMap<>(); for(int i = 0; i< Tightenrules.size(); i++) { CustRuleBean rulebean = Tightenrules.get(i); String rule_svpps = rulebean.getSVPPS(); boolean is_ok = true; if(rule_svpps != null && rule_svpps.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_svpps, bean.getSVPPS()); if(!result) is_ok = false; } String rule_FCCDESC = rulebean.getFCCDES(); if(rule_FCCDESC != null && rule_FCCDESC.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_FCCDESC, bl_rev_object_name); if(!result) is_ok = false; } String rule_dongtai = rulebean.getDongtai(); if(rule_dongtai != null && rule_dongtai.length() > 0) { if(dongtai.length() > 0) { if(dongtai.contains("N.M")) { String[] split = dongtai.split("N.M", -1); if(split!= null && split.length == 2) { boolean result = ConditionChecker.checkCondition(rule_dongtai, split[1], split[0]); if(!result) is_ok = false; } } else { boolean result = ConditionChecker.checkCondition(rule_dongtai, dongtai,""); if(!result) is_ok = false; } } else { is_ok = false; } } if(is_ok) { //获取资源名称 String resourceType = rulebean.getResourceType(); if(resourceType != null && resourceType.length() > 0) { String[] res = resourceType.split("\\|", -1); for(String re:res) { if(Tightenexcelname.containsKey(re)) { // } else { Tightenexcelname.put(re, 1); } } } System.out.println("拧紧性质规则匹配"+resourceType); break; } } //KCDS //看读取哪个表 Map KCDSexcelname = new HashMap<>(); for(int i = 0; i< KCDSrules.size(); i++) { CustRuleBean rulebean = KCDSrules.get(i); String rule_svpps = rulebean.getSVPPS(); boolean is_ok = true; if(rule_svpps != null && rule_svpps.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_svpps, bean.getSVPPS()); if(!result) is_ok = false; } String rule_FCCDESC = rulebean.getFCCDES(); if(rule_FCCDESC != null && rule_FCCDESC.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_FCCDESC, bl_rev_object_name); if(!result) is_ok = false; } String rule_KCDS = rulebean.getKCDS(); if(rule_KCDS != null && rule_KCDS.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_KCDS, bean.getKCDS()); if(!result) is_ok = false; } if(is_ok) { //获取资源类型 String resourceType = rulebean.getResourceType(); if(resourceType != null && resourceType.length() > 0) { String[] res = resourceType.split("\\|", -1); for(String re:res) { if(KCDSexcelname.containsKey(re)) { } else { KCDSexcelname.put(re, 1); } } } System.out.println("KCDS匹配"+resourceType); break; } } //拧紧方式 Map TightenMethodexcelname = new HashMap<>(); for(int i = 0; i< TightenMethodrules.size(); i++) { CustRuleBean rulebean = TightenMethodrules.get(i); String rule_svpps = rulebean.getSVPPS(); boolean is_ok = true; if(rule_svpps != null && rule_svpps.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_svpps, bean.getSVPPS()); if(!result) is_ok = false; } String rule_FCCDESC = rulebean.getFCCDES(); if(rule_FCCDESC != null && rule_FCCDESC.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_FCCDESC, bl_rev_object_name); if(!result) is_ok = false; } String rule_dongtai = rulebean.getDongtai(); if(rule_dongtai != null && rule_dongtai.length() > 0) { if(dongtai.length() > 0) { if(dongtai.contains("N.M")) { String[] split = dongtai.split("N.M", -1); if(split!= null && split.length == 2) { boolean result = ConditionChecker.checkCondition(rule_dongtai, split[1], split[0]); if(!result) is_ok = false; } } else { boolean result = ConditionChecker.checkCondition(rule_dongtai, dongtai,""); if(!result) is_ok = false; } } else { is_ok = false; } } if(is_ok) { //获取资源类型 String resourceType = rulebean.getResourceType(); if(resourceType != null && resourceType.length() > 0) { String[] res = resourceType.split("\\|", -1); for(String re:res) { if(TightenMethodexcelname.containsKey(re)) { } else { TightenMethodexcelname.put(re, 1); } } } System.out.println("拧紧方式匹配"+resourceType); break; } } //扭矩值 Map Torqueexcelname = new HashMap<>(); for(int i = 0; i< Torquerules.size(); i++) { CustRuleBean rulebean = Torquerules.get(i); String rule_svpps = rulebean.getSVPPS(); boolean is_ok = true; if(rule_svpps != null && rule_svpps.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_svpps, bean.getSVPPS()); if(!result) is_ok = false; } String rule_FCCDESC = rulebean.getFCCDES(); if(rule_FCCDESC != null && rule_FCCDESC.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_FCCDESC, bl_rev_object_name); if(!result) is_ok = false; } String rule_dongtai = rulebean.getDongtai(); if(rule_dongtai != null && rule_dongtai.length() > 0) { if(dongtai.length() > 0) { if(dongtai.contains("N.M")) { String[] split = dongtai.split("N.M", -1); if(split!= null && split.length == 2) { boolean result = ConditionChecker.checkCondition(rule_dongtai, split[1], split[0]); if(!result) is_ok = false; } } else { boolean result = ConditionChecker.checkCondition(rule_dongtai, dongtai,""); if(!result) is_ok = false; } } else { is_ok = false; } } if(is_ok) { //获取资源类型 String resourceType = rulebean.getResourceType(); String resourceName = rulebean.getResourceName(); if(resourceType != null && resourceType.length() > 0) { String[] res = resourceType.split("\\|", -1); for(String re:res) { if(Torqueexcelname.containsKey(re)) { } else { Torqueexcelname.put(re, 1); } } } if(resourceName != null && resourceName.length() > 0) { String[] res = resourceName.split("\\|", -1); for(String re:res) { if(resourcename.containsKey(re)) { } else { resourcename.put(re, re); } } } System.out.println("扭矩值匹配"+resourceType); break; } } // 将所有 Map 放入一个列表 // List> maps = Arrays.asList(Tightenexcelname, KCDSexcelname, TightenMethodexcelname, Torqueexcelname); Set commonKeys = new HashSet<>(Tightenexcelname.keySet()); // 保留 map2、map3、map4 中也有的键 commonKeys.retainAll(KCDSexcelname.keySet()); commonKeys.retainAll(TightenMethodexcelname.keySet()); commonKeys.retainAll(Torqueexcelname.keySet()); System.out.println("四个 Map 都有的 key: " + commonKeys); //读取工具excel数据 for(String name:commonKeys) { if("电动工具".equals(name)){ for(String resourceType:eleTool.keySet()) { List toolbeans = eleTool.get(resourceType); for(ToolBean toolbean:toolbeans) { String range = toolbean.getRange(); String outSize = toolbean.getOutSize(); String resourceName = toolbean.getResourceName(); boolean isWithinRange = false; if(range!= null && range.length() > 0 && niuju != null && niuju.length() > 0) { range = range.replace("|", "-"); String newrange = RangeCalculator.adjustRange(range); String newniuju = niuju; if(bl_rev_object_name.contains("预紧")) { newniuju = RangeAdjuster.adjustRange(niuju); } System.out.print("判断BOM表中扭矩是否符合:"+niuju+"新扭矩:"+newniuju+" 扭矩范围:"+range+" 新扭矩范围:"+newrange+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" "); isWithinRange = RangChecker.isWithinRange(newniuju, newrange); if(isWithinRange) { System.out.println("新扭矩和新扭矩范围匹配"); } else { System.out.println("新扭矩和新扭矩范围不匹配"); } } else if((range == null || range.length() == 0) && (niuju == null || niuju.length() == 0)) { System.out.print("判断BOM表中扭矩是否符合:"+niuju+" 扭矩范围:"+range+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" 匹配扭矩"); isWithinRange = true; } if(isWithinRange) { System.out.println("后续和套筒匹配"); Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); if(resourcename.size() > 0 && resourcename.containsKey(resourceName)) { resourceTool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); } } } } } else if("手动工具".equals(name)){ for(String resourceType:eleTool.keySet()) { List toolbeans = eleTool.get(resourceType); for(ToolBean toolbean:toolbeans) { String resourceName = toolbean.getResourceName(); Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); if((resourcename.size() > 0 && resourcename.containsKey(resourceName))) { resourceTool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); } } // Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).addAll(toolbeans); } } else if("气动工具".equals(name)){ for(String resourceType:pneumaticTool.keySet()) { List toolbeans = pneumaticTool.get(resourceType); for(ToolBean toolbean:toolbeans) { String range = toolbean.getRange(); String outSize = toolbean.getOutSize(); String resourceName = toolbean.getResourceName(); boolean isWithinRange = false; if(range!= null && range.length() > 0 && niuju != null && niuju.length() > 0) { range = range.replace("|", "-"); String newrange = RangeCalculator.adjustRange(range); String newniuju = niuju; if(bl_rev_object_name.contains("预紧")) { newniuju = RangeAdjuster.adjustRange(niuju); } System.out.print("判断BOM表中扭矩是否符合:"+niuju+"新扭矩:"+newniuju+" 扭矩范围:"+range+" 新扭矩范围:"+newrange+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" "); isWithinRange = RangChecker.isWithinRange(newniuju, newrange); if(isWithinRange) { System.out.println("新扭矩和新扭矩范围匹配"); } else { System.out.println("新扭矩和新扭矩范围不匹配"); } } else if((range == null || range.length() == 0) && (niuju == null || niuju.length() == 0)) { System.out.print("判断BOM表中扭矩是否符合:"+niuju+" 扭矩范围:"+range+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" 匹配扭矩"); isWithinRange = true; } if(isWithinRange) { System.out.println("后续和套筒匹配"); Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); if((resourcename.size() > 0 && resourcename.containsKey(resourceName))) { resourceTool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); } } } } } else if("电池工具".equals(name)){ for(String resourceName:batteryTool.keySet()) { List toolbeans = batteryTool.get(resourceName); for(ToolBean toolbean:toolbeans) { String range = toolbean.getRange(); String outSize = toolbean.getOutSize(); String resourceType = toolbean.getResourceType(); boolean isWithinRange = false; if(range!= null && range.length() > 0 && niuju != null && niuju.length() > 0) { range = range.replace("|", "-"); String newrange = RangeCalculator.adjustRange(range); String newniuju = niuju; if(bl_rev_object_name.contains("预紧")) { newniuju = RangeAdjuster.adjustRange(niuju); } System.out.print("判断BOM表中扭矩是否符合:"+niuju+"新扭矩:"+newniuju+" 扭矩范围:"+range+" 新扭矩范围:"+newrange+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" "); isWithinRange = RangChecker.isWithinRange(newniuju, newrange); if(isWithinRange) { System.out.println("新扭矩和新扭矩范围匹配"); } else { System.out.println("新扭矩和新扭矩范围不匹配"); } } else if((range == null || range.length() == 0) && (niuju == null || niuju.length() == 0)) { System.out.print("判断BOM表中扭矩是否符合:"+niuju+" 扭矩范围:"+range+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" 匹配扭矩"); isWithinRange = true; } if(isWithinRange) { System.out.println("后续和套筒匹配"); Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); if((resourcename.size() > 0 && resourcename.containsKey(resourceName))) { resourceTool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); } } } } } } } System.out.println("匹配的工具有哪些"); for(String resourcetype:Tool.keySet()) { List toolsbean = Tool.get(resourcetype); for(ToolBean toolbean:toolsbean) { String outsize = toolbean.getOutSize(); System.out.println("resourcetype:"+resourcetype+" outsize:"+outsize); } } System.out.println("有限匹配的资源名称工具有哪些"); for(String resourcetype:resourceTool.keySet()) { List toolsbean = resourceTool.get(resourcetype); for(ToolBean toolbean:toolsbean) { String outsize = toolbean.getOutSize(); System.out.println("resourcetype:"+resourcetype+" outsize:"+outsize); } } Map> needTool = null; if(resourceTool.size() > 0) { needTool = resourceTool; } else { needTool = Tool; } //匹配标准件 System.out.println("匹配标准件designid:"+designid); if(StandardPartMap.containsKey(designid)) { StandardPartBean stdbean = StandardPartMap.get(designid); // String headform = stdbean.getHeadform(); String headsize = stdbean.getHeadsize(); // Cell headform_cell = row.createCell(6); // headform_cell.setCellValue(headform); Cell headsize_cell = row.createCell(6); headsize_cell.setCellValue(headsize); // String key2 = headsize+"|"+headform; String key2 = headsize; System.out.println("寻找套筒 头部尺寸|头部形式:"+key2); if(SleeveMap.containsKey(key2)) { System.out.println("找到匹配"); Cell all_cell = row.createCell(7); String all = ""; List SleeveBeans = SleeveMap.get(key2); for(SleeveBean sleevebean:SleeveBeans) { String inputsize = sleevebean.getInputSize(); String length = sleevebean.getLength(); String resourceType = sleevebean.getResourceType(); boolean haspipei = false; if(length == null || length.length() == 0) { continue; } //后续工具与套筒匹配 for(String resourcetype:needTool.keySet()) { List toolsbean = needTool.get(resourcetype); // Cell toolresourceType_cell = row.createCell(8); // toolresourceType_cell.setCellValue(resourcetype); boolean has = false; for(ToolBean toolbean:toolsbean) { String outsize = toolbean.getOutSize(); if(outsize != null && outsize.length() > 0 && inputsize != null && inputsize.length() > 0) { if(outsize.equals(inputsize)) { System.out.println("工具匹配上套筒,工具的输出尺寸:"+outsize+" 套筒输入尺寸:"+inputsize+" 长度:"+length +" 资源类型:"+resourceType); has = true; all = all+resourcetype+"+"+resourceType; break; } } else if((outsize == null || outsize.length() == 0) && (inputsize == null || inputsize.length() == 0)){ System.out.println("工具匹配上套筒,工具的输出尺寸:"+outsize+" 套筒输入尺寸:"+inputsize+" 长度:"+length +" 资源类型:"+resourceType); all = all+resourcetype+"+"+resourceType; has = true; break; } } if(has) { // Cell resourceType_cell = row.createCell(9); // resourceType_cell.setCellValue(resourceType); haspipei = true; break; } } if(haspipei) { break; } } all_cell.setCellValue(all); if(all != null && all.length() > 0) { if(!pipei_resource_map.containsKey(all)) pipei_resource_map.put(all, all); } } else System.out.println("没有找到匹配"); } } else { System.out.println("未找到匹配的"); } Tool.clear(); resourceTool.clear(); } } if(!hasdesign) { bl_rev_object_name = bl_rev_object_name.replaceAll("预紧", ""); bl_rev_object_name = bl_rev_object_name.replaceAll("终紧", ""); bl_rev_object_name = bl_rev_object_name.replaceAll("紧固", ""); bl_rev_object_name = bl_rev_object_name.replaceAll("拧紧", ""); // String bl_item_item_id = op.getProperty("bl_item_item_id"); op_nodesignmap.put(bl_rev_object_name, op); } else { // List newresources = new ArrayList<>(); // for(String pipei_resource:pipei_resource_map.keySet()) { // if(resource_map.containsKey(pipei_resource)) { // resource_map.remove(pipei_resource); // } // else { // newresources.add(pipei_resource); // } // } //将不能存在的资源移除掉 // String resourceids = ""; // for(String pipei_resource:resource_map.keySet()) { // List bomline = resource_map.get(pipei_resource); // for(InterfaceAIFComponent com:bomline) { // if(com != null && com instanceof TCComponentBOMLine) { // TCComponentBOMLine line = (TCComponentBOMLine) com; // String resourceid = line.getProperty("bl_item_item_id"); // resourceids = resourceids +resourceid+";"; // line.cut(); // } // } // // } // if(resourceids.endsWith(";")) { // resourceids = resourceids.substring(0,resourceids.length() - 1); // } ((TCComponentMfgBvrOperation) childcom).window().save(); //获取工位 System.out.println(childcom+"获取工位"); List result = getStation((TCComponentBOMLine)childcom); if(result.size() > 0) { String queryid = ""; for(TCComponent station:result) { String stationid = station.getProperty("bl_item_item_id"); queryid = queryid + stationid+";"; } if(queryid.endsWith(";")) { queryid = queryid.substring(0, queryid.length()-1); } if(workline != null) { Map clause = new HashMap<>(); clause.put("item_id", queryid); System.out.println("获取到的工位id:"+queryid); List result2 = TCUtil.queryBOMStructObject(session,workline,"queryItem",clause); if(result2 != null) { for(TCComponent stationline:result2) { //工位下先去除资源 // if(queryid.length() > 0) { // Map clause2 = new HashMap<>(); // clause2.put("object_name", queryid); // List deleteResourceresult2 = TCUtil.queryBOMStructObject2(session,stationline,"queryItem",clause2); // if(deleteResourceresult2 != null) // for(TCComponent resourceline:deleteResourceresult2) { // if(resourceline instanceof TCComponentBOMLine) { // TCComponentBOMLine rs = (TCComponentBOMLine) resourceline; // rs.cut(); // } // // } // } if(stationline instanceof TCComponentBOMLine) { TCComponentBOMLine station = (TCComponentBOMLine) stationline; for(String pipei_resource:pipei_resource_map.keySet()) { //要放的资源到工序下 if(pipei_resource == null || pipei_resource.length() == 0) continue; //先判断工位下是否有此名称的资源,有的直接拿来用 System.out.println("先判断工位下是否有此名称的资源,有的直接拿来用"); Map clause3 = new HashMap<>(); clause3.put("object_name", pipei_resource); List Resourceresult2 = TCUtil.queryBOMStructObject2(session,stationline,"queryItem",clause3); if(Resourceresult2 != null && Resourceresult2.size() > 0) { System.out.println("工位下直接拿来用"+pipei_resource); TCUtil.connectObject(session, Resourceresult2.get(0), (TCComponent)op, "MEResource"); } else { System.out.println("工位下没有资源:"+pipei_resource); Map clause22 = new HashMap<>(); clause22.put("object_name", pipei_resource); clause22.put("object_type", "Item"); TCComponent[] query_items = TCUtil.Generalquery2(session, "queryItem", clause22); if(query_items != null && query_items.length > 0) { System.out.println("工位下没有资源:"+pipei_resource); TCComponentBOMLine newResourceline = station.add((TCComponentItem) query_items[0],null, null, false); TCUtil.connectObject(session, newResourceline, (TCComponent)op, "MEResource"); } else { //创建新的item System.out.println("工位下没有资源,创建新的资源:"+pipei_resource); TCComponentItem item = TCUtil.createItem(session, "", "A", "Item", pipei_resource); TCComponentBOMLine newResourceline = station.add(item,null, null, false); TCUtil.connectObject(session, newResourceline, (TCComponent)op, "MEResource"); String[] split = pipei_resource.split("\\+",-1); Map clause2 = new HashMap<>(); for(String split_value:split) { clause2.clear(); clause2.put("object_name", split_value); clause2.put("object_type", "Design Part"); System.out.println("资源添加工具或套筒:"+split_value); TCComponent[] tool_resource = TCUtil.Generalquery2(session, "queryItem", clause2); if(tool_resource != null && tool_resource.length > 0) { newResourceline.add((TCComponentItem) tool_resource[0],null, null, false); } } } } } } } } } } } idmap.clear(); } // } else if(childcom instanceof TCComponentMfgBvrProcessStation || childcom instanceof TCComponentMfgBvrProcessLine || childcom instanceof TCComponentMfgBvrPlantBOP) { opBOMLineData(childcom,sheet); } } } /** * no_load:已经加载过的数据id下次就不加载了 * */ private void getparent(TCComponentBOMLine parent,Sheet sheet,TCComponentBOMLine oldparent)throws Exception{ if(parent != null && op_nodesignmap.size() > 0) { String parentid = parent.getProperty("bl_item_item_id"); System.out.println("parentid"+parentid); AIFComponentContext[] children = parent.getChildren(); for (AIFComponentContext child : children) { InterfaceAIFComponent childcom = child.getComponent(); String id = childcom.getProperty("bl_item_item_id"); System.out.println("子层级:"+id); if(op_nodesignmap.size() == 0) { break; } if(no_load.containsKey(id)) { System.out.println("子层级处理过不再处理:"+id); continue; } if(childcom instanceof TCComponentMfgBvrOperation) { TCComponentMfgBvrOperation op = (TCComponentMfgBvrOperation) childcom; final String bl_rev_object_name = op.getProperty("bl_rev_object_name"); String bl_indented_title = op.getProperty("bl_indented_title"); Set keys = op_nodesignmap.keySet(); boolean found = false; String haskey = ""; for (String key : keys) { if (bl_rev_object_name.contains(key)) { found = true; haskey = key; break; // 一旦找到了就退出循环 } } if(found) { TCComponentMfgBvrOperation oldop = op_nodesignmap.get(haskey); AIFComponentContext[] design_children = op.getChildren(); boolean hasdesign = false; Map idmap = new HashMap<>(); Map pipei_resource_map = new HashMap<>(); // Map> resource_map = new HashMap<>();//工序下挂接的资源 for(AIFComponentContext designchild:design_children) { InterfaceAIFComponent designchildcom = designchild.getComponent(); String bl_item_object_type = designchildcom.getProperty("bl_item_object_type"); String bl_occ_type = designchildcom.getProperty("bl_occ_type"); // if("MEResource".equalsIgnoreCase(bl_occ_type)) { // String Resource_name = designchildcom.getProperty("bl_rev_object_name"); // resource_map.computeIfAbsent(Resource_name, key2 -> new ArrayList<>()).add(designchildcom); // } if("Design Part".equalsIgnoreCase(bl_item_object_type)) { hasdesign = true; //获取符合的数据 Map> Tool = new HashMap<>(); Map> resourceTool = new HashMap<>(); //获取design String designid = designchildcom.getProperty("bl_item_item_id"); if(idmap.containsKey(designid)) { continue; } else { idmap.put(designid, designid); } String newname = bl_rev_object_name.replaceAll("预紧", "") .replaceAll("终紧", "") .replaceAll("紧固", "") .replaceAll("拧紧", ""); Row row = sheet.createRow(row_num); row_num ++; Cell optitle_cell = row.createCell(0); optitle_cell.setCellValue(bl_indented_title); Cell designid_cell = row.createCell(1); designid_cell.setCellValue(designid); String key = designid; System.out.println("看design是否匹配:"+key); if(DesignPartBeanMap.containsKey(key)) { System.out.println("找到匹配的,开始匹配规则"); DesignPartBean bean = DesignPartBeanMap.get(key); String fccdes = bean.getFCCDES(); if(!newname.contains(fccdes)) { continue; } String niuju = ""; String dongtai = bean.getDongtai(); if(dongtai.length() > 0) { if(dongtai.contains("N.M")) { String[] split = dongtai.split("N.M", -1); if(split!= null && split.length == 2) { niuju = split[0]; } } } Cell svpps_cell = row.createCell(2); svpps_cell.setCellValue(bean.getSVPPS()); Cell fcc_cell = row.createCell(3); fcc_cell.setCellValue(bean.getFCC()); Cell dongtai_cell = row.createCell(4); dongtai_cell.setCellValue(bean.getDongtai()); Cell kcds_cell = row.createCell(5); kcds_cell.setCellValue(bean.getKCDS()); //优先执行特殊工艺规则和电动工具新型号规则,若无匹配全量跑后续规则 boolean processrule = false; for(int i = 0; i< processrules.size(); i++) { CustRuleBean rulebean = processrules.get(i); String rule_svpps = rulebean.getSVPPS(); boolean is_ok = true; if(rule_svpps != null && rule_svpps.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_svpps, bean.getSVPPS()); if(!result) is_ok = false; } String rule_fcc = rulebean.getFCC(); if(rule_fcc != null && rule_fcc.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_fcc, bean.getFCC()); if(!result) is_ok = false; } String rule_dongtai = rulebean.getDongtai(); if(rule_dongtai != null && rule_dongtai.length() > 0) { if(dongtai.length() > 0) { if(dongtai.contains("N.M")) { String[] split = dongtai.split("N.M", -1); if(split!= null && split.length == 2) { niuju = split[0]; boolean result = ConditionChecker.checkCondition(rule_dongtai, split[1], split[0]); if(!result) is_ok = false; } } else { boolean result = ConditionChecker.checkCondition(rule_dongtai, dongtai,""); if(!result) is_ok = false; } } else { is_ok = false; } } String rule_FCCDESC = rulebean.getFCCDES(); if(rule_FCCDESC != null && rule_FCCDESC.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_FCCDESC, bl_rev_object_name); if(!result) is_ok = false; } if(is_ok) { //获取资源名称 processrule = true; String resourceName = rulebean.getResourceName(); // System.out.println("根据资源名称去电池工具里面找:"+resourceName); if(batteryTool.containsKey(resourceName)) { List tools = batteryTool.get(resourceName); for(ToolBean tool:tools) { String range = tool.getRange(); String resourceType = tool.getResourceType(); String outSize = tool.getOutSize(); boolean isWithinRange = false; if(range!= null && range.length() > 0 && niuju != null && niuju.length() > 0) { range = range.replace("|", "-"); String newrange = RangeCalculator.adjustRange(range); String newniuju = niuju; if(bl_rev_object_name.contains("预紧")) { newniuju = RangeAdjuster.adjustRange(niuju); } System.out.print("判断BOM表中扭矩是否符合:"+niuju+"新扭矩:"+newniuju+"资源名称:"+resourceName+" 扭矩范围:"+range+" 新扭矩范围:"+newrange+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" "); isWithinRange = RangChecker.isWithinRange(newniuju, newrange); if(isWithinRange) { System.out.println("新扭矩和新扭矩范围匹配"); } else { System.out.println("新扭矩和新扭矩范围不匹配"); } } else if((range == null || range.length() == 0) && (niuju == null || niuju.length() == 0)) { System.out.print("判断BOM表中扭矩是否符合:"+niuju+"资源名称:"+resourceName+" 扭矩范围:"+range+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" 匹配扭矩"); isWithinRange = true; } if(isWithinRange) { System.out.println("后续和套筒匹配"); Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(tool); } } } } } boolean autotoolrule = false; if(!processrule) { //执行电动工具规则 for(int i = 0; i< autotoolrules.size(); i++) { CustRuleBean rulebean = autotoolrules.get(i); String rule_svpps = rulebean.getSVPPS(); boolean is_ok = true; if(rule_svpps != null && rule_svpps.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_svpps, bean.getSVPPS()); if(!result) is_ok = false; } String rule_fcc = rulebean.getFCC(); if(rule_fcc != null && rule_fcc.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_fcc, bean.getFCC()); if(!result) is_ok = false; } String rule_FCCDESC = rulebean.getFCCDES(); if(rule_FCCDESC != null && rule_FCCDESC.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_FCCDESC, bl_rev_object_name); if(!result) is_ok = false; } if(is_ok) { //获取资源类型 autotoolrule = true; String resourceType = rulebean.getResourceType(); System.out.println("匹配上电动工具,资源型号:"+resourceType); if(eleTool.containsKey(resourceType)) { List tools = eleTool.get(resourceType); for(ToolBean tool:tools) { String range = tool.getRange(); String outSize = tool.getOutSize(); boolean isWithinRange = false; if(range!= null && range.length() > 0 && niuju != null && niuju.length() > 0) { range = range.replace("|", "-"); String newrange = RangeCalculator.adjustRange(range); String newniuju = niuju; if(bl_rev_object_name.contains("预紧")) { newniuju = RangeAdjuster.adjustRange(niuju); } System.out.print("判断BOM表中扭矩是否符合:"+niuju+"新扭矩:"+newniuju+" 扭矩范围:"+range+" 新扭矩范围:"+newrange+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" "); isWithinRange = RangChecker.isWithinRange(newniuju, newrange); if(isWithinRange) { System.out.println("新扭矩和新扭矩范围匹配"); } else { System.out.println("新扭矩和新扭矩范围不匹配"); } } else if((range == null || range.length() == 0) && (niuju == null || niuju.length() == 0)) { System.out.print("判断BOM表中扭矩是否符合:"+niuju+" 扭矩范围:"+range+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" 匹配扭矩"); isWithinRange = true; } if(isWithinRange) { System.out.println("后续和套筒匹配"); Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(tool); } } } } } } if(!autotoolrule) { Map resourcename = new HashMap<>(); //拧紧性质规则 //看读取哪个表 Map Tightenexcelname = new HashMap<>(); for(int i = 0; i< Tightenrules.size(); i++) { CustRuleBean rulebean = Tightenrules.get(i); String rule_svpps = rulebean.getSVPPS(); boolean is_ok = true; if(rule_svpps != null && rule_svpps.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_svpps, bean.getSVPPS()); if(!result) is_ok = false; } String rule_FCCDESC = rulebean.getFCCDES(); if(rule_FCCDESC != null && rule_FCCDESC.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_FCCDESC, bl_rev_object_name); if(!result) is_ok = false; } String rule_dongtai = rulebean.getDongtai(); if(rule_dongtai != null && rule_dongtai.length() > 0) { if(dongtai.length() > 0) { if(dongtai.contains("N.M")) { String[] split = dongtai.split("N.M", -1); if(split!= null && split.length == 2) { boolean result = ConditionChecker.checkCondition(rule_dongtai, split[1], split[0]); if(!result) is_ok = false; } } else { boolean result = ConditionChecker.checkCondition(rule_dongtai, dongtai,""); if(!result) is_ok = false; } } else { is_ok = false; } } if(is_ok) { //获取资源名称 String resourceType = rulebean.getResourceType(); if(resourceType != null && resourceType.length() > 0) { String[] res = resourceType.split("\\|", -1); for(String re:res) { if(Tightenexcelname.containsKey(re)) { // } else { Tightenexcelname.put(re, 1); } } } System.out.println("拧紧性质规则匹配"+resourceType); break; } } //KCDS //看读取哪个表 Map KCDSexcelname = new HashMap<>(); for(int i = 0; i< KCDSrules.size(); i++) { CustRuleBean rulebean = KCDSrules.get(i); String rule_svpps = rulebean.getSVPPS(); boolean is_ok = true; if(rule_svpps != null && rule_svpps.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_svpps, bean.getSVPPS()); if(!result) is_ok = false; } String rule_FCCDESC = rulebean.getFCCDES(); if(rule_FCCDESC != null && rule_FCCDESC.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_FCCDESC, bl_rev_object_name); if(!result) is_ok = false; } String rule_KCDS = rulebean.getKCDS(); if(rule_KCDS != null && rule_KCDS.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_KCDS, bean.getKCDS()); if(!result) is_ok = false; } if(is_ok) { //获取资源类型 String resourceType = rulebean.getResourceType(); if(resourceType != null && resourceType.length() > 0) { String[] res = resourceType.split("\\|", -1); for(String re:res) { if(KCDSexcelname.containsKey(re)) { } else { KCDSexcelname.put(re, 1); } } } System.out.println("KCDS匹配"+resourceType); break; } } //拧紧方式 Map TightenMethodexcelname = new HashMap<>(); for(int i = 0; i< TightenMethodrules.size(); i++) { CustRuleBean rulebean = TightenMethodrules.get(i); String rule_svpps = rulebean.getSVPPS(); boolean is_ok = true; if(rule_svpps != null && rule_svpps.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_svpps, bean.getSVPPS()); if(!result) is_ok = false; } String rule_FCCDESC = rulebean.getFCCDES(); if(rule_FCCDESC != null && rule_FCCDESC.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_FCCDESC, bl_rev_object_name); if(!result) is_ok = false; } String rule_dongtai = rulebean.getDongtai(); if(rule_dongtai != null && rule_dongtai.length() > 0) { if(dongtai.length() > 0) { if(dongtai.contains("N.M")) { String[] split = dongtai.split("N.M", -1); if(split!= null && split.length == 2) { boolean result = ConditionChecker.checkCondition(rule_dongtai, split[1], split[0]); if(!result) is_ok = false; } } else { boolean result = ConditionChecker.checkCondition(rule_dongtai, dongtai,""); if(!result) is_ok = false; } } else { is_ok = false; } } if(is_ok) { //获取资源类型 String resourceType = rulebean.getResourceType(); if(resourceType != null && resourceType.length() > 0) { String[] res = resourceType.split("\\|", -1); for(String re:res) { if(TightenMethodexcelname.containsKey(re)) { } else { TightenMethodexcelname.put(re, 1); } } } System.out.println("拧紧方式匹配"+resourceType); break; } } //扭矩值 Map Torqueexcelname = new HashMap<>(); for(int i = 0; i< Torquerules.size(); i++) { CustRuleBean rulebean = Torquerules.get(i); String rule_svpps = rulebean.getSVPPS(); boolean is_ok = true; if(rule_svpps != null && rule_svpps.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_svpps, bean.getSVPPS()); if(!result) is_ok = false; } String rule_FCCDESC = rulebean.getFCCDES(); if(rule_FCCDESC != null && rule_FCCDESC.length() > 0) { boolean result = StringConditionChecker.checkCondition(rule_FCCDESC, bl_rev_object_name); if(!result) is_ok = false; } String rule_dongtai = rulebean.getDongtai(); if(rule_dongtai != null && rule_dongtai.length() > 0) { if(dongtai.length() > 0) { if(dongtai.contains("N.M")) { String[] split = dongtai.split("N.M", -1); if(split!= null && split.length == 2) { boolean result = ConditionChecker.checkCondition(rule_dongtai, split[1], split[0]); if(!result) is_ok = false; } } else { boolean result = ConditionChecker.checkCondition(rule_dongtai, dongtai,""); if(!result) is_ok = false; } } else { is_ok = false; } } if(is_ok) { //获取资源类型 String resourceType = rulebean.getResourceType(); String resourceName = rulebean.getResourceName(); if(resourceType != null && resourceType.length() > 0) { String[] res = resourceType.split("\\|", -1); for(String re:res) { if(Torqueexcelname.containsKey(re)) { } else { Torqueexcelname.put(re, 1); } } } if(resourceName != null && resourceName.length() > 0) { String[] res = resourceName.split("\\|", -1); for(String re:res) { if(resourcename.containsKey(re)) { } else { resourcename.put(re, re); } } } System.out.println("扭矩值匹配"+resourceType); break; } } // 将所有 Map 放入一个列表 // List> maps = Arrays.asList(Tightenexcelname, KCDSexcelname, TightenMethodexcelname, Torqueexcelname); Set commonKeys = new HashSet<>(Tightenexcelname.keySet()); // 保留 map2、map3、map4 中也有的键 commonKeys.retainAll(KCDSexcelname.keySet()); commonKeys.retainAll(TightenMethodexcelname.keySet()); commonKeys.retainAll(Torqueexcelname.keySet()); System.out.println("四个 Map 都有的 key: " + commonKeys); //读取工具excel数据 for(String name:commonKeys) { if("电动工具".equals(name)){ for(String resourceType:eleTool.keySet()) { List toolbeans = eleTool.get(resourceType); for(ToolBean toolbean:toolbeans) { String range = toolbean.getRange(); String outSize = toolbean.getOutSize(); String resourceName = toolbean.getResourceName(); boolean isWithinRange = false; if(range!= null && range.length() > 0 && niuju != null && niuju.length() > 0) { range = range.replace("|", "-"); String newrange = RangeCalculator.adjustRange(range); String newniuju = niuju; if(bl_rev_object_name.contains("预紧")) { newniuju = RangeAdjuster.adjustRange(niuju); } System.out.print("判断BOM表中扭矩是否符合:"+niuju+"新扭矩:"+newniuju+" 扭矩范围:"+range+" 新扭矩范围:"+newrange+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" "); isWithinRange = RangChecker.isWithinRange(newniuju, newrange); if(isWithinRange) { System.out.println("新扭矩和新扭矩范围匹配"); } else { System.out.println("新扭矩和新扭矩范围不匹配"); } } else if((range == null || range.length() == 0) && (niuju == null || niuju.length() == 0)) { System.out.print("判断BOM表中扭矩是否符合:"+niuju+" 扭矩范围:"+range+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" 匹配扭矩"); isWithinRange = true; } if(isWithinRange) { System.out.println("后续和套筒匹配"); Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); if(resourcename.size() > 0 && resourcename.containsKey(resourceName)) { resourceTool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); } } } } } else if("手动工具".equals(name)){ for(String resourceType:eleTool.keySet()) { List toolbeans = eleTool.get(resourceType); for(ToolBean toolbean:toolbeans) { String resourceName = toolbean.getResourceName(); Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); if((resourcename.size() > 0 && resourcename.containsKey(resourceName))) { resourceTool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); } } // Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).addAll(toolbeans); } } else if("气动工具".equals(name)){ for(String resourceType:pneumaticTool.keySet()) { List toolbeans = pneumaticTool.get(resourceType); for(ToolBean toolbean:toolbeans) { String range = toolbean.getRange(); String outSize = toolbean.getOutSize(); String resourceName = toolbean.getResourceName(); boolean isWithinRange = false; if(range!= null && range.length() > 0 && niuju != null && niuju.length() > 0) { range = range.replace("|", "-"); String newrange = RangeCalculator.adjustRange(range); String newniuju = niuju; if(bl_rev_object_name.contains("预紧")) { newniuju = RangeAdjuster.adjustRange(niuju); } System.out.print("判断BOM表中扭矩是否符合:"+niuju+"新扭矩:"+newniuju+" 扭矩范围:"+range+" 新扭矩范围:"+newrange+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" "); isWithinRange = RangChecker.isWithinRange(newniuju, newrange); if(isWithinRange) { System.out.println("新扭矩和新扭矩范围匹配"); } else { System.out.println("新扭矩和新扭矩范围不匹配"); } } else if((range == null || range.length() == 0) && (niuju == null || niuju.length() == 0)) { System.out.print("判断BOM表中扭矩是否符合:"+niuju+" 扭矩范围:"+range+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" 匹配扭矩"); isWithinRange = true; } if(isWithinRange) { System.out.println("后续和套筒匹配"); Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); if((resourcename.size() > 0 && resourcename.containsKey(resourceName))) { resourceTool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); } } } } } else if("电池工具".equals(name)){ for(String resourceName:batteryTool.keySet()) { List toolbeans = batteryTool.get(resourceName); for(ToolBean toolbean:toolbeans) { String range = toolbean.getRange(); String outSize = toolbean.getOutSize(); String resourceType = toolbean.getResourceType(); boolean isWithinRange = false; if(range!= null && range.length() > 0 && niuju != null && niuju.length() > 0) { range = range.replace("|", "-"); String newrange = RangeCalculator.adjustRange(range); String newniuju = niuju; if(bl_rev_object_name.contains("预紧")) { newniuju = RangeAdjuster.adjustRange(niuju); } System.out.print("判断BOM表中扭矩是否符合:"+niuju+"新扭矩:"+newniuju+" 扭矩范围:"+range+" 新扭矩范围:"+newrange+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" "); isWithinRange = RangChecker.isWithinRange(newniuju, newrange); if(isWithinRange) { System.out.println("新扭矩和新扭矩范围匹配"); } else { System.out.println("新扭矩和新扭矩范围不匹配"); } } else if((range == null || range.length() == 0) && (niuju == null || niuju.length() == 0)) { System.out.print("判断BOM表中扭矩是否符合:"+niuju+" 扭矩范围:"+range+" 资源型号:"+resourceType+" 输出尺寸:"+outSize+" 匹配扭矩"); isWithinRange = true; } if(isWithinRange) { System.out.println("后续和套筒匹配"); Tool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); if((resourcename.size() > 0 && resourcename.containsKey(resourceName))) { resourceTool.computeIfAbsent(resourceType, key2 -> new ArrayList<>()).add(toolbean); } } } } } } } System.out.println("匹配的工具有哪些"); for(String resourcetype:Tool.keySet()) { List toolsbean = Tool.get(resourcetype); for(ToolBean toolbean:toolsbean) { String outsize = toolbean.getOutSize(); System.out.println("resourcetype:"+resourcetype+" outsize:"+outsize); } } System.out.println("有限匹配的资源名称工具有哪些"); for(String resourcetype:resourceTool.keySet()) { List toolsbean = resourceTool.get(resourcetype); for(ToolBean toolbean:toolsbean) { String outsize = toolbean.getOutSize(); System.out.println("resourcetype:"+resourcetype+" outsize:"+outsize); } } Map> needTool = null; if(resourceTool.size() > 0) { needTool = resourceTool; } else { needTool = Tool; } //匹配标准件 System.out.println("匹配标准件designid:"+designid); if(StandardPartMap.containsKey(designid)) { StandardPartBean stdbean = StandardPartMap.get(designid); // String headform = stdbean.getHeadform(); String headsize = stdbean.getHeadsize(); // Cell headform_cell = row.createCell(6); // headform_cell.setCellValue(headform); Cell headsize_cell = row.createCell(6); headsize_cell.setCellValue(headsize); // String key2 = headsize+"|"+headform; String key2 = headsize; System.out.println("寻找套筒 头部尺寸|头部形式:"+key2); if(SleeveMap.containsKey(key2)) { System.out.println("找到匹配"); Cell all_cell = row.createCell(7); String all = ""; List SleeveBeans = SleeveMap.get(key2); for(SleeveBean sleevebean:SleeveBeans) { String inputsize = sleevebean.getInputSize(); String length = sleevebean.getLength(); String resourceType = sleevebean.getResourceType(); boolean haspipei = false; if(length == null || length.length() == 0) { continue; } //后续工具与套筒匹配 for(String resourcetype:needTool.keySet()) { List toolsbean = needTool.get(resourcetype); // Cell toolresourceType_cell = row.createCell(8); // toolresourceType_cell.setCellValue(resourcetype); boolean has = false; for(ToolBean toolbean:toolsbean) { String outsize = toolbean.getOutSize(); if(outsize != null && outsize.length() > 0 && inputsize != null && inputsize.length() > 0) { if(outsize.equals(inputsize)) { System.out.println("工具匹配上套筒,工具的输出尺寸:"+outsize+" 套筒输入尺寸:"+inputsize+" 长度:"+length +" 资源类型:"+resourceType); has = true; all = all+resourcetype+"+"+resourceType; break; } } else if((outsize == null || outsize.length() == 0) && (inputsize == null || inputsize.length() == 0)){ System.out.println("工具匹配上套筒,工具的输出尺寸:"+outsize+" 套筒输入尺寸:"+inputsize+" 长度:"+length +" 资源类型:"+resourceType); all = all+resourcetype+"+"+resourceType; has = true; break; } } if(has) { // Cell resourceType_cell = row.createCell(9); // resourceType_cell.setCellValue(resourceType); haspipei = true; break; } } if(haspipei) { break; } } all_cell.setCellValue(all); if(all != null && all.length() > 0) { if(!pipei_resource_map.containsKey(all)) pipei_resource_map.put(all, all); } } else System.out.println("没有找到匹配"); } } else { System.out.println("未找到匹配的"); } Tool.clear(); resourceTool.clear(); } } if(hasdesign) { op_nodesignmap.remove(haskey); } else { // List newresources = new ArrayList<>(); // for(String pipei_resource:pipei_resource_map.keySet()) { // if(resource_map.containsKey(pipei_resource)) { // resource_map.remove(pipei_resource); // } // else { // newresources.add(pipei_resource); // } // } //将不能存在的资源移除掉 // String resourceids = ""; // for(String pipei_resource:resource_map.keySet()) { // List bomline = resource_map.get(pipei_resource); // for(InterfaceAIFComponent com:bomline) { // if(com != null && com instanceof TCComponentBOMLine) { // TCComponentBOMLine line = (TCComponentBOMLine) com; // String resourceid = line.getProperty("bl_item_item_id"); // resourceids = resourceids +resourceid+";"; // line.cut(); // } // } // // } // if(resourceids.endsWith(";")) { // resourceids = resourceids.substring(0,resourceids.length() - 1); // } ((TCComponentMfgBvrOperation) childcom).window().save(); //获取工位 System.out.println(childcom+"获取工位"); List result = getStation((TCComponentBOMLine)childcom); if(result.size() > 0) { String queryid = ""; for(TCComponent station:result) { String stationid = station.getProperty("bl_item_item_id"); queryid = queryid + stationid+";"; } if(queryid.endsWith(";")) { queryid = queryid.substring(0, queryid.length()-1); } if(workline != null) { Map clause = new HashMap<>(); clause.put("item_id", queryid); List result2 = TCUtil.queryBOMStructObject(session,workline,"queryItem",clause); if(result2 != null) { for(TCComponent stationline:result2) { //工位下先去除资源 // if(queryid.length() > 0) { // Map clause2 = new HashMap<>(); // clause2.put("object_name", queryid); // List deleteResourceresult2 = TCUtil.queryBOMStructObject2(session,stationline,"queryItem",clause2); // if(deleteResourceresult2 != null) // for(TCComponent resourceline:deleteResourceresult2) { // if(resourceline instanceof TCComponentBOMLine) { // TCComponentBOMLine rs = (TCComponentBOMLine) resourceline; // rs.cut(); // } // // } // } if(stationline instanceof TCComponentBOMLine) { TCComponentBOMLine station = (TCComponentBOMLine) stationline; for(String pipei_resource:pipei_resource_map.keySet()) { //要放的资源到工序下 if(pipei_resource == null || pipei_resource.length() == 0) continue; //先判断工位下是否有此名称的资源,有的直接拿来用 System.out.println("先判断工位下是否有此名称的资源,有的直接拿来用"); Map clause3 = new HashMap<>(); clause3.put("object_name", pipei_resource); List Resourceresult2 = TCUtil.queryBOMStructObject2(session,stationline,"queryItem",clause3); if(Resourceresult2 != null && Resourceresult2.size() > 0) { System.out.println("工位下直接拿来用"+pipei_resource); TCUtil.connectObject(session, Resourceresult2.get(0), (TCComponent)oldop, "MEResource"); } else { System.out.println("工位下没有资源:"+pipei_resource); Map clause22 = new HashMap<>(); clause22.put("object_name", pipei_resource); clause22.put("object_type", "Item"); TCComponent[] query_items = TCUtil.Generalquery2(session, "queryItem", clause22); if(query_items != null && query_items.length > 0) { System.out.println("工位下没有资源:"+pipei_resource); TCComponentBOMLine newResourceline = station.add((TCComponentItem) query_items[0],null, null, false); TCUtil.connectObject(session, newResourceline, (TCComponent)oldop, "MEResource"); } else { //创建新的item System.out.println("工位下没有资源,创建新的资源:"+pipei_resource); TCComponentItem item = TCUtil.createItem(session, "", "A", "Item", pipei_resource); TCComponentBOMLine newResourceline = station.add(item,null, null, false); TCUtil.connectObject(session, newResourceline, (TCComponent)oldop, "MEResource"); String[] split = pipei_resource.split("\\+",-1); Map clause2 = new HashMap<>(); for(String split_value:split) { clause2.clear(); clause2.put("object_name", split_value); clause2.put("object_type", "Design Part"); System.out.println("资源添加工具或套筒:"+split_value); TCComponent[] tool_resource = TCUtil.Generalquery2(session, "queryItem", clause2); if(tool_resource != null && tool_resource.length > 0) { newResourceline.add((TCComponentItem) tool_resource[0],null, null, false); } } } } } } } } } } } idmap.clear(); } } else if(childcom instanceof TCComponentMfgBvrProcessStation || childcom instanceof TCComponentMfgBvrProcessLine || childcom instanceof TCComponentMfgBvrPlantBOP) { System.out.println("往下找"+id); getparent((TCComponentBOMLine)childcom,sheet,null); } if(op_nodesignmap.size() > 0) { no_load.put(id, id); } else { break; } } // if(op_nodesignmap.size() > 0) { if(!no_load.containsKey(parentid)) { no_load.put(parentid, parentid); if(oldparent != null) { System.out.println("想上找"+parentid); getparent(oldparent.parent(),sheet,oldparent.parent()); } } } } } //读取BOM表 // private void readExcel(File excelfile,int start_rownum,int idcol2,int svppscol2,int fcccol2 // ,int fccdescol2,int dongtaicol,int kcdscol2) { // // Workbook work = null; // try(InputStream is = new FileInputStream(excelfile);){ // if (excelfile.getAbsolutePath().endsWith(".xls")) // work = new HSSFWorkbook(is); // else { // work = new XSSFWorkbook(is); // } // Sheet sheet = work.getSheetAt(0); // int count = sheet.getPhysicalNumberOfRows(); // for(int i = start_rownum; i < count ;i++) { // Row row = sheet.getRow(i); // String id = ExcelUtil.getStringCellValue(row.getCell(idcol2-1)); // if(id == null || id.length() == 0) // break; // String svpps = ExcelUtil.getStringCellValue(row.getCell(svppscol2-1)); // String fcc = ExcelUtil.getStringCellValue(row.getCell(fcccol2-1)); // String fccdes = ExcelUtil.getStringCellValue(row.getCell(fccdescol2-1)); // String dongtai = ExcelUtil.getStringCellValue(row.getCell(dongtaicol-1)); // String kcds = ExcelUtil.getStringCellValue(row.getCell(kcdscol2-1)); // System.out.println("id:"+id+" svpps:"+svpps+" fcc:"+fcc+" fccdes:"+fccdes+" dongtai:"+dongtai+" kcds:"+kcds); // String key = id; // if(!DesignPartBeanMap.containsKey(key)) { // DesignPartBean bean = new DesignPartBean(); // bean.setDongtai(dongtai); // bean.setFCC(fcc); // bean.setFCCDES(fccdes); // bean.setKCDS(kcds); // bean.setSVPPS(svpps); // DesignPartBeanMap.put(key, bean); // } // } // } catch (FileNotFoundException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } catch (IOException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } private void readExcel(File excelfile,int start_rownum,int idcol2,int svppscol2,int fcccol2 ,int fccdescol2,int dongtaicol,int kcdscol2) { // 自定义监听器 AnalysisEventListener> listener = new AnalysisEventListener>() { @Override public void invoke(Map rowData, AnalysisContext context) { String id = rowData.get(idcol2-1) != null ? rowData.get(idcol2-1) : ""; String dongtai = rowData.get(dongtaicol-1) != null ? rowData.get(dongtaicol-1) : ""; String fcc = rowData.get(fcccol2-1) != null ? rowData.get(fcccol2-1) : ""; String fccdes = rowData.get(fccdescol2-1) != null ? rowData.get(fccdescol2-1) : ""; String kcds = rowData.get(kcdscol2-1) != null ? rowData.get(kcdscol2-1) : ""; String svpps = rowData.get(svppscol2-1) != null ? rowData.get(svppscol2-1) : ""; String key = id; if (!DesignPartBeanMap.containsKey(key)) { DesignPartBean bean = new DesignPartBean(); // 设置值,确保不会为 null bean.setDongtai(dongtai); bean.setFCC(fcc); bean.setFCCDES(fccdes); bean.setKCDS(kcds); bean.setSVPPS(svpps); DesignPartBeanMap.put(key, bean); } } @Override public void doAfterAllAnalysed(AnalysisContext context) { System.out.println("读取完成,共 " + DesignPartBeanMap.size() + " 行数据"); } }; // 执行读取 EasyExcel.read(excelfile, listener) .sheet(0) // 指定 sheet 索引 .headRowNumber(start_rownum) // 从第0行开始读取(包含标题行则设为1) .doRead(); } //读取规则表 private void readRuleExcel(File excelfile) { Workbook work = null; try(InputStream is = new FileInputStream(excelfile);){ if (excelfile.getAbsolutePath().endsWith(".xls")) work = new HSSFWorkbook(is); else { work = new XSSFWorkbook(is); } //读取特殊工艺规则sheet Sheet sheet = work.getSheet("特殊工艺规则"); System.out.println("特殊工艺规则"); if(sheet != null) { int count = sheet.getPhysicalNumberOfRows(); for(int i = 1; i < count ;i++) { Row row = sheet.getRow(i); String svpps = ExcelUtil.getStringCellValue(row.getCell(1)); String fcc = ExcelUtil.getStringCellValue(row.getCell(2)); String fccdes = ExcelUtil.getStringCellValue(row.getCell(0)); String dongtai = ExcelUtil.getStringCellValue(row.getCell(3)); String resourceName = ExcelUtil.getStringCellValue(row.getCell(4)); System.out.println("svpps:"+svpps+" fcc:"+fcc+" fccdes:"+fccdes+" dongtai:"+dongtai+" resourceName:"+resourceName); CustRuleBean bean = new CustRuleBean(); bean.setDongtai(dongtai); bean.setFCC(fcc); bean.setFCCDES(fccdes); bean.setResourceName(resourceName); bean.setSVPPS(svpps); processrules.add(bean); } } else { System.out.println("没有特殊工艺规则sheet页"); } Sheet sheet2 = work.getSheet("电动工具新型号"); System.out.println("电动工具新型号"); if(sheet2 != null) { int count = sheet2.getPhysicalNumberOfRows(); for(int i = 1; i < count ;i++) { Row row = sheet2.getRow(i); String svpps = ExcelUtil.getStringCellValue(row.getCell(1)); String fcc = ExcelUtil.getStringCellValue(row.getCell(2)); String fccdes = ExcelUtil.getStringCellValue(row.getCell(0)); String dongtai = ExcelUtil.getStringCellValue(row.getCell(3)); String resourceType = ExcelUtil.getStringCellValue(row.getCell(4)); System.out.println("svpps:"+svpps+" fcc:"+fcc+" fccdes:"+fccdes+" dongtai:"+dongtai+" resourceType:"+resourceType); CustRuleBean bean = new CustRuleBean(); bean.setDongtai(dongtai); bean.setFCC(fcc); bean.setFCCDES(fccdes); bean.setResourceType(resourceType); bean.setSVPPS(svpps); autotoolrules.add(bean); } } else { System.out.println("没有电动工具新型号sheet页"); } //Tightenrules Sheet sheet3 = work.getSheet("拧紧性质"); System.out.println("拧紧性质"); if(sheet3 != null) { int count = sheet3.getPhysicalNumberOfRows(); for(int i = 1; i < count ;i++) { Row row = sheet3.getRow(i); String svpps = ExcelUtil.getStringCellValue(row.getCell(1)); // String fcc = ExcelUtil.getStringCellValue(row.getCell(2)); String fccdes = ExcelUtil.getStringCellValue(row.getCell(0)); String dongtai = ExcelUtil.getStringCellValue(row.getCell(3)); String resourceType = ExcelUtil.getStringCellValue(row.getCell(4)); System.out.println("svpps:"+svpps+" fccdes:"+fccdes+" dongtai:"+dongtai+" resourceType:"+resourceType); CustRuleBean bean = new CustRuleBean(); bean.setDongtai(dongtai); // bean.setFCC(fcc); bean.setFCCDES(fccdes); bean.setResourceType(resourceType); bean.setSVPPS(svpps); Tightenrules.add(bean); } } else { System.out.println("没有拧紧性质sheet页"); } Sheet sheet4 = work.getSheet("KCDS判定"); System.out.println("KCDS判定"); if(sheet4 != null) { int count = sheet4.getPhysicalNumberOfRows(); for(int i = 1; i < count ;i++) { Row row = sheet4.getRow(i); String svpps = ExcelUtil.getStringCellValue(row.getCell(1)); // String fcc = ExcelUtil.getStringCellValue(row.getCell(2)); String fccdes = ExcelUtil.getStringCellValue(row.getCell(0)); // String dongtai = ExcelUtil.getStringCellValue(row.getCell(3)); String resourceType = ExcelUtil.getStringCellValue(row.getCell(4)); String KCDS = ExcelUtil.getStringCellValue(row.getCell(6)); System.out.println("svpps:"+svpps+" fccdes:"+fccdes+" resourceType:"+resourceType+" KCDS:"+KCDS); CustRuleBean bean = new CustRuleBean(); // bean.setDongtai(dongtai); // bean.setFCC(fcc); bean.setFCCDES(fccdes); bean.setResourceType(resourceType); bean.setSVPPS(svpps); bean.setKCDS(KCDS); KCDSrules.add(bean); } } else { System.out.println("没有KCDS判定sheet页"); } //TightenMethodrules Sheet sheet5 = work.getSheet("拧紧方式"); System.out.println("拧紧方式"); if(sheet5 != null) { int count = sheet5.getPhysicalNumberOfRows(); for(int i = 1; i < count ;i++) { Row row = sheet5.getRow(i); String svpps = ExcelUtil.getStringCellValue(row.getCell(1)); // String fcc = ExcelUtil.getStringCellValue(row.getCell(2)); String fccdes = ExcelUtil.getStringCellValue(row.getCell(0)); String dongtai = ExcelUtil.getStringCellValue(row.getCell(3)); String resourceType = ExcelUtil.getStringCellValue(row.getCell(4)); System.out.println("svpps:"+svpps+" fccdes:"+fccdes+" dongtai:"+dongtai+" resourceType:"+resourceType); CustRuleBean bean = new CustRuleBean(); bean.setDongtai(dongtai); // bean.setFCC(fcc); bean.setFCCDES(fccdes); bean.setResourceType(resourceType); bean.setSVPPS(svpps); TightenMethodrules.add(bean); } } else { System.out.println("没有拧紧方式sheet页"); } Sheet sheet6 = work.getSheet("扭矩值判定"); System.out.println("扭矩值判定"); if(sheet6 != null) { int count = sheet6.getPhysicalNumberOfRows(); for(int i = 1; i < count ;i++) { Row row = sheet6.getRow(i); String svpps = ExcelUtil.getStringCellValue(row.getCell(1)); // String fcc = ExcelUtil.getStringCellValue(row.getCell(2)); String fccdes = ExcelUtil.getStringCellValue(row.getCell(0)); String dongtai = ExcelUtil.getStringCellValue(row.getCell(3)); String resourceType = ExcelUtil.getStringCellValue(row.getCell(4)); String resourceName = ExcelUtil.getStringCellValue(row.getCell(5)); System.out.println("svpps:"+svpps+" fccdes:"+fccdes+" dongtai:"+dongtai+" resourceType:"+resourceType+" resourceName:"+resourceName); CustRuleBean bean = new CustRuleBean(); bean.setDongtai(dongtai); // bean.setFCC(fcc); bean.setFCCDES(fccdes); bean.setResourceType(resourceType); bean.setSVPPS(svpps); bean.setResourceName(resourceName); Torquerules.add(bean); } } else { System.out.println("没有扭矩值判定sheet页"); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 读取电动工具表*/ private void readElectricfile(File excelfile,int start_rownum) { Workbook work = null; try(InputStream is = new FileInputStream(excelfile);){ if (excelfile.getAbsolutePath().endsWith(".xls")) work = new HSSFWorkbook(is); else { work = new XSSFWorkbook(is); } Sheet sheet = work.getSheetAt(0); int count = sheet.getPhysicalNumberOfRows(); for(int i = start_rownum; i < count ;i++) { Row row = sheet.getRow(i); String ResourceType = ExcelUtil.getStringCellValue(row.getCell(1)); String Torque = ExcelUtil.getStringCellValue(row.getCell(6)); String outSize = ExcelUtil.getStringCellValue(row.getCell(8)); String resourceName = ExcelUtil.getStringCellValue(row.getCell(2)); if(ResourceType != null && ResourceType.length() > 0) { // 使用 computeIfAbsent 简化操作 ToolBean tool = new ToolBean(); tool.setOutSize(outSize); tool.setRange(Torque); tool.setResourceName(resourceName); eleTool.computeIfAbsent(ResourceType, key -> new ArrayList<>()).add(tool); } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 读取电池工具表*/ private void readbatteryfile(File excelfile,int start_rownum) { Workbook work = null; try(InputStream is = new FileInputStream(excelfile);){ if (excelfile.getAbsolutePath().endsWith(".xls")) work = new HSSFWorkbook(is); else { work = new XSSFWorkbook(is); } Sheet sheet = work.getSheetAt(0); int count = sheet.getPhysicalNumberOfRows(); for(int i = start_rownum; i < count ;i++) { Row row = sheet.getRow(i); String ResourceType = ExcelUtil.getStringCellValue(row.getCell(1)); String ResourceName = ExcelUtil.getStringCellValue(row.getCell(2)); String Torque = ExcelUtil.getStringCellValue(row.getCell(6)); String outSize = ExcelUtil.getStringCellValue(row.getCell(8)); if(ResourceType != null && ResourceType.length() > 0) { // 使用 computeIfAbsent 简化操作 ToolBean tool = new ToolBean(); tool.setOutSize(outSize); tool.setResourceName(ResourceName); tool.setRange(Torque); tool.setResourceType(ResourceType); batteryTool.computeIfAbsent(ResourceName, key -> new ArrayList<>()).add(tool); } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 读取气动工具表*/ private void readpneumaticfile(File excelfile,int start_rownum) { Workbook work = null; try(InputStream is = new FileInputStream(excelfile);){ if (excelfile.getAbsolutePath().endsWith(".xls")) work = new HSSFWorkbook(is); else { work = new XSSFWorkbook(is); } Sheet sheet = work.getSheetAt(0); int count = sheet.getPhysicalNumberOfRows(); for(int i = start_rownum; i < count ;i++) { Row row = sheet.getRow(i); String ResourceType = ExcelUtil.getStringCellValue(row.getCell(1)); String ResourceName = ExcelUtil.getStringCellValue(row.getCell(2)); String Torque = ExcelUtil.getStringCellValue(row.getCell(6)); String outSize = ExcelUtil.getStringCellValue(row.getCell(8)); if(ResourceType != null && ResourceType.length() > 0) { // 使用 computeIfAbsent 简化操作 ToolBean tool = new ToolBean(); tool.setOutSize(outSize); tool.setResourceName(ResourceName); tool.setRange(Torque); tool.setResourceType(ResourceType); pneumaticTool.computeIfAbsent(ResourceType, key -> new ArrayList<>()).add(tool); } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 读取手动工具表*/ private void readmanualfile(File excelfile,int start_rownum) { Workbook work = null; try(InputStream is = new FileInputStream(excelfile);){ if (excelfile.getAbsolutePath().endsWith(".xls")) work = new HSSFWorkbook(is); else { work = new XSSFWorkbook(is); } Sheet sheet = work.getSheetAt(0); int count = sheet.getPhysicalNumberOfRows(); for(int i = start_rownum; i < count ;i++) { Row row = sheet.getRow(i); String ResourceType = ExcelUtil.getStringCellValue(row.getCell(1)); String ResourceName = ExcelUtil.getStringCellValue(row.getCell(2)); String Torque = ExcelUtil.getStringCellValue(row.getCell(6)); String outSize = ExcelUtil.getStringCellValue(row.getCell(8)); if(ResourceType != null && ResourceType.length() > 0) { // 使用 computeIfAbsent 简化操作 ToolBean tool = new ToolBean(); tool.setOutSize(outSize); tool.setResourceName(ResourceName); tool.setRange(Torque); tool.setResourceType(ResourceType); manualTool.computeIfAbsent(ResourceType, key -> new ArrayList<>()).add(tool); } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 读取标准件表*/ private void readstdPartfile(File excelfile,int start_rownum) { Workbook work = null; try(InputStream is = new FileInputStream(excelfile);){ if (excelfile.getAbsolutePath().endsWith(".xls")) work = new HSSFWorkbook(is); else { work = new XSSFWorkbook(is); } Sheet sheet = work.getSheetAt(0); int count = sheet.getPhysicalNumberOfRows(); for(int i = start_rownum; i < count ;i++) { Row row = sheet.getRow(i); String id = ExcelUtil.getStringCellValue(row.getCell(1)); String spec = ExcelUtil.getStringCellValue(row.getCell(3)); String length = ExcelUtil.getStringCellValue(row.getCell(6)); String headform = ExcelUtil.getStringCellValue(row.getCell(8)); String headsize = ExcelUtil.getStringCellValue(row.getCell(9)); if(id != null && id.length() > 0) { // 使用 computeIfAbsent 简化操作 StandardPartBean tool = new StandardPartBean(); tool.setHeadform(headform); tool.setHeadsize(headsize); tool.setLength(length); tool.setSpecification(spec); StandardPartMap.computeIfAbsent(id, key -> tool); } else { break; } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * 读取套筒表*/ private void readsleevefile(File excelfile, int start_rownum) { Workbook work = null; try (InputStream is = new FileInputStream(excelfile)) { if (excelfile.getAbsolutePath().endsWith(".xls")) { work = new HSSFWorkbook(is); } else { work = new XSSFWorkbook(is); } Sheet sheet = work.getSheetAt(0); int count = sheet.getPhysicalNumberOfRows(); // 临时存储所有 SleeveBean,按 outSize 分组 Map> tempMap = new HashMap<>(); for (int i = start_rownum; i < count; i++) { Row row = sheet.getRow(i); String resourceType = ExcelUtil.getStringCellValue(row.getCell(1)); String inputSize = ExcelUtil.getStringCellValue(row.getCell(6)); String outSize = ExcelUtil.getStringCellValue(row.getCell(7)); String length = ExcelUtil.getStringCellValue(row.getCell(11)); String headform = ExcelUtil.getStringCellValue(row.getCell(16)); if (resourceType != null && resourceType.length() > 0) { SleeveBean tool = new SleeveBean(); tool.setResourceType(resourceType); tool.setLength(length); tool.setHeadform(headform); tool.setInputSize(inputSize); tool.setOutSize(outSize); // 添加到临时 Map 中 tempMap.computeIfAbsent(outSize, key -> new ArrayList<>()).add(tool); } else { break; } } // 对每个 outSize 的 List 按 length 排序 for (Map.Entry> entry : tempMap.entrySet()) { List sleeveList = entry.getValue(); sleeveList.sort((bean1, bean2) -> { // 将 length 转换为数字进行比较 double length1 = parseLength(bean1.getLength()); double length2 = parseLength(bean2.getLength()); return Double.compare(length1, length2); }); // 将排序后的列表放入 SleeveMap SleeveMap.put(entry.getKey(), sleeveList); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private double parseLength(String length) { if (length == null || length.trim().isEmpty()) { return 0.0; // 默认值,可以根据需求调整 } try { return Double.parseDouble(length.trim()); } catch (NumberFormatException e) { System.err.println("无法解析 length: " + length); return 0.0; // 解析失败时返回默认值 } } private List getStation(TCComponentBOMLine child){ List result = null; Map clause = new HashMap<>(); clause.put("object_type", "MEStation"); try { result = TCUtil.queryBOMStructObject2(session,child,"queryItem",clause); if((result == null || result.size() == 0 )&& child.parent() != null) { result = getStation(child.parent()); } } catch (ServiceException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TCException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; } }