Refactor brand service and related components
- Removed ListQuestionVersions method and associated types from BrandService and Queries. - Updated PromptRuleGenerationService to change task naming and handling. - Enhanced ScheduleTaskService to support filtering by created date range and keyword. - Introduced InstantTaskService for managing instant tasks with appropriate filtering and response structures. - Added InstantTaskHandler for handling API requests related to instant tasks. - Created InstantTaskTab component for the admin web interface to display and manage instant tasks. - Updated database migrations to rename source types for articles and generation tasks. - Adjusted models and repository queries to reflect the removal of question version handling.
This commit is contained in:
@@ -209,7 +209,7 @@ async function refreshArticleData(): Promise<void> {
|
||||
<p class="eyebrow">{{ t("article.preview") }}</p>
|
||||
<h2>{{ displayTitle }}</h2>
|
||||
<p>
|
||||
{{ getSourceTypeLabel(detail.source_type) }} ·
|
||||
{{ getSourceTypeLabel(detail.source_type, detail.generation_mode) }} ·
|
||||
{{ formatDateTime(detail.created_at) }}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
LoadingOutlined,
|
||||
AppstoreOutlined,
|
||||
ClockCircleOutlined,
|
||||
EditOutlined,
|
||||
DeleteOutlined,
|
||||
} from "@ant-design/icons-vue";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||
import { message, type TableColumnsType } from "ant-design-vue";
|
||||
@@ -16,6 +20,7 @@ import {
|
||||
formatDateTime,
|
||||
getGenerateStatusMeta,
|
||||
getPublishStatusMeta,
|
||||
getSourceTypeLabel,
|
||||
} from "@/lib/display";
|
||||
import { formatError } from "@/lib/errors";
|
||||
import { formatPublishPlatformList } from "@/lib/publish-platforms";
|
||||
@@ -78,7 +83,7 @@ const articleParams = computed<ArticleListParams>(() => {
|
||||
const params: ArticleListParams = {
|
||||
page: page.value,
|
||||
page_size: pageSize.value,
|
||||
source_type: "prompt_rule",
|
||||
source_type: "custom_generation",
|
||||
};
|
||||
if (appliedFilters.prompt_rule_id) params.prompt_rule_id = appliedFilters.prompt_rule_id;
|
||||
if (appliedFilters.publish_status) params.publish_status = appliedFilters.publish_status;
|
||||
@@ -90,7 +95,7 @@ const articleParams = computed<ArticleListParams>(() => {
|
||||
});
|
||||
|
||||
const listQuery = useQuery({
|
||||
queryKey: computed(() => ["articles", "list", "prompt_rule", articleParams.value]),
|
||||
queryKey: computed(() => ["articles", "list", "custom_generation", articleParams.value]),
|
||||
queryFn: () => articlesApi.list(articleParams.value),
|
||||
});
|
||||
|
||||
@@ -106,14 +111,13 @@ const deleteMutation = useMutation({
|
||||
});
|
||||
|
||||
const columns = computed<TableColumnsType<ArticleListItem>>(() => [
|
||||
{ title: t("common.title"), dataIndex: "title", key: "title" },
|
||||
{ title: t("custom.article.titleColumn"), dataIndex: "title", key: "title", width: 340 },
|
||||
{ title: t("custom.filters.promptRule"), dataIndex: "prompt_rule_name", key: "prompt_rule_name", width: 160 },
|
||||
{ title: t("custom.schedule.platform"), dataIndex: "platforms", key: "platforms", width: 180 },
|
||||
{ title: t("common.generateStatus"), dataIndex: "generate_status", key: "generate_status", width: 128 },
|
||||
{ title: t("common.publishStatus"), dataIndex: "publish_status", key: "publish_status", width: 128 },
|
||||
{ title: t("common.wordCount"), dataIndex: "word_count", key: "word_count", width: 100 },
|
||||
{ title: t("common.createdAt"), dataIndex: "created_at", key: "created_at", width: 168 },
|
||||
{ title: t("common.actions"), key: "actions", width: 140, fixed: "right" },
|
||||
{ title: t("common.actions"), key: "actions", width: 120, fixed: "right", align: "right" },
|
||||
]);
|
||||
|
||||
function applyFilters(): void {
|
||||
@@ -148,6 +152,13 @@ function canEditArticle(status: string): boolean {
|
||||
return status === "completed" || status === "draft";
|
||||
}
|
||||
|
||||
function getDisplayTitle(article: ArticleListItem): string {
|
||||
if ((article.generate_status === "generating" || article.generate_status === "running") && !article.title) {
|
||||
return t("custom.article.titleGenerating");
|
||||
}
|
||||
return article.title || t("article.untitled");
|
||||
}
|
||||
|
||||
function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
page.value = nextPage;
|
||||
pageSize.value = nextPageSize;
|
||||
@@ -273,9 +284,21 @@ onBeforeUnmount(() => {
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'title'">
|
||||
<a class="custom-article-tab__title-link" @click="openDetail(record)">
|
||||
{{ record.title || t("article.untitled") }}
|
||||
</a>
|
||||
<div class="custom-article-tab__title-cell">
|
||||
<a class="custom-article-tab__title-link" @click="openDetail(record)">
|
||||
{{ getDisplayTitle(record) }}
|
||||
</a>
|
||||
<div class="custom-article-tab__title-meta">
|
||||
<span class="custom-article-tab__title-badge">
|
||||
<AppstoreOutlined />
|
||||
<span>{{ getSourceTypeLabel(record.source_type, record.generation_mode) }}</span>
|
||||
</span>
|
||||
<span class="custom-article-tab__title-time">
|
||||
<ClockCircleOutlined />
|
||||
<span>{{ formatDateTime(record.created_at) }}</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'prompt_rule_name'">
|
||||
{{ record.prompt_rule_name || "--" }}
|
||||
@@ -302,28 +325,37 @@ onBeforeUnmount(() => {
|
||||
<template v-else-if="column.key === 'word_count'">
|
||||
{{ record.word_count || "--" }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'created_at'">
|
||||
{{ formatDateTime(record.created_at) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space :size="4">
|
||||
<a-button
|
||||
type="link"
|
||||
size="small"
|
||||
:disabled="!canEditArticle(record.generate_status)"
|
||||
@click="openEditor(record)"
|
||||
>
|
||||
{{ t("common.edit") }}
|
||||
</a-button>
|
||||
<div class="table-actions-row">
|
||||
<a-tooltip :title="t('common.edit')">
|
||||
<span>
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-edit"
|
||||
:disabled="!canEditArticle(record.generate_status)"
|
||||
@click="openEditor(record)"
|
||||
>
|
||||
<EditOutlined />
|
||||
</a-button>
|
||||
</span>
|
||||
</a-tooltip>
|
||||
<a-popconfirm
|
||||
:title="t('templates.list.deleteConfirm')"
|
||||
@confirm="deleteMutation.mutate(record.id)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
{{ t("common.delete") }}
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-delete"
|
||||
:title="t('common.delete')"
|
||||
>
|
||||
<DeleteOutlined />
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
@@ -370,12 +402,46 @@ onBeforeUnmount(() => {
|
||||
}
|
||||
|
||||
.custom-article-tab__title-link {
|
||||
color: #1677ff;
|
||||
display: inline-block;
|
||||
color: #434343;
|
||||
cursor: pointer;
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.custom-article-tab__title-link:hover {
|
||||
text-decoration: underline;
|
||||
color: #1677ff;
|
||||
}
|
||||
|
||||
.custom-article-tab__title-cell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.custom-article-tab__title-meta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.custom-article-tab__title-badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: #b45f06;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.custom-article-tab__title-time {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
color: #a3a3a3;
|
||||
}
|
||||
|
||||
.custom-article-tab__status-tag {
|
||||
|
||||
@@ -126,6 +126,7 @@ const instantGenerateMutation = useMutation({
|
||||
target_platform: serializeTargetPlatforms(form.platformIds),
|
||||
extra_params: {
|
||||
task_name: form.name.trim(),
|
||||
generation_mode: "instant",
|
||||
enable_web_search: form.enableWebSearch,
|
||||
generate_count: form.generateCount,
|
||||
target_platforms: form.platformIds,
|
||||
@@ -135,7 +136,10 @@ const instantGenerateMutation = useMutation({
|
||||
onSuccess: async () => {
|
||||
message.success(t("custom.messages.generateSubmitted"));
|
||||
emit("update:open", false);
|
||||
await queryClient.invalidateQueries({ queryKey: ["articles"] });
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ["articles"] }),
|
||||
queryClient.invalidateQueries({ queryKey: ["instantTasks"] }),
|
||||
]);
|
||||
},
|
||||
onError: (error) => message.error(formatError(error)),
|
||||
});
|
||||
|
||||
@@ -0,0 +1,328 @@
|
||||
<script setup lang="ts">
|
||||
import { LoadingOutlined, EyeOutlined } from "@ant-design/icons-vue";
|
||||
import { useQuery } from "@tanstack/vue-query";
|
||||
import { type TableColumnsType } from "ant-design-vue";
|
||||
import type { InstantTaskItem, InstantTaskListParams } from "@geo/shared-types";
|
||||
import type { Dayjs } from "dayjs";
|
||||
import { computed, onBeforeUnmount, reactive, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
import ArticleDetailDrawer from "@/components/ArticleDetailDrawer.vue";
|
||||
import { instantTasksApi, promptRulesApi } from "@/lib/api";
|
||||
import { formatDateTime, getGenerateStatusMeta } from "@/lib/display";
|
||||
import { formatPublishPlatformList } from "@/lib/publish-platforms";
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const page = ref(1);
|
||||
const pageSize = ref(20);
|
||||
const createdRange = ref<[Dayjs, Dayjs] | null>(null);
|
||||
const detailOpen = ref(false);
|
||||
const selectedArticleId = ref<number | null>(null);
|
||||
|
||||
const draftFilters = reactive<{
|
||||
prompt_rule_id?: number;
|
||||
status?: string;
|
||||
keyword?: string;
|
||||
}>({
|
||||
keyword: "",
|
||||
});
|
||||
|
||||
const appliedFilters = reactive<{
|
||||
prompt_rule_id?: number;
|
||||
status?: string;
|
||||
keyword?: string;
|
||||
created_from?: string;
|
||||
created_to?: string;
|
||||
}>({
|
||||
keyword: "",
|
||||
});
|
||||
|
||||
const rulesQuery = useQuery({
|
||||
queryKey: ["promptRules", "simple"],
|
||||
queryFn: () => promptRulesApi.listSimple(),
|
||||
});
|
||||
|
||||
const promptOptions = computed(() =>
|
||||
(rulesQuery.data.value ?? []).map((rule) => ({
|
||||
label: rule.name,
|
||||
value: rule.id,
|
||||
})),
|
||||
);
|
||||
|
||||
const statusOptions = computed(() => [
|
||||
{ label: getGenerateStatusMeta("queued").label, value: "queued" },
|
||||
{ label: getGenerateStatusMeta("running").label, value: "running" },
|
||||
{ label: getGenerateStatusMeta("completed").label, value: "completed" },
|
||||
{ label: getGenerateStatusMeta("failed").label, value: "failed" },
|
||||
]);
|
||||
|
||||
const listParams = computed<InstantTaskListParams>(() => {
|
||||
const params: InstantTaskListParams = {
|
||||
page: page.value,
|
||||
page_size: pageSize.value,
|
||||
};
|
||||
if (appliedFilters.prompt_rule_id) params.prompt_rule_id = appliedFilters.prompt_rule_id;
|
||||
if (appliedFilters.status) params.status = appliedFilters.status;
|
||||
if (appliedFilters.keyword?.trim()) params.keyword = appliedFilters.keyword.trim();
|
||||
if (appliedFilters.created_from) params.created_from = appliedFilters.created_from;
|
||||
if (appliedFilters.created_to) params.created_to = appliedFilters.created_to;
|
||||
return params;
|
||||
});
|
||||
|
||||
const listQuery = useQuery({
|
||||
queryKey: computed(() => ["instantTasks", "list", listParams.value]),
|
||||
queryFn: () => instantTasksApi.list(listParams.value),
|
||||
});
|
||||
|
||||
const columns = computed<TableColumnsType<InstantTaskItem>>(() => [
|
||||
{ title: t("custom.instant.name"), dataIndex: "name", key: "name", width: 220 },
|
||||
{ title: t("custom.schedule.rule"), dataIndex: "prompt_rule_name", key: "prompt_rule_name", width: 180 },
|
||||
{ title: t("custom.instant.executionStatus"), dataIndex: "status", key: "status", width: 140 },
|
||||
{ title: t("custom.instant.executionTime"), dataIndex: "execution_time", key: "execution_time", width: 170 },
|
||||
{ title: t("custom.schedule.platform"), dataIndex: "platforms", key: "platforms", width: 220 },
|
||||
{ title: t("custom.task.generateCount"), dataIndex: "generate_count", key: "generate_count", width: 120 },
|
||||
{ title: t("custom.instant.createdTime"), dataIndex: "created_at", key: "created_at", width: 170 },
|
||||
{ title: t("common.actions"), key: "actions", width: 88, fixed: "right", align: "right" },
|
||||
]);
|
||||
|
||||
let pollingTimer: number | null = null;
|
||||
|
||||
function applyFilters(): void {
|
||||
page.value = 1;
|
||||
appliedFilters.prompt_rule_id = draftFilters.prompt_rule_id;
|
||||
appliedFilters.status = draftFilters.status;
|
||||
appliedFilters.keyword = draftFilters.keyword?.trim() || "";
|
||||
appliedFilters.created_from = createdRange.value?.[0]?.startOf("day").toISOString();
|
||||
appliedFilters.created_to = createdRange.value?.[1]?.endOf("day").toISOString();
|
||||
}
|
||||
|
||||
function resetFilters(): void {
|
||||
draftFilters.prompt_rule_id = undefined;
|
||||
draftFilters.status = undefined;
|
||||
draftFilters.keyword = "";
|
||||
createdRange.value = null;
|
||||
applyFilters();
|
||||
}
|
||||
|
||||
function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
page.value = nextPage;
|
||||
pageSize.value = nextPageSize;
|
||||
}
|
||||
|
||||
function openArticle(task: InstantTaskItem): void {
|
||||
if (!task.article_id) {
|
||||
return;
|
||||
}
|
||||
selectedArticleId.value = task.article_id;
|
||||
detailOpen.value = true;
|
||||
}
|
||||
|
||||
function startPolling(): void {
|
||||
if (pollingTimer !== null) return;
|
||||
pollingTimer = window.setInterval(() => {
|
||||
void listQuery.refetch();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
function stopPolling(): void {
|
||||
if (pollingTimer === null) return;
|
||||
window.clearInterval(pollingTimer);
|
||||
pollingTimer = null;
|
||||
}
|
||||
|
||||
watch(
|
||||
() => listQuery.data.value?.items ?? [],
|
||||
(items) => {
|
||||
const hasActive = items.some((item) => item.status === "queued" || item.status === "running");
|
||||
if (hasActive) {
|
||||
startPolling();
|
||||
} else {
|
||||
stopPolling();
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
stopPolling();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="task-tab">
|
||||
<div class="task-tab__filters">
|
||||
<div class="task-tab__filter">
|
||||
<label>{{ t("custom.filters.promptRule") }}:</label>
|
||||
<a-select
|
||||
v-model:value="draftFilters.prompt_rule_id"
|
||||
allow-clear
|
||||
size="large"
|
||||
:options="promptOptions"
|
||||
:placeholder="t('custom.task.promptPlaceholder')"
|
||||
:loading="rulesQuery.isPending.value"
|
||||
@change="applyFilters"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="task-tab__filter">
|
||||
<label>{{ t("custom.filters.status") }}:</label>
|
||||
<a-select
|
||||
v-model:value="draftFilters.status"
|
||||
allow-clear
|
||||
size="large"
|
||||
:options="statusOptions"
|
||||
:placeholder="t('common.selectPlease')"
|
||||
@change="applyFilters"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="task-tab__filter task-tab__filter--range">
|
||||
<label>{{ t("custom.filters.createdTime") }}:</label>
|
||||
<a-range-picker
|
||||
v-model:value="createdRange"
|
||||
allow-clear
|
||||
size="large"
|
||||
format="YYYY-MM-DD"
|
||||
@change="applyFilters"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="task-tab__filter task-tab__filter--keyword">
|
||||
<label>{{ t("custom.filters.name") }}:</label>
|
||||
<a-input-search
|
||||
v-model:value="draftFilters.keyword"
|
||||
size="large"
|
||||
:placeholder="t('custom.filters.namePlaceholder')"
|
||||
@search="applyFilters"
|
||||
@pressEnter="applyFilters"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="task-tab__filter task-tab__filter--action">
|
||||
<a-button size="large" @click="resetFilters">{{ t("common.reset") }}</a-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a-table
|
||||
:columns="columns"
|
||||
:data-source="listQuery.data.value?.items ?? []"
|
||||
:loading="listQuery.isPending.value"
|
||||
:pagination="{
|
||||
current: page,
|
||||
pageSize,
|
||||
total: listQuery.data.value?.total ?? 0,
|
||||
showSizeChanger: true,
|
||||
}"
|
||||
row-key="id"
|
||||
:scroll="{ x: 1280 }"
|
||||
@change="(p: any) => handleTableChange(p.current, p.pageSize)"
|
||||
>
|
||||
<template #emptyText>{{ t("custom.instant.empty") }}</template>
|
||||
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'prompt_rule_name'">
|
||||
{{ record.prompt_rule_name || "--" }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="getGenerateStatusMeta(record.status).color">
|
||||
<span class="task-tab__status">
|
||||
<LoadingOutlined v-if="record.status === 'queued' || record.status === 'running'" spin />
|
||||
<span>{{ getGenerateStatusMeta(record.status).label }}</span>
|
||||
</span>
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'execution_time'">
|
||||
{{ formatDateTime(record.execution_time) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'platforms'">
|
||||
{{ formatPublishPlatformList(record.platforms) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'generate_count'">
|
||||
{{ record.generate_count || 1 }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'created_at'">
|
||||
{{ formatDateTime(record.created_at) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<div class="table-actions-row">
|
||||
<a-tooltip :title="t('common.preview')">
|
||||
<span>
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-eye"
|
||||
:disabled="!record.article_id"
|
||||
@click="openArticle(record)"
|
||||
>
|
||||
<EyeOutlined />
|
||||
</a-button>
|
||||
</span>
|
||||
</a-tooltip>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
<ArticleDetailDrawer
|
||||
:open="detailOpen"
|
||||
:article-id="selectedArticleId"
|
||||
@close="detailOpen = false"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.task-tab__filters {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(180px, 240px) minmax(180px, 240px) minmax(240px, 320px) minmax(240px, 1fr) auto;
|
||||
gap: 16px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.task-tab__filter {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.task-tab__filter label {
|
||||
flex-shrink: 0;
|
||||
color: #434343;
|
||||
font-size: 14px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.task-tab__filter :deep(.ant-select),
|
||||
.task-tab__filter :deep(.ant-picker),
|
||||
.task-tab__filter :deep(.ant-input-search) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.task-tab__filter--action {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.task-tab__status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
@media (max-width: 1400px) {
|
||||
.task-tab__filters {
|
||||
grid-template-columns: repeat(2, minmax(260px, 1fr));
|
||||
}
|
||||
|
||||
.task-tab__filter--action {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.task-tab__filters {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -2,6 +2,8 @@
|
||||
import {
|
||||
DeleteOutlined,
|
||||
EditOutlined,
|
||||
PauseCircleOutlined,
|
||||
PlayCircleOutlined,
|
||||
PlusOutlined,
|
||||
} from "@ant-design/icons-vue";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||
@@ -59,7 +61,7 @@ const columns = computed<TableColumnsType<PromptRule>>(() => [
|
||||
{ title: t("custom.promptRule.articleCount"), dataIndex: "article_count", key: "article_count", width: 100 },
|
||||
{ title: t("custom.promptRule.status"), dataIndex: "status", key: "status", width: 100 },
|
||||
{ title: t("common.createdAt"), dataIndex: "created_at", key: "created_at", width: 168 },
|
||||
{ title: t("common.actions"), key: "actions", width: 140, fixed: "right" },
|
||||
{ title: t("common.actions"), key: "actions", width: 140, fixed: "right", align: "right" },
|
||||
]);
|
||||
|
||||
const groupMutations = {
|
||||
@@ -252,29 +254,53 @@ watch(selectedGroupId, () => {
|
||||
{{ formatDateTime(record.created_at) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space :size="4">
|
||||
<a-button type="link" size="small" @click="openRuleModal(record)">
|
||||
{{ t("common.edit") }}
|
||||
</a-button>
|
||||
<a-button
|
||||
type="link"
|
||||
size="small"
|
||||
@click="ruleMutations.toggleStatus.mutate({
|
||||
id: record.id,
|
||||
status: record.status === 'enabled' ? 'disabled' : 'enabled',
|
||||
})"
|
||||
<div class="table-actions-row">
|
||||
<a-tooltip :title="t('common.edit')">
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-edit"
|
||||
@click="openRuleModal(record)"
|
||||
>
|
||||
<EditOutlined />
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-tooltip
|
||||
:title="record.status === 'enabled' ? t('custom.promptRule.disabled') : t('custom.promptRule.enabled')"
|
||||
>
|
||||
{{ record.status === "enabled" ? t("custom.promptRule.disabled") : t("custom.promptRule.enabled") }}
|
||||
</a-button>
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
:class="[
|
||||
'action-btn',
|
||||
record.status === 'enabled' ? 'action-disable' : 'action-enable',
|
||||
]"
|
||||
@click="ruleMutations.toggleStatus.mutate({
|
||||
id: record.id,
|
||||
status: record.status === 'enabled' ? 'disabled' : 'enabled',
|
||||
})"
|
||||
>
|
||||
<PauseCircleOutlined v-if="record.status === 'enabled'" />
|
||||
<PlayCircleOutlined v-else />
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-popconfirm
|
||||
:title="t('custom.promptRule.deleteConfirm')"
|
||||
@confirm="ruleMutations.remove.mutate(record.id)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
{{ t("common.delete") }}
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-delete"
|
||||
:title="t('common.delete')"
|
||||
>
|
||||
<DeleteOutlined />
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import { PlusOutlined } from "@ant-design/icons-vue";
|
||||
import {
|
||||
DeleteOutlined,
|
||||
EditOutlined,
|
||||
PauseCircleOutlined,
|
||||
PlayCircleOutlined,
|
||||
} from "@ant-design/icons-vue";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||
import { message, type TableColumnsType } from "ant-design-vue";
|
||||
import type { ScheduleTask } from "@geo/shared-types";
|
||||
import { computed, ref } from "vue";
|
||||
import type { ScheduleTask, ScheduleTaskListParams } from "@geo/shared-types";
|
||||
import type { Dayjs } from "dayjs";
|
||||
import { computed, reactive, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
import ScheduleTaskModal from "@/components/ScheduleTaskModal.vue";
|
||||
import { schedulesApi } from "@/lib/api";
|
||||
import { formatDateTime } from "@/lib/display";
|
||||
import { promptRulesApi, schedulesApi } from "@/lib/api";
|
||||
import { formatCronExecutionTime, formatDateTime } from "@/lib/display";
|
||||
import { formatError } from "@/lib/errors";
|
||||
import { formatPublishPlatformSummary } from "@/lib/publish-platforms";
|
||||
|
||||
@@ -19,11 +25,55 @@ const modalOpen = ref(false);
|
||||
const editingTask = ref<ScheduleTask | null>(null);
|
||||
const page = ref(1);
|
||||
const pageSize = ref(20);
|
||||
const createdRange = ref<[Dayjs, Dayjs] | null>(null);
|
||||
|
||||
const listParams = computed(() => ({
|
||||
page: page.value,
|
||||
page_size: pageSize.value,
|
||||
}));
|
||||
const draftFilters = reactive<{
|
||||
prompt_rule_id?: number;
|
||||
status?: string;
|
||||
keyword?: string;
|
||||
}>({
|
||||
keyword: "",
|
||||
});
|
||||
|
||||
const appliedFilters = reactive<{
|
||||
prompt_rule_id?: number;
|
||||
status?: string;
|
||||
keyword?: string;
|
||||
created_from?: string;
|
||||
created_to?: string;
|
||||
}>({
|
||||
keyword: "",
|
||||
});
|
||||
|
||||
const rulesQuery = useQuery({
|
||||
queryKey: ["promptRules", "simple"],
|
||||
queryFn: () => promptRulesApi.listSimple(),
|
||||
});
|
||||
|
||||
const promptOptions = computed(() =>
|
||||
(rulesQuery.data.value ?? []).map((rule) => ({
|
||||
label: rule.name,
|
||||
value: rule.id,
|
||||
})),
|
||||
);
|
||||
|
||||
const statusOptions = computed(() => [
|
||||
{ label: t("custom.schedule.enabled"), value: "enabled" },
|
||||
{ label: t("custom.schedule.disabled"), value: "disabled" },
|
||||
]);
|
||||
|
||||
const listParams = computed<ScheduleTaskListParams>(() => {
|
||||
const params: ScheduleTaskListParams = {
|
||||
page: page.value,
|
||||
page_size: pageSize.value,
|
||||
};
|
||||
if (appliedFilters.prompt_rule_id) params.prompt_rule_id = appliedFilters.prompt_rule_id;
|
||||
if (appliedFilters.status) params.status = appliedFilters.status;
|
||||
if (appliedFilters.keyword?.trim()) params.keyword = appliedFilters.keyword.trim();
|
||||
if (appliedFilters.created_from) params.created_from = appliedFilters.created_from;
|
||||
if (appliedFilters.created_to) params.created_to = appliedFilters.created_to;
|
||||
return params;
|
||||
});
|
||||
|
||||
const listQuery = useQuery({
|
||||
queryKey: computed(() => ["schedules", "list", listParams.value]),
|
||||
@@ -31,15 +81,14 @@ const listQuery = useQuery({
|
||||
});
|
||||
|
||||
const columns = computed<TableColumnsType<ScheduleTask>>(() => [
|
||||
{ title: t("custom.schedule.name"), dataIndex: "name", key: "name", width: 160 },
|
||||
{ title: t("custom.schedule.rule"), dataIndex: "prompt_rule_name", key: "prompt_rule_name", width: 140 },
|
||||
{ title: t("custom.schedule.cron"), dataIndex: "cron_expr", key: "cron_expr", width: 140 },
|
||||
{ title: t("custom.schedule.platform"), dataIndex: "target_platform", key: "target_platform", width: 120 },
|
||||
{ title: t("custom.schedule.brand"), dataIndex: "brand_name", key: "brand_name", width: 120 },
|
||||
{ title: t("custom.schedule.nextRun"), dataIndex: "next_run_at", key: "next_run_at", width: 168 },
|
||||
{ title: t("custom.promptRule.status"), dataIndex: "status", key: "status", width: 100 },
|
||||
{ title: t("common.createdAt"), dataIndex: "created_at", key: "created_at", width: 168 },
|
||||
{ title: t("common.actions"), key: "actions", width: 160, fixed: "right" },
|
||||
{ title: t("custom.schedule.name"), dataIndex: "name", key: "name", width: 220 },
|
||||
{ title: t("custom.schedule.rule"), dataIndex: "prompt_rule_name", key: "prompt_rule_name", width: 180 },
|
||||
{ title: t("custom.instant.executionStatus"), dataIndex: "status", key: "status", width: 140 },
|
||||
{ title: t("custom.instant.executionTime"), dataIndex: "cron_expr", key: "cron_expr", width: 170 },
|
||||
{ title: t("custom.schedule.platform"), dataIndex: "target_platform", key: "target_platform", width: 220 },
|
||||
{ title: t("custom.task.generateCount"), dataIndex: "generate_count", key: "generate_count", width: 120 },
|
||||
{ title: t("custom.instant.createdTime"), dataIndex: "created_at", key: "created_at", width: 170 },
|
||||
{ title: t("common.actions"), key: "actions", width: 140, fixed: "right", align: "right" },
|
||||
]);
|
||||
|
||||
const removeMutation = useMutation({
|
||||
@@ -65,6 +114,23 @@ const toggleStatusMutation = useMutation({
|
||||
onError: (error) => message.error(formatError(error)),
|
||||
});
|
||||
|
||||
function applyFilters(): void {
|
||||
page.value = 1;
|
||||
appliedFilters.prompt_rule_id = draftFilters.prompt_rule_id;
|
||||
appliedFilters.status = draftFilters.status;
|
||||
appliedFilters.keyword = draftFilters.keyword?.trim() || "";
|
||||
appliedFilters.created_from = createdRange.value?.[0]?.startOf("day").toISOString();
|
||||
appliedFilters.created_to = createdRange.value?.[1]?.endOf("day").toISOString();
|
||||
}
|
||||
|
||||
function resetFilters(): void {
|
||||
draftFilters.prompt_rule_id = undefined;
|
||||
draftFilters.status = undefined;
|
||||
draftFilters.keyword = "";
|
||||
createdRange.value = null;
|
||||
applyFilters();
|
||||
}
|
||||
|
||||
function openModal(task?: ScheduleTask): void {
|
||||
editingTask.value = task ?? null;
|
||||
modalOpen.value = true;
|
||||
@@ -77,15 +143,58 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="schedule-task-tab">
|
||||
<div class="schedule-task-tab__head">
|
||||
<span class="schedule-task-tab__count">
|
||||
{{ t("templates.list.count", { count: listQuery.data.value?.total ?? 0 }) }}
|
||||
</span>
|
||||
<a-button type="primary" @click="openModal()">
|
||||
<template #icon><PlusOutlined /></template>
|
||||
{{ t("common.create") }}
|
||||
</a-button>
|
||||
<div class="task-tab">
|
||||
<div class="task-tab__filters">
|
||||
<div class="task-tab__filter">
|
||||
<label>{{ t("custom.filters.promptRule") }}:</label>
|
||||
<a-select
|
||||
v-model:value="draftFilters.prompt_rule_id"
|
||||
allow-clear
|
||||
size="large"
|
||||
:options="promptOptions"
|
||||
:placeholder="t('custom.task.promptPlaceholder')"
|
||||
:loading="rulesQuery.isPending.value"
|
||||
@change="applyFilters"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="task-tab__filter">
|
||||
<label>{{ t("custom.filters.status") }}:</label>
|
||||
<a-select
|
||||
v-model:value="draftFilters.status"
|
||||
allow-clear
|
||||
size="large"
|
||||
:options="statusOptions"
|
||||
:placeholder="t('common.selectPlease')"
|
||||
@change="applyFilters"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="task-tab__filter task-tab__filter--range">
|
||||
<label>{{ t("custom.filters.createdTime") }}:</label>
|
||||
<a-range-picker
|
||||
v-model:value="createdRange"
|
||||
allow-clear
|
||||
size="large"
|
||||
format="YYYY-MM-DD"
|
||||
@change="applyFilters"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="task-tab__filter task-tab__filter--keyword">
|
||||
<label>{{ t("custom.filters.name") }}:</label>
|
||||
<a-input-search
|
||||
v-model:value="draftFilters.keyword"
|
||||
size="large"
|
||||
:placeholder="t('custom.filters.namePlaceholder')"
|
||||
@search="applyFilters"
|
||||
@pressEnter="applyFilters"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="task-tab__filter task-tab__filter--action">
|
||||
<a-button size="large" @click="resetFilters">{{ t("common.reset") }}</a-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<a-table
|
||||
@@ -99,55 +208,78 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
showSizeChanger: true,
|
||||
}"
|
||||
row-key="id"
|
||||
size="small"
|
||||
:scroll="{ x: 1200 }"
|
||||
:scroll="{ x: 1360 }"
|
||||
@change="(p: any) => handleTableChange(p.current, p.pageSize)"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'prompt_rule_name'">
|
||||
{{ record.prompt_rule_name || "--" }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'target_platform'">
|
||||
{{ formatPublishPlatformSummary(record.target_platform) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'brand_name'">
|
||||
{{ record.brand_name || "--" }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'next_run_at'">
|
||||
{{ record.next_run_at ? formatDateTime(record.next_run_at) : "--" }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<a-tag :color="record.status === 'enabled' ? 'green' : 'default'">
|
||||
{{ record.status === "enabled" ? t("custom.schedule.enabled") : t("custom.schedule.disabled") }}
|
||||
</a-tag>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'cron_expr'">
|
||||
{{ formatCronExecutionTime(record.cron_expr) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'target_platform'">
|
||||
{{ formatPublishPlatformSummary(record.target_platform) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'generate_count'">
|
||||
--
|
||||
</template>
|
||||
<template v-else-if="column.key === 'created_at'">
|
||||
{{ formatDateTime(record.created_at) }}
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<a-space :size="4">
|
||||
<a-button type="link" size="small" @click="openModal(record)">
|
||||
{{ t("common.edit") }}
|
||||
</a-button>
|
||||
<a-button
|
||||
type="link"
|
||||
size="small"
|
||||
@click="toggleStatusMutation.mutate({
|
||||
id: record.id,
|
||||
status: record.status === 'enabled' ? 'disabled' : 'enabled',
|
||||
})"
|
||||
<div class="table-actions-row">
|
||||
<a-tooltip :title="t('common.edit')">
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-edit"
|
||||
@click="openModal(record)"
|
||||
>
|
||||
<EditOutlined />
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-tooltip
|
||||
:title="record.status === 'enabled' ? t('custom.schedule.disabled') : t('custom.schedule.enabled')"
|
||||
>
|
||||
{{ record.status === "enabled" ? t("custom.schedule.disabled") : t("custom.schedule.enabled") }}
|
||||
</a-button>
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
:class="[
|
||||
'action-btn',
|
||||
record.status === 'enabled' ? 'action-disable' : 'action-enable',
|
||||
]"
|
||||
@click="toggleStatusMutation.mutate({
|
||||
id: record.id,
|
||||
status: record.status === 'enabled' ? 'disabled' : 'enabled',
|
||||
})"
|
||||
>
|
||||
<PauseCircleOutlined v-if="record.status === 'enabled'" />
|
||||
<PlayCircleOutlined v-else />
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-popconfirm
|
||||
:title="t('custom.schedule.deleteConfirm')"
|
||||
@confirm="removeMutation.mutate(record.id)"
|
||||
>
|
||||
<a-button type="link" size="small" danger>
|
||||
{{ t("common.delete") }}
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-delete"
|
||||
:title="t('common.delete')"
|
||||
>
|
||||
<DeleteOutlined />
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
</a-table>
|
||||
@@ -157,15 +289,49 @@ function handleTableChange(nextPage: number, nextPageSize: number): void {
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.schedule-task-tab__head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 16px;
|
||||
.task-tab__filters {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(180px, 240px) minmax(180px, 240px) minmax(240px, 320px) minmax(240px, 1fr) auto;
|
||||
gap: 16px;
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
|
||||
.schedule-task-tab__count {
|
||||
font-size: 13px;
|
||||
color: #8c8c8c;
|
||||
.task-tab__filter {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.task-tab__filter label {
|
||||
flex-shrink: 0;
|
||||
color: #434343;
|
||||
font-size: 14px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.task-tab__filter :deep(.ant-select),
|
||||
.task-tab__filter :deep(.ant-picker),
|
||||
.task-tab__filter :deep(.ant-input-search) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.task-tab__filter--action {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
@media (max-width: 1400px) {
|
||||
.task-tab__filters {
|
||||
grid-template-columns: repeat(2, minmax(260px, 1fr));
|
||||
}
|
||||
|
||||
.task-tab__filter--action {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.task-tab__filters {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -187,6 +187,7 @@ const enUS = {
|
||||
status: {
|
||||
generate: {
|
||||
draft: "Draft",
|
||||
queued: "Queued",
|
||||
generating: "Generating",
|
||||
running: "Running",
|
||||
completed: "Completed",
|
||||
@@ -202,6 +203,9 @@ const enUS = {
|
||||
},
|
||||
sourceType: {
|
||||
template: "Template generation",
|
||||
custom_generation: "Custom generation",
|
||||
instant_task: "Instant task",
|
||||
schedule_task: "Scheduled task",
|
||||
},
|
||||
},
|
||||
templates: {
|
||||
@@ -568,6 +572,11 @@ const enUS = {
|
||||
selectPlatform: "Target platform",
|
||||
submit: "Generate now",
|
||||
extraParams: "Extra parameters",
|
||||
name: "Task name",
|
||||
executionStatus: "Execution status",
|
||||
executionTime: "Execution time",
|
||||
createdTime: "Created time",
|
||||
empty: "No instant tasks yet.",
|
||||
},
|
||||
filters: {
|
||||
promptRule: "Prompt rule",
|
||||
@@ -575,6 +584,14 @@ const enUS = {
|
||||
generateStatus: "Generation status",
|
||||
title: "Title",
|
||||
generateTime: "Generation time",
|
||||
status: "Status",
|
||||
name: "Name",
|
||||
namePlaceholder: "Search by task name",
|
||||
createdTime: "Created time",
|
||||
},
|
||||
article: {
|
||||
titleColumn: "Article title",
|
||||
titleGenerating: "Generating title",
|
||||
},
|
||||
messages: {
|
||||
ruleCreated: "Rule created.",
|
||||
|
||||
@@ -187,6 +187,7 @@ const zhCN = {
|
||||
status: {
|
||||
generate: {
|
||||
draft: "草稿",
|
||||
queued: "排队中",
|
||||
generating: "生成中",
|
||||
running: "运行中",
|
||||
completed: "已完成",
|
||||
@@ -202,6 +203,9 @@ const zhCN = {
|
||||
},
|
||||
sourceType: {
|
||||
template: "模版单次生成",
|
||||
custom_generation: "自定义生成",
|
||||
instant_task: "即时任务",
|
||||
schedule_task: "定时任务",
|
||||
},
|
||||
},
|
||||
templates: {
|
||||
@@ -577,6 +581,11 @@ const zhCN = {
|
||||
selectPlatform: "目标平台",
|
||||
submit: "立即生成",
|
||||
extraParams: "额外参数",
|
||||
name: "任务名称",
|
||||
executionStatus: "执行状态",
|
||||
executionTime: "执行时间",
|
||||
createdTime: "创建时间",
|
||||
empty: "还未创建即时任务,暂无相关数据~",
|
||||
},
|
||||
filters: {
|
||||
promptRule: "Prompt 规则",
|
||||
@@ -584,6 +593,14 @@ const zhCN = {
|
||||
generateStatus: "生成状态",
|
||||
title: "标题",
|
||||
generateTime: "生成时间",
|
||||
status: "状态",
|
||||
name: "名称",
|
||||
namePlaceholder: "请输入任务名称内搜索",
|
||||
createdTime: "创建时间",
|
||||
},
|
||||
article: {
|
||||
titleColumn: "文章标题",
|
||||
titleGenerating: "标题生成中",
|
||||
},
|
||||
messages: {
|
||||
ruleCreated: "规则创建成功",
|
||||
|
||||
@@ -29,7 +29,13 @@ const quotaQuery = useQuery({
|
||||
});
|
||||
|
||||
const userInitial = computed(() => authStore.user?.name?.slice(0, 1).toUpperCase() ?? "A");
|
||||
const selectedKey = computed(() => String(route.meta.navKey ?? route.path));
|
||||
const selectedKeys = computed(() => {
|
||||
if (route.meta.navKey === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [String(route.meta.navKey ?? route.path)];
|
||||
});
|
||||
const pageTitle = computed(() => t(String(route.meta.titleKey ?? "route.workspace.title")));
|
||||
|
||||
const localeOptions = computed(() => [
|
||||
@@ -117,7 +123,7 @@ async function handleLogout(): Promise<void> {
|
||||
<a-menu
|
||||
mode="inline"
|
||||
theme="light"
|
||||
:selected-keys="[selectedKey]"
|
||||
:selected-keys="selectedKeys"
|
||||
class="admin-menu"
|
||||
>
|
||||
<template v-for="section in navSections" :key="section.key">
|
||||
|
||||
@@ -11,6 +11,8 @@ import type {
|
||||
CompetitorRequest,
|
||||
GenerateFromRuleRequest,
|
||||
GenerateFromRuleResponse,
|
||||
InstantTaskListParams,
|
||||
InstantTaskListResponse,
|
||||
JsonValue,
|
||||
Keyword,
|
||||
KeywordRequest,
|
||||
@@ -27,7 +29,6 @@ import type {
|
||||
QuotaSummary,
|
||||
Question,
|
||||
QuestionRequest,
|
||||
QuestionVersion,
|
||||
RecentArticle,
|
||||
RefreshResponse,
|
||||
ScheduleTask,
|
||||
@@ -319,9 +320,6 @@ export const brandsApi = {
|
||||
removeQuestion(brandId: number, questionId: number) {
|
||||
return apiClient.remove<null>(`/api/tenant/brands/${brandId}/questions/${questionId}`);
|
||||
},
|
||||
listQuestionVersions(brandId: number) {
|
||||
return apiClient.get<QuestionVersion[]>(`/api/tenant/brands/${brandId}/question-versions`);
|
||||
},
|
||||
listCompetitors(brandId: number) {
|
||||
return apiClient.get<Competitor[]>(`/api/tenant/brands/${brandId}/competitors`);
|
||||
},
|
||||
@@ -408,6 +406,12 @@ export const generateApi = {
|
||||
},
|
||||
};
|
||||
|
||||
export const instantTasksApi = {
|
||||
list(params?: InstantTaskListParams) {
|
||||
return apiClient.get<InstantTaskListResponse>("/api/tenant/instant-tasks", { params });
|
||||
},
|
||||
};
|
||||
|
||||
export function normalizeInputParams(
|
||||
payload: Record<string, JsonValue>,
|
||||
articleId?: number,
|
||||
|
||||
@@ -4,6 +4,7 @@ import { i18n } from "@/i18n";
|
||||
|
||||
const generateStatusMap: Record<string, { label: string; color: string }> = {
|
||||
draft: { label: "status.generate.draft", color: "default" },
|
||||
queued: { label: "status.generate.queued", color: "processing" },
|
||||
generating: { label: "status.generate.generating", color: "processing" },
|
||||
running: { label: "status.generate.running", color: "processing" },
|
||||
completed: { label: "status.generate.completed", color: "success" },
|
||||
@@ -43,16 +44,45 @@ export function getPublishStatusMeta(status?: string | null): { label: string; c
|
||||
return meta ? { label: i18n.global.t(meta.label), color: meta.color } : { label: status, color: "default" };
|
||||
}
|
||||
|
||||
export function getSourceTypeLabel(sourceType?: string | null): string {
|
||||
export function getSourceTypeLabel(sourceType?: string | null, generationMode?: string | null): string {
|
||||
if (!sourceType) {
|
||||
return "--";
|
||||
}
|
||||
if (sourceType === "template") {
|
||||
return i18n.global.t("status.sourceType.template");
|
||||
}
|
||||
if (sourceType === "custom_generation") {
|
||||
if (generationMode === "schedule") {
|
||||
return i18n.global.t("status.sourceType.schedule_task");
|
||||
}
|
||||
if (generationMode === "instant") {
|
||||
return i18n.global.t("status.sourceType.instant_task");
|
||||
}
|
||||
return i18n.global.t("status.sourceType.custom_generation");
|
||||
}
|
||||
return sourceType;
|
||||
}
|
||||
|
||||
export function formatCronExecutionTime(cronExpr?: string | null): string {
|
||||
if (!cronExpr) {
|
||||
return "--";
|
||||
}
|
||||
|
||||
const fiveFieldMatch = cronExpr.match(/^(\d{1,2})\s+(\d{1,2})\s+\*\s+\*\s+\*$/);
|
||||
if (fiveFieldMatch) {
|
||||
const [, minute, hour] = fiveFieldMatch;
|
||||
return `${hour.padStart(2, "0")}:${minute.padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
const sixFieldMatch = cronExpr.match(/^(\d{1,2})\s+(\d{1,2})\s+(\d{1,2})\s+\*\s+\*\s+\*$/);
|
||||
if (sixFieldMatch) {
|
||||
const [, second, minute, hour] = sixFieldMatch;
|
||||
return `${hour.padStart(2, "0")}:${minute.padStart(2, "0")}:${second.padStart(2, "0")}`;
|
||||
}
|
||||
|
||||
return cronExpr;
|
||||
}
|
||||
|
||||
export function getTemplateMeta(templateKey: string): {
|
||||
eyebrow: string;
|
||||
helper: string;
|
||||
|
||||
@@ -63,7 +63,7 @@ const router = createRouter({
|
||||
meta: {
|
||||
titleKey: "route.articleEditor.title",
|
||||
descriptionKey: "route.articleEditor.description",
|
||||
navKey: "/articles/templates",
|
||||
navKey: null,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
Vendored
+1
-1
@@ -7,7 +7,7 @@ declare module "vue-router" {
|
||||
titleKey?: string;
|
||||
descriptionKey?: string;
|
||||
requiresAuth?: boolean;
|
||||
navKey?: string;
|
||||
navKey?: string | null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,44 @@ html, body, #app {
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.table-actions-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.action-btn.ant-btn {
|
||||
color: #8c8c8c;
|
||||
font-size: 14px;
|
||||
transition: color 0.2s, background-color 0.2s;
|
||||
}
|
||||
|
||||
.action-edit.ant-btn:hover:not(:disabled) {
|
||||
color: #52c41a;
|
||||
background: #f6ffed;
|
||||
}
|
||||
|
||||
.action-eye.ant-btn:hover:not(:disabled) {
|
||||
color: #13c2c2;
|
||||
background: #e6fffb;
|
||||
}
|
||||
|
||||
.action-enable.ant-btn:hover:not(:disabled) {
|
||||
color: #52c41a;
|
||||
background: #f6ffed;
|
||||
}
|
||||
|
||||
.action-disable.ant-btn:hover:not(:disabled) {
|
||||
color: #fa8c16;
|
||||
background: #fff7e6;
|
||||
}
|
||||
|
||||
.action-delete.ant-btn:hover:not(:disabled) {
|
||||
color: #ff4d4f;
|
||||
background: #fff2f0;
|
||||
}
|
||||
|
||||
/* Component Overrides for Ant Design to match Pro style */
|
||||
.ant-layout {
|
||||
min-height: 100vh;
|
||||
@@ -180,3 +218,38 @@ html, body, #app {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
/* Premium Modal Overrides */
|
||||
.ant-modal-content {
|
||||
border-radius: 16px !important;
|
||||
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.08) !important;
|
||||
padding: 12px !important;
|
||||
}
|
||||
|
||||
.ant-modal-header {
|
||||
border-bottom: none !important;
|
||||
padding: 16px 16px 8px !important;
|
||||
background: transparent !important;
|
||||
}
|
||||
|
||||
.ant-modal-title {
|
||||
font-size: 18px !important;
|
||||
font-weight: 700 !important;
|
||||
color: #111827 !important;
|
||||
}
|
||||
|
||||
.ant-modal-body {
|
||||
padding: 12px 16px !important;
|
||||
}
|
||||
|
||||
.ant-modal-footer {
|
||||
border-top: none !important;
|
||||
padding: 8px 16px 12px !important;
|
||||
}
|
||||
|
||||
.ant-modal-footer .ant-btn {
|
||||
border-radius: 8px !important;
|
||||
height: 38px !important;
|
||||
padding: 0 20px !important;
|
||||
font-weight: 500 !important;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
import {
|
||||
DeleteOutlined,
|
||||
EditOutlined,
|
||||
FileSearchOutlined,
|
||||
PlusOutlined,
|
||||
} from "@ant-design/icons-vue";
|
||||
import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query";
|
||||
@@ -13,6 +12,7 @@ import { computed, reactive, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
import { brandsApi } from "@/lib/api";
|
||||
import { formatDateTime } from "@/lib/display";
|
||||
import { formatError } from "@/lib/errors";
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
@@ -21,8 +21,6 @@ const { t } = useI18n();
|
||||
const activeTab = ref("keywords");
|
||||
const selectedBrandId = ref<number | null>(null);
|
||||
const selectedKeywordId = ref<number | null>(null);
|
||||
const versionsDrawerOpen = ref(false);
|
||||
const selectedQuestionId = ref<number | null>(null);
|
||||
|
||||
const brandModalOpen = ref(false);
|
||||
const editingBrandId = ref<number | null>(null);
|
||||
@@ -78,12 +76,6 @@ const filteredQuestionsQuery = useQuery({
|
||||
queryFn: () => brandsApi.listQuestions(selectedBrandId.value as number, selectedKeywordId.value),
|
||||
});
|
||||
|
||||
const questionVersionsQuery = useQuery({
|
||||
queryKey: computed(() => ["brands", selectedBrandId.value, "question-versions"]),
|
||||
enabled: computed(() => Boolean(selectedBrandId.value)),
|
||||
queryFn: () => brandsApi.listQuestionVersions(selectedBrandId.value as number),
|
||||
});
|
||||
|
||||
const competitorsQuery = useQuery({
|
||||
queryKey: computed(() => ["brands", selectedBrandId.value, "competitors"]),
|
||||
enabled: computed(() => Boolean(selectedBrandId.value)),
|
||||
@@ -192,10 +184,7 @@ const questionMutations = {
|
||||
onSuccess: async () => {
|
||||
message.success(t("brands.messages.createQuestion"));
|
||||
questionModalOpen.value = false;
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ["brands", selectedBrandId.value, "questions"] }),
|
||||
queryClient.invalidateQueries({ queryKey: ["brands", selectedBrandId.value, "question-versions"] }),
|
||||
]);
|
||||
await queryClient.invalidateQueries({ queryKey: ["brands", selectedBrandId.value, "questions"] });
|
||||
},
|
||||
onError: (error) => message.error(formatError(error)),
|
||||
}),
|
||||
@@ -207,10 +196,7 @@ const questionMutations = {
|
||||
onSuccess: async () => {
|
||||
message.success(t("brands.messages.updateQuestion"));
|
||||
questionModalOpen.value = false;
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ["brands", selectedBrandId.value, "questions"] }),
|
||||
queryClient.invalidateQueries({ queryKey: ["brands", selectedBrandId.value, "question-versions"] }),
|
||||
]);
|
||||
await queryClient.invalidateQueries({ queryKey: ["brands", selectedBrandId.value, "questions"] });
|
||||
},
|
||||
onError: (error) => message.error(formatError(error)),
|
||||
}),
|
||||
@@ -219,10 +205,7 @@ const questionMutations = {
|
||||
brandsApi.removeQuestion(selectedBrandId.value as number, questionId),
|
||||
onSuccess: async () => {
|
||||
message.success(t("brands.messages.deleteQuestion"));
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({ queryKey: ["brands", selectedBrandId.value, "questions"] }),
|
||||
queryClient.invalidateQueries({ queryKey: ["brands", selectedBrandId.value, "question-versions"] }),
|
||||
]);
|
||||
await queryClient.invalidateQueries({ queryKey: ["brands", selectedBrandId.value, "questions"] });
|
||||
},
|
||||
onError: (error) => message.error(formatError(error)),
|
||||
}),
|
||||
@@ -273,9 +256,6 @@ const competitorMutations = {
|
||||
const selectedKeyword = computed(() =>
|
||||
keywordsQuery.data.value?.find((item) => item.id === selectedKeywordId.value) ?? null,
|
||||
);
|
||||
const versionItems = computed(() =>
|
||||
(questionVersionsQuery.data.value || []).filter((item) => item.question_id === selectedQuestionId.value),
|
||||
);
|
||||
|
||||
const questionColumns = computed<TableColumnsType<Question>>(() => [
|
||||
{
|
||||
@@ -287,12 +267,13 @@ const questionColumns = computed<TableColumnsType<Question>>(() => [
|
||||
title: t("common.createdAt"),
|
||||
dataIndex: "created_at",
|
||||
key: "created_at",
|
||||
width: 160,
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: t("common.actions"),
|
||||
key: "actions",
|
||||
width: 180,
|
||||
width: 120,
|
||||
align: "right",
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -379,11 +360,6 @@ function openCompetitorModal(competitor?: Competitor): void {
|
||||
competitorModalOpen.value = true;
|
||||
}
|
||||
|
||||
function openVersions(questionId: number): void {
|
||||
selectedQuestionId.value = questionId;
|
||||
versionsDrawerOpen.value = true;
|
||||
}
|
||||
|
||||
async function submitBrand(): Promise<void> {
|
||||
if (!brandForm.name.trim()) {
|
||||
return;
|
||||
@@ -474,13 +450,28 @@ async function submitCompetitor(): Promise<void> {
|
||||
</div>
|
||||
|
||||
<div class="brands-view__brand-card-actions">
|
||||
<a-button size="small" @click.stop="openBrandModal(brand)">
|
||||
<template #icon><EditOutlined /></template>
|
||||
</a-button>
|
||||
<a-tooltip :title="t('common.edit')">
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-edit"
|
||||
@click.stop="openBrandModal(brand)"
|
||||
>
|
||||
<EditOutlined />
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-popconfirm @confirm="brandMutations.remove.mutate(brand.id)">
|
||||
<template #title>{{ t("brands.deleteBrand") }}</template>
|
||||
<a-button size="small" danger @click.stop>
|
||||
<template #icon><DeleteOutlined /></template>
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-delete"
|
||||
:title="t('common.delete')"
|
||||
@click.stop
|
||||
>
|
||||
<DeleteOutlined />
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</div>
|
||||
@@ -497,7 +488,6 @@ async function submitCompetitor(): Promise<void> {
|
||||
<aside class="brands-view__keywords-panel">
|
||||
<div class="brands-view__section-head brands-view__section-head--compact">
|
||||
<div>
|
||||
<p class="eyebrow">{{ t("brands.sections.keywords") }}</p>
|
||||
<h3>{{ t("brands.sections.keywords") }}</h3>
|
||||
</div>
|
||||
<a-button type="primary" size="small" @click="openKeywordModal()">
|
||||
@@ -516,13 +506,28 @@ async function submitCompetitor(): Promise<void> {
|
||||
>
|
||||
<span>{{ keyword.name }}</span>
|
||||
<div class="brands-view__keyword-actions">
|
||||
<a-button size="small" @click.stop="openKeywordModal(keyword)">
|
||||
<template #icon><EditOutlined /></template>
|
||||
</a-button>
|
||||
<a-tooltip :title="t('common.edit')">
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-edit"
|
||||
@click.stop="openKeywordModal(keyword)"
|
||||
>
|
||||
<EditOutlined />
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-popconfirm @confirm="keywordMutations.remove.mutate(keyword.id)">
|
||||
<template #title>{{ t("common.delete") }}</template>
|
||||
<a-button size="small" danger @click.stop>
|
||||
<template #icon><DeleteOutlined /></template>
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-delete"
|
||||
:title="t('common.delete')"
|
||||
@click.stop
|
||||
>
|
||||
<DeleteOutlined />
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</div>
|
||||
@@ -554,24 +559,34 @@ async function submitCompetitor(): Promise<void> {
|
||||
<template v-if="column.key === 'question_text'">
|
||||
<div class="brands-view__question-cell">
|
||||
<strong>{{ record.question_text }}</strong>
|
||||
<span>{{ record.version_no ? `v${record.version_no}` : "--" }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'created_at'">
|
||||
{{ record.created_at }}
|
||||
<span class="brands-view__datetime">{{ formatDateTime(record.created_at) }}</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<div class="brands-view__inline-actions">
|
||||
<a-button size="small" @click="openVersions(record.id)">
|
||||
<template #icon><FileSearchOutlined /></template>
|
||||
</a-button>
|
||||
<a-button size="small" @click="openQuestionModal(record)">
|
||||
<template #icon><EditOutlined /></template>
|
||||
</a-button>
|
||||
<div class="table-actions-row">
|
||||
<a-tooltip :title="t('common.edit')">
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-edit"
|
||||
@click="openQuestionModal(record)"
|
||||
>
|
||||
<EditOutlined />
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-popconfirm @confirm="questionMutations.remove.mutate(record.id)">
|
||||
<template #title>{{ t("common.delete") }}</template>
|
||||
<a-button size="small" danger>
|
||||
<template #icon><DeleteOutlined /></template>
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-delete"
|
||||
:title="t('common.delete')"
|
||||
>
|
||||
<DeleteOutlined />
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</div>
|
||||
@@ -608,13 +623,27 @@ async function submitCompetitor(): Promise<void> {
|
||||
</a>
|
||||
</div>
|
||||
<div class="brands-view__inline-actions">
|
||||
<a-button size="small" @click="openCompetitorModal(competitor)">
|
||||
<template #icon><EditOutlined /></template>
|
||||
</a-button>
|
||||
<a-tooltip :title="t('common.edit')">
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-edit"
|
||||
@click="openCompetitorModal(competitor)"
|
||||
>
|
||||
<EditOutlined />
|
||||
</a-button>
|
||||
</a-tooltip>
|
||||
<a-popconfirm @confirm="competitorMutations.remove.mutate(competitor.id)">
|
||||
<template #title>{{ t("common.delete") }}</template>
|
||||
<a-button size="small" danger>
|
||||
<template #icon><DeleteOutlined /></template>
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-delete"
|
||||
:title="t('common.delete')"
|
||||
>
|
||||
<DeleteOutlined />
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</div>
|
||||
@@ -641,6 +670,7 @@ async function submitCompetitor(): Promise<void> {
|
||||
<a-modal
|
||||
v-model:open="brandModalOpen"
|
||||
:title="editingBrandId ? t('brands.editBrand') : t('brands.newBrand')"
|
||||
centered
|
||||
@ok="submitBrand"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
@@ -659,6 +689,7 @@ async function submitCompetitor(): Promise<void> {
|
||||
<a-modal
|
||||
v-model:open="keywordModalOpen"
|
||||
:title="editingKeywordId ? t('common.edit') : t('brands.actions.newKeyword')"
|
||||
centered
|
||||
@ok="submitKeyword"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
@@ -671,6 +702,7 @@ async function submitCompetitor(): Promise<void> {
|
||||
<a-modal
|
||||
v-model:open="questionModalOpen"
|
||||
:title="editingQuestionId ? t('common.edit') : t('brands.actions.newQuestion')"
|
||||
centered
|
||||
@ok="submitQuestion"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
@@ -689,6 +721,7 @@ async function submitCompetitor(): Promise<void> {
|
||||
<a-modal
|
||||
v-model:open="competitorModalOpen"
|
||||
:title="editingCompetitorId ? t('common.edit') : t('brands.actions.newCompetitor')"
|
||||
centered
|
||||
@ok="submitCompetitor"
|
||||
>
|
||||
<a-form layout="vertical">
|
||||
@@ -709,22 +742,6 @@ async function submitCompetitor(): Promise<void> {
|
||||
</a-form-item>
|
||||
</a-form>
|
||||
</a-modal>
|
||||
|
||||
<a-drawer
|
||||
v-model:open="versionsDrawerOpen"
|
||||
:title="t('brands.sections.versions')"
|
||||
width="520"
|
||||
class="brands-view__versions-drawer"
|
||||
>
|
||||
<a-list :data-source="versionItems" item-layout="vertical">
|
||||
<template #renderItem="{ item }">
|
||||
<a-list-item>
|
||||
<a-list-item-meta :title="`v${item.version_no}`" :description="item.created_at" />
|
||||
<p class="brands-view__version-text">{{ item.question_text }}</p>
|
||||
</a-list-item>
|
||||
</template>
|
||||
</a-list>
|
||||
</a-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -880,7 +897,8 @@ async function submitCompetitor(): Promise<void> {
|
||||
.brands-view__keyword-actions,
|
||||
.brands-view__inline-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.brands-view__keyword-layout {
|
||||
@@ -922,12 +940,10 @@ async function submitCompetitor(): Promise<void> {
|
||||
.brands-view__question-cell {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.brands-view__question-cell span {
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
.brands-view__datetime {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.brands-view__competitor-grid {
|
||||
@@ -975,16 +991,6 @@ async function submitCompetitor(): Promise<void> {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.brands-view__version-text {
|
||||
margin: 0;
|
||||
color: #334155;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.brands-view__versions-drawer :deep(.ant-drawer-body) {
|
||||
padding: 18px 24px 24px;
|
||||
}
|
||||
|
||||
@media (max-width: 1080px) {
|
||||
.brands-view__brand-grid,
|
||||
.brands-view__keyword-layout,
|
||||
|
||||
@@ -7,6 +7,7 @@ import { ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
import CustomArticleTab from "@/components/CustomArticleTab.vue";
|
||||
import InstantTaskTab from "@/components/InstantTaskTab.vue";
|
||||
import PromptRuleTab from "@/components/PromptRuleTab.vue";
|
||||
import ScheduleTaskTab from "@/components/ScheduleTaskTab.vue";
|
||||
import InstantGenerateModal from "@/components/InstantGenerateModal.vue";
|
||||
@@ -56,6 +57,9 @@ function openScheduleModal(): void {
|
||||
<a-tab-pane key="articles" :tab="t('custom.tabs.articles')">
|
||||
<CustomArticleTab />
|
||||
</a-tab-pane>
|
||||
<a-tab-pane key="instantTasks" :tab="t('custom.tabs.instantTasks')">
|
||||
<InstantTaskTab />
|
||||
</a-tab-pane>
|
||||
<a-tab-pane key="scheduleTasks" :tab="t('custom.tabs.scheduleTasks')">
|
||||
<ScheduleTaskTab />
|
||||
</a-tab-pane>
|
||||
|
||||
@@ -172,7 +172,8 @@ const articleColumns = computed<TableColumnsType<ArticleListItem>>(() => [
|
||||
{
|
||||
title: t("common.actions"),
|
||||
key: "actions",
|
||||
width: 180,
|
||||
width: 120,
|
||||
align: "right",
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -447,24 +448,36 @@ async function handleDelete(articleId: number): Promise<void> {
|
||||
</template>
|
||||
|
||||
<template v-else-if="column.key === 'actions'">
|
||||
<div class="templates-view__actions">
|
||||
<div class="table-actions-row">
|
||||
<a-tooltip
|
||||
:title="canEditArticle(record.generate_status) ? t('templates.list.edit') : t('templates.list.editDisabled')"
|
||||
>
|
||||
<a-button
|
||||
size="small"
|
||||
:disabled="!canEditArticle(record.generate_status)"
|
||||
@click="openEditor(record)"
|
||||
>
|
||||
<template #icon><EditOutlined /></template>
|
||||
</a-button>
|
||||
<span>
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-edit"
|
||||
:disabled="!canEditArticle(record.generate_status)"
|
||||
@click="openEditor(record)"
|
||||
>
|
||||
<EditOutlined />
|
||||
</a-button>
|
||||
</span>
|
||||
</a-tooltip>
|
||||
<a-popconfirm
|
||||
:title="t('templates.list.deleteConfirm')"
|
||||
@confirm="handleDelete(record.id)"
|
||||
>
|
||||
<a-button size="small" danger :loading="deleteMutation.isPending.value">
|
||||
<template #icon><DeleteOutlined /></template>
|
||||
<a-button
|
||||
type="text"
|
||||
shape="circle"
|
||||
size="small"
|
||||
class="action-btn action-delete"
|
||||
:loading="deleteMutation.isPending.value"
|
||||
:title="t('common.delete')"
|
||||
>
|
||||
<DeleteOutlined />
|
||||
</a-button>
|
||||
</a-popconfirm>
|
||||
</div>
|
||||
@@ -624,11 +637,6 @@ async function handleDelete(articleId: number): Promise<void> {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.templates-view__actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.templates-view__status-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -1070,7 +1070,6 @@ flowchart LR
|
||||
- `/api/tenant/brands/{id}`
|
||||
- `/api/tenant/brands/{id}/keywords`
|
||||
- `/api/tenant/brands/{id}/questions`
|
||||
- `/api/tenant/brands/{id}/question-versions`
|
||||
- `/api/tenant/brands/{id}/competitors`
|
||||
- `/api/tenant/knowledge/groups`
|
||||
- `/api/tenant/knowledge/items`
|
||||
|
||||
@@ -557,7 +557,6 @@ workspace_service 聚合多个 repository 数据,单次返回,避免前端
|
||||
| DELETE | `/api/tenant/brands/{id}/keywords/{kid}` | 删除关键词 |
|
||||
| GET | `/api/tenant/brands/{id}/questions` | 问题列表 (按关键词筛选) |
|
||||
| POST | `/api/tenant/brands/{id}/questions` | 创建问题 (自动创建 v1 版本) |
|
||||
| GET | `/api/tenant/brands/{id}/question-versions` | 问题版本列表 |
|
||||
| GET | `/api/tenant/brands/{id}/competitors` | 竞品列表 |
|
||||
| POST | `/api/tenant/brands/{id}/competitors` | 创建竞品 |
|
||||
| PUT | `/api/tenant/brands/{id}/competitors/{cid}` | 更新竞品 |
|
||||
|
||||
@@ -214,6 +214,7 @@ export interface ArticleListParams {
|
||||
generate_status?: string;
|
||||
publish_status?: string;
|
||||
source_type?: string;
|
||||
generation_mode?: string;
|
||||
template_id?: number;
|
||||
prompt_rule_id?: number;
|
||||
keyword?: string;
|
||||
@@ -228,6 +229,7 @@ export interface ArticleListItem {
|
||||
template_name: string | null;
|
||||
prompt_rule_id: number | null;
|
||||
prompt_rule_name: string | null;
|
||||
generation_mode: string | null;
|
||||
platforms: string[];
|
||||
generate_status: string;
|
||||
publish_status: string;
|
||||
@@ -250,6 +252,7 @@ export interface ArticleDetail {
|
||||
source_type: string;
|
||||
template_id: number | null;
|
||||
template_name: string | null;
|
||||
generation_mode: string | null;
|
||||
platforms: string[];
|
||||
generate_status: string;
|
||||
publish_status: string;
|
||||
@@ -327,16 +330,6 @@ export interface Question {
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface QuestionVersion {
|
||||
id: number;
|
||||
question_id: number;
|
||||
question_text: string;
|
||||
question_hash: string;
|
||||
version_no: number;
|
||||
is_active: boolean;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface CompetitorRequest {
|
||||
name: string;
|
||||
website?: string | null;
|
||||
@@ -450,6 +443,9 @@ export interface ScheduleTaskListParams {
|
||||
page_size?: number;
|
||||
prompt_rule_id?: number;
|
||||
status?: string;
|
||||
keyword?: string;
|
||||
created_from?: string;
|
||||
created_to?: string;
|
||||
}
|
||||
|
||||
export interface ScheduleTaskListResponse {
|
||||
@@ -474,3 +470,31 @@ export interface GenerateFromRuleResponse {
|
||||
article_id: number;
|
||||
task_id: number;
|
||||
}
|
||||
|
||||
export interface InstantTaskListParams {
|
||||
page?: number;
|
||||
page_size?: number;
|
||||
prompt_rule_id?: number;
|
||||
status?: string;
|
||||
keyword?: string;
|
||||
created_from?: string;
|
||||
created_to?: string;
|
||||
}
|
||||
|
||||
export interface InstantTaskItem {
|
||||
id: number;
|
||||
article_id: number | null;
|
||||
prompt_rule_id: number | null;
|
||||
prompt_rule_name: string | null;
|
||||
name: string;
|
||||
status: string;
|
||||
execution_time: string | null;
|
||||
platforms: string[];
|
||||
generate_count: number;
|
||||
created_at: string;
|
||||
}
|
||||
|
||||
export interface InstantTaskListResponse {
|
||||
items: InstantTaskItem[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ type ArticleListParams struct {
|
||||
GenerateStatus *string
|
||||
PublishStatus *string
|
||||
SourceType *string
|
||||
GenerationMode *string
|
||||
TemplateID *int64
|
||||
PromptRuleID *int64
|
||||
Keyword *string
|
||||
@@ -45,6 +46,7 @@ type ArticleListItem struct {
|
||||
TemplateName *string `json:"template_name"`
|
||||
PromptRuleID *int64 `json:"prompt_rule_id"`
|
||||
PromptRuleName *string `json:"prompt_rule_name"`
|
||||
GenerationMode *string `json:"generation_mode"`
|
||||
Platforms []string `json:"platforms"`
|
||||
GenerateStatus string `json:"generate_status"`
|
||||
PublishStatus string `json:"publish_status"`
|
||||
@@ -64,6 +66,7 @@ type ArticleListResponse struct {
|
||||
|
||||
func (s *ArticleService) List(ctx context.Context, params ArticleListParams) (*ArticleListResponse, error) {
|
||||
actor := auth.MustActor(ctx)
|
||||
sourceType := params.SourceType
|
||||
|
||||
if params.Page < 1 {
|
||||
params.Page = 1
|
||||
@@ -99,9 +102,14 @@ func (s *ArticleService) List(ctx context.Context, params ArticleListParams) (*A
|
||||
countArgs = append(countArgs, *params.PublishStatus)
|
||||
argIdx++
|
||||
}
|
||||
if params.SourceType != nil {
|
||||
if sourceType != nil {
|
||||
countQuery += ` AND a.source_type = $` + strconv.Itoa(argIdx)
|
||||
countArgs = append(countArgs, *params.SourceType)
|
||||
countArgs = append(countArgs, *sourceType)
|
||||
argIdx++
|
||||
}
|
||||
if params.GenerationMode != nil {
|
||||
countQuery += ` AND a.source_type = 'custom_generation' AND COALESCE(NULLIF(gt.input_params_json ->> 'generation_mode', ''), 'instant') = $` + strconv.Itoa(argIdx)
|
||||
countArgs = append(countArgs, *params.GenerationMode)
|
||||
argIdx++
|
||||
}
|
||||
if params.TemplateID != nil {
|
||||
@@ -162,9 +170,14 @@ func (s *ArticleService) List(ctx context.Context, params ArticleListParams) (*A
|
||||
listArgs = append(listArgs, *params.PublishStatus)
|
||||
listIdx++
|
||||
}
|
||||
if params.SourceType != nil {
|
||||
if sourceType != nil {
|
||||
listQuery += ` AND a.source_type = $` + strconv.Itoa(listIdx)
|
||||
listArgs = append(listArgs, *params.SourceType)
|
||||
listArgs = append(listArgs, *sourceType)
|
||||
listIdx++
|
||||
}
|
||||
if params.GenerationMode != nil {
|
||||
listQuery += ` AND a.source_type = 'custom_generation' AND COALESCE(NULLIF(gt.input_params_json ->> 'generation_mode', ''), 'instant') = $` + strconv.Itoa(listIdx)
|
||||
listArgs = append(listArgs, *params.GenerationMode)
|
||||
listIdx++
|
||||
}
|
||||
if params.TemplateID != nil {
|
||||
@@ -205,13 +218,16 @@ func (s *ArticleService) List(ctx context.Context, params ArticleListParams) (*A
|
||||
var items []ArticleListItem
|
||||
for rows.Next() {
|
||||
var item ArticleListItem
|
||||
var dbSourceType string
|
||||
var markdownContent *string
|
||||
var wizardStateJSON []byte
|
||||
var inputParamsJSON []byte
|
||||
if err := rows.Scan(&item.ID, &item.SourceType, &item.TemplateID, &item.PromptRuleID, &item.GenerateStatus, &item.PublishStatus, &item.CreatedAt,
|
||||
if err := rows.Scan(&item.ID, &dbSourceType, &item.TemplateID, &item.PromptRuleID, &item.GenerateStatus, &item.PublishStatus, &item.CreatedAt,
|
||||
&item.Title, &item.GenerationErrorMessage, &markdownContent, &item.WordCount, &item.SourceLabel, &item.TemplateName, &item.PromptRuleName, &wizardStateJSON, &inputParamsJSON); err != nil {
|
||||
return nil, response.ErrInternal(50010, "scan_failed", err.Error())
|
||||
}
|
||||
item.SourceType = dbSourceType
|
||||
item.GenerationMode = resolveArticleGenerationMode(dbSourceType, inputParamsJSON)
|
||||
item.Platforms = resolveArticlePlatforms(wizardStateJSON, inputParamsJSON)
|
||||
item.WordCount = resolveWordCount(markdownContent, item.WordCount)
|
||||
items = append(items, item)
|
||||
@@ -228,6 +244,7 @@ type ArticleDetailResponse struct {
|
||||
SourceType string `json:"source_type"`
|
||||
TemplateID *int64 `json:"template_id"`
|
||||
TemplateName *string `json:"template_name"`
|
||||
GenerationMode *string `json:"generation_mode"`
|
||||
Platforms []string `json:"platforms"`
|
||||
GenerateStatus string `json:"generate_status"`
|
||||
PublishStatus string `json:"publish_status"`
|
||||
@@ -245,6 +262,7 @@ type ArticleDetailResponse struct {
|
||||
func (s *ArticleService) Detail(ctx context.Context, id int64) (*ArticleDetailResponse, error) {
|
||||
actor := auth.MustActor(ctx)
|
||||
var d ArticleDetailResponse
|
||||
var dbSourceType string
|
||||
|
||||
var wizardStateJSON []byte
|
||||
var inputParamsJSON []byte
|
||||
@@ -263,15 +281,17 @@ func (s *ArticleService) Detail(ctx context.Context, id int64) (*ArticleDetailRe
|
||||
LIMIT 1
|
||||
) gt ON true
|
||||
WHERE a.id = $1 AND a.tenant_id = $2 AND a.deleted_at IS NULL
|
||||
`, id, actor.TenantID).Scan(&d.ID, &d.SourceType, &d.TemplateID, &d.GenerateStatus, &d.PublishStatus, &d.CreatedAt,
|
||||
`, id, actor.TenantID).Scan(&d.ID, &dbSourceType, &d.TemplateID, &d.GenerateStatus, &d.PublishStatus, &d.CreatedAt,
|
||||
&d.Title, &d.HTMLContent, &d.MarkdownContent, &d.WordCount, &d.SourceLabel, &d.VersionNo, &d.TemplateName, &d.GenerationErrorMessage, &wizardStateJSON, &inputParamsJSON)
|
||||
if err != nil {
|
||||
return nil, response.ErrNotFound(40411, "article_not_found", "article not found")
|
||||
}
|
||||
d.SourceType = dbSourceType
|
||||
if len(wizardStateJSON) > 0 {
|
||||
d.WizardState = map[string]interface{}{}
|
||||
_ = json.Unmarshal(wizardStateJSON, &d.WizardState)
|
||||
}
|
||||
d.GenerationMode = resolveArticleGenerationMode(dbSourceType, inputParamsJSON)
|
||||
d.Platforms = resolveArticlePlatforms(wizardStateJSON, inputParamsJSON)
|
||||
d.WordCount = resolveWordCount(d.MarkdownContent, d.WordCount)
|
||||
return &d, nil
|
||||
@@ -455,6 +475,24 @@ func resolveWordCount(markdown *string, stored int) int {
|
||||
return stored
|
||||
}
|
||||
|
||||
func resolveArticleGenerationMode(sourceType string, inputParamsJSON []byte) *string {
|
||||
if sourceType != "custom_generation" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(inputParamsJSON) > 0 {
|
||||
var payload map[string]interface{}
|
||||
if err := json.Unmarshal(inputParamsJSON, &payload); err == nil {
|
||||
if mode := strings.TrimSpace(extractString(payload, "generation_mode")); mode != "" {
|
||||
return &mode
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mode := "instant"
|
||||
return &mode
|
||||
}
|
||||
|
||||
func nilIfEmptyString(value string) *string {
|
||||
value = strings.TrimSpace(value)
|
||||
if value == "" {
|
||||
|
||||
@@ -429,46 +429,6 @@ func (s *BrandService) DeleteQuestion(ctx context.Context, brandID, questionID i
|
||||
return nil
|
||||
}
|
||||
|
||||
type QuestionVersionResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
QuestionID int64 `json:"question_id"`
|
||||
QuestionText string `json:"question_text"`
|
||||
QuestionHash string `json:"question_hash"`
|
||||
VersionNo int `json:"version_no"`
|
||||
IsActive bool `json:"is_active"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
func (s *BrandService) ListQuestionVersions(ctx context.Context, brandID int64) ([]QuestionVersionResponse, error) {
|
||||
actor := auth.MustActor(ctx)
|
||||
rows, err := s.pool.Query(ctx, `
|
||||
SELECT v.id, v.question_id, v.question_text, v.question_hash, v.version_no, v.is_active, v.created_at
|
||||
FROM brand_question_versions v
|
||||
JOIN brand_questions q ON q.id = v.question_id
|
||||
WHERE q.brand_id = $1 AND q.tenant_id = $2
|
||||
ORDER BY v.created_at DESC
|
||||
`, brandID, actor.TenantID)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50010, "query_failed", "failed to list question versions")
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var versions []QuestionVersionResponse
|
||||
for rows.Next() {
|
||||
var v QuestionVersionResponse
|
||||
var ca interface{}
|
||||
if err := rows.Scan(&v.ID, &v.QuestionID, &v.QuestionText, &v.QuestionHash, &v.VersionNo, &v.IsActive, &ca); err != nil {
|
||||
return nil, response.ErrInternal(50010, "scan_failed", err.Error())
|
||||
}
|
||||
v.CreatedAt = fmt.Sprintf("%v", ca)
|
||||
versions = append(versions, v)
|
||||
}
|
||||
if versions == nil {
|
||||
versions = []QuestionVersionResponse{}
|
||||
}
|
||||
return versions, nil
|
||||
}
|
||||
|
||||
// --- Competitor CRUD ---
|
||||
|
||||
type CompetitorRequest struct {
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/shared/auth"
|
||||
"github.com/geo-platform/tenant-api/internal/shared/response"
|
||||
)
|
||||
|
||||
type InstantTaskService struct {
|
||||
pool *pgxpool.Pool
|
||||
}
|
||||
|
||||
func NewInstantTaskService(pool *pgxpool.Pool) *InstantTaskService {
|
||||
return &InstantTaskService{pool: pool}
|
||||
}
|
||||
|
||||
type InstantTaskListParams struct {
|
||||
PromptRuleID *int64
|
||||
Status *string
|
||||
Keyword *string
|
||||
CreatedFrom *time.Time
|
||||
CreatedTo *time.Time
|
||||
Page int
|
||||
PageSize int
|
||||
}
|
||||
|
||||
type InstantTaskResponse struct {
|
||||
ID int64 `json:"id"`
|
||||
ArticleID *int64 `json:"article_id"`
|
||||
PromptRuleID *int64 `json:"prompt_rule_id"`
|
||||
PromptRuleName *string `json:"prompt_rule_name"`
|
||||
Name string `json:"name"`
|
||||
Status string `json:"status"`
|
||||
ExecutionTime *string `json:"execution_time"`
|
||||
Platforms []string `json:"platforms"`
|
||||
GenerateCount int `json:"generate_count"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
}
|
||||
|
||||
type InstantTaskListResponse struct {
|
||||
Items []InstantTaskResponse `json:"items"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
func (s *InstantTaskService) List(ctx context.Context, params InstantTaskListParams) (*InstantTaskListResponse, error) {
|
||||
actor := auth.MustActor(ctx)
|
||||
if params.Page < 1 {
|
||||
params.Page = 1
|
||||
}
|
||||
if params.PageSize < 1 || params.PageSize > 100 {
|
||||
params.PageSize = 20
|
||||
}
|
||||
offset := (params.Page - 1) * params.PageSize
|
||||
|
||||
var total int64
|
||||
err := s.pool.QueryRow(ctx, `
|
||||
SELECT COUNT(*)
|
||||
FROM generation_tasks gt
|
||||
LEFT JOIN articles a ON a.id = gt.article_id
|
||||
LEFT JOIN prompt_rules pr ON pr.id = COALESCE(a.prompt_rule_id, NULLIF(gt.input_params_json ->> 'prompt_rule_id', '')::bigint)
|
||||
WHERE gt.tenant_id = $1
|
||||
AND gt.task_type = 'custom_generation'
|
||||
AND ($2::bigint IS NULL OR pr.id = $2)
|
||||
AND ($3::text IS NULL OR gt.status = $3)
|
||||
AND ($4::text IS NULL OR COALESCE(NULLIF(gt.input_params_json ->> 'task_name', ''), pr.name, '') ILIKE '%' || $4 || '%')
|
||||
AND ($5::timestamptz IS NULL OR gt.created_at >= $5)
|
||||
AND ($6::timestamptz IS NULL OR gt.created_at <= $6)
|
||||
`, actor.TenantID, params.PromptRuleID, params.Status, params.Keyword, params.CreatedFrom, params.CreatedTo).Scan(&total)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50010, "count_failed", "failed to count instant tasks")
|
||||
}
|
||||
|
||||
rows, err := s.pool.Query(ctx, `
|
||||
SELECT gt.id, gt.article_id, pr.id, pr.name,
|
||||
COALESCE(NULLIF(gt.input_params_json ->> 'task_name', ''), pr.name, '即时任务') AS task_name,
|
||||
gt.status,
|
||||
COALESCE(gt.started_at, gt.completed_at, gt.created_at) AS execution_time,
|
||||
gt.input_params_json,
|
||||
gt.created_at
|
||||
FROM generation_tasks gt
|
||||
LEFT JOIN articles a ON a.id = gt.article_id
|
||||
LEFT JOIN prompt_rules pr ON pr.id = COALESCE(a.prompt_rule_id, NULLIF(gt.input_params_json ->> 'prompt_rule_id', '')::bigint)
|
||||
WHERE gt.tenant_id = $1
|
||||
AND gt.task_type = 'custom_generation'
|
||||
AND ($2::bigint IS NULL OR pr.id = $2)
|
||||
AND ($3::text IS NULL OR gt.status = $3)
|
||||
AND ($4::text IS NULL OR COALESCE(NULLIF(gt.input_params_json ->> 'task_name', ''), pr.name, '') ILIKE '%' || $4 || '%')
|
||||
AND ($5::timestamptz IS NULL OR gt.created_at >= $5)
|
||||
AND ($6::timestamptz IS NULL OR gt.created_at <= $6)
|
||||
ORDER BY gt.created_at DESC
|
||||
LIMIT $7 OFFSET $8
|
||||
`, actor.TenantID, params.PromptRuleID, params.Status, params.Keyword, params.CreatedFrom, params.CreatedTo, params.PageSize, offset)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50010, "query_failed", "failed to list instant tasks")
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
items := make([]InstantTaskResponse, 0)
|
||||
for rows.Next() {
|
||||
var item InstantTaskResponse
|
||||
var executionAt interface{}
|
||||
var createdAt interface{}
|
||||
var inputParamsJSON []byte
|
||||
if err := rows.Scan(
|
||||
&item.ID,
|
||||
&item.ArticleID,
|
||||
&item.PromptRuleID,
|
||||
&item.PromptRuleName,
|
||||
&item.Name,
|
||||
&item.Status,
|
||||
&executionAt,
|
||||
&inputParamsJSON,
|
||||
&createdAt,
|
||||
); err != nil {
|
||||
return nil, response.ErrInternal(50010, "scan_failed", err.Error())
|
||||
}
|
||||
|
||||
item.ExecutionTime = stringPtrFromDBValue(executionAt)
|
||||
item.CreatedAt = fmt.Sprintf("%v", createdAt)
|
||||
item.Platforms = resolveArticlePlatforms(nil, inputParamsJSON)
|
||||
item.GenerateCount = 1
|
||||
|
||||
if len(inputParamsJSON) > 0 {
|
||||
payload, err := parseJSONMap(inputParamsJSON)
|
||||
if err == nil {
|
||||
if count := extractInt(payload, "generate_count"); count > 0 {
|
||||
item.GenerateCount = count
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
items = append(items, item)
|
||||
}
|
||||
|
||||
return &InstantTaskListResponse{
|
||||
Items: items,
|
||||
Total: total,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func stringPtrFromDBValue(value interface{}) *string {
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
text := fmt.Sprintf("%v", value)
|
||||
return &text
|
||||
}
|
||||
|
||||
func parseJSONMap(raw []byte) (map[string]interface{}, error) {
|
||||
if len(raw) == 0 {
|
||||
return map[string]interface{}{}, nil
|
||||
}
|
||||
|
||||
payload := make(map[string]interface{})
|
||||
if err := json.Unmarshal(raw, &payload); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return payload, nil
|
||||
}
|
||||
@@ -62,6 +62,8 @@ type promptRuleGenerationRecord struct {
|
||||
Status string
|
||||
}
|
||||
|
||||
const promptRuleGeneratingTitlePlaceholder = "标题生成中"
|
||||
|
||||
func NewPromptRuleGenerationService(
|
||||
pool *pgxpool.Pool,
|
||||
llmClient llm.Client,
|
||||
@@ -121,12 +123,12 @@ func (s *PromptRuleGenerationService) GenerateFromRule(ctx context.Context, req
|
||||
return nil, response.ErrBadRequest(40018, "generate_count_not_supported", "prompt rule instant generation currently supports generate_count = 1 only")
|
||||
}
|
||||
|
||||
initialTitle := strings.TrimSpace(extractString(extra, "task_name"))
|
||||
if initialTitle == "" {
|
||||
initialTitle = strings.TrimSpace(rule.Name)
|
||||
taskName := strings.TrimSpace(extractString(extra, "task_name"))
|
||||
if taskName == "" {
|
||||
taskName = strings.TrimSpace(rule.Name)
|
||||
}
|
||||
if initialTitle == "" {
|
||||
initialTitle = "Generated Article"
|
||||
if taskName == "" {
|
||||
taskName = "即时任务"
|
||||
}
|
||||
|
||||
quotaRepo := repository.NewQuotaRepository(s.pool)
|
||||
@@ -136,11 +138,14 @@ func (s *PromptRuleGenerationService) GenerateFromRule(ctx context.Context, req
|
||||
}
|
||||
|
||||
inputParams := map[string]interface{}{
|
||||
"title": initialTitle,
|
||||
"prompt_rule_id": req.PromptRuleID,
|
||||
"task_name": taskName,
|
||||
"target_platform": strings.TrimSpace(derefString(req.TargetPlatform)),
|
||||
"enable_web_search": extractBool(extra, "enable_web_search"),
|
||||
}
|
||||
if generationMode := strings.TrimSpace(extractString(extra, "generation_mode")); generationMode != "" {
|
||||
inputParams["generation_mode"] = generationMode
|
||||
}
|
||||
platformIDs := parsePlatformIDs(derefString(req.TargetPlatform))
|
||||
if len(platformIDs) > 0 {
|
||||
inputParams["target_platforms"] = platformIDs
|
||||
@@ -150,7 +155,7 @@ func (s *PromptRuleGenerationService) GenerateFromRule(ctx context.Context, req
|
||||
}
|
||||
|
||||
inputJSON, _ := json.Marshal(inputParams)
|
||||
wizardStateJSON, _ := mergeArticleWizardState(nil, initialTitle, platformIDs)
|
||||
wizardStateJSON, _ := mergeArticleWizardState(nil, promptRuleGeneratingTitlePlaceholder, platformIDs)
|
||||
|
||||
tx, err := s.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
@@ -195,7 +200,7 @@ func (s *PromptRuleGenerationService) GenerateFromRule(ctx context.Context, req
|
||||
var articleID int64
|
||||
err = tx.QueryRow(ctx, `
|
||||
INSERT INTO articles (tenant_id, source_type, prompt_rule_id, generate_status, publish_status, wizard_state_json)
|
||||
VALUES ($1, 'prompt_rule', $2, 'generating', 'unpublished', $3)
|
||||
VALUES ($1, 'custom_generation', $2, 'generating', 'unpublished', $3)
|
||||
RETURNING id
|
||||
`, actor.TenantID, req.PromptRuleID, wizardStateJSON).Scan(&articleID)
|
||||
if err != nil {
|
||||
@@ -211,7 +216,7 @@ func (s *PromptRuleGenerationService) GenerateFromRule(ctx context.Context, req
|
||||
TenantID: actor.TenantID,
|
||||
ArticleID: &articleID,
|
||||
QuotaReservationID: &reservationID,
|
||||
TaskType: "prompt_rule",
|
||||
TaskType: "custom_generation",
|
||||
InputParamsJSON: inputJSON,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -230,7 +235,7 @@ func (s *PromptRuleGenerationService) GenerateFromRule(ctx context.Context, req
|
||||
ReservationID: reservationID,
|
||||
Prompt: buildPromptRuleGenerationPrompt(rule, inputParams),
|
||||
InputParams: inputParams,
|
||||
InitialTitle: initialTitle,
|
||||
InitialTitle: promptRuleGeneratingTitlePlaceholder,
|
||||
WebSearch: llm.WebSearchOptions{
|
||||
Enabled: extractBool(extra, "enable_web_search"),
|
||||
},
|
||||
@@ -242,7 +247,7 @@ func (s *PromptRuleGenerationService) GenerateFromRule(ctx context.Context, req
|
||||
}
|
||||
|
||||
if s.streamEnabled {
|
||||
s.streams.Start(articleID, taskID, initialTitle)
|
||||
s.streams.Start(articleID, taskID, promptRuleGeneratingTitlePlaceholder)
|
||||
}
|
||||
|
||||
return &GenerateFromRuleResponse{ArticleID: articleID, TaskID: taskID}, nil
|
||||
@@ -392,6 +397,10 @@ func (s *PromptRuleGenerationService) executeGeneration(ctx context.Context, job
|
||||
func (s *PromptRuleGenerationService) failGeneration(ctx context.Context, job promptRuleGenerationJob, title, stage string, genErr error) {
|
||||
errMsg := formatGenerationFailure(stage, genErr)
|
||||
now := time.Now()
|
||||
failureTitle := strings.TrimSpace(extractString(job.InputParams, "task_name"))
|
||||
if failureTitle == "" {
|
||||
failureTitle = title
|
||||
}
|
||||
|
||||
auditRepo := repository.NewAuditRepository(s.pool)
|
||||
articleRepo := repository.NewArticleRepository(s.pool)
|
||||
@@ -405,6 +414,14 @@ func (s *PromptRuleGenerationService) failGeneration(ctx context.Context, job pr
|
||||
CompletedAt: &now,
|
||||
})
|
||||
_ = articleRepo.UpdateArticleGenerateStatus(ctx, job.ArticleID, job.TenantID, "failed")
|
||||
if failureTitle != "" {
|
||||
_, _ = s.pool.Exec(ctx, `
|
||||
UPDATE articles
|
||||
SET wizard_state_json = jsonb_set(COALESCE(wizard_state_json, '{}'::jsonb), '{title}', to_jsonb($1::text), true),
|
||||
updated_at = NOW()
|
||||
WHERE id = $2 AND tenant_id = $3
|
||||
`, failureTitle, job.ArticleID, job.TenantID)
|
||||
}
|
||||
|
||||
balance, balanceErr := quotaRepo.GetCurrentBalance(ctx, job.TenantID, "article_generation")
|
||||
if balanceErr == nil {
|
||||
@@ -426,7 +443,7 @@ func (s *PromptRuleGenerationService) failGeneration(ctx context.Context, job pr
|
||||
_ = quotaRepo.RefundReservation(ctx, job.ReservationID, job.TenantID)
|
||||
|
||||
if s.streamEnabled {
|
||||
s.streams.Fail(job.ArticleID, job.TaskID, title, errMsg)
|
||||
s.streams.Fail(job.ArticleID, job.TaskID, failureTitle, errMsg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,8 +451,8 @@ func buildPromptRuleGenerationPrompt(rule *promptRuleGenerationRecord, params ma
|
||||
sections := []string{strings.TrimSpace(rule.PromptContent)}
|
||||
|
||||
var supplements []string
|
||||
if title := strings.TrimSpace(extractString(params, "title")); title != "" {
|
||||
supplements = append(supplements, "任务名称:"+title)
|
||||
if taskName := strings.TrimSpace(extractString(params, "task_name")); taskName != "" {
|
||||
supplements = append(supplements, "任务名称:"+taskName)
|
||||
}
|
||||
if rule.Scene != nil && strings.TrimSpace(*rule.Scene) != "" {
|
||||
supplements = append(supplements, "适用场景:"+strings.TrimSpace(*rule.Scene))
|
||||
@@ -454,7 +471,7 @@ func buildPromptRuleGenerationPrompt(rule *promptRuleGenerationRecord, params ma
|
||||
sections = append(sections, "补充要求:\n- "+strings.Join(supplements, "\n- "))
|
||||
}
|
||||
|
||||
sections = append(sections, "输出要求:\n1. 直接输出完整可发布的中文 Markdown 文章。\n2. 标题使用一级标题。\n3. 不要输出你的思考过程、解释或致歉。")
|
||||
sections = append(sections, "输出要求:\n1. 直接输出完整可发布的中文 Markdown 文章。\n2. 标题使用一级标题,并由 AI 根据正文内容自行生成,不要直接复用任务名称。\n3. 不要输出你的思考过程、解释或致歉。")
|
||||
return strings.Join(sections, "\n\n")
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
@@ -52,8 +53,11 @@ type ScheduleTaskResponse struct {
|
||||
type ScheduleTaskListParams struct {
|
||||
PromptRuleID *int64 `json:"prompt_rule_id"`
|
||||
Status *string `json:"status"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
Keyword *string `json:"keyword"`
|
||||
CreatedFrom *time.Time
|
||||
CreatedTo *time.Time
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
|
||||
type ScheduleTaskListResponse struct {
|
||||
@@ -81,7 +85,10 @@ func (s *ScheduleTaskService) List(ctx context.Context, params ScheduleTaskListP
|
||||
WHERE tenant_id = $1 AND deleted_at IS NULL
|
||||
AND ($2::bigint IS NULL OR prompt_rule_id = $2)
|
||||
AND ($3::text IS NULL OR status = $3)
|
||||
`, actor.TenantID, params.PromptRuleID, params.Status).Scan(&total)
|
||||
AND ($4::text IS NULL OR name ILIKE '%' || $4 || '%')
|
||||
AND ($5::timestamptz IS NULL OR created_at >= $5)
|
||||
AND ($6::timestamptz IS NULL OR created_at <= $6)
|
||||
`, actor.TenantID, params.PromptRuleID, params.Status, params.Keyword, params.CreatedFrom, params.CreatedTo).Scan(&total)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50010, "count_failed", "failed to count schedule tasks")
|
||||
}
|
||||
@@ -98,9 +105,12 @@ func (s *ScheduleTaskService) List(ctx context.Context, params ScheduleTaskListP
|
||||
WHERE st.tenant_id = $1 AND st.deleted_at IS NULL
|
||||
AND ($2::bigint IS NULL OR st.prompt_rule_id = $2)
|
||||
AND ($3::text IS NULL OR st.status = $3)
|
||||
AND ($4::text IS NULL OR st.name ILIKE '%' || $4 || '%')
|
||||
AND ($5::timestamptz IS NULL OR st.created_at >= $5)
|
||||
AND ($6::timestamptz IS NULL OR st.created_at <= $6)
|
||||
ORDER BY st.created_at DESC
|
||||
LIMIT $4 OFFSET $5
|
||||
`, actor.TenantID, params.PromptRuleID, params.Status, params.PageSize, offset)
|
||||
LIMIT $7 OFFSET $8
|
||||
`, actor.TenantID, params.PromptRuleID, params.Status, params.Keyword, params.CreatedFrom, params.CreatedTo, params.PageSize, offset)
|
||||
if err != nil {
|
||||
return nil, response.ErrInternal(50010, "query_failed", "failed to list schedule tasks")
|
||||
}
|
||||
|
||||
@@ -345,47 +345,6 @@ func (q *Queries) ListKeywords(ctx context.Context, arg ListKeywordsParams) ([]L
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listQuestionVersions = `-- name: ListQuestionVersions :many
|
||||
SELECT v.id, v.question_id, v.question_text, v.question_hash, v.version_no, v.is_active, v.created_at
|
||||
FROM brand_question_versions v
|
||||
JOIN brand_questions q ON q.id = v.question_id
|
||||
WHERE q.brand_id = $1 AND q.tenant_id = $2
|
||||
ORDER BY v.created_at DESC
|
||||
`
|
||||
|
||||
type ListQuestionVersionsParams struct {
|
||||
BrandID int64 `json:"brand_id"`
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
}
|
||||
|
||||
func (q *Queries) ListQuestionVersions(ctx context.Context, arg ListQuestionVersionsParams) ([]BrandQuestionVersion, error) {
|
||||
rows, err := q.db.Query(ctx, listQuestionVersions, arg.BrandID, arg.TenantID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var items []BrandQuestionVersion
|
||||
for rows.Next() {
|
||||
var i BrandQuestionVersion
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.QuestionID,
|
||||
&i.QuestionText,
|
||||
&i.QuestionHash,
|
||||
&i.VersionNo,
|
||||
&i.IsActive,
|
||||
&i.CreatedAt,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, i)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listQuestions = `-- name: ListQuestions :many
|
||||
SELECT q.id, q.tenant_id, q.brand_id, q.keyword_id, q.current_version_id, q.status, q.created_at,
|
||||
v.question_text, v.version_no
|
||||
|
||||
@@ -79,6 +79,7 @@ type Brand struct {
|
||||
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
||||
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
||||
DeletedAt pgtype.Timestamptz `json:"deleted_at"`
|
||||
Website pgtype.Text `json:"website"`
|
||||
}
|
||||
|
||||
type BrandKeyword struct {
|
||||
|
||||
@@ -61,7 +61,6 @@ type Querier interface {
|
||||
// ============================================================
|
||||
ListPromptRules(ctx context.Context, arg ListPromptRulesParams) ([]ListPromptRulesRow, error)
|
||||
ListPromptRulesUngrouped(ctx context.Context, arg ListPromptRulesUngroupedParams) ([]ListPromptRulesUngroupedRow, error)
|
||||
ListQuestionVersions(ctx context.Context, arg ListQuestionVersionsParams) ([]BrandQuestionVersion, error)
|
||||
ListQuestions(ctx context.Context, arg ListQuestionsParams) ([]ListQuestionsRow, error)
|
||||
ListScheduleTasks(ctx context.Context, arg ListScheduleTasksParams) ([]ListScheduleTasksRow, error)
|
||||
ListTemplates(ctx context.Context, tenantID int64) ([]ListTemplatesRow, error)
|
||||
|
||||
@@ -85,13 +85,6 @@ WHERE id = sqlc.arg(id) AND brand_id = sqlc.arg(brand_id) AND tenant_id = sqlc.a
|
||||
UPDATE brand_questions SET deleted_at = NOW(), updated_at = NOW()
|
||||
WHERE brand_id = sqlc.arg(brand_id) AND tenant_id = sqlc.arg(tenant_id) AND deleted_at IS NULL;
|
||||
|
||||
-- name: ListQuestionVersions :many
|
||||
SELECT v.id, v.question_id, v.question_text, v.question_hash, v.version_no, v.is_active, v.created_at
|
||||
FROM brand_question_versions v
|
||||
JOIN brand_questions q ON q.id = v.question_id
|
||||
WHERE q.brand_id = sqlc.arg(brand_id) AND q.tenant_id = sqlc.arg(tenant_id)
|
||||
ORDER BY v.created_at DESC;
|
||||
|
||||
-- name: ListCompetitors :many
|
||||
SELECT id, tenant_id, brand_id, name, website, description, product_lines_json, created_at, updated_at
|
||||
FROM competitors
|
||||
|
||||
@@ -50,6 +50,9 @@ func (h *ArticleHandler) List(c *gin.Context) {
|
||||
if v := c.Query("source_type"); v != "" {
|
||||
params.SourceType = &v
|
||||
}
|
||||
if v := c.Query("generation_mode"); v != "" {
|
||||
params.GenerationMode = &v
|
||||
}
|
||||
if v := c.Query("template_id"); v != "" {
|
||||
if id, err := strconv.ParseInt(v, 10, 64); err == nil {
|
||||
params.TemplateID = &id
|
||||
|
||||
@@ -202,16 +202,6 @@ func (h *BrandHandler) DeleteQuestion(c *gin.Context) {
|
||||
response.Success(c, nil)
|
||||
}
|
||||
|
||||
func (h *BrandHandler) ListQuestionVersions(c *gin.Context) {
|
||||
brandID, _ := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
data, err := h.svc.ListQuestionVersions(c.Request.Context(), brandID)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
|
||||
// Competitors
|
||||
func (h *BrandHandler) ListCompetitors(c *gin.Context) {
|
||||
brandID, _ := strconv.ParseInt(c.Param("id"), 10, 64)
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/geo-platform/tenant-api/internal/bootstrap"
|
||||
"github.com/geo-platform/tenant-api/internal/shared/response"
|
||||
"github.com/geo-platform/tenant-api/internal/tenant/app"
|
||||
)
|
||||
|
||||
type InstantTaskHandler struct {
|
||||
svc *app.InstantTaskService
|
||||
}
|
||||
|
||||
func NewInstantTaskHandler(a *bootstrap.App) *InstantTaskHandler {
|
||||
return &InstantTaskHandler{svc: app.NewInstantTaskService(a.DB)}
|
||||
}
|
||||
|
||||
func (h *InstantTaskHandler) List(c *gin.Context) {
|
||||
params := app.InstantTaskListParams{
|
||||
Page: 1,
|
||||
PageSize: 20,
|
||||
}
|
||||
if v := c.Query("page"); v != "" {
|
||||
if p, err := strconv.Atoi(v); err == nil {
|
||||
params.Page = p
|
||||
}
|
||||
}
|
||||
if v := c.Query("page_size"); v != "" {
|
||||
if ps, err := strconv.Atoi(v); err == nil {
|
||||
params.PageSize = ps
|
||||
}
|
||||
}
|
||||
if v := c.Query("prompt_rule_id"); v != "" {
|
||||
if rid, err := strconv.ParseInt(v, 10, 64); err == nil {
|
||||
params.PromptRuleID = &rid
|
||||
}
|
||||
}
|
||||
if v := c.Query("status"); v != "" {
|
||||
params.Status = &v
|
||||
}
|
||||
if v := c.Query("keyword"); v != "" {
|
||||
params.Keyword = &v
|
||||
}
|
||||
if v := c.Query("created_from"); v != "" {
|
||||
parsed, err := time.Parse(time.RFC3339, v)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40014, "invalid_created_from", "created_from must be RFC3339"))
|
||||
return
|
||||
}
|
||||
params.CreatedFrom = &parsed
|
||||
}
|
||||
if v := c.Query("created_to"); v != "" {
|
||||
parsed, err := time.Parse(time.RFC3339, v)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40015, "invalid_created_to", "created_to must be RFC3339"))
|
||||
return
|
||||
}
|
||||
params.CreatedTo = &parsed
|
||||
}
|
||||
|
||||
data, err := h.svc.List(c.Request.Context(), params)
|
||||
if err != nil {
|
||||
response.Error(c, err)
|
||||
return
|
||||
}
|
||||
response.Success(c, data)
|
||||
}
|
||||
@@ -64,7 +64,6 @@ func RegisterRoutes(app *bootstrap.App) {
|
||||
brands.POST("/:id/questions", brandHandler.CreateQuestion)
|
||||
brands.PUT("/:id/questions/:qid", brandHandler.UpdateQuestion)
|
||||
brands.DELETE("/:id/questions/:qid", brandHandler.DeleteQuestion)
|
||||
brands.GET("/:id/question-versions", brandHandler.ListQuestionVersions)
|
||||
brands.GET("/:id/competitors", brandHandler.ListCompetitors)
|
||||
brands.POST("/:id/competitors", brandHandler.CreateCompetitor)
|
||||
brands.PUT("/:id/competitors/:cid", brandHandler.UpdateCompetitor)
|
||||
@@ -95,4 +94,8 @@ func RegisterRoutes(app *bootstrap.App) {
|
||||
schedules.PUT("/:id", schHandler.Update)
|
||||
schedules.DELETE("/:id", schHandler.Delete)
|
||||
schedules.PUT("/:id/status", schHandler.ToggleStatus)
|
||||
|
||||
instantTasks := protected.Group("/tenant/instant-tasks")
|
||||
instHandler := NewInstantTaskHandler(app)
|
||||
instantTasks.GET("", instHandler.List)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package transport
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@@ -41,6 +42,25 @@ func (h *ScheduleTaskHandler) List(c *gin.Context) {
|
||||
if v := c.Query("status"); v != "" {
|
||||
params.Status = &v
|
||||
}
|
||||
if v := c.Query("keyword"); v != "" {
|
||||
params.Keyword = &v
|
||||
}
|
||||
if v := c.Query("created_from"); v != "" {
|
||||
parsed, err := time.Parse(time.RFC3339, v)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40014, "invalid_created_from", "created_from must be RFC3339"))
|
||||
return
|
||||
}
|
||||
params.CreatedFrom = &parsed
|
||||
}
|
||||
if v := c.Query("created_to"); v != "" {
|
||||
parsed, err := time.Parse(time.RFC3339, v)
|
||||
if err != nil {
|
||||
response.Error(c, response.ErrBadRequest(40015, "invalid_created_to", "created_to must be RFC3339"))
|
||||
return
|
||||
}
|
||||
params.CreatedTo = &parsed
|
||||
}
|
||||
|
||||
data, err := h.svc.List(c.Request.Context(), params)
|
||||
if err != nil {
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
UPDATE articles
|
||||
SET source_type = 'prompt_rule'
|
||||
WHERE source_type = 'custom_generation';
|
||||
|
||||
UPDATE generation_tasks
|
||||
SET task_type = 'prompt_rule'
|
||||
WHERE task_type = 'custom_generation';
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
UPDATE articles
|
||||
SET source_type = 'custom_generation'
|
||||
WHERE source_type = 'prompt_rule';
|
||||
|
||||
UPDATE generation_tasks
|
||||
SET task_type = 'custom_generation'
|
||||
WHERE task_type = 'prompt_rule';
|
||||
Reference in New Issue
Block a user