|
@@ -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()));
|
|
|
+
|
|
|
+ }
|
|
|
+}
|