feat(supply-chain): 店铺账号离职负责人红色标注与负责人状态筛选(自定义下拉)
This commit is contained in:
parent
bcfadc1e3f
commit
ba1209deb3
File diff suppressed because one or more lines are too long
@ -1,4 +1,5 @@
|
||||
import {
|
||||
buildDepartedStoreAccountOwnerNames,
|
||||
formatStoreAccountLogValue,
|
||||
formatStoreAccountType,
|
||||
getStoreAccountLogFieldLabel,
|
||||
@ -18,6 +19,36 @@ describe('store account type presentation', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('departed store account owner names', () => {
|
||||
it('marks names whose internal accounts are all INACTIVE', () => {
|
||||
const departed = buildDepartedStoreAccountOwnerNames([
|
||||
{ name: '玄机', status: 'INACTIVE' },
|
||||
{ name: '子龙', status: 'ACTIVE' },
|
||||
{ name: ' 惠然 ', status: 'INACTIVE' },
|
||||
])
|
||||
expect(departed.has('玄机')).toBe(true)
|
||||
expect(departed.has('惠然')).toBe(true)
|
||||
expect(departed.has('子龙')).toBe(false)
|
||||
})
|
||||
|
||||
it('does not mark a name when an ACTIVE account shares it', () => {
|
||||
const departed = buildDepartedStoreAccountOwnerNames([
|
||||
{ name: '鲁肃', status: 'ACTIVE' },
|
||||
{ name: '鲁肃', status: 'INACTIVE' },
|
||||
])
|
||||
expect(departed.has('鲁肃')).toBe(false)
|
||||
})
|
||||
|
||||
it('does not mark unknown names or non-departure statuses', () => {
|
||||
const departed = buildDepartedStoreAccountOwnerNames([
|
||||
{ name: '刘景刚', status: 'ACTIVE' },
|
||||
{ name: '白泽', status: 'SUSPENDED' },
|
||||
{ name: ' ', status: 'INACTIVE' },
|
||||
])
|
||||
expect(departed.size).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('store account profile platform', () => {
|
||||
it('recognizes only the supported 京东- and 京喜- store prefixes', () => {
|
||||
expect(getStoreAccountProfilePlatformForStoreName('京东-旗舰店')).toBe('JD')
|
||||
|
||||
@ -126,6 +126,7 @@ export const STORE_ACCOUNT_FILTER_KEYS = [
|
||||
"accountType",
|
||||
"operationOwner",
|
||||
"operationOwnerExact",
|
||||
"operationOwnerStatus",
|
||||
"operationDepartmentHead",
|
||||
"operationDirector",
|
||||
"profitCenter",
|
||||
@ -144,6 +145,7 @@ export const EMPTY_STORE_ACCOUNT_FILTERS: StoreAccountFilters = {
|
||||
accountType: "",
|
||||
operationOwner: "",
|
||||
operationOwnerExact: "",
|
||||
operationOwnerStatus: "",
|
||||
operationDepartmentHead: "",
|
||||
operationDirector: "",
|
||||
profitCenter: "",
|
||||
@ -154,6 +156,12 @@ export const EMPTY_STORE_ACCOUNT_FILTERS: StoreAccountFilters = {
|
||||
createdAtValue: "",
|
||||
};
|
||||
|
||||
// 负责人状态筛选:已离职=内部账号查得到且全为离职;在职=内部账号存在在职账号;查无此人(不在内部)两档都不算。
|
||||
export const STORE_ACCOUNT_OWNER_STATUS_FILTER_OPTIONS = [
|
||||
{ value: "DEPARTED", label: "已离职" },
|
||||
{ value: "ACTIVE", label: "在职" },
|
||||
] as const;
|
||||
|
||||
export type StoreAccountFieldAccess = Record<
|
||||
StoreAccountFieldKey,
|
||||
StoreAccountFieldVisibility
|
||||
@ -200,6 +208,8 @@ export type StoreAccountRow = {
|
||||
id: string;
|
||||
storeName: string;
|
||||
operationOwner: string;
|
||||
/** 店铺运营负责人已离职(内部账号存在但状态=离职)时为 true,列表用红色提示需要换人 */
|
||||
operationOwnerDeparted?: boolean;
|
||||
operationDepartmentHead: string;
|
||||
operationDirector: string;
|
||||
profitCenter: string;
|
||||
@ -365,6 +375,39 @@ export type StoreAccountAuthorizationNoticeResult = {
|
||||
};
|
||||
};
|
||||
|
||||
export type StoreAccountOwnerEmploymentUser = {
|
||||
name: string;
|
||||
status: string;
|
||||
};
|
||||
|
||||
// 同名存在在职账号时不算离职;只有查到账号且全为离职(INACTIVE)才判为离职。查无此人不判离职(另属"不在内部"口径)。
|
||||
export function resolveStoreAccountOwnerEmployment(
|
||||
users: readonly StoreAccountOwnerEmploymentUser[],
|
||||
) {
|
||||
const byName = new Map<string, { active: boolean; inactive: boolean }>();
|
||||
for (const user of users) {
|
||||
const name = user.name.trim();
|
||||
if (!name) continue;
|
||||
const entry = byName.get(name) ?? { active: false, inactive: false };
|
||||
if (user.status === "ACTIVE") entry.active = true;
|
||||
if (user.status === "INACTIVE") entry.inactive = true;
|
||||
byName.set(name, entry);
|
||||
}
|
||||
const departedNames = new Set<string>();
|
||||
const employedNames = new Set<string>();
|
||||
for (const [name, entry] of byName) {
|
||||
if (entry.inactive && !entry.active) departedNames.add(name);
|
||||
if (entry.active) employedNames.add(name);
|
||||
}
|
||||
return { departedNames, employedNames };
|
||||
}
|
||||
|
||||
export function buildDepartedStoreAccountOwnerNames(
|
||||
users: readonly StoreAccountOwnerEmploymentUser[],
|
||||
) {
|
||||
return resolveStoreAccountOwnerEmployment(users).departedNames;
|
||||
}
|
||||
|
||||
export function getStoreAccountLogOperationLabel(operation: string) {
|
||||
return STORE_ACCOUNT_LOG_OPERATION_LABELS[operation] ?? "其他操作";
|
||||
}
|
||||
|
||||
@ -3,6 +3,8 @@ import { AppError, ErrorCode } from "@/server/core/errors";
|
||||
import {
|
||||
EMPTY_STORE_ACCOUNT_FILTERS,
|
||||
STORE_ACCOUNT_AUTHORIZATION_FILTER_OPTIONS,
|
||||
buildDepartedStoreAccountOwnerNames,
|
||||
resolveStoreAccountOwnerEmployment,
|
||||
getStoreAccountProfilePlatformForStoreName,
|
||||
STORE_ACCOUNT_PROFIT_CENTERS,
|
||||
STORE_ACCOUNT_PROFILE_PLATFORMS,
|
||||
@ -23,6 +25,7 @@ import {
|
||||
type StoreAccountFilters,
|
||||
type StoreAccountImportProgress,
|
||||
type StoreAccountPage,
|
||||
type StoreAccountRow,
|
||||
type StoreAccountOwnerOption,
|
||||
type StoreAccountType,
|
||||
type StoreAccountProfilePlatform,
|
||||
@ -47,6 +50,7 @@ import {
|
||||
} from "@/server/repositories/store-account-management.repository";
|
||||
import { permissionRoleRepository } from "@/server/repositories/permission-role.repository";
|
||||
import { storeAccountNotificationService } from "@/server/services/store-account-notification.service";
|
||||
import { storeAccountNotificationRepository } from "@/server/repositories/store-account-notification.repository";
|
||||
import {
|
||||
canRevealStoreAccountPassword,
|
||||
storeAccountPasswordAccessService,
|
||||
@ -155,6 +159,12 @@ type StoreAccountOwnerOptionReader = {
|
||||
listOwnerOptions(): Promise<{ items: StoreAccountOwnerOption[] }>;
|
||||
};
|
||||
|
||||
// 列表标注“店铺运营负责人已离职”用:按姓名批量查内部账号在职状态。
|
||||
type StoreAccountOwnerUserReader = Pick<
|
||||
typeof storeAccountNotificationRepository,
|
||||
"findUsersByNames"
|
||||
>;
|
||||
|
||||
export class StoreAccountManagementService {
|
||||
constructor(
|
||||
private readonly repository: StoreAccountManagementRepository = storeAccountManagementRepository,
|
||||
@ -162,6 +172,7 @@ export class StoreAccountManagementService {
|
||||
private readonly passwordAccessReader: StoreAccountPasswordAccessReader = storeAccountPasswordAccessService,
|
||||
private readonly authorizationReader: StoreAccountAuthorizationReader = storeAccountAuthorizationService,
|
||||
private readonly ownerOptionReader: StoreAccountOwnerOptionReader = supplyChainManagementOwnerConfigService,
|
||||
private readonly ownerUserReader: StoreAccountOwnerUserReader = storeAccountNotificationRepository,
|
||||
) {}
|
||||
|
||||
private async getPasswordViewContext(
|
||||
@ -175,6 +186,13 @@ export class StoreAccountManagementService {
|
||||
return { scope, rowAccess };
|
||||
}
|
||||
|
||||
// 负责人状态筛选用:候选名字取自筛选选项里的运营负责人清单,再批量查内部账号在职状态。
|
||||
private async resolveOwnerEmployment(candidateOwners: readonly string[]) {
|
||||
const names = [...new Set(candidateOwners.map((name) => name.trim()).filter(Boolean))];
|
||||
const users = names.length > 0 ? await this.ownerUserReader.findUsersByNames(names) : [];
|
||||
return resolveStoreAccountOwnerEmployment(users);
|
||||
}
|
||||
|
||||
async getFieldAccess(user: AuthUser) {
|
||||
const target = await supplyChainPermissionSettingsService.getUserAccess(
|
||||
user,
|
||||
@ -263,8 +281,13 @@ export class StoreAccountManagementService {
|
||||
);
|
||||
const authorizationFilter = splitFilterValues(filters.authorizationStatus);
|
||||
const hasAuthorizationFilter = authorizationFilter.length > 0;
|
||||
const ownerStatusFilter = filters.operationOwnerStatus.trim();
|
||||
const hasOwnerStatusFilter =
|
||||
ownerStatusFilter === "DEPARTED" || ownerStatusFilter === "ACTIVE";
|
||||
// 授权状态与负责人状态都不是店铺账号表的本列值,需要拉全量后在内存过滤。
|
||||
const needsFullScan = hasAuthorizationFilter || hasOwnerStatusFilter;
|
||||
const [result, storeNames, filterOptions, passwordView] = await Promise.all([
|
||||
hasAuthorizationFilter
|
||||
needsFullScan
|
||||
? this.repository.listAll({ filters }).then((rows) => ({ rows, total: rows.length }))
|
||||
: this.repository.listPage({
|
||||
skip: (page - 1) * pageSize,
|
||||
@ -278,24 +301,55 @@ export class StoreAccountManagementService {
|
||||
const authorizationStatusByStoreName = await this.authorizationReader.getStatusMap(
|
||||
result.rows.map((record) => record.storeName),
|
||||
);
|
||||
const filteredRows = hasAuthorizationFilter
|
||||
const ownerEmployment = hasOwnerStatusFilter
|
||||
? await this.resolveOwnerEmployment(filterOptions.operationOwner)
|
||||
: null;
|
||||
const filteredRows = needsFullScan
|
||||
? result.rows.filter((record) => {
|
||||
const status = authorizationStatusByStoreName.get(record.storeName.trim());
|
||||
return STORE_ACCOUNT_AUTHORIZATION_STATUSES.has(status ?? "")
|
||||
&& authorizationFilter.includes(status as string);
|
||||
if (hasAuthorizationFilter) {
|
||||
const status = authorizationStatusByStoreName.get(record.storeName.trim());
|
||||
if (
|
||||
!STORE_ACCOUNT_AUTHORIZATION_STATUSES.has(status ?? "")
|
||||
|| !authorizationFilter.includes(status as string)
|
||||
) return false;
|
||||
}
|
||||
if (hasOwnerStatusFilter && ownerEmployment) {
|
||||
const ownerName = record.operationOwner.trim();
|
||||
if (ownerStatusFilter === "DEPARTED" && !ownerEmployment.departedNames.has(ownerName)) {
|
||||
return false;
|
||||
}
|
||||
if (ownerStatusFilter === "ACTIVE" && !ownerEmployment.employedNames.has(ownerName)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
})
|
||||
: result.rows;
|
||||
const pageRows = hasAuthorizationFilter
|
||||
const pageRows = needsFullScan
|
||||
? filteredRows.slice((page - 1) * pageSize, page * pageSize)
|
||||
: filteredRows;
|
||||
const rows = pageRows.map((record) =>
|
||||
this.toRow(
|
||||
const ownerNames = [
|
||||
...new Set(
|
||||
pageRows.map((record) => record.operationOwner.trim()).filter(Boolean),
|
||||
),
|
||||
];
|
||||
const ownerUsers =
|
||||
ownerNames.length > 0
|
||||
? await this.ownerUserReader.findUsersByNames(ownerNames)
|
||||
: [];
|
||||
const departedOwnerNames = buildDepartedStoreAccountOwnerNames(ownerUsers);
|
||||
const rows = pageRows.map((record) => {
|
||||
const row = this.toRow(
|
||||
record,
|
||||
passwordView.rowAccess,
|
||||
passwordView.scope,
|
||||
authorizationStatusByStoreName.get(record.storeName.trim()) ?? null,
|
||||
),
|
||||
);
|
||||
);
|
||||
if (departedOwnerNames.has(record.operationOwner.trim())) {
|
||||
row.operationOwnerDeparted = true;
|
||||
}
|
||||
return row;
|
||||
});
|
||||
return {
|
||||
rows,
|
||||
storeNames,
|
||||
@ -308,10 +362,10 @@ export class StoreAccountManagementService {
|
||||
pageInfo: {
|
||||
page,
|
||||
pageSize,
|
||||
total: hasAuthorizationFilter ? filteredRows.length : result.total,
|
||||
total: needsFullScan ? filteredRows.length : result.total,
|
||||
totalPages: Math.max(
|
||||
1,
|
||||
Math.ceil((hasAuthorizationFilter ? filteredRows.length : result.total) / pageSize),
|
||||
Math.ceil((needsFullScan ? filteredRows.length : result.total) / pageSize),
|
||||
),
|
||||
},
|
||||
fieldAccess: passwordView.rowAccess,
|
||||
@ -1037,7 +1091,7 @@ export class StoreAccountManagementService {
|
||||
access: StoreAccountFieldAccess,
|
||||
passwordScope: StoreAccountPasswordScope = "DEFAULT",
|
||||
authorizationStatus: StoreAccountAuthorizationStatus | null = null,
|
||||
) {
|
||||
): StoreAccountRow {
|
||||
const value = (key: StoreAccountFieldKey, fallback = "") =>
|
||||
access[key] === "HIDDEN" ? "" : fallback;
|
||||
const canSeePassword =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user