package com.guwan.backend.jpaTest; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.sql.ResultSet; import java.util.List; @RestController @RequestMapping("/api/employees") public class EmployeeController { @Autowired private EmployeeService employeeService; @Autowired private JdbcTemplate jdbcTemplate; @PersistenceContext private EntityManager entityManager; /** * 获取员工详细信息,包含部门和项目信息 * 使用Spring JdbcTemplate直接映射SQL结果 * * @param departmentName 部门名称过滤条件 * @param projectDeleted 项目是否已删除的过滤条件 * @return 员工DTO列表 */ @GetMapping("/details") public List getEmployeeDetails( @RequestParam(required = false) String departmentName, @RequestParam(required = false, defaultValue = "false") boolean projectDeleted) { return employeeService.getEmployeeDetails(departmentName, projectDeleted); } /** * 根据条件查询员工信息 * * @param employeeName 员工名称过滤条件,可选 * @param departmentName 部门名称过滤条件,可选 * @return 员工DTO列表 */ @GetMapping("/search") public List searchEmployees( @RequestParam(required = false) String employeeName, @RequestParam(required = false) String departmentName) { return employeeService.findEmployees(employeeName, departmentName); } }