package com.example.web.controller; import com.example.web.entity.Login; import com.example.web.entity.Personnel; import com.example.web.service.LoginService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import java.util.HashMap; import java.util.Map; /** * @Description: 登录控制器 * @Author: * @Date: 2025-12-17 */ @Controller public class LoginController { @Autowired private LoginService loginService; /** * 处理登录请求 * @param projectName 工位名 * @param userName 用户名 * @param password 密码 * @return 包含登录结果和用户信息的Map */ @PostMapping("/logins") @ResponseBody public Map login(@RequestParam String projectName, @RequestParam String userName, @RequestParam String password) { // 创建响应结果Map Map result = new HashMap<>(); try { // 验证登录信息 Login login = loginService.verifyLogin(projectName, userName, password); if (login != null) { // 登录成功,获取员工详细信息 Personnel personnel = loginService.getPersonnelInfo(login.getManagerId()); // 设置响应结果 result.put("success", true); result.put("userInfo", personnel); result.put("message", "登录成功"); } else { // 登录失败 result.put("success", false); result.put("message", "用户名或密码不正确"); } } catch (Exception e) { // 处理异常 result.put("success", false); result.put("message", "登录失败,请稍后重试"); e.printStackTrace(); } return result; } }