fix: 优化逻辑

This commit is contained in:
tangwei 2026-09-01 11:50:51 +08:00
parent 83a18a31a1
commit 817c3ba49d
2 changed files with 63 additions and 24 deletions

View File

@ -75,16 +75,16 @@ public class JobRunner implements ApplicationRunner {
ao.setStartTime(DateUtil.beginOfYear(DateUtil.offset(ao.getEndTime(), DateField.YEAR,-1)));
}
envWqDataService.wqLastData(ao);
log.info("--------------------wq最新一条数据---------------------");
eqJobService.eqAnchorPointLastDate(ao);
log.info("--------------------eq最新一条数据---------------------");
eqJobService.eqAnchorPointLastDate(ao);
log.info("--------------------eq最新一条数据---------------------");
dwJobService.wtLastData(ao);
log.info("--------------------wt最新一条数据---------------------");
dwJobService.wtvtPointData(ao);
log.info("--------------------wt最新一条数据---------------------");
fhJobService.zqLastData(ao);
log.info("--------------------fh最新一条数据---------------------");
// log.info("--------------------wq最新一条数据---------------------");
// eqJobService.eqAnchorPointLastDate(ao);
// log.info("--------------------eq最新一条数据---------------------");
// eqJobService.eqAnchorPointLastDate(ao);
// log.info("--------------------eq最新一条数据---------------------");
// dwJobService.wtLastData(ao);
// log.info("--------------------wt最新一条数据---------------------");
// dwJobService.wtvtPointData(ao);
// log.info("--------------------wt最新一条数据---------------------");
// fhJobService.zqLastData(ao);
// log.info("--------------------fh最新一条数据---------------------");
}
}

View File

@ -27,6 +27,7 @@ import com.yfd.platform.utils.ExportZipUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@ -362,8 +363,26 @@ public class QgcExportServiceImpl implements IQgcExportService {
}
if (rstcdToStcd.isEmpty()) {
log.warn("指标 {} 未找到 STTP={} 的测站数据", processor.getFieldName(), sttp);
return null;
// 无对应测站时仍生成 Sheet仅保留日期列无电站列避免整表缺失
log.warn("指标 {} 未找到 STTP={} 的测站数据,生成空 Sheet仅日期列", processor.getFieldName(), sttp);
List<List<Object>> emptyRows = new ArrayList<>();
int daysInMonth = getDaysInMonth(mr);
for (int d = 1; d <= daysInMonth; d++) {
List<Object> row = new ArrayList<>();
row.add(String.format("%02d", d));
emptyRows.add(row);
}
List<String> emptyLabels = processor.isVariation()
? VARIATION_LABELS
: (processor.hasComplianceRate()
? List.of("日均最低", "日均最高", "月内最低", "月内最低时间", "月内最高", "月内最高时间", "月均", LABEL_COMPLIANCE)
: BASE_LABELS);
for (String label : emptyLabels) {
List<Object> row = new ArrayList<>();
row.add(label);
emptyRows.add(row);
}
return emptyRows;
}
List<String> uniqueStcds = rstcdToStcd.values().stream().distinct().toList();
@ -466,8 +485,16 @@ public class QgcExportServiceImpl implements IQgcExportService {
}
}
if (rstcdToStcd.isEmpty()) {
log.warn("生态流量未找到 STTP=ENG 的测站数据");
return null;
// 未找到电站时仍生成 Sheet仅保留子标题行无电站数据行
log.warn("生态流量未找到 STTP=ENG 的测站数据,生成空 Sheet");
List<String> subHeaders = Arrays.asList("电站名称", "所属水电基地", "生态流量限值", "日达标率", "小时达标率", "备注");
List<Object> subRow = new ArrayList<>();
subRow.addAll(subHeaders);
subRow.addAll(subHeaders);
subRow.addAll(subHeaders);
List<List<Object>> rows = new ArrayList<>();
rows.add(subRow);
return rows;
}
List<String> uniqueStcds = rstcdToStcd.values().stream().distinct().toList();
@ -773,8 +800,20 @@ public class QgcExportServiceImpl implements IQgcExportService {
}
}
if (rstcdToStcd.isEmpty()) {
log.warn("水质达标率未找到 STTP=WQ 的测站数据");
return null;
// 未找到测站时仍生成 Sheet仅保留子标题行无电站数据行
log.warn("水质达标率未找到 STTP=WQ 的测站数据,生成空 Sheet");
List<Object> subRow = new ArrayList<>();
subRow.add("");
subRow.add("达标数");
subRow.add("总数");
subRow.add("达标率(%)");
subRow.add("达标数");
subRow.add("总数");
subRow.add("达标率(%)");
subRow.add("");
List<List<Object>> rows = new ArrayList<>();
rows.add(subRow);
return rows;
}
List<String> uniqueStcds = rstcdToStcd.values().stream().distinct().toList();
@ -1007,13 +1046,13 @@ public class QgcExportServiceImpl implements IQgcExportService {
private StationResolution resolveStations(List<String> rstcds, Set<String> sttpTypes) {
StationResolution result = new StationResolution();
if (rstcds == null || rstcds.isEmpty()) return result;
List<StationMapping> mappings = stationMappingMapper.selectList(
new LambdaQueryWrapper<StationMapping>()
.in(StationMapping::getRstcd, rstcds)
.or()
.in(StationMapping::getStcd, rstcds)
);
LambdaQueryWrapper<StationMapping> wrapper = new LambdaQueryWrapper<>();
wrapper.and(w -> {
if (CollectionUtils.isNotEmpty(rstcds)) {
w.in(StationMapping::getRstcd, rstcds).or().in(StationMapping::getStcd, rstcds);
}
});
List<StationMapping> mappings = stationMappingMapper.selectList(wrapper);
// 添加逻辑如果 sttp "ENG" rstcd 赋值为 stcd
mappings.forEach(mapping -> {