lyhzzz 7 bulan lalu
induk
melakukan
b82ca401c2

+ 16 - 0
src/main/java/com/fdkankan/fusion/common/util/LocalToOssUtil.java

@@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
 import com.fdkankan.fusion.response.FileInfoVo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 
@@ -24,6 +25,9 @@ public class LocalToOssUtil {
     private String basePath;
 
     private String getOssPath(String bucket, String filePath) {
+        if(filePath.contains(basePath)){
+           return filePath.replace(basePath,basePath.concat(bucket).concat(File.separator));
+        }
         return basePath.concat(bucket).concat(File.separator).concat(filePath);
 
     }
@@ -122,4 +126,16 @@ public class LocalToOssUtil {
     public Long getSize(String filePath) {
         return getSizeCount( getOssPath(bucket, filePath));
     }
+
+    public void deleteModel(Integer modelId) {
+        if(modelId == null){
+            return;
+        }
+        String nasPath = getOssPath(bucket,"/oss/fusion/model/"+modelId);
+        File file = new File(nasPath);
+        if(!file.exists()){
+            return;
+        }
+        FileUtil.del(file);
+    }
 }

+ 17 - 0
src/main/java/com/fdkankan/fusion/common/util/MinIoChunkUtils.java

@@ -355,6 +355,23 @@ public class MinIoChunkUtils implements InitializingBean {
     }
 
     /**
+     * 删除文件
+     */
+    public static void deleteObject(String bucketName, String objectName) {
+        try {
+            if(objectName.contains(".")){
+                minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(objectName).build());
+            }else {
+                List<String> list = listObjectNames(bucketName, null, null);
+                for (String s : list) {
+                    minioClient.removeObject(RemoveObjectArgs.builder().bucket(bucketName).object(s).build());
+                }
+            }
+        } catch (Exception e) {
+        }
+    }
+
+    /**
      * 判断目录是否存在
      *
      * @param bucketName 存储桶

+ 4 - 0
src/main/java/com/fdkankan/fusion/common/util/UploadToOssUtil.java

@@ -142,6 +142,10 @@ public class UploadToOssUtil {
 		}
 	}
 
+	public void deleteModel(Integer modelId){
+		localToOssUtil.deleteModel(modelId);
+	}
+
 	/**
 	 * 获得文件列表-阿里云
 	 * @return

+ 4 - 0
src/main/java/com/fdkankan/fusion/mapper/IModelMapper.java

@@ -7,6 +7,8 @@ import com.fdkankan.fusion.request.ModelPram;
 import com.fdkankan.fusion.response.ModelVo;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
  * <p>
  *  Mapper 接口
@@ -19,4 +21,6 @@ import org.apache.ibatis.annotations.Mapper;
 public interface IModelMapper extends BaseMapper<Model> {
 
     Page<ModelVo> pageList(Page<Object> objectPage, ModelPram param);
+
+    List<Model> getByDelData();
 }

+ 4 - 0
src/main/java/com/fdkankan/fusion/mapper/IUploadChunkMapper.java

@@ -7,6 +7,8 @@ import com.fdkankan.fusion.request.ScenePram;
 import com.fdkankan.fusion.response.SceneVo;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
  * <p>
  *  Mapper 接口
@@ -19,4 +21,6 @@ import org.apache.ibatis.annotations.Mapper;
 public interface IUploadChunkMapper extends BaseMapper<UploadChunk> {
 
     Page<SceneVo> getScenePageList(Page<Object> objectPage, ScenePram param);
+
+    List<UploadChunk> getByDelData();
 }

+ 2 - 0
src/main/java/com/fdkankan/fusion/service/IModelService.java

@@ -53,4 +53,6 @@ public interface IModelService extends IService<Model> {
     Model getByUploadSuccess(String fileMd5);
 
     Model getByUPloadId(Integer id);
+
+    List<Model> getByDelData();
 }

+ 4 - 0
src/main/java/com/fdkankan/fusion/service/IUploadChunkService.java

@@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.fdkankan.fusion.request.ScenePram;
 import com.fdkankan.fusion.response.SceneVo;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -25,4 +27,6 @@ public interface IUploadChunkService extends IService<UploadChunk> {
     void uploadSuccess(UploadChunk uploadChunk);
 
     Page<SceneVo> getScenePageList(Page<Object> objectPage, ScenePram param);
+
+    List<UploadChunk> getByDelData();
 }

+ 6 - 4
src/main/java/com/fdkankan/fusion/service/impl/ModelServiceImpl.java

@@ -197,9 +197,6 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
             if(model != null ){
                 this.removeById(modelId);
                 fusionNumService.deleteByModelId(modelId);
-                if(StringUtils.isNotBlank(model.getModelGlbUrl() ) && checkeModelGlbUrl(model.getModelGlbUrl())){
-                    uploadService.deleteOssUrl(model.getModelGlbUrl());
-                }
                 if(model.getUploadId() != null){
                     this.updateUploadId(model.getModelId(),null);
                 }
@@ -218,7 +215,7 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
         LambdaQueryWrapper<Model> wrapper = new LambdaQueryWrapper<>();
         wrapper.eq(Model::getModelGlbUrl,modelGlbUrl);
         long count = this.count(wrapper);
-        if(count >1){
+        if(count >0){
             return false;
         }
         return true;
@@ -376,4 +373,9 @@ public class ModelServiceImpl extends ServiceImpl<IModelMapper, Model> implement
         }
         return list.get(0);
     }
+
+    @Override
+    public List<Model> getByDelData() {
+        return this.getBaseMapper().getByDelData();
+    }
 }

+ 4 - 1
src/main/java/com/fdkankan/fusion/service/impl/UploadChunkServiceImpl.java

@@ -122,5 +122,8 @@ public class UploadChunkServiceImpl extends ServiceImpl<IUploadChunkMapper, Uplo
         return this.getBaseMapper().getScenePageList(objectPage,param);
     }
 
-
+    @Override
+    public List<UploadChunk> getByDelData() {
+        return this.getBaseMapper().getByDelData();
+    }
 }

+ 61 - 7
src/main/java/com/fdkankan/fusion/task/TaskService.java

@@ -1,9 +1,19 @@
 package com.fdkankan.fusion.task;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.fdkankan.fusion.common.util.DateUtils;
+import com.fdkankan.fusion.common.util.MinIoChunkUtils;
+import com.fdkankan.fusion.common.util.UploadToOssUtil;
 import com.fdkankan.fusion.entity.CaseLive;
+import com.fdkankan.fusion.entity.Model;
+import com.fdkankan.fusion.entity.UploadChunk;
+import com.fdkankan.fusion.mapper.IModelMapper;
 import com.fdkankan.fusion.service.ICaseLiveService;
+import com.fdkankan.fusion.service.IModelService;
+import com.fdkankan.fusion.service.IUploadChunkService;
 import com.fdkankan.redis.util.RedisUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
@@ -15,20 +25,64 @@ import java.util.List;
 import java.util.Set;
 
 import static com.fdkankan.fusion.down.CaseDownService.downProcessKey;
+import static com.fdkankan.fusion.down.CaseDownService.model;
 
 @Service
+@Slf4j
 public class TaskService {
 
     @Autowired
-    ICaseLiveService caseLiveService;
+    IUploadChunkService uploadChunkService;
+    @Autowired
+    IModelService modelService;
+    @Autowired
+    UploadToOssUtil uploadToOssUtil;
+
 
-    @Scheduled(initialDelay = 2000, fixedDelay = 1000 * 60)
+    /**
+     * 清除删除数据资源
+     */
+    @Scheduled(initialDelay = 2000, fixedDelay = 1000 * 60 * 60 * 24)
     public void run() {
-        List<CaseLive> list = caseLiveService.list();
-        for (CaseLive caseLive : list) {
-            Date hoursTime = DateUtils.getHoursTime(caseLive.getCreateTime());
-            if(hoursTime.getTime() <= new Date().getTime()){
-                caseLiveService.removeById(caseLive);
+        List<Model> modelList = modelService.getByDelData();
+        if(modelList.isEmpty()){
+            return;
+        }
+        for (Model model1 : modelList) {
+            if(StringUtils.isBlank(model1.getModelGlbUrl())){
+                continue;
+            }
+            LambdaQueryWrapper<Model> wrapper = new LambdaQueryWrapper<>();
+            wrapper.eq(Model::getModelGlbUrl,model1.getModelGlbUrl());
+            long count = modelService.count(wrapper);
+            if(count <=0){
+                log.info("删除文件资源:{},{}",model1.getModelId(),model1.getModelGlbUrl());
+                uploadToOssUtil.deleteModel(model1.getModelId());
+            }
+        }
+        List<UploadChunk> uploadChunks = uploadChunkService.getByDelData();
+        if(uploadChunks.isEmpty()){
+            return;
+        }
+        for (UploadChunk uploadChunk : uploadChunks) {
+
+            if(StringUtils.isNotBlank(uploadChunk.getFileMd5())){
+                LambdaQueryWrapper<UploadChunk> wrapper = new LambdaQueryWrapper<>();
+                wrapper.eq(UploadChunk::getFileMd5,uploadChunk.getFileMd5());
+                long count = uploadChunkService.count(wrapper);
+                if(count <=0){
+                    log.info("删除文件资源:{},{}",MinIoChunkUtils.chunkBucKet,uploadChunk.getFileMd5());
+                    MinIoChunkUtils.deleteObject(MinIoChunkUtils.chunkBucKet,uploadChunk.getFileMd5());
+                }
+            }
+            if(StringUtils.isNotBlank(uploadChunk.getFilePath())){
+                LambdaQueryWrapper<UploadChunk> wrapper = new LambdaQueryWrapper<>();
+                wrapper.eq(UploadChunk::getFilePath,uploadChunk.getFilePath());
+                long count = uploadChunkService.count(wrapper);
+                if(count <=0){
+                    log.info("删除文件资源:{},{}",MinIoChunkUtils.chunkBucKet,uploadChunk.getFilePath());
+                    MinIoChunkUtils.deleteObject(MinIoChunkUtils.chunkBucKet,uploadChunk.getFilePath());
+                }
             }
         }
     }

+ 4 - 0
src/main/resources/mapper/fusion/ModelMapper.xml

@@ -52,5 +52,9 @@
         order by create_time desc
     </select>
 
+    <select id="getByDelData" resultType="com.fdkankan.fusion.entity.Model">
+        SELECT * from t_model WHERE tb_status !=0 and update_time >= DATE_SUB(NOW(), INTERVAL 1 DAY);
+    </select>
+
 
 </mapper>

+ 3 - 0
src/main/resources/mapper/fusion/ScenePlusMapper.xml

@@ -51,6 +51,9 @@
         <if test="param.sceneName != null and param.sceneName != ''">
             and s.title like concat ('%',#{param.sceneName},'%')
         </if>
+        <if test="param.status != null and param.status ==2">
+            and s.scene_status = -2
+        </if>
         <if test="param.userNames != null and param.userNames.size >0">
             and u.user_name in
             <foreach collection="param.userNames" item="userName" open="(" separator="," close=")">

+ 4 - 0
src/main/resources/mapper/fusion/UploadChunkMapper.xml

@@ -42,4 +42,8 @@
 
     order by  u.id desc
     </select>
+    <select id="getByDelData" resultType="com.fdkankan.fusion.entity.UploadChunk">
+        SELECT * from t_upload_chunk WHERE tb_status !=0 and update_time >= DATE_SUB(NOW(), INTERVAL 1 DAY);
+
+    </select>
 </mapper>