package com.zy.asrs.wcs.sys.controller; import com.zy.asrs.wcs.sys.entity.User; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; /** * Created by vincent on 1/30/2024 */ public class BaseController { public User getLoginUser() { try { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null) { Object object = authentication.getPrincipal(); if (object instanceof User) { return (User) object; } } } catch (Exception e) { System.out.println(e.getMessage()); } return null; } public Long getLoginUserId() { User loginUser = getLoginUser(); return loginUser == null ? null : loginUser.getId(); } }