package com.landtool.lanbase.modules.res.service.impl; import java.util.HashMap; import java.util.List; import java.util.Map; import com.landtool.lanbase.common.utils.HttpUtils; import com.landtool.lanbase.config.SysTemPropertyConfig; import com.landtool.lanbase.modules.res.entity.Res_ExtBaseMap; import com.qiniu.util.Json; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import com.landtool.lanbase.modules.res.dao.Res_ExtMapUrlMapper; import com.landtool.lanbase.modules.res.entity.Res_ExtMapUrl; import com.landtool.lanbase.modules.res.service.ResExtMapUrlService; @Service("resExtMapUrlService") public class ResExtMapUrlServiceImpl implements ResExtMapUrlService { @Autowired private Res_ExtMapUrlMapper resExtMapUrlMapper; @Autowired private SysTemPropertyConfig sysConfig; @Override public int deleteByPrimaryKey(int urlid) { return resExtMapUrlMapper.deleteByPrimaryKey(urlid); } @Override public int insert(Res_ExtMapUrl record) { return resExtMapUrlMapper.insert(record); } @Override public int insertSelective(Res_ExtMapUrl record) { return resExtMapUrlMapper.insertSelective(record); } @Override public Res_ExtMapUrl selectByPrimaryKey(int urlid) { return resExtMapUrlMapper.selectByPrimaryKey(urlid); } @Override public int updateByPrimaryKeySelective(Res_ExtMapUrl record) { return resExtMapUrlMapper.updateByPrimaryKeySelective(record); } @Override public int updateByPrimaryKey(Res_ExtMapUrl record) { return resExtMapUrlMapper.updateByPrimaryKey(record); } @Override public List selectByCondition(Integer resourceid){return resExtMapUrlMapper.selectByCondition(resourceid);} @Override public int deleteByResourceId(Integer resourceId){return resExtMapUrlMapper.deleteByResourceId(resourceId);} @Override public Res_ExtMapUrl queryFirstOrderByResId(Integer resourceId) { return resExtMapUrlMapper.queryFirstOrderByResId(resourceId); } /**获取第一条服务地址*/ @Override public String getFirstServerUrl(Integer resourceid) { String url =""; List urlList = resExtMapUrlMapper.selectByCondition(resourceid); if(urlList != null && urlList.size() > 0){ url = urlList.get(0).getServerurl(); } return url; } /**从空间服务Controller提取出来,插入资源支持协议与地址表**/ @Override public void deleteAndInsertMapUrlArray(Integer resourceid,String extMapUrlStr){ System.out.println("extMapUrlStr = " + extMapUrlStr); resExtMapUrlMapper.deleteByResourceId(resourceid); if (!extMapUrlStr.equals("")) { // String[] extMapUrlArray = extMapUrlStr.split("\\|"); //插入资源支持协议与地址表 // for (int i = 0; i < extMapUrlArray.length; i++) { // String[] extMapUrlArray2 = extMapUrlArray[i].split(","); String[] extMapUrlArray2 = extMapUrlStr.split(","); String typeAndUrl = extMapUrlArray2[0]; String serverUrl = extMapUrlArray2[1]; Integer esbid = Integer.parseInt(extMapUrlArray2[2].toString()); Res_ExtMapUrl resExtMapUrl = new Res_ExtMapUrl(); resExtMapUrl.setResourceid(resourceid); resExtMapUrl.setTypeandurl(typeAndUrl); if(extMapUrlArray2.length>4){ String layertype=extMapUrlArray2[3]; String layername=extMapUrlArray2[4]; resExtMapUrl.setLayertype(layertype); resExtMapUrl.setLayername(layername); } resExtMapUrl.setServerurl(serverUrl); resExtMapUrl.setServername(extMapUrlStr.split("=").length>1?extMapUrlStr.split("=")[1]:""); if(esbid != 0) resExtMapUrl.setEsbid(esbid); resExtMapUrl.setIsPublic(esbid); String proxyurl = getProxyurl(resExtMapUrl, resourceid); resExtMapUrl.setServerurl(proxyurl); resExtMapUrl.setOldserverurl(serverUrl); System.out.println("resExtMapUrl = " + resExtMapUrl); resExtMapUrlMapper.insertSelective(resExtMapUrl); } } /**根据资源id获取REBids(英文逗号,分隔)**/ @Override public String queryRsbidsByResourceid(Integer resourceid) { String oldesbids = ""; List oldMapUrlList = resExtMapUrlMapper.selectByCondition(resourceid); if (oldMapUrlList != null && oldMapUrlList.size() > 0) { for (int i = 0; i < oldMapUrlList.size(); i++) { if (oldMapUrlList.get(i).getEsbid() != null && oldMapUrlList.get(i).getEsbid() != 0) { if (oldesbids.length() != 0) { oldesbids += "," + oldMapUrlList.get(i).getEsbid(); } else { oldesbids += oldMapUrlList.get(i).getEsbid(); } } } } return oldesbids; } @Override public int isExistContextPath(String contextPth){ return resExtMapUrlMapper.isExistContextPath(contextPth); } @Override public List selectAllUrl() { return resExtMapUrlMapper.selectAllUrl(); } @Override public List selectBatchUrl(List resourceids) { return resExtMapUrlMapper.selectBatchUrl(resourceids); } private String getProxyurl(Res_ExtMapUrl record, Integer resourceid) { String proxyUrl=sysConfig.getProxyUrl()+"/serverRegister/addArcGisServer"; String resourceIdStr="zyid="+resourceid; String serverUrlStr="serverUrl="+record.getServerurl(); String isPublicStr= "isPublic="+record.getIsPublic(); String fromsys= "fromsys=HYJGPT"; String enable="enable=1"; String servername="servername="+record.getServername(); String s = null; try { s = HttpUtils.get(proxyUrl+"?"+ resourceIdStr+"&"+ serverUrlStr+"&"+ isPublicStr+"&"+ fromsys+"&"+ enable+"&"+ servername ); } catch (Exception e) { e.printStackTrace(); } HashMap result= Json.decode(s,HashMap.class); return (String)result.get("proxyurl"); } @Override public List checkAllUrls() { return resExtMapUrlMapper.checkAllUrls(); } public static void main(String[] args) { String str="DYNAMIC,http://192.168.20.106:8066/test/2,0,,ditu,|"; String[] split = str.split(","); } @Override public Res_ExtMapUrl queryResourceId(Res_ExtMapUrl extMapUrl) { return resExtMapUrlMapper.queryResourceId(extMapUrl); } @Override public void updateSpcStatus(Map param) { resExtMapUrlMapper.updateSpcStatus(param); } }