diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/crops/FarmMachineryController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/crops/FarmMachineryController.java index 1f78970..f234b77 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/crops/FarmMachineryController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/crops/FarmMachineryController.java @@ -21,11 +21,8 @@ import com.ruoyi.crops.domain.gsonBean.GsonFarmMachineryBean; import com.ruoyi.crops.domain.gsonBean.GsonMachineryPositionBean; import com.ruoyi.crops.domain.vo.FarmMachineryVo; import com.ruoyi.crops.domain.vo.MachineryJobDataVo; -import com.ruoyi.crops.service.IFarmMachineryService; -import com.ruoyi.crops.service.IGeoServer; -import com.ruoyi.crops.service.IMapDrawPolygonService; +import com.ruoyi.crops.service.*; -import com.ruoyi.crops.service.IWarningFarmService; import org.apache.commons.collections.map.HashedMap; import org.checkerframework.checker.units.qual.A; import org.locationtech.jts.geom.Geometry; @@ -59,6 +56,8 @@ public class FarmMachineryController extends BaseController { @Autowired private IWarningFarmService iWarningFarmService; @Autowired + private IGeoserverShpService iGeoserverShpService; + @Autowired private IGeoServer iGeoServer; @Value("${FarmMachinery.vehicleList}") @@ -274,7 +273,7 @@ public class FarmMachineryController extends BaseController { userdata.add(trajectory.getWorkplace()); //通过农机编号查询作业类型 userdata.add(String.valueOf(iFarmMachineryService.selectJobtype(vehicleno))); - + userdata.add(DateUtils.getDate()); //截取wkt格式字符串,改变为MULTIPOLYGON格式 String substring = drawPolygon.substring(8, drawPolygon.length() - 1); String linestring = line.substring(10); @@ -330,8 +329,14 @@ public class FarmMachineryController extends BaseController { String polygonZipPath = RuoYiConfig.getUploadPath()+ "/shpFile/" + LocalDate.now() + "polygon.zip"; String lineStringZipPath = RuoYiConfig.getUploadPath()+ "/shpFile/lineString.zip"; //发布shp服务 - String polygonShpResult = iGeoServer.publishShp("PJZ", fileName, fileName, polygonZipPath); - String lineStringShpResult = iGeoServer.publishShp("PJZ", "lineString", "lineString", lineStringZipPath); + Boolean polygonShpResult = iGeoServer.publishShp("PJZ", fileName, fileName, polygonZipPath); + Boolean lineStringShpResult = iGeoServer.publishShp("PJZ", "lineString", "lineString", lineStringZipPath); + if (polygonShpResult){ + GeoserverShp geoserverShp = new GeoserverShp(); + geoserverShp.setFileName(fileName); + geoserverShp.setTime(new Date()); + iGeoserverShpService.insert(geoserverShp); + } result.put("publishPolygonShp", polygonShpResult); result.put("publishlineStringShp", lineStringShpResult); return AjaxResult.success(result); diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/crops/GeoserverShpController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/crops/GeoserverShpController.java new file mode 100644 index 0000000..74c7c0e --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/crops/GeoserverShpController.java @@ -0,0 +1,53 @@ +package com.ruoyi.web.controller.crops; + +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.crops.domain.GeoserverShp; +import com.ruoyi.crops.service.IGeoserverShpService; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Date; + +/** + * 发布shp地图服务文件表;(geoserver_shp)表控制层 + * @author : http://www.chiner.pro + * @date : 2023-6-30 + */ +@RestController +@RequestMapping("/geoserverShp") +public class GeoserverShpController extends BaseController { + @Autowired + private IGeoserverShpService iGeoserverShpService; + + /** + * 通过时间查询 + */ + @GetMapping("/queryByTime") + public AjaxResult queryByTime(@RequestParam Date beginTime,Date endTime){ + return AjaxResult.success(iGeoserverShpService.queryByTime(beginTime,endTime)); + } + + /** + * 新增数据 + * + * @param geoserverShp 实例对象 + * @return 实例对象 + */ + @PostMapping + public AjaxResult add(GeoserverShp geoserverShp){ + return AjaxResult.success(iGeoserverShpService.insert(geoserverShp)); + } + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + @DeleteMapping + public AjaxResult deleteById(Integer id){ + return AjaxResult.success(iGeoserverShpService.deleteById(id)); + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ShapeUtil.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ShapeUtil.java index c4b829b..8b3289d 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ShapeUtil.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ShapeUtil.java @@ -75,6 +75,8 @@ public class ShapeUtil { builder.add("workplace", String.class); //作业类型 builder.add("jobtype", String.class); + //作业时间 + builder.add("date", String.class); if ("Polygon".equals(geoType) || "polygon".equals(geoType)) { builder.add("the_geom", Polygon.class); @@ -172,6 +174,7 @@ public class ShapeUtil { featureBuilder.add(userdata.get(++index)); featureBuilder.add(userdata.get(++index)); featureBuilder.add(userdata.get(++index)); + featureBuilder.add(userdata.get(++index)); featureBuilder.add(polygon); SimpleFeature feature = featureBuilder.buildFeature(null); @@ -195,6 +198,7 @@ public class ShapeUtil { featureBuilder.add(userdata.get(++index)); featureBuilder.add(userdata.get(++index)); featureBuilder.add(userdata.get(++index)); + featureBuilder.add(userdata.get(++index)); featureBuilder.add(lineString); SimpleFeature feature = featureBuilder.buildFeature(null); diff --git a/ruoyi-crops/src/main/java/com/ruoyi/crops/domain/GeoserverShp.java b/ruoyi-crops/src/main/java/com/ruoyi/crops/domain/GeoserverShp.java new file mode 100644 index 0000000..2ea7680 --- /dev/null +++ b/ruoyi-crops/src/main/java/com/ruoyi/crops/domain/GeoserverShp.java @@ -0,0 +1,48 @@ +package com.ruoyi.crops.domain; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonInclude; + +import java.util.Date; + +/** + * 发布shp地图服务文件表; + * @author : http://www.chiner.pro + * @date : 2023-6-30 + */ + +public class GeoserverShp{ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private Integer id ; + private String fileName ; + @JsonFormat(pattern="yyyy-MM-dd",timezone = "GMT+8") + private Date time ; + + public Integer getId(){ + return this.id; + } + public void setId(Integer id){ + this.id=id; + } + public String getFileName(){ + return this.fileName; + } + public void setFileName(String fileName){ + this.fileName=fileName; + } + public Date getTime(){ + return this.time; + } + public void setTime(Date time){ + this.time=time; + } + + @Override + public String toString() { + return "GeoserverShp{" + + "id=" + id + + ", fileName='" + fileName + '\'' + + ", time='" + time + '\'' + + '}'; + } +} diff --git a/ruoyi-crops/src/main/java/com/ruoyi/crops/domain/vo/FarmMachineryVo.java b/ruoyi-crops/src/main/java/com/ruoyi/crops/domain/vo/FarmMachineryVo.java index d06f0fd..51870f3 100644 --- a/ruoyi-crops/src/main/java/com/ruoyi/crops/domain/vo/FarmMachineryVo.java +++ b/ruoyi-crops/src/main/java/com/ruoyi/crops/domain/vo/FarmMachineryVo.java @@ -5,6 +5,8 @@ public class FarmMachineryVo { private Integer id ; /** 农机编号 */ private String vehicleno ; + /** 终端编号 */ + private String vmeid ; /** 农机类型 */ private String vehicletype ; /** 车主姓名 */ @@ -41,4 +43,12 @@ public class FarmMachineryVo { public void setOwnername(String ownername) { this.ownername = ownername; } + + public String getVmeid() { + return vmeid; + } + + public void setVmeid(String vmeid) { + this.vmeid = vmeid; + } } diff --git a/ruoyi-crops/src/main/java/com/ruoyi/crops/mapper/GeoserverShpMapper.java b/ruoyi-crops/src/main/java/com/ruoyi/crops/mapper/GeoserverShpMapper.java new file mode 100644 index 0000000..b1b608c --- /dev/null +++ b/ruoyi-crops/src/main/java/com/ruoyi/crops/mapper/GeoserverShpMapper.java @@ -0,0 +1,15 @@ +package com.ruoyi.crops.mapper; + +import com.ruoyi.crops.domain.GeoserverShp; +import org.apache.ibatis.annotations.Param; + +import java.util.Date; +import java.util.List; + +public interface GeoserverShpMapper { + List queryByTime(@Param("beginTime")Date beginTime, @Param("endTime")Date endTime); + + void insert(GeoserverShp geoserverShp); + + int deleteById(Integer id); +} diff --git a/ruoyi-crops/src/main/java/com/ruoyi/crops/service/IFarmMachineryService.java b/ruoyi-crops/src/main/java/com/ruoyi/crops/service/IFarmMachineryService.java index e59293b..d115494 100644 --- a/ruoyi-crops/src/main/java/com/ruoyi/crops/service/IFarmMachineryService.java +++ b/ruoyi-crops/src/main/java/com/ruoyi/crops/service/IFarmMachineryService.java @@ -11,7 +11,6 @@ import org.locationtech.jts.geom.Coordinate; import java.util.Date; import java.util.List; -import java.util.Map; public interface IFarmMachineryService { diff --git a/ruoyi-crops/src/main/java/com/ruoyi/crops/service/IGeoServer.java b/ruoyi-crops/src/main/java/com/ruoyi/crops/service/IGeoServer.java index 7ac8732..6bccec5 100644 --- a/ruoyi-crops/src/main/java/com/ruoyi/crops/service/IGeoServer.java +++ b/ruoyi-crops/src/main/java/com/ruoyi/crops/service/IGeoServer.java @@ -6,6 +6,6 @@ import com.ruoyi.crops.domain.ServiceType; public interface IGeoServer { public String publishTiff(String workSpace, String storeName, String filePath ,String styleName) throws Exception; - public String publishShp(String workSpace, String storeName, String layername, String filePath); + public Boolean publishShp(String workSpace, String storeName, String layername, String filePath); int insert(ServiceType serviceType); } diff --git a/ruoyi-crops/src/main/java/com/ruoyi/crops/service/IGeoserverShpService.java b/ruoyi-crops/src/main/java/com/ruoyi/crops/service/IGeoserverShpService.java new file mode 100644 index 0000000..1ccf4c0 --- /dev/null +++ b/ruoyi-crops/src/main/java/com/ruoyi/crops/service/IGeoserverShpService.java @@ -0,0 +1,36 @@ +package com.ruoyi.crops.service; +import com.ruoyi.crops.domain.GeoserverShp; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; + +import java.util.Date; +import java.util.List; + + +/** + * 发布shp地图服务文件表;(geoserver_shp)表服务接口 + * @author : http://www.chiner.pro + * @date : 2023-6-30 + */ +public interface IGeoserverShpService { + /** + * 通过时间查询 + */ + List queryByTime(Date begintime,Date endtime); + + /** + * 新增数据 + * + * @param geoserverShp 实例对象 + * @return 实例对象 + */ + GeoserverShp insert(GeoserverShp geoserverShp); + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + boolean deleteById(Integer id); +} diff --git a/ruoyi-crops/src/main/java/com/ruoyi/crops/service/impl/GeoServerImpl.java b/ruoyi-crops/src/main/java/com/ruoyi/crops/service/impl/GeoServerImpl.java index 23f6b4f..c8c4c0c 100644 --- a/ruoyi-crops/src/main/java/com/ruoyi/crops/service/impl/GeoServerImpl.java +++ b/ruoyi-crops/src/main/java/com/ruoyi/crops/service/impl/GeoServerImpl.java @@ -72,8 +72,8 @@ public class GeoServerImpl implements IGeoServer { } @Override - public String publishShp(String workSpace, String storeName, String layername, String filePath) { - String result=""; + public Boolean publishShp(String workSpace, String storeName, String layername, String filePath) { + boolean result = false; try { File zipFile=new File(filePath); GeoServerRESTReader reader = new GeoServerRESTReader(url, username, password); @@ -92,10 +92,10 @@ public class GeoServerImpl implements IGeoServer { if(workspaces.contains(workSpace)){ if(publisher.publishShp(workSpace, storeName, layername, zipFile, "EPSG:4326")){ - result = "发布成功!"; - } else { - result = "发布失败!"; +// result = "发布成功!"; + result = true; } + } }catch (Exception e){ e.printStackTrace(); diff --git a/ruoyi-crops/src/main/java/com/ruoyi/crops/service/impl/GeoserverShpServiceImpl.java b/ruoyi-crops/src/main/java/com/ruoyi/crops/service/impl/GeoserverShpServiceImpl.java new file mode 100644 index 0000000..afc64d6 --- /dev/null +++ b/ruoyi-crops/src/main/java/com/ruoyi/crops/service/impl/GeoserverShpServiceImpl.java @@ -0,0 +1,50 @@ +package com.ruoyi.crops.service.impl; + +import com.ruoyi.crops.domain.GeoserverShp; +import com.ruoyi.crops.mapper.GeoserverShpMapper; +import com.ruoyi.crops.service.IGeoserverShpService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +/** + * 发布shp地图服务文件表;(geoserver_shp)表服务实现类 + * @author : http://www.chiner.pro + * @date : 2023-6-30 + */ +@Service +public class GeoserverShpServiceImpl implements IGeoserverShpService { + @Autowired + private GeoserverShpMapper geoserverShpMapper; + + /** + * 通过时间查询 + */ + public List queryByTime(Date beginTime,Date endTime){ + return geoserverShpMapper.queryByTime(beginTime,endTime); + } + + /** + * 新增数据 + * + * @param geoserverShp 实例对象 + * @return 实例对象 + */ + public GeoserverShp insert(GeoserverShp geoserverShp){ + geoserverShpMapper.insert(geoserverShp); + return geoserverShp; + } + + /** + * 通过主键删除数据 + * + * @param id 主键 + * @return 是否成功 + */ + public boolean deleteById(Integer id){ + int total = geoserverShpMapper.deleteById(id); + return total > 0; + } +} diff --git a/ruoyi-crops/src/main/resources/mapper/crops/FarmMachineryMapper.xml b/ruoyi-crops/src/main/resources/mapper/crops/FarmMachineryMapper.xml index cfd8e5e..ae85547 100644 --- a/ruoyi-crops/src/main/resources/mapper/crops/FarmMachineryMapper.xml +++ b/ruoyi-crops/src/main/resources/mapper/crops/FarmMachineryMapper.xml @@ -16,7 +16,7 @@ + select file_name,time from ruoyi.geoserver_shp where time between #{beginTime} and #{endTime} + + + + insert into ruoyi.geoserver_shp(file_name, time) + select #{fileName} ,#{time} + where not exists (select file_name from ruoyi.geoserver_shp where file_name = #{fileName}) + + + + delete from ruoyi.geoserver_shp where id = #{id} + + diff --git a/ruoyi-crops/src/main/resources/mapper/crops/MachineryJobDataMapper.xml b/ruoyi-crops/src/main/resources/mapper/crops/MachineryJobDataMapper.xml index 9c9b066..561c71e 100644 --- a/ruoyi-crops/src/main/resources/mapper/crops/MachineryJobDataMapper.xml +++ b/ruoyi-crops/src/main/resources/mapper/crops/MachineryJobDataMapper.xml @@ -34,7 +34,7 @@