#
luxiaotao1123
2024-02-16 3b1672c22fe83d442e81092a6efac71b284cf4a7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package com.zy.asrs.wcs.sys.controller;
 
import com.zy.asrs.wcs.common.domain.BaseParam;
import com.zy.asrs.wcs.sys.entity.User;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
 
import java.util.Map;
 
/**
 * 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();
    }
 
    public BaseParam getBaseParam(Map<String, Object> map) {
        return BaseParam.build(map);
    }
 
}