69 lines
2.5 KiB
JavaScript
69 lines
2.5 KiB
JavaScript
/**
|
||
* 复现原料出库单保存 500 错误
|
||
* 用法:node server/scripts/debug-outstock-save.mjs
|
||
*/
|
||
const BASE = process.env.F9MES_API || 'http://localhost:5136';
|
||
const PHONE = '13800000000';
|
||
const PASSWORD = '123456';
|
||
|
||
async function main() {
|
||
const login = await fetch(BASE + '/api/auth/login', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ phone: PHONE, password: PASSWORD }),
|
||
}).then((r) => r.json());
|
||
if (login.code !== 0) throw new Error('登录失败: ' + JSON.stringify(login));
|
||
const h = { Authorization: 'Bearer ' + login.data.token, 'Content-Type': 'application/json' };
|
||
|
||
// 取第一个庄口
|
||
const zk = await fetch(BASE + '/api/data/RawMaterial_Zhuangkou/all', { headers: h }).then((r) => r.json());
|
||
const zkItems = (zk.data && (zk.data.data || zk.data.items)) || (Array.isArray(zk.data) ? zk.data : []);
|
||
if (!zkItems.length) throw new Error('无庄口');
|
||
const zhuangkouId = zkItems[0].id;
|
||
console.log('使用庄口 id=' + zhuangkouId);
|
||
|
||
// 取第一个组织(OutOrgId)
|
||
let outOrgId = 0;
|
||
try {
|
||
const org = await fetch(BASE + '/api/data/RawMaterial_Org/all', { headers: h }).then((r) => r.json());
|
||
const orgItems = (org.data && (org.data.data || org.data.items)) || (Array.isArray(org.data) ? org.data : []);
|
||
if (orgItems.length) outOrgId = orgItems[0].id;
|
||
} catch { /* 无组织表则用0 */ }
|
||
console.log('使用组织 id=' + outOrgId);
|
||
|
||
// 生成单号
|
||
let billNo = 'YLC' + new Date().toISOString().slice(0, 10).replace(/-/g, '') + '-DBG';
|
||
try {
|
||
const g = await fetch(BASE + '/api/meta/gencode/RawMaterial_OutStock/billNo', { method: 'POST', headers: h }).then((r) => r.json());
|
||
if (g.code === 0 && g.data && g.data.value) billNo = g.data.value;
|
||
} catch (e) { console.log('gencode 失败,使用自造单号', e.message); }
|
||
console.log('使用单号 ' + billNo);
|
||
|
||
// 模拟前端 payload(与 outstock-bill.vue handleSave 完全一致)
|
||
const payload = {
|
||
billNo,
|
||
zhuangkouId,
|
||
outOrgId,
|
||
outWeight: 100,
|
||
receiver: '张三',
|
||
outDate: '2026-08-16 14:30:00',
|
||
outType: 0,
|
||
status: 0,
|
||
};
|
||
|
||
const resp = await fetch(BASE + '/api/data/RawMaterial_OutStock/add', {
|
||
method: 'POST',
|
||
headers: h,
|
||
body: JSON.stringify(payload),
|
||
});
|
||
const text = await resp.text();
|
||
console.log('HTTP ' + resp.status);
|
||
console.log('BODY>>>');
|
||
console.log(text.slice(0, 3000));
|
||
}
|
||
|
||
main().catch((e) => {
|
||
console.error('ERR: ' + e.message);
|
||
process.exit(1);
|
||
});
|