Merge commit 'dc8c288f' — lps-admin 신설·LPS 운영기능(ip_session/alerts/admin API)·최저가 출처링크 반영

This commit is contained in:
minaChoi committed 2026-07-24 15:30:36 +09:00
commit b539e073cb
86 files changed
+7216 -968

No files matched your search

@@ -86,7 +86,9 @@ export * from './listUsersParams';
export * from './lowestPriceEntry';
export * from './lowestPriceEntryCrawlEndTime';
export * from './lowestPriceEntryFailReason';
export * from './lowestPriceEntryLpName';
export * from './lowestPriceEntryLpPrice';
export * from './lowestPriceEntryLpUrl';
export * from './notificationData';
export * from './notificationDataCreatedAt';
export * from './notificationDataData';
@@ -6,6 +6,8 @@
*/
import type { LowestPriceEntryLpPrice } from './lowestPriceEntryLpPrice';
import type { LowestPriceEntryFailReason } from './lowestPriceEntryFailReason';
import type { LowestPriceEntryLpName } from './lowestPriceEntryLpName';
import type { LowestPriceEntryLpUrl } from './lowestPriceEntryLpUrl';
import type { LowestPriceEntryCrawlEndTime } from './lowestPriceEntryCrawlEndTime';
/**
@@ -16,5 +18,7 @@ export interface LowestPriceEntry {
website?: number;
success_yn?: boolean;
fail_reason?: LowestPriceEntryFailReason;
lp_name?: LowestPriceEntryLpName;
lp_url?: LowestPriceEntryLpUrl;
crawl_end_time?: LowestPriceEntryCrawlEndTime;
}
@@ -0,0 +1,8 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
export type LowestPriceEntryLpName = string | null;
@@ -0,0 +1,8 @@
/**
* Generated by orval v7.21.0 🍺
* Do not edit manually.
* Negodata Api Server
* OpenAPI spec version: 0.1.0
*/
export type LowestPriceEntryLpUrl = string | null;
@@ -0,0 +1,232 @@
import type { ReactNode } from 'react';
import { ChartSpline, ExternalLink, Loader2, TrendingDown, TrendingUp } from 'lucide-react';
import { CartesianGrid, Line, LineChart, XAxis, YAxis } from 'recharts';
import { ChartContainer, ChartTooltip, type ChartConfig } from '@/components/ui/chart';
import { Badge } from '@/components/ui/badge';
import { Card } from '@/components/ui/card';
import { Sheet } from '@/components/ui/sheet';
import { Typography } from '@/components/ui/typography';
import { useGetLowestPrice } from '@/api/generated/item/item';
import type { LowestPriceEntry } from '@/api/generated/model';
import type { Product } from '../types';
type LowestPriceHistorySheetProps = {
product: Product;
onClose: () => void;
};
// LowestPriceWebsite 코드(백엔드 common/enums.py) → 표시 라벨
const WEBSITE_LABEL: Record<number, string> = {
1: '네이버',
2: '쿠팡',
3: 'G마켓',
4: '옥션',
5: '11번가',
99: '기타',
};
const websiteLabel = (code?: number) => WEBSITE_LABEL[code ?? 99] ?? '기타';
// 단일 시리즈(인터넷 최저가) — 가격 UI 컨벤션인 rose 를 라이트/다크 쌍으로(통계 팔레트와 동일 문법).
const chartConfig = {
price: { label: '인터넷 최저가', theme: { light: '#f43f5e', dark: '#fb7185' } },
} satisfies ChartConfig;
const won = (n: number) => `₩${Math.round(n).toLocaleString()}`;
const timeLabel = (iso: string) =>
new Date(iso).toLocaleString('ko-KR', { month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' });
/** 견적 상세 드로어와 같은 문법의 섹션 카드 — 11px 볼드 타이틀 + 하단 구분선. */
function SectionCard({ title, action, children }: { title: string; action?: ReactNode; children: ReactNode }) {
return (
<Card className="p-3 gap-2 rounded shadow-xs border-border/80">
<div className="flex items-center justify-between border-b border-border pb-1">
<span className="font-bold text-foreground text-[11px] font-sans">{title}</span>
{action}
</div>
{children}
</Card>
);
}
// 인터넷 최저가 상세 시트 — 대표값·출처(사이트/상품명/링크)·가격 추이 그래프·수집 이력.
// 협상 근거로 쓰는 값이므로 "어디서 찾았는지"를 클릭 한 번으로 검증할 수 있게 한다.
export function LowestPriceHistorySheet({ product, onClose }: LowestPriceHistorySheetProps) {
// GET 이 서버에서 lps_db 증분 동기화를 겸하므로, 열 때마다 최신 상태가 온다.
const { data, isLoading } = useGetLowestPrice(product.item_id);
const entries = data?.results ?? [];
const successes = entries.filter((e): e is LowestPriceEntry & { lp_price: number } => !!e.success_yn && e.lp_price != null);
const latest = successes[0]; // API 가 최신순으로 준다
const representative = data?.lowest_price ?? product.internet_lowest_price ?? latest?.lp_price ?? null;
const diff = product.price != null && representative != null ? Number(representative) - product.price : null;
// 그래프는 시간 오름차순(성공 수집만). 점 1개는 추이가 아니므로 2건부터 그린다.
const chartData = [...successes]
.reverse()
.map((e) => ({ t: e.crawl_end_time ?? '', price: e.lp_price }));
return (
<Sheet open title="인터넷 최저가 상세" onClose={onClose}>
<div className="space-y-4">
{/* ── 헤드라인: 상품명 · 대표가 · 단가 대비 칩 ── */}
<div className="rounded border border-border/80 bg-muted/25 p-3">
<Typography as="p" variant="caption" className="font-medium">{product.name}</Typography>
<div className="mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1.5">
<span className="font-mono text-[26px] leading-none font-bold text-rose-600 dark:text-rose-400">
{representative != null ? won(Number(representative)) : '수집 전'}
</span>
{diff != null && (
<span
className={`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-[11px] font-medium ${
diff <= 0
? 'bg-emerald-500/10 text-emerald-700 dark:text-emerald-400'
: 'bg-amber-500/10 text-amber-700 dark:text-amber-400'
}`}
>
{diff <= 0 ? <TrendingDown size={12} /> : <TrendingUp size={12} />}
단가 대비 {diff > 0 ? '+' : diff < 0 ? '-' : ''}{won(Math.abs(diff))}
</span>
)}
</div>
<Typography as="p" variant="caption" className="mt-1.5">
상품 단가 {product.price != null ? won(product.price) : '-'}
{latest?.crawl_end_time && <> · 마지막 수집 {timeLabel(latest.crawl_end_time)}</>}
</Typography>
</div>
{/* ── 출처 — 최신 성공 수집의 사이트/상품명/링크 ── */}
{latest && (
<SectionCard
title="최저가 출처"
action={<Badge variant="secondary" className="text-[10px]">{websiteLabel(latest.website)}</Badge>}
>
{latest.lp_name ? (
<Typography as="p" variant="small" className="text-[12.5px] leading-snug">{latest.lp_name}</Typography>
) : (
<Typography as="p" variant="caption">출처 상세 미수집(이전 버전 수집분)</Typography>
)}
{latest.lp_url && (
<a
href={latest.lp_url}
target="_blank"
rel="noopener noreferrer"
className="inline-flex w-fit items-center gap-1.5 rounded border border-border px-2.5 py-1.5 text-[11px] font-medium text-foreground transition-colors hover:border-rose-400/60 hover:bg-rose-500/10 hover:text-rose-600 dark:hover:text-rose-400"
>
판매 페이지에서 확인 <ExternalLink size={11} />
</a>
)}
</SectionCard>
)}
{/* ── 가격 추이 ── */}
<SectionCard
title="가격 추이"
action={
successes.length > 0 ? (
<Typography variant="caption">{successes.length}회 수집</Typography>
) : undefined
}
>
{chartData.length >= 2 ? (
<ChartContainer config={chartConfig} className="aspect-auto h-40 w-full">
<LineChart data={chartData} margin={{ top: 10, right: 12, left: 4, bottom: 0 }}>
<CartesianGrid vertical={false} strokeDasharray="3 3" />
<XAxis dataKey="t" tickLine={false} axisLine={false} tickMargin={8} tickFormatter={timeLabel} fontSize={10} />
<YAxis
tickLine={false}
axisLine={false}
width={52}
domain={['dataMin', 'dataMax']}
tickFormatter={(v) => Number(v).toLocaleString()}
fontSize={10}
/>
<ChartTooltip cursor={{ strokeDasharray: '3 3' }} content={<PriceTooltip />} />
<Line
dataKey="price"
type="monotone"
stroke="var(--color-price)"
strokeWidth={2}
dot={{ r: 3, fill: 'var(--color-price)', strokeWidth: 0 }}
activeDot={{ r: 5 }}
/>
</LineChart>
</ChartContainer>
) : (
<div className="flex items-center gap-2 py-3 text-muted-foreground">
<ChartSpline size={14} className="shrink-0" />
<Typography variant="caption">
{successes.length === 1
? '수집이 2회 이상 쌓이면 가격 추이 그래프가 표시됩니다.'
: '성공한 수집이 쌓이면 가격 추이 그래프가 표시됩니다.'}
</Typography>
</div>
)}
</SectionCard>
{/* ── 수집 이력 ── */}
<SectionCard title="최근 수집 이력">
{isLoading ? (
<div className="flex items-center justify-center gap-2 py-6 text-muted-foreground">
<Loader2 size={14} className="animate-spin" />
<Typography variant="caption">이력을 불러오는 중...</Typography>
</div>
) : entries.length === 0 ? (
<div className="space-y-1 rounded border border-dashed border-border bg-muted/10 py-6 text-center">
<TrendingDown size={18} className="mx-auto text-muted-foreground/60" />
<Typography as="p" variant="caption">
수집 이력이 없습니다 — 상품 목록에서 "최저가 업데이트하기"로 수집을 시작하세요.
</Typography>
</div>
) : (
<ul className="divide-y divide-border/60">
{entries.map((e, i) => (
<li key={i} className="flex items-center justify-between gap-2 py-2 first:pt-0.5 last:pb-0.5">
<div className="flex min-w-0 items-center gap-2">
<Badge variant="secondary" className="w-14 shrink-0 justify-center text-[10px]">
{websiteLabel(e.website)}
</Badge>
<span className="truncate text-[11px] text-muted-foreground">
{e.crawl_end_time ? timeLabel(e.crawl_end_time) : '-'}
</span>
</div>
<div className="flex shrink-0 items-center gap-2.5 font-mono text-[12px]">
{e.success_yn && e.lp_price != null ? (
<span className="font-semibold text-rose-600 dark:text-rose-400">{won(e.lp_price)}</span>
) : (
<span className="text-amber-600 dark:text-amber-400">미발견</span>
)}
{e.lp_url ? (
<a
href={e.lp_url}
target="_blank"
rel="noopener noreferrer"
className="text-muted-foreground transition-colors hover:text-rose-600 dark:hover:text-rose-400"
title="판매 페이지 열기"
>
<ExternalLink size={12} />
</a>
) : (
<span className="w-3" /> /* 링크 없는 행도 가격 우측 정렬 유지 */
)}
</div>
</li>
))}
</ul>
)}
</SectionCard>
</div>
</Sheet>
);
}
// 툴팁 — 시각 + 가격(텍스트 토큰, 시리즈색은 마크에만)
function PriceTooltip({ active, payload }: { active?: boolean; payload?: { payload: { t: string; price: number } }[] }) {
if (!active || !payload?.length) return null;
const p = payload[0].payload;
return (
<div className="rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl">
<Typography as="p" variant="caption" className="mb-0.5 font-medium text-foreground">{timeLabel(p.t)}</Typography>
<Typography as="p" variant="caption" className="font-mono text-foreground">{won(p.price)}</Typography>
</div>
);
}
@@ -1,4 +1,4 @@
import { Image as ImageIcon } from 'lucide-react';
import { ChartSpline, Image as ImageIcon } from 'lucide-react';
import { Badge } from '@/components/ui/badge';
import { DataTable, type Column } from '@/components/ui/data-table';
import { TablePagination } from '@/components/ui/table-pagination';
@@ -10,6 +10,7 @@ type ProductTableProps = {
selectedIds: string[];
onSelectionChange: (ids: string[]) => void;
onRowClick: (prod: Product) => void;
onLowestPriceClick: (prod: Product) => void; // 인터넷 최저가 셀 클릭 → 출처·이력 시트
page: number;
totalPages: number;
totalCount: number;
@@ -24,6 +25,7 @@ export function ProductTable({
selectedIds,
onSelectionChange,
onRowClick,
onLowestPriceClick,
page,
totalPages,
totalCount,
@@ -114,7 +116,24 @@ export function ProductTable({
header: label('item.internet_lowest_price'),
align: 'right',
cellClassName: 'font-mono font-semibold text-rose-600 dark:text-rose-400',
cell: (prod) => (prod.internet_lowest_price != null ? `₩${Number(prod.internet_lowest_price).toLocaleString()}` : '-'),
// 값 + 상세보기 버튼(항상 노출) → 출처(사이트·링크)·가격 추이 시트. 행 클릭과 전파 차단.
cell: (prod) => (
<div className="flex items-center justify-end gap-1.5">
<span>{prod.internet_lowest_price != null ? `₩${Number(prod.internet_lowest_price).toLocaleString()}` : '-'}</span>
<button
type="button"
onClick={(e) => {
e.stopPropagation();
onLowestPriceClick(prod);
}}
className="cursor-pointer shrink-0 rounded border border-border/70 p-1 text-muted-foreground transition-colors hover:border-rose-400/60 hover:bg-rose-500/10 hover:text-rose-600 dark:hover:text-rose-400"
title="출처·가격 추이 상세보기"
aria-label="인터넷 최저가 상세보기"
>
<ChartSpline size={13} />
</button>
</div>
),
},
{
header: label('creator'),
+10 -1
View File
@@ -16,6 +16,7 @@ import type { ListItemsParams } from '@/api/generated/model/listItemsParams';
import { ProductTable } from '@/features/products/components/ProductTable';
import { ProductFormSheet } from '@/features/products/components/ProductFormSheet';
import { PriceUpdateModal } from '@/features/products/components/PriceUpdateModal';
import { LowestPriceHistorySheet } from '@/features/products/components/LowestPriceHistorySheet';
import { ExcelUploadModal, downloadProductTemplate } from '@/features/products/components/ExcelUploadModal';
import { type Product } from '@/features/products/types';
@@ -51,13 +52,16 @@ export default function ProductsPage() {
const [selectedIds, setSelectedIds] = useState<string[]>([]);
// 딥링크·뒤로가기·새로고침 지원
const overlay = useOverlayRouter(['new', 'detail', 'modal']);
const overlay = useOverlayRouter(['new', 'detail', 'modal', 'lowest']);
const editId = overlay.get('detail');
const modal = overlay.get('modal'); // 'price' | 'excel' | null
const editing = editId ? allProducts.find((p) => p.item_id === editId) ?? null : null;
const formMode: 'create' | 'edit' = editId ? 'edit' : 'create';
const isFormOpen = overlay.has('new') || !!editing;
const lowestId = overlay.get('lowest');
const lowestProduct = products.find((prod) => prod.item_id === lowestId) ?? null;
const openCreate = () => overlay.open('new');
const openEdit = (prod: Product) => overlay.open('detail', prod.item_id);
@@ -175,6 +179,7 @@ export default function ProductsPage() {
selectedIds={selectedIds}
onSelectionChange={setSelectedIds}
onRowClick={openEdit}
onLowestPriceClick={(prod) => overlay.open('lowest', prod.item_id)}
page={list.page}
totalPages={totalPages}
totalCount={total}
@@ -209,6 +214,10 @@ export default function ProductsPage() {
/>
)}
{lowestProduct && (
<LowestPriceHistorySheet product={lowestProduct} onClose={overlay.close} />
)}
{modal === 'excel' && (
<ExcelUploadModal
open