package com.fdkankan.fusion.task; import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.unit.DataSizeUtil; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.fdkankan.fusion.common.util.DateUtils; import com.fdkankan.fusion.entity.*; import com.fdkankan.fusion.service.*; import com.fdkankan.redis.util.RedisUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.PostMapping; import javax.annotation.PostConstruct; import java.util.Date; import java.util.List; import java.util.Set; import static com.fdkankan.fusion.down.CaseDownService.downProcessKey; @Service public class TaskService { @Autowired ICaseLiveService caseLiveService; @Scheduled(initialDelay = 2000, fixedDelay = 1000 * 60) public void run() { List list = caseLiveService.list(); for (CaseLive caseLive : list) { Date hoursTime = DateUtils.getHoursTime(caseLive.getCreateTime()); if(hoursTime.getTime() <= new Date().getTime()){ caseLiveService.removeById(caseLive); } } } @Autowired RedisUtil redisUtil; @PostConstruct public void cleanRedisKey(){ String redisKey = String.format(downProcessKey, "*"); Set keys = redisUtil.keys(redisKey); if(keys != null && !keys.isEmpty()){ for (String key : keys) { redisUtil.del(key); } } //modelToMedia(); } @Autowired IModelService modelService; @Autowired ICommonUploadService commonUploadService; @Autowired IDictFileService dictFileService; @Autowired ITmUserService tmUserService; public void modelToMedia(){ LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(Model::getType,3); wrapper.eq(Model::getCreateStatus,1); wrapper.isNotNull(Model::getModelGlbUrl); wrapper.isNotNull(Model::getUserName); List list = modelService.list(wrapper); for (Model model : list) { TmUser tmUser = tmUserService.getByUserName(model.getUserName()); if(tmUser == null){ continue; } String modelGlbUrl = model.getModelGlbUrl(); JSONArray jsonArray = JSONArray.parseArray(modelGlbUrl); String fileUrl = (String) jsonArray.get(0); LambdaQueryWrapper wrapper1 = new LambdaQueryWrapper<>(); wrapper1.eq(CommonUpload::getFileUrl,fileUrl); List list1 = commonUploadService.list(wrapper1); if(!list1.isEmpty()){ continue; } CommonUpload commonUpload = new CommonUpload(); commonUpload.setFileName(model.getModelTitle()); commonUpload.setFileUrl(fileUrl); commonUpload.setFileSize(String.valueOf(DataSizeUtil.parse(model.getModelSize()))); commonUpload.setNewFileName(model.getModelTitle()); commonUpload.setFileType(3); commonUpload.setFileTypeStr("模型"); commonUpload.setFileFormat(model.getModelDateType()); commonUpload.setResultFileFormat(model.getModelType()); commonUpload.setStatus(1); commonUpload.setUseType("ordinary"); commonUploadService.save(commonUpload); DictFile dictFile = new DictFile(); dictFile.setName(model.getModelTitle()); dictFile.setTypeKey("media-library"); dictFile.setSysUserId(tmUser.getId()); dictFile.setUploadId(commonUpload.getId()); dictFile.setUseType("ordinary"); dictFileService.save(dictFile); } } }