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;
|
}
|
}
|