refactor(frontend): align TJWater Next integrations

This commit is contained in:
2026-08-26 12:26:29 +08:00
parent 6623f4f7fb
commit fee4fc6ce1
51 changed files with 3074 additions and 22280 deletions
@@ -7,30 +7,67 @@ import type {
} from "./types";
export interface OptimizeSchemeInput {
scheme_name: string;
run_name: string;
sensor_type: "pressure";
method: "sensitivity" | "kmeans";
sensor_count: number;
min_diameter: number;
}
type SensorPlacementRunResponse = {
run_id: string;
name: string;
sensor_count: number;
min_diameter: number;
created_by: string;
created_at: string;
sensor_locations: string[];
sensor_points: SensorPoint[];
can_edit: boolean;
};
const toSensorPlacementScheme = (
run: SensorPlacementRunResponse,
): SensorPlacementScheme => ({
id: run.run_id,
scheme_name: run.name,
sensor_number: run.sensor_count,
min_diameter: run.min_diameter,
username: run.created_by,
create_time: run.created_at,
sensor_location: run.sensor_locations,
sensor_points: run.sensor_points,
can_edit: run.can_edit,
});
export const optimizeSensorPlacement = async (
input: OptimizeSchemeInput,
): Promise<SensorPlacementScheme> => {
const response = await api.post<SensorPlacementScheme>(
`${config.BACKEND_URL}/api/v1/sensor-placement-optimization-runs`,
const response = await api.post<SensorPlacementRunResponse>(
`${config.BACKEND_URL}/api/v1/sensor-placement-runs`,
input,
);
return response.data;
return toSensorPlacementScheme(response.data);
};
export const listSensorPlacementSchemes = async (): Promise<
SensorPlacementScheme[]
> => {
const response = await api.get<{
items: SensorPlacementRunResponse[];
}>(`${config.BACKEND_URL}/api/v1/sensor-placement-runs`, {
params: { limit: 1000, offset: 0 },
});
return response.data.items.map(toSensorPlacementScheme);
};
export const getSensorPlacementScheme = async (
schemeId: number,
schemeId: string,
): Promise<SensorPlacementScheme> => {
const response = await api.get<SensorPlacementScheme>(
`${config.BACKEND_URL}/api/v1/sensor-placement-schemes/${schemeId}`,
const response = await api.get<SensorPlacementRunResponse>(
`${config.BACKEND_URL}/api/v1/sensor-placement-runs/${encodeURIComponent(schemeId)}`,
);
return response.data;
return toSensorPlacementScheme(response.data);
};
export const getSensorPlacementCandidate = async (
@@ -43,29 +80,29 @@ export const getSensorPlacementCandidate = async (
};
export const overwriteSensorPlacementScheme = async (
schemeId: number,
schemeId: string,
expectedSensorLocation: string[],
sensorLocation: string[],
): Promise<SensorPlacementScheme> => {
const response = await api.put<SensorPlacementScheme>(
`${config.BACKEND_URL}/api/v1/sensor-placement-schemes/${schemeId}`,
const response = await api.put<SensorPlacementRunResponse>(
`${config.BACKEND_URL}/api/v1/sensor-placement-runs/${encodeURIComponent(schemeId)}`,
{
expected_sensor_location: expectedSensorLocation,
sensor_location: sensorLocation,
expected_sensor_locations: expectedSensorLocation,
sensor_locations: sensorLocation,
},
);
return response.data;
return toSensorPlacementScheme(response.data);
};
export const exportSensorPlacementExcel = async (
schemeId: number,
schemeId: string,
sensorLocation: string[],
adjustmentStatus: Record<string, AdjustmentStatus>,
) => {
const response = await api.post<Blob>(
`${config.BACKEND_URL}/api/v1/sensor-placement-schemes/${schemeId}/exports/excel`,
`${config.BACKEND_URL}/api/v1/sensor-placement-runs/${encodeURIComponent(schemeId)}/exports/excel`,
{
sensor_location: sensorLocation,
sensor_locations: sensorLocation,
adjustment_status: adjustmentStatus,
},
{