- 仪表盘报表:新增 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>
76 lines
2.8 KiB
JavaScript
76 lines
2.8 KiB
JavaScript
'use strict';
|
||
|
||
/**
|
||
* 账号在「主体维度」下的资料(名称 / 头像)
|
||
*
|
||
* 口径(2026-09-14 按用户要求):同一账号在不同主体下可以有不同名称与头像,
|
||
* 数据落在主体账号关联表 `principal_users.name` / `principal_users.avatar`:
|
||
* - 推送单据的操作人取该关联表的名称(入库 entryOrder.operatorName、发货单 deliveryOrder.operatorName 等)
|
||
* - 页面右上角展示:有关联头像显示头像 → 无头像显示名称首字符 → 无名称显示账号(username)首字符
|
||
*
|
||
* 回退顺序(关联表未配置时保持旧行为,避免历史账号显示空白):
|
||
* name:principal_users.name → users.nickname → users.username
|
||
* avatar:principal_users.avatar → users.avatar
|
||
*/
|
||
|
||
/**
|
||
* 取账号在指定主体下的资料
|
||
* @param {Object} ctx egg context
|
||
* @param {Number|String} userId 用户ID
|
||
* @param {Number|String} principalId 主体ID(缺省时只取全局 users 字段)
|
||
* @return {Promise<{name: string, avatar: string}>} 名称与头像(可能为空串)
|
||
*/
|
||
async function resolveAccountProfile(ctx, userId, principalId) {
|
||
const id = Number(userId);
|
||
if (!id) return { name: '', avatar: '' };
|
||
|
||
let relation = null;
|
||
if (Number(principalId)) {
|
||
relation = await ctx.model.PrincipalUser.findOne({
|
||
where: { user_id: id, principal_id: Number(principalId) },
|
||
attributes: [ 'name', 'avatar' ],
|
||
});
|
||
}
|
||
|
||
let user = null;
|
||
if (!relation || !relation.name || !relation.avatar) {
|
||
user = await ctx.model.User.findByPk(id, { attributes: [ 'nickname', 'username', 'avatar' ] });
|
||
}
|
||
|
||
const name = (relation && relation.name)
|
||
|| (user && (user.nickname || user.username))
|
||
|| '';
|
||
const avatar = (relation && relation.avatar)
|
||
|| (user && user.avatar)
|
||
|| '';
|
||
|
||
return { name: String(name), avatar: String(avatar) };
|
||
}
|
||
|
||
/**
|
||
* 取账号在指定主体下的显示名称(推送单据操作人用)
|
||
* @param {Object} ctx egg context
|
||
* @param {Number|String} userId 用户ID
|
||
* @param {Number|String} principalId 主体ID
|
||
* @return {Promise<String>} 名称(兜底为空串)
|
||
*/
|
||
async function resolveAccountName(ctx, userId, principalId) {
|
||
const { name } = await resolveAccountProfile(ctx, userId, principalId);
|
||
return name;
|
||
}
|
||
|
||
/**
|
||
* 取展示用首字符:名称首字符(支持中文)→ 账号首字符
|
||
* @param {String} name 关联表名称
|
||
* @param {String} username 账号
|
||
* @return {String} 单个字符(都没有时返回空串)
|
||
*/
|
||
function firstCharOf(name, username) {
|
||
const source = String(name || '').trim() || String(username || '').trim();
|
||
if (!source) return '';
|
||
// 取首个「字」,避免把 emoji/代理对切一半
|
||
return Array.from(source)[0];
|
||
}
|
||
|
||
module.exports = { resolveAccountProfile, resolveAccountName, firstCharOf };
|