package com.landtool.lanbase.modules.res.controller; 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.landtool.lanbase.common.utils.HttpOperateUtils; import com.landtool.lanbase.config.SysTemPropertyConfig; 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_ExtMapUrl; import com.landtool.lanbase.modules.res.entity.Res_MainInfo; import com.landtool.lanbase.modules.res.service.KeShiHuaFuWuService; import com.landtool.lanbase.modules.res.service.ResDiyLayerInfoService; import com.landtool.lanbase.modules.res.service.ResExtMapUrlService; import com.landtool.lanbase.modules.res.service.ResMainInfoService; import com.landtool.lanbase.modules.sys.controller.AbstractController; import com.landtool.lanbase.modules.sys.service.SysFieldvalueService; @Controller @RequestMapping("/res/KeShiHuaFuWu") public class KeShiHuaFuWuController extends AbstractController { @Autowired private SysTemPropertyConfig sysConfig; @Autowired private ResMainInfoService resMainInfoService; @Autowired private KeShiHuaFuWuService keShiHuaFuWuService; @Autowired private ResExtMapUrlService resExtMapUrlService; @Autowired private ResDiyLayerInfoService resDiyLayerInfoService; @Autowired private OrgUserService orgUserService; @Autowired private OrgUnitService orgUnitService; @Autowired private SysFieldvalueService FieldUtils; @RequestMapping("Index") public String index(Model model) { model.addAttribute("pubzyWebRoot", sysConfig.getPubzyWebRoot()); model.addAttribute("systemName", sysConfig.getAppFullName()); model.addAttribute("gisPortal", sysConfig.getGisPortal()); model.addAttribute("backstageWebRoot", sysConfig.getApiServer() + "/"); return "KeShiHuaFuWu/Index"; } /** * 获取业务图层、专题地图列表 * @param parentid 父节点ID * @param type 目录树类型(0:专题地图、业务集成 1:业务图层 2:基础底图) * @param info 查询条件 * @return */ @ResponseBody @RequestMapping("GetYWTCAndZTDTList") public String getYWTCList(String parentid, Integer type, 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(暂无) map.put("type", type); //目录树类型 List resCatalogList = keShiHuaFuWuService.getYWTCAndZTDTCataLogList(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 = keShiHuaFuWuService.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 icon = ""; if (resMainInfo1.getResourceclass().equals("KJ_ZTDT")) { icon = "KJ_JCDT"; } else if (resMainInfo1.getResourceclass().equals("KJ_JCDT")) { icon = "JCDT"; } else { icon = resMainInfo1.getResourceclass(); } String FaBuRen = orgUserService.getChinesename(resMainInfo1.getCreateuserid());//发布人 String FaBuDanWei = orgUnitService.getUnitName((long) resMainInfo1.getPubunitid());//发布单位 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("ResourceClass", resMainInfo1.getResourceclass()); catalogmap.put("icon", "./images/classicons/" + icon + ".png"); maps.add(catalogmap); // resCatalogJson.append("{icon:'./images/classicons/" + icon // + ".png',id: 'ZiYuan_" + resMainInfo1.getResourceid() + "',name:'" + title + "', title: '" // + resMainInfo1.getTitle() + "|" + FaBuDanWei + "|" + FaBuRen // + "',isParent:false, hidtxt: '', isMapUrl: " + isMapUrl + ", ResourceClass: '" + resMainInfo1.getResourceclass() + "'}"); } } else { String idstr = parentid.substring(parentid.indexOf("_") + 1, parentid.length()); Res_MainInfo resMainInfo = resMainInfoService.selectByPrimaryKey(Integer.parseInt(idstr)); 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()); // resCatalogJson.append("{id: 'Url_" + urlitem.getUrlid() + "', resourceId: " + idstr + ",name:'" // + name + "',ResourceClass:'" + resMainInfo.getResourceclass() + "', hidtxt: ''}"); Map catalogmap = new HashMap<>(); catalogmap.put("id", "Url_" + urlitem.getUrlid()); catalogmap.put("resourceId", idstr); catalogmap.put("name", name); catalogmap.put("hidtxt", ""); catalogmap.put("ResourceClass", resMainInfo.getResourceclass()); maps.add(catalogmap); } } Res_DiyLayerInfo resDiyLayerInfo = new Res_DiyLayerInfo(); resDiyLayerInfo.setResourceid(Integer.parseInt(idstr)); resDiyLayerInfo.setIsshare(1); resDiyLayerInfo.setResourceid(Integer.parseInt(idstr)); 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()); // resCatalogJson.append("{id: 'Diy_" + item.getDiyid() + "', resourceId: " + idstr + ",name:'" // + item.getTitle() + "(" + ChineseName + ")', hidtxt: '', showDelBtn: " + (item.getDiyuserid() == userId.intValue() ? true : false) + "}"); 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); } } } return callbackFunName + "(" + JSON.toJSONString(maps, SerializerFeature.WriteMapNullValue) + ")"; // return callbackFunName + "([" + resCatalogJson.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(); } }