refactor(finance): 成本模型与履约方式正交,拆分成本中心巨型文件
后端: - 删除 services/admin/admin-cost-center-service.ts(4,248 行),拆为 services/cost-center/ 下 5 个模块: cost-center-shared(类型/枚举/归一化/映射/costModelScopeSql)、 cost-center-overview(总览与选项)、 product-catalog(商品与渠道映射)、 template-bootstrap(模板引导、自动发货同步、工单证据回填)、 cost-definition(成本项/版本/异常/预览/快照) - cost_items.carrier_type / cost_type 改为单一 cost_model;专属模型只对 对应履约方式生效,通用模型对所有履约方式生效 - cost_snapshots / cost_exceptions 删除载体列;按履约方式筛异常改用 IN 半连接(248k 异常下 EXISTS 逐行回表 2.7s -> 170ms) - sales_daily_facts.carrier_type -> fulfillment_mode - 人工支出按 cost_model 归类;履约方式只读 order_items.fulfillment_mode - 移除 syncOpenCostExceptionCarrierTypes:异常表已无载体列可同步 前端: - AdminCostCenterPage.tsx(2,887 行 -> 18 行转发),拆为 pages/admin/cost-center/ 下 8 个 Panel + shared + CostCenterContext - CostCarrierType 删除;新增 FulfillmentMode / ProductSource / CostModel - 销售毛利页 carrierType -> fulfillmentMode 同步补两个索引:idx_order_items_fulfillment_id(异常半连接)、 idx_work_categories_name(商品目录分类 lateral join)。
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
/**
|
||||
* 成本中心页面上下文。
|
||||
*
|
||||
* 面板只读这里的查询结果与动作,不自己发请求,避免同一页多套口径。
|
||||
*/
|
||||
import { createContext, useContext } from 'react'
|
||||
|
||||
import type {
|
||||
ChannelProductMapping,
|
||||
CostException,
|
||||
CostItem,
|
||||
CostModel,
|
||||
CostPreview,
|
||||
CostVersion,
|
||||
ProductCatalogItem,
|
||||
ProductSource,
|
||||
} from '@/types/admin'
|
||||
|
||||
import type { CostScope } from './shared'
|
||||
|
||||
export type CostCenterContextValue = {
|
||||
canConfig: boolean
|
||||
scope: CostScope
|
||||
scopeLabel: string
|
||||
/** 商品/映射按来源前缀筛选;成本项/版本/异常按履约方式筛选。 */
|
||||
productSourceFilter?: ProductSource
|
||||
fulfillmentModeFilter?: 'affiliate_dash' | 'work_order' | 'manual'
|
||||
|
||||
overview?: {
|
||||
productCount: number
|
||||
mappingCount: number
|
||||
costItemCount: number
|
||||
activeVersionCount: number
|
||||
openExceptionCount: number
|
||||
unmappedOrderItemCount: number
|
||||
productSourceCounts?: Record<string, number>
|
||||
costModelCounts?: Record<string, number>
|
||||
}
|
||||
options?: {
|
||||
providers: string[]
|
||||
products: Array<{
|
||||
id: number
|
||||
canonicalSku: string
|
||||
canonicalName: string
|
||||
unitName: string
|
||||
source: ProductSource
|
||||
}>
|
||||
costItems: Array<{
|
||||
id: number
|
||||
code: string
|
||||
name: string
|
||||
pricingMode: CostItem['pricingMode']
|
||||
costModel: CostModel
|
||||
}>
|
||||
rules: Array<{
|
||||
id: number
|
||||
ruleKey: string
|
||||
productName: string
|
||||
skuCode: string
|
||||
provider: string
|
||||
}>
|
||||
}
|
||||
|
||||
products: ProductCatalogItem[]
|
||||
mappingGroups: Array<{
|
||||
canonicalProductId: number
|
||||
canonicalSku: string
|
||||
canonicalName: string
|
||||
category: string
|
||||
unitName: string
|
||||
status: 'active' | 'archived'
|
||||
mappings: ChannelProductMapping[]
|
||||
}>
|
||||
costItems: CostItem[]
|
||||
versions: CostVersion[]
|
||||
exceptions: CostException[]
|
||||
|
||||
productsLoading: boolean
|
||||
mappingsLoading: boolean
|
||||
costItemsLoading: boolean
|
||||
versionsLoading: boolean
|
||||
exceptionsLoading: boolean
|
||||
|
||||
refreshAll: () => void
|
||||
}
|
||||
|
||||
export const CostCenterContext = createContext<CostCenterContextValue | null>(null)
|
||||
|
||||
export function useCostCenter() {
|
||||
const value = useContext(CostCenterContext)
|
||||
if (!value) {
|
||||
throw new Error('useCostCenter 必须在成本中心外壳内使用')
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
export type CostPreviewState = {
|
||||
preview: CostPreview | null
|
||||
previewing: boolean
|
||||
snapshotting: boolean
|
||||
previewOrderItemId: number | null
|
||||
setPreviewOrderItemId: (value: number | null) => void
|
||||
setPreview: (value: CostPreview | null) => void
|
||||
}
|
||||
Reference in New Issue
Block a user