1.匹配套筒逻辑

main
xuezhou 1 month ago
parent c10a034108
commit 8a5a36da5f

@ -3,5 +3,20 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="lib/easyexcel-core-3.2.0.jar"/>
<classpathentry kind="lib" path="lib/commons-collections4-4.1.jar"/>
<classpathentry kind="lib" path="lib/poi-3.17.jar"/>
<classpathentry kind="lib" path="lib/poi-examples-3.17.jar"/>
<classpathentry kind="lib" path="lib/poi-excelant-3.17.jar"/>
<classpathentry kind="lib" path="lib/poi-ooxml-3.17.jar"/>
<classpathentry kind="lib" path="lib/poi-ooxml-schemas-3.17.jar"/>
<classpathentry kind="lib" path="lib/poi-scratchpad-3.17.jar"/>
<classpathentry kind="lib" path="lib/xmlbeans-2.6.0.jar"/>
<classpathentry kind="lib" path="lib/xml-apis-1.4.01.jar"/>
<classpathentry kind="lib" path="lib/xalan-2.7.2.jar"/>
<classpathentry kind="lib" path="lib/serializer-2.7.2.jar"/>
<classpathentry kind="lib" path="lib/cglib-3.3.0.jar"/>
<classpathentry kind="lib" path="lib/easyexcel-support-3.2.0.jar"/>
<classpathentry kind="lib" path="lib/easyexcel-3.2.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -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

@ -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

@ -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<ExcelBean> 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; }
}

@ -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;
}
}

@ -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;
}
}

@ -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;
}
}

@ -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 ? "符合" : "不符合"));

@ -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));
}
}
}

@ -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));
}
}
}

@ -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));
}
}
}
Loading…
Cancel
Save