fix: 优化sheet电站排序
This commit is contained in:
parent
062590a032
commit
a4f0d34776
@ -0,0 +1,25 @@
|
|||||||
|
package com.yfd.platform.qgc_export.mapper;
|
||||||
|
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MS_ALONGDET_B 沿程配置详情表 Mapper
|
||||||
|
*/
|
||||||
|
public interface MsAlongdetBMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询指定 STTP 类型的出库沿程配置(IO_DIRECTION=1),按 SORT 排序。
|
||||||
|
*/
|
||||||
|
List<Map<String, Object>> selectAlongStations(@Param("sttp") String sttp,
|
||||||
|
@Param("rstcdList") List<String> rstcdList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有沿程配置的电站排序(MS_ALONG_B JOIN MS_ALONGDET_B),
|
||||||
|
* 按 MS_ALONG_B.ORDER_INDEX, MS_ALONGDET_B.SORT 排序。
|
||||||
|
* 返回 RSTCD, ORDER_INDEX。
|
||||||
|
*/
|
||||||
|
List<Map<String, Object>> selectAlongSortOrder(@Param("rstcdList") List<String> rstcdList);
|
||||||
|
}
|
||||||
@ -13,6 +13,7 @@ import com.yfd.platform.qgc_export.mapper.SdHydropwdaySMapper;
|
|||||||
import com.yfd.platform.qgc_export.mapper.SdQecRMapper;
|
import com.yfd.platform.qgc_export.mapper.SdQecRMapper;
|
||||||
import com.yfd.platform.qgc_export.mapper.SdQecdaySMapper;
|
import com.yfd.platform.qgc_export.mapper.SdQecdaySMapper;
|
||||||
import com.yfd.platform.qgc_export.mapper.StationMappingMapper;
|
import com.yfd.platform.qgc_export.mapper.StationMappingMapper;
|
||||||
|
import com.yfd.platform.qgc_export.mapper.MsAlongdetBMapper;
|
||||||
import com.yfd.platform.qgc_export.processor.*;
|
import com.yfd.platform.qgc_export.processor.*;
|
||||||
import com.yfd.platform.qgc_export.service.IQgcExportService;
|
import com.yfd.platform.qgc_export.service.IQgcExportService;
|
||||||
import com.yfd.platform.qgc_eng.eq.entity.vo.EngEqRuleVo;
|
import com.yfd.platform.qgc_eng.eq.entity.vo.EngEqRuleVo;
|
||||||
@ -142,6 +143,9 @@ public class QgcExportServiceImpl implements IQgcExportService {
|
|||||||
@Resource
|
@Resource
|
||||||
private EngEqDataService engEqDataService;
|
private EngEqDataService engEqDataService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private MsAlongdetBMapper msAlongdetBMapper;
|
||||||
|
|
||||||
private static final SimpleDateFormat SDF_TIME = new SimpleDateFormat("dd日 HH时");
|
private static final SimpleDateFormat SDF_TIME = new SimpleDateFormat("dd日 HH时");
|
||||||
private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
@ -174,10 +178,8 @@ public class QgcExportServiceImpl implements IQgcExportService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 电站顺序
|
// 4. 电站顺序:优先按沿程配置 MS_ALONG_B.ORDER_INDEX 排序,其余保持前端传入顺序
|
||||||
List<String> stationOrder = new ArrayList<>(stationRes.displayNames.keySet());
|
List<String> stationOrder = buildAlongSortedOrder(stationCodes, stationRes);
|
||||||
|
|
||||||
// 5. 每月一个 ExcelData
|
|
||||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||||
List<ExportZipUtil.ExcelData> excelList = new ArrayList<>();
|
List<ExportZipUtil.ExcelData> excelList = new ArrayList<>();
|
||||||
for (String month : months) {
|
for (String month : months) {
|
||||||
@ -188,6 +190,7 @@ public class QgcExportServiceImpl implements IQgcExportService {
|
|||||||
// 判断是否包含水质指标,后续用于追加 WQ 合规 Sheet
|
// 判断是否包含水质指标,后续用于追加 WQ 合规 Sheet
|
||||||
boolean hasWqIndicator = false;
|
boolean hasWqIndicator = false;
|
||||||
for (ExportIndicatorProcessor processor : processors) {
|
for (ExportIndicatorProcessor processor : processors) {
|
||||||
|
String sttp = processor.getSttpType();
|
||||||
List<List<Object>> rows;
|
List<List<Object>> rows;
|
||||||
// QEC 自定义三栏达标率格式
|
// QEC 自定义三栏达标率格式
|
||||||
if (processor instanceof QecProcessor) {
|
if (processor instanceof QecProcessor) {
|
||||||
@ -197,7 +200,6 @@ public class QgcExportServiceImpl implements IQgcExportService {
|
|||||||
}
|
}
|
||||||
if (rows != null) {
|
if (rows != null) {
|
||||||
List<String> headers;
|
List<String> headers;
|
||||||
String sttp = processor.getSttpType();
|
|
||||||
if (processor instanceof QecProcessor) {
|
if (processor instanceof QecProcessor) {
|
||||||
// 分部标题作为列标题(合并单元格)
|
// 分部标题作为列标题(合并单元格)
|
||||||
String[] sectionTitles = {"生态流量达标率(环保部)", "生态流量达标率(水利部)", "生态流量达标率(多年平均)"};
|
String[] sectionTitles = {"生态流量达标率(环保部)", "生态流量达标率(水利部)", "生态流量达标率(多年平均)"};
|
||||||
@ -824,6 +826,47 @@ public class QgcExportServiceImpl implements IQgcExportService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按沿程配置 MS_ALONG_B.ORDER_INDEX 排序电站列表。
|
||||||
|
* 有沿程配置的电站排前面,无配置的保持原有顺序排后面。
|
||||||
|
*/
|
||||||
|
private List<String> buildAlongSortedOrder(List<String> rstcds, StationResolution stationRes) {
|
||||||
|
if (rstcds.isEmpty()) return Collections.emptyList();
|
||||||
|
|
||||||
|
// 查询沿程配置:MS_ALONGDET_B JOIN MS_ALONG_B,按 ORDER_INDEX, SORT 排序
|
||||||
|
List<Map<String, Object>> alongList = msAlongdetBMapper.selectAlongSortOrder(rstcds);
|
||||||
|
if (alongList.isEmpty()) {
|
||||||
|
return new ArrayList<>(stationRes.displayNames.keySet());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按 ORDER_INDEX 分组去重,保留每站的最小 ORDER_INDEX
|
||||||
|
Map<String, Integer> rstcdOrderMap = new LinkedHashMap<>();
|
||||||
|
for (Map<String, Object> row : alongList) {
|
||||||
|
String rstcd = (String) row.get("RSTCD");
|
||||||
|
Object orderIdx = row.get("ORDER_INDEX");
|
||||||
|
if (rstcd != null && orderIdx != null && !rstcdOrderMap.containsKey(rstcd)) {
|
||||||
|
rstcdOrderMap.put(rstcd, ((Number) orderIdx).intValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 有沿程配置的电站按 ORDER_INDEX 升序,无配置的排后面
|
||||||
|
List<String> alongSorted = new ArrayList<>();
|
||||||
|
List<String> remaining = new ArrayList<>();
|
||||||
|
for (String rstcd : stationRes.displayNames.keySet()) {
|
||||||
|
if (rstcdOrderMap.containsKey(rstcd)) {
|
||||||
|
alongSorted.add(rstcd);
|
||||||
|
} else {
|
||||||
|
remaining.add(rstcd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alongSorted.sort(Comparator.comparingInt(rstcdOrderMap::get));
|
||||||
|
|
||||||
|
List<String> result = new ArrayList<>(alongSorted);
|
||||||
|
result.addAll(remaining);
|
||||||
|
log.info("沿程排序完成,有沿程={}, 无沿程={}", alongSorted.size(), remaining.size());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// ======================== 月份范围 ========================
|
// ======================== 月份范围 ========================
|
||||||
|
|
||||||
private MonthRange buildMonthRange(String month) {
|
private MonthRange buildMonthRange(String month) {
|
||||||
|
|||||||
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.yfd.platform.qgc_export.mapper.MsAlongdetBMapper">
|
||||||
|
|
||||||
|
<!-- 查询指定 STTP 的出库沿程配置,关联 V_MS_STBPRP_T 获取测站名称 -->
|
||||||
|
<select id="selectAlongStations" resultType="java.util.HashMap">
|
||||||
|
SELECT
|
||||||
|
A.RSTCD,
|
||||||
|
A.STCD,
|
||||||
|
A.SORT,
|
||||||
|
A.STTP,
|
||||||
|
S.STNM,
|
||||||
|
S.BASE_NAME
|
||||||
|
FROM MS_ALONGDET_B A
|
||||||
|
LEFT JOIN V_MS_STBPRP_T S ON S.STCD = A.STCD AND S.STTP = A.STTP
|
||||||
|
WHERE NVL(A.IS_DELETED, 0) = 0
|
||||||
|
AND A.IO_DIRECTION = '1'
|
||||||
|
AND A.STTP = #{sttp}
|
||||||
|
AND A.RSTCD IN
|
||||||
|
<foreach collection="rstcdList" item="rstcd" open="(" separator="," close=")">
|
||||||
|
#{rstcd}
|
||||||
|
</foreach>
|
||||||
|
ORDER BY A.SORT
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 查询所有沿程配置的电站排序(MS_ALONG_B + MS_ALONGDET_B),
|
||||||
|
按 MS_ALONG_B.ORDER_INDEX, MS_ALONGDET_B.SORT 排序 -->
|
||||||
|
<select id="selectAlongSortOrder" resultType="java.util.HashMap">
|
||||||
|
SELECT D.STCD, B.ORDER_INDEX
|
||||||
|
FROM MS_ALONGDET_B D
|
||||||
|
INNER JOIN MS_ALONG_B B ON B.ID = D.ALONG_ID AND NVL(B.IS_DELETED, 0) = 0
|
||||||
|
WHERE NVL(D.IS_DELETED, 0) = 0
|
||||||
|
-- AND D.IO_DIRECTION = '1'
|
||||||
|
AND D.STCD IN
|
||||||
|
<foreach collection="rstcdList" item="rstcd" open="(" separator="," close=")">
|
||||||
|
#{rstcd}
|
||||||
|
</foreach>
|
||||||
|
ORDER BY B.ORDER_INDEX, D.SORT
|
||||||
|
</select>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Loading…
Reference in New Issue
Block a user