diff --git a/com.sq.customization/.classpath b/com.sq.customization/.classpath index eca7bdb..de52b6b 100644 --- a/com.sq.customization/.classpath +++ b/com.sq.customization/.classpath @@ -3,5 +3,20 @@ + + + + + + + + + + + + + + + diff --git a/com.sq.customization/META-INF/MANIFEST.MF b/com.sq.customization/META-INF/MANIFEST.MF index 7694063..ba0eb33 100644 --- a/com.sq.customization/META-INF/MANIFEST.MF +++ b/com.sq.customization/META-INF/MANIFEST.MF @@ -19,8 +19,23 @@ Require-Bundle: org.eclipse.ui, com.teamcenter.rac.util;bundle-version="13000.3.0", com.teamcenter.rac.pca.kernel;bundle-version="13000.3.0", com.teamcenter.rac.pse.pca;bundle-version="13000.3.0", - com.teamcenter.rac.cme.kernel;bundle-version="13000.3.0", - org.apache.poi.39;bundle-version="3.9.0" + com.teamcenter.rac.cme.kernel;bundle-version="13000.3.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Automatic-Module-Name: com.sq.customization Bundle-ActivationPolicy: lazy +Bundle-ClassPath: lib/cglib-3.3.0.jar, + lib/commons-collections4-4.1.jar, + lib/easyexcel-3.2.0.jar, + lib/easyexcel-core-3.2.0.jar, + lib/easyexcel-support-3.2.0.jar, + lib/poi-3.17.jar, + lib/poi-examples-3.17.jar, + lib/poi-excelant-3.17.jar, + lib/poi-ooxml-3.17.jar, + lib/poi-ooxml-schemas-3.17.jar, + lib/poi-scratchpad-3.17.jar, + lib/serializer-2.7.2.jar, + lib/slf4j-api-1.7.5.jar, + lib/xalan-2.7.2.jar, + lib/xml-apis-1.4.01.jar, + lib/xmlbeans-2.6.0.jar diff --git a/com.sq.customization/build.properties b/com.sq.customization/build.properties index f3f7e80..2cf1c63 100644 --- a/com.sq.customization/build.properties +++ b/com.sq.customization/build.properties @@ -1,7 +1,21 @@ -source.. = src/ output.. = bin/ javacDefaultEncoding.. = UTF-8 bin.includes = plugin.xml,\ META-INF/,\ - .,\ - icons/ + icons/,\ + lib/cglib-3.3.0.jar,\ + lib/commons-collections4-4.1.jar,\ + lib/easyexcel-3.2.0.jar,\ + lib/easyexcel-core-3.2.0.jar,\ + lib/easyexcel-support-3.2.0.jar,\ + lib/poi-3.17.jar,\ + lib/poi-examples-3.17.jar,\ + lib/poi-excelant-3.17.jar,\ + lib/poi-ooxml-3.17.jar,\ + lib/poi-ooxml-schemas-3.17.jar,\ + lib/poi-scratchpad-3.17.jar,\ + lib/serializer-2.7.2.jar,\ + lib/slf4j-api-1.7.5.jar,\ + lib/xalan-2.7.2.jar,\ + lib/xml-apis-1.4.01.jar,\ + lib/xmlbeans-2.6.0.jar diff --git a/com.sq.customization/lib/cglib-3.3.0.jar b/com.sq.customization/lib/cglib-3.3.0.jar new file mode 100644 index 0000000..ed830f4 Binary files /dev/null and b/com.sq.customization/lib/cglib-3.3.0.jar differ diff --git a/com.sq.customization/lib/commons-collections4-4.1.jar b/com.sq.customization/lib/commons-collections4-4.1.jar new file mode 100644 index 0000000..43a9413 Binary files /dev/null and b/com.sq.customization/lib/commons-collections4-4.1.jar differ diff --git a/com.sq.customization/lib/easyexcel-3.2.0.jar b/com.sq.customization/lib/easyexcel-3.2.0.jar new file mode 100644 index 0000000..96f44f9 Binary files /dev/null and b/com.sq.customization/lib/easyexcel-3.2.0.jar differ diff --git a/com.sq.customization/lib/easyexcel-core-3.2.0.jar b/com.sq.customization/lib/easyexcel-core-3.2.0.jar new file mode 100644 index 0000000..c7d327e Binary files /dev/null and b/com.sq.customization/lib/easyexcel-core-3.2.0.jar differ diff --git a/com.sq.customization/lib/easyexcel-support-3.2.0.jar b/com.sq.customization/lib/easyexcel-support-3.2.0.jar new file mode 100644 index 0000000..f298973 Binary files /dev/null and b/com.sq.customization/lib/easyexcel-support-3.2.0.jar differ diff --git a/com.sq.customization/lib/poi-3.17.jar b/com.sq.customization/lib/poi-3.17.jar new file mode 100644 index 0000000..353ce76 Binary files /dev/null and b/com.sq.customization/lib/poi-3.17.jar differ diff --git a/com.sq.customization/lib/poi-examples-3.17.jar b/com.sq.customization/lib/poi-examples-3.17.jar new file mode 100644 index 0000000..a923b04 Binary files /dev/null and b/com.sq.customization/lib/poi-examples-3.17.jar differ diff --git a/com.sq.customization/lib/poi-excelant-3.17.jar b/com.sq.customization/lib/poi-excelant-3.17.jar new file mode 100644 index 0000000..da9f5ed Binary files /dev/null and b/com.sq.customization/lib/poi-excelant-3.17.jar differ diff --git a/com.sq.customization/lib/poi-ooxml-3.17.jar b/com.sq.customization/lib/poi-ooxml-3.17.jar new file mode 100644 index 0000000..68086e8 Binary files /dev/null and b/com.sq.customization/lib/poi-ooxml-3.17.jar differ diff --git a/com.sq.customization/lib/poi-ooxml-schemas-3.17.jar b/com.sq.customization/lib/poi-ooxml-schemas-3.17.jar new file mode 100644 index 0000000..2e9b3e7 Binary files /dev/null and b/com.sq.customization/lib/poi-ooxml-schemas-3.17.jar differ diff --git a/com.sq.customization/lib/poi-scratchpad-3.17.jar b/com.sq.customization/lib/poi-scratchpad-3.17.jar new file mode 100644 index 0000000..12ba1f1 Binary files /dev/null and b/com.sq.customization/lib/poi-scratchpad-3.17.jar differ diff --git a/com.sq.customization/lib/serializer-2.7.2.jar b/com.sq.customization/lib/serializer-2.7.2.jar new file mode 100644 index 0000000..10c881c Binary files /dev/null and b/com.sq.customization/lib/serializer-2.7.2.jar differ diff --git a/com.sq.customization/lib/slf4j-api-1.7.5.jar b/com.sq.customization/lib/slf4j-api-1.7.5.jar new file mode 100644 index 0000000..8f004d3 Binary files /dev/null and b/com.sq.customization/lib/slf4j-api-1.7.5.jar differ diff --git a/com.sq.customization/lib/xalan-2.7.2.jar b/com.sq.customization/lib/xalan-2.7.2.jar new file mode 100644 index 0000000..abdabe3 Binary files /dev/null and b/com.sq.customization/lib/xalan-2.7.2.jar differ diff --git a/com.sq.customization/lib/xml-apis-1.4.01.jar b/com.sq.customization/lib/xml-apis-1.4.01.jar new file mode 100644 index 0000000..4673346 Binary files /dev/null and b/com.sq.customization/lib/xml-apis-1.4.01.jar differ diff --git a/com.sq.customization/lib/xmlbeans-2.6.0.jar b/com.sq.customization/lib/xmlbeans-2.6.0.jar new file mode 100644 index 0000000..d1b6627 Binary files /dev/null and b/com.sq.customization/lib/xmlbeans-2.6.0.jar differ diff --git a/com.sq.customization/src/com/sq/customization/bean/ExcelBean.java b/com.sq.customization/src/com/sq/customization/bean/ExcelBean.java new file mode 100644 index 0000000..6464d16 --- /dev/null +++ b/com.sq.customization/src/com/sq/customization/bean/ExcelBean.java @@ -0,0 +1,140 @@ +package com.sq.customization.bean; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import org.apache.poi.EncryptedDocumentException; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +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.ss.usermodel.WorkbookFactory; + +import com.alibaba.excel.EasyExcel; +import com.alibaba.excel.annotation.ExcelProperty; +import com.sq.customization.util.ExcelUtil; + +public class ExcelBean { + @ExcelProperty("工序信息") + private String bl_indented_title; + @ExcelProperty("紧固件号") + private String item_id; + @ExcelProperty("SSVPPS") + private String SSVPPS; + @ExcelProperty("FCC") + private String FCC; + @ExcelProperty("动态扭矩") + private String dongtai; + @ExcelProperty("KCDS") + private String KCDS; + @ExcelProperty("头部形式") + private String headForm; + @ExcelProperty("头部尺寸") + private String headSize; + @ExcelProperty("工具组合") + private String alltool; + @ExcelProperty("工具") + private String SleeveResourceType; + @ExcelProperty("套筒") + private String ToolResourceType; + + public ExcelBean() {} + + public ExcelBean(String bl_indented_title, String item_id, String SSVPPS, String FCC, String dongtai, + String KCDS, String headForm, String headSize, String alltool, String SleeveResourceType, + String ToolResourceType) { + this.bl_indented_title = bl_indented_title; + this.item_id = item_id; + this.SSVPPS = SSVPPS; + this.FCC = FCC; + this.dongtai = dongtai; + this.KCDS = KCDS; + this.headForm = headForm; + this.headSize = headSize; + this.alltool = alltool; + this.SleeveResourceType = SleeveResourceType; + this.ToolResourceType = ToolResourceType; + } + + // Getter 和 Setter(保持不变,省略以节省篇幅) + + public static void main(String[] args) { + List data = Arrays.asList( + new ExcelBean("工序1", "ID001", "SSVPPS1", "FCC1", "动态1", "KCDS1", "圆头", "10mm", "工具A", "工具类型1", "套筒1"), + new ExcelBean("工序2", "ID002", "SSVPPS2", "FCC2", "动态2", "KCDS2", "平头", "12mm", "工具B", "工具类型2", "套筒2") + ); + + String fileName = "C:\\Users\\TEMP.CNSHI6P1090.000.001.002.003.004.005.006\\Desktop\\新建文件夹\\cust_rule_data.xlsx"; // 修改为可写路径 + try (FileOutputStream fos = new FileOutputStream(fileName)) { + EasyExcel.write(fos, ExcelBean.class) + .sheet("Sheet1") + .doWrite(data); + System.out.println("数据已成功导出到 " + fileName); + } catch (Exception e) { + System.err.println("导出失败: " + e.getMessage()); + e.printStackTrace(); // 打印详细异常信息 + } +// String filePath = "C:\\Users\\YourName\\Desktop\\cust_rule_data.xlsx"; // 替换为你的 Excel 文件路径 + + try (FileInputStream fis = new FileInputStream(fileName)) { + // 使用 WorkbookFactory 自动适配 .xls 和 .xlsx + Workbook workbook = WorkbookFactory.create(fis); + + // 获取第一个工作表(Sheet1) + Sheet sheet = workbook.getSheetAt(0); // 或使用 getSheet("Sheet1") 指定名称 + + // 遍历所有行 + for (Row row : sheet) { + // 遍历每行中的单元格 + for (Cell cell : row) { + // 根据单元格类型读取数据 + String value = ExcelUtil.getStringCellValue(cell); + System.out.println(value); + } + System.out.println(); // 每行结束后换行 + } + + // 关闭工作簿 + workbook.close(); + System.out.println("Excel 文件读取完成"); + + } catch (IOException e) { + System.err.println("读取 Excel 失败: " + e.getMessage()); + e.printStackTrace(); + } catch (EncryptedDocumentException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InvalidFormatException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + // Getter 和 Setter(以下为完整代码,之前省略的部分) + public String getBl_indented_title() { return bl_indented_title; } + public void setBl_indented_title(String bl_indented_title) { this.bl_indented_title = bl_indented_title; } + public String getItem_id() { return item_id; } + public void setItem_id(String item_id) { this.item_id = item_id; } + public String getSSVPPS() { return SSVPPS; } + public void setSSVPPS(String SSVPPS) { this.SSVPPS = SSVPPS; } + public String getFCC() { return FCC; } + public void setFCC(String FCC) { this.FCC = FCC; } + public String getDongtai() { return dongtai; } + public void setDongtai(String dongtai) { this.dongtai = dongtai; } + public String getKCDS() { return KCDS; } + public void setKCDS(String KCDS) { this.KCDS = KCDS; } + public String getHeadForm() { return headForm; } + public void setHeadForm(String headForm) { this.headForm = headForm; } + public String getHeadSize() { return headSize; } + public void setHeadSize(String headSize) { this.headSize = headSize; } + public String getAlltool() { return alltool; } + public void setAlltool(String alltool) { this.alltool = alltool; } + public String getSleeveResourceType() { return SleeveResourceType; } + public void setSleeveResourceType(String SleeveResourceType) { this.SleeveResourceType = SleeveResourceType; } + public String getToolResourceType() { return ToolResourceType; } + public void setToolResourceType(String ToolResourceType) { this.ToolResourceType = ToolResourceType; } +} diff --git a/com.sq.customization/src/com/sq/customization/bean/SleeveBean.java b/com.sq.customization/src/com/sq/customization/bean/SleeveBean.java new file mode 100644 index 0000000..1bf8b2b --- /dev/null +++ b/com.sq.customization/src/com/sq/customization/bean/SleeveBean.java @@ -0,0 +1,39 @@ +package com.sq.customization.bean; + +public class SleeveBean { + private String resourceType; + private String inputSize; + private String outSize; + private String length; + private String headform; + public String getResourceType() { + return resourceType; + } + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + public String getInputSize() { + return inputSize; + } + public void setInputSize(String inputSize) { + this.inputSize = inputSize; + } + public String getOutSize() { + return outSize; + } + public void setOutSize(String outSize) { + this.outSize = outSize; + } + public String getLength() { + return length; + } + public void setLength(String length) { + this.length = length; + } + public String getHeadform() { + return headform; + } + public void setHeadform(String headform) { + this.headform = headform; + } +} diff --git a/com.sq.customization/src/com/sq/customization/bean/StandardPartBean.java b/com.sq.customization/src/com/sq/customization/bean/StandardPartBean.java new file mode 100644 index 0000000..869e01b --- /dev/null +++ b/com.sq.customization/src/com/sq/customization/bean/StandardPartBean.java @@ -0,0 +1,32 @@ +package com.sq.customization.bean; + +public class StandardPartBean { + private String specification; + private String length; + private String headform; + private String headsize; + public String getSpecification() { + return specification; + } + public void setSpecification(String specification) { + this.specification = specification; + } + public String getLength() { + return length; + } + public void setLength(String length) { + this.length = length; + } + public String getHeadform() { + return headform; + } + public void setHeadform(String headform) { + this.headform = headform; + } + public String getHeadsize() { + return headsize; + } + public void setHeadsize(String headsize) { + this.headsize = headsize; + } +} diff --git a/com.sq.customization/src/com/sq/customization/bean/ToolBean.java b/com.sq.customization/src/com/sq/customization/bean/ToolBean.java new file mode 100644 index 0000000..ce18f25 --- /dev/null +++ b/com.sq.customization/src/com/sq/customization/bean/ToolBean.java @@ -0,0 +1,32 @@ +package com.sq.customization.bean; + +public class ToolBean { + private String resourceType; + private String resourceName; + private String range;//扭矩范围 + private String outSize; + public String getResourceType() { + return resourceType; + } + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + public String getResourceName() { + return resourceName; + } + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + public String getRange() { + return range; + } + public void setRange(String range) { + this.range = range; + } + public String getOutSize() { + return outSize; + } + public void setOutSize(String outSize) { + this.outSize = outSize; + } +} 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 d1cfbfe..65f75f4 100644 --- a/com.sq.customization/src/com/sq/customization/dialogs/AutoTransToolDialog.java +++ b/com.sq.customization/src/com/sq/customization/dialogs/AutoTransToolDialog.java @@ -30,9 +30,15 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; 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.teamcenter.rac.aif.AbstractAIFDialog; import com.teamcenter.rac.aif.kernel.AIFComponentContext; @@ -79,6 +85,12 @@ public class AutoTransToolDialog extends AbstractAIFDialog { 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; public AutoTransToolDialog(Frame fm,InterfaceAIFComponent target,TCSession session) { super(fm); @@ -93,6 +105,7 @@ public class AutoTransToolDialog extends AbstractAIFDialog { TightenMethodrules.clear(); KCDSrules.clear(); Torquerules.clear(); + eleTool.clear(); times = 0; init(); } @@ -209,6 +222,42 @@ public class AutoTransToolDialog extends AbstractAIFDialog { 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"); @@ -216,7 +265,50 @@ public class AutoTransToolDialog extends AbstractAIFDialog { 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; + } + File excelfile = files[0]; + File electricfile = cust_electric_excelfiles[0]; + File batteryfile = cust_battery_exceldatasetfiles[0]; + File pneumaticfile = cust_pneumatic_excelfiles[0]; + File manualfile = cust_manual_excelfiles[0]; + File standardpartfile = cust_standardpart_excelfiles[0]; + File sleevefile = cust_sleeve_excelfiles[0]; if(isValidExcelColumn(idcol) && isValidExcelColumn(svppscol) && isValidExcelColumn(fcccol) && isValidExcelColumn(fccdescol) && isValidExcelColumn(dongtaicol) && isValidExcelColumn(kcdscol)) { op_nodesignmap.clear(); @@ -232,15 +324,23 @@ public class AutoTransToolDialog extends AbstractAIFDialog { public void run(){ ProgressCustomDialog.lbStatus.setText("正在创建 ...."); try { - //读取自定义的规则表 + //读取自定义的表 if(times == 0) { readRuleExcel(excelfile); + readElectricfile(electricfile,1); + readbatteryfile(batteryfile,1); + readpneumaticfile(pneumaticfile,1); + readmanualfile(manualfile,1); + readstdPartfile(standardpartfile,1); + readsleevefile(sleevefile,1); times = 1; } //读取EXCEL readExcel(excel,2,idcol2,svppscol2,fcccol2,fccdescol2,dongtaicol2,kcdscol2); //先处理选中对象层级有design的工序,获取没有design的工序 + + opBOMLineData(target); if(op_nodesignmap.size() > 0) { TCComponentBOMLine parent = null; @@ -334,6 +434,8 @@ public class AutoTransToolDialog extends AbstractAIFDialog { InterfaceAIFComponent designchildcom = designchild.getComponent(); if(designchildcom instanceof TCComponentMfgBvrPart) { hasdesign = true; + //获取符合的数据 + Map> Tool = new HashMap<>(); //获取design String designid = designchildcom.getProperty("bl_item_item_id"); String newname = bl_rev_object_name.replaceAll("预紧", "") @@ -345,6 +447,16 @@ public class AutoTransToolDialog extends AbstractAIFDialog { if(DesignPartBeanMap.containsKey(key)) { System.out.println("找到匹配的,开始匹配规则"); DesignPartBean bean = DesignPartBeanMap.get(key); + 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]; + } + } + } //优先执行特殊工艺规则和电动工具新型号规则,若无匹配全量跑后续规则 boolean processrule = false; @@ -363,13 +475,14 @@ public class AutoTransToolDialog extends AbstractAIFDialog { 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) { + niuju = split[0]; boolean result = ConditionChecker.checkCondition(rule_dongtai, split[1], split[0]); if(!result) is_ok = false; @@ -399,6 +512,45 @@ public class AutoTransToolDialog extends AbstractAIFDialog { //获取资源名称 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; @@ -431,10 +583,46 @@ public class AutoTransToolDialog extends AbstractAIFDialog { //获取资源类型 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 excelname = new HashMap<>(); //拧紧性质规则 for(int i = 0; i< Tightenrules.size(); i++) { CustRuleBean rulebean = Tightenrules.get(i); @@ -454,7 +642,7 @@ public class AutoTransToolDialog extends AbstractAIFDialog { } 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); @@ -479,6 +667,19 @@ public class AutoTransToolDialog extends AbstractAIFDialog { if(is_ok) { //获取资源名称 String resourceType = rulebean.getResourceType(); + if(resourceType != null && resourceType.length() > 0) { + String[] res = resourceType.split("\\|", -1); + for(String re:res) { + if(excelname.containsKey(re)) { + int count = excelname.get(re); + excelname.put(re, count+1); + } + else { + excelname.put(re, 1); + } + + } + } } } //KCDS @@ -507,6 +708,19 @@ public class AutoTransToolDialog extends AbstractAIFDialog { if(is_ok) { //获取资源类型 String resourceType = rulebean.getResourceType(); + if(resourceType != null && resourceType.length() > 0) { + String[] res = resourceType.split("\\|", -1); + for(String re:res) { + if(excelname.containsKey(re)) { + int count = excelname.get(re); + excelname.put(re, count+1); + } + else { + excelname.put(re, 1); + } + + } + } } } //拧紧方式 @@ -528,7 +742,6 @@ public class AutoTransToolDialog extends AbstractAIFDialog { } 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); @@ -553,6 +766,19 @@ public class AutoTransToolDialog extends AbstractAIFDialog { if(is_ok) { //获取资源类型 String resourceType = rulebean.getResourceType(); + if(resourceType != null && resourceType.length() > 0) { + String[] res = resourceType.split("\\|", -1); + for(String re:res) { + if(excelname.containsKey(re)) { + int count = excelname.get(re); + excelname.put(re, count+1); + } + else { + excelname.put(re, 1); + } + + } + } } } //扭矩值 @@ -575,7 +801,6 @@ public class AutoTransToolDialog extends AbstractAIFDialog { } 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); @@ -601,8 +826,179 @@ public class AutoTransToolDialog extends AbstractAIFDialog { //获取资源类型 String resourceType = rulebean.getResourceType(); String resourceName = rulebean.getResourceName(); + if(resourceType != null && resourceType.length() > 0) { + String[] res = resourceType.split("\\|", -1); + for(String re:res) { + if(excelname.containsKey(re)) { + int count = excelname.get(re); + excelname.put(re, count+1); + } + else { + excelname.put(re, 1); + } + + } + } + } + } + + //读取工具excel数据 + for(String name:excelname.keySet()) { + 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(); + 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); + } + } + } + } + else if("手动工具".equals(name)){ + for(String resourceType:eleTool.keySet()) { + List toolbeans = eleTool.get(resourceType); + 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(); + 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); + } + } + } + } + else if("电池工具".equals(name)){ + for(String resourceType:batteryTool.keySet()) { + List toolbeans = batteryTool.get(resourceType); + for(ToolBean toolbean:toolbeans) { + String range = toolbean.getRange(); + String outSize = toolbean.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(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("匹配标准件designid:"+designid); + if(StandardPartMap.containsKey(designid)) { + StandardPartBean stdbean = StandardPartMap.get(designid); + String headform = stdbean.getHeadform(); + String headsize = stdbean.getHeadsize(); + String key2 = headsize+"|"+headform; + System.out.println("寻找套筒 头部尺寸|头部形式:"+key2); + if(SleeveMap.containsKey(key2)) { + System.out.println("找到匹配"); + List SleeveBeans = SleeveMap.get(key2); + for(SleeveBean sleevebean:SleeveBeans) { + String inputsize = sleevebean.getInputSize(); + String length = sleevebean.getLength(); + String resourceType = sleevebean.getResourceType(); + //后续工具与套筒匹配 + for(String resourcetype:Tool.keySet()) { + List toolsbean = Tool.get(resourcetype); + 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); + } + } + else if((outsize == null || outsize.length() == 0) && (inputsize == null || inputsize.length() == 0)){ + System.out.println("工具匹配上套筒,工具的输出尺寸:"+outsize+" 套筒输入尺寸:"+inputsize+" 长度:"+length +" 资源类型:"+resourceType); + } + } + } } } + else + System.out.println("没有找到匹配"); } } else { @@ -669,7 +1065,576 @@ public class AutoTransToolDialog extends AbstractAIFDialog { if(designchildcom instanceof TCComponentMfgBvrPart) { hasdesign = true; //获取design - + //获取符合的数据 + Map> Tool = new HashMap<>(); + //获取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); + 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]; + } + } + } + + //优先执行特殊工艺规则和电动工具新型号规则,若无匹配全量跑后续规则 + 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 excelname = 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(excelname.containsKey(re)) { + int count = excelname.get(re); + excelname.put(re, count+1); + } + else { + excelname.put(re, 1); + } + + } + } + } + } + //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(); + if(resourceType != null && resourceType.length() > 0) { + String[] res = resourceType.split("\\|", -1); + for(String re:res) { + if(excelname.containsKey(re)) { + int count = excelname.get(re); + excelname.put(re, count+1); + } + else { + excelname.put(re, 1); + } + + } + } + } + } + //拧紧方式 + 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(excelname.containsKey(re)) { + int count = excelname.get(re); + excelname.put(re, count+1); + } + else { + excelname.put(re, 1); + } + + } + } + } + } + //扭矩值 + + 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(excelname.containsKey(re)) { + int count = excelname.get(re); + excelname.put(re, count+1); + } + else { + excelname.put(re, 1); + } + + } + } + } + } + + //读取工具excel数据 + for(String name:excelname.keySet()) { + 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(); + 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); + } + } + } + } + else if("手动工具".equals(name)){ + for(String resourceType:eleTool.keySet()) { + List toolbeans = eleTool.get(resourceType); + 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(); + 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); + } + } + } + } + else if("电池工具".equals(name)){ + for(String resourceType:batteryTool.keySet()) { + List toolbeans = batteryTool.get(resourceType); + for(ToolBean toolbean:toolbeans) { + String range = toolbean.getRange(); + String outSize = toolbean.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(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("匹配标准件designid:"+designid); + if(StandardPartMap.containsKey(designid)) { + StandardPartBean stdbean = StandardPartMap.get(designid); + String headform = stdbean.getHeadform(); + String headsize = stdbean.getHeadsize(); + String key2 = headsize+"|"+headform; + System.out.println("寻找套筒 头部尺寸|头部形式:"+key2); + if(SleeveMap.containsKey(key2)) { + System.out.println("找到匹配"); + List SleeveBeans = SleeveMap.get(key2); + for(SleeveBean sleevebean:SleeveBeans) { + String inputsize = sleevebean.getInputSize(); + String length = sleevebean.getLength(); + String resourceType = sleevebean.getResourceType(); + //后续工具与套筒匹配 + for(String resourcetype:Tool.keySet()) { + List toolsbean = Tool.get(resourcetype); + 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); + } + } + else if((outsize == null || outsize.length() == 0) && (inputsize == null || inputsize.length() == 0)){ + System.out.println("工具匹配上套筒,工具的输出尺寸:"+outsize+" 套筒输入尺寸:"+inputsize+" 长度:"+length +" 资源类型:"+resourceType); + } + } + } + } + } + else + System.out.println("没有找到匹配"); + } + } + else { + System.out.println("未找到匹配的"); + } } } if(hasdesign) { @@ -701,7 +1666,7 @@ public class AutoTransToolDialog extends AbstractAIFDialog { } } - + //读取BOM表 private void readExcel(File excelfile,int start_rownum,int idcol2,int svppscol2,int fcccol2 ,int fccdescol2,int dongtaicol,int kcdscol2) { Workbook work = null; @@ -741,6 +1706,7 @@ public class AutoTransToolDialog extends AbstractAIFDialog { e.printStackTrace(); } } + //读取规则表 private void readRuleExcel(File excelfile) { Workbook work = null; try(InputStream is = new FileInputStream(excelfile);){ @@ -910,4 +1876,244 @@ public class AutoTransToolDialog extends AbstractAIFDialog { 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)); + + if(ResourceType != null && ResourceType.length() > 0) { + // 使用 computeIfAbsent 简化操作 + ToolBean tool = new ToolBean(); + tool.setOutSize(outSize); + tool.setRange(Torque); + 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(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 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(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 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(); + 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) { + // 使用 computeIfAbsent 简化操作 + SleeveBean tool = new SleeveBean(); + tool.setResourceType(resourceType); + tool.setLength(length); + tool.setHeadform(headform); + tool.setInputSize(inputSize); + tool.setOutSize(outSize); + + SleeveMap.computeIfAbsent(outSize+"|"+headform, key -> new ArrayList<>()).add(tool); + + } + else { + break; + } + + } + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff --git a/com.sq.customization/src/com/sq/customization/util/ConditionChecker.java b/com.sq.customization/src/com/sq/customization/util/ConditionChecker.java index 7e15344..25e20ae 100644 --- a/com.sq.customization/src/com/sq/customization/util/ConditionChecker.java +++ b/com.sq.customization/src/com/sq/customization/util/ConditionChecker.java @@ -18,9 +18,9 @@ public class ConditionChecker { System.out.println("条件 2: " + (result2 ? "符合" : "不符合")); // 示例测试 3 - String condition3 = "<3.0 &=="; + String condition3 = "<5.0"; String str3 = ""; - String range3 = ""; + String range3 = "4±1.5"; boolean result3 = checkCondition(condition3, str3, range3); System.out.println("条件 3: " + (result3 ? "符合" : "不符合")); diff --git a/com.sq.customization/src/com/sq/customization/util/RangChecker.java b/com.sq.customization/src/com/sq/customization/util/RangChecker.java new file mode 100644 index 0000000..1ffc069 --- /dev/null +++ b/com.sq.customization/src/com/sq/customization/util/RangChecker.java @@ -0,0 +1,77 @@ +package com.sq.customization.util; + +public class RangChecker { + // 解析范围并返回 [min, max] 数组 + private static double[] parseRange(String range) { + if (range == null || range.trim().isEmpty()) { + return null; + } + + double minValue, maxValue; + + if (range.contains("±")) { + // 处理 "3±1" 格式 + String[] parts = range.split("±"); + if (parts.length != 2) { + return null; + } + try { + double center = Double.parseDouble(parts[0].trim()); + double offset = Double.parseDouble(parts[1].trim()); + minValue = center - offset; + maxValue = center + offset; + } catch (NumberFormatException e) { + return null; + } + } else if (range.contains("-")) { + // 处理 "1-4" 格式 + String[] parts = range.split("-"); + String minStr = parts.length > 0 ? parts[0].trim() : ""; + String maxStr = parts.length > 1 ? parts[1].trim() : ""; + + try { + minValue = minStr.isEmpty() ? Double.NEGATIVE_INFINITY : Double.parseDouble(minStr); + maxValue = maxStr.isEmpty() ? Double.POSITIVE_INFINITY : Double.parseDouble(maxStr); + } catch (NumberFormatException e) { + return null; + } + } else { + return null; + } + + return new double[]{minValue, maxValue}; + } + + // 判断 inputRange 是否在 targetRange 内 + public static boolean isWithinRange(String inputRange, String targetRange) { + // 解析输入范围 + double[] input = parseRange(inputRange); + if (input == null) { + return false; // 输入范围无效 + } + double inputMin = input[0]; + double inputMax = input[1]; + + // 解析目标范围 + double[] target = parseRange(targetRange); + if (target == null) { + return false; // 目标范围无效 + } + double targetMin = target[0]; + double targetMax = target[1]; + + // 判断输入范围是否完全在目标范围内 + return inputMin >= targetMin && inputMax <= targetMax; + } + + public static void main(String[] args) { + // 测试用例 + String targetRange = "2-5.5"; // 动态目标范围 + String[] inputRanges = {"1-4.4", "3±1", "2-5.6", "6-7", "1-", "-4", "2-6"}; + + for (String input : inputRanges) { + System.out.println("Input: " + input + " -> Within " + targetRange + ": " + + isWithinRange(input, targetRange)); + } + } +} diff --git a/com.sq.customization/src/com/sq/customization/util/RangeAdjuster.java b/com.sq.customization/src/com/sq/customization/util/RangeAdjuster.java new file mode 100644 index 0000000..f2ab5f0 --- /dev/null +++ b/com.sq.customization/src/com/sq/customization/util/RangeAdjuster.java @@ -0,0 +1,87 @@ +package com.sq.customization.util; + +public class RangeAdjuster { + public static String adjustRange(String range) { + if (range == null || range.trim().isEmpty()) { + return ""; + } + + // 判断格式:± 或 - + if (range.contains("±")) { + // 处理 "3±1" 格式 + String[] parts = range.split("±"); + if (parts.length != 2) { + return range; // 格式错误,返回原字符串 + } + + try { + double center = Double.parseDouble(parts[0].trim()); // 中心值 + double offset = Double.parseDouble(parts[1].trim()); // 偏移量 + + double minValue = center - offset; // 最小值 + double maxValue = center + offset; // 最大值 + + // 调整最小值和最大值 + double adjustedMin = minValue * 0.33; + double adjustedMax = maxValue * 0.33; + + return String.format("%.3f-%.3f", adjustedMin, adjustedMax); // 保留两位小数 + } catch (NumberFormatException e) { + return range; // 无法解析数字,返回原字符串 + } + } else if (range.contains("-")) { + // 处理 "1-4" 格式 + String[] parts = range.split("-"); + String minStr = parts.length > 0 ? parts[0].trim() : ""; + String maxStr = parts.length > 1 ? parts[1].trim() : ""; + + String adjustedMin, adjustedMax; + + // 处理最小值 + if (minStr.isEmpty()) { + adjustedMin = ""; + } else { + try { + double minValue = Double.parseDouble(minStr); + adjustedMin = String.format("%.3f", minValue * 0.33); // 保留两位小数 + } catch (NumberFormatException e) { + adjustedMin = minStr; // 解析失败,保留原值 + } + } + + // 处理最大值 + if (maxStr.isEmpty()) { + adjustedMax = ""; + } else { + try { + double maxValue = Double.parseDouble(maxStr); + adjustedMax = String.format("%.3f", maxValue * 0.33); // 保留两位小数 + } catch (NumberFormatException e) { + adjustedMax = maxStr; // 解析失败,保留原值 + } + } + + // 拼接结果 + if (adjustedMin.isEmpty() && adjustedMax.isEmpty()) { + return ""; + } else if (adjustedMin.isEmpty()) { + return "-" + adjustedMax; + } else if (adjustedMax.isEmpty()) { + return adjustedMin + "-"; + } else { + return adjustedMin + "-" + adjustedMax; + } + } else { + return range; // 不支持的格式,返回原字符串 + } + } + + public static void main(String[] args) { + // 测试用例 + String[] tests = {"3±1", "1-4", "1-", "-4", ""}; + for (String test : tests) { + System.out.println("Input: " + test + " -> Output: " + adjustRange(test)); + } + } +} + diff --git a/com.sq.customization/src/com/sq/customization/util/RangeCalculator.java b/com.sq.customization/src/com/sq/customization/util/RangeCalculator.java new file mode 100644 index 0000000..73e835c --- /dev/null +++ b/com.sq.customization/src/com/sq/customization/util/RangeCalculator.java @@ -0,0 +1,52 @@ +package com.sq.customization.util; + +public class RangeCalculator { + public static String adjustRange(String range) { + // 如果输入为空,直接返回空字符串或抛出异常(根据需求) + if (range == null || range.trim().isEmpty()) { + return ""; + } + + // 分割字符串,基于 "-" + String[] parts = range.split("-"); + String minStr = parts.length > 0 ? parts[0].trim() : ""; + String maxStr = parts.length > 1 ? parts[1].trim() : ""; + + // 处理最小值 + String adjustedMin = minStr.isEmpty() ? "" : minStr; + + // 处理最大值 + String adjustedMax; + if (maxStr.isEmpty()) { + adjustedMax = ""; // 最大值为空,不需要乘以 0.85 + } else { + try { + double maxValue = Double.parseDouble(maxStr); // 转换为 double + double adjustedValue = maxValue * 0.85; // 最大值乘以 0.85 + adjustedMax = String.valueOf(adjustedValue); // 转换回字符串 + } catch (NumberFormatException e) { + adjustedMax = maxStr; // 如果无法解析为数字,保持原样 + } + } + + // 拼接结果 + if (adjustedMin.isEmpty() && adjustedMax.isEmpty()) { + return ""; + } else if (adjustedMin.isEmpty()) { + return "-" + adjustedMax; + } else if (adjustedMax.isEmpty()) { + return adjustedMin + "-"; + } else { + return adjustedMin + "-" + adjustedMax; + } + } + + public static void main(String[] args) { + // 测试用例 + String[] tests = {"1.2-6", "1.2-", "-6", ""}; + for (String test : tests) { + System.out.println("Input: " + test + " -> Output: " + adjustRange(test)); + } + } +} +