1d27806a61
本批两件事,加上随本批一起入仓的并行会话在制品: 一、菜单权限按公司隔离(批次 6) - V149 给 columns 加 company_id:先可空加列(末位、ALGORITHM=INSTANT)→ 回填公司 1 → MODIFY 收紧 NOT NULL;三段式缺一即撞 1048。同时建 (company_id, column_key) 复合键、 把公司 2 的 16 笔授权按 column_key 改指向它自己的副本,三类 menu_type 全复制, admin_companies 作为角色内生闸门行不复制(D3)。 - 第三道归属门 PermissionMenuService.resolveScopeCompanyId:站点超管可带 company_id 读写任意公司,非超管锁本公司、越界 403。它注册进 CompanyIdParamGoesThroughReadScopeTest 的 SCOPE_DOORS,四条判据与 readScope / readCompanyIdOrOwn 共用——护栏在代码出口,不靠清单。 - 旁路种子 PermissionMenuSchemaInitializer 只种公司 1:31 段种子逐条钉公司, 按 column_key 点查的 14 段全部带 company_id,否则摘了 DEFAULT 就是跨公司串写。 - CompanyService.create 同一次写入里给新公司复制模板树(D4)。 二、公司 tab 收口(批次 b) tab 条挂在壳层,对 22 页全画;改为按正列表 companyTabAppliesTo(menuKey) 判定, 只有注册表页渲染。护栏钉在用户看见的那个出口。 三、并行会话在制品(控制方「全部提交」,未单独拆分——见下) - V150 店铺密钥 biz_shop_key 按公司(readCompanyIdOrOwn + writeCompanyId 两道门) - V151 品牌库/商品类目推翻为全平台共享:只退唯一键、company_id DEFAULT 保留为 NOT NULL 承重约束(摘了每条 1364);删掉 ProductCategoryControllerCompanyScopeTest 那支"按公司隔离"的旧护栏,readCompanyId 方法一并移除 - invalidasin 字段与外观专利合批的连带改动 为什么不拆笔:后端 3891 例 / 0 红、前端 1731 例 / 0 红这两个读数是"合起来的树"的读数, 拆成多笔会让每一笔落到从未一起验过的组合上,而这一版要直接上两台。 回滚脚本在 backend-java/docs/rollback-V149/V150/V151-*.sql,不放进 Flyway 扫描路径。 设计记录:docs/ops/menu-company-tree-design-2026-10-06.md
177 lines
5.8 KiB
TypeScript
177 lines
5.8 KiB
TypeScript
/** 店铺中心共享 DTO(任务 81):店铺密钥/店铺摘要/明文凭据/分组与分页类型;
|
||
* 纯逻辑、无框架依赖,与 Java shopkey 模块的 camelCase 接口契约对齐。 */
|
||
|
||
export const SHOP_PAGE_DEFAULT_SIZE = 15
|
||
export const SHOP_PAGE_MIN_PAGE = 1
|
||
export const SHOP_PAGE_MAX_SIZE = 100
|
||
|
||
/** 敏感字符串品牌:紫鸟令牌、店铺密码等明文只允许经 toSensitiveString 标记,禁止直接进入通用日志/上报。 */
|
||
export type SensitiveString = string & { readonly __sensitiveBrand: unique symbol }
|
||
|
||
export function toSensitiveString(value: string): SensitiveString {
|
||
return value as SensitiveString
|
||
}
|
||
|
||
/** 紫鸟 IP 白名单状态。 */
|
||
export type IpWhitelistStatus = 'UNKNOWN' | 'ALLOWED' | 'BLOCKED'
|
||
|
||
/** 店铺密钥行(GET /api/admin/shop-keys data.items;Java ShopKeyItemVo)。 */
|
||
export interface ShopKeyItem {
|
||
id: number
|
||
remarkName: string
|
||
ziniaoAccountName: string
|
||
/** 紫鸟令牌:敏感字段,列表展示必须掩码。 */
|
||
ziniaoToken: SensitiveString
|
||
/** 静态代理地址;为空表示直连。用于出口 IP 不在紫鸟白名单的 key。 */
|
||
proxyUrl: string
|
||
ipWhitelistStatus: IpWhitelistStatus
|
||
ipWhitelistCheckedAt?: string
|
||
ipWhitelistMessage?: string
|
||
/** 连续白名单失败次数;达上限后不再自动重试,需人工检测。 */
|
||
ipWhitelistFailCount: number
|
||
createdAt?: string
|
||
updatedAt?: string
|
||
}
|
||
|
||
export interface ShopKeyPageResult {
|
||
items: ShopKeyItem[]
|
||
total: number
|
||
page: number
|
||
pageSize: number
|
||
}
|
||
|
||
/** 店铺行(GET /api/admin/shop-manages data.items;Java ShopManageItemVo,密码只下发掩码)。 */
|
||
export interface ShopSummary {
|
||
id: number
|
||
groupId: number | null
|
||
groupName: string
|
||
shopName: string
|
||
mallName: string
|
||
znUsername: string
|
||
account: string
|
||
passwordMasked?: string
|
||
createdAt?: string
|
||
updatedAt?: string
|
||
}
|
||
|
||
export interface ShopPageResult {
|
||
items: ShopSummary[]
|
||
total: number
|
||
page: number
|
||
pageSize: number
|
||
}
|
||
|
||
/** 店铺明文凭据(GET /api/admin/shop-manages/{id}/credential data;Java ShopManageCredentialVo)。 */
|
||
export interface ShopCredential {
|
||
id: number
|
||
groupId: number | null
|
||
groupName: string
|
||
shopName: string
|
||
mallName: string
|
||
znUsername: string
|
||
account: string
|
||
password: SensitiveString
|
||
}
|
||
|
||
/** 店铺分组下拉项(GET /api/admin/shop-manages/groups data)。 */
|
||
export interface ShopGroupOption {
|
||
id: number
|
||
groupName: string
|
||
memberCount?: number
|
||
leaderUsername?: string
|
||
}
|
||
|
||
/** 店铺密钥列表分页参数(分页 + 公司 tab;归一是白名单构造,不点名 companyId)。 */
|
||
export interface ShopKeyListParams {
|
||
page: number
|
||
pageSize: number
|
||
/** 公司 tab 的值;normalizeKeyListParams 不点名它,只有 api 层能从原始 params 读到。 */
|
||
companyId?: number | null
|
||
}
|
||
|
||
/** 店铺列表分页/筛选参数。 */
|
||
export interface ShopManageListParams {
|
||
page: number
|
||
pageSize: number
|
||
groupId?: number | null
|
||
shopName?: string
|
||
/** 公司 tab 的值;normalizeShopListParams 不点名它,只有 api 层能从原始 params 读到。 */
|
||
companyId?: number | null
|
||
}
|
||
|
||
export interface ShopKeyPageQuery {
|
||
page: number
|
||
pageSize: number
|
||
/** 下划线形:与后端 @RequestParam(name = "company_id") 逐字对齐。 */
|
||
company_id?: number
|
||
}
|
||
|
||
export interface ShopManagePageQuery {
|
||
page: number
|
||
pageSize: number
|
||
groupId?: number
|
||
shopName?: string
|
||
/** 下划线形:与后端 @RequestParam(name = "company_id") 逐字对齐。 */
|
||
company_id?: number
|
||
}
|
||
|
||
function finiteInt(value: unknown): number | null {
|
||
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null
|
||
}
|
||
|
||
function positiveIdOrNull(value: unknown): number | null {
|
||
const id = finiteInt(value)
|
||
return id === null || id < 1 ? null : id
|
||
}
|
||
|
||
function trimOrUndefined(value: unknown): string | undefined {
|
||
return typeof value === 'string' && value.trim() ? value.trim() : undefined
|
||
}
|
||
|
||
/** 归一化分页:页码下限 1、页大小钳制在 1..100(与 Java 服务端一致)。 */
|
||
function normalizePageCore(raw: { page?: unknown; pageSize?: unknown }): { page: number; pageSize: number } {
|
||
const page = Math.max(finiteInt(raw.page) ?? SHOP_PAGE_MIN_PAGE, SHOP_PAGE_MIN_PAGE)
|
||
const rawSize = finiteInt(raw.pageSize)
|
||
const pageSize =
|
||
rawSize === null || rawSize < SHOP_PAGE_MIN_PAGE
|
||
? SHOP_PAGE_DEFAULT_SIZE
|
||
: Math.min(rawSize, SHOP_PAGE_MAX_SIZE)
|
||
return { page, pageSize }
|
||
}
|
||
|
||
/** 店铺密钥列表分页归一。 */
|
||
export function normalizeKeyListParams(raw: Partial<ShopKeyListParams>): ShopKeyListParams {
|
||
return normalizePageCore(raw)
|
||
}
|
||
|
||
/** 店铺列表分页/筛选归一:负/缺分组 id 视为无筛选,空白店铺名视为无过滤。 */
|
||
export function normalizeShopListParams(raw: Partial<ShopManageListParams>): ShopManageListParams {
|
||
return {
|
||
...normalizePageCore(raw),
|
||
groupId: positiveIdOrNull(raw.groupId),
|
||
shopName: trimOrUndefined(raw.shopName),
|
||
}
|
||
}
|
||
|
||
export function toKeyPageQuery(params: ShopKeyListParams): ShopKeyPageQuery {
|
||
return { page: params.page, pageSize: params.pageSize }
|
||
}
|
||
|
||
/** 前端状态 → Java 查询参数(camelCase);仅下发非空可选字段。 */
|
||
export function toShopManagePageQuery(params: ShopManageListParams): ShopManagePageQuery {
|
||
const query: ShopManagePageQuery = { page: params.page, pageSize: params.pageSize }
|
||
if (params.groupId != null) query.groupId = params.groupId
|
||
if (params.shopName) query.shopName = params.shopName
|
||
return query
|
||
}
|
||
|
||
/** 无数据密钥分页缺省值(首屏/加载前占位)。 */
|
||
export function emptyShopKeyPageResult(): ShopKeyPageResult {
|
||
return { items: [], total: 0, page: SHOP_PAGE_MIN_PAGE, pageSize: SHOP_PAGE_DEFAULT_SIZE }
|
||
}
|
||
|
||
/** 无数据店铺分页缺省值(首屏/加载前占位)。 */
|
||
export function emptyShopPageResult(): ShopPageResult {
|
||
return { items: [], total: 0, page: SHOP_PAGE_MIN_PAGE, pageSize: SHOP_PAGE_DEFAULT_SIZE }
|
||
}
|