fix: 优化轮询逻辑

This commit is contained in:
tangwei 2026-05-07 16:10:11 +08:00
parent b8d401f662
commit f7eb3a8ab7
5 changed files with 23 additions and 50 deletions

View File

@ -702,28 +702,13 @@ public class FishDraftDataController {
return ResponseResult.successData(result);
}
int totalCount = currentTask.getTotalCount() != null ? currentTask.getTotalCount() : 0;
int successCount = currentTask.getSuccessCount() != null ? currentTask.getSuccessCount() : 0;
int failCount = currentTask.getFailCount() != null ? currentTask.getFailCount() : 0;
int progressPercent = totalCount > 0 ? (int) ((successCount + failCount) * 100.0 / totalCount) : 0;
String statusText = getStatusText(currentTask.getStatus());
boolean canImport = isTaskComplete(currentTask.getStatus());
Map<String, Object> taskInfo = new HashMap<>();
taskInfo.put("id", currentTask.getId());
taskInfo.put("importNo", currentTask.getImportNo());
taskInfo.put("fileName", currentTask.getFileName());
taskInfo.put("fileSize", currentTask.getFileSize());
taskInfo.put("status", currentTask.getStatus());
taskInfo.put("statusText", statusText);
taskInfo.put("totalCount", totalCount);
taskInfo.put("successCount", successCount);
taskInfo.put("failCount", failCount);
taskInfo.put("progressPercent", progressPercent);
taskInfo.put("errorMsg", currentTask.getErrorMsg() != null ? currentTask.getErrorMsg() : "");
taskInfo.put("uploadTime", currentTask.getUploadTime());
result.put("hasImportingTask", true);
result.put("canImport", canImport);
result.put("currentTask", taskInfo);

View File

@ -38,15 +38,16 @@ public interface ImportTaskMapper extends BaseMapper<ImportTask> {
@Select("SELECT * FROM IMPORT_TASK WHERE UPLOAD_USER_ID = #{uploadUserId} ORDER BY CREATED_AT DESC")
List<ImportTask> selectByUploadUserId(@Param("uploadUserId") String uploadUserId);
@Select("<script>" +
"SELECT * FROM IMPORT_TASK WHERE UPLOAD_USER_ID = #{uploadUserId} AND STATUS IN " +
"<foreach item='status' collection='statuses' open='(' separator=',' close=')'>" +
"#{status}" +
"</foreach>" +
@Select("SELECT * FROM (" +
"SELECT ID, IMPORT_NO, BIZ_TYPE, FILE_NAME, FILE_SIZE, FILE_PATH, TEMP_DIR, " +
"TOTAL_COUNT, SUCCESS_COUNT, FAIL_COUNT, STATUS, ERROR_MSG, " +
"UPLOAD_USER_ID, UPLOAD_TIME, EXPIRE_TIME, CREATED_AT, UPDATED_AT " +
"FROM IMPORT_TASK " +
"WHERE UPLOAD_USER_ID = #{uploadUserId} " +
"AND STATUS IN ('UPLOADED', 'PARSING', 'VALIDATED') " +
"ORDER BY CREATED_AT DESC" +
"</script>")
List<ImportTask> selectByUserIdAndStatuses(@Param("uploadUserId") String uploadUserId,
@Param("statuses") List<String> statuses);
") WHERE ROWNUM = 1")
List<ImportTask> selectByUserIdAndStatuses(@Param("uploadUserId") String uploadUserId);
/**
* 查询过期的任务

View File

@ -218,14 +218,14 @@ public class FishImportServiceImpl implements IFishImportService {
}
}
Set<String> allStcdSet = new HashSet<>();
// Set<String> allStcdSet = new HashSet<>();
if (!allowedHbrvcdSet.isEmpty() || !directStcdSet.isEmpty()) {
if (!allowedHbrvcdSet.isEmpty()) {
List<SdEngInfoBH> stationsFromHbrv = engInfoBHMapper.selectByHbrvcdList(new ArrayList<>(allowedHbrvcdSet));
for (SdEngInfoBH station : stationsFromHbrv) {
if (station.getStcd() != null) {
allStcdSet.add(station.getStcd());
directStcdSet.add(station.getStcd());
}
}
}
@ -234,7 +234,7 @@ public class FishImportServiceImpl implements IFishImportService {
List<SdEngInfoBH> stationsFromStcd = engInfoBHMapper.selectBatchIds(new ArrayList<>(directStcdSet));
for (SdEngInfoBH station : stationsFromStcd) {
if (station.getStcd() != null) {
allStcdSet.add(station.getStcd());
directStcdSet.add(station.getStcd());
}
if (station.getHbrvcd() != null) {
allowedHbrvcdSet.add(station.getHbrvcd());
@ -243,7 +243,7 @@ public class FishImportServiceImpl implements IFishImportService {
}
}
if (!directStcdSet.isEmpty()) {
List<SdFpssBH> sdFpssBHS = fpssBHMapper.selectList(new LambdaQueryWrapper<SdFpssBH>().in(SdFpssBH::getRstcd, allStcdSet).select(SdFpssBH::getStcd));
List<SdFpssBH> sdFpssBHS = fpssBHMapper.selectList(new LambdaQueryWrapper<SdFpssBH>().in(SdFpssBH::getRstcd, directStcdSet).select(SdFpssBH::getStcd));
for (SdFpssBH sdFpssBH : sdFpssBHS) {
if (sdFpssBH.getStcd() != null) {
directBHSet.add(sdFpssBH.getStcd());
@ -268,7 +268,7 @@ public class FishImportServiceImpl implements IFishImportService {
importRow.getWarnings().add("rstcd");
data.setEnnm(cellValue.trim());
} else {
if (allStcdSet.contains(stcd)) {
if (directStcdSet.contains(stcd)) {
data.setEnnm(cellValue.trim());
data.setRstcd(stcd);
} else {

View File

@ -12,12 +12,14 @@ import com.yfd.platform.data.mapper.ImportTaskMapper;
import com.yfd.platform.data.service.AttachmentUploadService;
import com.yfd.platform.data.service.IImportTaskService;
import jakarta.annotation.Resource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CompletableFuture;
/**
* <p>
@ -166,8 +168,8 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
@Override
public boolean hasImportingTask(String uploadUserId) {
List<String> activeStatuses = List.of("UPLOADED", "PARSING", "VALIDATING");
List<ImportTask> tasks = importTaskMapper.selectByUserIdAndStatuses(uploadUserId, activeStatuses);
// List<String> activeStatuses = List.of("UPLOADED", "PARSING", "VALIDATING");
List<ImportTask> tasks = importTaskMapper.selectByUserIdAndStatuses(uploadUserId);
return tasks != null && !tasks.isEmpty();
}
@ -185,21 +187,6 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
if (importTask.getResultJson() != null && !importTask.getResultJson().isEmpty()) {
try {
FishImportResult importResult = objectMapper.readValue(importTask.getResultJson(), FishImportResult.class);
// for (FishImportResult.FishImportRow successRow : importResult.getRows()) {
// if (successRow.getData()==null) {
// continue;
// }
// String vdpth = successRow.getData().getVdpth();
// if (StringUtils.hasText(vdpth)) {
// List<String> fileIds = StrUtil.split(vdpth, ",");
// fileIds.forEach(fileId -> attachmentUploadService.deleteFile(fileId));
// }
// String picpth = successRow.getData().getPicpth();
// if (StringUtils.hasText(picpth)) {
// List<String> fileIds = StrUtil.split(vdpth, ",");
// fileIds.forEach(fileId -> attachmentUploadService.deleteFile(fileId));
// }
// }
String tempDir = importResult.getTempDir();
// del 方法会递归删除目录及其所有内容
FileUtil.del(tempDir);
@ -216,8 +203,8 @@ public class ImportTaskServiceImpl extends ServiceImpl<ImportTaskMapper, ImportT
@Override
public ImportTask getCurrentTaskByUserId(String uploadUserId) {
List<String> activeStatuses = List.of("UPLOADED", "PARSING", "VALIDATED");
List<ImportTask> tasks = importTaskMapper.selectByUserIdAndStatuses(uploadUserId, activeStatuses);
// List<String> activeStatuses = List.of("UPLOADED", "PARSING", "VALIDATED");
List<ImportTask> tasks = importTaskMapper.selectByUserIdAndStatuses(uploadUserId);
if (tasks == null || tasks.isEmpty()) {
return null;
}

View File

@ -10,12 +10,12 @@ spring:
druid:
master:
driverClassName: oracle.jdbc.OracleDriver
url: "${DB_MASTER_URL:jdbc:oracle:thin:@172.16.31.190:1521/SDLYZ}"
url: "${DB_MASTER_URL:jdbc:oracle:thin:@172.16.21.134:1521/SDLYZ}"
username: "${DB_MASTER_USERNAME:QGC_REFA}"
password: "${DB_MASTER_PASSWORD:Y4M4K1oCkL8U}"
slave:
driverClassName: oracle.jdbc.OracleDriver
url: "${DB_SLAVE_URL:jdbc:oracle:thin:@172.16.31.190:1521/SDLYZ}"
url: "${DB_SLAVE_URL:jdbc:oracle:thin:@172.16.21.134:1521/SDLYZ}"
username: "${DB_SLAVE_USERNAME:QGC_REFA}"
password: "${DB_SLAVE_PASSWORD:Y4M4K1oCkL8U}"