refactor(frontend): align TJWater Next integrations
This commit is contained in:
@@ -25,8 +25,8 @@ import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
|
||||
import "dayjs/locale/zh-cn";
|
||||
import dayjs, { Dayjs } from "dayjs";
|
||||
import { useNotification } from "@refinedev/core";
|
||||
import { api } from "@/lib/api";
|
||||
import { NETWORK_NAME, config } from "@config/config";
|
||||
import { getAnalysisScheme, listAnalysisSchemes } from "@/lib/analysisRuns";
|
||||
import { NETWORK_NAME } from "@config/config";
|
||||
import { useControllableObjectState } from "@components/olmap/core/useControllableState";
|
||||
import { useMap } from "@components/olmap/core/MapComponent";
|
||||
import { queryFeaturesByIds } from "@/utils/mapQueryService";
|
||||
@@ -56,7 +56,7 @@ interface Props {
|
||||
export interface BurstLocationSchemeQueryState {
|
||||
queryAll: boolean;
|
||||
queryDate: Dayjs | null;
|
||||
expandedId: number | null;
|
||||
expandedId: string | null;
|
||||
simulationBurstIdsByName: Record<string, string[]>;
|
||||
hasQueried: boolean;
|
||||
}
|
||||
@@ -147,10 +147,7 @@ const SchemeQuery: React.FC<Props> = ({
|
||||
if (!uniquePipeIds.length || !map) return;
|
||||
|
||||
try {
|
||||
let features = await queryFeaturesByIds(uniquePipeIds, "geo_pipes_mat");
|
||||
if (features.length === 0) {
|
||||
features = await queryFeaturesByIds(uniquePipeIds, "geo_pipes");
|
||||
}
|
||||
const features = await queryFeaturesByIds(uniquePipeIds, "pipes");
|
||||
if (features.length === 0) return;
|
||||
|
||||
setHighlightFeatures(features);
|
||||
@@ -227,23 +224,17 @@ const SchemeQuery: React.FC<Props> = ({
|
||||
const handleQuery = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const params: Record<string, string> = {
|
||||
scheme_type: "burst_location",
|
||||
};
|
||||
if (!queryAll && queryDate) {
|
||||
params.query_date = queryDate.startOf("day").toISOString();
|
||||
}
|
||||
|
||||
const [response, simulationResponse] = await Promise.all([
|
||||
api.get(`${config.BACKEND_URL}/api/v1/schemes`, { params }),
|
||||
api.get(`${config.BACKEND_URL}/api/v1/schemes`, {
|
||||
params: { scheme_type: "burst_analysis" },
|
||||
const [nextSchemes, simulationSchemes] = await Promise.all([
|
||||
listAnalysisSchemes({
|
||||
runType: "burst_location",
|
||||
queryDate: !queryAll && queryDate
|
||||
? queryDate.format("YYYY-MM-DD")
|
||||
: undefined,
|
||||
}),
|
||||
listAnalysisSchemes({ runType: "burst_analysis" }),
|
||||
]);
|
||||
const nextSchemes = response.data as BurstSchemeRecord[];
|
||||
const nextSimulationBurstIdsByName = Object.fromEntries(
|
||||
(simulationResponse.data as BurstSimulationSchemeItem[])
|
||||
.filter((scheme) => scheme.scheme_type === "burst_analysis")
|
||||
(simulationSchemes as BurstSimulationSchemeItem[])
|
||||
.map((scheme) => [
|
||||
scheme.scheme_name,
|
||||
normalizeBurstIds(scheme.scheme_detail?.burst_ID),
|
||||
@@ -253,7 +244,7 @@ const SchemeQuery: React.FC<Props> = ({
|
||||
setSchemes(
|
||||
nextSchemes.map((scheme) =>
|
||||
enrichSchemeWithSimulationBurstIds(
|
||||
scheme,
|
||||
scheme as BurstSchemeRecord,
|
||||
nextSimulationBurstIdsByName,
|
||||
),
|
||||
),
|
||||
@@ -276,13 +267,9 @@ const SchemeQuery: React.FC<Props> = ({
|
||||
}
|
||||
};
|
||||
|
||||
const handleViewSchemeResult = async (schemeName: string) => {
|
||||
const handleViewSchemeResult = async (runId: string) => {
|
||||
try {
|
||||
const response = await api.get(
|
||||
`${config.BACKEND_URL}/api/v1/schemes/${encodeURIComponent(schemeName)}`,
|
||||
{ params: { scheme_type: "burst_location" } },
|
||||
);
|
||||
const schemeRecord = response.data as BurstSchemeRecord & {
|
||||
const schemeRecord = (await getAnalysisScheme(runId)) as BurstSchemeRecord & {
|
||||
result_payload?: BurstLocationResult;
|
||||
};
|
||||
const normalizedResult =
|
||||
@@ -302,7 +289,7 @@ const SchemeQuery: React.FC<Props> = ({
|
||||
open?.({
|
||||
type: "success",
|
||||
message: "方案加载成功",
|
||||
description: `已加载方案: ${schemeName}`,
|
||||
description: `已加载方案: ${schemeRecord.scheme_name}`,
|
||||
});
|
||||
} catch (error: any) {
|
||||
open?.({
|
||||
@@ -516,7 +503,7 @@ const SchemeQuery: React.FC<Props> = ({
|
||||
size="small"
|
||||
className="bg-blue-600 hover:bg-blue-700"
|
||||
sx={{ textTransform: "none", fontWeight: 500 }}
|
||||
onClick={() => handleViewSchemeResult(scheme.scheme_name)}
|
||||
onClick={() => handleViewSchemeResult(scheme.scheme_id)}
|
||||
>
|
||||
查看定位结果
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user