Commit 8c69bb27 authored by 周健威's avatar 周健威

添加一键发布

parent 2c75e023
package com.upyuns.platform.rs.datacenter.rest.backstage; package com.upyuns.platform.rs.datacenter.rest.backstage;
import cn.hutool.core.util.StrUtil;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController; import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.vo.PageDataVO; import com.github.wxiaoqi.security.common.vo.PageDataVO;
...@@ -32,8 +33,18 @@ public class BgRscpmonitorimageController extends BaseController<RscpMonitorimag ...@@ -32,8 +33,18 @@ public class BgRscpmonitorimageController extends BaseController<RscpMonitorimag
@RequestMapping(value = "/addRscpMosaicimage",method = RequestMethod.POST) @RequestMapping(value = "/addRscpMosaicimage",method = RequestMethod.POST)
public ObjectRestResponse <RscpMonitorimage> addMosaicimage(@RequestBody RscpMonitorimage rscpMonitorimage ) { public ObjectRestResponse <RscpMonitorimage> addMosaicimage(@RequestBody RscpMonitorimage rscpMonitorimage ) {
if (rscpMonitorimage.getId()==null){ if (rscpMonitorimage.getId()==null){
rscpMonitorimage.setIsDel(0); rscpMonitorimage.setIsDel(0);
if(rscpMonitorimage.getStatus() == null) {
rscpMonitorimage.setStatus(2);
}
if(StrUtil.isBlank(rscpMonitorimage.getSrs())) {
rscpMonitorimage.setSrs("EPSG:4326");
}
if(StrUtil.isBlank(rscpMonitorimage.getExtentSrs())) {
rscpMonitorimage.setExtentSrs("EPSG:4326");
}
baseBiz.insertSelective(rscpMonitorimage); baseBiz.insertSelective(rscpMonitorimage);
}else { }else {
rscpMonitorimage.setIsDel(0); rscpMonitorimage.setIsDel(0);
......
package com.upyuns.platform.rs.datacenter.rest.backstage; package com.upyuns.platform.rs.datacenter.rest.backstage;
import cn.hutool.core.util.StrUtil;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController; import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.vo.PageDataVO; import com.github.wxiaoqi.security.common.vo.PageDataVO;
...@@ -35,6 +36,15 @@ public class BgRscpmosaicimageController extends BaseController<RscpMosaicimageB ...@@ -35,6 +36,15 @@ public class BgRscpmosaicimageController extends BaseController<RscpMosaicimageB
public ObjectRestResponse <RscpMosaicimage> addMosaicimage(@RequestBody RscpMosaicimage rscpMosaicimage ) { public ObjectRestResponse <RscpMosaicimage> addMosaicimage(@RequestBody RscpMosaicimage rscpMosaicimage ) {
if (rscpMosaicimage.getId()==null){ if (rscpMosaicimage.getId()==null){
rscpMosaicimage.setIsDel(0); rscpMosaicimage.setIsDel(0);
if(rscpMosaicimage.getStatus() == null) {
rscpMosaicimage.setStatus(2);
}
if(StrUtil.isBlank(rscpMosaicimage.getSrs())) {
rscpMosaicimage.setSrs("EPSG:4326");
}
if(StrUtil.isBlank(rscpMosaicimage.getExtentSrs())) {
rscpMosaicimage.setExtentSrs("EPSG:4326");
}
baseBiz.insertSelective(rscpMosaicimage); baseBiz.insertSelective(rscpMosaicimage);
}else { }else {
rscpMosaicimage.setIsDel(0); rscpMosaicimage.setIsDel(0);
......
...@@ -15,6 +15,19 @@ ...@@ -15,6 +15,19 @@
<dependencies> <dependencies>
<dependency>
<groupId>it.geosolutions</groupId>
<artifactId>geoserver-manager</artifactId>
<version>1.7.0</version>
</dependency>
<!--style 生成-->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.19</version>
</dependency>
<dependency> <dependency>
<groupId>com.upyuns.platform.rs</groupId> <groupId>com.upyuns.platform.rs</groupId>
<artifactId>rs-website-api</artifactId> <artifactId>rs-website-api</artifactId>
......
package com.upyuns.platform.rs.website.controller.web; package com.upyuns.platform.rs.website.controller.web;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse; import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.rest.BaseController; import com.github.wxiaoqi.security.common.rest.BaseController;
import com.github.wxiaoqi.security.common.util.Query; import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.vo.PageDataVO; import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.upyuns.platform.rs.website.biz.LmyxmonitorimageBiz; import com.upyuns.platform.rs.website.biz.LmyxmonitorimageBiz;
import com.upyuns.platform.rs.website.entity.Lmyxmonitorimage; import com.upyuns.platform.rs.website.entity.Lmyxmonitorimage;
import com.upyuns.platform.rs.website.util.GeoServerUtil;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.List; import java.util.List;
...@@ -35,4 +40,41 @@ public class LmyxmonitorimageController extends BaseController<LmyxmonitorimageB ...@@ -35,4 +40,41 @@ public class LmyxmonitorimageController extends BaseController<LmyxmonitorimageB
entity.setState(Lmyxmonitorimage.STATE_UP); entity.setState(Lmyxmonitorimage.STATE_UP);
return ObjectRestResponse.succ(baseBiz.selectList(entity)); return ObjectRestResponse.succ(baseBiz.selectList(entity));
} }
@RequestMapping(value = "/app/unauth/publishMap",method={RequestMethod.POST})
@ResponseBody
public ObjectRestResponse<String> publishMap(@RequestBody PublishMapDTO dto){
if(StrUtil.isBlank(dto.getWorkSpace())) {
dto.setWorkSpace("test");
}
// ResultBean<String> resultBean = new ResultBean<String>();
dto.setStyle("raster");
GeoServerUtil.publishGeoTIFF(dto.getWorkSpace(), dto.getLayerName(), dto.getFilePath(), dto.getLayerName(), dto.getStyle());
// HttpClientUtils httpClientApi = new HttpClientUtils("https://zzrsmgmt.upyuns.com/api/website/lmyxmonitorimage/web/app/unauth/baseAdd");
// httpClientApi.execute()
Lmyxmonitorimage lmyxmonitorimage = new Lmyxmonitorimage();
lmyxmonitorimage.setState(1);
lmyxmonitorimage.setType(dto.getType());
if(dto.getType() == 2213) {
lmyxmonitorimage.setLegendUrl("https://hstandfarm.upyuns.com/legend/植被覆盖度图例.png");
}
if(dto.getType() == 2216) {
lmyxmonitorimage.setLegendUrl("https://hstandfarm.upyuns.com/legend/火灾风险等级图例.png");
}
lmyxmonitorimage.setUrl("https://hstandfarm.upyuns.com/geoserver/"+dto.getWorkSpace()+"/wms");
lmyxmonitorimage.setTitle(dto.getTitle());
lmyxmonitorimage.setResourcename(dto.getLayerName());
String result = HttpUtil.post("http://zzrsmgmt.upyuns.com/api/website/lmyxmonitorimage/web/app/unauth/baseAdd", JSONUtil.toJsonStr(lmyxmonitorimage));
return ObjectRestResponse.succ(result);
}
@Data
public static class PublishMapDTO {
String workSpace;
String title;
String filePath;
String layerName;
String style;
Integer type;
}
} }
\ No newline at end of file
package com.upyuns.platform.rs.website.util;
import it.geosolutions.geoserver.rest.GeoServerRESTManager;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
import java.io.File;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.List;
public class GeoServerUtil {
/**
* geoServer配置
*/
private static String url = "http://10.5.52.4:18080/geoserver";
private static String geoUsername = "admin";
private static String geoPassword = "upyuns";
public static GeoServerRESTManager getManager() throws MalformedURLException {
URL u = new URL(url);
//获取管理对象
GeoServerRESTManager geoServerRESTManager = new GeoServerRESTManager(u, geoUsername, geoPassword);
return geoServerRESTManager;
}
/**
* 判断工作区(workspace)是否存在,不存在则创建
*/
public static boolean judgeWorkSpace(String workspace) throws MalformedURLException {
boolean flag = false;
GeoServerRESTManager manager = getManager();
GeoServerRESTPublisher publisher = manager.getPublisher();
List<String> workspaces = manager.getReader().getWorkspaceNames();
if (!workspaces.contains(workspace)) {
boolean createWorkspace = publisher.createWorkspace(workspace);
flag = true;
System.out.println("create workspace : " + createWorkspace);
} else {
flag = false;
System.out.println("workspace已经存在了,workspace :" + workspace);
}
return flag;
}
/**
* 当发布图层时会自动创建数据储存,于是我把创建数据储存的方法删除了
*
* @param store 存储名
* @param workSpace 工作空间名
* @param filePath 要发布的图层的硬盘的目录地址
* @param layerName 要发布的图层的名字
* @param style 发布图层使用的样式,因为我的几个样式已经提前传到工作空间了,所以就没有用代码
* @return boolean
*/
public static boolean shpJudgeDatabase(String workSpace, String store, String filePath, String layerName, String style) {
GeoServerRESTManager manager = null;
RESTCoverageStore restStore = null;
try {
manager = getManager();
GeoServerRESTPublisher publisher = manager.getPublisher();
//
boolean publish = publisher.publishGeoTIFF(workSpace, store, layerName, new File(filePath), "EPSG:4326",
GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED, style, null);
System.out.println("publish (TIFF文件发布状态) : " + publish);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 当发布图层时会自动创建数据储存,于是我把创建数据储存的方法删除了
*
* @param store 存储名
* @param workSpace 工作空间名
* @param filePath 要发布的图层的硬盘的目录地址
* @param layerName 要发布的图层的名字
* @param style 发布图层使用的样式,因为我的几个样式已经提前传到工作空间了,所以就没有用代码
* @return boolean
*/
public static boolean publishGeoTIFF(String workSpace, String store, String filePath, String layerName, String style) {
GeoServerRESTManager manager = null;
// RESTCoverageStore restStore = null;
try {
// URL urlShapefilePath = new URL("file://"+ filePath);
manager = getManager();
GeoServerRESTPublisher publisher = manager.getPublisher();
// boolean result = false;
// GSGeoTIFFDatastoreEncoder storeEncoder = new GSGeoTIFFDatastoreEncoder(store, urlShapefilePath);
// result = manager.getStoreManager().create(workSpace, storeEncoder);
// if(result) {
boolean publish = publisher.publishGeoTIFF(workSpace, store, layerName, new File(filePath), "EPSG:4326",
GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED, style, null);
System.out.println("publish (TIFF文件发布状态) : " + publish);
// }
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static void main(String[] args) throws MalformedURLException, FileNotFoundException, URISyntaxException {
GeoServerRESTManager manager = GeoServerUtil.getManager();
Boolean flag = manager.getReader().existsDatastore("test", "mt-VC-202312-yangxi-a-2public");
Boolean flag2 = manager.getReader().existsCoveragestore("test", "mt-VC-202312-yangxi-a-2public");
Boolean flag3 = manager.getReader().existsDatastore("rsinsure2", "mt-rsinsure2farmblock-2024-231224206201-a-0public");
GeoServerRESTPublisher publisher = manager.getPublisher();
// try {
// // 数据存储需要的文件
//// String shpFilePath = String.format("file://%s", "/sdbdata/geoserver/data_insure2/block/230781/mt-farmblock-2023-230781202-a-0public/mt-farmblock-2023-230781202-a-0public.shp");
// String shpFilePath = String.format("file://%s", "/sdbdata/geoserver/data_insure2/block/230781/mt-farmblock-2023-230781202-a-0public/mt-farmblock-2023-230781202-a-0public.shp");
// URL urlShapeFile = new URL(shpFilePath);
// // 创建数据集
// GSShapefileDatastoreEncoder datastoreEncoder = new GSShapefileDatastoreEncoder("mt-rsinsure3farmblock6", urlShapeFile);
// datastoreEncoder.setCharset(Charset.forName("UTF-8"));
// datastoreEncoder.setType("shapefile");
// datastoreEncoder.setE
// manager.getStoreManager().create("rsinsure3", datastoreEncoder);
// } catch (MalformedURLException e) {
// e.printStackTrace();
// }
///Users/zhoujianwei/Downloads/农险平安202410/mt-rsinsure3farmblock/mt-rsinsure3farmblock.shp
// boolean publish = publisher.publishShp("rsinsure3", "mt-rsinsure3farmblock", (NameValuePair[])null, "mt-rsinsure3farmblock", GeoServerRESTPublisher.UploadMethod.EXTERNAL, new URI("file:///sdbdata/geoserver/data_insure3/mt-rsinsure3farmblock/mt-rsinsure3farmblock.shp"), "EPSG:4326",(String)null,
// GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED, "polygon");
// try {
// // 数据存储需要的文件
// String shpFilePath = String.format("file://%s", "/sdbdata/geoserver/data_insure3/mt-rsinsure3farmblock/mt-rsinsure3farmblock.shp");
// URL urlShapeFile = new URL(shpFilePath);
// // 创建数据集
// GSShapefileDatastoreEncoder datastoreEncoder = new GSShapefileDatastoreEncoder("mt-rsinsure3farmblock2", urlShapeFile);
// datastoreEncoder.setCharset(Charset.forName("UTF-8"));
// manager.getStoreManager().create("rsinsure3", datastoreEncoder);
// } catch (MalformedURLException e) {
// e.printStackTrace();
// }
// if (!restReader.existsLayer(workSpace, layerName)) {
// try {
// GSFeatureTypeEncoder gsFeatureTypeEncoder = new GSFeatureTypeEncoder();
// gsFeatureTypeEncoder.setTitle("mt-rsinsure3farmblock2");
// gsFeatureTypeEncoder.setName("mt-rsinsure3farmblock2");
// gsFeatureTypeEncoder.setSRS(GeoServerRESTPublisher.DEFAULT_CRS);
//
// GSLayerEncoder gsLayerEncoder = new GSLayerEncoder();
// gsLayerEncoder.addStyle("polygon");
//
// boolean layer = publisher.publishDBLayer("rsinsure3", "mt-rsinsure3farmblock2", gsFeatureTypeEncoder, gsLayerEncoder);
// System.out.println("publish layer : " + layer);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// GSFeatureTypeEncoder featureTypeEncoder = new GSFeatureTypeEncoder();
// featureTypeEncoder.setName("mt-rsinsure3farmblock2");
// featureTypeEncoder.setTitle("mt-rsinsure3farmblock2");
// featureTypeEncoder.setSRS(GeoServerRESTPublisher.DEFAULT_CRS);
//
// featureTypeEncoder.setProjectionPolicy(GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED);
// if (!publisher.createResource("rsinsure3", GeoServerRESTPublisher.StoreType.DATASTORES, "mt-rsinsure3farmblock2", featureTypeEncoder)) {
//
// } else {
// GSLayerEncoder layerEncoder = publisher.configureDefaultStyle("polygon");
// publisher.configureLayer("rsinsure3", "mt-rsinsure3farmblock2", layerEncoder);
// }
// }
// String layerName = "mt-rsinsure3farmblock2";
// if (!manager.getReader().existsLayer("rsinsure3", layerName)) {
// try {
// GSFeatureTypeEncoder gsFeatureTypeEncoder = new GSFeatureTypeEncoder();
// gsFeatureTypeEncoder.setTitle(layerName);
// gsFeatureTypeEncoder.setName(layerName);
// gsFeatureTypeEncoder.setSRS(GeoServerRESTPublisher.DEFAULT_CRS);
//
// GSLayerEncoder gsLayerEncoder = new GSLayerEncoder();
// gsLayerEncoder.addStyle("polygon");
//
//// boolean layer = publisher.configureLayer("rsinsure3", "mt-rsinsure3farmblock3", gsLayerEncoder);
// boolean layer = publisher.publishDBLayer("rsinsure3", "mt-rsinsure3farmblock2", gsFeatureTypeEncoder, gsLayerEncoder);
// System.out.println("publish layer : " + layer);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// GSFeatureTypeEncoder featureTypeEncoder = new GSFeatureTypeEncoder();
// featureTypeEncoder.setName("mt-rsinsure3farmblock2");
// featureTypeEncoder.setTitle("mt-rsinsure3farmblock2");
// featureTypeEncoder.setSRS(GeoServerRESTPublisher.DEFAULT_CRS);
// featureTypeEncoder.setNativeCRS(GeoServerRESTPublisher.DEFAULT_CRS);
//
// featureTypeEncoder.setProjectionPolicy(GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED);
// if (!publisher.createResource("rsinsure3", GeoServerRESTPublisher.StoreType.DATASTORES, "mt-rsinsure3farmblock2", featureTypeEncoder)) {
//
// } else {
// GSLayerEncoder layerEncoder = publisher.configureDefaultStyle("polygon");
// publisher.configureLayer("rsinsure3", "mt-rsinsure3farmblock2", layerEncoder);
// }
//publishShp(String workspace, String storename, String layername, File zipFile, String srs)
//
// boolean publish = publisher.publishShp("rsinsure3", "mt-rsinsure3farmblock", "mt-rsinsure3farmblock", new File("/Users/zhoujianwei/Downloads/农险平安202410/mt-rsinsure3farmblock.zip"), GeoServerRESTPublisher.DEFAULT_CRS);
// .publishShp("rsinsure3", "mt-rsinsure3farmblock", (NameValuePair[])null, "mt-rsinsure3farmblock", GeoServerRESTPublisher.UploadMethod.FILE, new File("/sdbdata/geoserver/data_insure3/block/mt-rsinsure3farmblock.zip"), "EPSG:4326",(String)null,
// GSResourceEncoder.ProjectionPolicy.FORCE_DECLARED, "polygon");
//
// File file = new File("/Users/zhoujianwei/Downloads/农险平安202410/mt-rsinsure3farmblock.zip");
////File file = new File("/Users/zhoujianwei/Downloads/农险平安202410/mt-rsinsure3farmblock/mt-rsinsure3farmblock.shp");
// flag = publisher.publishShp("rsinsure3", "mt-rsinsure3farmblock",
// new NameValuePair[]{new NameValuePair("charset", "UTF-8")},
// "mt-rsinsure3farmblock",
// GeoServerRESTPublisher.UploadMethod.FILE,
// file.toURI(),
// GeoServerRESTPublisher.DEFAULT_CRS,
// "polygon");
System.out.println(flag);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment