瀏覽代碼

refining the data syn

MergeProblem1
[email protected] 2 週之前
父節點
當前提交
30eb8517d1
共有 2 個檔案被更改,包括 124 行新增3 行删除
  1. +50
    -2
      src/app/api/settings/m18ImportTesting/actions.ts
  2. +74
    -1
      src/components/M18ImportTesting/M18ImportTesting.tsx

+ 50
- 2
src/app/api/settings/m18ImportTesting/actions.ts 查看文件

@@ -53,19 +53,67 @@ export const testM18ImportDo = async (data: M18ImportDoForm) => {
};

export const testM18ImportPq = async (data: M18ImportPqForm) => {
const token = localStorage.getItem("accessToken");
return serverFetchWithNoContent(`${BASE_API_URL}/m18/pq`, {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}`, },
});
};

export const testM18ImportMasterData = async (
data: M18ImportMasterDataForm,
) => {
const token = localStorage.getItem("accessToken");
return serverFetchWithNoContent(`${BASE_API_URL}/m18/master-data`, {
method: "POST",
body: JSON.stringify(data),
headers: { "Content-Type": "application/json" },
headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}`, },
});
};

export const triggerScheduler = async (type: 'po' | 'do1' | 'do2' | 'master-data' | 'refresh-cron') => {
try {
// IMPORTANT: 'refresh-cron' is a direct endpoint /api/scheduler/refresh-cron
// Others are /api/scheduler/trigger/{type}
const path = type === 'refresh-cron'
? 'refresh-cron'
: `trigger/${type}`;

const url = `${BASE_API_URL}/scheduler/${path}`;
console.log("Fetching URL:", url);

const response = await serverFetchWithNoContent(url, {
method: "GET",
cache: "no-store",
});

if (!response.ok) throw new Error(`Failed: ${response.status}`);
return await response.text();
} catch (error) {
console.error("Scheduler Action Error:", error);
return null;
}
};

export const refreshCronSchedules = async () => {
// Simply reuse the triggerScheduler logic to avoid duplication
// or call serverFetch directly as shown below:
try {
const response = await serverFetchWithNoContent(`${BASE_API_URL}/scheduler/refresh-cron`, {
method: "GET",
cache: "no-store",
});

if (!response.ok) throw new Error(`Failed to refresh: ${response.status}`);
return await response.text();
} catch (error) {
console.error("Refresh Cron Error:", error);
return "Refresh failed. Check server logs.";
}
};

+ 74
- 1
src/components/M18ImportTesting/M18ImportTesting.tsx 查看文件

@@ -8,7 +8,7 @@ import {
testM18ImportMasterData,
testM18ImportDo,
} from "@/app/api/settings/m18ImportTesting/actions";
import { Card, CardContent, Grid, Stack, Typography } from "@mui/material";
import { Card, CardContent, Grid, Stack, Typography, Button } from "@mui/material";
import React, {
BaseSyntheticEvent,
FormEvent,
@@ -22,6 +22,8 @@ import M18ImportPq from "./M18ImportPq";
import { dateTimeStringToDayjs } from "@/app/utils/formatUtil";
import M18ImportMasterData from "./M18ImportMasterData";
import M18ImportDo from "./M18ImportDo";
import { PlayArrow, Refresh as RefreshIcon } from "@mui/icons-material";
import { triggerScheduler, refreshCronSchedules } from "@/app/api/settings/m18ImportTesting/actions";

interface Props {}

@@ -166,9 +168,80 @@ const M18ImportTesting: React.FC<Props> = ({}) => {
// [],
// );

const handleManualTrigger = async (type: any) => {
setIsLoading(true);
setLoadingType(`Manual ${type}`);
try {
const result = await triggerScheduler(type);
if (result) alert(result);
} catch (error) {
console.error(error);
alert("Trigger failed. Check server logs.");
} finally {
setIsLoading(false);
}
};

const handleRefreshSchedules = async () => {
// Re-use the manual trigger logic which we know works
await handleManualTrigger('refresh-cron');
};

return (
<Card>
<CardContent sx={{ display: "flex", flexDirection: "column", gap: 1 }}>
<Typography variant="h6">{t("Manual Scheduler Triggers")}</Typography>
<Stack direction="row" spacing={1} flexWrap="wrap" useFlexGap>
<Button
variant="outlined"
startIcon={<PlayArrow />}
onClick={() => handleManualTrigger('po')}
disabled={isLoading}
>
Trigger PO
</Button>
<Button
variant="outlined"
startIcon={<PlayArrow />}
onClick={() => handleManualTrigger('do1')}
disabled={isLoading}
>
Trigger DO1
</Button>
<Button
variant="outlined"
startIcon={<PlayArrow />}
onClick={() => handleManualTrigger('do2')}
disabled={isLoading}
>
Trigger DO2
</Button>
<Button
variant="outlined"
startIcon={<PlayArrow />}
onClick={() => handleManualTrigger('master-data')}
disabled={isLoading}
>
Trigger Master
</Button>
<Button
variant="contained"
color="secondary"
startIcon={<RefreshIcon />}
onClick={handleRefreshSchedules} // This now uses the logic that works
disabled={isLoading}
>
Reload Cron Settings
</Button>
</Stack>

<hr style={{ opacity: 0.2 }} />

<Typography variant="overline">
{t("Status: ")}
{isLoading ? t(`Processing ${loadingType}...`) : t("Ready")}
</Typography>

<Typography variant="overline">
{t("Status: ")}
{isLoading ? t(`Importing ${loadingType}...`) : t("Ready to import")}


Loading…
取消
儲存