|
6 | 6 | import com.alibaba.excel.enums.BooleanEnum;
|
7 | 7 | import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
|
8 | 8 |
|
| 9 | +import java.util.Objects; |
| 10 | + |
9 | 11 | @SuppressWarnings("unused")
|
10 | 12 | @HeadStyle(wrapped = BooleanEnum.FALSE, horizontalAlignment = HorizontalAlignmentEnum.LEFT)
|
11 | 13 | @HeadFontStyle(fontHeightInPoints = 11, bold = BooleanEnum.FALSE, fontName = "宋体")
|
12 |
| -public class Rel { |
13 |
| - @ColumnWidth(50) |
14 |
| - private String a; |
15 |
| - @ColumnWidth(50) |
16 |
| - private String b; |
| 14 | +public class Rel implements Comparable<Rel> { |
| 15 | + @ColumnWidth(25) |
| 16 | + private String tableL; |
| 17 | + @ColumnWidth(25) |
| 18 | + private String columnL; |
| 19 | + @ColumnWidth(25) |
| 20 | + private String tableR; |
| 21 | + @ColumnWidth(25) |
| 22 | + private String columnR; |
| 23 | + @ColumnWidth(25) |
| 24 | + private String tableCommentL; |
| 25 | + @ColumnWidth(25) |
| 26 | + private String columnCommentL; |
| 27 | + @ColumnWidth(25) |
| 28 | + private String tableCommentR; |
| 29 | + @ColumnWidth(25) |
| 30 | + private String columnCommentR; |
| 31 | + |
| 32 | + public static Rel sortRelOrNull(String tableL, String columnL, String tableR, String columnR) { |
| 33 | + if (tableL == null || columnL == null || tableR == null || columnR == null) { |
| 34 | + return null; |
| 35 | + } |
| 36 | + tableL = tableL.toLowerCase(); |
| 37 | + tableR = tableR.toLowerCase(); |
| 38 | + columnL = columnL.toLowerCase(); |
| 39 | + columnR = columnR.toLowerCase(); |
| 40 | + int compare = tableL.compareTo(tableR); |
| 41 | + if (compare == 0) { |
| 42 | + compare = columnL.compareTo(columnR); |
| 43 | + } |
| 44 | + if (compare == 0) { |
| 45 | + return null; |
| 46 | + } |
| 47 | + Rel rel = new Rel(); |
| 48 | + if (compare < 0) { |
| 49 | + rel.tableL = tableL; |
| 50 | + rel.columnL = columnL; |
| 51 | + rel.tableR = tableR; |
| 52 | + rel.columnR = columnR; |
| 53 | + } else { |
| 54 | + rel.tableL = tableR; |
| 55 | + rel.columnL = columnR; |
| 56 | + rel.tableR = tableL; |
| 57 | + rel.columnR = columnL; |
| 58 | + } |
| 59 | + return rel; |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public String toString() { |
| 64 | + return tableL + "." + columnL + " --> " + tableR + "." + tableCommentR; |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public int compareTo(Rel o) { |
| 69 | + return toString().compareTo((o.toString())); |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + public boolean equals(Object o) { |
| 74 | + if (this == o) return true; |
| 75 | + if (o == null || getClass() != o.getClass()) return false; |
| 76 | + Rel rel = (Rel) o; |
| 77 | + return Objects.equals(tableL, rel.tableL) |
| 78 | + && Objects.equals(columnL, rel.columnL) |
| 79 | + && Objects.equals(tableR, rel.tableR) |
| 80 | + && Objects.equals(columnR, rel.columnR); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public int hashCode() { |
| 85 | + return Objects.hash(tableL, columnL, tableR, columnR); |
| 86 | + } |
| 87 | + |
| 88 | + public String getTableL() { |
| 89 | + return tableL; |
| 90 | + } |
| 91 | + |
| 92 | + public void setTableL(String tableL) { |
| 93 | + this.tableL = tableL; |
| 94 | + } |
| 95 | + |
| 96 | + public String getColumnL() { |
| 97 | + return columnL; |
| 98 | + } |
| 99 | + |
| 100 | + public void setColumnL(String columnL) { |
| 101 | + this.columnL = columnL; |
| 102 | + } |
| 103 | + |
| 104 | + public String getTableR() { |
| 105 | + return tableR; |
| 106 | + } |
| 107 | + |
| 108 | + public void setTableR(String tableR) { |
| 109 | + this.tableR = tableR; |
| 110 | + } |
| 111 | + |
| 112 | + public String getColumnR() { |
| 113 | + return columnR; |
| 114 | + } |
| 115 | + |
| 116 | + public void setColumnR(String columnR) { |
| 117 | + this.columnR = columnR; |
| 118 | + } |
| 119 | + |
| 120 | + public String getTableCommentL() { |
| 121 | + return tableCommentL; |
| 122 | + } |
| 123 | + |
| 124 | + public void setTableCommentL(String tableCommentL) { |
| 125 | + this.tableCommentL = tableCommentL; |
| 126 | + } |
| 127 | + |
| 128 | + public String getColumnCommentL() { |
| 129 | + return columnCommentL; |
| 130 | + } |
| 131 | + |
| 132 | + public void setColumnCommentL(String columnCommentL) { |
| 133 | + this.columnCommentL = columnCommentL; |
| 134 | + } |
| 135 | + |
| 136 | + public String getTableCommentR() { |
| 137 | + return tableCommentR; |
| 138 | + } |
| 139 | + |
| 140 | + public void setTableCommentR(String tableCommentR) { |
| 141 | + this.tableCommentR = tableCommentR; |
| 142 | + } |
| 143 | + |
| 144 | + public String getColumnCommentR() { |
| 145 | + return columnCommentR; |
| 146 | + } |
| 147 | + |
| 148 | + public void setColumnCommentR(String columnCommentR) { |
| 149 | + this.columnCommentR = columnCommentR; |
| 150 | + } |
17 | 151 | }
|
0 commit comments