oms/backend/database/migrations/20260915002900-bump-bill-no-auto-increment.js
liufumingren 489563a4b2 feat(backend): 仪表盘报表接口、配置裁剪、单号 5 位与账号名称/头像
- 仪表盘报表:新增 app/service/dashboard.js + app/controller/dashboard.js +
  app/lib/billStatus.js,注册 GET /api/dashboard/report(jwtAuth + principalCheck),
  一次聚合返回概览指标、发货单/入库单/出库单状态分布与待办、近 N 天单据量与
  出入库数量趋势、库存 Top 商品、最近出入库流水;warehouse_id 只过滤单据与流水
  (product_stocks 无仓库维度);契约 dashboard* 同步到 swagger
- 接口配置裁剪:仓库接口配置只保留 api_version 与 item_name_with_spec;
  历史 warehouse_apis.extra 冗余键、owner_code 配置、递交/回传设置一并清理
  (迁移 20260915002400~02800)
- 入库/出库/发货单报文与字段对齐 WMS 标准:去掉 ownerCode、operatorCode 等多余字段,
  入库明细补 itemId;发货单明细去掉无意义的 owner_code(迁移 20260915002600)
- 单号 5 位起:四张单据表 AUTO_INCREMENT 提到 10000(迁移 20260915002900)
- 账号名称/头像按主体维护:principal_users 增 name/avatar 并回填(迁移 20260915003000/03100),
  新增 app/lib/accountProfile.js(关联表名称/头像 → users 兜底);审核人写入 operator/operator_name;
  register 不再写 nickname、updateProfile 仅接受邮箱/手机号
- 出库单推送/锁库存链路的配套调整(outboundOrderPush、订单与发货单控制器)

Co-Authored-By: GitHub Copilot <noreply@github.com>
2026-09-14 16:09:35 +08:00

49 lines
2.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 单号数字部分提到 5 位数:把单据表的自增起点推到 10000
*
* 背景(2026-09-14 按用户要求):出入库单/发货单号由系统按 `{前缀}_{自增id}` 生成
* (`RK_{id}` / `CK_{id}` / `FH_{id}`,见各控制器 create()),当前自增值还是个位数,
* 单号看起来太"短"。这里把相关表的 AUTO_INCREMENT 提升到 10000,
* 使后续新单号至少是 5 位数(如 RK_10000 / CK_10001 / FH_10002)。
*
* 口径:
* - **历史单号不改**(它们是 WMS 侧的外部单号:entryOrderCode / deliveryOrderCode / stockoutOrderCode,
* 改动会与外部系统失联),只影响之后新建的单据
* - id 与单号仍一一对应(单号就是 `{前缀}_{id}`),驳回换号 `nextRejectedBillNo` 仍按 id 识别基础号
* - 幂等:表当前自增值已 >= 10000 时不动;表不存在时跳过
*/
const TABLES = [ 'inbound_orders', 'outbound_orders', 'order_deliveries', 'orders' ];
const START = 10000;
module.exports = {
async up(queryInterface) {
const sequelize = queryInterface.sequelize;
for (const table of TABLES) {
const [ info ] = await sequelize.query(
`SELECT AUTO_INCREMENT AS autoIncrement FROM information_schema.TABLES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = ?`,
{ replacements: [ table ], type: sequelize.QueryTypes.SELECT }
);
if (!info) {
console.log(`[migration] 表 ${table} 不存在,跳过`);
continue;
}
const current = info.autoIncrement == null ? null : Number(info.autoIncrement);
if (current != null && current >= START) {
console.log(`[migration] 表 ${table} 自增值已是 ${current}(>= ${START}),跳过`);
continue;
}
await sequelize.query(`ALTER TABLE \`${table}\` AUTO_INCREMENT = ${START}`);
console.log(`[migration] 表 ${table} 自增起点 ${current} -> ${START}(新单号将 >= ${START})`);
}
},
/**
* 不可逆:自增起点只增不减(回退会让新单号重新变短,且可能与既有单据冲突),故不做处理
*/
async down() {},
};