diff --git a/com.sq.customization/src/com/sq/customization/bean/CustRuleBean.java b/com.sq.customization/src/com/sq/customization/bean/CustRuleBean.java new file mode 100644 index 0000000..9a4a852 --- /dev/null +++ b/com.sq.customization/src/com/sq/customization/bean/CustRuleBean.java @@ -0,0 +1,55 @@ +package com.sq.customization.bean; + +public class CustRuleBean { + private String SVPPS; + private String FCC; + private String dongtai; + private String FCCDES; + private String KCDS; + private String resourceName; + + private String resourceType; + + public String getSVPPS() { + return SVPPS; + } + public void setSVPPS(String sVPPS) { + SVPPS = sVPPS; + } + public String getFCC() { + return FCC; + } + public void setFCC(String fCC) { + FCC = fCC; + } + public String getDongtai() { + return dongtai; + } + public void setDongtai(String dongtai) { + this.dongtai = dongtai; + } + public String getFCCDES() { + return FCCDES; + } + public void setFCCDES(String fCCDES) { + FCCDES = fCCDES; + } + public String getKCDS() { + return KCDS; + } + public void setKCDS(String kCDS) { + KCDS = kCDS; + } + public String getResourceName() { + return resourceName; + } + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + public String getResourceType() { + return resourceType; + } + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } +} diff --git a/com.sq.customization/src/com/sq/customization/bean/DesignPartBean.java b/com.sq.customization/src/com/sq/customization/bean/DesignPartBean.java new file mode 100644 index 0000000..7740983 --- /dev/null +++ b/com.sq.customization/src/com/sq/customization/bean/DesignPartBean.java @@ -0,0 +1,39 @@ +package com.sq.customization.bean; + +public class DesignPartBean { + private String SVPPS; + private String FCC; + private String dongtai; + private String FCCDES; + private String KCDS; + public String getSVPPS() { + return SVPPS; + } + public void setSVPPS(String sVPPS) { + SVPPS = sVPPS; + } + public String getFCC() { + return FCC; + } + public void setFCC(String fCC) { + FCC = fCC; + } + public String getDongtai() { + return dongtai; + } + public void setDongtai(String dongtai) { + this.dongtai = dongtai; + } + public String getFCCDES() { + return FCCDES; + } + public void setFCCDES(String fCCDES) { + FCCDES = fCCDES; + } + public String getKCDS() { + return KCDS; + } + public void setKCDS(String kCDS) { + KCDS = kCDS; + } +} diff --git a/com.sq.customization/src/com/sq/customization/dialogs/AutoTransToolDialog.java b/com.sq.customization/src/com/sq/customization/dialogs/AutoTransToolDialog.java index f035151..d1cfbfe 100644 --- a/com.sq.customization/src/com/sq/customization/dialogs/AutoTransToolDialog.java +++ b/com.sq.customization/src/com/sq/customization/dialogs/AutoTransToolDialog.java @@ -10,7 +10,9 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; @@ -26,8 +28,12 @@ import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import com.sq.customization.bean.CustRuleBean; +import com.sq.customization.bean.DesignPartBean; +import com.sq.customization.util.ConditionChecker; import com.sq.customization.util.ExcelUtil; import com.sq.customization.util.ProgressCustomDialog; +import com.sq.customization.util.StringConditionChecker; import com.teamcenter.rac.aif.AbstractAIFDialog; import com.teamcenter.rac.aif.kernel.AIFComponentContext; import com.teamcenter.rac.aif.kernel.InterfaceAIFComponent; @@ -36,7 +42,11 @@ 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.TCComponentDataset; +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; @@ -57,16 +67,33 @@ public class AutoTransToolDialog extends AbstractAIFDialog { private JButton cancel; private JButton directory; - private Registry registry = Registry.getRegistry(AutoTransToolDialog.class); +// private Registry registry = Registry.getRegistry(AutoTransToolDialog.class); private TCSession session; private InterfaceAIFComponent target; - Map no_load = new HashMap<>(); - Map op_nodesignmap = new HashMap<>(); - public AutoTransToolDialog(Frame fm,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 int times = 0; + public AutoTransToolDialog(Frame fm,InterfaceAIFComponent target,TCSession session) { super(fm); this.target = target; + this.session = session; op_nodesignmap.clear(); no_load.clear(); + DesignPartBeanMap.clear(); + processrules.clear(); + autotoolrules.clear(); + Tightenrules.clear(); + TightenMethodrules.clear(); + KCDSrules.clear(); + Torquerules.clear(); + times = 0; init(); } private void init() { @@ -177,69 +204,95 @@ public class AutoTransToolDialog extends AbstractAIFDialog { MessageBox.post(AutoTransToolDialog.this,"文件路径不存在", "Message", MessageBox.INFORMATION); return; } - if(isValidExcelColumn(idcol) && isValidExcelColumn(svppscol) && isValidExcelColumn(fcccol) - && isValidExcelColumn(fccdescol) && isValidExcelColumn(dongtaicol) && isValidExcelColumn(kcdscol)) { - op_nodesignmap.clear(); - no_load.clear(); - int idcol2 = columnToNumber(idcol.toUpperCase()); - int svppscol2 = columnToNumber(svppscol.toUpperCase()); - int fcccol2 = columnToNumber(fcccol.toUpperCase()); - int fccdescol2 = columnToNumber(fccdescol.toUpperCase()); - int dongtaicol2 = columnToNumber(dongtaicol.toUpperCase()); - int kcdscol2 = columnToNumber(kcdscol.toUpperCase()); - try { - //读取EXCEL - - //先处理选中对象层级有design的工序,获取没有design的工序 - opBOMLineData(target); - 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); - } - if(op_nodesignmap.size() > 0) { - System.out.println("整个结构没有匹配的紧固件"); + 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; + } + 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; + } + File excelfile = files[0]; + if(isValidExcelColumn(idcol) && isValidExcelColumn(svppscol) && isValidExcelColumn(fcccol) + && isValidExcelColumn(fccdescol) && isValidExcelColumn(dongtaicol) && isValidExcelColumn(kcdscol)) { + op_nodesignmap.clear(); + no_load.clear(); + DesignPartBeanMap.clear(); + int idcol2 = columnToNumber(idcol.toUpperCase()); + int svppscol2 = columnToNumber(svppscol.toUpperCase()); + int fcccol2 = columnToNumber(fcccol.toUpperCase()); + int fccdescol2 = columnToNumber(fccdescol.toUpperCase()); + int dongtaicol2 = columnToNumber(dongtaicol.toUpperCase()); + int kcdscol2 = columnToNumber(kcdscol.toUpperCase()); + Thread thread = new Thread(){ + public void run(){ + ProgressCustomDialog.lbStatus.setText("正在创建 ...."); + try { + //读取自定义的规则表 + if(times == 0) { + readRuleExcel(excelfile); + times = 1; + } + + //读取EXCEL + readExcel(excel,2,idcol2,svppscol2,fcccol2,fccdescol2,dongtaicol2,kcdscol2); + //先处理选中对象层级有design的工序,获取没有design的工序 + opBOMLineData(target); + 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); + } + if(op_nodesignmap.size() > 0) { + System.out.println("整个结构没有匹配的紧固件"); + } + } + + } catch (Exception e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } - } + }; + ProgressCustomDialog.show(thread, "执行中", null, null, null); - } catch (Exception e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); + AutoTransToolDialog.this.dispose(); + } + else { + MessageBox.post(AutoTransToolDialog.this,"请填写正确的列,比如A,B,C..", "Message", MessageBox.INFORMATION); + } - AutoTransToolDialog.this.dispose(); + } catch (TCException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); } - else { - MessageBox.post(AutoTransToolDialog.this,"请填写正确的列,比如A,B,C..", "Message", MessageBox.INFORMATION); - } - Thread thread = new Thread(){ - public void run(){ - ProgressCustomDialog.lbStatus.setText("正在创建 ...."); - - - } - }; - ProgressCustomDialog.show(thread, "执行中", null, null, null); + //session.queueOperation(operation); } @@ -282,7 +335,279 @@ public class AutoTransToolDialog extends AbstractAIFDialog { if(designchildcom instanceof TCComponentMfgBvrPart) { hasdesign = true; //获取design - + String designid = designchildcom.getProperty("bl_item_item_id"); + String newname = bl_rev_object_name.replaceAll("预紧", "") + .replaceAll("终紧", "") + .replaceAll("紧固", "") + .replaceAll("拧紧", ""); + String key = designid+"|"+newname; + System.out.println("看design是否匹配:"+key); + if(DesignPartBeanMap.containsKey(key)) { + System.out.println("找到匹配的,开始匹配规则"); + DesignPartBean bean = DesignPartBeanMap.get(key); + + //优先执行特殊工艺规则和电动工具新型号规则,若无匹配全量跑后续规则 + 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) { + 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) { + 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(); + } + } + 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(); + } + } + } + if(!autotoolrule) { + //拧紧性质规则 + 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) { + 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) { + 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(); + } + } + //KCDS + 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(); + } + } + //拧紧方式 + 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) { + 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) { + 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(); + } + } + //扭矩值 + + 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) { + 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) { + 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(); + } + } + } + } + else { + System.out.println("未找到匹配的"); + } } } if(!hasdesign) { @@ -397,7 +722,185 @@ public class AutoTransToolDialog extends AbstractAIFDialog { 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 + "|"+fccdes; + 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 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 diff --git a/com.sq.customization/src/com/sq/customization/handlers/SampleHandler.java b/com.sq.customization/src/com/sq/customization/handlers/SampleHandler.java index 3efc33e..13364d5 100644 --- a/com.sq.customization/src/com/sq/customization/handlers/SampleHandler.java +++ b/com.sq.customization/src/com/sq/customization/handlers/SampleHandler.java @@ -37,7 +37,7 @@ public class SampleHandler extends AbstractHandler { System.out.println(target[0].getType()); System.out.println(target[0].getClass()); if("Mfg0BvrPlantBOP".equals(target[0].getType()) || "Mfg0BvrProcessLine".equals(target[0].getType()) || "Mfg0BvrProcessStation".equals(target[0].getType())) { - new AutoTransToolDialog(app.getDesktop(),target[0]); + new AutoTransToolDialog(app.getDesktop(),target[0],session); // TCComponentMfgBvrPlantBOP targetline = (TCComponentMfgBvrPlantBOP) target[0]; // try { // AIFComponentContext[] comcontext = targetline.getChildren(); diff --git a/com.sq.customization/src/com/sq/customization/util/ConditionChecker.java b/com.sq.customization/src/com/sq/customization/util/ConditionChecker.java new file mode 100644 index 0000000..7e15344 --- /dev/null +++ b/com.sq.customization/src/com/sq/customization/util/ConditionChecker.java @@ -0,0 +1,201 @@ +package com.sq.customization.util; + +public class ConditionChecker { + + public static void main(String[] args) { + // 示例测试 1 + String condition1 = "%abc & ==5.0 & %xyz"; + String str1 = "This is abc xyz text"; + String range1 = "4.5-6.2"; + boolean result1 = checkCondition(condition1, str1, range1); + System.out.println("条件 1: " + (result1 ? "符合" : "不符合")); + + // 示例测试 2 + String condition2 = "(%text & >5.5 & <=10.0) | %xyz"; + String str2 = "This is text"; + String range2 = "7-8"; // 空字符串 + boolean result2 = checkCondition(condition2, str2, range2); + System.out.println("条件 2: " + (result2 ? "符合" : "不符合")); + + // 示例测试 3 + String condition3 = "<3.0 &=="; + String str3 = ""; + String range3 = ""; + boolean result3 = checkCondition(condition3, str3, range3); + System.out.println("条件 3: " + (result3 ? "符合" : "不符合")); + + // 示例测试 4 + String condition4 = "%abcg|%t"; + String str4 = "abc text"; + String range4 = ""; + boolean result4 = checkCondition(condition4, str4, range4); + System.out.println("条件 4: " + (result4 ? "符合" : "不符合")); + } + + /** + * 检查条件是否符合 + */ + public static boolean checkCondition(String condition, String str, String range) { + condition = condition.trim(); + + // 解析范围 + double[] rangeBounds = parseRange(range); + double min = rangeBounds != null ? rangeBounds[0] : Double.NaN; // 用 NaN 表示无效范围 + double max = rangeBounds != null ? rangeBounds[1] : Double.NaN; + + // 处理括号 + if (condition.startsWith("(")) { + int parenthesesLevel = 1; + int endIndex = -1; + for (int i = 1; i < condition.length(); i++) { + if (condition.charAt(i) == '(') parenthesesLevel++; + else if (condition.charAt(i) == ')') parenthesesLevel--; + if (parenthesesLevel == 0) { + endIndex = i; + break; + } + } + if (endIndex != -1 && endIndex == condition.length() - 1) { + return checkCondition(condition.substring(1, endIndex), str, range); + } + } + + // 处理多个 & 和 | 运算符 + int[] operatorIndices = findAllOuterOperators(condition); + if (operatorIndices.length > 0) { + String[] parts = splitCondition(condition, operatorIndices); + char[] operators = getOperators(condition, operatorIndices); + + boolean result = checkCondition(parts[0], str, range); + int partIndex = 1; + for (int i = 0; i < operators.length; i++) { + boolean nextResult = checkCondition(parts[partIndex++], str, range); + if (operators[i] == '&') { + result = result && nextResult; + } else if (operators[i] == '|') { + result = result || nextResult; + } + } + return result; + } + + // 处理单个条件 + return checkSingleCondition(condition, str, min, max); + } + + /** + * 解析范围字符串,支持小数 + */ + private static double[] parseRange(String range) { + if (range == null || range.isEmpty()) { + return null; // 空字符串返回 null,表示无有效范围 + } + try { + if (range.contains("-")) { + String[] parts = range.split("-"); + double start = Double.parseDouble(parts[0].trim()); + double end = Double.parseDouble(parts[1].trim()); + return new double[]{start, end}; + } else if (range.contains("±")) { + String[] parts = range.split("±"); + double center = Double.parseDouble(parts[0].trim()); + double delta = Double.parseDouble(parts[1].trim()); + return new double[]{center - delta, center + delta}; + } + } catch (NumberFormatException | ArrayIndexOutOfBoundsException e) { + throw new IllegalArgumentException("无效的范围格式: " + range + ",应为 'x-y' 或 'x±y'"); + } + return null; + } + + /** + * 查找所有最外层的 & 和 | 运算符 + */ + private static int[] findAllOuterOperators(String condition) { + int parenthesesLevel = 0; + java.util.List indices = new java.util.ArrayList<>(); + for (int i = 0; i < condition.length(); i++) { + char c = condition.charAt(i); + if (c == '(') parenthesesLevel++; + else if (c == ')') parenthesesLevel--; + else if (parenthesesLevel == 0 && (c == '&' || c == '|')) indices.add(i); + } + return indices.stream().mapToInt(Integer::intValue).toArray(); + } + + /** + * 根据运算符位置分割条件 + */ + private static String[] splitCondition(String condition, int[] operatorIndices) { + String[] parts = new String[operatorIndices.length + 1]; + int start = 0; + for (int i = 0; i < operatorIndices.length; i++) { + parts[i] = condition.substring(start, operatorIndices[i]).trim(); + start = operatorIndices[i] + 1; + } + parts[operatorIndices.length] = condition.substring(start).trim(); + return parts; + } + + /** + * 获取所有运算符 + */ + private static char[] getOperators(String condition, int[] operatorIndices) { + char[] operators = new char[operatorIndices.length]; + for (int i = 0; i < operatorIndices.length; i++) { + operators[i] = condition.charAt(operatorIndices[i]); + } + return operators; + } + + /** + * 检查单个条件,使用范围的最小值和最大值,支持小数 + */ + private static boolean checkSingleCondition(String condition, String str, double min, double max) { + condition = condition.trim(); + + if (condition.startsWith("!%")) { + String substring = condition.substring(2); + return !str.contains(substring); + } else if (condition.startsWith("%")) { + String substring = condition.substring(1); + return str.contains(substring); + } else if (condition.startsWith(">=")) { + if (Double.isNaN(min)) return false; // 空范围,不符合数字比较 + double value = Double.parseDouble(condition.substring(2)); + return min >= value; + } else if (condition.startsWith("<=")) { + if (Double.isNaN(max)) return false; // 空范围,不符合数字比较 + double value = Double.parseDouble(condition.substring(2)); + return max <= value; + } else if (condition.startsWith(">")) { + if (Double.isNaN(min)) return false; // 空范围,不符合数字比较 + double value = Double.parseDouble(condition.substring(1)); + return min > value; + } else if (condition.startsWith("<")) { + if (Double.isNaN(max)) return false; // 空范围,不符合数字比较 + double value = Double.parseDouble(condition.substring(1)); + return max < value; + } else if (condition.startsWith("==")) { + String operand = condition.substring(2); + try { + if (Double.isNaN(min) || Double.isNaN(max)) return false; // 空范围,不符合数字比较 + double value = Double.parseDouble(operand); + return min == value && max == value; + } catch (NumberFormatException e) { + return str.equals(operand); + } + } else if (condition.startsWith("!=")) { + String operand = condition.substring(2); + try { + if (Double.isNaN(min) || Double.isNaN(max)) return false; // 空范围,不符合数字比较 + double value = Double.parseDouble(operand); + return min != value || max != value; + } catch (NumberFormatException e) { + return !str.equals(operand); + } + } + + return false; + } +} diff --git a/com.sq.customization/src/com/sq/customization/util/StringConditionChecker.java b/com.sq.customization/src/com/sq/customization/util/StringConditionChecker.java new file mode 100644 index 0000000..7e91477 --- /dev/null +++ b/com.sq.customization/src/com/sq/customization/util/StringConditionChecker.java @@ -0,0 +1,122 @@ +package com.sq.customization.util; + +public class StringConditionChecker { + + public static void main(String[] args) { + // 示例测试 + String condition = "%abc & !=def | (%xyz & ==abc)"; // 条件示例 + String str = "This is abc text"; // 目标字符串 + boolean result = checkCondition(condition, str); + System.out.println(result ? "条件符合" : "条件不符合"); + } + + /** + * 检查条件是否符合 + * @param condition 条件字符串 + * @param str 目标字符串 + * @return 是否符合条件 + */ + public static boolean checkCondition(String condition, String str) { + condition = condition.trim(); // 去掉首尾空格 + + // 处理括号 + if (condition.startsWith("(") && condition.endsWith(")")) { + return checkCondition(condition.substring(1, condition.length() - 1), str); + } + + // 处理多个 & 和 | 运算符 + int[] operatorIndices = findAllOuterOperators(condition); + if (operatorIndices.length > 0) { + String[] parts = splitCondition(condition, operatorIndices); + char[] operators = getOperators(condition, operatorIndices); + + boolean result = checkCondition(parts[0], str); + int partIndex = 1; + for (int i = 0; i < operators.length; i++) { + boolean nextResult = checkCondition(parts[partIndex++], str); + if (operators[i] == '&') { + result = result && nextResult; + } else if (operators[i] == '|') { + result = result || nextResult; + } + } + return result; + } + + // 处理单个条件 + return checkSingleCondition(condition, str); + } + + /** + * 查找所有最外层的 & 和 | 运算符 + */ + private static int[] findAllOuterOperators(String condition) { + int parenthesesLevel = 0; + java.util.List indices = new java.util.ArrayList<>(); + for (int i = 0; i < condition.length(); i++) { + char c = condition.charAt(i); + if (c == '(') { + parenthesesLevel++; + } else if (c == ')') { + parenthesesLevel--; + } else if (parenthesesLevel == 0 && (c == '&' || c == '|')) { + indices.add(i); + } + } + int[] result = new int[indices.size()]; + for (int i = 0; i < indices.size(); i++) { + result[i] = indices.get(i); + } + return result; + } + + /** + * 根据运算符位置分割条件 + */ + private static String[] splitCondition(String condition, int[] operatorIndices) { + String[] parts = new String[operatorIndices.length + 1]; + int start = 0; + for (int i = 0; i < operatorIndices.length; i++) { + parts[i] = condition.substring(start, operatorIndices[i]).trim(); + start = operatorIndices[i] + 1; + } + parts[operatorIndices.length] = condition.substring(start).trim(); + return parts; + } + + /** + * 获取所有运算符 + */ + private static char[] getOperators(String condition, int[] operatorIndices) { + char[] operators = new char[operatorIndices.length]; + for (int i = 0; i < operatorIndices.length; i++) { + operators[i] = condition.charAt(operatorIndices[i]); + } + return operators; + } + + /** + * 检查单个条件 + */ + private static boolean checkSingleCondition(String condition, String str) { + condition = condition.trim(); + + // 从长到短检查运算符,避免冲突 + if (condition.startsWith("!%")) { + String substring = condition.substring(2); + return !str.contains(substring); // 不包含 + } else if (condition.startsWith("%")) { + String substring = condition.substring(1); + return str.contains(substring); // 包含 + } else if (condition.startsWith("==")) { + String operand = condition.substring(2); + return str.equals(operand); // 等于 + } else if (condition.startsWith("!=")) { + String operand = condition.substring(2); + return !str.equals(operand); // 不等于 + } + + return false; // 未识别的条件返回 false + } +} + diff --git a/特殊工艺规则配置2.xlsx b/特殊工艺规则配置2.xlsx new file mode 100644 index 0000000..0fd39f1 Binary files /dev/null and b/特殊工艺规则配置2.xlsx differ