|
|
@@ -1,6 +1,8 @@
|
|
|
package com.ruoyi.system.service.impl;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.util.List;
|
|
|
+import com.ruoyi.common.config.RuoYiConfig;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -92,6 +94,8 @@ public class WatershedServiceServiceImpl implements IWatershedService
|
|
|
@Override
|
|
|
public int deleteWatershedServiceByServiceId(Long serviceId)
|
|
|
{
|
|
|
+ System.out.println("===== deleteWatershedServiceByServiceId called, serviceId=" + serviceId);
|
|
|
+ deleteServiceFiles(serviceId);
|
|
|
return watershedServiceMapper.deleteWatershedServiceByServiceId(serviceId);
|
|
|
}
|
|
|
|
|
|
@@ -104,6 +108,67 @@ public class WatershedServiceServiceImpl implements IWatershedService
|
|
|
@Override
|
|
|
public int deleteWatershedServiceByServiceIds(Long[] serviceIds)
|
|
|
{
|
|
|
+ System.out.println("===== deleteWatershedServiceByServiceIds called, serviceIds=" + java.util.Arrays.toString(serviceIds));
|
|
|
+ for (Long serviceId : serviceIds) {
|
|
|
+ deleteServiceFiles(serviceId);
|
|
|
+ }
|
|
|
return watershedServiceMapper.deleteWatershedServiceByServiceIds(serviceIds);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除自定义服务对应的本地文件
|
|
|
+ *
|
|
|
+ * @param serviceId 自定义服务主键
|
|
|
+ */
|
|
|
+ private void deleteServiceFiles(Long serviceId)
|
|
|
+ {
|
|
|
+ System.out.println("========== deleteServiceFiles START, serviceId=" + serviceId);
|
|
|
+ try {
|
|
|
+ WatershedService service = watershedServiceMapper.selectWatershedServiceByServiceId(serviceId);
|
|
|
+ System.out.println("========== deleteServiceFiles, service=" + service);
|
|
|
+ if (service != null && service.getServiceUrl() != null) {
|
|
|
+ String serviceUrl = service.getServiceUrl();
|
|
|
+ System.out.println("========== deleteServiceFiles, serviceUrl=" + serviceUrl);
|
|
|
+
|
|
|
+ if (serviceUrl.contains("/profile/geojson/")) {
|
|
|
+ String basePath = RuoYiConfig.getProfile();
|
|
|
+ System.out.println("========== deleteServiceFiles, basePath=" + basePath);
|
|
|
+
|
|
|
+ String geojsonPath = serviceUrl.replace("/profile/", "");
|
|
|
+ String geojsonFullPath = basePath + File.separator + geojsonPath;
|
|
|
+ System.out.println("========== deleteServiceFiles, geojsonFullPath=" + geojsonFullPath);
|
|
|
+
|
|
|
+ File geojsonFile = new File(geojsonFullPath);
|
|
|
+ if (geojsonFile.exists()) {
|
|
|
+ boolean deleted = geojsonFile.delete();
|
|
|
+ System.out.println("========== GeoJSON文件删除" + (deleted ? "成功: " : "失败: ") + geojsonFullPath);
|
|
|
+ } else {
|
|
|
+ System.out.println("========== GeoJSON文件不存在: " + geojsonFullPath);
|
|
|
+ }
|
|
|
+
|
|
|
+ String uuid = geojsonPath.replace("geojson", "").replace(".geojson", "").replace("/", "");
|
|
|
+ String shpDirPath = basePath + File.separator + "geojson" + File.separator + uuid;
|
|
|
+ System.out.println("========== deleteServiceFiles, shpDirPath=" + shpDirPath);
|
|
|
+
|
|
|
+ File shpDir = new File(shpDirPath);
|
|
|
+ if (shpDir.exists() && shpDir.isDirectory()) {
|
|
|
+ File[] files = shpDir.listFiles();
|
|
|
+ if (files != null) {
|
|
|
+ for (File file : files) {
|
|
|
+ file.delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ boolean deleted = shpDir.delete();
|
|
|
+ System.out.println("========== SHP文件夹删除" + (deleted ? "成功: " : "失败: ") + shpDirPath);
|
|
|
+ } else {
|
|
|
+ System.out.println("========== SHP文件夹不存在: " + shpDirPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("========== 删除本地文件时出错: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println("========== deleteServiceFiles END");
|
|
|
+ }
|
|
|
}
|