package com.landtool.lanbase.modules.res.controller; import static com.landtool.lanbase.common.utils.HttpOperateUtils.httpGet; import java.io.IOException; import java.util.Map; import org.apache.commons.lang.StringEscapeUtils; import org.apache.shiro.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.alibaba.fastjson.JSONObject; import com.landtool.lanbase.common.annotation.LogAction; import com.landtool.lanbase.common.utils.HttpOperateUtils; import com.landtool.lanbase.modules.res.entity.Res_ExtIntegrate; import com.landtool.lanbase.modules.res.entity.Res_ExtMapUrl; import com.landtool.lanbase.modules.res.entity.Res_MainInfo; import com.landtool.lanbase.modules.res.service.ResExtIntegrateService; import com.landtool.lanbase.modules.res.service.ResExtMapUrlService; import com.landtool.lanbase.modules.res.service.ResMainInfoService; /** * @Author: lizhao * @Description:10系统资源扩展(业务集成)(RES_EXTINTEGRATE) * */ @Controller @RequestMapping("/res") public class ResExtIntegrateController { @Autowired private ResExtIntegrateService resExtIntegrateService; @Autowired private ResMainInfoService resMainInfoService; @Autowired private ResExtMapUrlService resExtMapUrlService; /** * 访问资源业务集成图层信息页面 */ @RequestMapping("/ResManage/ResRegister/ExtIntegrate") public String ExtIntegrate(int resMainInfoId, Model model) { Res_ExtIntegrate resExtIntegrate = resExtIntegrateService.selectByPrimaryKey(resMainInfoId); Integer isSetChart = 0;//是否显示模型设置按钮(0不显示1显示) String serverUrl = ""; String resolutionBen = ""; String resolutionEnd = ""; if (resExtIntegrate != null) { model.addAttribute("Res_ExtIntegrate", resExtIntegrate); model.addAttribute("resMainInfoId", resMainInfoId); //获取关联基础底图资源名称 if(resExtIntegrate.getRefbasemapid() != null) { Res_MainInfo res_mainInfo1 = resMainInfoService.selectByPrimaryKey(resExtIntegrate.getRefbasemapid()); String name = res_mainInfo1.getTitle(); model.addAttribute("baseMapLayerName",name); } //获取关联业务图层资源名称 if(resExtIntegrate.getReflayerid() != null) { Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resExtIntegrate.getReflayerid()); String name = res_mainInfo.getTitle(); model.addAttribute("reflayername",name); } Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resMainInfoId); model.addAttribute("resMainInfo",res_mainInfo); if(resExtIntegrate.getRendermode() != null && resExtIntegrate.getRendermode().equals("统计图")){ isSetChart = 1; } serverUrl = resExtIntegrate.getServerurl(); if(resExtIntegrate.getResolution() != null && resExtIntegrate.getResolution().length() != 0){ String resolution = resExtIntegrate.getResolution(); resolutionBen = resolution.substring(0,resolution.indexOf("X")); resolutionEnd = resolution.substring(resolution.indexOf("X")+1,resolution.length()); } } else { Res_ExtIntegrate resExtIntegrate1 = new Res_ExtIntegrate(); model.addAttribute("Res_ExtIntegrate", resExtIntegrate1); model.addAttribute("resMainInfo",new Res_MainInfo()); } model.addAttribute("isSetChart", isSetChart); model.addAttribute("serverUrl", serverUrl); model.addAttribute("resolutionBen", resolutionBen); model.addAttribute("resolutionEnd", resolutionEnd); if(SecurityUtils.getSubject().isPermitted("org_user_admin")) { //判断当前用户是否是管理员,是管理员或是未提交的资源才可以修改资源相关信息 model.addAttribute("admin",true); } else { model.addAttribute("admin",false); } return "ResManage/ResRegister/ExtIntegrate"; } /** 根据id 删除系统资源扩展列表功能*/ @ResponseBody @RequestMapping("/resExtIntegrate/deleteByPrimaryKey") public int deleteByPrimaryKey(int resourceid) { return resExtIntegrateService.deleteByPrimaryKey(resourceid); } @ResponseBody @RequestMapping("/resExtIntegrate/insert") public int insert(Res_ExtIntegrate record) { return resExtIntegrateService.insert(record); } /** * 新增或更新 * @param record * @return */ @ResponseBody @RequestMapping("/resExtIntegrate/insertSelectiveAndUpdate") @LogAction("资源管理,资源发布,资源修改,修改|zy") public int insertSelectiveAndUpdate(Res_ExtIntegrate record) { Res_ExtIntegrate resExtIntegrate=resExtIntegrateService.selectByPrimaryKey(record.getResourceid()); if(record.getServerurl() != null && record.getServerurl().length() > 0){ record.setServerurl(StringEscapeUtils.unescapeHtml(record.getServerurl())); } if(resExtIntegrate==null){ //添加 if(record.getIntegratetype().equals("页面集成")) { String showmodel = record.getShowmodel(); int id = record.getResourceid(); String url = record.getServerurl(); String type = record.getIntegratetype(); Res_ExtIntegrate res_extIntegrate = new Res_ExtIntegrate(); res_extIntegrate.setResourceid(id); res_extIntegrate.setIntegratetype(type); res_extIntegrate.setServerurl(url); res_extIntegrate.setShowmodel(showmodel); res_extIntegrate.setResolution(record.getResolution()); return resExtIntegrateService.insertSelective(res_extIntegrate); } if(record.getIntegratetype().equals("数据集成")) { if (record.getShowmodel() != null) { record.setShowmodel(null); record.setResolution(null); } return resExtIntegrateService.insertSelective(record); } }else { //更新 if(record.getIntegratetype().equals("页面集成")) { String showmodel = record.getShowmodel(); int id = record.getResourceid(); String url = record.getServerurl(); String type = record.getIntegratetype(); Res_ExtIntegrate res_extIntegrate = new Res_ExtIntegrate(); res_extIntegrate.setResourceid(id); res_extIntegrate.setIntegratetype(type); res_extIntegrate.setServerurl(url); res_extIntegrate.setShowmodel(showmodel); res_extIntegrate.setResolution(record.getResolution()); return resExtIntegrateService.updateByPrimaryKeyWithBLOBs(res_extIntegrate); } if(record.getIntegratetype().equals("数据集成")) { if (resExtIntegrate.getShowmodel() != null) { //集成类型改变,如果数据库的值不为空则清空 record.setShowmodel(null); record.setResolution(null); } if(resExtIntegrate.getChartmodel() != null) { record.setChartmodel(resExtIntegrate.getChartmodel()); } if(resExtIntegrate.getChartheight() != null) { record.setChartheight(resExtIntegrate.getChartheight()); } if(resExtIntegrate.getChartwidth() != null) { record.setChartwidth(resExtIntegrate.getChartwidth()); } return resExtIntegrateService.updateByPrimaryKeyWithBLOBs(record); } } return 0; } @ResponseBody @RequestMapping("/resExtIntegrate/insertSelective") public int insertSelective(Res_ExtIntegrate record) { return resExtIntegrateService.insertSelective(record); } @ResponseBody @RequestMapping("/resExtIntegrate/selectByPrimaryKey") public Res_ExtIntegrate selectByPrimaryKey(int resourceid) { return resExtIntegrateService.selectByPrimaryKey(resourceid); } @ResponseBody @RequestMapping("/resExtIntegrate/updateByPrimaryKeySelective") public int updateByPrimaryKeySelective(Res_ExtIntegrate record) { return resExtIntegrateService.updateByPrimaryKeySelective(record); } @ResponseBody @RequestMapping("/resExtIntegrate/updateByPrimaryKeyWithBLOBs") public int updateByPrimaryKeyWithBLOBs(Res_ExtIntegrate record) { return resExtIntegrateService.updateByPrimaryKeyWithBLOBs(record); } @ResponseBody @RequestMapping("/resExtIntegrate/updateByPrimaryKey") public int updateByPrimaryKey(Res_ExtIntegrate record) { return resExtIntegrateService.updateByPrimaryKey(record); } /** * 获取关联业务图层图层字段列表 * @param ResourceId 业务图层资源ID * @return */ @ResponseBody @RequestMapping("/resExtIntegrate/getGLTCFiled") public String getGLTCFiled(Integer ResourceId) { try { Res_ExtMapUrl resExtMapUrl = resExtMapUrlService.queryFirstOrderByResId(ResourceId); if (resExtMapUrl != null) { if (resExtMapUrl.getServerurl() != null && !resExtMapUrl.getServerurl().isEmpty()) { String url = resExtMapUrl.getServerurl().substring(resExtMapUrl.getServerurl().lastIndexOf("//") + 2); if (url != null && !url.isEmpty()) { String filedList = GetYWTCFiled(resExtMapUrl.getServerurl()); return filedList; } } } } catch(Exception e) { return "[]"; } return "[]"; } /** * 获取图层字段 * @param ServerURL 服务地址 * @return */ public String GetYWTCFiled(String ServerURL) { try { StringBuilder sb = new StringBuilder(); ServerURL = ServerURL + "/query?where=1%3D1&outFields=*&returnGeometry=false&f=pjson"; String jsonStr = HttpOperateUtils.httpGet(ServerURL.trim()); if (jsonStr != null && !jsonStr.isEmpty()) { JSONObject item = JSONObject.parseObject(jsonStr); JSONObject fieldAliases = item.getJSONObject("fieldAliases");//获取图层字段及字段别名列表 if(fieldAliases != null && !fieldAliases.isEmpty()) { Map map = fieldAliases.getInnerMap(); for(Map.Entry entry: map.entrySet()) { if(!sb.toString().isEmpty()) sb.append(","); sb.append("{name:'" + entry.getKey() + "', alias: '" + entry.getValue().toString() + "'}"); } } } return "[" + sb.toString() + "]"; } catch(IOException e) { return "[]"; } } //设置Chart模型 @ResponseBody @RequestMapping("/resExtIntegrate/updateChartInfo") public int updateChartInfo(Res_ExtIntegrate record) { int result = resExtIntegrateService.updateChartInfo(record); return result; } /** * 获取Chart模型 * @param serverurl 服务地址 * @return */ @ResponseBody @RequestMapping("/resExtIntegrate/getChartInfo") public String getChartInfo(String serverurl,Integer resourceid) { //只有地址解析出数据才显示按钮 StringBuilder urlResult = new StringBuilder(); Res_ExtIntegrate resExtIntegrate = resExtIntegrateService.selectByPrimaryKey(resourceid); serverurl = serverurl != null ? StringEscapeUtils.unescapeHtml(serverurl) : ""; if(resExtIntegrate != null && resExtIntegrate.getServerurl().equals(serverurl) && resExtIntegrate.getChartmodel()!=null && !resExtIntegrate.getChartmodel().isEmpty()){ urlResult.append("{model:"+resExtIntegrate.getChartmodel()); urlResult.append(",width:"+resExtIntegrate.getChartwidth()); urlResult.append(",height:"+resExtIntegrate.getChartheight()+"}"); }else{ try { urlResult.append(httpGet(serverurl)); } catch (Exception e) { } } return urlResult.toString(); } }