package com.landtool.lanbase.modules.res.controller; import java.io.File; import java.io.IOException; import java.net.URLDecoder; import java.net.URLEncoder; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.servlet.http.HttpServletRequest; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; 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 org.springframework.web.multipart.MultipartFile; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.serializer.SerializerFeature; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import com.landtool.lanbase.common.annotation.LogAction; import com.landtool.lanbase.common.annotation.SysLog; import com.landtool.lanbase.common.map.EsbToken; import com.landtool.lanbase.common.utils.AttachmentUtils; import com.landtool.lanbase.common.utils.FileUtils; import com.landtool.lanbase.common.utils.HttpOperateUtils; import com.landtool.lanbase.common.utils.HttpUtils; import com.landtool.lanbase.common.utils.JpinyinUtils; import com.landtool.lanbase.common.utils.Result; import com.landtool.lanbase.config.SysTemPropertyConfig; import com.landtool.lanbase.modules.api.utils.PageBean; import com.landtool.lanbase.modules.org.entity.OrgUser; import com.landtool.lanbase.modules.res.entity.GraphicStyle; import com.landtool.lanbase.modules.res.entity.Res_Catalog; import com.landtool.lanbase.modules.res.entity.Res_EchartsConfing; import com.landtool.lanbase.modules.res.entity.Res_ExtBusinessLayer; import com.landtool.lanbase.modules.res.entity.Res_ExtMapUrl; import com.landtool.lanbase.modules.res.entity.Res_ExtThemeMap; import com.landtool.lanbase.modules.res.entity.Res_MainInfo; import com.landtool.lanbase.modules.res.entity.Res_SymbolLibrary; import com.landtool.lanbase.modules.res.entity.Res_Theme_Module; import com.landtool.lanbase.modules.res.entity.JSONModels.ServiceConfig; import com.landtool.lanbase.modules.res.service.ResBusinessRefService; import com.landtool.lanbase.modules.res.service.ResEchartsCofingService; import com.landtool.lanbase.modules.res.service.ResExtBusinessLayerService; import com.landtool.lanbase.modules.res.service.ResExtMapUrlService; import com.landtool.lanbase.modules.res.service.ResExtThemeMapService; import com.landtool.lanbase.modules.res.service.ResMainInfoService; import com.landtool.lanbase.modules.res.service.ResQueryAroundService; import com.landtool.lanbase.modules.res.service.ResSymbolLibraryService; import com.landtool.lanbase.modules.res.service.ResThemeModuleService; import com.landtool.lanbase.modules.sys.controller.AbstractController; import com.landtool.lanbase.modules.sys.service.SysFieldvalueService; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; @Controller @RequestMapping("res/common") public class CommonController extends AbstractController { @Autowired private SysTemPropertyConfig sysConfig; @Autowired private SysFieldvalueService FieldUtils; @Autowired private ResMainInfoService resMainInfoService; @Autowired private ResQueryAroundService resQueryAroundService; @Autowired private ResBusinessRefService resBusinessRefService; @Autowired private ResSymbolLibraryService resSymbolLibraryService; @Autowired private ResExtMapUrlService resExtMapUrlService; @Autowired private ResExtThemeMapService resExtThemeMapService; @Autowired private ResExtBusinessLayerService resExtBusinessLayerService; @Autowired private ResEchartsCofingService resEchartsCofingService; @Autowired private ResThemeModuleService resThemeModuleService; @RequestMapping("/resource_set_zbcx") public String resource_set_zbcx(Integer resourceid, Model model) { model.addAttribute("resourceid", resourceid); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); return "common/resource_set_zbcx"; } @RequestMapping("/resource_set_gltc") public String resource_set_gltc(Integer resourceid, Model model) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); return "common/resource_set_gltc"; } //图形设置 @RequestMapping("/resource_set_TuXin") public String resource_set_TuXin(Integer resourceid, Model model) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid); model.addAttribute("resMainInfo", res_mainInfo); return "common/resource_set_TuXin"; } //添加图形设置面板 //id表示 要编辑的行,如果有id的话,那么表示编辑 @RequestMapping("/resource_add_TuXin") public String resource_add_TuXin(Integer resourceid, Model model, Integer id) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); List resExtMapUrlList = resExtMapUrlService.selectByCondition(resourceid); String url = ""; List List = new ArrayList(); for (int i = 0; i < resExtMapUrlList.size(); i++) { url = resExtMapUrlList.get(0).getServerurl(); } try { String TokenResponse = HttpOperateUtils.httpGet(url + "?f=pjson"); JSONObject jsStr = JSONObject.parseObject(TokenResponse); JSONArray obj = JSONArray.parseArray(jsStr.get("fields").toString()); for (int i = 0; i < obj.size(); i++) { List.add(obj.getJSONObject(i).getString("name")); } } catch (IOException e) { e.printStackTrace(); } model.addAttribute("list", List); GraphicStyle graphicStyle = new GraphicStyle(); if (id != null) { Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid); String[] Graphic = res_mainInfo.getGraphicStyle().split("\\|"); JSONObject jsStr = JSONObject.parseObject(Graphic[id - 1]); graphicStyle.setType(jsStr.getString("type")); graphicStyle.setDisplayMode(jsStr.getString("displayMode")); graphicStyle.setClassfield(jsStr.getString("classfield")); graphicStyle.setValueField(jsStr.getString("ValueField")); graphicStyle.setStatisticalMethod(jsStr.getString("StatisticalMethod")); } model.addAttribute("graphicStyle", graphicStyle); model.addAttribute("hangshu", id); model.addAttribute("resourceid", resourceid); return "common/resource_add_TuXin"; } //图形保存设置 @ResponseBody @RequestMapping("/TuXingConfigAdd") public String TuXingConfigAdd(Integer resourceid, Model model, GraphicStyle graphicStyle, Integer hangshu) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid); //新增 int count = 0; if (hangshu == null) { String graphic = ""; if (res_mainInfo.getGraphicStyle() == null || !res_mainInfo.getGraphicStyle().equals("")) { graphic += "|"; } graphic += "{'type':" + "'" + graphicStyle.getType() + "'" + ","; graphic += "'displayMode':" + "'" + graphicStyle.getDisplayMode() + "'" + ","; graphic += "'classfield':" + "'" + graphicStyle.getClassfield() + "'" + ","; graphic += "'ValueField':" + "'" + graphicStyle.getValueField() + "'" + ","; graphic += "'StatisticalMethod':" + "'" + graphicStyle.getStatisticalMethod() + "'}"; Res_MainInfo res_mainInfo1 = new Res_MainInfo(); res_mainInfo1.setResourceid(resourceid); if (res_mainInfo.getGraphicStyle() == null) { res_mainInfo1.setGraphicStyle(graphic); } else { res_mainInfo1.setGraphicStyle(res_mainInfo.getGraphicStyle() + graphic); } count = resMainInfoService.updateByPrimaryKeySelective(res_mainInfo1); } else { String[] Graphic = res_mainInfo.getGraphicStyle().split("\\|"); String graphic = ""; graphic += "{'type':" + "'" + graphicStyle.getType() + "'" + ","; graphic += "'displayMode':" + "'" + graphicStyle.getDisplayMode() + "'" + ","; graphic += "'classfield':" + "'" + graphicStyle.getClassfield() + "'" + ","; graphic += "'ValueField':" + "'" + graphicStyle.getValueField() + "'" + ","; graphic += "'StatisticalMethod':" + "'" + graphicStyle.getStatisticalMethod() + "'}"; //对应行数里面的值替换 Graphic[hangshu - 1] = graphic; StringBuilder rsb = new StringBuilder(); //然后对数组进行循环,拼接成字符串 for (int i = 0; i < Graphic.length; i++) { JSONObject jsStr = JSONObject.parseObject(Graphic[i]); if (i != 0) { rsb.append("|"); } int id = i + 1; rsb.append("{"); rsb.append("'type':'" + jsStr.getString("type") + "'"); rsb.append(",'id':'" + id + "'"); rsb.append(",'displayMode':'" + jsStr.getString("displayMode") + "'"); rsb.append(",'classfield':'" + jsStr.getString("classfield") + "'"); rsb.append(",'ValueField':'" + jsStr.getString("ValueField") + "'"); rsb.append(",'StatisticalMethod':'" + jsStr.getString("StatisticalMethod") + "'");//资源类型 rsb.append("}"); } Res_MainInfo res_mainInfo1 = new Res_MainInfo(); res_mainInfo1.setResourceid(resourceid); res_mainInfo1.setGraphicStyle(rsb.toString()); count = resMainInfoService.updateByPrimaryKeySelective(res_mainInfo1); } model.addAttribute("resMainInfo", res_mainInfo); return "{'count':'" + count + "'}"; } //图形删除设置 @ResponseBody @RequestMapping("/TuXinCongiDelect") public String TuXinCongiDelect(Integer resourceid, Model model, Integer hangshu) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid); int count = 0; String[] Graphic = res_mainInfo.getGraphicStyle().split("\\|"); Graphic = deleteMethod(hangshu - 1, Graphic); StringBuilder rsb = new StringBuilder(); //然后对数组进行循环,拼接成字符串 for (int i = 0; i < Graphic.length; i++) { JSONObject jsStr = JSONObject.parseObject(Graphic[i]); if (i != 0) { rsb.append("|"); } int id = i + 1; rsb.append("{"); rsb.append("'type':'" + jsStr.getString("type") + "'"); rsb.append(",'id':'" + id + "'"); rsb.append(",'displayMode':'" + jsStr.getString("displayMode") + "'"); rsb.append(",'classfield':'" + jsStr.getString("classfield") + "'"); rsb.append(",'ValueField':'" + jsStr.getString("ValueField") + "'"); rsb.append(",'StatisticalMethod':'" + jsStr.getString("StatisticalMethod") + "'");//资源类型 rsb.append("}"); } Res_MainInfo res_mainInfo1 = new Res_MainInfo(); res_mainInfo1.setResourceid(resourceid); res_mainInfo1.setGraphicStyle(rsb.toString()); count = resMainInfoService.updateByPrimaryKeySelective(res_mainInfo1); model.addAttribute("resMainInfo", res_mainInfo); return "{'count':'" + count + "'}"; } public String[] deleteMethod(int index, String array[]) { //数组的删除其实就是覆盖前一位 String[] arrNew = new String[array.length - 1]; for (int i = index; i < array.length - 1; i++) { array[i] = array[i + 1]; } System.arraycopy(array, 0, arrNew, 0, arrNew.length); return arrNew; } //读取图形设置 @ResponseBody @RequestMapping("/TuXingConfigSelectAll") public String TuXingConfigSelectAll(Integer resourceid) { Res_MainInfo res_mainInfo = resMainInfoService.selectByPrimaryKey(resourceid); String[] Graphic = {}; if (res_mainInfo != null && res_mainInfo.getGraphicStyle() != null) { Graphic = res_mainInfo.getGraphicStyle().split("\\|"); } //查询arg url. List resExtMapUrlList = resExtMapUrlService.selectByCondition(resourceid); String url = ""; List List = new ArrayList(); for (int i = 0; i < resExtMapUrlList.size(); i++) { url = resExtMapUrlList.get(0).getServerurl(); } // http://192.168.0.140:6080/arcgis/rest/services/onemapjm/MapServer/26/query 加上query才能查询地图字段 url = url + "/query"; StringBuilder rsb = new StringBuilder(); rsb.append("{'totalCount':'" + Graphic.length + "','url':'" + url + ""); rsb.append("','topics':["); for (int i = 0; i < Graphic.length; i++) { JSONObject jsStr = JSONObject.parseObject(Graphic[i]); if (i != 0) { rsb.append(","); } int id = i + 1; rsb.append("{"); rsb.append("'type':'" + jsStr.getString("type") + "'"); rsb.append(",'id':'" + id + "'"); rsb.append(",'displayMode':'" + jsStr.getString("displayMode") + "'"); rsb.append(",'classfield':'" + jsStr.getString("classfield") + "'"); rsb.append(",'ValueField':'" + jsStr.getString("ValueField") + "'"); rsb.append(",'StatisticalMethod':'" + jsStr.getString("StatisticalMethod") + "'");//资源类型 rsb.append("}"); } rsb.append("]}"); return rsb.toString(); } //读取图形配置 //http://127.0.0.1:8082/res/common/TuXingConfig @RequestMapping("/TuXingConfig") public String TuXingConfig(Integer resourceid, Model model) { List resExtMapUrlList = resExtMapUrlService.selectByCondition(resourceid); String url = ""; List List = new ArrayList(); for (int i = 0; i < resExtMapUrlList.size(); i++) { url = resExtMapUrlList.get(0).getServerurl(); } // http://192.168.0.140:6080/arcgis/rest/services/onemapjm/MapServer/26/query 加上query才能查询地图字段 url = url + "/query"; model.addAttribute("url", url); model.addAttribute("resourceid", resourceid); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); return "common/TuXingConfig"; } //添加资源 - 多选 @RequestMapping("/resource_select") public String resource_select(Model model, String flag, Integer resourceid) { model.addAttribute("flag", flag); model.addAttribute("resourceid", resourceid); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("lanbaseurl", sysConfig.getApiServer()); // 获取数据来源表 HashMap DataSourceList = FieldUtils.getDataSourceList();// 获取数据来源列表 model.addAttribute("DataSourceList", DataSourceList); return "common/resource_select"; } /** * 添加关联图层列表(弃用,改用树) * * @param flag * @param resMainInfo * @param pageBean * @return */ @ResponseBody @RequestMapping("/getResourceSelect") public String getResourceSelect(String flag, Res_MainInfo resMainInfo, PageBean pageBean) { Page page = PageHelper.startPage(pageBean.getPage(), pageBean.getLimit()); List res_mainInfos = null; if (flag.equals("zbcx")) { res_mainInfos = resQueryAroundService.getResourceSelectZBCX(resMainInfo); } else if (flag.equals("gltc")) { res_mainInfos = resBusinessRefService.getResourceSelectGLTC(resMainInfo); } int countNums = (int) ((Page) res_mainInfos).getTotal(); PageBean pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums); pageData.setItems(res_mainInfos); LinkedHashMap resourceTypeList = FieldUtils.getFieldListByKey("ResourceType");//获取资源类型列表 StringBuilder rsb = new StringBuilder(); rsb.append("{'totalCount':'" + countNums); rsb.append("','topics':["); for (int i = 0; i < res_mainInfos.size(); i++) { if (i != 0) { rsb.append(","); } rsb.append("{"); rsb.append("'TITLE':'" + res_mainInfos.get(i).getTitle() + "'"); rsb.append(",'DATASOURCES':'" + res_mainInfos.get(i).getDatasources() + "'"); rsb.append(",'RESOURCEID':'" + res_mainInfos.get(i).getResourceid() + "'"); rsb.append(",'RESOURCECLASS':'" + resourceTypeList.get(res_mainInfos.get(i).getResourceclass()) + "'");//资源类型 rsb.append("}"); } rsb.append("]}"); return rsb.toString(); } /** * 获取资源设置树 */ @ResponseBody @RequestMapping("/getResourceSelectTree") public String getResourceSelectTree(String flag, Res_MainInfo resMainInfo, String parentid) { StringBuilder resCatalogJson = new StringBuilder(); Map map = new HashMap<>(); map.put("resourceid", resMainInfo.getResourceid()); map.put("title", resMainInfo.getTitle()); map.put("resourceclass", resMainInfo.getResourceclass()); map.put("datasources", resMainInfo.getDatasources()); map.put("parentid", parentid); List res_mainInfos = null; List resCatalogList = null; if (flag.equals("zbcx")) { resCatalogList = resQueryAroundService.getResourceZBCXCatalog(map); res_mainInfos = resQueryAroundService.getResourceZBCXCatalogList(map); } else if (flag.equals("gltc")) { resCatalogList = resBusinessRefService.getResourceGLTCCatalog(map); res_mainInfos = resBusinessRefService.getResourceGLTCCatalogList(map); } // 循环构造子目录节点 List> maps = new LinkedList<>(); for (Res_Catalog resCatalog : resCatalogList) { if (!"".equals(resCatalogJson.toString())) { resCatalogJson.append(','); } Map catlogmap = new HashMap<>(); catlogmap.put("id", resCatalog.getCatlogid()); catlogmap.put("name", resCatalog.getTitle()); catlogmap.put("title", resCatalog.getTitle()); catlogmap.put("isParent", true); catlogmap.put("iconOpen", "/image/classicons/folderOpen.png"); catlogmap.put("iconClose", "/image/classicons/folder.png"); maps.add(catlogmap); // resCatalogJson.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle() + "',title:'" + resCatalog.getTitle() + "',isParent: true,iconOpen:'/image/classicons/folderOpen.png',iconClose:'/image/classicons/folder.png'}"); } // 循环构造资源节点 for (Res_MainInfo resMainInfo1 : res_mainInfos) { if (!"".equals(resCatalogJson.toString())) { resCatalogJson.append(','); } Map ctalogmap = new HashMap<>(); ctalogmap.put("id", "ZiYuan_" + resMainInfo1.getResourceid()); ctalogmap.put("name", resMainInfo1.getTitle()); ctalogmap.put("title", resMainInfo1.getTitle()); ctalogmap.put("isParent", false); ctalogmap.put("icon", "/image/classicons/"+ resMainInfo1.getResourceclass() +".png"); maps.add(ctalogmap); // resCatalogJson.append("{id: 'ZiYuan_" + resMainInfo1.getResourceid() + "',name:'" + resMainInfo1.getTitle() + "', title: '" + resMainInfo1.getDatasources() + "',isParent:false,icon:'/image/classicons/"+ resMainInfo1.getResourceclass() +".png'}"); } return JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue); } /** * 自动补全输入首字母查询 * * @param keyWord * @return */ @ResponseBody @GetMapping("/findPinyinByKeyWord") public String[] findpinyinByKeyWord(@RequestParam(name = "keyWord") String keyWord, String flag, Integer resourceid) { keyWord = URLDecoder.decode(keyWord); Map map = new HashMap(); map.put("resourceid", resourceid); map.put("keyWord", keyWord); List list = null; if (flag.equals("zbcx")) { list = resQueryAroundService.getResourceZBCXCatalogList(map); } else if (flag.equals("gltc")) { list = resBusinessRefService.getResourceGLTCCatalogList(map); } String[] arr = new String[list.size()]; for (int i = 0; i < list.size(); i++) { String title = list.get(i).getTitle(); arr[i] = title; } return arr; } /** * 地图范围框选 * * @param drawType 地图绘制类型(point: 点 extent: 范围) * @param callbackFun 绘制回调类型(处理同一页面多个调用类型区分) * @param model * @return */ @RequestMapping("/obtainExtentMapViewer") public String obtainExtentMapViewer(String drawType, String callbackFun, Model model) { model.addAttribute("drawType", drawType);//绘制类型 model.addAttribute("callbackFun", callbackFun);//回调类型 model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("obtainExtentMapUrl", sysConfig.getObtainExtentMapUrl());//框选地图底图URL return "common/obtainExtentMapViewer"; } /** * 符号库风格更新 * * @return */ @ResponseBody @RequestMapping("/updateSymbolLibrary") public String updateSymbolLibrary() { String pointSymbolUrl = "http://ocean-data.nmdis.com/arcgis/rest/services/JCDL/fuhao2/MapServer/0"; //点符号服务地址 String polylineSymbolUrl = "http://ocean-data.nmdis.com/arcgis/rest/services/JCDL/fuhao2/MapServer/1"; //线符号服务地址 String polygonSymbolUrl = "http://ocean-data.nmdis.com/arcgis/rest/services/JCDL/fuhao2/MapServer/2"; //面符号服务地址 String[][] arr = new String[][]{{pointSymbolUrl, "点"}, {polylineSymbolUrl, "线"}, {polygonSymbolUrl, "面"}}; String resultMsg = "更新成功!"; String errorMsg = ""; for (int i = 0; i < arr.length; i++) { try { String ResultJsonStr = HttpOperateUtils.httpGet(arr[i][0].trim() + "?f=json"); JSONObject drawingInfo = JSONObject.parseObject(ResultJsonStr).getJSONObject("drawingInfo"); if (drawingInfo != null) { JSONObject renderer = drawingInfo.getJSONObject("renderer"); if (renderer != null) { JSONArray uniqueValueInfos = renderer.getJSONArray("uniqueValueInfos"); if (uniqueValueInfos != null) { for (int j = 0; j < uniqueValueInfos.size(); j++) { String FHID = uniqueValueInfos.getJSONObject(j).getString("label"); String SYMBOL = uniqueValueInfos.getJSONObject(j).getString("symbol"); Res_SymbolLibrary resSymbolLibrary = new Res_SymbolLibrary(); resSymbolLibrary.setFhid(FHID); resSymbolLibrary.setGeotype(arr[i][1]); Res_SymbolLibrary res_symbolLibrary = resSymbolLibraryService.getByIdAndGeoType(resSymbolLibrary);//获取符号库对应记录 if (res_symbolLibrary != null) { res_symbolLibrary.setSymbol(SYMBOL); resSymbolLibraryService.updateByPrimaryKey(res_symbolLibrary);//更新符号库对应记录符号风格 } } } } } } catch (IOException e) { errorMsg += arr[i][1] + ":" + e.getMessage() + "\r\n"; continue; } } if (errorMsg.isEmpty()) { return resultMsg; } else { return errorMsg; } } /** * 符号库管理 * * @return */ @RequestMapping("symbolLibrary/index") public String symbolLibraryIndex(Model model) { List mc = resSymbolLibraryService.getMC(); model.addAttribute("mclist", mc); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); return "manage/symbolLibrary/index"; } /** * 获取符号库列表 * * @param resSymbolLibrary * @param pageBean * @return */ @ResponseBody @RequestMapping("symbolLibrary/getlist") @RequiresPermissions("res:symbolLibrary:edit") @LogAction("资源管理,符号库管理,符号库列表查询,查询") public Result getList(Res_SymbolLibrary resSymbolLibrary, PageBean pageBean) { PageHelper.startPage(pageBean.getPage(), pageBean.getLimit()); List resSymbolLibraryList = resSymbolLibraryService.getList(resSymbolLibrary); int countNums = (int) ((Page) resSymbolLibraryList).getTotal(); PageBean pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums); pageData.setItems(resSymbolLibraryList); StringBuilder rsb = new StringBuilder(); rsb.append("{'totalCount':'" + countNums + "','topics':["); List> maps = new LinkedList<>(); for (int i = 0; i < resSymbolLibraryList.size(); i++) { Map map = new HashMap<>(); map.put("objectid", resSymbolLibraryList.get(i).getObjectid()); map.put("fhid", resSymbolLibraryList.get(i).getFhid()); map.put("mc", resSymbolLibraryList.get(i).getMc()); map.put("geotype", resSymbolLibraryList.get(i).getGeotype()); maps.add(map); // if (i != 0) rsb.append(","); // rsb.append("{'objectid':'" + resSymbolLibraryList.get(i).getObjectid() + "','fhid':'" + resSymbolLibraryList.get(i).getFhid() + "','mc':'" + resSymbolLibraryList.get(i).getMc() + "','geotype':'" + resSymbolLibraryList.get(i).getGeotype() + "'}"); } // rsb.append("]}"); return Result.ok().put("totalCount", countNums).put("topics", maps); } /** * 符号编辑页面 * * @param OBJECTID * @return */ @RequestMapping("symbolLibrary/edit") public String edit(Model model, int OBJECTID) { Res_SymbolLibrary resSymbolLibrary = resSymbolLibraryService.getById(OBJECTID);//获取符号信息 if (resSymbolLibrary == null) { resSymbolLibrary = new Res_SymbolLibrary(); } model.addAttribute("resSymbolLibrary", resSymbolLibrary); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); return "manage/symbolLibrary/edit"; } /** * 符号编辑保存 * * @param entity * @return */ @ResponseBody @RequestMapping("symbolLibrary/save") @LogAction("资源管理,符号库管理,符号库列表修改,修改") public String edit(Model model, Res_SymbolLibrary entity) { try { Res_SymbolLibrary resSymbolLibrary = resSymbolLibraryService.getById(entity.getObjectid());//获取符号信息 resSymbolLibrary.setSymbol(entity.getSymbol()); resSymbolLibraryService.updateByPrimaryKey(resSymbolLibrary); return "{success: true, msg: '保存成功!'}"; } catch (Exception e) { return "{success: false, msg: '" + e.getMessage() + "'}"; } } /** * 符号库符号展示地图页面 * * @param model * @param symbol * @param geotype * @return */ @RequestMapping("symbolLibrary/symbolmap") public String symbolmap(Model model, String symbol, String geotype) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("obtainExtentMapUrl", sysConfig.getObtainExtentMapUrl());//框选地图底图URL model.addAttribute("symbol", symbol); model.addAttribute("geotype", geotype); return "manage/symbolLibrary/symbolmap"; } //编辑器上传图片 @RequestMapping("/uploadueditorfile") public ResponseEntity> uploadueditorfile(@RequestParam(value = "upfile", required = false) MultipartFile file, HttpServletRequest request) {//value的名字一定要叫upfile,这是ueditor写好的参数名称 String fileName = file.getOriginalFilename(); String[] types = fileName.split("\\."); String type = types[types.length - 1]; String root = sysConfig.getUploadPath().replace("/", "\\"); String LinShiUrl = root + "\\ueditor"; String suffix = FileUtils.getSuffix(file.getOriginalFilename()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM"); String timePath = sdf.format(new Date().getTime()); timePath = timePath.replace("-", ""); String newFileName = AttachmentUtils.newFileName(suffix, LinShiUrl, timePath); File newFile = new File(newFileName); //临时文件处理 try { file.transferTo(newFile); } catch (Exception e) { e.printStackTrace(); } Map result = new HashMap(); result.put("state", "SUCCESS");// UEDITOR的规则:不为SUCCESS则显示state的内容 result.put("url", sysConfig.getUploadRootPath() + FileUtils.removePrefix(newFile.getAbsolutePath(), root).replace("\\", "/")); result.put("title", file.getOriginalFilename()); result.put("original", file.getOriginalFilename()); result.put("size", file.getSize()); result.put("type", type); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); return new ResponseEntity>(result, headers, HttpStatus.OK); } /** * 客户端获取Token * * @param resourceId 资源ID * @param request * @return */ @ResponseBody @RequestMapping("/getToken") public String getToken(int resourceId, HttpServletRequest request) { String result = ""; String callbackFunName = request.getParameter("callback"); if (callbackFunName == null || callbackFunName.isEmpty()) { callbackFunName = "callback"; } try { Long userid = ((OrgUser) SecurityUtils.getSubject().getPrincipal()).getUserid(); Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resourceId);//获取资源主表信息 if (resMainInfo != null) { boolean isPubzy = false; if (resMainInfo != null && resMainInfo.getSharprotocol().equals("完全公开")) { isPubzy = true; } 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() + "\""; } String token = EsbToken.getEsbUrl(serverUrl, userid.intValue(), request.getRemoteAddr(), resourceId, resMainInfo.getEspproxy(), sysConfig, subzyids, isPubzy, resMainInfo.getToken(), true); result = "{ \"success\": true, \"serverUrl\": " + serverUrl + ", \"token\": " + (token.isEmpty() ? "null" : "\"" + token + "\"") + "}"; } else { result = "{ \"success\": false, \"msg\": \"资源不存在!\" }"; } } catch (Exception e) { result = "{ \"success\": false, \"msg\": \"" + e.getMessage() + "\" }"; } return callbackFunName + "(" + result + ")"; } /** * 业务图层 - 图表设置页面 * * @param resourceid 资源ID * @param model * @param name 变量 如:var1,table1 * @param type 所属类别 如:vars,tables * @return */ @RequestMapping("/serviceconfig") public String setServiceConfig(Integer resourceid, Model model, String name, String type) { List resExtMapUrlList = resExtMapUrlService.selectByCondition(resourceid); model.addAttribute("resourceid", resourceid); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("jspwebroot", sysConfig.getPubzyWebRoot().replace("javapubzy/", ""));// 临时处理 //获取list JSONArray chartsList = new JSONArray(); JSONArray tablesList = new JSONArray(); JSONArray varsList = new JSONArray(); Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid); if (resExtBusinessLayer != null && resExtBusinessLayer.getServiceConfig() != null && !resExtBusinessLayer.getServiceConfig().equals("")) { JSONObject obj = JSONObject.parseObject(resExtBusinessLayer.getServiceConfig()); for (int i = 0; i < obj.size(); i++) { JSONArray object = null; //每次只取一个类 if (i == 0) { if (obj.getJSONArray("vars") != null) { //常量 object = obj.getJSONArray("vars"); if (object != null) { for (int j = 0; j < object.size(); j++) { String key = object.getJSONObject(j).getString("name"); String explain = object.getJSONObject(j).getJSONObject(key).getString("explain"); if(explain == null) { explain = ""; } String listKey = "{\"key\":\"" + key + "\",\"explain\":\"" + explain + "\"}"; varsList.add(JSONObject.parseObject(listKey)); } } } } if (i == 1) { if (obj.getJSONArray("tables") != null) { //表格 object = obj.getJSONArray("tables"); if (object != null) { for (int j = 0; j < object.size(); j++) { String key = object.getJSONObject(j).getString("name"); String explain = object.getJSONObject(j).getJSONObject(key).getString("explain"); if(explain == null) { explain = ""; } String listKey = "{\"key\":\"" + key + "\",\"explain\":\"" + explain + "\"}"; tablesList.add(JSONObject.parseObject(listKey)); } } } } if (i == 2) { if (obj.getJSONArray("charts") != null) { //图表 object = obj.getJSONArray("charts"); if (object != null) { for (int j = 0; j < object.size(); j++) { String key = object.getJSONObject(j).getString("name"); String explain = object.getJSONObject(j).getJSONObject(key).getString("explain"); if(explain == null) { explain = ""; } String listKey = "{\"key\":\"" + key + "\",\"explain\":\"" + explain + "\"}"; chartsList.add(JSONObject.parseObject(listKey)); } } } } } } model.addAttribute("chartsList", chartsList); model.addAttribute("tablesList", tablesList); model.addAttribute("varsList", varsList); String serviceHTML = ""; if(resExtBusinessLayer != null && resExtBusinessLayer.getServiceHTML() != null && !resExtBusinessLayer.getServiceHTML().equals("")) { serviceHTML = replaceServiceHTML(resExtBusinessLayer.getServiceHTML(), resourceid, "htmlToChar"); } model.addAttribute("serviceHTML", serviceHTML); model.addAttribute("systemName", sysConfig.getAppFullName()); return "common/ServiceConfig"; } // settype0是表示业务图层的 1是表示一张图的 @RequestMapping("/addserviceconfig") public String addSetServiceConfig(Integer resourceid, Model model, String name, String type,Integer moduleid,Integer settype,String associationlayer) { String url = ""; List List = new ArrayList(); Res_ExtBusinessLayer resExtBusinessLayer = null; Res_Theme_Module resThemeModule = null; Integer thismoduleid = moduleid != null?moduleid:0; String token = ""; if(settype != null && settype == 0) { //业务图层 resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid); List resExtMapUrlList = resExtMapUrlService.selectByCondition(resourceid); if (resExtMapUrlList.size() > 0) { url = resExtMapUrlList.get(0).getServerurl(); Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(resourceid); boolean isPubzy = false; if (resMainInfo != null && !resMainInfo.getSharprotocol().equals("完全公开")) { token = EsbToken.getEsbUrl(url, getUserId().intValue(), sysConfig.getIpHost(), resourceid, resMainInfo.getEspproxy(), sysConfig, null, isPubzy, resMainInfo.getToken(), true); } } }else { //一张图 resThemeModule = resThemeModuleService.selectByid(moduleid); if(resThemeModule != null && resThemeModule.getServiceconfig() !=null && !resThemeModule.getServiceconfig().trim().equals("")){ if(type.equals("tables")){ name = "table1"; }else{ name = "chart1"; } } url = java.net.URLDecoder.decode(associationlayer); } if (url != null && !"".equals(url)) { try { if(url.indexOf("?")!=-1){ if(!"".equals(token)) { url += "&f=pjson&token=" + token; } else { url += "&f=pjson"; } }else{ if(!"".equals(token)) { url +="?f=pjson&token=" + token; } else { url += "?f=pjson"; } } String TokenResponse = ""; //ESB代理的地址需要解密 if(HttpOperateUtils.isgzip(url)) { TokenResponse = HttpUtils.getGZip(url); } else { TokenResponse = HttpOperateUtils.httpGet(url); } JSONObject jsStr = JSONObject.parseObject(TokenResponse); if(jsStr.containsKey("fields")) { JSONArray obj = JSONArray.parseArray(jsStr.get("fields").toString()); for (int i = 0; i < obj.size(); i++) { List.add(obj.getJSONObject(i).getString("name")); } } } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } model.addAttribute("list", List); model.addAttribute("resourceid", resourceid); model.addAttribute("moduleid", thismoduleid); model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("jspwebroot", sysConfig.getPubzyWebRoot().replace("javapubzy/", ""));// 临时处理 model.addAttribute("settype", settype); ServiceConfig serviceConfig = new ServiceConfig(); String key = ""; List fieldsList = new ArrayList(); StringBuilder str = new StringBuilder(); String fileds = "[]"; //编辑配置相关信息 if (name != null && !name.equals("")) { //判断是属于哪一项,获取对应的json if (name.substring(0, 1).equals("v")) { key = "vars"; } if (name.substring(0, 1).equals("t")) { key = "tables"; } if (name.substring(0, 1).equals("c")) { key = "charts"; } if ((settype == 0 && resExtBusinessLayer != null && resExtBusinessLayer.getServiceConfig() != null) || (settype == 1 && resThemeModule != null && resThemeModule.getServiceconfig() != null && !resThemeModule.getServiceconfig().trim().equals(""))) { JSONObject obj = JSONObject.parseObject(settype == 0 ?resExtBusinessLayer.getServiceConfig():resThemeModule.getServiceconfig()); JSONObject newobj = null; boolean flag = false; if (obj.getJSONArray(key) != null) { //获取所要编辑的项所在的json数组 JSONArray jsonArray = obj.getJSONArray(key); if (jsonArray != null) { //遍历数组,如果key一致则取出相关配置信息,退出循环 for (int j = 0; j < jsonArray.size(); j++) { org.json.JSONObject jsonObject = new org.json.JSONObject(jsonArray.getJSONObject(j)); Iterator iterator = jsonObject.keys(); while (iterator.hasNext()) { String skey = (String) iterator.next(); if (skey.equals(name)) { newobj = JSONObject.parseObject(jsonArray.getString(j)); newobj = JSONObject.parseObject(newobj.getString(name)); if (key.equals("vars")) { serviceConfig.setField(newobj.getString("field")); serviceConfig.setFunc(newobj.getString("StatisticalMethod")); serviceConfig.setWhere(newobj.getString("where")); serviceConfig.setExplain(newobj.getString("explain")); serviceConfig.setDecimalDigits(newobj.getString("DecimalDigits")); serviceConfig.setUnitConversion(newobj.getString("UnitConversion")); } if (key.equals("tables")) { serviceConfig.setGroupby(newobj.getString("groupby")); serviceConfig.setGroupbyalias(newobj.getString("groupbyalias")); serviceConfig.setWhere(newobj.getString("where")); serviceConfig.setExplain(newobj.getString("explain")); serviceConfig.setDecimalDigits(newobj.getString("DecimalDigits")); serviceConfig.setUnitConversion(newobj.getString("UnitConversion")); JSONArray tableArray = newobj.getJSONArray("list"); fileds =newobj.getString("list"); } if (key.equals("charts")) { serviceConfig.setId(newobj.getString("id")); serviceConfig.setClassfield(newobj.getString("classField")); serviceConfig.setStatisticalmethod(newobj.getString("StatisticalMethod")); serviceConfig.setTitle(newobj.getString("title")); serviceConfig.setType(newobj.getString("type")); serviceConfig.setDisplaymode(newobj.getString("displayMode")); serviceConfig.setOption(newobj.getString("option")); serviceConfig.setValuefield(newobj.getString("ValueField")); serviceConfig.setWhere(newobj.getString("where")); serviceConfig.setExplain(newobj.getString("explain")); serviceConfig.setDecimalDigits(newobj.getString("DecimalDigits")); serviceConfig.setUnitConversion(newobj.getString("UnitConversion")); } flag = true; break; } } if (flag) break; } } } } } model.addAttribute("jsonconfig", serviceConfig); if (key.equals("") && type != null) { key = type; } model.addAttribute("jsontype", key); model.addAttribute("jsonname", name); model.addAttribute("fieldsList", fileds); List resEchartsConfingList = resEchartsCofingService.selectAllChart(settype); JSONArray echarts = new JSONArray(); for (int i=0;i 0) { return "{'success':'success','id':'" + id + "'}"; } else { return "{'success':'erro'}"; } } else { return "{'success':'success','charttitle':'" + (contype.equals("tables") ? serviceConfig.getGroupbyalias() : serviceConfig.getTitle()) + "','serviceconfig':" + (resThemeModule.getServiceconfig() != null ? resThemeModule.getServiceconfig() : "") + "}"; } } /** * 编辑配置信息 * * @param name 需要修改的变量 如:var1,table1 * @param resourceid 资源ID * @param serviceConfig 相关配置字段信息 * @param serviceHTML 编辑器HTML内容 * @return */ @RequestMapping("editserviceconfig") @ResponseBody public String editServiceConfig(String name, Integer resourceid, ServiceConfig serviceConfig, String serviceHTML,Integer moduleid,Integer settype) { Res_ExtBusinessLayer resExtBusinessLayer = null; Res_Theme_Module resThemeModule = null; if (moduleid == 0) { resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid); } else { resThemeModule = resThemeModuleService.selectByid(moduleid); } String key = ""; if (name != null && !name.equals("")) { if (name.substring(0, 1).equals("v")) { key = "vars"; } if (name.substring(0, 1).equals("t")) { key = "tables"; } if (name.substring(0, 1).equals("c")) { key = "charts"; } StringBuilder sb = new StringBuilder(); if ((settype == 0 && resExtBusinessLayer != null && resExtBusinessLayer.getServiceConfig() != null) || (settype == 1 &&resThemeModule != null && resThemeModule.getServiceconfig() != null && !resThemeModule.getServiceconfig().trim().equals(""))) { JSONObject obj = JSONObject.parseObject(settype == 0 ? resExtBusinessLayer.getServiceConfig() : resThemeModule.getServiceconfig()); boolean flag = false; if (obj.getJSONArray(key) != null) { JSONArray jsonArray = obj.getJSONArray(key); if (jsonArray != null) { for (int j = 0; j < jsonArray.size(); j++) { org.json.JSONObject jsonObject = new org.json.JSONObject(jsonArray.getJSONObject(j)); Iterator iterator = jsonObject.keys(); while (iterator.hasNext()) { String skey = (String) iterator.next(); if (skey.equals(name)) { //找到编辑的项则替换掉旧的 if (key.equals("vars")) { sb.append("{"); sb.append("\"field\":\"" + serviceConfig.getField() + "\""); sb.append(",\"StatisticalMethod\":\"" + serviceConfig.getFunc() + "\""); sb.append(",\"where\":\"" + serviceConfig.getWhere() + "\""); sb.append(",\"explain\":\"" + serviceConfig.getExplain() + "\""); sb.append(",\"DecimalDigits\":\"" + serviceConfig.getDecimalDigits() + "\""); sb.append(",\"UnitConversion\":\"" + serviceConfig.getUnitConversion() + "\""); sb.append("}"); } else if (key.equals("tables")) { sb.append("{"); sb.append("\"groupby\":\"" + serviceConfig.getGroupby() + "\""); sb.append(",\"groupbyalias\":\"" + serviceConfig.getGroupbyalias() + "\""); sb.append(",\"where\":\"" + serviceConfig.getWhere() + "\""); sb.append(",\"explain\":\"" + serviceConfig.getExplain() + "\""); sb.append(",\"DecimalDigits\":\"" + serviceConfig.getDecimalDigits() + "\""); sb.append(",\"UnitConversion\":\"" + serviceConfig.getUnitConversion() + "\""); sb.append(",\"list\":["); sb.append(serviceConfig.getFields()); sb.append("]"); sb.append("}"); } else if (key.equals("charts")) { sb.append("{"); sb.append("\"id\":\"" + serviceConfig.getId() + "\""); sb.append(",\"title\":\"" + serviceConfig.getTitle() + "\""); sb.append(",\"type\":\"" + serviceConfig.getType() + "\""); sb.append(",\"displayMode\":\"" + serviceConfig.getDisplaymode() + "\""); sb.append(",\"classField\":\"" + serviceConfig.getClassfield() + "\""); sb.append(",\"ValueField\":\"" + serviceConfig.getValuefield() + "\""); sb.append(",\"StatisticalMethod\":\"" + serviceConfig.getStatisticalmethod() + "\""); sb.append(",\"option\":\"" + serviceConfig.getOption() + "\""); sb.append(",\"where\":\"" + serviceConfig.getWhere() + "\""); sb.append(",\"explain\":\"" + serviceConfig.getExplain() + "\""); sb.append(",\"DecimalDigits\":\"" + serviceConfig.getDecimalDigits() + "\""); sb.append(",\"UnitConversion\":\"" + serviceConfig.getUnitConversion() + "\""); sb.append("}"); } String ff = jsonString(sb.toString()); jsonArray.getJSONObject(j).replace(name, JSONObject.parseObject(ff)); flag = true; break; } } if (flag) break; } } } if (settype == 0) { resExtBusinessLayer.setServiceConfig(obj.toString()); } else { resThemeModule.setServiceconfig(obj.toString()); } } } // String replaceHTML = replaceServiceHTML(serviceHTML, resourceid, "charToHTML"); // resExtBusinessLayer.setServiceHTML(replaceHTML); if (settype == 0) { int count = resExtBusinessLayerService.updateByPrimaryKeySelective(resExtBusinessLayer); if (count > 0) { return "{'success':'success'}"; } return "{'success':'erro'}"; } else { return "{'success':'success','charttitle':'" + (key.equals("tables") ? serviceConfig.getGroupbyalias() : serviceConfig.getTitle()) + "','serviceconfig':" + (resThemeModule.getServiceconfig() != null ? resThemeModule.getServiceconfig() :"") + "}"; } } @RequestMapping("saveHtmlConfig") @ResponseBody public String saveHtmlConfig(String serviceHTML,Integer resourceid) { Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid); if(resExtBusinessLayer != null) { String replaceHTML = replaceServiceHTML(serviceHTML, resourceid, "charToHTML"); resExtBusinessLayer.setServiceHTML(replaceHTML); resExtBusinessLayer.setCache(""); int count = resExtBusinessLayerService.updateByPrimaryKeySelective(resExtBusinessLayer); if (count > 0) { return "success"; } else { return "error"; } } else { return "error"; } } @ResponseBody @RequestMapping("matchKeyNotInHTML") public String matchKeyNotInHTML(String serviceHTML,Integer resourceid) { Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid); String notkey = ""; if (resExtBusinessLayer.getServiceConfig() != null && !resExtBusinessLayer.getServiceConfig().equals("")) { JSONObject obj = JSONObject.parseObject(resExtBusinessLayer.getServiceConfig()); for (int i = 0; i < obj.size(); i++) { JSONArray object = null; //每次只取一个类 if (i == 0) { if (obj.getJSONArray("vars") != null) { object = obj.getJSONArray("vars"); } } if (i == 1) { if (obj.getJSONArray("tables") != null) { object = obj.getJSONArray("tables"); } } if (i == 2) { if (obj.getJSONArray("charts") != null) { object = obj.getJSONArray("charts"); } } if (object != null) { for (int j = 0; j < object.size(); j++) { String key = object.getJSONObject(j).getString("name"); Pattern p = Pattern.compile(key); Matcher m = p.matcher(serviceHTML); boolean flag = false; if(m.find()) { flag = true; if(flag) continue; } if (!flag) { if(notkey != "") notkey += ","; String keyString = "{" + key + "}"; notkey += keyString; } } } } } return notkey; } /** * 删除配置信息 */ @RequestMapping("delserviceconfig") @ResponseBody public String delServiceConfig(String name, Integer resourceid) { String key = ""; String type = ""; //判断是属于哪一项,获取对应的json if (name.substring(0, 1).equals("v")) { key = "vars"; type = "var"; } if (name.substring(0, 1).equals("t")) { key = "tables"; type = "table"; } if (name.substring(0, 1).equals("c")) { key = "charts"; type = "chart"; } Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid); if (resExtBusinessLayer.getServiceConfig() != null) { JSONObject obj = JSONObject.parseObject(resExtBusinessLayer.getServiceConfig()); boolean flag = false; if (obj.getJSONArray(key) != null) { //获取所要删除的项所在的json数组 JSONArray jsonArray = obj.getJSONArray(key); if (jsonArray != null) { //遍历数组,如果name一致则直接删除,退出循环 for (int j = 0; j < jsonArray.size(); j++) { org.json.JSONObject jsonObject = new org.json.JSONObject(jsonArray.getJSONObject(j)); Iterator iterator = jsonObject.keys(); while (iterator.hasNext()) { String skey = (String) iterator.next(); if (skey.equals(name)) { //找到删除该项 jsonArray.remove(j); flag = true; break; } } if (flag) break; } } // jsonArray = newSortJson(jsonArray, type); } resExtBusinessLayer.setServiceConfig(obj.toString()); int count = resExtBusinessLayerService.updateByPrimaryKeySelective(resExtBusinessLayer); if (count > 0) { return "success"; } } return "error"; } /** * 获取配置的变量键,用来命名变量值 如:var + 返回值 * * @param type 类别 * @param jsonArray json数组 * @return */ public String getConfigNum(String type, JSONArray jsonArray) { String i = ""; if (jsonArray != null && jsonArray.size() > 0) { int max = 1; for (int j = 0; j < jsonArray.size(); j++) { String key = jsonArray.getJSONObject(j).getString("name"); if (type.equals("vars")) { int t = Integer.parseInt(key.substring(3, key.length())) + 1; if (max < t) { max = t; } } else if (type.equals("tables") || type.equals("charts")) { int t = Integer.parseInt(key.substring(5, key.length())) + 1; if (max < t) { max = t; } } } i = String.valueOf(max); } else { i = "1"; } return i; } //替换占位符 public String replaceServiceHTML(String serviceHTML, Integer resourceid, String type) { //获取list Res_ExtBusinessLayer resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid); if (resExtBusinessLayer.getServiceConfig() != null && !resExtBusinessLayer.getServiceConfig().equals("")) { JSONObject obj = JSONObject.parseObject(resExtBusinessLayer.getServiceConfig()); for (int i = 0; i < obj.size(); i++) { JSONArray object = null; String replaceString = ""; String contype = ""; //每次只取一个类 if (i == 0) { if (obj.getJSONArray("vars") != null) { object = obj.getJSONArray("vars"); contype = "vars"; } } if (i == 1) { if (obj.getJSONArray("tables") != null) { object = obj.getJSONArray("tables"); contype = "tables"; } } if (i == 2) { if (obj.getJSONArray("charts") != null) { object = obj.getJSONArray("charts"); contype = "charts"; } } if (object != null) { for (int j = 0; j < object.size(); j++) { org.json.JSONObject jsonObject = new org.json.JSONObject(object.getJSONObject(j)); Iterator iterator = jsonObject.keys(); while (iterator.hasNext()) { if (contype.equals("vars")) { replaceString = ""; } else if (contype.equals("tables")) { replaceString = "
"; } else if (contype.equals("charts")) { replaceString = "
"; } String key = (String) iterator.next(); replaceString = replaceString.replace("var", key); String keyString = '{' + key + '}'; if (type.equals("charToHTML")) { serviceHTML = serviceHTML.replace(keyString, replaceString); } if (type.equals("htmlToChar")) { serviceHTML = serviceHTML.replace(replaceString, keyString); } } } } } } return serviceHTML; } //删除 后重新组合排序(暂不使用重新排序) public JSONArray newSortJson(JSONArray jsonArray, String type) { JSONArray array = new JSONArray(); for (int i = 0; i < jsonArray.size(); i++) { //循环获取第i个值,重新拼接 JSONObject jsonObject = JSONObject.parseObject(jsonArray.getString(i)); StringBuilder sb = new StringBuilder(); org.json.JSONObject obj = new org.json.JSONObject(jsonArray.getJSONObject(i)); Iterator iterator = obj.keys(); while (iterator.hasNext()) { String skey = (String) iterator.next(); JSONObject object = JSONObject.parseObject(jsonObject.getString(skey)); sb.append("{"); Integer nameNum = i + 1; sb.append("'name':'" + type + nameNum + "',"); sb.append("'" + type + nameNum + "':"); sb.append(jsonObject.getString(skey)); } sb.append("}"); System.out.println(sb.toString()); array.add(JSONObject.parseObject(sb.toString())); } return array; } //切换图表样式时获取对应样式的echarts默认模板代码 @ResponseBody @RequestMapping("getEchartsCode") public String getEchartsCode(Integer echartsid, String jsonname, Integer resourceid,Integer settype,Integer moduleid) { //编辑配置相关信息 String key = ""; String code = ""; if (jsonname != null && !jsonname.equals("") && resourceid != null) { Res_ExtBusinessLayer resExtBusinessLayer = null; Res_Theme_Module resThemeModule = null; if(settype == 0 ){ resExtBusinessLayer = resExtBusinessLayerService.selectByPrimaryKey(resourceid); }else{ resThemeModule = resThemeModuleService.selectByid(moduleid); } //判断是属于哪一项,获取对应的json if (jsonname.substring(0, 1).equals("v")) { key = "vars"; } if (jsonname.substring(0, 1).equals("t")) { key = "tables"; } if (jsonname.substring(0, 1).equals("c")) { key = "charts"; } if ((settype == 0&&resExtBusinessLayer.getServiceConfig() != null && key.equals("charts"))|| (settype != 0 &&resThemeModule.getServiceconfig() != null && key.equals("charts"))) { JSONObject obj = JSONObject.parseObject(settype==0?resExtBusinessLayer.getServiceConfig():resThemeModule.getServiceconfig()); JSONObject newobj = null; boolean flag = false; if (obj.getJSONArray(key) != null) { //获取所要获取的项所在的json数组 JSONArray jsonArray = obj.getJSONArray(key); if (jsonArray != null) { //遍历数组,如果key一致则取出相关配置信息,退出循环 for (int j = 0; j < jsonArray.size(); j++) { org.json.JSONObject jsonObject = new org.json.JSONObject(jsonArray.getJSONObject(j)); Iterator iterator = jsonObject.keys(); while (iterator.hasNext()) { String skey = (String) iterator.next(); if (skey.equals(jsonname)) { //如果切换的类型与数据库存的类型一致则取配置过的echarta代码 if (echartsid.equals(jsonArray.getJSONObject(j).getJSONObject(jsonname).getString("id"))) { code = jsonArray.getJSONObject(j).getJSONObject(jsonname).getString("option"); } else { Res_EchartsConfing resEchartsCofing = resEchartsCofingService.selectByPrimaryKey(echartsid); if (resEchartsCofing != null) { code = resEchartsCofing.getEchartsoption(); } } flag = true; break; } else continue; } if (flag) break; } } } } } else { Res_EchartsConfing resEchartsCofing = resEchartsCofingService.selectByPrimaryKey(echartsid); if (resEchartsCofing != null) { code = resEchartsCofing.getEchartsoption(); } } return code; } //把json化的字符串的键值中的英文双引号转化为单引号,避免因用户输入的英文双引号导致无法json化字符串 private static String jsonString(String s){ char[] temp = s.toCharArray(); int n = temp.length; for(int i =0;i