fix: 图册查询,零件编号按照升序排列
This commit is contained in:
parent
7a9e6f79d3
commit
881827ae7e
@ -46,6 +46,7 @@ import java.math.RoundingMode;
|
|||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhouc
|
* @author zhouc
|
||||||
@ -777,42 +778,61 @@ public class AssepcNewDynamicEdut extends AbstractFormPlugin implements BeforeBi
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sortDynamicObjectCollection(DynamicObjectCollection data) {
|
public static void sortDynamicObjectCollection(DynamicObjectCollection data) {
|
||||||
List<DynamicObject> list = new ArrayList<>(data);
|
// 自定义比较器
|
||||||
|
Comparator<DynamicObject> comparator = (obj1, obj2) -> {
|
||||||
|
String atlasNo1 = obj1.getString("yem_atlasno");
|
||||||
|
String atlasNo2 = obj2.getString("yem_atlasno");
|
||||||
|
|
||||||
Collections.sort(list, new Comparator<DynamicObject>() {
|
List<Integer> parsed1 = parseAtlasNo(atlasNo1);
|
||||||
@Override
|
List<Integer> parsed2 = parseAtlasNo(atlasNo2);
|
||||||
public int compare(DynamicObject o1, DynamicObject o2) {
|
|
||||||
BigDecimal num1 = parseBigDecimal(o1.getString("yem_atlasno"));
|
|
||||||
BigDecimal num2 = parseBigDecimal(o2.getString("yem_atlasno"));
|
|
||||||
|
|
||||||
// 如果两个都转换成功,按数值比较
|
// 如果两个都是有效编号,逐级比较
|
||||||
if (num1 != null && num2 != null) {
|
if (parsed1 != null && parsed2 != null) {
|
||||||
return num1.compareTo(num2);
|
int minLength = Math.min(parsed1.size(), parsed2.size());
|
||||||
|
for (int i = 0; i < minLength; i++) {
|
||||||
|
int compare = Integer.compare(parsed1.get(i), parsed2.get(i));
|
||||||
|
if (compare != 0) {
|
||||||
|
return compare;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 如果前缀相同,较短的编号排在前面
|
||||||
|
return Integer.compare(parsed1.size(), parsed2.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num1 != null) {
|
// 如果一个是有效编号,另一个无效,有效编号排在前面
|
||||||
return -1;
|
if (parsed1 == null && parsed2 != null) {
|
||||||
|
return 1; // obj1 无效,排在后面
|
||||||
}
|
}
|
||||||
if (num2 != null) {
|
if (parsed1 != null && parsed2 == null) {
|
||||||
return 1;
|
return -1; // obj2 无效,排在后面
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果两个都失败,按字符串比较
|
// 如果两个都无效,按字符串字典序排序
|
||||||
return o1.getString("yem_atlasno").compareTo(o2.getString("yem_atlasno"));
|
return atlasNo1.compareTo(atlasNo2);
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
|
||||||
// 将排序后的结果重新赋值给原集合
|
// 对集合进行排序
|
||||||
data.clear();
|
data.sort(comparator);
|
||||||
data.addAll(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static BigDecimal parseBigDecimal(String value) {
|
/**
|
||||||
try {
|
* 将 yem_atlasno 转换为可比较的 List<Integer>。
|
||||||
return new BigDecimal(value);
|
* 如果格式无效,返回 null。
|
||||||
} catch (NumberFormatException e) {
|
*/
|
||||||
return null; // 转换失败返回 null
|
private static List<Integer> parseAtlasNo(String atlasNo) {
|
||||||
|
if (atlasNo == null || atlasNo.isEmpty()) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否只包含数字和点
|
||||||
|
if (!atlasNo.matches("^(\\d+\\.)*\\d+$")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 拆分并转换为整数列表
|
||||||
|
return Arrays.stream(atlasNo.split("\\."))
|
||||||
|
.map(Integer::parseInt)
|
||||||
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user