oms/backend/database/migrations/20260915003100-backfill-principal-user-name-avatar.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

38 lines
1.5 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';
/**
* 回填主体账号关联表的名称/头像:principal_users.name / avatar ← users.nickname / users.avatar
*
* 背景(2026-09-14):账号显示名称与头像改为按主体维度维护(principal_users.name / avatar),
* 新建/邀请会产生新值;为了让**历史账号**在关联表里也有名称与头像(右上角展示、推送单据操作人取名称),
* 这里把全局 users 的昵称/头像回填一份(仅回填关联表为空的记录,不覆盖已有值)。
*
* 幂等:只更新 name/avatar 为 NULL/空串 的行,可重复执行。
*/
module.exports = {
async up(queryInterface) {
const sequelize = queryInterface.sequelize;
const [ nameResult ] = await sequelize.query(
`UPDATE principal_users pu
JOIN users u ON u.id = pu.user_id
SET pu.name = u.nickname
WHERE (pu.name IS NULL OR pu.name = '') AND u.nickname IS NOT NULL AND u.nickname <> ''`
);
console.log(`[migration] principal_users.name 回填:${nameResult.affectedRows || 0} 行`);
const [ avatarResult ] = await sequelize.query(
`UPDATE principal_users pu
JOIN users u ON u.id = pu.user_id
SET pu.avatar = u.avatar
WHERE (pu.avatar IS NULL OR pu.avatar = '') AND u.avatar IS NOT NULL AND u.avatar <> ''`
);
console.log(`[migration] principal_users.avatar 回填:${avatarResult.affectedRows || 0} 行`);
},
/**
* 不可逆:回填是幂等的资料补齐,无需回退(如需清空可在账号页重新设置)
*/
async down() {},
};