package com.landtool.lanbase.modules.res.controller; import java.io.File; import java.io.IOException; import java.net.URLEncoder; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; 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.JSON; import com.alibaba.fastjson.JSONArray; 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.utils.CommonUtils; import com.landtool.lanbase.common.utils.HttpOperateUtils; import com.landtool.lanbase.config.SysTemPropertyConfig; import com.landtool.lanbase.modules.api.utils.PageBean; import com.landtool.lanbase.modules.org.entity.OrgUnit; import com.landtool.lanbase.modules.org.service.OrgUnitService; import com.landtool.lanbase.modules.org.service.OrgUserService; import com.landtool.lanbase.modules.res.entity.Res_Catalog; import com.landtool.lanbase.modules.res.entity.Res_DiyLayerInfo; import com.landtool.lanbase.modules.res.entity.Res_ExtFileSource; 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.ResDiyLayerInfoService; import com.landtool.lanbase.modules.res.service.ResExtFileSourceService; import com.landtool.lanbase.modules.res.service.ResExtMapUrlService; import com.landtool.lanbase.modules.res.service.ResMainInfoService; import com.landtool.lanbase.modules.res.service.ZhuanTiZhiTuService; import com.landtool.lanbase.modules.sys.controller.AbstractController; import com.landtool.lanbase.modules.sys.service.SysFieldvalueService; /** * 专题制图 */ @Controller @RequestMapping("/res/zhuantizhitu") public class ZhuanTiZhiTuController extends AbstractController { @Autowired private SysTemPropertyConfig sysConfig; @Autowired private ResMainInfoService resMainInfoService; @Autowired private ZhuanTiZhiTuService zhuanTiZhiTuService; @Autowired private ResExtMapUrlService resExtMapUrlService; @Autowired private ResDiyLayerInfoService resDiyLayerInfoService; @Autowired private OrgUserService orgUserService; @Autowired private OrgUnitService orgUnitService; @Autowired private SysFieldvalueService FieldUtils; @Autowired private ResExtFileSourceService resExtFileSourceService; /** * 主页 */ @RequestMapping("/index") public String index(Model model) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); model.addAttribute("id", getUserId()); model.addAttribute("gisPortal", sysConfig.getGisPortal()); model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/"); return "zhuantizhitu/index"; } /** * 数据资源 - 我的制图 * @param request * @param pageBean * @return */ @ResponseBody @RequestMapping(value = "/getWoDeZhiTu") @LogAction("地图服务,我的制图,我的制图查询,查询") public String getWoDeZhiTu(HttpServletRequest request, PageBean pageBean) { String callbackFunName = request.getParameter("callback"); if(callbackFunName == null || callbackFunName.isEmpty()){ callbackFunName = "callback"; } pageBean.setLimit(10); PageHelper.startPage(pageBean.getPage(), pageBean.getLimit());//设置当前页数及每页条数 Long userid = getUserId();//获取登录用户ID //构造查询对象 Map map = new HashMap<>(); map.put("leixiId", "KJ_ZTDT");//资源类型 map.put("userid", userid);//用户ID List res_mainInfos = resMainInfoService.selectZTDTList(map); int countNums = (int) ((Page) res_mainInfos).getTotal();//获取记录总数 PageBean pageData = new PageBean<>(pageBean.getPage(), pageBean.getLimit(), countNums); pageData.setItems(res_mainInfos); StringBuilder rsb = new StringBuilder(); rsb.append("["); List> maps = new LinkedList<>(); for (int i = 0; i < res_mainInfos.size(); i++) { String title = res_mainInfos.get(i).getTitle(); if(title.length() > 15) { title = CommonUtils.subStringUtils(title,30); } Map remap = new HashMap<>(); remap.put("resourceId", res_mainInfos.get(i).getResourceid()); remap.put("title", title); remap.put("fulltitle", res_mainInfos.get(i).getTitle()); maps.add(remap); // if(i > 0) rsb.append(","); // rsb.append("{resourceId:" + res_mainInfos.get(i).getResourceid()); // // rsb.append(", title: '" + title + "'"); // rsb.append(", fulltitle: '" + res_mainInfos.get(i).getTitle() + "'}"); } // rsb.append("]"); Map newmap = new HashMap<>(); newmap.put("Count", countNums); newmap.put("Page", pageBean.getPage()); newmap.put("ShuJu", maps); StringBuilder rsb1 = new StringBuilder(); rsb1.append("{"); rsb1.append("Count:"+countNums); rsb1.append(",Page:"+pageBean.getPage()); rsb1.append(",ShuJu:"+ JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue)); rsb1.append("}"); return callbackFunName + "(" + JSON.toJSONString(newmap, SerializerFeature.WriteMapNullValue) + ")"; } /** * 获取业务图层列表 * @param parentid 父节点ID * @param info 查询条件 * @return */ @ResponseBody @RequestMapping("GetYWTCList") @LogAction("地图服务,业务图层,业务图层列表查询,查询") public String getYWTCList(String parentid, Res_MainInfo info, HttpServletRequest request) { String callbackFunName = request.getParameter("callback"); if(callbackFunName == null || callbackFunName.isEmpty()){ callbackFunName = "callback"; } //alert ykm 2019/01/23 根据用户输入的信息获取相关的用户ID if(info.getCreateuserid() == null && info.getFaburen() != null && !info.getFaburen().equals("")) { String name = getUserIds(info.getFaburen()); info.setFaburen(name); } if(info.getCreateuserid() != null) { info.setFaburen(null); } Long userId = getUserId(); //获取用户ID StringBuilder resCatalogJson = new StringBuilder(); List> maps = new LinkedList<>(); //alert 2019/01/23 if (parentid.indexOf("ZiYuan_") == -1) { Map map = new HashMap<>(); map.put("parentid", parentid); map.put("title", info.getTitle()); //资源名称 map.put("createuserid", info.getCreateuserid()); //发布人 map.put("pubdateBegin", info.getPubdateBegin()); //发布起始时间 map.put("pubdatefinish", info.getPubdatefinish()); //发布结束时间 map.put("iscollect", info.getIscollect()); //是否收藏 map.put("userid", userId); //用户ID map.put("faburen", info.getFaburen()); //用户自己输入的发布人信息获取到的ID OrgUnit orgUnit = getUnit(); //获取登录用户所属单位 if(orgUnit != null) { map.put("unitid", orgUnit.getUnitid()); //用户单位ID } //map.put("departID", "1,2,3"); //获取用户所属部门ID(暂无) List resCatalogList = zhuanTiZhiTuService.getYWTCCataLogList(map);// 获取子目录列表 // 循环构造子目录节点 for (Res_Catalog resCatalog : resCatalogList) { Map catalogmap = new HashMap<>(); catalogmap.put("id", resCatalog.getCatlogid()); catalogmap.put("name", resCatalog.getTitle()); catalogmap.put("isParent", true); catalogmap.put("iconOpen", "./images/classicons/folderOpen.png"); catalogmap.put("iconClose", "./images/classicons/folder.png"); maps.add(catalogmap); // if (!"".equals(resCatalogJson.toString())) { // resCatalogJson.append(','); // } // resCatalogJson.append("{id: " + resCatalog.getCatlogid() + ",name:'" + resCatalog.getTitle() + "', isParent: true,iconOpen:'./images/classicons/folderOpen.png',iconClose:'./images/classicons/folder.png'}"); } // 获取资源类型列表 List resMainInfo = zhuanTiZhiTuService.getCatalogZiYuanList(map); // 获取目录下业务图层资源列表 // 循环构造资源节点 for (Res_MainInfo resMainInfo1 : resMainInfo) { // if (!"".equals(resCatalogJson.toString())) { // resCatalogJson.append(','); // } List urlList = resExtMapUrlService.selectByCondition(resMainInfo1.getResourceid()); boolean isMapUrl = urlList.size() == 0 ? false : true; String title = resMainInfo1.getTitle(); if (resMainInfo1.getTitle().length() > 16) { title = resMainInfo1.getTitle().substring(0, 16) + ".."; } String FaBuRen = orgUserService.getChinesename(resMainInfo1.getCreateuserid());//发布人 String FaBuDanWei = orgUnitService.getUnitName((long) resMainInfo1.getPubunitid());//发布单位 Res_ExtFileSource fileSource = resExtFileSourceService.selectByPrimaryKey(resMainInfo1.getResourceid()); int isNC = (fileSource != null && fileSource.getNcconfig() != null && fileSource.getNcconfig().length() != 0) ? 1 : 0; Map catalogmap = new HashMap<>(); catalogmap.put("id", "ZiYuan_" + resMainInfo1.getResourceid()); catalogmap.put("name", title); catalogmap.put("title", resMainInfo1.getTitle() + "|" + FaBuDanWei + "|" + FaBuRen); catalogmap.put("isParent", false); catalogmap.put("hidtxt", ""); catalogmap.put("isMapUrl", isMapUrl); catalogmap.put("isNC", isNC); catalogmap.put("icon", "./images/classicons/" + resMainInfo1.getResourceclass() + ".png"); maps.add(catalogmap); // resCatalogJson.append("{icon:'./images/classicons/" + resMainInfo1.getResourceclass() // + ".png',id: 'ZiYuan_" + resMainInfo1.getResourceid() + "',name:'" + title + "', title: '" // + resMainInfo1.getTitle() + "|" + FaBuDanWei + "|" + FaBuRen // + "',isParent:false, hidtxt: '', isMapUrl: " + isMapUrl + ",isNC:" + isNC + "}"); } } else { String idstr = parentid.substring(parentid.indexOf("_") + 1, parentid.length()); List urlList = resExtMapUrlService.selectByCondition(Integer.parseInt(idstr));//获取资源协议信息列表 if (urlList.size() != 0) { LinkedHashMap TypeAndURLList = FieldUtils.getFieldListByKey("TypeAndURL");//获取地图服务协议字典 for (Res_ExtMapUrl urlitem : urlList) { // if (!"".equals(resCatalogJson.toString())) { // resCatalogJson.append(','); // } String name = TypeAndURLList.get(urlitem.getTypeandurl()); Map catalogmap = new HashMap<>(); catalogmap.put("id", "Url_" + urlitem.getUrlid()); catalogmap.put("resourceId", idstr); catalogmap.put("name", name); catalogmap.put("hidtxt", ""); maps.add(catalogmap); // resCatalogJson.append("{id: 'Url_" + urlitem.getUrlid() + "', resourceId: " + idstr + ",name:'" // + name + "', hidtxt: ''}"); } } Res_DiyLayerInfo resDiyLayerInfo = new Res_DiyLayerInfo(); resDiyLayerInfo.setResourceid(Integer.parseInt(idstr)); resDiyLayerInfo.setIsshare(1); resDiyLayerInfo.setDiyuserid(Integer.valueOf(getUserId().toString())); List resDiyLayerInfoList = resDiyLayerInfoService.queryApiList(resDiyLayerInfo);// 获取自定义图层信息列表 if (resDiyLayerInfoList.size() > 0) { for (Res_DiyLayerInfo item : resDiyLayerInfoList) { // if (!"".equals(resCatalogJson.toString())) { // resCatalogJson.append(','); // } String ChineseName = orgUserService.getChinesename(item.getDiyuserid()); Map catalogmap = new HashMap<>(); catalogmap.put("id", "Diy_" + item.getDiyid()); catalogmap.put("resourceId", idstr); catalogmap.put("name", item.getTitle() + "(" + ChineseName + ")"); catalogmap.put("hidtxt", ""); catalogmap.put("showDelBtn", (item.getDiyuserid() == userId.intValue() ? true : false)); maps.add(catalogmap); // resCatalogJson.append("{id: 'Diy_" + item.getDiyid() + "', resourceId: " + idstr + ",name:'" // + item.getTitle() + "(" + ChineseName + ")', hidtxt: '', showDelBtn: " + (item.getDiyuserid() == userId.intValue() ? true : false) + "}"); } } Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(Integer.parseInt(idstr)); if(resExtFileSource != null) { String html = getSJWJFileListHtml(resExtFileSource.getResourceid()); Map catalogmap = new HashMap<>(); catalogmap.put("id", "Sjwj_" + resExtFileSource.getResourceid()); catalogmap.put("resourceId", idstr); catalogmap.put("html",html); maps.add(catalogmap); resCatalogJson.append("{id: \"Sjwj_" + resExtFileSource.getResourceid() + "\", resourceId: " + idstr + ",html:\"" + html +"\"}"); } } // return callbackFunName + "([" + resCatalogJson.toString() + "])"; return callbackFunName + "(" + JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue) + ")"; } // 暂停使用 @ResponseBody @RequestMapping("GetSJWJFileList") public String getSJWJFileList(Integer resourceid,HttpServletRequest request) { String callbackFunName = request.getParameter("callback"); Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(resourceid); StringBuilder sb = new StringBuilder(); if(resExtFileSource != null && resExtFileSource.getServerurl() != null) { sb.append("{Ncjsonpath:'"+ (resExtFileSource.getNcjsonpath()==null?"": resExtFileSource.getNcjsonpath())+"'"); sb.append(",filesname:["); if(resExtFileSource.getSourcetype().equals("文件夹")) { File file = new File(sysConfig.getUploadPath() + resExtFileSource.getServerurl()); String[] fileLists = file.list(); if (fileLists != null) { for (int i = 0; i < fileLists.length; i++) { File file1 = new File(fileLists[i]); if (i != 0) sb.append(","); sb.append("'" + file1.getName().substring(0, file1.getName().indexOf(".")) + "'"); } } } else { sb.append("'" + resExtFileSource.getFilename().substring(0, resExtFileSource.getFilename().indexOf(".")) + "'"); } sb.append("]}"); } return callbackFunName + "(" + sb.toString() + ")"; } private String getSJWJFileListHtml(Integer resourceid) { Res_ExtFileSource resExtFileSource = resExtFileSourceService.selectByPrimaryKey(resourceid); StringBuilder sb = new StringBuilder(); if(resExtFileSource != null && resExtFileSource.getServerurl() != null) { sb.append("{Ncjsonpath:'"+ (resExtFileSource.getNcjsonpath()==null?"": resExtFileSource.getNcjsonpath())+"'"); sb.append(",filesname:["); if(resExtFileSource.getSourcetype().equals("文件夹")) { File file = new File(sysConfig.getUploadPath() + resExtFileSource.getServerurl()); String[] fileLists = file.list(); if (fileLists != null) { for (int i = 0; i < fileLists.length; i++) { File file1 = new File(fileLists[i]); if (i != 0) sb.append(","); sb.append("'" + file1.getName().substring(0, file1.getName().indexOf(".")) + "'"); } } } else { sb.append("'" + resExtFileSource.getFilename().substring(0, resExtFileSource.getFilename().indexOf(".")) + "'"); } sb.append("]}"); } return sb.toString(); } //根据输入的用户名获取用户ID private String getUserIds(String name) { String url = sysConfig.getApiServer() + "/api/org/user/findUserByWord/" + URLEncoder.encode(URLEncoder.encode(name)); String username = null; try { username = HttpOperateUtils.httpGet(url); } catch (IOException e) { e.printStackTrace(); } JSONArray object = JSONArray.parseArray(username); StringBuilder t = new StringBuilder(); if(!name.equals( "%")) { for (int i = 0; i < object.size(); i++) { if (i != 0) t.append(","); t.append(object.getJSONObject(i).getString("id")); } } if(t.toString().equals("") && !name.equals( "%")) { t.append("-1"); } return t.toString(); } }