| | |
| | | standardProductList.setMethodS(code); |
| | | return standardProductList; |
| | | }).collect(Collectors.toList()); |
| | | //按照电路试验--辐射试验--温湿度试验--环境试验进行排序 |
| | | // 定义自定义排序器 |
| | | Comparator<StandardProductList> testTypeComparator = (o1, o2) -> { |
| | | String[] order = {"电路试验", "辐射试验", "温湿度试验", "环境试验","功率试验"}; |
| | | int index1 = -1; |
| | | int index2 = -1; |
| | | // 找出两个对象 在自定义顺序数组中的位置 |
| | | for (int i = 0; i < order.length; i++) { |
| | | if (o1.getInspectionItem().equals(order[i])) { |
| | | index1 = i; |
| | | } |
| | | if (o2.getInspectionItem().equals(order[i])) { |
| | | index2 = i; |
| | | } |
| | | if (index1 != -1 && index2 != -1) { |
| | | break; // 两个位置都找到了,可以退出循环 |
| | | } |
| | | } |
| | | // 比较位置 |
| | | int compareResult = Integer.compare(index1, index2); |
| | | // 如果是环境试验,且两个对象在主检验项目上排序相同,则用次级检验项目排序 |
| | | if (compareResult == 0 && order[index1].equals("环境试验")) { |
| | | String[] subOrder = {"冲水试验", "振动试验"}; |
| | | int subIndex1 = -1; |
| | | int subIndex2 = -1; |
| | | for (int i = 0; i < subOrder.length; i++) { |
| | | if (o1.getInspectionItemSubclass().equals(subOrder[i])) { |
| | | subIndex1 = i; |
| | | } |
| | | if (o2.getInspectionItemSubclass().equals(subOrder[i])) { |
| | | subIndex2 = i; |
| | | } |
| | | if (subIndex1 != -1 && subIndex2 != -1) { |
| | | break; // 两个次级位置都找到了,可以退出循环 |
| | | } |
| | | } |
| | | compareResult = Integer.compare(subIndex1, subIndex2); |
| | | } |
| | | // 比较位置 |
| | | return compareResult; |
| | | }; |
| | | // 对列表进行排序 |
| | | Collections.sort(list, testTypeComparator); |
| | | return list; |
| | | } |
| | | |