leutu
2024-05-08 543e4eb01ca210b20876e8139cb3d0403d7d065c
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.skyline.electricity.controller;
 
import org.springframework.stereotype.*;
import com.skyline.electricity.service.*;
import org.springframework.beans.factory.annotation.*;
import com.skyline.electricity.interceptor.*;
import org.apache.commons.lang3.*;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;
import com.skyline.electricity.entity.*;
import java.util.*;
 
@Controller
@RequestMapping({ "/interceptor" })
@Api("基于SpringBoot的廊坊热电厂三维可视化系统")
@CrossOrigin
public class InterceptorController
{
    @Autowired
    private InfoSynchService infoSynchService;
    
    @RequestMapping(value = { "/getUserInfo" }, method = { RequestMethod.POST })
    @ApiOperation("获取前端页面传送的session信息")
    @ResponseBody
    public Object getUserInfo(final String code) {
        final Map<String, Object> map = new HashMap<String, Object>();
        final IAMUtils iamUtils = new IAMUtils();
        if (code != null) {
            String tokenOfCode = null;
            tokenOfCode = iamUtils.getTokenByCode(code);
            if (StringUtils.isNotBlank((CharSequence)tokenOfCode)) {
                Object userInfo = null;
                try {
                    userInfo = iamUtils.getUserInfoFromIam(tokenOfCode);
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
                if (userInfo != null && !"".equals(userInfo)) {
                    map.put("userInfo", userInfo);
                    map.put("msg", "success");
                    map.put("code", "0");
                    return map;
                }
                map.put("userInfo", null);
                map.put("msg", "failure");
                map.put("code", "-1");
                return map;
            }
        }
        return null;
    }
    
    @RequestMapping(value = { "/getUserInfoByToken" }, method = { RequestMethod.POST })
    @ApiOperation("获取前端页面传送的token信息")
    @ResponseBody
    public Object getUserInfoByToken(final String token) {
        final Map<String, Object> map = new HashMap<String, Object>();
        final IAMUtils iamUtils = new IAMUtils();
        if (token == null) {
            return null;
        }
        Object userInfo = null;
        try {
            userInfo = iamUtils.getUserInfoFromIam(token);
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        if (userInfo != null && !"".equals(userInfo)) {
            map.put("userInfo", userInfo);
            map.put("msg", "success");
            map.put("code", "0");
            return map;
        }
        map.put("userInfo", null);
        map.put("msg", "failure");
        map.put("code", "-1");
        return map;
    }
    
    @RequestMapping(value = { "/judgePermissions" }, method = { RequestMethod.POST })
    @ApiOperation("判断当前用户是否拥有权限")
    @ResponseBody
    public Object judgePermissions(final String id) {
        final List<Permissions> permissionsList = (List<Permissions>)this.infoSynchService.getPermissions();
        final List<String> idList = new ArrayList<String>();
        for (final Permissions permissions : permissionsList) {
            idList.add(permissions.getUser_id());
        }
        final boolean flag = idList.contains(id);
        return flag;
    }
    
    @RequestMapping(value = { "/testConfig" }, method = { RequestMethod.POST })
    @ApiOperation("测试读取配置文件内容")
    @ResponseBody
    public Object testConfig() {
        final IAMUtils iamUtils = new IAMUtils();
        final Object info = iamUtils.getUserInfoFromIam("ooo");
        return info;
    }
}