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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package com.landtool.lanbase.modules.api.controller.MapPortal;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
 
import com.landtool.lanbase.common.map.EsbToken;
import com.landtool.lanbase.common.utils.HttpOperateUtils;
import com.landtool.lanbase.config.SysTemPropertyConfig;
import com.landtool.lanbase.modules.org.entity.OrgUser;
import com.landtool.lanbase.modules.org.service.OrgUserService;
import com.landtool.lanbase.modules.res.entity.Res_Ext3D;
import com.landtool.lanbase.modules.res.entity.Res_ExtFileSource;
import com.landtool.lanbase.modules.res.entity.Res_ExtIntegrate;
import com.landtool.lanbase.modules.res.entity.Res_ExtInterFaceService;
import com.landtool.lanbase.modules.res.entity.Res_ExtMapUrl;
import com.landtool.lanbase.modules.res.entity.Res_ExtSpaceServer;
import com.landtool.lanbase.modules.res.entity.Res_ExtThemeMap;
import com.landtool.lanbase.modules.res.entity.Res_MainInfo;
import com.landtool.lanbase.modules.res.service.ResApplyRecommendService;
import com.landtool.lanbase.modules.res.service.ResExt3DService;
import com.landtool.lanbase.modules.res.service.ResExtFileSourceService;
import com.landtool.lanbase.modules.res.service.ResExtIntegrateService;
import com.landtool.lanbase.modules.res.service.ResExtInterFaceService;
import com.landtool.lanbase.modules.res.service.ResExtMapUrlService;
import com.landtool.lanbase.modules.res.service.ResExtSpaceServerService;
import com.landtool.lanbase.modules.res.service.ResExtThemeMapService;
import com.landtool.lanbase.modules.res.service.ResMainInfoService;
import com.landtool.lanbase.modules.sys.entity.SysSysteminfo;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
 
@Controller
@RequestMapping("/api/token/")
@Api(value = "", tags = {"Token接口"})
public class TokenController {
    @Autowired
    private ResExtMapUrlService resExtMapUrlService;
    
    @Autowired
    private SysTemPropertyConfig sysConfig;
    
    @Autowired
    private ResExtThemeMapService resExtThemeMapService;
    
    @Autowired
    private ResMainInfoService resMainInfoService;
    
    @Autowired
    private ResApplyRecommendService resApplyRecommendService;
    
    @Autowired
    private OrgUserService orgUserService;
    
    @Autowired
    private ResExtInterFaceService resExtInterFaceService;
    
    @Autowired
    private ResExtFileSourceService resExtFileSourceService;
    
    @Autowired
    private ResExtIntegrateService resExtIntegrateService;
    
    @Autowired
    private ResExtSpaceServerService resExtSpaceServerService;
    
    @Autowired
    private ResExt3DService resExt3DService;
    
    /**
     * 应用程序获取Token
     */
    @ResponseBody
    @GetMapping(path = "appgenerate")
    @ApiOperation(value = "应用程序获取资源Token", notes = "")
    public String getAppToken(@ApiParam(name = "loginname", value = "登录用户名", required = true) @RequestParam(name = "loginname") String loginname, @ApiParam(name = "appid", value = "应用程序ID", required = true) @RequestParam(name = "appid") Integer appid, @ApiParam(name = "resourceid", value = "资源ID", required = true) @RequestParam(name = "resourceid") Integer resourceid) {
        String result = "";
        try {
            OrgUser orgUser = orgUserService.queryByUserName(loginname);//获取用户信息
            if (orgUser != null) {
                Integer userid = orgUser.getUserid().intValue();//用户ID
                String checkAppUrl = sysConfig.getApiServer() + "/api/sys/systeminfo/getSysListByUserId/" + userid;//获取用户所属应用程序列表地址
                List<SysSysteminfo> permsList = HttpOperateUtils.getJsonObjectArray(checkAppUrl, SysSysteminfo.class);
                boolean isApp = false;//用户是否为应用程序负责人
                String referenceurl = "";//资源调用地址
                if (permsList != null && permsList.size() > 0) {
                    for (int i = 0; i < permsList.size(); i++) {
                        if (permsList.get(i).getAppid().intValue() == appid) {
                            isApp = true;
                            referenceurl = permsList.get(i).getReferenceurl();
                            break;
                        }
                    }
                }
                if (isApp) {
                    Map<String, Object> map = new HashMap<String, Object>();
                    map.put("sysid", appid);
                    map.put("resourceid", resourceid);
                    Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resourceid);//获取资源主表信息
                    if (resMainInfo != null) {
                        int num = resApplyRecommendService.checkAppZiYuan(map);//获取应用程序申请审核通过资源数量
                        if (num > 0 || resMainInfo.getSharprotocol().equals("完全公开")) {
                            if (referenceurl != null && !referenceurl.isEmpty()) {
                                String subzyids = "";
                                String serverUrl = "null";
                                //查询是否是专题地图,是专题地图则获取相关子图层ID
                                if (resMainInfo.getResourceclass().equals("KJ_ZTDT")) {
                                    Res_ExtThemeMap resExtThemeMap = resExtThemeMapService.selectByPrimaryKey(resourceid);
                                    if (resExtThemeMap != null) {
                                        subzyids = resExtThemeMap.getSublayerset();
                                    }
                                }
                                Res_ExtMapUrl resExtMapUrl = resExtMapUrlService.queryFirstOrderByResId(resourceid);
                                if (resExtMapUrl != null) {
                                    serverUrl = (resExtMapUrl.getServerurl() == null || resExtMapUrl.getServerurl().isEmpty()) ? "null" : "\"" + resExtMapUrl.getServerurl() + "\"";
                                } else {
                                    if (resMainInfo.getResourceclass().equals("JKFW")) {
                                        Res_ExtInterFaceService res_extInterFaceService = resExtInterFaceService.selectByPrimaryKey(resourceid);
                                        if (res_extInterFaceService != null) {
                                            serverUrl = res_extInterFaceService.getServerurl() == null ? "null" : "\"" + res_extInterFaceService.getServerurl() + "\"";
                                        }
                                    }
                                    if (resMainInfo.getResourceclass().equals("SJWJ")) {
                                        Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(resourceid);
                                        if (resExtFileSource != null) {
                                            serverUrl = resExtFileSource.getServerurl() == null ? "null" : "\"" + resExtFileSource.getServerurl() + "\"";
                                        }
                                    }
                                    if (resMainInfo.getResourceclass().equals("YWJC")) {
                                        Res_ExtIntegrate resExtIntegrate = resExtIntegrateService.selectByPrimaryKey(resourceid);
                                        if (resExtIntegrate != null) {
                                            serverUrl = resExtIntegrate.getServerurl() == null ? "null" : "\"" + resExtIntegrate.getServerurl() + "\"";
                                        }
                                    }
                                    if (resMainInfo.getResourceclass().equals("KJ_KJFX")) {
                                        Res_ExtSpaceServer resExtSpaceServer = resExtSpaceServerService.selectByPrimaryKey(resourceid);
                                        if (resExtSpaceServer != null) {
                                            serverUrl = resExtSpaceServer.getServerurl() == null ? "null" : "\"" + resExtSpaceServer.getServerurl() + "\"";
                                        }
                                    }
//                                    添加三维地形和三维影像 add 2019/08/01
                                    if (resMainInfo.getResourceclass().equals("KJ_SWMX") || resMainInfo.getResourceclass().equals("KJ_SWDX") || resMainInfo.getResourceclass().equals("KJ_SWYX")) {
                                        Res_Ext3D resExt3D = resExt3DService.selectByPrimaryKey(resourceid);
                                        if (resExt3D != null) {
                                            serverUrl = resExt3D.getServerurl() == null ? "null" : "\"" + resExt3D.getServerurl() + "\"";
                                        }
                                    }
                                }
                                String token = EsbToken.getAppEsbToken(userid, appid, referenceurl, resourceid, resMainInfo.getEspproxy(), sysConfig, subzyids, resMainInfo.getToken());
                                result = "{ \"success\": true, \"serverUrl\": " + serverUrl + ", \"token\": " + (token.isEmpty() ? "null" : "\"" + token + "\"") + "}";
                                
                            } else {
                                result = "{ \"success\": false, \"msg\": \"应用程序资源引用地址未配置!\" }";
                            }
                        } else {
                            result = "{ \"success\": false, \"msg\": \"应用程序没有资源权限!\" }";
                        }
                    } else {
                        result = "{ \"success\": false, \"msg\": \"资源不存在!\" }";
                    }
                } else {
                    result = "{ \"success\": false, \"msg\": \"用户不是应用程序系统负责人!\" }";
                }
            } else {
                result = "{ \"success\": false, \"msg\": \"用户不存在!\" }";
            }
        } catch (IOException e) {
            result = "{ \"success\": false, \"msg\": \"" + e.getMessage() + "\" }";
        }
        
        return result;
    }
}