123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- 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.*;
- 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.nio.charset.StandardCharsets;
- 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();
- writerStateFile();
- }
- public void initConfig(){
- CacheUtil.uploadType = uploadType;
- CacheUtil.installPath = new File(installPath).getParentFile().getPath() +File.separator;
- Path path = pathService.getBasePath();
- if(path != null){
- CacheUtil.mapping = path.getMapping() + File.separator;
- CacheUtil.basePath = path.getDir() ;
- }else {
- CacheUtil.mapping = "profile" + File.separator;
- CacheUtil.basePath = CacheUtil.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("profile"+ 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().replace("profile",CacheUtil.installPath +"/4DKK_PROGRAM_STATIC"));
- if(!file.exists()){
- InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("static/default/tag_icon_default.svg");
- FileUtils.copyInputStreamToFile(inputStream,file);
- }
- }
- }catch (Exception e){
- }
- }
- @Autowired
- ICommonUploadService commonUploadService;
- @Autowired
- IModelService modelService;
- @Autowired
- ICaseFilesService caseFilesService;
- @Autowired
- IFusionNumService fusionNumService;
- 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());
- List<Model> list = modelService.list(wrapper);
- List<Integer> modelIds = list.stream().map(Model::getModelId).collect(Collectors.toList());
- List<FusionNum> fusionNums = fusionNumService.getByModelId(modelIds);
- LambdaQueryWrapper<CaseFiles> wrapper2 = new LambdaQueryWrapper<>();
- wrapper2.like(CaseFiles::getFilesUrl,commonUpload.getFileUrl());
- Long count2 = caseFilesService.count(wrapper2);
- if(fusionNums.size() + 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()));
- }
- private void writerStateFile() {
- String path = CacheUtil.installPath + "bin" + File.separator + "resources" + File.separator + "static" + File.separator +".fusionstate";
- log.info("写入status文件:{}",path);
- FileUtil.writeString("1",new File(path), StandardCharsets.UTF_8);
- }
- }
|