Skip to content

修复多处 Bug 并清理调试遗留代码#1

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-project-features-and-fix-bugs
Draft

修复多处 Bug 并清理调试遗留代码#1
Copilot wants to merge 2 commits intomainfrom
copilot/refactor-project-features-and-fix-bugs

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 12, 2026

梳理项目发现多个功能缺陷和安全隐患,集中修复如下。

Bug 修复

  • AppointmentServlet — 假宠物注入(严重):用户无宠物时,forwardToAddPage() 会注入 pet_id=999 的虚假宠物,提交预约时触发外键约束错误。改为直接传真实(可能为空)列表。

  • UserServlet.handleRegister() — NPE(高)password.equals(confirmPassword)passwordnull 时抛 NullPointerException。加前置 null 检查。

  • UserServiceImpl.updateUser() — 邮箱唯一性校验失效(中)

    // 旧逻辑:findByUsername 返回的是当前用户自身,ID 相等判断永远 false
    User existingUser = userDao.findByUsername(user.getUsername());
    if (existingUser != null && !existingUser.getUserId().equals(user.getUserId()) && ...)
    
    // 新逻辑:existsByEmail 确认存在后,再用 findById 判断是否属于其他用户
    if (userDao.existsByEmail(email)) {
        User stored = userDao.findById(user.getUserId());
        if (stored == null || !email.equals(stored.getEmail())) return false;
    }
  • HealthRecord.needsFollowUp() — 当天复诊漏判(中)after(now) 严格大于,当天到期不显示"需复诊"。改为 !before(now)

  • HealthRecordDaoImpl.findByCondition() — 脆弱的 COUNT SQL(中):用 .replace("SELECT hr.*, p.pet_name, p.pet_type, p.breed", "SELECT COUNT(*)") 拼 COUNT 查询,SELECT 子句变更即静默失效。改为单独构建 WHERE 子句,分别组合两条独立查询。

信息泄露清理

移除 PetDaoImplPetServiceImplAppointmentServletPetServletUserServlet 中所有 System.out.println("DEBUG: ...") 语句,这些语句将用户 ID、宠物信息、SQL 语句等敏感数据打印至服务器日志。

数据层修复与清理

  • init.sqlusers.email 列补加 UNIQUE 约束,将唯一性约束下沉到数据库层。
  • 删除 5 个遗留调试 JSP 文件:debug-pets.jspdirect-test.jspfix-pet-data.jsptest-basic.jspappointment-add-simple.jsp

…ug prints, needsFollowUp, fragile count SQL; remove debug JSP files; add email UNIQUE constraint

Agent-Logs-Url: https://github.com/xiaoyuanhost/PetHospitalManagementSystem/sessions/e5ff2be9-dd00-4adf-b08c-03288c672a43

Co-authored-by: xiaoyuanhost <46616128+xiaoyuanhost@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor project features and fix identified bugs 修复多处 Bug 并清理调试遗留代码 Apr 12, 2026
Copilot AI requested a review from xiaoyuanhost April 12, 2026 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants