Pārlūkot izejas kodu

文件绝对路径

lyhzzz 5 mēneši atpakaļ
vecāks
revīzija
0b9e076510

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 2 - 0
null/fusion/default/tag_icon_default.svg


+ 3 - 18
src/main/java/com/fdkankan/fusion/FusionApplication.java

@@ -17,27 +17,12 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 @EnableScheduling
 @ComponentScan(basePackages = {"com.fdkankan.*"})
 @MapperScan("com.fdkankan.**.mapper")
-public class FusionApplication  implements CommandLineRunner {
+public class FusionApplication   {
+
 
-    @Value("${upload.type}")
-    private String uploadType;
-    @Value("${fdkk.installPath}")
-    private String installPath;
-    @Autowired
-    IPathService pathService;
     public static void main(String[] args) {
         SpringApplication.run(FusionApplication.class, args);
     }
 
-    @Override
-    public void run(String... args) throws Exception {
-        CacheUtil.uploadType = uploadType;
-        CacheUtil.installPath = installPath;
-        String path = pathService.getBasePath();
-        if(path != null){
-            CacheUtil.basePath = path ;
-        }else {
-            CacheUtil.basePath = installPath +"/4DKK_PROGRAM_STATIC/";
-        }
-    }
+
 }

+ 5 - 0
src/main/java/com/fdkankan/fusion/mapper/ICommonUploadMapper.java

@@ -4,6 +4,8 @@ import com.fdkankan.fusion.entity.CommonUpload;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
  * <p>
  *  Mapper 接口
@@ -15,4 +17,7 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface ICommonUploadMapper extends BaseMapper<CommonUpload> {
 
+    List<CommonUpload> getDelData();
+
+    void delByIds(List<Integer> ids);
 }

+ 6 - 0
src/main/java/com/fdkankan/fusion/service/ICommonUploadService.java

@@ -6,6 +6,8 @@ import com.fdkankan.fusion.entity.CommonUpload;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务类
@@ -24,4 +26,8 @@ public interface ICommonUploadService extends IService<CommonUpload> {
 
     void updateByPath(String localPath, String url, String wgs84, String gcj02);
     void updateByPath(String localPath, String url);
+
+    List<CommonUpload> getDelData();
+
+    void delByIds(List<Integer> ids);
 }

+ 10 - 0
src/main/java/com/fdkankan/fusion/service/impl/CommonUploadServiceImpl.java

@@ -291,4 +291,14 @@ public class CommonUploadServiceImpl extends ServiceImpl<ICommonUploadMapper, Co
         }
         return size;
     }
+
+    @Override
+    public List<CommonUpload> getDelData() {
+        return this.getBaseMapper().getDelData();
+    }
+
+    @Override
+    public void delByIds(List<Integer> ids) {
+         this.getBaseMapper().delByIds(ids);
+    }
 }

+ 135 - 0
src/main/java/com/fdkankan/fusion/task/InitService.java

@@ -0,0 +1,135 @@
+package com.fdkankan.fusion.task;
+
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.log.Log;
+import com.alibaba.fastjson.JSONArray;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.fdkankan.fusion.common.util.LocalToOssUtil;
+import com.fdkankan.fusion.config.CacheUtil;
+import com.fdkankan.fusion.entity.CaseFiles;
+import com.fdkankan.fusion.entity.CommonUpload;
+import com.fdkankan.fusion.entity.HotIcon;
+import com.fdkankan.fusion.entity.Model;
+import com.fdkankan.fusion.service.*;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+@Slf4j
+public class InitService {
+
+    @Autowired
+    IHotIconService hotIconService;
+    @Value("${upload.type}")
+    private String uploadType;
+    @Value("${fdkk.installPath}")
+    private String installPath;
+    @Autowired
+    IPathService pathService;
+    @PostConstruct
+    public void run()  {
+        initConfig();
+        checkDefaultImag();
+        delMediaLibrary();
+    }
+
+
+
+    public void initConfig(){
+        CacheUtil.uploadType = uploadType;
+        CacheUtil.installPath = installPath;
+        String path = pathService.getBasePath();
+        if(path != null){
+            CacheUtil.basePath = path ;
+        }else {
+            CacheUtil.basePath = installPath +"/4DKK_PROGRAM_STATIC/";
+        }
+    }
+
+    public void checkDefaultImag()  {
+        try {
+            List<HotIcon> defaultIcon = hotIconService.getDefaultIcon();
+            HotIcon hotIcon = null;
+            if(defaultIcon.isEmpty()){
+                hotIcon = new HotIcon();
+                hotIcon.setIconTitle("系统默认");
+                hotIcon.setIconUrl(CacheUtil.basePath+ File.separator+"fusion" + File.separator +"default"+File.separator+"tag_icon_default.svg" );
+                hotIcon.setIsSystem(1);
+                hotIconService.save(hotIcon);
+                log.info("默认热点数据不存在新建,{}",hotIcon.getIconUrl());
+            }else {
+                hotIcon = defaultIcon.get(0);
+            }
+
+            if(hotIcon != null){
+                File file = new File(hotIcon.getIconUrl());
+                if(!file.exists()){
+                    InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("static/tag_icon_default.svg");
+                    FileUtils.copyInputStreamToFile(inputStream,file);
+                }
+            }
+        }catch (Exception e){
+
+        }
+
+    }
+
+
+    @Autowired
+    ICommonUploadService commonUploadService;
+    @Autowired
+    IModelService modelService;
+    @Autowired
+    ICaseFilesService caseFilesService;
+
+
+    public void delMediaLibrary() {
+        List<CommonUpload> commonUploadList = commonUploadService.getDelData();
+        if(commonUploadList.isEmpty()){
+            return;
+        }
+        List<CommonUpload> delUploadList = new ArrayList<>();
+        for (CommonUpload commonUpload : commonUploadList) {
+            if(StringUtils.isNotBlank(commonUpload.getFileUrl())){
+                LambdaQueryWrapper<Model> wrapper = new LambdaQueryWrapper<>();
+                JSONArray jsonArray = new JSONArray();
+                jsonArray.add(commonUpload.getFileUrl());
+                wrapper.like(Model::getModelGlbUrl,jsonArray.toJSONString());
+                Long count1 = modelService.count(wrapper);
+
+                LambdaQueryWrapper<CaseFiles> wrapper2 = new LambdaQueryWrapper<>();
+                wrapper2.like(CaseFiles::getFilesUrl,commonUpload.getFileUrl());
+                Long count2 = caseFilesService.count(wrapper2);
+                if(count1 + count2 <=0){
+                    delUploadList.add(commonUpload);
+                }
+            }else {
+                delUploadList.add(commonUpload);
+            }
+        }
+
+        if(delUploadList.isEmpty()){
+            return;
+        }
+        for (CommonUpload commonUpload : delUploadList) {
+            FileUtil.del(commonUpload.getFileUrl());
+            FileUtil.del(commonUpload.getUnzipPath());
+            log.info("删除文件资源:{},{}",commonUpload.getFileUrl(),commonUpload.getUnzipPath());
+        }
+        commonUploadService.delByIds(delUploadList.stream().map(CommonUpload::getId).collect(Collectors.toList()));
+
+    }
+}

+ 11 - 0
src/main/resources/mapper/fusion/CommonUploadMapper.xml

@@ -2,4 +2,15 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fdkankan.fusion.mapper.ICommonUploadMapper">
 
+
+    <select id="getDelData" resultType="com.fdkankan.fusion.entity.CommonUpload">
+        select * from t_common_upload where rec_status = 'I'
+    </select>
+
+    <delete id="delByIds">
+        delete from t_common_upload where id in
+        <foreach collection="ids" item="id" open="(" separator="," close=")">
+            #{id}
+        </foreach>
+    </delete>
 </mapper>

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 2 - 0
src/main/resources/static/tag_icon_default.svg


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 2 - 0
tag_icon_default.svg