feat(EmployeeDAO): 添加员工查询功能
- 新增 queryByPerformance 方法查询高绩效员工 - 新增 queryRecentPromotion 方法查询近一年晋升员工 - 优化员工查询相关代码,提高可读性和可维护性
This commit is contained in:
parent
c019e5fe37
commit
c0f3efb8dd
@ -37,8 +37,40 @@ public class EmployeeDAO {
|
||||
table.close();
|
||||
}
|
||||
|
||||
// 其他查询方法实现(与原HBaseEmpManager逻辑相同)
|
||||
// ... existing query methods ...
|
||||
public static void queryByPerformance() throws IOException {
|
||||
Table table = HBaseConnectionManager.getConnection().getTable(TableName.valueOf("emp1520"));
|
||||
Scan scan = new Scan();
|
||||
scan.addFamily(Bytes.toBytes(CF_PERFORMANCE));
|
||||
ResultScanner scanner = table.getScanner(scan);
|
||||
for (Result result : scanner) {
|
||||
String perf = Bytes.toString(result.getValue(
|
||||
Bytes.toBytes(CF_PERFORMANCE), Bytes.toBytes("performance_score")));
|
||||
if (perf != null && Integer.parseInt(perf) >= 90) {
|
||||
System.out.println("高绩效员工: " +
|
||||
Bytes.toString(result.getValue(Bytes.toBytes(CF_EMPNUM), Bytes.toBytes("empno"))));
|
||||
}
|
||||
}
|
||||
table.close();
|
||||
}
|
||||
|
||||
public static void queryRecentPromotion() throws IOException {
|
||||
Table table = HBaseConnectionManager.getConnection().getTable(TableName.valueOf("emp1520"));
|
||||
Scan scan = new Scan();
|
||||
scan.addColumn(Bytes.toBytes(CF_PERFORMANCE), Bytes.toBytes("promotion_date"));
|
||||
ResultScanner scanner = table.getScanner(scan);
|
||||
for (Result result : scanner) {
|
||||
String dateStr = Bytes.toString(result.getValue(
|
||||
Bytes.toBytes(CF_PERFORMANCE), Bytes.toBytes("promotion_date")));
|
||||
if (dateStr != null && !dateStr.isEmpty()) {
|
||||
LocalDate date = LocalDate.parse(dateStr);
|
||||
if (date.isAfter(LocalDate.now().minusYears(1))) {
|
||||
System.out.println("近一年晋升员工: " +
|
||||
Bytes.toString(result.getValue(Bytes.toBytes(CF_EMPNUM), Bytes.toBytes("empno"))));
|
||||
}
|
||||
}
|
||||
}
|
||||
table.close();
|
||||
}
|
||||
|
||||
private static String generateRowKey(String empno) throws NoSuchAlgorithmException {
|
||||
String prefix = empno.substring(0, 3);
|
||||
|
Loading…
Reference in New Issue
Block a user