fix: 解决merge conflict

This commit is contained in:
sophie committed 2026-10-13 13:17:14 +08:00
1 parent e38e5a63fe
commit 7e7bcbd388
5 files changed
+78 -20

No files matched your search

@@ -3,6 +3,7 @@
* 用途:设备验收预警同步列表、详情和手动同步。
* 依赖:统一 requestJson;后端 /api/equipment-acceptance。
* 逻辑:Chat 作业面调用。同步只读 E10。配置只保存天数和系统用户,不保存发送时刻。
* 保存配置自行声明 Content-Type: application/json,供 Flask get_json 解析。
* 发送记录只读已落库的行,扫描尚未写入时列表为空。
*/
import { requestJson } from '@/shared/api/client';
@@ -206,8 +207,8 @@ export function getEquipmentAcceptanceConfig() {
* @param payload.days - 四个逐档增大的天数
* @param payload.buyerManagerUserId - 采购经副理
* @param payload.cooUserId - COO
* @param payload.executiveUserId - 廖总对应岗位
* @returns 保存后的配置
* @param payload.executiveUserId - 总经理对应岗位
* @returns 保存后的配置。请求头带 application/json,避免 Flask 把正文当成空对象。
*/
export function saveEquipmentAcceptanceConfig(payload: {
days: number[];
@@ -217,6 +218,7 @@ export function saveEquipmentAcceptanceConfig(payload: {
}) {
return requestJson<EquipmentAcceptanceConfig>('/api/equipment-acceptance/config', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
days: payload.days,
buyer_manager_user_id: payload.buyerManagerUserId,
@@ -0,0 +1,47 @@
/**
* features/order-delivery-reply/api/orderDeliveryReply.api.spec.ts
* 用途:锁定交期回复 JSON 写请求自行声明 Content-Type。
* 依赖:vitest、orderDeliveryReply.api。
* 逻辑:requestJson 不再为所有 body 补 application/json;漏掉该头时 Flask get_json 会把保存当成空正文。
*/
import { beforeEach, describe, expect, it, vi } from 'vitest';
const requestJson = vi.hoisted(() => vi.fn());
vi.mock('@/shared/api/client', () => ({
requestJson,
}));
import {
batchReplyOrderDelivery,
notifyOrderDeliveryBatch,
saveOrderDeliveryBatches,
} from './orderDeliveryReply.api';
describe('order delivery reply JSON writes', () => {
beforeEach(() => {
requestJson.mockReset();
requestJson.mockResolvedValue({});
});
it('sends Content-Type application/json when saving one line', async () => {
await saveOrderDeliveryBatches('SO-1', 2, [{ planned_date: '2026-10-13', qty: '1' }]);
const init = requestJson.mock.calls[0][1] as RequestInit;
// 断言:保存请求自己带 JSON 类型,不依赖公共客户端补头。
expect((init.headers as Record<string, string>)['Content-Type']).toBe('application/json');
expect(init.method).toBe('PUT');
expect(init.body).toBe(JSON.stringify({ batches: [{ planned_date: '2026-10-13', qty: '1' }] }));
});
it('sends Content-Type application/json for batch reply and batch notify', async () => {
await batchReplyOrderDelivery([]);
await notifyOrderDeliveryBatch([]);
for (const [, init] of requestJson.mock.calls as [string, RequestInit][]) {
// 断言:联合回复与批量通知同样声明 JSON 类型。
expect((init.headers as Record<string, string>)['Content-Type']).toBe('application/json');
expect(init.method).toBe('POST');
}
});
});
@@ -2,10 +2,26 @@
* 订单交期回复 API 类型与请求封装。
* 依赖:统一 requestJson(失败抛 BusinessError);后端 /api/order-delivery-reply。
* 逻辑:列表筛选分页、保存批次(单行/联合)、单行与批量通知、手动同步与最近同步状态。
* 带 JSON 正文的写请求在本文件声明 Content-Type: application/json,供 Flask get_json 解析。
*/
import { requestJson } from '@/shared/api/client';
/**
* 组装带 JSON 正文的写请求。
* 核心逻辑:显式声明 application/json。浏览器对字符串正文默认是 text/plain,Flask get_json 会读成空对象。
* @param method - HTTP 方法
* @param payload - 将序列化为 JSON 的请求体
* @returns fetch 的 method、headers 与 body
*/
function jsonWrite(method: 'POST' | 'PUT', payload: unknown): RequestInit {
return {
method,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
};
}
/** 已保存的交期批次(计划交期 + 数量 + 可选备注)。 */
export interface DeliveryBatch {
seq?: number;
@@ -100,7 +116,7 @@ export const listOrderDeliveryLines = (params?: OrderDeliveryListParams) => {
return requestJson<OrderDeliveryListResponse>(`/api/order-delivery-reply/lines${suffix}`);
};
/** 保存单行交期批次(未锁定行整表替换)。 */
/** 保存单行交期批次(未锁定行整表替换)。请求头带 application/json,避免正文被 Flask 当成空对象。 */
export const saveOrderDeliveryBatches = (
orderNo: string,
lineNo: number,
@@ -108,17 +124,14 @@ export const saveOrderDeliveryBatches = (
) =>
requestJson<{ order_no: string; line_no: number; batches: DeliveryBatch[]; total_qty: string }>(
`/api/order-delivery-reply/lines/${encodeURIComponent(orderNo)}/${lineNo}/batches`,
{ method: 'PUT', body: JSON.stringify({ batches }) },
jsonWrite('PUT', { batches }),
);
/** 联合回复:对多行逐行保存批次(只保存,不通知不锁定)。 */
/** 联合回复:对多行逐行保存批次(只保存,不通知不锁定)。请求头带 application/json。 */
export const batchReplyOrderDelivery = (
items: { order_no: string; line_no: number; batches: { planned_date: string; qty: string | number; remark?: string | null }[] }[],
) =>
requestJson<BatchSummary>('/api/order-delivery-reply/batch-reply', {
method: 'POST',
body: JSON.stringify({ items }),
});
requestJson<BatchSummary>('/api/order-delivery-reply/batch-reply', jsonWrite('POST', { items }));
/** 单行发送通知业务部门(企微),成功后行级锁定。 */
export const notifyOrderDeliveryLine = (orderNo: string, lineNo: number) =>
@@ -127,12 +140,12 @@ export const notifyOrderDeliveryLine = (orderNo: string, lineNo: number) =>
{ method: 'POST' },
);
/** 批量通知勾选行;无批次/已锁定跳过,单行失败不回滚其它行。 */
/** 批量通知勾选行;无批次/已锁定跳过,单行失败不回滚其它行。请求头带 application/json。 */
export const notifyOrderDeliveryBatch = (lines: { order_no: string; line_no: number }[]) =>
requestJson<BatchSummary>('/api/order-delivery-reply/notify-batch', {
method: 'POST',
body: JSON.stringify({ lines }),
});
requestJson<BatchSummary>(
'/api/order-delivery-reply/notify-batch',
jsonWrite('POST', { lines }),
);
/** 手动触发 ERP 全量同步(范围与 07:00 排程一致)。 */
export const runOrderDeliverySync = () =>
@@ -395,11 +395,12 @@ async function focusTargetLine(orderNo: string, lineNo: number) {
highlightTimer = setTimeout(clearHighlight, 8000);
}
/** 上报企微卡片打开回执(WecomNotifyAudit.opened_at);仅留痕,失败不影响页面使用。 */
/** 上报企微卡片打开回执(WecomNotifyAudit.opened_at);仅留痕,失败不影响页面使用。请求头带 application/json,后端 get_json 才读得到 trace_id。 */
async function reportWecomTraceOpened(traceId: string) {
try {
await requestJson('/api/user/wecom/deeplink-opened', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ trace_id: traceId }),
});
} catch {
-5
View File
@@ -168,11 +168,6 @@ export async function requestJson<T>(url: string, init?: RequestInit): Promise<T
const headers = new Headers(init?.headers || {});
const authHeaders = getAuthHeaders();
Object.entries(authHeaders).forEach(([k, v]) => headers.set(k, v as string));
// 带 body 的请求若未显式声明类型,统一补 JSON 头:否则 Flask get_json(silent=True)
// 会因 Content-Type 非 JSON 解析出 None,把有效载荷当空 body 处理(如订单交期回复保存被误判 400)。
if (init?.body && !headers.has('Content-Type')) {
headers.set('Content-Type', 'application/json');
}
const res = await fetchJsonResponse(url, { ...init, headers });
let data: any = null;