You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.1 KiB

3 months ago
package com.example.web.controller;
import com.example.web.entity.Login;
import com.example.web.entity.Personnel;
3 months ago
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;
3 months ago
import java.util.HashMap;
3 months ago
import java.util.Map;
/**
* @Description: 登录控制器
* @Author:
* @Date: 2025-12-17
*/
@Controller
3 months ago
public class LoginController {
@Autowired
private LoginService loginService;
/**
* 处理登录请求
* @param projectName 工位名
* @param userName 用户名
* @param password 密码
* @return 包含登录结果和用户信息的Map
*/
3 months ago
@PostMapping("/logins")
@ResponseBody
public Map<String, Object> login(@RequestParam String projectName,
@RequestParam String userName,
3 months ago
@RequestParam String password) {
// 创建响应结果Map
Map<String, Object> 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();
3 months ago
}
3 months ago
return result;
}
}