From c0f3efb8ddb1397016d9dd7bbe5a996362cd28d1 Mon Sep 17 00:00:00 2001 From: fly6516 Date: Wed, 26 Mar 2025 11:26:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(EmployeeDAO):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=91=98=E5=B7=A5=E6=9F=A5=E8=AF=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 queryByPerformance 方法查询高绩效员工 - 新增 queryRecentPromotion 方法查询近一年晋升员工 - 优化员工查询相关代码,提高可读性和可维护性 --- src/main/java/EmployeeDAO.java | 36 ++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/EmployeeDAO.java b/src/main/java/EmployeeDAO.java index 07af7dd..c0ce76c 100644 --- a/src/main/java/EmployeeDAO.java +++ b/src/main/java/EmployeeDAO.java @@ -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);