优化刷新数据状态方法。
This commit is contained in:
parent
bb5bc7468d
commit
21078a6f83
|
|
@ -1,15 +1,35 @@
|
|||
package com.electromagnetic.industry.software.manage;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.electromagnetic.industry.software.common.enums.EleDataStatusEnum;
|
||||
import com.electromagnetic.industry.software.manage.mapper.EdFileInfoMapper;
|
||||
import com.electromagnetic.industry.software.manage.pojo.models.EdFileInfo;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableScheduling
|
||||
@MapperScan("com.electromagnetic.industry.software.manage.mapper")
|
||||
public class Application {
|
||||
public class Application implements CommandLineRunner {
|
||||
|
||||
@Resource
|
||||
private EdFileInfoMapper edFileInfoMapper;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
edFileInfoMapper.update(Wrappers.lambdaUpdate(EdFileInfo.class)
|
||||
.set(EdFileInfo::getDataStatus, EleDataStatusEnum.PUBLISHED.code)
|
||||
.set(EdFileInfo::getUpdatedTime, new Date())
|
||||
.eq(EdFileInfo::getDataStatus, EleDataStatusEnum.OCCUPY.code));
|
||||
}
|
||||
}
|
||||
|
|
@ -37,6 +37,7 @@ import com.electromagnetic.industry.software.manage.pojo.resp.FileProjectVO;
|
|||
import com.electromagnetic.industry.software.manage.pojo.resp.FileVersionViewVO;
|
||||
import com.electromagnetic.industry.software.manage.pojo.resp.UploadRecordVO;
|
||||
import com.electromagnetic.industry.software.manage.service.*;
|
||||
import com.electromagnetic.industry.software.manage.tasks.FlushDataStatusList;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -325,6 +326,8 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
String info = StrFormatter.format("下载文件异常 {},路径 {}", fileName, dbPath);
|
||||
log.error(info, e);
|
||||
throw new BizException(info);
|
||||
} finally {
|
||||
FlushDataStatusList.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -277,10 +277,12 @@ public class BackupTask {
|
|||
}
|
||||
|
||||
// 每 2 分钟执行一次
|
||||
@Scheduled(cron = "0 0 4 * * ?")
|
||||
@Scheduled(cron = "*/3 * * * * ?")
|
||||
public void updateFileStatus() {
|
||||
DateTime twoMinutesAgo = DateUtil.offsetMinute(DateUtil.date(), -2);
|
||||
edFileInfoMapper.update(Wrappers.<EdFileInfo>lambdaUpdate().set(EdFileInfo::getDataStatus, EleDataStatusEnum.PUBLISHED.code).le(EdFileInfo::getUpdatedTime, twoMinutesAgo));
|
||||
String id = FlushDataStatusList.get();
|
||||
if (StrUtil.isNotEmpty(id)) {
|
||||
edFileInfoMapper.update(new EdFileInfo(), Wrappers.<EdFileInfo>lambdaUpdate().eq(EdFileInfo::getId, id).set(EdFileInfo::getDataStatus, EleDataStatusEnum.PUBLISHED.code));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
package com.electromagnetic.industry.software.manage.tasks;
|
||||
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FlushDataStatusList {
|
||||
|
||||
private static final Map<String, Date> MAP = new HashMap<>();
|
||||
|
||||
public static void add(String id) {
|
||||
MAP.put(id, new Date());
|
||||
}
|
||||
|
||||
public static String get() {
|
||||
|
||||
for (Map.Entry<String, Date> entry : MAP.entrySet()) {
|
||||
String id = entry.getKey();
|
||||
Date value = entry.getValue();
|
||||
long betweenMs = DateUtil.between(value, DateUtil.date(), DateUnit.MS);
|
||||
if (betweenMs >= 2000) {
|
||||
MAP.remove(id);
|
||||
return id;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue