2
13693261870
2022-09-16 653761a31dfeb50dd3d007e892d69c90bf0cdafc
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package com.landtool.lanbase.modules.sys.controller;
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import com.landtool.lanbase.config.SysTemPropertyConfig;
import com.landtool.lanbase.modules.org.entity.OrgUnit;
import com.landtool.lanbase.modules.org.entity.OrgUser;
 
import springfox.documentation.annotations.ApiIgnore;
 
/**
 * @author lanbase
 * @Description: TODO(系统用户)
 * @date 2017-6-23 15:07
 */
@RestController
@RequestMapping("/sys/user")
@ApiIgnore()
public class SysUserController extends AbstractController {
    @Autowired
    private SysTemPropertyConfig sysConfig;
 
    /**
     * JS获取登录的用户信息
     */
    @RequestMapping("/jsinfo")
    public String jsinfo() {
        return "var userid=" + getUserId() + ";";
    }
 
    /**
     * JSONP获取登录用户ID
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/getUserInfo")
    public String getUserInfo(HttpServletRequest request) {
        String callbackFunName = request.getParameter("callback");
        if (callbackFunName == null || callbackFunName.isEmpty()) {
            callbackFunName = "callback";
        }
        String result = "";
        try {
            OrgUser orgUser = getUser();
            OrgUnit orgUnit = getUnit();
            result = "{success: true, info: { userid: " + orgUser.getUserid() + ", chinesename: '" + orgUser.getChinesename()
                    + "', unitname: '" + (orgUnit != null ? orgUnit.getUnitname() : "") + "', useradmin: " + SecurityUtils.getSubject().isPermitted("org_user_admin")
                    + ", userprintaudit: " + SecurityUtils.getSubject().isPermitted("portal:print:audit") + "}}";
        } catch (Exception e) {
            // TODO: handle exception
            result = "{success: false, msg: '获取用户信息失败!'}";
        }
        return callbackFunName + "([" + result + "])";
    }
 
    /**
     * JSONP获取登录用户中文名
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("/getUserName")
    public String getUserName(HttpServletRequest request) {
        //String username = request.getRemoteUser();
        OrgUser orgUser = getUser();
        String username = orgUser.getChinesename();
        String callbackFunName = request.getParameter("callback");
        if (callbackFunName == null || callbackFunName.isEmpty()) {
            callbackFunName = "callback";
        }
        String result = "";
        try {
            //result = "{success: true, msg: '" + getUser().getChinesename() + "'}";
            result = "{success: true, msg: '" + username + "'}";
        } catch (Exception e) {
            // TODO: handle exception
            result = "{success: false, msg: '获取用户信息失败!'}";
        }
        return callbackFunName + "(" + result + ")";
    }
}