feat(jd): 京东数据库公共化——数据不区分公司、分组全平台一份(2026-11-15 用户定案)
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
/** 京东数据库查询适配(v1.4 Phase 5):GET /api/admin/jd-products + 删除(DELETE /{id} +
|
||||
* POST /batch-delete)+ 分组端点 /api/admin/jd-product-groups。
|
||||
* 只读列表+删除+分组管理:公司 tab 的值由本发送口从原始入参自己下传
|
||||
* (白名单构造不认识 company_id),取值口形状由 company-tab-wiring 护栏钉住。
|
||||
* 导出发送口已随 2026-11-15 客户口径「导出也不用」从前端下线(后端 /export 端点保留)。 */
|
||||
* 公司口径(2026-11-15 用户定案「京东数据库不区分公司、属于公共的」):公共库只有两个
|
||||
* 公司维度出口——只读列表与类目下拉把公司 tab 的值下传(仅超管生效=筛选管理员);
|
||||
* 详情/编辑/删除/分组管理全平台一份,不收 company_id(后端写侧也没有公司维度)。
|
||||
* 取值口形状由 company-tab-wiring 护栏钉住。导出发送口已随 2026-11-15 客户口径
|
||||
* 「导出也不用」从前端下线(后端 /export 端点保留)。 */
|
||||
import { http } from '@/api/http'
|
||||
import { errorTextOf, unwrap } from '../../api/envelope.ts'
|
||||
import {
|
||||
@@ -39,14 +41,12 @@ export async function fetchJdProductList(
|
||||
return parseJdProductPage(data)
|
||||
}
|
||||
|
||||
/** 详情:GET /api/admin/jd-products/{id}(信封 data=主字段 + attrGroups + attrJsonRaw + images)。 */
|
||||
/** 详情:GET /api/admin/jd-products/{id}(信封 data=主字段 + attrGroups + attrJsonRaw + images)。
|
||||
* 公共库无公司维度,按 id 直取。 */
|
||||
export async function fetchJdProductDetail(
|
||||
id: number,
|
||||
companyId: number | null,
|
||||
): Promise<ReturnType<typeof parseJdProductDetail>> {
|
||||
const query: Record<string, number> = {}
|
||||
if (companyId != null) query.company_id = companyId
|
||||
const { data } = await http.get<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}`, { params: query })
|
||||
const { data } = await http.get<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}`)
|
||||
return parseJdProductDetail(data)
|
||||
}
|
||||
|
||||
@@ -59,18 +59,16 @@ export interface JdProductDeleteResult {
|
||||
objectsSkipped: number
|
||||
}
|
||||
|
||||
/** 删除是先删桶、全成功才删库行(后端 JdProductDeleteService);失败文案原样抛给页面。 */
|
||||
/** 删除是先删桶、全成功才删库行(后端 JdProductDeleteService);失败文案原样抛给页面。
|
||||
* 公共库写侧无公司维度(2026-11-15 用户定案)。 */
|
||||
export async function deleteJdProducts(
|
||||
ids: number[],
|
||||
companyId: number | null,
|
||||
): Promise<JdProductDeleteResult> {
|
||||
const query: Record<string, number> = {}
|
||||
if (companyId != null) query.company_id = companyId
|
||||
if (ids.length === 1) {
|
||||
const { data } = await http.delete<unknown>(`${JD_PRODUCT_ENDPOINT}/${ids[0]}`, { params: query })
|
||||
const { data } = await http.delete<unknown>(`${JD_PRODUCT_ENDPOINT}/${ids[0]}`)
|
||||
return unwrap<JdProductDeleteResult>(data)
|
||||
}
|
||||
const { data } = await http.post<unknown>(`${JD_PRODUCT_ENDPOINT}/batch-delete`, { ids }, { params: query })
|
||||
const { data } = await http.post<unknown>(`${JD_PRODUCT_ENDPOINT}/batch-delete`, { ids })
|
||||
return unwrap<JdProductDeleteResult>(data)
|
||||
}
|
||||
|
||||
@@ -92,17 +90,14 @@ export interface JdProductUpdatePayload {
|
||||
deleteImageIds: number[] | null
|
||||
}
|
||||
|
||||
/** 编辑保存(PUT + company_id 作 query,照 deleteJdProducts 形状):主字段保存即置
|
||||
* 人工编辑锁(V199 manual_locked=1,后续采集不再覆盖该行);失败文案原样抛给抽屉红条。
|
||||
* 返回刷新后的详情(与 fetchJdProductDetail 同一信封),抽屉用它回填。 */
|
||||
/** 编辑保存(PUT):主字段保存即置人工编辑锁(V199 manual_locked=1,后续采集不再覆盖该行);
|
||||
* 失败文案原样抛给抽屉红条。公共库写侧无公司维度。返回刷新后的详情(与
|
||||
* fetchJdProductDetail 同一信封),抽屉用它回填。 */
|
||||
export async function updateJdProduct(
|
||||
id: number,
|
||||
payload: JdProductUpdatePayload,
|
||||
companyId: number | null,
|
||||
): Promise<ReturnType<typeof parseJdProductDetail>> {
|
||||
const query: Record<string, number> = {}
|
||||
if (companyId != null) query.company_id = companyId
|
||||
const { data } = await http.put<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}`, payload, { params: query })
|
||||
const { data } = await http.put<unknown>(`${JD_PRODUCT_ENDPOINT}/${id}`, payload)
|
||||
return parseJdProductDetail(data)
|
||||
}
|
||||
|
||||
@@ -133,11 +128,10 @@ function numberOr(value: unknown, fallback: number): number {
|
||||
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : fallback
|
||||
}
|
||||
|
||||
/** 分组下拉/管理列表;失败由页面自己兜(分组只是筛选项,不拦首屏行集)。 */
|
||||
export async function fetchJdProductGroups(companyId: number | null): Promise<JdProductGroup[]> {
|
||||
const query: Record<string, number> = {}
|
||||
if (companyId != null) query.company_id = companyId
|
||||
const { data } = await http.get<unknown>(JD_PRODUCT_GROUP_ENDPOINT, { params: query })
|
||||
/** 分组下拉/管理列表(分组 2026-11-15 起全平台一份,不带公司维度);失败由页面自己兜
|
||||
* (分组只是筛选项,不拦首屏行集)。 */
|
||||
export async function fetchJdProductGroups(): Promise<JdProductGroup[]> {
|
||||
const { data } = await http.get<unknown>(JD_PRODUCT_GROUP_ENDPOINT)
|
||||
const core = unwrap<unknown>(data)
|
||||
if (!Array.isArray(core)) return []
|
||||
const out: JdProductGroup[] = []
|
||||
@@ -182,13 +176,11 @@ export async function fetchJdProductCategories(
|
||||
return out
|
||||
}
|
||||
|
||||
/** 新建分组;重名等业务失败把后端中文文案抛回(页面直接展示)。 */
|
||||
/** 新建分组(公共库无公司维度);重名等业务失败把后端中文文案抛回(页面直接展示)。 */
|
||||
export async function createJdProductGroup(
|
||||
payload: JdProductGroupPayload,
|
||||
companyId: number | null,
|
||||
): Promise<JdProductGroup | null> {
|
||||
const body: Record<string, unknown> = { name: payload.name, sortOrder: payload.sortOrder }
|
||||
if (companyId != null) body.company_id = companyId
|
||||
const { data } = await http.post<unknown>(JD_PRODUCT_GROUP_ENDPOINT, body)
|
||||
return groupDataOf<JdProductGroup | null>(data)
|
||||
}
|
||||
@@ -197,18 +189,14 @@ export async function createJdProductGroup(
|
||||
export async function updateJdProductGroup(
|
||||
id: number,
|
||||
payload: JdProductGroupPayload,
|
||||
companyId: number | null,
|
||||
): Promise<JdProductGroup | null> {
|
||||
const body: Record<string, unknown> = { name: payload.name, sortOrder: payload.sortOrder }
|
||||
if (companyId != null) body.company_id = companyId
|
||||
const { data } = await http.put<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${id}`, body)
|
||||
return groupDataOf<JdProductGroup | null>(data)
|
||||
}
|
||||
|
||||
/** 删除分组;业务失败文案同上。 */
|
||||
export async function deleteJdProductGroup(id: number, companyId: number | null): Promise<void> {
|
||||
const query: Record<string, number> = {}
|
||||
if (companyId != null) query.company_id = companyId
|
||||
const { data } = await http.delete<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${id}`, { params: query })
|
||||
export async function deleteJdProductGroup(id: number): Promise<void> {
|
||||
const { data } = await http.delete<unknown>(`${JD_PRODUCT_GROUP_ENDPOINT}/${id}`)
|
||||
groupDataOf<unknown>(data)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user