Pārlūkot izejas kodu

1. 删除服务器文件
2. 升级fastJson 1.2.83

wuweihao 3 gadi atpakaļ
vecāks
revīzija
71fc006288

+ 21 - 1
720yun_fd_manage/gis_common/src/main/java/com/gis/common/util/FileUtils.java

@@ -3,8 +3,11 @@ package com.gis.common.util;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.img.Img;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.URLUtil;
+import com.gis.common.constant.ConfigConstant;
 import lombok.extern.log4j.Log4j2;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -24,7 +27,7 @@ import java.util.*;
 /**
  * Created by owen on 2020/5/12 0012 17:21
  */
-@Log4j2
+@Slf4j
 @Component
 public class FileUtils {
 
@@ -32,6 +35,9 @@ public class FileUtils {
     @Autowired
     AliyunOssUtil aliyunOssUtil;
 
+    @Autowired
+    ConfigConstant configConstant;
+
 
     /**
      * 多文件上传
@@ -770,4 +776,18 @@ public class FileUtils {
         return ossUrl;
     }
 
+
+    /**
+     * 真删除文件
+     * @param path 参数是相对地址
+     */
+    public void del(String path){
+        if (StrUtil.isNotBlank(path)){
+            String delPath = configConstant.serverBasePath + path;
+            FileUtil.del(delPath);
+            log.info("真删除文件: {}", delPath);
+        }
+
+    }
+
 }

+ 2 - 0
720yun_fd_manage/gis_mapper/src/main/java/com/gis/mapper/WorkMapper.java

@@ -45,4 +45,6 @@ public interface WorkMapper extends IBaseStrMapper<WorkEntity, String> {
     void delByTime(String now);
 
 
+    @Select("select id from tb_work where is_delete=0 and status=#{status}")
+    List<String> getIdByStatus(int status);
 }

+ 1 - 0
720yun_fd_manage/gis_service/src/main/java/com/gis/service/FodderService.java

@@ -27,4 +27,5 @@ public interface FodderService extends IBaseService<FodderEntity, Long> {
     Result checkStatus(String ids);
 
 
+    Result remove(Long id);
 }

+ 56 - 29
720yun_fd_manage/gis_service/src/main/java/com/gis/service/impl/FodderServiceImpl.java

@@ -12,17 +12,22 @@ import com.gis.common.exception.BaseRuntimeException;
 import com.gis.common.util.*;
 import com.gis.domain.dto.*;
 import com.gis.domain.entity.FodderEntity;
+import com.gis.domain.entity.WorkEntity;
 import com.gis.mapper.FodderMapper;
 import com.gis.mapper.IBaseMapper;
 import com.gis.service.FodderService;
 import com.gis.service.SceneService;
+import com.gis.service.WorkService;
 import com.github.pagehelper.PageInfo;
+import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.junit.Test;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.transaction.Transactional;
@@ -61,6 +66,9 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
     @Autowired
     AliyunOssUtil aliyunOssUtil;
 
+    @Autowired
+    WorkService workService;
+
     // 用户最大空间3G
     static int MAX_SIZE = 1024 * 1024 * 3;
 
@@ -72,7 +80,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
 
 
     @Override
-    public Result upload(MultipartFile file, String type, String tempId)  {
+    public Result upload(MultipartFile file, String type, String tempId) {
 
         long start = System.currentTimeMillis();
         String phone = getUserNameForToken();
@@ -93,16 +101,16 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
             return Result.failure(3003, "文件名称不允许超过50个字节");
         }
         String suffix = StringUtils.substringAfterLast(fileName, ".");
-        String newName = time  + "."  +suffix;
+        String newName = time + "." + suffix;
         String dirType = "fodder/";
         long size = file.getSize();
-        size = size/1024;
+        size = size / 1024;
         log.info("fileSize: " + size);
 
         String ossUrl = null;
         String iconPath = "0";
         String dpi = "0";
-        String ossPath = configConstant.ossBasePath+dirType+newName;
+        String ossPath = configConstant.ossBasePath + dirType + newName;
         String savePath = configConstant.serverBasePath;
         String ossPreviewIcon = null;
 
@@ -110,7 +118,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
         try {
             if (type.equals("pano")) {
 
-                if ((size/1024) >= 120) {
+                if ((size / 1024) >= 120) {
                     return Result.failure(MsgCode.e3004, "全景图文件不能超过120MB");
                 }
 
@@ -123,9 +131,8 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
                 }
 
                 String sceneCode = RandomUtils.getSceneCode("fd720_");
-                newName = sceneCode+"." + suffix;
-                savePath =savePath + sceneCode + "/" + newName;
-
+                newName = sceneCode + "." + suffix;
+                savePath = savePath + sceneCode + "/" + newName;
 
 
                 FileUtil.writeFromStream(file.getInputStream(), savePath);
@@ -136,12 +143,11 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
 
                 // 全景图的预览图
                 ossPreviewIcon = convertAndUploadOss(
-                        savePath, configConstant.ossBasePath + sceneCode , configConstant.ossDomain, 1920, 960, "/preview.jpg");
+                        savePath, configConstant.ossBasePath + sceneCode, configConstant.ossDomain, 1920, 960, "/preview.jpg");
 
                 // 使用oss截取缩略图
-                iconPath = ossPreviewIcon ;
-                ossUrl = configConstant.ossDomain+configConstant.ossBasePath + sceneCode;
-
+                iconPath = ossPreviewIcon;
+                ossUrl = configConstant.ossDomain + configConstant.ossBasePath + sceneCode;
 
 
                 entity.setSceneCode(sceneCode);
@@ -149,7 +155,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
                 entity.setStatus(1);
 
             } else {
-                ossUrl = configConstant.ossDomain+ossPath;
+                ossUrl = configConstant.ossDomain + ossPath;
 
                 if (type.equals("image")) {
                     // 图片大于1MB生成缩略图, 小于1MB使用原图作为缩略图
@@ -176,7 +182,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
             entity.setOssPath(ossUrl);
             entity.setIcon(iconPath);
             entity.setUserId(phone);
-            entity.setFileSize(size+"");
+            entity.setFileSize(size + "");
             entity.setDpi(dpi);
             entity.setPreviewIcon(ossPreviewIcon);
             entity.setTempId(tempId);
@@ -190,7 +196,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
                 log.info("发送消息到队列完成: " + entity.getId());
             }
             long end = System.currentTimeMillis();
-            log.info("上传完成,耗时: {} s" , (end-start)/1000);
+            log.info("上传完成,耗时: {} s", (end - start) / 1000);
         } catch (Exception e) {
             e.printStackTrace();
             log.error(e.getMessage());
@@ -202,19 +208,19 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
     }
 
 
-
     /**
      * 2021-04-27
      * 压缩图片 使用convert 工具
      * 固定名称: 名称固定是xxx.jpg
+     *
      * @param inputFilePath
      * @param ossBasePath
      * @param ossDomain
-     * @param width 宽
-     * @param height 高
+     * @param width         
+     * @param height        
      * @return 完整的oss访问地址
      */
-    public  String convertAndUploadOss(String inputFilePath, String ossBasePath, String ossDomain, Integer width, Integer height, String imgName){
+    public String convertAndUploadOss(String inputFilePath, String ossBasePath, String ossDomain, Integer width, Integer height, String imgName) {
         String serverBasePath = StringUtils.substringBeforeLast(inputFilePath, "/");
 
         // 保存图片位置
@@ -247,10 +253,6 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
     }
 
 
-
-
-
-
     @Override
     public Result search(FodderPageDto param) {
         startPage(param);
@@ -259,8 +261,6 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
     }
 
 
-
-
     @Override
     public Result selectFodderPano(PageDto param, String workId) {
         startPage(param);
@@ -277,7 +277,7 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
         List<FodderEntity> fodderList = pageInfo.getList();
         for (FodderEntity entity : fodderList) {
             String sceneCode = entity.getSceneCode();
-            if (useScenes.contains(sceneCode)){
+            if (useScenes.contains(sceneCode)) {
                 entity.setIsUse(1);
             }
             result.add(entity);
@@ -293,19 +293,46 @@ public class FodderServiceImpl extends IBaseServiceImpl<FodderEntity, Long> impl
         return Result.success(list);
     }
 
+    @Override
+    public Result remove(Long id) {
+        FodderEntity entity = this.findById(id);
+        if (entity == null) {
+            return Result.failure("对象不存在, id: " + id);
+        }
+
+        // 检查全景图是否被引用
+        if ("pano".equals(entity.getType())) {
+
+            if (entity.getStatus() == 1) {
+                return Result.failure("计算中的场景不能删除");
+            }
+
+            List<WorkEntity> list = workService.likeSceneCode(entity.getSceneCode());
+            if (list.size() > 0) {
+                return Result.failure(MsgCode.e3007, "素材已经被引用, 不能删除");
+            }
+        }
+
+        // 2022-06-09 删除服务器文件, 目前只有全景图
+        fileUtils.del(entity.getSceneCode());
+        entity.setIsDelete(1);
+        entity.setUpdateTime(new Date());
+        this.update(entity);
+        return Result.success();
+    }
+
 
     /**
      * 2022-05-31 by owen
      * 检查用户空间, 最大3G
+     *
      * @param phone
      */
-    private void checkUserSize(String phone){
+    private void checkUserSize(String phone) {
         Integer size = entityMapper.countSize(phone);
         log.info("当前用户空间: {} M", (size / 1024));
         BaseRuntimeException.isTrue(size >= MAX_SIZE, null, "该用户空间已满");
     }
 
 
-
-
 }

+ 14 - 2
720yun_fd_manage/gis_service/src/main/java/com/gis/service/impl/WorkServiceImpl.java

@@ -174,10 +174,19 @@ public class WorkServiceImpl extends IBaseStrServiceImpl<WorkEntity, String> imp
             String now = LocalDate.now().minusMonths(1).toString();
             log.warn("执行删除: {} 月份之前的空作品数据", now);
             entityMapper.delByTime(now);
+
+            List<String> ids = entityMapper.getIdByStatus(0);
+            for (String id : ids) {
+                // 删除服务器器文件
+                fileUtils.del(id);
+            }
+
             redisUtil.set(RedisConstant.WORK_DEL, now, 30, TimeUnit.DAYS);
         }
     }
 
+
+
     @Test
     public void test1(){
         LocalDate now = LocalDate.now();
@@ -197,8 +206,11 @@ public class WorkServiceImpl extends IBaseStrServiceImpl<WorkEntity, String> imp
         entity.setUpdateTime(new Date());
 
         // 分组、场景设置为删除
-        catalogMapper.setDeleteByWorkId(id);
-        sceneMapper.setDeleteByWorkId(id);
+//        catalogMapper.setDeleteByWorkId(id);
+//        sceneMapper.setDeleteByWorkId(id);
+
+        // 删除服务器器文件
+        fileUtils.del(entity.getId());
 
         this.update(entity);
 

+ 32 - 24
720yun_fd_manage/gis_web/src/main/java/com/gis/web/controller/FodderController.java

@@ -78,33 +78,41 @@ public class FodderController extends BaseController {
         return Result.success();
     }
 
-    @ApiOperation(value = "删除", position = 1)
-    @PostMapping("remove/{id}")
-    public Result remove( @PathVariable Long id) {
-        FodderEntity entity = fodderService.findById(id);
-        if (entity == null) {
-            return Result.failure("对象不存在, id: " + id);
-        }
-
-        // 检查全景图是否被引用
-        if ("pano".equals(entity.getType())) {
-
-            if (entity.getStatus() == 1) {
-                return Result.failure("计算中的场景不能删除");
-            }
+//    @ApiOperation(value = "删除", position = 1)
+//    @PostMapping("remove/{id}")
+//    public Result remove( @PathVariable Long id) {
+//        FodderEntity entity = fodderService.findById(id);
+//        if (entity == null) {
+//            return Result.failure("对象不存在, id: " + id);
+//        }
+//
+//        // 检查全景图是否被引用
+//        if ("pano".equals(entity.getType())) {
+//
+//            if (entity.getStatus() == 1) {
+//                return Result.failure("计算中的场景不能删除");
+//            }
+//
+//            List<WorkEntity> list = workService.likeSceneCode(entity.getSceneCode());
+//            if (list.size() > 0) {
+//                return Result.failure(MsgCode.e3007,"素材已经被引用, 不能删除");
+//            }
+//
+//
+//        }
+//
+//        entity.setIsDelete(1);
+//        entity.setUpdateTime(new Date());
+//        fodderService.update(entity);
+//        return Result.success();
+//    }
 
-            List<WorkEntity> list = workService.likeSceneCode(entity.getSceneCode());
-            if (list.size() > 0) {
-                return Result.failure(MsgCode.e3007,"素材已经被引用, 不能删除");
-            }
 
 
-        }
-
-        entity.setIsDelete(1);
-        entity.setUpdateTime(new Date());
-        fodderService.update(entity);
-        return Result.success();
+    @ApiOperation(value = "删除", position = 1)
+    @PostMapping("remove/{id}")
+    public Result remove( @PathVariable Long id) {
+        return fodderService.remove(id);
     }
 
     @ApiOperation(value = "详情", position = 1)

+ 1 - 1
720yun_fd_manage/pom.xml

@@ -32,7 +32,7 @@
         <java.version>1.8</java.version>
         <spring.boot.version>2.1.0.RELEASE</spring.boot.version>
         <gis.version>1.0.0</gis.version>
-        <fastjson.version>1.2.75</fastjson.version>
+        <fastjson.version>1.2.83</fastjson.version>
         <druid.version>1.1.14</druid.version>
         <hutool.version>5.3.3</hutool.version>
         <lombok.version>1.18.2</lombok.version>