Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c7a310ee7 | |||
| 764eeb2914 |
@@ -15,6 +15,8 @@ export interface CompanyItem {
|
||||
remark: string | null
|
||||
createdAt: string | null
|
||||
updatedAt: string | null
|
||||
/** 所属平台(V206):'amazon'|'jd';后端恒带值(列 NOT NULL DEFAULT 'amazon'),旧负载缺省不渲染。 */
|
||||
platform?: string
|
||||
}
|
||||
|
||||
/** 新建/改名的表单草稿。 */
|
||||
@@ -22,6 +24,8 @@ export interface CompanyDraft {
|
||||
companyName: string
|
||||
status?: number
|
||||
remark?: string | null
|
||||
/** 所属平台(V206):新建必带(页面从平台 tab 取),编辑显式下发,缺省后端不动。 */
|
||||
platform?: string
|
||||
}
|
||||
|
||||
export function text(value: unknown): string {
|
||||
@@ -48,5 +52,6 @@ export function toCompanyPayload(draft: CompanyDraft): Record<string, unknown> {
|
||||
const payload: Record<string, unknown> = { companyName: text(draft.companyName).trim() }
|
||||
if (typeof draft.status === 'number') payload.status = draft.status
|
||||
payload.remark = trimmedOrNull(draft.remark)
|
||||
if (draft.platform) payload.platform = draft.platform
|
||||
return payload
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export function toCompanyItem(raw: unknown): CompanyItem | null {
|
||||
const r = raw as Record<string, unknown>
|
||||
const id = numberOrNull(r.id)
|
||||
if (id === null) return null
|
||||
return {
|
||||
const item: CompanyItem = {
|
||||
id,
|
||||
companyName: text(r.company_name),
|
||||
// status 列 NOT NULL,取不到就是链路异常;未知一律按停用,不把异常状态当启用。
|
||||
@@ -27,6 +27,10 @@ export function toCompanyItem(raw: unknown): CompanyItem | null {
|
||||
createdAt: trimmedOrNull(r.created_at),
|
||||
updatedAt: trimmedOrNull(r.updated_at),
|
||||
}
|
||||
// platform 后端恒带(列 NOT NULL);旧负载/测试桩缺省就不渲染该键,字段形状与 users-model 一致。
|
||||
const platform = text(r.platform)
|
||||
if (platform) item.platform = platform
|
||||
return item
|
||||
}
|
||||
|
||||
/** 解析 GET /api/admin/companies:接受 data 为数组或 {items:[...]},success=false 抛后端文案。 */
|
||||
|
||||
@@ -4,8 +4,10 @@ import { toCompanyPayload, type CompanyDraft, type CompanyItem } from './compani
|
||||
|
||||
/** 公司目录(设计文档 §2.3)。GET 的可见范围由后端收窄:超管全部、公司内 admin 只自己公司。 */
|
||||
|
||||
export async function fetchCompanies(): Promise<CompanyItem[]> {
|
||||
const { data } = await http.get('/api/admin/companies')
|
||||
export async function fetchCompanies(platform?: string): Promise<CompanyItem[]> {
|
||||
const { data } = await http.get('/api/admin/companies', {
|
||||
params: platform ? { platform } : {},
|
||||
})
|
||||
return parseCompanyList(data)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/** 用户管理列表/分页 DTO(任务 41):纯逻辑,无框架依赖,与 Java AdminUserController 对齐。 */
|
||||
import type { AdminUser } from '../types/admin'
|
||||
import type { PlatformTabId } from '../config/platform-scope.ts'
|
||||
|
||||
export const USER_PAGE_DEFAULT_SIZE = 10
|
||||
export const USER_PAGE_MIN_PAGE = 1
|
||||
@@ -18,6 +19,8 @@ export interface UserListParams {
|
||||
/** 公司 tab 的当前公司;由页面从 store 传入,**不住在 UserFilterState 里**
|
||||
* (normalizeUserPageParams 白名单构造会把它丢掉,取值口只认 fetchUserList 的原始入参)。 */
|
||||
companyId?: number | null
|
||||
/** 平台 tab 的当前平台(V206);同 companyId 形状:白名单构造不收,从原始入参读。 */
|
||||
platform?: PlatformTabId
|
||||
}
|
||||
|
||||
/** 序列化到 GET /api/admin/users 的查询参数(Java snake_case)。 */
|
||||
@@ -30,6 +33,7 @@ export interface UserListQuery {
|
||||
admin_id?: number
|
||||
role?: string
|
||||
company_id?: number
|
||||
platform?: string
|
||||
}
|
||||
|
||||
/** 用户列表项即 AdminUser(与 Java AdminUserItemVo 字段对齐)。 */
|
||||
|
||||
@@ -18,6 +18,10 @@ export function toAdminUserItem(raw: unknown): AdminUser | null {
|
||||
const id = numberOrNull(r.id)
|
||||
if (id === null) return null
|
||||
const item: AdminUser = { id, username: text(r.username), role: text(r.role) }
|
||||
const quota = numberOrNull(r.jd_publish_quota)
|
||||
if (quota !== null) item.jdPublishQuota = quota
|
||||
const platform = text(r.platform)
|
||||
if (platform) item.platform = platform
|
||||
if (typeof r.is_admin === 'boolean') item.isAdmin = r.is_admin
|
||||
const createdById = numberOrNull(r.created_by_id)
|
||||
if (createdById !== null) item.createdById = createdById
|
||||
|
||||
@@ -15,6 +15,8 @@ export async function fetchUserList(params: Partial<UserListParams> = {}): Promi
|
||||
// normalizeUserPageParams 是白名单构造(只点名 page/pageSize/keyword/createdById/adminId/role),
|
||||
// 公司值必须从原始 params 读:写成 normalized.companyId 会 TS 绿、运行时恒 undefined。
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
// 平台值(V206)同 companyId 形状:白名单构造不收,只认原始入参。
|
||||
if (params.platform) query.platform = params.platform
|
||||
const { data } = await http.get('/api/admin/users', { params: query })
|
||||
return parseUserPage(data)
|
||||
}
|
||||
|
||||
@@ -15,20 +15,29 @@ export const PLATFORM_TABS: readonly PlatformTabDef[] = [
|
||||
{ id: 'jd', label: '京东' },
|
||||
]
|
||||
|
||||
/** 京东侧菜单的 menuKey 唯一清单(与 routes.ts 的 menuKey 逐字一致,用例钉住)。
|
||||
* 2026-11-16 用户按截图圈定四项;2026-11-17 加京东分类管理(用户口径「这边分组是
|
||||
* 京东的分组管理的而不是亚马逊的」——分类管理子菜单归京东侧,不与亚马逊侧混排)。
|
||||
/** 京东侧独占菜单的 menuKey 唯一清单(与 routes.ts 的 menuKey 逐字一致,用例钉住)。
|
||||
* 2026-11-17 加京东分类管理(用户口径「这边分组是京东的分组管理的而不是亚马逊的」——
|
||||
* 分类管理子菜单归京东侧,不与亚马逊侧混排)。
|
||||
* 后续京东新页面上线把 key 加进这里即可,清单外的 key(含店铺管理/生成记录等
|
||||
* 存量页)一律归亚马逊。 */
|
||||
* 存量页)一律归亚马逊或双侧清单。 */
|
||||
export const JD_MENU_KEYS: readonly string[] = [
|
||||
'admin_users',
|
||||
'admin_group_manage',
|
||||
'admin_companies',
|
||||
'admin_jd_database',
|
||||
'admin_jd_category_manage',
|
||||
]
|
||||
|
||||
/** menuKey → 平台归属:命中京东清单即 jd,其余(未知 key 在内)默认亚马逊。 */
|
||||
export function platformOfMenuKey(key: string): PlatformTabId {
|
||||
return JD_MENU_KEYS.includes(key) ? 'jd' : 'amazon'
|
||||
/** 双侧共用菜单(2026-11-17 用户口径「这些亚马逊这边也要有」):三个账号域页面在两个
|
||||
* 平台 tab 下都显示——同一套组件、按当前 tab 给接口传 platform,各自只看/管各自平台的
|
||||
* 账号、分组、公司(后端 V206 三表加列,存量默认亚马逊,京东侧数据在编辑弹窗里翻档)。 */
|
||||
export const BOTH_PLATFORM_MENU_KEYS: readonly string[] = [
|
||||
'admin_users',
|
||||
'admin_group_manage',
|
||||
'admin_companies',
|
||||
]
|
||||
|
||||
/** menuKey → 平台归属清单(唯一判定出口):京东独占 → ['jd'];双侧清单 → ['amazon','jd'];
|
||||
* 其余(未知 key 在内)默认亚马逊。 */
|
||||
export function platformsOfMenuKey(key: string): PlatformTabId[] {
|
||||
if (JD_MENU_KEYS.includes(key)) return ['jd']
|
||||
if (BOTH_PLATFORM_MENU_KEYS.includes(key)) return ['amazon', 'jd']
|
||||
return ['amazon']
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { joinAdminPath } from '@/config/app'
|
||||
import { pageTitleOf, topbarUserOf } from '@/layout/topbar-model'
|
||||
import { groupKeysForActive, toSidebarEntries } from '@/layout/menu-mapper'
|
||||
import { filterMenuTreeByPlatform, visiblePlatformsFor } from '@/layout/platform-menu-filter'
|
||||
import { PLATFORM_TABS, platformOfMenuKey } from '@/config/platform-scope'
|
||||
import { PLATFORM_TABS, platformsOfMenuKey } from '@/config/platform-scope'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import { firstVisiblePath } from '@/router/helpers'
|
||||
import {
|
||||
@@ -58,12 +58,15 @@ watch(
|
||||
)
|
||||
|
||||
// 直达 URL/面包屑跳到另一平台的页面时,tab 指示自动跟过去(与侧边栏保持一致)。
|
||||
// 双侧清单里的页面(账号域三页)两个 tab 都算归属:当前 tab 已含它就不动。
|
||||
watch(
|
||||
() => route.meta.menuKey as string | undefined,
|
||||
(menuKey) => {
|
||||
if (!menuKey) return
|
||||
const target = platformOfMenuKey(menuKey)
|
||||
if (target !== platformTab.active && visibleTabIds.value.includes(target)) {
|
||||
const owners = platformsOfMenuKey(menuKey)
|
||||
if (owners.includes(platformTab.active)) return
|
||||
const target = owners.find((platform) => visibleTabIds.value.includes(platform))
|
||||
if (target && target !== platformTab.active) {
|
||||
platformTab.setActive(target)
|
||||
}
|
||||
},
|
||||
@@ -71,11 +74,12 @@ watch(
|
||||
)
|
||||
|
||||
// 切到另一侧 tab 时当前页多半不在那边:跳到该侧第一个可见页;该侧为空(tab 不可见)则不动。
|
||||
// 双侧清单里的页面(账号域三页)切 tab 不跳转——页面自己按当前平台过滤数据。
|
||||
watch(
|
||||
() => platformTab.active,
|
||||
(tab) => {
|
||||
const menuKey = route.meta.menuKey as string | undefined
|
||||
if (!menuKey || platformOfMenuKey(menuKey) === tab) return
|
||||
if (!menuKey || platformsOfMenuKey(menuKey).includes(tab)) return
|
||||
const first = firstVisiblePath(filterMenuTreeByPlatform(session.menuTree, tab))
|
||||
if (first) void router.replace(first)
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { AdminMenuNode } from '../types/admin'
|
||||
import { PLATFORM_TABS, platformOfMenuKey } from '../config/platform-scope.ts'
|
||||
import { PLATFORM_TABS, platformsOfMenuKey } from '../config/platform-scope.ts'
|
||||
import type { PlatformTabId } from '../config/platform-scope.ts'
|
||||
import { firstVisiblePath } from '../router/helpers.ts'
|
||||
|
||||
@@ -7,10 +7,11 @@ import { firstVisiblePath } from '../router/helpers.ts'
|
||||
* 按平台 tab 过滤后端菜单树(2026-11-16「亚马逊/京东不混」):**只做显示分组,不做鉴权**——
|
||||
* 准入仍由 session.menuTree(后端按权限裁剪)与路由守卫负责,这里只是把当前用户已被授权的
|
||||
* 菜单按平台分到两个 tab 下展示。
|
||||
* 规则:叶子按 platformOfMenuKey(key) 留下;分组节点(admin_group_*)自身的 key 不参与平台
|
||||
* 判定,按「留住的子项数 > 0」决定去留——否则京东 tab 下「账号与权限」这类混合分组会被整组
|
||||
* 误剪。节点的 key/name/route/children 形状原样透传(浅拷贝不改写),toSidebarEntries、
|
||||
* groupKeysForActive 与面包屑都不受影响。
|
||||
* 规则:叶子按 platformsOfMenuKey(key) 是否包含当前平台留下(双侧清单里的账号域三页两个
|
||||
* tab 都显示);分组节点(admin_group_*)自身的 key 不参与平台判定,按「留住的子项数 > 0」
|
||||
* 决定去留——否则京东 tab 下「账号与权限」这类混合分组会被整组误剪。节点的 key/name/
|
||||
* route/children 形状原样透传(浅拷贝不改写),toSidebarEntries、groupKeysForActive 与
|
||||
* 面包屑都不受影响。
|
||||
*/
|
||||
export function filterMenuTreeByPlatform(
|
||||
nodes: AdminMenuNode[] | null | undefined,
|
||||
@@ -24,7 +25,7 @@ export function filterMenuTreeByPlatform(
|
||||
continue
|
||||
}
|
||||
if ((node.children || []).length > 0) continue
|
||||
if (platformOfMenuKey(node.key || '') === platform) filtered.push({ ...node })
|
||||
if (platformsOfMenuKey(node.key || '').includes(platform)) filtered.push({ ...node })
|
||||
}
|
||||
return filtered
|
||||
}
|
||||
|
||||
@@ -2,18 +2,21 @@
|
||||
/** 公司管理(设计文档 §2.3):列表 + 新建 + 改名/启停。
|
||||
* 可见范围由后端收窄(超管全部、公司内 admin 只自己公司);写操作仅超管,这里隐藏入口只是配合,
|
||||
* 真正的把关在 CompanyController,页面不得当作权限边界。 */
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
|
||||
import { formatDateTime } from '@/utils/datetime'
|
||||
import { fetchCompanies } from '@/api/companies'
|
||||
import { COMPANY_STATUS_ACTIVE, type CompanyItem } from '@/api/companies-dto'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import CompanyEditorDialog from './CompanyEditorDialog.vue'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
// 平台 tab(V206):公司列表按当前平台过滤,新建默认落当前平台。
|
||||
const platformTab = usePlatformTabStore()
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const rows = ref<CompanyItem[]>([])
|
||||
@@ -38,7 +41,7 @@ async function loadCompanies() {
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
rows.value = await fetchCompanies()
|
||||
rows.value = await fetchCompanies(platformTab.active)
|
||||
} catch (error) {
|
||||
loadFailure.value = error instanceof Error ? error.message : '公司列表加载失败'
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
@@ -57,6 +60,12 @@ function openEdit(company: CompanyItem) {
|
||||
editorVisible.value = true
|
||||
}
|
||||
|
||||
// 切平台 tab(V206)= 重新取数:公司归属按平台分列,两 tab 各看各的公司。
|
||||
watch(() => platformTab.active, () => {
|
||||
page.value = 1
|
||||
void loadCompanies()
|
||||
})
|
||||
|
||||
onMounted(loadCompanies)
|
||||
</script>
|
||||
|
||||
@@ -127,7 +136,7 @@ onMounted(loadCompanies)
|
||||
/>
|
||||
</section>
|
||||
|
||||
<CompanyEditorDialog v-model="editorVisible" :company="editingCompany" @saved="loadCompanies" />
|
||||
<CompanyEditorDialog v-model="editorVisible" :company="editingCompany" :platform="platformTab.active" @saved="loadCompanies" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import type { PlatformTabId } from '@/config/platform-scope'
|
||||
import { createCompany, updateCompany } from '@/api/companies'
|
||||
import {
|
||||
COMPANY_NAME_MAX_LENGTH,
|
||||
@@ -12,11 +13,11 @@ import {
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { actionableErrorText } from '@/components/admin-feedback'
|
||||
|
||||
/** 新建/编辑公司(改名 + 启停 + 备注);写操作仅超管可用,权限由后端把关。 */
|
||||
const props = defineProps<{ modelValue: boolean; company: CompanyItem | null }>()
|
||||
/** 新建/编辑公司(改名 + 启停 + 备注 + 所属平台 V206);写操作仅超管可用,权限由后端把关。 */
|
||||
const props = defineProps<{ modelValue: boolean; company: CompanyItem | null; platform?: PlatformTabId }>()
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'saved'): void }>()
|
||||
|
||||
const form = ref<CompanyDraft>({ companyName: '', status: COMPANY_STATUS_ACTIVE, remark: '' })
|
||||
const form = ref<CompanyDraft>({ companyName: '', status: COMPANY_STATUS_ACTIVE, remark: '', platform: 'amazon' })
|
||||
const errorText = ref('')
|
||||
const busy = ref(false)
|
||||
|
||||
@@ -25,8 +26,13 @@ watch(
|
||||
(open) => {
|
||||
if (!open) return
|
||||
form.value = props.company
|
||||
? { companyName: props.company.companyName, status: props.company.status, remark: props.company.remark || '' }
|
||||
: { companyName: '', status: COMPANY_STATUS_ACTIVE, remark: '' }
|
||||
? {
|
||||
companyName: props.company.companyName,
|
||||
status: props.company.status,
|
||||
remark: props.company.remark || '',
|
||||
platform: props.company.platform === 'jd' ? 'jd' : 'amazon',
|
||||
}
|
||||
: { companyName: '', status: COMPANY_STATUS_ACTIVE, remark: '', platform: props.platform ?? 'amazon' }
|
||||
errorText.value = ''
|
||||
},
|
||||
)
|
||||
@@ -71,6 +77,12 @@ async function save() {
|
||||
placeholder="请输入公司名称(全平台唯一)"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="所属平台">
|
||||
<el-radio-group v-model="form.platform">
|
||||
<el-radio-button value="amazon">亚马逊</el-radio-button>
|
||||
<el-radio-button value="jd">京东</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="form.status" style="width: 100%">
|
||||
<el-option :value="COMPANY_STATUS_ACTIVE" label="启用" />
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import type { PlatformTabId } from '@/config/platform-scope'
|
||||
import { submitCreateUser } from './user-create-adapter'
|
||||
import {
|
||||
createEmptyCreateUserForm,
|
||||
@@ -28,6 +29,8 @@ const props = defineProps<{
|
||||
operatorCompanyId?: number | null
|
||||
/** 当前公司 tab:这次建号落在哪家,就决定能建哪些角色。 */
|
||||
activeCompanyId?: number | null
|
||||
/** 当前平台 tab(V206):新号默认落当前平台,单选可改。 */
|
||||
platform?: PlatformTabId
|
||||
}>()
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'created'): void }>()
|
||||
|
||||
@@ -71,6 +74,8 @@ watch(
|
||||
form.expiresAt = ''
|
||||
// 预填当前 tab:跨公司时角色本来就只剩公司超管,而那一例必须带公司
|
||||
form.companyId = props.activeCompanyId ?? null
|
||||
// 预填当前平台 tab(V206):京东侧建的号默认归京东,亚马逊侧默认亚马逊。
|
||||
form.platform = props.platform ?? 'amazon'
|
||||
errors.username = undefined
|
||||
errors.password = undefined
|
||||
errors.companyId = undefined
|
||||
@@ -131,6 +136,12 @@ async function create(): Promise<void> {
|
||||
<el-option v-for="opt in roleChoices" :key="opt.value" :label="opt.label" :value="opt.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="所属平台">
|
||||
<el-radio-group v-model="form.platform">
|
||||
<el-radio-button value="amazon">亚马逊</el-radio-button>
|
||||
<el-radio-button value="jd">京东</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item
|
||||
v-if="operatorSuper && form.role === 'company_super_admin'"
|
||||
label="所属公司"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive, ref, watch } from 'vue'
|
||||
import type { AdminUser } from '@/types/admin'
|
||||
import type { PlatformTabId } from '@/config/platform-scope'
|
||||
import { mayCarryOwnExpiry } from './user-create-model'
|
||||
import { fillEditUserForm, validateEditUserForm, type EditUserForm, type EditUserFormErrors } from './user-edit-model'
|
||||
import { submitEditUser } from './user-edit-adapter'
|
||||
@@ -10,11 +11,12 @@ import { actionableErrorText } from '@/components/admin-feedback'
|
||||
import UserMenuAuthTree from './UserMenuAuthTree.vue'
|
||||
|
||||
/** companyId 由 UsersPage 把 companyTab.requestCompanyId 透传进来(本页的用户列表本来就由它筛 ⇒ 目标账号的公司
|
||||
* 就是 tab 选中的那家);弹窗自己不读 store,公司 tab 的取值口只留在页面组件那一处。 */
|
||||
const props = defineProps<{ modelValue: boolean; user: AdminUser | null; operatorSuper?: boolean; companyId?: number | null }>()
|
||||
* 就是 tab 选中的那家);弹窗自己不读 store,公司 tab 的取值口只留在页面组件那一处。
|
||||
* platform(V206)同理由页面透传:决定上架上限是否参与校验/下发(仅京东侧)。 */
|
||||
const props = defineProps<{ modelValue: boolean; user: AdminUser | null; operatorSuper?: boolean; companyId?: number | null; platform?: PlatformTabId }>()
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'updated'): void }>()
|
||||
|
||||
const form = reactive<EditUserForm>({ uid: 0, username: '', password: '', role: 'normal', columnIds: [], originalRole: '', expiresAt: '' })
|
||||
const form = reactive<EditUserForm>({ uid: 0, username: '', password: '', role: 'normal', columnIds: [], originalRole: '', expiresAt: '', jdPublishQuota: 5000, platform: 'amazon' })
|
||||
const errors = reactive<EditUserFormErrors>({})
|
||||
const busy = ref(false)
|
||||
const loadingAuth = ref(false)
|
||||
@@ -22,6 +24,9 @@ const loadingAuth = ref(false)
|
||||
const authReady = ref(false)
|
||||
/** 公司超管目标:角色单选隐藏(请求体也不带 role),只允许改密码/到期时间/菜单。 */
|
||||
const targetIsCompanySuperAdmin = computed(() => (props.user?.role || '').trim().toLowerCase() === 'company_super_admin')
|
||||
/** 上架上限只属京东口径(用户 2026-11-17:「只要在京东这边用户编辑里加就行,不需要在亚马逊那边」):
|
||||
* 亚马逊侧隐藏该项,且校验与下发都不带 quota——字段留后端不动。 */
|
||||
const includeQuota = computed(() => props.platform === 'jd')
|
||||
/** 公司超管目标的角色单选是隐藏的(改完仍是 company_super_admin),到期时间照旧可改;
|
||||
* 管理员改成普通账号时这一项消失,保存按「清空」下发(见 user-edit-model 的 roleAfter)。 */
|
||||
const expiryEditable = computed(() =>
|
||||
@@ -40,6 +45,9 @@ watch(
|
||||
form.columnIds = []
|
||||
form.originalRole = base.originalRole
|
||||
form.expiresAt = base.expiresAt
|
||||
form.jdPublishQuota = base.jdPublishQuota
|
||||
form.platform = base.platform
|
||||
errors.jdPublishQuota = undefined
|
||||
errors.password = undefined
|
||||
authReady.value = false
|
||||
void refreshAuth()
|
||||
@@ -71,12 +79,12 @@ async function save(): Promise<void> {
|
||||
showAdminFeedback('菜单权限尚未加载完成,请稍后重试', 'error')
|
||||
return
|
||||
}
|
||||
const { valid, errors: errs } = validateEditUserForm(form)
|
||||
const { valid, errors: errs } = validateEditUserForm(form, { includeQuota: includeQuota.value })
|
||||
Object.assign(errors, errs)
|
||||
if (!valid) return
|
||||
busy.value = true
|
||||
try {
|
||||
await submitEditUser(form)
|
||||
await submitEditUser(form, { includeQuota: includeQuota.value })
|
||||
showAdminFeedback('更新成功', 'success')
|
||||
emit('updated')
|
||||
close()
|
||||
@@ -120,6 +128,12 @@ async function save(): Promise<void> {
|
||||
<el-form-item v-if="targetIsCompanySuperAdmin" label="角色">
|
||||
<el-input model-value="公司超级管理员" readonly />
|
||||
</el-form-item>
|
||||
<el-form-item label="所属平台">
|
||||
<el-radio-group v-model="form.platform">
|
||||
<el-radio-button value="amazon">亚马逊</el-radio-button>
|
||||
<el-radio-button value="jd">京东</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="expiryEditable" label="到期时间(清空 = 永不过期;到期后该账号及其名下账号将停用)">
|
||||
<el-date-picker
|
||||
v-model="form.expiresAt"
|
||||
@@ -130,6 +144,9 @@ async function save(): Promise<void> {
|
||||
style="width: 240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="includeQuota && (targetIsCompanySuperAdmin || form.role === 'admin')" label="京东上架额度(0 表示不限)" :error="errors.jdPublishQuota">
|
||||
<el-input-number v-model="form.jdPublishQuota" :min="0" :max="2147483647" :precision="0" />
|
||||
</el-form-item>
|
||||
<el-form-item v-if="props.user && props.user.creatorUsername" label="所属管理员">
|
||||
<el-input :model-value="props.user.creatorUsername" readonly />
|
||||
</el-form-item>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import type { AdminUser } from '@/types/admin'
|
||||
import type { PlatformTabId } from '@/config/platform-scope'
|
||||
import {
|
||||
eligibleGroupMembers,
|
||||
groupMemberCandidateHint,
|
||||
@@ -13,11 +14,13 @@ import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { actionableErrorText } from '@/components/admin-feedback'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
|
||||
const props = defineProps<{ modelValue: boolean; group: ShopGroupItem | null; operatorSuper?: boolean }>()
|
||||
const props = defineProps<{ modelValue: boolean; group: ShopGroupItem | null; operatorSuper?: boolean; platform?: PlatformTabId }>()
|
||||
const emit = defineEmits<{ (e: 'update:modelValue', v: boolean): void; (e: 'saved'): void }>()
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
const groupName = ref('')
|
||||
/** 所属平台(V206):新建默认当前平台 tab,编辑回填分组原值,单选可翻档。 */
|
||||
const groupPlatform = ref<PlatformTabId>('amazon')
|
||||
const memberIds = ref<number[]>([])
|
||||
const errorText = ref('')
|
||||
const busy = ref(false)
|
||||
@@ -48,6 +51,9 @@ watch(
|
||||
if (props.group) {
|
||||
groupName.value = props.group.name
|
||||
memberIds.value = props.group.memberUserIds ?? []
|
||||
groupPlatform.value = props.group.platform === 'jd' ? 'jd' : 'amazon'
|
||||
} else {
|
||||
groupPlatform.value = props.platform ?? 'amazon'
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -76,7 +82,7 @@ async function save(): Promise<void> {
|
||||
busy.value = true
|
||||
try {
|
||||
if (props.group) {
|
||||
await updateShopGroup(props.group.id, groupName.value, memberIds.value)
|
||||
await updateShopGroup(props.group.id, groupName.value, memberIds.value, groupPlatform.value)
|
||||
showAdminFeedback('更新成功', 'success')
|
||||
} else {
|
||||
// 对齐 admin:组长恒为当前登录用户,提交 createdBy=当前用户 id。
|
||||
@@ -85,7 +91,7 @@ async function save(): Promise<void> {
|
||||
showAdminFeedback('无法获取当前登录用户,请重新登录', 'error')
|
||||
return
|
||||
}
|
||||
await createShopGroup(groupName.value, memberIds.value, operatorId)
|
||||
await createShopGroup(groupName.value, memberIds.value, operatorId, groupPlatform.value)
|
||||
showAdminFeedback('创建成功', 'success')
|
||||
}
|
||||
emit('saved')
|
||||
@@ -113,6 +119,12 @@ onMounted(loadCandidates)
|
||||
<el-form-item label="分组名称" :error="errorText || undefined">
|
||||
<el-input v-model="groupName" placeholder="请输入分组名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="所属平台">
|
||||
<el-radio-group v-model="groupPlatform">
|
||||
<el-radio-button value="amazon">亚马逊</el-radio-button>
|
||||
<el-radio-button value="jd">京东</el-radio-button>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="组长">
|
||||
<el-input :model-value="leaderUsername" readonly placeholder="当前登录用户" />
|
||||
</el-form-item>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import { deleteShopGroup, fetchShopGroups } from './shop-group-api'
|
||||
import type { ShopGroupItem } from './shop-group-model'
|
||||
@@ -16,6 +17,8 @@ import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
const companyTab = useCompanyTabStore()
|
||||
// 平台 tab(V206):分组列表按当前平台过滤,新建默认落当前平台。
|
||||
const platformTab = usePlatformTabStore()
|
||||
const loading = ref(false)
|
||||
const loadFailure = ref('')
|
||||
const rows = ref<ShopGroupItem[]>([])
|
||||
@@ -52,7 +55,7 @@ async function loadGroups() {
|
||||
loading.value = true
|
||||
loadFailure.value = ''
|
||||
try {
|
||||
rows.value = await fetchShopGroups(companyTab.requestCompanyId)
|
||||
rows.value = await fetchShopGroups(companyTab.requestCompanyId, platformTab.active)
|
||||
} catch (error) {
|
||||
loadFailure.value = error instanceof Error ? error.message : '数据权限分组加载失败'
|
||||
showAdminFeedback(loadFailure.value, 'error')
|
||||
@@ -64,6 +67,12 @@ async function loadGroups() {
|
||||
// 切公司 = 重新取数(G1 的 pageFiles 断言盯着这一条)。
|
||||
watch(() => companyTab.activeId, () => void loadGroups())
|
||||
|
||||
// 切平台 tab(V206)= 重新取数:分组归属按平台分列,两 tab 各看各的分组。
|
||||
watch(() => platformTab.active, () => {
|
||||
page.value = 1
|
||||
void loadGroups()
|
||||
})
|
||||
|
||||
function openCreate() {
|
||||
editingGroup.value = null
|
||||
editorVisible.value = true
|
||||
@@ -164,6 +173,7 @@ onMounted(loadGroups)
|
||||
v-model="editorVisible"
|
||||
:group="editingGroup"
|
||||
:operator-super="isSuperAdmin"
|
||||
:platform="platformTab.active"
|
||||
@saved="loadGroups"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { AdminUser } from '@/types/admin'
|
||||
import { roleLabel } from '@/types/admin'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import { deleteUser, fetchUserList, setUserDisabled } from '@/api/users'
|
||||
import { fetchCompanies } from '@/api/companies'
|
||||
import { createUserFilterState, toUserListParams, type UserFilterState } from './users-filter'
|
||||
@@ -26,6 +27,10 @@ import { createLatestRequestGate } from '@/utils/latest-request'
|
||||
|
||||
const session = useAdminSessionStore()
|
||||
const companyTab = useCompanyTabStore()
|
||||
// 平台 tab(V206):账号域三页两 tab 共用本组件,列表/新建/编辑都按当前平台收放。
|
||||
const platformTab = usePlatformTabStore()
|
||||
/** 京东侧标记:上架上限列与编辑入口只在京东 tab 显示(用户口径「不需要在亚马逊那边」)。 */
|
||||
const isJdSide = computed(() => platformTab.active === 'jd')
|
||||
const loading = ref(false)
|
||||
const loadError = ref('')
|
||||
// 用户列表竞态门(S1-F4):快速切公司/翻页只让最后一次响应落地
|
||||
@@ -65,10 +70,16 @@ function editableOf(row: AdminUser): boolean {
|
||||
return editableBy(row.role, operatorRole.value)
|
||||
}
|
||||
|
||||
/** 列表请求参数 = 用户填的筛选态 + 当前公司。公司值每次现取、不写进 filters:
|
||||
* 它由上方 tab 决定而不是用户填的筛选项,住进 filters 就等于多出第二个取值口径(Store 之外再长一个)。 */
|
||||
/** 上架上限列文案(仅京东侧渲染该列):null=旧数据未配('-'),0=不限,其余为具体条数。 */
|
||||
function quotaCellText(row: AdminUser): string {
|
||||
if (row.jdPublishQuota == null) return '-'
|
||||
return row.jdPublishQuota === 0 ? '不限' : String(row.jdPublishQuota)
|
||||
}
|
||||
|
||||
/** 列表请求参数 = 用户填的筛选态 + 当前公司 + 当前平台。公司/平台值每次现取、不写进 filters:
|
||||
* 它们由上方 tab 决定而不是用户填的筛选项,住进 filters 就等于多出第二个取值口径(Store 之外再长一个)。 */
|
||||
function listParams() {
|
||||
return { ...toUserListParams(filters), companyId: companyTab.requestCompanyId }
|
||||
return { ...toUserListParams(filters), companyId: companyTab.requestCompanyId, platform: platformTab.active }
|
||||
}
|
||||
|
||||
async function loadUsers() {
|
||||
@@ -171,6 +182,14 @@ function goJump() {
|
||||
// ② 用户名全平台唯一(V143 的唯一索引),留着上一家填的关键字去筛新一家 ⇒ 必然空页,而输入框还显示着那个值。
|
||||
watch(() => companyTab.activeId, () => { filters.createdByAdminId = null; filters.keyword = ''; filters.page = 1; void loadUsers() })
|
||||
|
||||
// 切平台 tab(V206)= 同样的重取数:列表按平台过滤,候选/关键字跨平台无意义,一并清掉。
|
||||
watch(() => platformTab.active, () => {
|
||||
filters.createdByAdminId = null
|
||||
filters.keyword = ''
|
||||
filters.page = 1
|
||||
void loadUsers()
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
void loadUsers()
|
||||
// 公司目录仅站点超管拉取(建「公司超级管理员」时选公司用);非超管不发这个请求,后端 403 兜底
|
||||
@@ -232,6 +251,7 @@ onMounted(() => {
|
||||
<th style="width: 140px">角色</th>
|
||||
<th style="width: 160px">所属管理员</th>
|
||||
<th style="width: 160px">到期时间</th>
|
||||
<th v-if="isJdSide" style="width: 110px">上架上限</th>
|
||||
<th style="width: 90px">状态</th>
|
||||
<th style="width: 180px">创建时间</th>
|
||||
<th style="width: 180px">更新时间</th>
|
||||
@@ -248,6 +268,7 @@ onMounted(() => {
|
||||
<td :class="{ 'expiry-cell-expired': formatExpiryCell(row).expired }">
|
||||
{{ formatExpiryCell(row).text }}
|
||||
</td>
|
||||
<td v-if="isJdSide">{{ quotaCellText(row) }}</td>
|
||||
<td class="status-cell" :class="{ 'status-cell-disabled': !!row.disabledAt }" :title="row.disabledAt ? `停用于 ${row.disabledAt}` : undefined">
|
||||
{{ disabledBadgeText(row) }}
|
||||
</td>
|
||||
@@ -285,10 +306,10 @@ onMounted(() => {
|
||||
</tr>
|
||||
</template>
|
||||
<tr v-else-if="loading">
|
||||
<td colspan="9" class="empty-tip">加载中...</td>
|
||||
<td :colspan="isJdSide ? 10 : 9" class="empty-tip">加载中...</td>
|
||||
</tr>
|
||||
<tr v-else>
|
||||
<td colspan="9" class="empty-tip">{{ userListEmptyHint() }}</td>
|
||||
<td :colspan="isJdSide ? 10 : 9" class="empty-tip">{{ userListEmptyHint() }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -305,9 +326,10 @@ onMounted(() => {
|
||||
:company-options="companyOptions"
|
||||
:operator-company-id="operatorCompanyId"
|
||||
:active-company-id="companyTab.requestCompanyId"
|
||||
:platform="platformTab.active"
|
||||
@created="loadUsers"
|
||||
/>
|
||||
<EditUserDialog v-model="editVisible" :user="editUser" :operator-super="isSuperAdmin" :company-id="companyTab.requestCompanyId" @updated="loadUsers" />
|
||||
<EditUserDialog v-model="editVisible" :user="editUser" :operator-super="isSuperAdmin" :company-id="companyTab.requestCompanyId" :platform="platformTab.active" @updated="loadUsers" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -11,22 +11,33 @@ import {
|
||||
|
||||
export const SHOP_GROUPS_ENDPOINT = '/api/admin/shop-manages/groups'
|
||||
|
||||
export async function fetchShopGroups(companyId?: number | null): Promise<ShopGroupItem[]> {
|
||||
const { data } = await http.get<unknown>(SHOP_GROUPS_ENDPOINT, { params: companyId != null ? { company_id: companyId } : {} })
|
||||
/** 列表:company_id 收公司口径(钉住的取值口),platform 收平台 tab 口径(V206),都缺省就不发。 */
|
||||
export async function fetchShopGroups(companyId?: number | null, platform?: string): Promise<ShopGroupItem[]> {
|
||||
const { data } = await http.get<unknown>(SHOP_GROUPS_ENDPOINT, {
|
||||
params: {
|
||||
...(companyId != null ? { company_id: companyId } : {}),
|
||||
...(platform ? { platform } : {}),
|
||||
},
|
||||
})
|
||||
return parseShopGroupList(data)
|
||||
}
|
||||
|
||||
/** 新建分组:POST /api/admin/shop-manages/groups(创建人 = 组长 = 当前操作者)。 */
|
||||
export async function createShopGroup(name: string, memberUserIds: number[], createdById: number): Promise<ShopGroupItem> {
|
||||
const { data } = await http.post<unknown>(SHOP_GROUPS_ENDPOINT, toShopGroupCreatePayload(name, memberUserIds, createdById))
|
||||
export async function createShopGroup(
|
||||
name: string,
|
||||
memberUserIds: number[],
|
||||
createdById: number,
|
||||
platform?: string,
|
||||
): Promise<ShopGroupItem> {
|
||||
const { data } = await http.post<unknown>(SHOP_GROUPS_ENDPOINT, toShopGroupCreatePayload(name, memberUserIds, createdById, platform))
|
||||
const created = parseShopGroupItem(unwrap<unknown>(data))
|
||||
if (!created) throw new Error('创建分组响应异常:缺少分组数据')
|
||||
return created
|
||||
}
|
||||
|
||||
/** 更新分组:PUT /api/admin/shop-manages/groups/{id}。 */
|
||||
export async function updateShopGroup(id: number, name: string, memberUserIds: number[]): Promise<ShopGroupItem> {
|
||||
const { data } = await http.put<unknown>(`${SHOP_GROUPS_ENDPOINT}/${id}`, toShopGroupUpdatePayload(name, memberUserIds))
|
||||
export async function updateShopGroup(id: number, name: string, memberUserIds: number[], platform?: string): Promise<ShopGroupItem> {
|
||||
const { data } = await http.put<unknown>(`${SHOP_GROUPS_ENDPOINT}/${id}`, toShopGroupUpdatePayload(name, memberUserIds, platform))
|
||||
const updated = parseShopGroupItem(unwrap<unknown>(data))
|
||||
if (!updated) throw new Error('更新分组响应异常:缺少分组数据')
|
||||
return updated
|
||||
|
||||
@@ -12,6 +12,8 @@ export interface ShopGroupItem {
|
||||
memberUserIds?: number[]
|
||||
createdAt?: string
|
||||
updatedAt?: string
|
||||
/** 所属平台(V206):'amazon'|'jd';旧负载缺省不渲染该键。 */
|
||||
platform?: string
|
||||
}
|
||||
|
||||
export interface ShopGroupFormErrors {
|
||||
@@ -53,6 +55,8 @@ export function parseShopGroupItem(raw: unknown): ShopGroupItem | null {
|
||||
if (createdAt) item.createdAt = createdAt
|
||||
const updatedAt = text(record.updatedAt ?? record.updated_at)
|
||||
if (updatedAt) item.updatedAt = updatedAt
|
||||
const platform = text(record.platform)
|
||||
if (platform) item.platform = platform
|
||||
return item
|
||||
}
|
||||
|
||||
@@ -79,18 +83,34 @@ export function validateShopGroupForm(name: string): ShopGroupFormErrors {
|
||||
return errors
|
||||
}
|
||||
|
||||
/** 创建载荷:groupName + 成员 + 创建人(= 组长,当前操作者)。 */
|
||||
/** 创建载荷:groupName + 成员 + 创建人(= 组长,当前操作者)+ 所属平台(V206,缺省不下发)。 */
|
||||
export function toShopGroupCreatePayload(
|
||||
name: string,
|
||||
memberUserIds: number[],
|
||||
createdById: number,
|
||||
): { groupName: string; memberUserIds: number[]; createdById: number } {
|
||||
return { groupName: text(name), memberUserIds: dedupeIds(memberUserIds), createdById }
|
||||
platform?: string,
|
||||
): { groupName: string; memberUserIds: number[]; createdById: number; platform?: string } {
|
||||
const payload: { groupName: string; memberUserIds: number[]; createdById: number; platform?: string } = {
|
||||
groupName: text(name),
|
||||
memberUserIds: dedupeIds(memberUserIds),
|
||||
createdById,
|
||||
}
|
||||
if (platform) payload.platform = platform
|
||||
return payload
|
||||
}
|
||||
|
||||
/** 更新载荷:groupName + 成员(组长/创建人不可改)。 */
|
||||
export function toShopGroupUpdatePayload(name: string, memberUserIds: number[]): { groupName: string; memberUserIds: number[] } {
|
||||
return { groupName: text(name), memberUserIds: dedupeIds(memberUserIds) }
|
||||
/** 更新载荷:groupName + 成员 + 所属平台(V206;组长/创建人不可改)。 */
|
||||
export function toShopGroupUpdatePayload(
|
||||
name: string,
|
||||
memberUserIds: number[],
|
||||
platform?: string,
|
||||
): { groupName: string; memberUserIds: number[]; platform?: string } {
|
||||
const payload: { groupName: string; memberUserIds: number[]; platform?: string } = {
|
||||
groupName: text(name),
|
||||
memberUserIds: dedupeIds(memberUserIds),
|
||||
}
|
||||
if (platform) payload.platform = platform
|
||||
return payload
|
||||
}
|
||||
|
||||
/** 组员候选用户(对齐 admin.js getEligibleShopManageGroupUsers 的过滤语义)。 */
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/** 新建用户表单模型(任务 45):纯逻辑,镜像 Java AdminUserCreateRequest 字段与后端校验。 */
|
||||
import type { PlatformTabId } from '../../config/platform-scope.ts'
|
||||
|
||||
export const CREATE_USERNAME_MIN_LEN = 2
|
||||
export const CREATE_PASSWORD_MIN_LEN = 6
|
||||
@@ -21,6 +22,8 @@ export interface CreateUserForm {
|
||||
expiresAt: string
|
||||
/** 所属公司 id:仅 role=company_super_admin 时由站点超管必选(2026-10-05 需求)。 */
|
||||
companyId?: number | null
|
||||
/** 所属平台(V206):弹窗打开时预填当前平台 tab,单选可改。 */
|
||||
platform: PlatformTabId
|
||||
}
|
||||
|
||||
export interface CreateUserFormErrors {
|
||||
@@ -43,10 +46,12 @@ export interface CreateUserPayload {
|
||||
* 反向钉(company-user-create.test.ts)唯一豁免的例外:公司超管必须落指定公司,
|
||||
* 否则会静默落操作者自己的公司(公司 1),用户需求就是给别家公司开超管。 */
|
||||
companyId?: number
|
||||
/** 所属平台(V206):恒下发(弹窗单选默认当前平台 tab),缺省后端落 amazon。 */
|
||||
platform: PlatformTabId
|
||||
}
|
||||
|
||||
export function createEmptyCreateUserForm(): CreateUserForm {
|
||||
return { username: '', password: '', role: 'normal', columnIds: [], createdBy: null, expiresAt: '', companyId: null }
|
||||
return { username: '', password: '', role: 'normal', columnIds: [], createdBy: null, expiresAt: '', companyId: null, platform: 'amazon' }
|
||||
}
|
||||
|
||||
/** 未知/空白/超管角色归一:admin/company_super_admin/normal 白名单,其余归 normal。 */
|
||||
@@ -147,6 +152,7 @@ export function toCreateUserRequest(form: CreateUserForm): CreateUserPayload {
|
||||
password: form.password || '',
|
||||
role,
|
||||
columnIds: Array.isArray(form.columnIds) ? form.columnIds.slice() : [],
|
||||
platform: form.platform,
|
||||
}
|
||||
if (payload.role === 'normal' && form.createdBy != null) {
|
||||
payload.createdById = form.createdBy
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
toEditUserUpdateRequest,
|
||||
validateEditUserForm,
|
||||
type EditUserForm,
|
||||
type EditUserFormOptions,
|
||||
} from './user-edit-model'
|
||||
|
||||
/** Java AdminUserController.updateUser 端点前缀。 */
|
||||
@@ -12,12 +13,13 @@ export const EDIT_USER_ENDPOINT = '/api/admin/user'
|
||||
|
||||
/**
|
||||
* 提交编辑用户:先校验(不通过抛首条错误),再序列化 PUT;http/后端失败交由调用方提示。
|
||||
* options.includeQuota=false(亚马逊侧)不下发上架上限——校验与序列化同口径。
|
||||
*/
|
||||
export async function submitEditUser(form: EditUserForm): Promise<void> {
|
||||
const { valid, errors } = validateEditUserForm(form)
|
||||
export async function submitEditUser(form: EditUserForm, options: EditUserFormOptions = {}): Promise<void> {
|
||||
const { valid, errors } = validateEditUserForm(form, options)
|
||||
if (!valid) {
|
||||
throw new Error(Object.values(errors)[0] || '编辑用户表单校验未通过')
|
||||
}
|
||||
const { data } = await http.put<unknown>(`${EDIT_USER_ENDPOINT}/${form.uid}`, toEditUserUpdateRequest(form))
|
||||
const { data } = await http.put<unknown>(`${EDIT_USER_ENDPOINT}/${form.uid}`, toEditUserUpdateRequest(form, options))
|
||||
unwrap<unknown>(data)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
/** 编辑用户表单回填模型(任务 47):从用户行回填可编辑表单,镜像 Java AdminUserUpdateRequest。 */
|
||||
import type { AdminUser } from '../../types/admin'
|
||||
import type { PlatformTabId } from '../../config/platform-scope.ts'
|
||||
import { CREATE_PASSWORD_MIN_LEN, mayCarryOwnExpiry } from './user-create-model.ts'
|
||||
|
||||
/** 编辑可选角色:站点/公司超管不可改,未知归 normal;后端只收 admin|normal。 */
|
||||
export type EditUserRole = 'normal' | 'admin'
|
||||
|
||||
export interface EditUserForm {
|
||||
jdPublishQuota: number
|
||||
uid: number
|
||||
/** 仅展示用,后端不支持改用户名。 */
|
||||
username: string
|
||||
@@ -18,9 +20,12 @@ export interface EditUserForm {
|
||||
originalRole: string
|
||||
/** 到期时间(yyyy-MM-dd HH:mm:ss);空串 = 永不过期。null = 后端本来就无到期。 */
|
||||
expiresAt: string
|
||||
/** 所属平台(V206):单选可翻档,未知/缺省归亚马逊(存量默认)。 */
|
||||
platform: PlatformTabId
|
||||
}
|
||||
|
||||
export interface EditUserFormErrors {
|
||||
jdPublishQuota?: string
|
||||
password?: string
|
||||
}
|
||||
|
||||
@@ -28,10 +33,13 @@ export interface EditUserFormErrors {
|
||||
export interface EditUserUpdateRequest {
|
||||
/** 目标是公司超管时不携带(防止表单把公司超管误降级);站点超管改其密码/到期时间即可。 */
|
||||
role?: EditUserRole
|
||||
jdPublishQuota?: number
|
||||
columnIds: number[]
|
||||
password?: string
|
||||
/** 到期时间:空串=清除(恢复永不过期),有值=改期;总是下发(与后端"传了就更新"对齐)。 */
|
||||
expiresAt: string
|
||||
/** 所属平台(V206):总是下发(弹窗单选恒渲染),翻档即把记录挪到另一平台的列表。 */
|
||||
platform: PlatformTabId
|
||||
}
|
||||
|
||||
/** 行角色 → 可编辑角色:仅 admin 映射 admin,其余(含 unknown)归 normal。 */
|
||||
@@ -71,22 +79,38 @@ export function fillEditUserForm(user: AdminUser): EditUserForm {
|
||||
const role = typeof user.role === 'string' ? user.role.trim() : ''
|
||||
return {
|
||||
uid: user.id,
|
||||
jdPublishQuota: user.jdPublishQuota ?? 5000,
|
||||
username: user.username || '',
|
||||
password: '',
|
||||
role: editRoleOf(role),
|
||||
columnIds: [],
|
||||
originalRole: role,
|
||||
expiresAt: normalizeExpiryForPicker(user.expiresAt),
|
||||
platform: user.platform === 'jd' ? 'jd' : 'amazon',
|
||||
}
|
||||
}
|
||||
|
||||
/** 编辑表单校验选项:includeQuota=false(亚马逊侧)跳过上架上限校验——该项不下发。 */
|
||||
export interface EditUserFormOptions {
|
||||
/** 是否参与上架上限(jd_publish_quota)的校验与下发;缺省 true(京东侧)。 */
|
||||
includeQuota?: boolean
|
||||
}
|
||||
|
||||
/** 编辑表单校验:密码可留空(不改),非空时须达到最小长度。 */
|
||||
export function validateEditUserForm(form: EditUserForm): { valid: boolean; errors: EditUserFormErrors } {
|
||||
export function validateEditUserForm(
|
||||
form: EditUserForm,
|
||||
options: EditUserFormOptions = {},
|
||||
): { valid: boolean; errors: EditUserFormErrors } {
|
||||
const errors: EditUserFormErrors = {}
|
||||
const password = form.password || ''
|
||||
if (password && password.length < CREATE_PASSWORD_MIN_LEN) {
|
||||
errors.password = `密码至少${CREATE_PASSWORD_MIN_LEN}个字符,留空则不修改`
|
||||
}
|
||||
if (options.includeQuota !== false &&
|
||||
(form.role === 'admin' || form.originalRole === 'company_super_admin') &&
|
||||
(!Number.isInteger(form.jdPublishQuota) || form.jdPublishQuota < 0 || form.jdPublishQuota > 2147483647)) {
|
||||
errors.jdPublishQuota = '请输入 0 至 2147483647 的整数'
|
||||
}
|
||||
return { valid: Object.keys(errors).length === 0, errors }
|
||||
}
|
||||
|
||||
@@ -96,8 +120,11 @@ export function validateEditUserForm(form: EditUserForm): { valid: boolean; erro
|
||||
* <p>expiresAt 按「改完之后的角色」决定:目标角色不能带自己的到期时间时发空串=清空
|
||||
* (后端 400 闸门只拦「有值」,空串走既有的清除分支)。公司超管目标不带 role,
|
||||
* 它的 roleAfter 就是 company_super_admin,续费那条空串不会被误当成清空。</p>
|
||||
*
|
||||
* <p>options.includeQuota=false(亚马逊侧编辑)不下发 jdPublishQuota——上架上限是京东
|
||||
* 口径,亚马逊侧不显示也不改它(用户口径 2026-11-17);platform 恒下发(单选恒渲染)。</p>
|
||||
*/
|
||||
export function toEditUserUpdateRequest(form: EditUserForm): EditUserUpdateRequest {
|
||||
export function toEditUserUpdateRequest(form: EditUserForm, options: EditUserFormOptions = {}): EditUserUpdateRequest {
|
||||
const originalRole = (form.originalRole || '').trim().toLowerCase()
|
||||
if (originalRole === 'super_admin') {
|
||||
throw new Error('不能修改超级管理员')
|
||||
@@ -110,10 +137,14 @@ export function toEditUserUpdateRequest(form: EditUserForm): EditUserUpdateReque
|
||||
const request: EditUserUpdateRequest = {
|
||||
columnIds: Array.isArray(form.columnIds) ? form.columnIds.slice() : [],
|
||||
expiresAt: mayCarryOwnExpiry(roleAfter) ? (form.expiresAt || '').trim() : '',
|
||||
platform: form.platform,
|
||||
}
|
||||
if (keepsRole) {
|
||||
request.role = nextRole
|
||||
}
|
||||
if (options.includeQuota !== false && (roleAfter === 'admin' || roleAfter === 'company_super_admin')) {
|
||||
request.jdPublishQuota = form.jdPublishQuota
|
||||
}
|
||||
const password = form.password || ''
|
||||
if (password) request.password = password
|
||||
return request
|
||||
|
||||
@@ -4,9 +4,12 @@
|
||||
export type AdminRole = 'super_admin' | 'company_super_admin' | 'admin' | 'normal'
|
||||
|
||||
export interface AdminUser {
|
||||
jdPublishQuota?: number
|
||||
id: number
|
||||
username: string
|
||||
role: string
|
||||
/** 所属平台(V206):'amazon'|'jd',存量默认亚马逊;账号域三页按当前平台 tab 过滤/归类。 */
|
||||
platform?: string
|
||||
/** 1 为管理员标志位;role 为空时可据此推断角色。 */
|
||||
isAdmin?: boolean
|
||||
createdById?: number | null
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -24,13 +24,13 @@ function form(overrides: Record<string, unknown> = {}) {
|
||||
return { ...createEmptyCreateUserForm(), username: 'zhangsan', password: 'secret123', ...overrides }
|
||||
}
|
||||
|
||||
test('空表单默认没有公司、没有到期时间', () => {
|
||||
test('空表单默认没有公司、没有到期时间(平台默认亚马逊 = 存量口径,V206)', () => {
|
||||
const blank = createEmptyCreateUserForm()
|
||||
assert.equal(blank.companyId ?? null, null, 'companyId 默认 null(仅公司超管角色使用)')
|
||||
assert.equal(blank.expiresAt, '', '到期时间默认空 = 永不过期')
|
||||
assert.deepEqual(
|
||||
{ ...blank, companyId: null, expiresAt: '' },
|
||||
{ username: '', password: '', role: 'normal', columnIds: [], createdBy: null, companyId: null, expiresAt: '' },
|
||||
{ username: '', password: '', role: 'normal', columnIds: [], createdBy: null, companyId: null, expiresAt: '', platform: 'amazon' },
|
||||
)
|
||||
})
|
||||
|
||||
@@ -51,6 +51,8 @@ test('请求体:admin/normal 一律不带 companyId;公司超管必须带且
|
||||
password: 'secret123',
|
||||
role: 'normal',
|
||||
columnIds: [3, 1],
|
||||
// V206:所属平台恒下发(弹窗单选默认当前平台 tab,空表单缺省亚马逊)。
|
||||
platform: 'amazon',
|
||||
})
|
||||
// 所属管理员仍按原语义携带(仅 normal 角色)
|
||||
assert.equal(toCreateUserRequest(form({ role: 'normal', createdBy: 5 })).createdById, 5)
|
||||
|
||||
@@ -88,11 +88,13 @@ test('账号页与顶栏的源码里公司维度已摘干净', () => {
|
||||
'拉公司目录必须按站点超管门控,非超管不发这个请求(后端 403 兜底)')
|
||||
|
||||
// 「删了列忘了改占位行 colspan」是这类改动最常留下的残行:按表头列数交叉核对
|
||||
// (`<th` 是 `<thead` 的前缀,必须带上后随字符才数得准)
|
||||
// (`<th` 是 `<thead` 的前缀,必须带上后随字符才数得准)。
|
||||
// 2026-11-17 V206:上架上限列 v-if="isJdSide" 按平台动态渲染 ⇒ 表头数 10(含源码里的 v-if th),
|
||||
// 占位行走 :colspan 动态绑定;字面量 colspan 在动态列下必然错位一半的 tab,反向钉死。
|
||||
const headers = (page.match(/<th[\s>]/g) || []).length
|
||||
const spans = [...page.matchAll(/colspan="(\d+)"/g)].map((m) => Number(m[1]))
|
||||
assert.ok(spans.length >= 1, '列表 tbody 没有 colspan 占位行')
|
||||
for (const span of spans) assert.equal(span, headers, `占位行 colspan=${span} 与表头列数 ${headers} 不符`)
|
||||
assert.equal(headers, 10, `用户列表表头应为 10 列(9 列存量 + 京东侧上架上限 v-if 列),实际 ${headers}`)
|
||||
assert.match(page, /:colspan="isJdSide \? 10 : 9"/, '空态占位行必须按平台动态切 colspan(静态值与动态列数错位一半 tab)')
|
||||
assert.equal(/colspan="\d+"/.test(page), false, '动态列下不许再留字面量 colspan(必有一侧 tab 列数对不上)')
|
||||
|
||||
const dialog = readSource('src/pages/account/CreateUserDialog.vue')
|
||||
assert.match(dialog, /operatorSuper && form\.role === 'company_super_admin'/,
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { fillEditUserForm, toEditUserUpdateRequest, validateEditUserForm } from '../src/pages/account/user-edit-model.ts'
|
||||
|
||||
test('京东上架额度回填、校验和按管理员提交', () => {
|
||||
const form = fillEditUserForm({ id: 3, username: '管理员', role: 'admin', jdPublishQuota: 0 })
|
||||
assert.equal(form.jdPublishQuota, 0)
|
||||
assert.equal(toEditUserUpdateRequest(form).jdPublishQuota, 0)
|
||||
form.jdPublishQuota = -1
|
||||
assert.equal(validateEditUserForm(form).valid, false)
|
||||
form.jdPublishQuota = 1.5
|
||||
assert.equal(validateEditUserForm(form).valid, false)
|
||||
form.role = 'normal'
|
||||
assert.equal(toEditUserUpdateRequest(form).jdPublishQuota, undefined)
|
||||
})
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* 用户管理页 × 平台 tab(V206)的挂载契约:
|
||||
* 账号域三页两 tab 共用组件,列表请求必须带 platform=当前平台;切 tab 重取数;
|
||||
* 「上架上限」列仅京东侧渲染(用户口径「不需要在亚马逊那边」),文案 0=不限/null=-。
|
||||
* 不用 readFileSync(source-pin-ratchet 对台账外新文件带读点即红),全部走真实挂载断言。
|
||||
*
|
||||
* 跑法:`npx vitest run tests/mount/users-page-platform.mount.test.ts`
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||||
|
||||
import UsersPage from '@/pages/account/UsersPage.vue'
|
||||
import { usePlatformTabStore } from '@/stores/platform-tab'
|
||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||
|
||||
const usersApi = vi.hoisted(() => ({
|
||||
fetchUserList: vi.fn(),
|
||||
deleteUser: vi.fn(),
|
||||
setUserDisabled: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/users', () => usersApi)
|
||||
vi.mock('@/api/companies', () => ({ fetchCompanies: vi.fn().mockResolvedValue([]) }))
|
||||
vi.mock('@/pages/account/user-menu-auth-api', () => ({ loadUserMenuAuth: vi.fn() }))
|
||||
|
||||
function pageOf(total = 0) {
|
||||
return {
|
||||
items: [
|
||||
{ id: 7, username: '京东号', role: 'normal', platform: 'jd' },
|
||||
{ id: 8, username: '存量号', role: 'admin', jdPublishQuota: 0 },
|
||||
{ id: 9, username: '老号', role: 'normal', jdPublishQuota: 800 },
|
||||
{ id: 10, username: '没配号', role: 'normal' },
|
||||
],
|
||||
total,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
}
|
||||
}
|
||||
|
||||
let pinia: Pinia
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
window.localStorage.removeItem('admin-platform-tab')
|
||||
pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
const session = useAdminSessionStore()
|
||||
session.user = { id: 1, username: 'root', role: 'super_admin' }
|
||||
usersApi.fetchUserList.mockResolvedValue(pageOf())
|
||||
})
|
||||
|
||||
describe('UsersPage × 平台 tab(V206)', () => {
|
||||
it('亚马逊 tab(默认):列表请求带 platform=amazon,无「上架上限」列', async () => {
|
||||
const wrapper = mount(UsersPage)
|
||||
await flushPromises()
|
||||
expect(usersApi.fetchUserList).toHaveBeenCalledTimes(1)
|
||||
const params = usersApi.fetchUserList.mock.calls[0][0] as Record<string, unknown>
|
||||
expect(params.platform).toBe('amazon')
|
||||
expect(params).toHaveProperty('companyId')
|
||||
const headers = wrapper.findAll('thead th').map((th) => th.text())
|
||||
expect(headers).not.toContain('上架上限')
|
||||
// 亚马逊侧表头 9 列(存量表头,quota 列不渲染)
|
||||
expect(headers.length).toBe(9)
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('切到京东 tab:重取数并带 platform=jd,「上架上限」列出现,文案 0=不限/null=-', async () => {
|
||||
const wrapper = mount(UsersPage)
|
||||
await flushPromises()
|
||||
const platformTab = usePlatformTabStore()
|
||||
platformTab.setActive('jd')
|
||||
await flushPromises()
|
||||
|
||||
expect(usersApi.fetchUserList).toHaveBeenCalledTimes(2)
|
||||
const params = usersApi.fetchUserList.mock.calls[1][0] as Record<string, unknown>
|
||||
expect(params.platform).toBe('jd')
|
||||
|
||||
const headers = wrapper.findAll('thead th').map((th) => th.text())
|
||||
expect(headers).toContain('上架上限')
|
||||
expect(headers.length).toBe(10)
|
||||
// quota 单元格:0=不限(存量号 8),null/缺省=-(京东号 7、没配号 10),800 原样
|
||||
const quotaCells = wrapper.findAll('tbody tr').map((tr) => {
|
||||
const tds = tr.findAll('td')
|
||||
// 上架上限列在第 5 列(ID/用户名/角色/所属管理员/到期时间 之后)
|
||||
return tds[5]?.text()
|
||||
})
|
||||
expect(quotaCells).toEqual(['-', '不限', '800', '-'])
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
it('切回亚马逊 tab:再次重取数且列消失(两 tab 各看各的数据面)', async () => {
|
||||
const wrapper = mount(UsersPage)
|
||||
await flushPromises()
|
||||
const platformTab = usePlatformTabStore()
|
||||
platformTab.setActive('jd')
|
||||
await flushPromises()
|
||||
platformTab.setActive('amazon')
|
||||
await flushPromises()
|
||||
|
||||
expect(usersApi.fetchUserList).toHaveBeenCalledTimes(3)
|
||||
const params = usersApi.fetchUserList.mock.calls[2][0] as Record<string, unknown>
|
||||
expect(params.platform).toBe('amazon')
|
||||
expect(wrapper.findAll('thead th').map((th) => th.text())).not.toContain('上架上限')
|
||||
wrapper.unmount()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,130 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readSource } from './helpers.ts'
|
||||
import { toCreateUserRequest, createEmptyCreateUserForm } from '../src/pages/account/user-create-model.ts'
|
||||
import {
|
||||
fillEditUserForm,
|
||||
toEditUserUpdateRequest,
|
||||
validateEditUserForm,
|
||||
} from '../src/pages/account/user-edit-model.ts'
|
||||
import { toShopGroupCreatePayload, toShopGroupUpdatePayload } from '../src/pages/account/shop-group-model.ts'
|
||||
import { toCompanyPayload } from '../src/api/companies-dto.ts'
|
||||
|
||||
/**
|
||||
* 账号域三页按平台 tab 分列(V206,2026-11-17 用户口径「这些亚马逊这边也要有……数据都是新的
|
||||
* 别把亚马逊的带过来」):users/company/biz_shop_manage_group 三表加 platform 列,存量默认亚马逊;
|
||||
* 前端同一套组件两 tab 共显,请求带 platform=当前 tab,弹窗单选默认当前平台、可翻档归侧。
|
||||
* 上架上限(jd_publish_quota)只属京东口径:编辑弹窗隐藏 + 校验/下发都跳过 + 列表列仅京东侧。
|
||||
*/
|
||||
|
||||
// ---------- 纯函数:payload 的 platform 下发与翻档 ----------
|
||||
|
||||
test('建号 payload 恒带 platform:京东 tab 建的号默认归京东,单选翻档即改归属', () => {
|
||||
const jd = toCreateUserRequest({ ...createEmptyCreateUserForm(), username: 'a', password: 'secret123', platform: 'jd' })
|
||||
assert.equal(jd.platform, 'jd')
|
||||
const amazon = toCreateUserRequest({ ...createEmptyCreateUserForm(), username: 'a', password: 'secret123' })
|
||||
assert.equal(amazon.platform, 'amazon', '空表单缺省亚马逊(存量口径),后端 normalizeOrCreate 同口径兜底')
|
||||
})
|
||||
|
||||
test('编辑回填 platform:行值 jd→jd,缺省/未知→amazon;请求体恒下发 platform(翻档即挪列)', () => {
|
||||
const jdForm = fillEditUserForm({ id: 7, username: '京东号', role: 'normal', platform: 'jd' })
|
||||
assert.equal(jdForm.platform, 'jd')
|
||||
assert.equal(toEditUserUpdateRequest(jdForm).platform, 'jd')
|
||||
|
||||
const legacy = fillEditUserForm({ id: 8, username: '存量号', role: 'normal' })
|
||||
assert.equal(legacy.platform, 'amazon', '旧负载没有 platform 时归亚马逊(存量默认),不许渲染成空串')
|
||||
|
||||
assert.equal(toEditUserUpdateRequest(legacy).platform, 'amazon', 'platform 恒下发:单选恒渲染,后端显式才落')
|
||||
})
|
||||
|
||||
test('includeQuota=false(亚马逊侧编辑):不下发 jdPublishQuota,校验也跳过;platform 照常下发', () => {
|
||||
const form = fillEditUserForm({ id: 3, username: '管理员', role: 'admin', jdPublishQuota: 800 })
|
||||
const amazon = toEditUserUpdateRequest(form, { includeQuota: false })
|
||||
assert.equal('jdPublishQuota' in amazon, false, '亚马逊侧不许把表单里的 quota 值带给后端(字段留在京东口径)')
|
||||
assert.equal(amazon.platform, 'amazon')
|
||||
|
||||
// 亚马逊侧 quota 校验跳过:表单残留的非法值不再拦保存(该值根本不下发)。
|
||||
form.jdPublishQuota = -1
|
||||
assert.equal(validateEditUserForm(form, { includeQuota: false }).valid, true)
|
||||
assert.equal(validateEditUserForm(form).valid, false, '京东侧(缺省 options)仍按原口径拦非法值')
|
||||
})
|
||||
|
||||
test('分组 payload 的 platform:创建/更新显式下发,缺省(旧调用方)不带——后端 normalizeOrCreate 兜底', () => {
|
||||
const created = toShopGroupCreatePayload('京东组', [2, 3], 9, 'jd')
|
||||
assert.equal(created.platform, 'jd')
|
||||
const createdLegacy = toShopGroupCreatePayload('旧组', [], 9)
|
||||
assert.equal('platform' in createdLegacy, false, '不传 platform 的调用形状不变(重载式扩展)')
|
||||
const updated = toShopGroupUpdatePayload('翻档组', [2], 'amazon')
|
||||
assert.equal(updated.platform, 'amazon')
|
||||
const updatedLegacy = toShopGroupUpdatePayload('旧组', [])
|
||||
assert.equal('platform' in updatedLegacy, false)
|
||||
})
|
||||
|
||||
test('公司 payload 的 platform:显式才下发(company-directory 的 deepEqual 形状不受存量影响)', () => {
|
||||
const withPlatform = toCompanyPayload({ companyName: '福州数富', status: 1, remark: '', platform: 'jd' })
|
||||
assert.equal(withPlatform.platform, 'jd')
|
||||
const legacy = toCompanyPayload({ companyName: '厦门米椿花', status: 1, remark: '' })
|
||||
assert.equal('platform' in legacy, false, '不带 platform 的草稿请求体形状不变')
|
||||
})
|
||||
|
||||
// ---------- 源码钉:三页接线 + 弹窗默认平台 + quota 仅京东侧 ----------
|
||||
|
||||
test('UsersPage:列表请求带当前平台、切平台重取数、上架上限列仅京东侧渲染', () => {
|
||||
const page = readSource('src/pages/account/UsersPage.vue')
|
||||
assert.match(page, /platform: platformTab\.active/,
|
||||
'列表请求必须带 platform=当前平台 tab(users.ts 从原始入参读,白名单构造不收它)')
|
||||
assert.match(page, /watch\(\(\) => platformTab\.active/,
|
||||
'切平台 tab 必须重取数:账号域三页两 tab 共用组件,列表按平台过滤')
|
||||
assert.match(page, /:platform="platformTab\.active"/, '新建/编辑弹窗要拿到当前平台(默认平台 + quota 可见性)')
|
||||
assert.match(page, /v-if="isJdSide" style="width: 110px">上架上限</,
|
||||
'上架上限列只许京东侧渲染(用户口径「不需要在亚马逊那边」)')
|
||||
assert.match(page, /quotaCellText/, 'quota 单元格文案走函数(null=-、0=不限、其余条数)')
|
||||
assert.match(page, /const isJdSide = computed/, '京东侧判定单一出处')
|
||||
})
|
||||
|
||||
test('GroupsPage:分组列表带平台、切平台重取数、编辑弹窗拿当前平台', () => {
|
||||
const page = readSource('src/pages/account/GroupsPage.vue')
|
||||
assert.match(page, /fetchShopGroups\(companyTab\.requestCompanyId, platformTab\.active\)/,
|
||||
'分组列表同时收公司(钉住的取值口)与平台两个口径')
|
||||
assert.match(page, /watch\(\(\) => platformTab\.active/, '切平台 tab 必须重取数')
|
||||
assert.match(page, /:platform="platformTab\.active"/, '新建分组弹窗默认落当前平台')
|
||||
})
|
||||
|
||||
test('CompaniesPage:公司列表带平台、切平台重取数、编辑弹窗拿当前平台', () => {
|
||||
const page = readSource('src/pages/account/CompaniesPage.vue')
|
||||
assert.match(page, /fetchCompanies\(platformTab\.active\)/, '公司列表按当前平台过滤')
|
||||
assert.match(page, /watch\(\(\) => platformTab\.active/, '切平台 tab 必须重取数')
|
||||
assert.match(page, /:platform="platformTab\.active"/, '新建公司弹窗默认落当前平台')
|
||||
})
|
||||
|
||||
test('EditUserDialog:上架上限仅京东侧显示且不参与亚马逊侧提交;所属平台单选恒在', () => {
|
||||
const dialog = readSource('src/pages/account/EditUserDialog.vue')
|
||||
assert.match(dialog, /v-if="includeQuota && \(targetIsCompanySuperAdmin \|\| form\.role === 'admin'\)"/,
|
||||
'quota 项必须叠上 includeQuota(京东侧)条件——只按角色判断会把该项带进亚马逊侧弹窗')
|
||||
assert.match(dialog, /submitEditUser\(form, \{ includeQuota: includeQuota\.value \}\)/,
|
||||
'提交必须透传 includeQuota:亚马逊侧校验与下发都跳过 quota')
|
||||
assert.match(dialog, /validateEditUserForm\(form, \{ includeQuota: includeQuota\.value \}\)/,
|
||||
'校验与下发同口径(校验过了但不下发 = 静默改值)')
|
||||
assert.match(dialog, /v-model="form\.platform"/, '所属平台单选恒在:翻档是把记录挪到另一平台列表的唯一入口')
|
||||
assert.match(dialog, /props\.platform === 'jd'/, 'includeQuota 取自页面透传的当前平台')
|
||||
assert.match(dialog, /form\.platform = base\.platform/, '打开弹窗必须回填行值(旧负载缺省归亚马逊)')
|
||||
})
|
||||
|
||||
test('CreateUserDialog/GroupEditorDialog/CompanyEditorDialog:新建默认当前平台、编辑回填行值', () => {
|
||||
const create = readSource('src/pages/account/CreateUserDialog.vue')
|
||||
assert.match(create, /form\.platform = props\.platform \?\? 'amazon'/, '建号默认当前平台 tab')
|
||||
assert.match(create, /v-model="form\.platform"/, '所属平台单选在')
|
||||
|
||||
const group = readSource('src/pages/account/GroupEditorDialog.vue')
|
||||
assert.match(group, /groupPlatform\.value = props\.platform \?\? 'amazon'/, '新建分组默认当前平台 tab')
|
||||
assert.match(group, /props\.group\.platform === 'jd' \? 'jd' : 'amazon'/, '编辑分组回填行值')
|
||||
assert.match(group, /createShopGroup\(groupName\.value, memberIds\.value, operatorId, groupPlatform\.value\)/,
|
||||
'创建分组必须带平台')
|
||||
assert.match(group, /updateShopGroup\(props\.group\.id, groupName\.value, memberIds\.value, groupPlatform\.value\)/,
|
||||
'更新分组必须带平台(翻档归侧)')
|
||||
assert.doesNotMatch(group, /companyTab/, '分组弹窗不读公司 tab(既有口径:候选按组长公司取人)')
|
||||
|
||||
const company = readSource('src/pages/account/CompanyEditorDialog.vue')
|
||||
assert.match(company, /platform: props\.platform \?\? 'amazon'/, '新建公司默认当前平台 tab')
|
||||
assert.match(company, /props\.company\.platform === 'jd' \? 'jd' : 'amazon'/, '编辑公司回填行值')
|
||||
})
|
||||
@@ -1,13 +1,20 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import type { AdminMenuNode } from '../src/types/admin.ts'
|
||||
import { JD_MENU_KEYS, PLATFORM_TABS, platformOfMenuKey } from '../src/config/platform-scope.ts'
|
||||
import {
|
||||
BOTH_PLATFORM_MENU_KEYS,
|
||||
JD_MENU_KEYS,
|
||||
PLATFORM_TABS,
|
||||
platformsOfMenuKey,
|
||||
} from '../src/config/platform-scope.ts'
|
||||
import { filterMenuTreeByPlatform, visiblePlatformsFor } from '../src/layout/platform-menu-filter.ts'
|
||||
import { adminPages } from '../src/router/routes.ts'
|
||||
|
||||
/** 2026-11-16 用户定案「亚马逊/京东不混一起」:侧边栏顶部加平台 tab,京东侧=截图圈定四项
|
||||
* (用户管理/分组管理/公司管理/京东数据库),其余归亚马逊。tab 只做显示分组——菜单可见性
|
||||
* 仍由 session.menuTree(后端按权限裁剪)决定,这里钉的是「分侧归属」与「空侧隐藏」两条形状。
|
||||
/** 2026-11-16 用户定案「亚马逊/京东不混一起」:侧边栏顶部加平台 tab,京东侧=截图圈定
|
||||
* 数据页(京东数据库/分类管理)。2026-11-17 用户口径「这些亚马逊这边也要有」:账号域三页
|
||||
* (用户管理/分组管理/公司管理)改为双侧显示(BOTH_PLATFORM_MENU_KEYS),同一组件按当前
|
||||
* tab 传 platform 过滤各自数据。tab 只做显示分组——菜单可见性仍由 session.menuTree(后端
|
||||
* 按权限裁剪)决定,这里钉的是「分侧归属」与「空侧隐藏」两条形状。
|
||||
* 辅助定义在所有 test 之前:node:test 的用例回调按声明序执行,挪到文件尾会踩 TDZ。 */
|
||||
|
||||
const node = (key: string, name: string, route?: string, children?: AdminMenuNode[]): AdminMenuNode => {
|
||||
@@ -43,16 +50,17 @@ function groupChildKeys(filtered: AdminMenuNode[], groupKey: string): string[] {
|
||||
return (group?.children || []).map((child) => child.key)
|
||||
}
|
||||
|
||||
test('menuKey 平台归属:京东清单四项即 jd,其余(含分组 key 与未知 key)一律 amazon', () => {
|
||||
for (const key of JD_MENU_KEYS) assert.equal(platformOfMenuKey(key), 'jd', key)
|
||||
assert.equal(platformOfMenuKey('admin_query_asin'), 'amazon')
|
||||
assert.equal(platformOfMenuKey('admin_columns'), 'amazon')
|
||||
assert.equal(platformOfMenuKey('admin_group_account'), 'amazon')
|
||||
assert.equal(platformOfMenuKey('admin_jd_unknown_future'), 'amazon')
|
||||
assert.equal(platformOfMenuKey(''), 'amazon')
|
||||
test('menuKey 平台归属:京东独占即 [jd],双侧清单即两侧,其余(含分组 key 与未知 key)一律 [amazon]', () => {
|
||||
for (const key of JD_MENU_KEYS) assert.deepEqual(platformsOfMenuKey(key), ['jd'], key)
|
||||
for (const key of BOTH_PLATFORM_MENU_KEYS) assert.deepEqual(platformsOfMenuKey(key), ['amazon', 'jd'], key)
|
||||
assert.deepEqual(platformsOfMenuKey('admin_query_asin'), ['amazon'])
|
||||
assert.deepEqual(platformsOfMenuKey('admin_columns'), ['amazon'])
|
||||
assert.deepEqual(platformsOfMenuKey('admin_group_account'), ['amazon'])
|
||||
assert.deepEqual(platformsOfMenuKey('admin_jd_unknown_future'), ['amazon'])
|
||||
assert.deepEqual(platformsOfMenuKey(''), ['amazon'])
|
||||
})
|
||||
|
||||
test('京东 tab:账号与权限只余圈定三项,数据管理只余京东两页(数据库+分类管理);顺序与 route 原样透传', () => {
|
||||
test('京东 tab:账号与权限只余双侧三项,数据管理只余京东两页(数据库+分类管理);顺序与 route 原样透传', () => {
|
||||
const filtered = filterMenuTreeByPlatform(TREE, 'jd')
|
||||
assert.deepEqual(filtered.map((item) => item.key), ['admin_group_account', 'admin_group_data'])
|
||||
assert.deepEqual(groupChildKeys(filtered, 'admin_group_account'),
|
||||
@@ -69,10 +77,11 @@ test('京东 tab:账号与权限只余圈定三项,数据管理只余京东
|
||||
assert.equal(categoryManage.name, '京东分类管理')
|
||||
})
|
||||
|
||||
test('亚马逊 tab:其余菜单全数保留且分组结构不变', () => {
|
||||
test('亚马逊 tab:除京东独占两页外全数保留(含 2026-11-17 回归的双侧账号域三页),分组结构不变', () => {
|
||||
const filtered = filterMenuTreeByPlatform(TREE, 'amazon')
|
||||
assert.deepEqual(groupChildKeys(filtered, 'admin_group_account'),
|
||||
['admin_columns', 'admin_user_secrets', 'admin_user_secret_usage'])
|
||||
['admin_columns', 'admin_users', 'admin_group_manage', 'admin_user_secrets',
|
||||
'admin_user_secret_usage', 'admin_companies'])
|
||||
assert.deepEqual(groupChildKeys(filtered, 'admin_group_data'),
|
||||
['admin_dedupe_total_data', 'admin_invalid_asin_data', 'admin_query_asin',
|
||||
'admin_appearance_patent_clean_items', 'admin_product_categories'])
|
||||
@@ -111,18 +120,20 @@ test('tab 显示依据:两侧都有可见页才画 tab 条,仅一侧授权
|
||||
assert.deepEqual(visiblePlatformsFor(null), [])
|
||||
})
|
||||
|
||||
test('平台 tab 定义与京东清单钉死(2026-11-16 用户圈定口径,防清单漂移)', () => {
|
||||
test('平台 tab 定义与两份菜单清单钉死(防清单漂移):京东独占两页、双侧共用账号域三页', () => {
|
||||
assert.deepEqual(PLATFORM_TABS, [
|
||||
{ id: 'amazon', label: '亚马逊' },
|
||||
{ id: 'jd', label: '京东' },
|
||||
])
|
||||
assert.deepEqual([...JD_MENU_KEYS].sort(),
|
||||
['admin_companies', 'admin_group_manage', 'admin_jd_category_manage', 'admin_jd_database', 'admin_users'])
|
||||
['admin_jd_category_manage', 'admin_jd_database'])
|
||||
assert.deepEqual([...BOTH_PLATFORM_MENU_KEYS].sort(),
|
||||
['admin_companies', 'admin_group_manage', 'admin_users'])
|
||||
})
|
||||
|
||||
test('JD_MENU_KEYS 每一条都必须在路由注册表登记(同 company-menu-route 护栏形状:少登记=看得见点进去404)', () => {
|
||||
test('两份清单的每一条都必须在路由注册表登记(同 company-menu-route 护栏形状:少登记=看得见点进去404)', () => {
|
||||
const registered = new Set(adminPages.map((page) => page.menuKey))
|
||||
for (const key of JD_MENU_KEYS) {
|
||||
assert.ok(registered.has(key), `京东侧菜单 key "${key}" 未在 src/router/routes.ts 登记 menuKey`)
|
||||
for (const key of [...JD_MENU_KEYS, ...BOTH_PLATFORM_MENU_KEYS]) {
|
||||
assert.ok(registered.has(key), `平台侧菜单 key "${key}" 未在 src/router/routes.ts 登记 menuKey`)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -88,7 +88,10 @@ test('test_task_048_normal_role_wording_agrees_across_all_exits', () => {
|
||||
const buttons = [...dialog.matchAll(/<el-radio-button\s+value="([a-z_]+)">([^<]*)</g)].map(
|
||||
(m) => [m[1], m[2]] as const,
|
||||
)
|
||||
assert.deepEqual(buttons, [['normal', word], ['admin', '管理员']], '编辑用户弹窗的角色按钮文案')
|
||||
// 2026-11-17 V206:弹窗新增「所属平台」单选(amazon/jd 两档)——角色按钮仍是前两枚,
|
||||
// 平台按钮单独钉,四出口文案对平的意图不变。
|
||||
assert.deepEqual(buttons.slice(0, 2), [['normal', word], ['admin', '管理员']], '编辑用户弹窗的角色按钮文案')
|
||||
assert.deepEqual(buttons.slice(2), [['amazon', '亚马逊'], ['jd', '京东']], '所属平台单选两档(V206 翻档归侧的唯一入口)')
|
||||
})
|
||||
|
||||
/**
|
||||
|
||||
@@ -48,6 +48,15 @@ public class AdminUserEntity {
|
||||
*/
|
||||
@TableField(value = "updated_at", insertStrategy = FieldStrategy.NEVER, updateStrategy = FieldStrategy.NEVER)
|
||||
private LocalDateTime updatedAt;
|
||||
@TableField("jd_publish_quota")
|
||||
private Integer jdPublishQuota;
|
||||
/**
|
||||
* 所属平台(V206 新增):amazon|jd,与后管侧边栏平台 tab 同字面量。只作用于后管
|
||||
* 用户管理页的显示与筛选,不影响登录与功能权限。存量 DEFAULT 'amazon',京东侧
|
||||
* 数据由使用者在编辑弹窗里翻档。
|
||||
*/
|
||||
@TableField("platform")
|
||||
private String platform;
|
||||
private String machine;
|
||||
/**
|
||||
* 会话世代(V172 新增):登录/登出各 +1,JWT 的 epoch claim 必须与它相等。
|
||||
|
||||
+5
@@ -22,6 +22,11 @@ public class ShopManageGroupEntity {
|
||||
private Long userId;
|
||||
@TableField("created_by_id")
|
||||
private Long createdById;
|
||||
/**
|
||||
* 所属平台(V206 新增):amazon|jd,与后管侧边栏平台 tab 同字面量。只作用于后管
|
||||
* 分组管理页的显示与筛选;存量 DEFAULT 'amazon',京东侧由使用者在编辑弹窗里翻档。
|
||||
*/
|
||||
private String platform;
|
||||
private LocalDateTime createdAt;
|
||||
private LocalDateTime updatedAt;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.nanri.aiimage.common.service;
|
||||
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
|
||||
/**
|
||||
* 账号域「所属平台」(V206)取值口径的唯一出处。取值字面量与 admin-frontend-vue 的
|
||||
* {@code PlatformTabId} 同源:{@code amazon | jd}。
|
||||
*
|
||||
* <p>语义边界:平台只作用于后管「用户管理 / 分组管理 / 公司管理」三个页面的显示与筛选,
|
||||
* 不影响登录、用户端功能、任务权限与 DataReadScope。存量行 DEFAULT 'amazon',京东侧数据
|
||||
* 由使用者在编辑弹窗里自己翻档(不做数据驱动的自动归类)。</p>
|
||||
*/
|
||||
public final class AdminPlatformScope {
|
||||
|
||||
public static final String AMAZON = "amazon";
|
||||
public static final String JD = "jd";
|
||||
|
||||
private AdminPlatformScope() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建侧归一:null/空白按 {@code amazon}(与列 DEFAULT 同口径);给了就只认合法值,
|
||||
* 非法值 400——静默归一会把"手滑打错"变成"悄悄归进亚马逊侧"。
|
||||
*/
|
||||
public static String normalizeOrCreate(String raw) {
|
||||
String value = raw == null ? "" : raw.trim();
|
||||
if (value.isEmpty()) {
|
||||
return AMAZON;
|
||||
}
|
||||
return requireLegal(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新侧归一:null/空白=本次不动(返回 null,调用方跳过该列);给了就只认合法值,
|
||||
* 非法值 400。{@code PUT} 只带部分字段的既有形状(如 setUserDisabled)不会把平台冲掉。
|
||||
*/
|
||||
public static String normalizeOrNull(String raw) {
|
||||
String value = raw == null ? "" : raw.trim();
|
||||
if (value.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return requireLegal(value);
|
||||
}
|
||||
|
||||
private static String requireLegal(String value) {
|
||||
if (AMAZON.equals(value) || JD.equals(value)) {
|
||||
return value;
|
||||
}
|
||||
throw new BusinessException(400, "所属平台只支持 amazon 或 jd");
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -41,11 +41,13 @@ public class AdminUserController {
|
||||
@RequestParam(name = "created_by_id", required = false) Long createdById,
|
||||
@RequestParam(name = "admin_id", required = false) Long adminId,
|
||||
@RequestParam(name = "role", required = false) String role,
|
||||
@RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
@RequestParam(name = "company_id", required = false) Long companyId,
|
||||
@RequestParam(name = "platform", required = false) String platform) {
|
||||
AdminUserEntity currentUser = adminAuthSupport.requireAdminOrInternal(request);
|
||||
String kw = (username == null || username.isBlank()) ? search : username;
|
||||
Long filterCreatedBy = createdById != null ? createdById : adminId;
|
||||
AdminUserListVo vo = adminUserService.listUsers(currentUser, page, pageSize, kw, filterCreatedBy, role, companyId);
|
||||
AdminUserListVo vo = adminUserService.listUsers(currentUser, page, pageSize, kw, filterCreatedBy, role,
|
||||
companyId, platform);
|
||||
return ApiResponse.success(vo);
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -11,6 +11,10 @@ public class AdminUserCreateRequest {
|
||||
private String role;
|
||||
private Long createdById;
|
||||
private Long companyId;
|
||||
/**
|
||||
* 所属平台(V206):amazon|jd;null/空白按 'amazon'(与列 DEFAULT 同口径)。
|
||||
*/
|
||||
private String platform;
|
||||
/**
|
||||
* 到期时间(V146):支持 yyyy-MM-dd / yyyy-MM-dd HH:mm / yyyy-MM-dd HH:mm:ss。
|
||||
* 空/不传 = 永不过期;super_admin 目标不存在本字段语义(超管建不出超管)。
|
||||
|
||||
+6
@@ -6,6 +6,12 @@ import java.util.List;
|
||||
|
||||
@Data
|
||||
public class AdminUserUpdateRequest {
|
||||
private Integer jdPublishQuota;
|
||||
/**
|
||||
* 所属平台(V206):null=不动;给了就只认 amazon|jd(非法值 400)。只改后管
|
||||
* 用户管理页的归属展示,不影响登录与功能权限。
|
||||
*/
|
||||
private String platform;
|
||||
private String password;
|
||||
private String role;
|
||||
private List<Long> columnIds;
|
||||
|
||||
+5
@@ -5,6 +5,11 @@ import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AdminUserItemVo {
|
||||
@JsonProperty("jd_publish_quota")
|
||||
private Integer jdPublishQuota;
|
||||
/** 所属平台(V206):amazon|jd,与后管侧边栏平台 tab 同字面量。 */
|
||||
@JsonProperty("platform")
|
||||
private String platform;
|
||||
private Long id;
|
||||
private String username;
|
||||
@JsonProperty("is_admin")
|
||||
|
||||
+46
-1
@@ -10,6 +10,7 @@ import com.nanri.aiimage.modules.admin.model.vo.AdminUserItemVo;
|
||||
import com.nanri.aiimage.modules.admin.model.vo.AdminUserListVo;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
import com.nanri.aiimage.common.service.AdminPlatformScope;
|
||||
import com.nanri.aiimage.modules.admin.util.PinyinAbbrUtil;
|
||||
import com.nanri.aiimage.modules.auth.util.WerkzeugPasswordEncoder;
|
||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||
@@ -54,6 +55,17 @@ public class AdminUserService {
|
||||
public AdminUserListVo listUsers(AdminUserEntity currentUser, Integer page, Integer pageSize,
|
||||
String username, Long createdById, String roleFilter,
|
||||
Long companyIdFilter) {
|
||||
return listUsers(currentUser, page, pageSize, username, createdById, roleFilter, companyIdFilter, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 带平台过滤的分页用户列表(V206):platformFilter 非空白时只返回该平台的账号
|
||||
* (amazon|jd,非法值 400),后管「用户管理」页按当前平台 tab 传参;null/空白=不过滤,
|
||||
* 用户选择器等旧调用方口径不变。
|
||||
*/
|
||||
public AdminUserListVo listUsers(AdminUserEntity currentUser, Integer page, Integer pageSize,
|
||||
String username, Long createdById, String roleFilter,
|
||||
Long companyIdFilter, String platformFilter) {
|
||||
String role = adminAuthSupport.currentRole(currentUser);
|
||||
if (role == null) {
|
||||
throw new BusinessException(403, "需要管理员权限");
|
||||
@@ -71,6 +83,11 @@ public class AdminUserService {
|
||||
Long filterCreatedBy = "super_admin".equals(role) ? createdById : null;
|
||||
|
||||
LambdaQueryWrapper<AdminUserEntity> query = new LambdaQueryWrapper<>();
|
||||
String platformFilterValue = AdminPlatformScope.normalizeOrNull(platformFilter);
|
||||
if (platformFilterValue != null) {
|
||||
// 平台过滤对三档可见范围(超管/公司超管/组长)统一生效:count 与取页共用同一 wrapper
|
||||
query.eq(AdminUserEntity::getPlatform, platformFilterValue);
|
||||
}
|
||||
String roleFilterValue = roleFilter == null ? "" : roleFilter.trim();
|
||||
if (!roleFilterValue.isEmpty()) {
|
||||
query.eq(AdminUserEntity::getRole, roleFilterValue);
|
||||
@@ -211,6 +228,7 @@ public class AdminUserService {
|
||||
entity.setRole(wantRole);
|
||||
entity.setCreatedById(wantCreatedBy);
|
||||
entity.setCompanyId(targetCompanyId);
|
||||
entity.setPlatform(AdminPlatformScope.normalizeOrCreate(request.getPlatform()));
|
||||
entity.setExpiresAt(parseExpiresAt(request.getExpiresAt()));
|
||||
try {
|
||||
adminUserMapper.insert(entity);
|
||||
@@ -379,13 +397,18 @@ public class AdminUserService {
|
||||
ensureAdminUsersMenuAccess(currentUser, List.of("admin_users"));
|
||||
String password = request.getPassword();
|
||||
String wantRole = request.getRole() == null ? null : request.getRole().trim();
|
||||
// 平台只在显式给出时落(null/空白=不动):PUT 只带 disabled 的既有形状不能把平台冲掉;
|
||||
// 非法值在这里直接 400,不等后面的 dirty 判定
|
||||
String platformUpdate = AdminPlatformScope.normalizeOrNull(request.getPlatform());
|
||||
|
||||
if ((password == null || password.isEmpty())
|
||||
&& (wantRole == null || wantRole.isEmpty())
|
||||
&& request.getColumnIds() == null
|
||||
&& request.getCompanyId() == null
|
||||
&& request.getExpiresAt() == null
|
||||
&& request.getDisabled() == null) {
|
||||
&& request.getDisabled() == null
|
||||
&& request.getJdPublishQuota() == null
|
||||
&& platformUpdate == null) {
|
||||
throw new BusinessException("请提供要修改的内容");
|
||||
}
|
||||
// 不许停自己:现有的角色闸(admin 只动自建普通账号 / 公司超管与超管目标互斥)已经
|
||||
@@ -440,6 +463,18 @@ public class AdminUserService {
|
||||
throw new BusinessException(400, NORMAL_ACCOUNT_EXPIRY_MESSAGE);
|
||||
}
|
||||
|
||||
if (request.getJdPublishQuota() != null) {
|
||||
if (!"super_admin".equals(role) && !"company_super_admin".equals(role)) {
|
||||
throw new BusinessException(403, "无权修改京东上架额度");
|
||||
}
|
||||
if (!"admin".equals(roleAfter) && !"company_super_admin".equals(roleAfter)) {
|
||||
throw new BusinessException(400, "只能为管理员设置京东上架额度");
|
||||
}
|
||||
if (request.getJdPublishQuota() < 0) {
|
||||
throw new BusinessException(400, "京东上架额度不能为负数");
|
||||
}
|
||||
}
|
||||
|
||||
// 移人先于写库:先确认目标公司可用,再确认 created_by_id 不变式没被破坏
|
||||
Long moveCompanyId = resolveCompanyMove(role, target, request.getCompanyId());
|
||||
if (moveCompanyId != null) {
|
||||
@@ -449,6 +484,14 @@ public class AdminUserService {
|
||||
LambdaUpdateWrapper<AdminUserEntity> update = new LambdaUpdateWrapper<AdminUserEntity>()
|
||||
.eq(AdminUserEntity::getId, uid);
|
||||
boolean dirty = false;
|
||||
if (request.getJdPublishQuota() != null) {
|
||||
update.set(AdminUserEntity::getJdPublishQuota, request.getJdPublishQuota());
|
||||
dirty = true;
|
||||
}
|
||||
if (platformUpdate != null) {
|
||||
update.set(AdminUserEntity::getPlatform, platformUpdate);
|
||||
dirty = true;
|
||||
}
|
||||
if (moveCompanyId != null) {
|
||||
update.set(AdminUserEntity::getCompanyId, moveCompanyId);
|
||||
dirty = true;
|
||||
@@ -635,11 +678,13 @@ public class AdminUserService {
|
||||
vo.setCompanyId(companyId);
|
||||
// 账号挂着公司表里查不到的 id(脏数据/回滚残留)时留空串,前端显示 '-',整页不能因此 500
|
||||
vo.setCompanyName(companyId == null ? "" : companyMap.getOrDefault(companyId, ""));
|
||||
vo.setPlatform(entity.getPlatform());
|
||||
LocalDateTime createdAt = entity.getCreatedAt();
|
||||
vo.setCreatedAt(createdAt == null ? "" : createdAt.format(CREATED_AT_FORMATTER));
|
||||
LocalDateTime updatedAt = entity.getUpdatedAt();
|
||||
vo.setUpdatedAt(updatedAt == null ? "" : updatedAt.format(CREATED_AT_FORMATTER));
|
||||
// 到期时间:null(永不过期)与空字符串在列表里都要有明确渲染,前端按空串判"永不过期"
|
||||
vo.setJdPublishQuota(entity.getJdPublishQuota());
|
||||
vo.setExpiresAt(entity.getExpiresAt() == null ? "" : entity.getExpiresAt().format(CREATED_AT_FORMATTER));
|
||||
// 停用时刻(V155):null=未停用,前端按此渲染「已停用」徽标
|
||||
vo.setDisabledAt(entity.getDisabledAt() == null ? null : entity.getDisabledAt().format(CREATED_AT_FORMATTER));
|
||||
|
||||
+6
@@ -43,6 +43,12 @@ public class LoginUserEntity {
|
||||
*/
|
||||
@TableField("disabled_at")
|
||||
private LocalDateTime disabledAt;
|
||||
/**
|
||||
* 所属平台(V206 新增):与 {@code AdminUserEntity.platform} 同列,amazon|jd。
|
||||
* 改一处必须同改两处(UsersCompanyIdMappingTest 钉住)。
|
||||
*/
|
||||
@TableField("platform")
|
||||
private String platform;
|
||||
/**
|
||||
* 会话世代(V172 新增):登录/登出各 +1,JWT 的 epoch claim 必须与它相等。
|
||||
* 与 {@code AdminUserEntity.sessionEpoch} 同列,改一处必须同改两处。
|
||||
|
||||
+7
-2
@@ -7,6 +7,7 @@ import com.nanri.aiimage.modules.company.model.dto.CompanySaveRequest;
|
||||
import com.nanri.aiimage.modules.company.model.vo.CompanyVo;
|
||||
import com.nanri.aiimage.modules.company.service.CompanyService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
@@ -35,9 +37,12 @@ public class CompanyController {
|
||||
|
||||
@GetMapping("/companies")
|
||||
@Operation(summary = "公司目录:仅超级管理员可读,非超管一律 403")
|
||||
public ApiResponse<List<CompanyVo>> listCompanies(HttpServletRequest request) {
|
||||
public ApiResponse<List<CompanyVo>> listCompanies(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "所属平台(V206):amazon|jd,缺省不过滤")
|
||||
@RequestParam(name = "platform", required = false) String platform) {
|
||||
AdminUserEntity operator = adminAuthSupport.requireAdminOrInternal(request);
|
||||
List<CompanyVo> items = companyService.listVisible(operator).stream().map(CompanyVo::from).toList();
|
||||
List<CompanyVo> items = companyService.listVisible(operator, platform).stream().map(CompanyVo::from).toList();
|
||||
return ApiResponse.success(items);
|
||||
}
|
||||
|
||||
|
||||
+4
@@ -14,4 +14,8 @@ public class CompanySaveRequest {
|
||||
/** 1=启用 0=停用;null 按启用(与 company.status 的 DEFAULT 1 一致)。 */
|
||||
private Integer status;
|
||||
private String remark;
|
||||
/**
|
||||
* 所属平台(V206):新建 null/空白按 'amazon';编辑 null=不动,给了就只认 amazon|jd。
|
||||
*/
|
||||
private String platform;
|
||||
}
|
||||
|
||||
+5
@@ -22,6 +22,11 @@ public class CompanyEntity {
|
||||
/** 1=启用 0=停用。停用不删行:有账号挂着的公司删不掉。 */
|
||||
private Integer status;
|
||||
private String remark;
|
||||
/**
|
||||
* 所属平台(V206 新增):amazon|jd,与后管侧边栏平台 tab 同字面量。只作用于后管
|
||||
* 公司管理页的显示与筛选;存量 DEFAULT 'amazon',京东侧由使用者在编辑弹窗里翻档。
|
||||
*/
|
||||
private String platform;
|
||||
@TableField("created_at")
|
||||
private LocalDateTime createdAt;
|
||||
@TableField("updated_at")
|
||||
|
||||
@@ -20,6 +20,9 @@ public class CompanyVo {
|
||||
private String companyName;
|
||||
private Integer status;
|
||||
private String remark;
|
||||
/** 所属平台(V206):amazon|jd,与后管侧边栏平台 tab 同字面量。 */
|
||||
@JsonProperty("platform")
|
||||
private String platform;
|
||||
@JsonProperty("created_at")
|
||||
private String createdAt;
|
||||
@JsonProperty("updated_at")
|
||||
@@ -31,6 +34,7 @@ public class CompanyVo {
|
||||
vo.setCompanyName(entity.getCompanyName());
|
||||
vo.setStatus(entity.getStatus());
|
||||
vo.setRemark(entity.getRemark());
|
||||
vo.setPlatform(entity.getPlatform());
|
||||
vo.setCreatedAt(entity.getCreatedAt() == null ? "" : entity.getCreatedAt().format(TIME));
|
||||
vo.setUpdatedAt(entity.getUpdatedAt() == null ? "" : entity.getUpdatedAt().format(TIME));
|
||||
return vo;
|
||||
|
||||
+22
-2
@@ -5,6 +5,7 @@ import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
import com.nanri.aiimage.common.service.AdminPlatformScope;
|
||||
import com.nanri.aiimage.modules.company.mapper.CompanyMapper;
|
||||
import com.nanri.aiimage.modules.company.model.dto.CompanySaveRequest;
|
||||
import com.nanri.aiimage.modules.company.model.entity.CompanyEntity;
|
||||
@@ -59,6 +60,14 @@ public class CompanyService {
|
||||
* 角色不会被"忘了授权"打穿,所以这里用 {@link #ensureSuperAdmin} 与写入口共用同一个出口。</p>
|
||||
*/
|
||||
public List<CompanyEntity> listVisible(AdminUserEntity operator) {
|
||||
return listVisible(operator, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 带平台过滤的公司目录(V206):platform 非空白时只返回该平台的公司(amazon|jd,非法值 400),
|
||||
* 后管「公司管理」页按当前平台 tab 传参;null/空白=不过滤,旧调用方口径不变。
|
||||
*/
|
||||
public List<CompanyEntity> listVisible(AdminUserEntity operator, String platform) {
|
||||
String role = adminAuthSupport.currentRole(operator);
|
||||
if (role == null) {
|
||||
throw new BusinessException(403, "需要管理员权限");
|
||||
@@ -66,8 +75,13 @@ public class CompanyService {
|
||||
// 读写都只超管(spec §2 的 A 类):判角色、不判菜单授权——
|
||||
// 12:3x 已经证明"把可见性挂在 user_column_permission 上"会因一笔授权没发而全员 403。
|
||||
ensureSuperAdmin(operator);
|
||||
return companyMapper.selectList(new LambdaQueryWrapper<CompanyEntity>()
|
||||
.orderByAsc(CompanyEntity::getId));
|
||||
LambdaQueryWrapper<CompanyEntity> query = new LambdaQueryWrapper<>();
|
||||
String platformValue = AdminPlatformScope.normalizeOrNull(platform);
|
||||
if (platformValue != null) {
|
||||
query.eq(CompanyEntity::getPlatform, platformValue);
|
||||
}
|
||||
query.orderByAsc(CompanyEntity::getId);
|
||||
return companyMapper.selectList(query);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,6 +141,7 @@ public class CompanyService {
|
||||
entity.setCompanyName(companyName);
|
||||
entity.setStatus(status);
|
||||
entity.setRemark(remark);
|
||||
entity.setPlatform(AdminPlatformScope.normalizeOrCreate(request.getPlatform()));
|
||||
companyMapper.insert(entity);
|
||||
permissionMenuService.copyTreeFromTemplate(entity.getId(), operator.getCompanyId());
|
||||
return entity;
|
||||
@@ -142,12 +157,17 @@ public class CompanyService {
|
||||
String companyName = requireValidName(request.getCompanyName());
|
||||
int status = resolveStatus(request.getStatus());
|
||||
String remark = normalizeRemark(request.getRemark());
|
||||
// 平台只在显式给出时落(null/空白=不动),与 users 的 PUT 同口径
|
||||
String platform = AdminPlatformScope.normalizeOrNull(request.getPlatform());
|
||||
// 排除自己:只改备注时名字没变,不排除就会把合法编辑判成重名
|
||||
ensureNameAvailable(companyName, id);
|
||||
|
||||
company.setCompanyName(companyName);
|
||||
company.setStatus(status);
|
||||
company.setRemark(remark);
|
||||
if (platform != null) {
|
||||
company.setPlatform(platform);
|
||||
}
|
||||
companyMapper.updateById(company);
|
||||
return company;
|
||||
}
|
||||
|
||||
+11
-18
@@ -8,14 +8,13 @@ import com.nanri.aiimage.modules.jd.mapper.JdProductMapper;
|
||||
import com.nanri.aiimage.modules.permission.support.UserDataScopeSupport;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 商品上架配额(2026-11-15 用户口径「限制管理员上架的商品数量,包括管理员下的员工
|
||||
* 总和不能超过配置的最大值」,默认 5000,{@code aiimage.jd.max-products-per-admin})。
|
||||
* 总和不能超过管理员账号设置的最大值」,默认 5000。
|
||||
*
|
||||
* <p>计数口径=团队在京东数据库({@code biz_jd_product})占有的行数:上架功能的数据源
|
||||
* 就是京东数据库,团队占有量即「可上架量」的上游闸。归属列 {@code user_id}=任务 owner
|
||||
@@ -38,9 +37,7 @@ public class JdPublishQuotaService {
|
||||
private final UserDataScopeSupport userDataScopeSupport;
|
||||
private final JdProductMapper jdProductMapper;
|
||||
|
||||
/** 出厂默认与 application.yml 的 aiimage.jd.max-products-per-admin 逐字相等(棘轮);包级可见供同包测试直设。 */
|
||||
@Value("${aiimage.jd.max-products-per-admin:5000}")
|
||||
long maxProductsPerAdmin = 5000L;
|
||||
private static final long DEFAULT_QUOTA = 5000L;
|
||||
|
||||
/** 配额只读快照:used=团队已占有行数,limit=配置上限(≤0=不限)。 */
|
||||
public record QuotaSnapshot(long used, long limit) {
|
||||
@@ -51,9 +48,13 @@ public class JdPublishQuotaService {
|
||||
|
||||
/** 团队已占用与上限的只读快照;uid 集为空(无主管且无 id)按 used=0 处理,不进 SQL。 */
|
||||
public QuotaSnapshot quotaOf(AdminUserEntity operator) {
|
||||
List<Long> userIds = teamUserIds(operator);
|
||||
AdminUserEntity anchor = operator == null ? null : anchorOf(operator);
|
||||
List<Long> userIds = anchor == null || anchor.getId() == null ? List.of()
|
||||
: userDataScopeSupport.resolveVisibleUserIds(anchor);
|
||||
long used = userIds.isEmpty() ? 0L : jdProductMapper.countByUserIds(userIds);
|
||||
return new QuotaSnapshot(used, maxProductsPerAdmin);
|
||||
long limit = anchor == null || anchor.getJdPublishQuota() == null
|
||||
? DEFAULT_QUOTA : anchor.getJdPublishQuota();
|
||||
return new QuotaSnapshot(used, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,14 +62,14 @@ public class JdPublishQuotaService {
|
||||
* 上限 ≤0(0=不限)放行;{@code additionalCount} 为负按 0 处理(本闸只判限不预占)。
|
||||
*/
|
||||
public void assertWithinQuota(AdminUserEntity operator, int additionalCount) {
|
||||
if (maxProductsPerAdmin <= 0) {
|
||||
return;
|
||||
}
|
||||
if (operator != null && DeviceSessionPolicy.isSuperAdmin(
|
||||
operator.getRole(), operator.getIsAdmin(), operator.getCreatedById())) {
|
||||
return;
|
||||
}
|
||||
QuotaSnapshot snapshot = quotaOf(operator);
|
||||
if (snapshot.unlimited()) {
|
||||
return;
|
||||
}
|
||||
long requested = Math.max(0, additionalCount);
|
||||
if (snapshot.used() + requested > snapshot.limit()) {
|
||||
log.warn("[jd-publish] 商品上架配额不足 operatorId={} used={} requested={} limit={}",
|
||||
@@ -80,14 +81,6 @@ public class JdPublishQuotaService {
|
||||
}
|
||||
}
|
||||
|
||||
/** 普通账号锚定到其所属管理员(created_by_id);管理员/公司超管锚自己;无 id 返回空集。 */
|
||||
private List<Long> teamUserIds(AdminUserEntity operator) {
|
||||
if (operator == null || operator.getId() == null) {
|
||||
return List.of();
|
||||
}
|
||||
return userDataScopeSupport.resolveVisibleUserIds(anchorOf(operator));
|
||||
}
|
||||
|
||||
private AdminUserEntity anchorOf(AdminUserEntity operator) {
|
||||
// resolveRole 对普通账号返回 null(角色域只有 super_admin/company_super_admin/admin/null)
|
||||
if (DeviceSessionPolicy.resolveRole(
|
||||
|
||||
+4
-3
@@ -131,15 +131,16 @@ public class ShopManageController {
|
||||
public ApiResponse<java.util.List<ShopManageGroupItemVo>> listGroups(
|
||||
HttpServletRequest request,
|
||||
@Parameter(description = "创建人用户ID") @RequestParam(required = false) Long createdById,
|
||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId) {
|
||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||
@Parameter(description = "所属平台(V206):amazon|jd,缺省不过滤") @RequestParam(required = false) String platform) {
|
||||
AdminUserEntity operator = requireOperator(request);
|
||||
if (isSuper(operator)) {
|
||||
// 公司 tab 只收窄可见集;list() 内按组长两列(created_by_id / user_id)认归属。
|
||||
List<Long> memberIds = dataReadScope.readScope(operator, companyId).userIdsOr(null);
|
||||
return ApiResponse.success(shopManageGroupService.list(createdById, memberIds));
|
||||
return ApiResponse.success(shopManageGroupService.list(createdById, memberIds, platform));
|
||||
}
|
||||
Long operatorId = operator.getId();
|
||||
return ApiResponse.success(shopManageGroupService.listAccessible(operatorId, false));
|
||||
return ApiResponse.success(shopManageGroupService.listAccessible(operatorId, false, platform));
|
||||
}
|
||||
|
||||
@PostMapping("/groups")
|
||||
|
||||
+3
@@ -20,4 +20,7 @@ public class ShopManageGroupCreateRequest {
|
||||
@Schema(description = "创建人用户ID,由后台代理透传", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "创建人不能为空")
|
||||
private Long createdById;
|
||||
|
||||
@Schema(description = "所属平台(V206):amazon|jd;空白按 'amazon'")
|
||||
private String platform;
|
||||
}
|
||||
|
||||
+3
@@ -15,4 +15,7 @@ public class ShopManageGroupUpdateRequest {
|
||||
|
||||
@Schema(description = "组员用户ID列表")
|
||||
private List<Long> memberUserIds;
|
||||
|
||||
@Schema(description = "所属平台(V206):null=不动;给了就只认 amazon|jd")
|
||||
private String platform;
|
||||
}
|
||||
|
||||
+2
@@ -9,6 +9,8 @@ import java.util.List;
|
||||
public class ShopManageGroupItemVo {
|
||||
private Long id;
|
||||
private String groupName;
|
||||
/** 所属平台(V206):amazon|jd,与后管侧边栏平台 tab 同字面量。 */
|
||||
private String platform;
|
||||
private Long leaderUserId;
|
||||
private String leaderUsername;
|
||||
private List<Long> memberUserIds;
|
||||
|
||||
+34
-4
@@ -8,6 +8,7 @@ import com.nanri.aiimage.modules.shopkey.mapper.QueryAsinMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.spi.GroupDeletionGuardPort;
|
||||
import com.nanri.aiimage.common.mapper.ShopManageGroupMapper;
|
||||
import com.nanri.aiimage.common.security.DeviceSessionPolicy;
|
||||
import com.nanri.aiimage.common.service.AdminPlatformScope;
|
||||
import com.nanri.aiimage.common.service.CompanyScopeSupport;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.ShopManageGroupMemberMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.ShopManageMapper;
|
||||
@@ -52,8 +53,20 @@ public class ShopManageGroupService {
|
||||
}
|
||||
|
||||
public List<ShopManageGroupItemVo> list(Long createdById, List<Long> companyMemberIds) {
|
||||
return list(createdById, companyMemberIds, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 带平台过滤的分组列表(V206):platform 非空白时只返回该平台的分组(amazon|jd,非法值 400),
|
||||
* 后管「分组管理」页按当前平台 tab 传参;null/空白=不过滤,旧调用方口径不变。
|
||||
*/
|
||||
public List<ShopManageGroupItemVo> list(Long createdById, List<Long> companyMemberIds, String platform) {
|
||||
LambdaQueryWrapper<ShopManageGroupEntity> qw = new LambdaQueryWrapper<ShopManageGroupEntity>()
|
||||
.orderByAsc(ShopManageGroupEntity::getId);
|
||||
String platformValue = AdminPlatformScope.normalizeOrNull(platform);
|
||||
if (platformValue != null) {
|
||||
qw.eq(ShopManageGroupEntity::getPlatform, platformValue);
|
||||
}
|
||||
if (createdById != null && createdById > 0) {
|
||||
// 这两条原本是平铺的 .eq(...).or(...):MP 的 normal 段按顺序拼 AND/OR,MySQL 里 AND 优先,
|
||||
// 外面再叠一条公司条件时 created_by_id = ? 那半边会整块逃出筛选(多放行、不报错)⇒ 必须收进 and()。
|
||||
@@ -77,16 +90,26 @@ public class ShopManageGroupService {
|
||||
}
|
||||
|
||||
public List<ShopManageGroupItemVo> listAccessible(Long operatorId, boolean superAdmin) {
|
||||
return listAccessible(operatorId, superAdmin, null);
|
||||
}
|
||||
|
||||
/** 带平台过滤的可见分组列表(V206):platform 非空白时只返回该平台的分组,null/空白=不过滤。 */
|
||||
public List<ShopManageGroupItemVo> listAccessible(Long operatorId, boolean superAdmin, String platform) {
|
||||
String platformValue = AdminPlatformScope.normalizeOrNull(platform);
|
||||
if (superAdmin) {
|
||||
return list();
|
||||
return list(null, null, platformValue);
|
||||
}
|
||||
Set<Long> groupIds = listAccessibleGroupIds(operatorId, false);
|
||||
if (groupIds.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
return toVoList(groupMapper.selectList(new LambdaQueryWrapper<ShopManageGroupEntity>()
|
||||
.in(ShopManageGroupEntity::getId, groupIds)
|
||||
.orderByAsc(ShopManageGroupEntity::getId)));
|
||||
LambdaQueryWrapper<ShopManageGroupEntity> qw = new LambdaQueryWrapper<ShopManageGroupEntity>()
|
||||
.in(ShopManageGroupEntity::getId, groupIds);
|
||||
if (platformValue != null) {
|
||||
qw.eq(ShopManageGroupEntity::getPlatform, platformValue);
|
||||
}
|
||||
qw.orderByAsc(ShopManageGroupEntity::getId);
|
||||
return toVoList(groupMapper.selectList(qw));
|
||||
}
|
||||
|
||||
public Set<Long> listAccessibleGroupIds(Long operatorId, boolean superAdmin) {
|
||||
@@ -179,6 +202,7 @@ public class ShopManageGroupService {
|
||||
entity.setGroupName(groupName);
|
||||
entity.setCreatedById(createdById);
|
||||
entity.setCompanyId(companyId);
|
||||
entity.setPlatform(AdminPlatformScope.normalizeOrCreate(request.getPlatform()));
|
||||
groupMapper.insert(entity);
|
||||
replaceMembers(entity.getId(), request.getMemberUserIds(), createdById, operatorId, superAdmin);
|
||||
return toVo(getById(entity.getId()));
|
||||
@@ -197,6 +221,11 @@ public class ShopManageGroupService {
|
||||
|
||||
entity.setGroupName(groupName);
|
||||
entity.setCompanyId(companyId);
|
||||
// 平台只在显式给出时落(null/空白=不动),与 users/company 的 PUT 同口径
|
||||
String platformUpdate = AdminPlatformScope.normalizeOrNull(request.getPlatform());
|
||||
if (platformUpdate != null) {
|
||||
entity.setPlatform(platformUpdate);
|
||||
}
|
||||
groupMapper.updateById(entity);
|
||||
// 组长取 resolveGroupLeaderUserId 而不是 created_by_id:生产有 2 个分组只有 user_id
|
||||
// (见 listCompanyGroupIds 的注释),只认 created_by_id 会让那 2 个分组绕过组员的公司校验。
|
||||
@@ -488,6 +517,7 @@ public class ShopManageGroupService {
|
||||
ShopManageGroupItemVo vo = new ShopManageGroupItemVo();
|
||||
vo.setId(entity.getId());
|
||||
vo.setGroupName(entity.getGroupName());
|
||||
vo.setPlatform(entity.getPlatform());
|
||||
Long leaderUserId = resolveGroupLeaderUserId(entity);
|
||||
vo.setLeaderUserId(leaderUserId);
|
||||
AdminUserEntity leaderUser = leaderUserId == null ? null : userById.get(leaderUserId);
|
||||
|
||||
@@ -177,11 +177,6 @@ aiimage:
|
||||
# SKU 矩阵单商品上限(V198 详情面):真机一个商品 12 行,超限截断并 WARN,
|
||||
# 防脏回传把整批撑爆。显式写在这里,不许只活在代码默认值里。
|
||||
sku-max-per-product: ${AIIMAGE_JD_SKU_MAX_PER_PRODUCT:200}
|
||||
# 商品上架配额(2026-11-15 用户口径):单个管理员(含其名下员工合计;公司超管按
|
||||
# 全公司合计)可上架的商品数上限,默认 5000;0=不限。计数源=biz_jd_product 按
|
||||
# owner uid 集计行数(上架功能的数据源就是京东数据库);站点超管不限额。
|
||||
# 校验出口=JdPublishQuotaService,商品上架建单入口落地时调用。
|
||||
max-products-per-admin: ${AIIMAGE_JD_MAX_PRODUCTS_PER_ADMIN:5000}
|
||||
# 设备日志对象存储:主机B 独立 MinIO(与业务 OSS 隔离,日志只保留 7 天)。
|
||||
# endpoint 未配置时日志上报/管理接口不可用(宁可失败也不静默落到业务桶)。
|
||||
# 桶的 7 天过期规则由运维用 mc 配置(与 retention-days 口径一致)。
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
-- =============================================================
|
||||
-- 迁移 V206__admin_account_platform
|
||||
-- 需求:2026-11-17 用户口径「用户管理/分组管理/公司管理亚马逊这边也要有」+
|
||||
-- 「京东是也有,但是数据都是新的,别把亚马逊的带过来」——后管三类账号域数据
|
||||
-- (users / company / biz_shop_manage_group)从全系统共用一份改成按平台(amazon/jd)
|
||||
-- 各管各的:后管在哪个平台 tab 下就只看/管那个平台的账号、分组、公司。
|
||||
-- 前版:V153(分组表挂 company_id)→ V202 待改号件(jd_publish_quota,另一窗在飞,见下)
|
||||
--
|
||||
-- 1. 变更目的:三张表各加一个「所属平台」标记列。存量一律 DEFAULT 'amazon'(亚马逊业务
|
||||
-- 一直在用这套账号;京东侧新录的数据由使用者在编辑弹窗里自己翻成 'jd',本迁移不做
|
||||
-- 数据驱动的自动归类——按引用猜归属会错分)。平台语义只作用于后管三个管理页的
|
||||
-- 显示与筛选:登录、用户端功能、任务权限、DataReadScope 全部不动。
|
||||
--
|
||||
-- 2. 号段协调(重要,写给并行的 jd_publish_quota 窗):V202 号已随 764eeb29 永久退役
|
||||
-- (RETIRED_HOLES),那个待入库的 V202__users_jd_publish_quota.sql 按 AGENTS.md 铁律 33
|
||||
-- 必须改号 V206+ 才能入库;本笔先占 V206,改号件请取 V207 及以上——若改号撞到 V206
|
||||
-- 会触发 MigrationInventoryTest 的重复版本断言(同 V148 先例:宁可测试红,不把撞号
|
||||
-- 留到 Flyway 运行期)。
|
||||
--
|
||||
-- 3. 口径:
|
||||
-- users + platform VARCHAR(16) NOT NULL DEFAULT 'amazon'
|
||||
-- company + platform VARCHAR(16) NOT NULL DEFAULT 'amazon'
|
||||
-- biz_shop_manage_group + platform VARCHAR(16) NOT NULL DEFAULT 'amazon'
|
||||
-- 取值字面量与 admin-frontend-vue 的 PlatformTabId 同源:'amazon' | 'jd'。
|
||||
-- users 是双映射表(AdminUserEntity + LoginUserEntity),实体两侧同加,UsersCompanyIdMappingTest 钉住。
|
||||
--
|
||||
-- 4. 可重跑性:三条列 DDL 都先查 information_schema 再 PREPARE,重跑逐条 no-op;
|
||||
-- ADD COLUMN ... DEFAULT 走 ALGORITHM = INSTANT(users 行数大,不锁表)。
|
||||
--
|
||||
-- 5. 回滚(人工补丁,写成注释以免落在 Flyway 扫描路径里被当迁移执行):
|
||||
-- ALTER TABLE users DROP COLUMN platform;
|
||||
-- ALTER TABLE company DROP COLUMN platform;
|
||||
-- ALTER TABLE biz_shop_manage_group DROP COLUMN platform;
|
||||
-- (jar 必须先回到"无平台维度"的那版,否则实体按不存在的列 select 会 500。)
|
||||
-- =============================================================
|
||||
|
||||
SET @db_name = DATABASE();
|
||||
|
||||
-- ---------- 1. users:所属平台(双映射实体同改) ----------
|
||||
|
||||
SET @v206_users_col := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db_name AND TABLE_NAME = 'users' AND COLUMN_NAME = 'platform');
|
||||
SET @sql := IF(@v206_users_col = 0,
|
||||
'ALTER TABLE `users` ADD COLUMN `platform` VARCHAR(16) NOT NULL DEFAULT ''amazon'' COMMENT ''所属平台(V206):amazon|jd,与后管平台 tab 同字面量;只作用于后管用户管理页的显示与筛选'', ALGORITHM = INSTANT',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------- 2. company:所属平台 ----------
|
||||
|
||||
SET @v206_company_col := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db_name AND TABLE_NAME = 'company' AND COLUMN_NAME = 'platform');
|
||||
SET @sql := IF(@v206_company_col = 0,
|
||||
'ALTER TABLE `company` ADD COLUMN `platform` VARCHAR(16) NOT NULL DEFAULT ''amazon'' COMMENT ''所属平台(V206):amazon|jd,与后管平台 tab 同字面量;只作用于后管公司管理页的显示与筛选'', ALGORITHM = INSTANT',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- ---------- 3. biz_shop_manage_group:所属平台 ----------
|
||||
|
||||
SET @v206_group_col := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = @db_name AND TABLE_NAME = 'biz_shop_manage_group' AND COLUMN_NAME = 'platform');
|
||||
SET @sql := IF(@v206_group_col = 0,
|
||||
'ALTER TABLE `biz_shop_manage_group` ADD COLUMN `platform` VARCHAR(16) NOT NULL DEFAULT ''amazon'' COMMENT ''所属平台(V206):amazon|jd,与后管平台 tab 同字面量;只作用于后管分组管理页的显示与筛选'', ALGORITHM = INSTANT',
|
||||
'SELECT 1');
|
||||
PREPARE stmt FROM @sql;
|
||||
EXECUTE stmt;
|
||||
DEALLOCATE PREPARE stmt;
|
||||
|
||||
-- =============================================================
|
||||
-- 验证 SQL(迁移后在库上执行,必须有人实跑,不许只看启动日志的 Successfully applied)
|
||||
--
|
||||
-- SHOW COLUMNS FROM users LIKE 'platform';
|
||||
-- SHOW COLUMNS FROM company LIKE 'platform';
|
||||
-- SHOW COLUMNS FROM biz_shop_manage_group LIKE 'platform';
|
||||
-- -> 三条都期望 Null = NO、Default = 'amazon'、Type = varchar(16)。
|
||||
--
|
||||
-- SELECT platform, COUNT(*) FROM users GROUP BY platform;
|
||||
-- -> 迁移后只有 'amazon' 一档(存量全归亚马逊,京东侧由使用者在界面翻档)。
|
||||
-- =============================================================
|
||||
@@ -0,0 +1,5 @@
|
||||
-- 迁移 V207:逐管理员设置京东上架额度;0 表示不限。已有账号保留原默认额度。
|
||||
-- 号段协调(2026-11-17):原 V202 号已被 V203/V204/V205 按序越过(764eeb29 把 202 登记
|
||||
-- RETIRED_HOLES),按其明文要求改号入库;V206 被同窗 admin_account_platform(三表平台列)占用,
|
||||
-- 故本件取 V207。改号只动文件名与头注释,ALTER 语句一个字节未变(可重入:加列前查重)。
|
||||
ALTER TABLE users ADD COLUMN jd_publish_quota INT NOT NULL DEFAULT 5000;
|
||||
@@ -88,9 +88,18 @@ class MigrationInventoryTest {
|
||||
* 目录最大值升到 170 之后若回填新内容,已应用 170 的环境在 Flyway out-of-order 关闭下会把它当
|
||||
* ignored migration 静默跳过,各环境 Schema 悄悄漂移。与 148 不同这不是并发护栏,是既成跳号的封账。</p>
|
||||
*
|
||||
* <p><b>202</b>:{@code V202__users_jd_publish_quota.sql}(users.jd_publish_quota,工作台商品上架配额)
|
||||
* 由并行会话在写、截至 2026-11-17 发版窗仍未入库;而 V203(61ab844e)已于 2026-11-16 21:1x 上线、
|
||||
* V204(aff6c88a)与 V205(任务证据下线,71b19e4f)随 2026-11-17 发版窗越过 202 落库。
|
||||
* Flyway 未开 out-of-order ⇒ 该路径入库前必须把文件改名到 V206+(RELEASE_LEDGER 2026-11-16
|
||||
* 22:2x 段的顺序债登记);把新迁移写回 202 会让已过 205 的环境启动期报
|
||||
* "resolved migration not applied" 失败。与 132/133 同属"只能永久保留、不能回填"。
|
||||
* 2026-11-17 已改号 {@code V207__users_jd_publish_quota.sql} 入库(V206 被同窗
|
||||
* admin_account_platform 三表平台列占用,account-platform 提交);202 号自此彻底空置。</p>
|
||||
*
|
||||
* <p>共同后果:新迁移只能取当前最大值之上的号(详见 docs/migration-inventory.md)。</p>
|
||||
*/
|
||||
private static final Set<Integer> RETIRED_HOLES = Set.of(132, 133, 148, 168, 169);
|
||||
private static final Set<Integer> RETIRED_HOLES = Set.of(132, 133, 148, 168, 169, 202);
|
||||
|
||||
/**
|
||||
* 文件名版本与头注释版本不一致的历史件。V170 的头注释误写成 V168;它已应用到生产,
|
||||
|
||||
+544
@@ -0,0 +1,544 @@
|
||||
package com.nanri.aiimage.modules.admin.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
||||
import com.nanri.aiimage.common.exception.BusinessException;
|
||||
import com.nanri.aiimage.common.mapper.AdminUserMapper;
|
||||
import com.nanri.aiimage.common.mapper.ShopManageGroupMapper;
|
||||
import com.nanri.aiimage.common.model.entity.AdminUserEntity;
|
||||
import com.nanri.aiimage.common.model.entity.ShopManageGroupEntity;
|
||||
import com.nanri.aiimage.common.security.AdminAuthSupport;
|
||||
import com.nanri.aiimage.common.service.AdminPlatformScope;
|
||||
import com.nanri.aiimage.common.service.CompanyScopeSupport;
|
||||
import com.nanri.aiimage.modules.admin.model.dto.AdminUserCreateRequest;
|
||||
import com.nanri.aiimage.modules.admin.model.dto.AdminUserUpdateRequest;
|
||||
import com.nanri.aiimage.modules.admin.spi.UserSecretCleanupPort;
|
||||
import com.nanri.aiimage.modules.auth.util.WerkzeugPasswordEncoder;
|
||||
import com.nanri.aiimage.modules.company.mapper.CompanyMapper;
|
||||
import com.nanri.aiimage.modules.company.model.dto.CompanySaveRequest;
|
||||
import com.nanri.aiimage.modules.company.model.entity.CompanyEntity;
|
||||
import com.nanri.aiimage.modules.company.service.CompanyService;
|
||||
import com.nanri.aiimage.modules.permission.service.PermissionMenuService;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.QueryAsinMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.ShopManageGroupMemberMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.ShopManageMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.mapper.SkipPriceAsinMapper;
|
||||
import com.nanri.aiimage.modules.shopkey.model.dto.ShopManageGroupCreateRequest;
|
||||
import com.nanri.aiimage.modules.shopkey.model.dto.ShopManageGroupUpdateRequest;
|
||||
import com.nanri.aiimage.modules.shopkey.service.ShopManageGroupService;
|
||||
import com.nanri.aiimage.modules.shopkey.spi.GroupDeletionGuardPort;
|
||||
import org.apache.ibatis.builder.MapperBuilderAssistant;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* 账号域「所属平台」(V206,2026-11-17 用户口径「亚马逊这边也要有;京东的数据是新的,
|
||||
* 别把亚马逊的带过来」):users / company / biz_shop_manage_group 三张表各带 platform 列
|
||||
* (amazon|jd),后管三个管理页按平台 tab 过滤、新建默认当前平台、编辑只显式翻档。
|
||||
*
|
||||
* <p>判据钉四条形状:①列表过滤真的进 SQL 条件(打在 wrapper 参数上,不是打在返回值——
|
||||
* 返回空也可能是别的条件写反);②新建缺省落 'amazon'(与列 DEFAULT 同口径);③编辑只在
|
||||
* 显式给出时落(PUT 只带 disabled 的既有形状不得把平台冲掉);④非法值 400,不许静默归档。</p>
|
||||
*/
|
||||
class AdminAccountPlatformScopeTest {
|
||||
|
||||
private AdminUserMapper userMapper;
|
||||
private AdminAuthSupport authSupport;
|
||||
private PermissionMenuService permissionService;
|
||||
private CompanyService companyService;
|
||||
private AdminUserService userService;
|
||||
|
||||
private CompanyMapper companyMapper;
|
||||
private CompanyService standaloneCompanyService;
|
||||
|
||||
private ShopManageGroupMapper groupMapper;
|
||||
private ShopManageGroupMemberMapper groupMemberMapper;
|
||||
private CompanyScopeSupport companyScope;
|
||||
private AdminUserMapper groupAdminUserMapper;
|
||||
private ShopManageGroupService groupService;
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void setUp() {
|
||||
TableInfoHelper.initTableInfo(
|
||||
new MapperBuilderAssistant(new MybatisConfiguration(), ""), AdminUserEntity.class);
|
||||
TableInfoHelper.initTableInfo(
|
||||
new MapperBuilderAssistant(new MybatisConfiguration(), ""), CompanyEntity.class);
|
||||
TableInfoHelper.initTableInfo(
|
||||
new MapperBuilderAssistant(new MybatisConfiguration(), ""), ShopManageGroupEntity.class);
|
||||
|
||||
userMapper = mock(AdminUserMapper.class);
|
||||
authSupport = mock(AdminAuthSupport.class);
|
||||
permissionService = mock(PermissionMenuService.class);
|
||||
companyService = mock(CompanyService.class);
|
||||
userService = new AdminUserService(userMapper, mock(WerkzeugPasswordEncoder.class), authSupport,
|
||||
permissionService, mock(UserSecretCleanupPort.class), companyService);
|
||||
when(permissionService.hasAnyAdminMenu(any(), any())).thenReturn(true);
|
||||
when(userMapper.selectCount(any(LambdaQueryWrapper.class))).thenReturn(0L);
|
||||
when(userMapper.selectList(any(LambdaQueryWrapper.class))).thenReturn(List.of());
|
||||
|
||||
companyMapper = mock(CompanyMapper.class);
|
||||
standaloneCompanyService = new CompanyService(companyMapper, authSupport,
|
||||
mock(PermissionMenuService.class));
|
||||
when(companyMapper.selectCount(any(LambdaQueryWrapper.class))).thenReturn(0L);
|
||||
when(companyMapper.selectList(any(LambdaQueryWrapper.class))).thenReturn(List.of());
|
||||
|
||||
groupMapper = mock(ShopManageGroupMapper.class);
|
||||
groupMemberMapper = mock(ShopManageGroupMemberMapper.class);
|
||||
companyScope = mock(CompanyScopeSupport.class);
|
||||
groupAdminUserMapper = mock(AdminUserMapper.class);
|
||||
groupService = new ShopManageGroupService(groupMapper, groupMemberMapper,
|
||||
List.of(mock(GroupDeletionGuardPort.class)), mock(ShopManageMapper.class),
|
||||
mock(QueryAsinMapper.class), mock(SkipPriceAsinMapper.class),
|
||||
groupAdminUserMapper, companyScope);
|
||||
when(groupMapper.selectCount(any(LambdaQueryWrapper.class))).thenReturn(0L);
|
||||
when(groupMapper.selectList(any(LambdaQueryWrapper.class))).thenReturn(List.of());
|
||||
when(groupMemberMapper.selectList(any(LambdaQueryWrapper.class))).thenReturn(List.of());
|
||||
when(companyScope.requireCompanyId(any(AdminUserEntity.class))).thenReturn(5L);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 用户列表过滤
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void userListPlatformFilterBecomesAQueryCondition() {
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
|
||||
userService.listUsers(operator, 1, 10, null, null, null, null, "jd");
|
||||
|
||||
LambdaQueryWrapper<AdminUserEntity> query = capturedUserCountQuery();
|
||||
// MP 的参数是惰性入表的:先渲染 SQL 段再断参数值(同 AdminUserListCompanyTest 的断言顺序)
|
||||
assertThat(query.getSqlSegment()).contains("platform");
|
||||
assertThat(query.getParamNameValuePairs()).containsValue("jd");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void userListWithoutPlatformAddsNoCondition() {
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
|
||||
// 8 参重载传 null 与旧 7 参口径完全一致:不带平台时查询条件一个都没有
|
||||
userService.listUsers(operator, 1, 10, null, null, null, null, null);
|
||||
|
||||
assertThat(capturedUserCountQuery().getParamNameValuePairs()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void userListRejectsIllegalPlatformValue() {
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
|
||||
assertThatThrownBy(() -> userService.listUsers(operator, 1, 10, null, null, null, null, "taobao"))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessageContaining("所属平台");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 用户新建/编辑落库
|
||||
|
||||
@Test
|
||||
void createUserWithoutPlatformFallsBackToAmazon() {
|
||||
AdminUserEntity operator = operator(1L, "company_super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("company_super_admin");
|
||||
AtomicReference<AdminUserEntity> inserted = captureUserInsert();
|
||||
|
||||
AdminUserCreateRequest request = new AdminUserCreateRequest();
|
||||
request.setUsername("京东客服");
|
||||
request.setPassword("123456");
|
||||
request.setRole("normal");
|
||||
|
||||
userService.createUser(operator, request);
|
||||
|
||||
assertThat(inserted.get().getPlatform()).isEqualTo(AdminPlatformScope.AMAZON);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createUserWithExplicitJdPlatformStoresJd() {
|
||||
AdminUserEntity operator = operator(1L, "company_super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("company_super_admin");
|
||||
AtomicReference<AdminUserEntity> inserted = captureUserInsert();
|
||||
|
||||
AdminUserCreateRequest request = new AdminUserCreateRequest();
|
||||
request.setUsername("京东客服");
|
||||
request.setPassword("123456");
|
||||
request.setRole("normal");
|
||||
request.setPlatform("jd");
|
||||
|
||||
userService.createUser(operator, request);
|
||||
|
||||
assertThat(inserted.get().getPlatform()).isEqualTo(AdminPlatformScope.JD);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createUserRejectsIllegalPlatformValue() {
|
||||
AdminUserEntity operator = operator(1L, "company_super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("company_super_admin");
|
||||
|
||||
AdminUserCreateRequest request = new AdminUserCreateRequest();
|
||||
request.setUsername("京东客服");
|
||||
request.setPassword("123456");
|
||||
request.setRole("normal");
|
||||
request.setPlatform("taobao");
|
||||
|
||||
assertThatThrownBy(() -> userService.createUser(operator, request))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessageContaining("所属平台");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void updateUserWithPlatformOnlyStillAppliesIt() {
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
when(userMapper.selectById(11L)).thenReturn(target(11L, "admin"));
|
||||
when(userMapper.update(any(), any(LambdaUpdateWrapper.class))).thenReturn(1);
|
||||
|
||||
AdminUserUpdateRequest request = new AdminUserUpdateRequest();
|
||||
request.setPlatform("jd");
|
||||
|
||||
userService.updateUser(operator, 11L, request);
|
||||
|
||||
LambdaUpdateWrapper<AdminUserEntity> update = capturedUserUpdate();
|
||||
assertThat(update.getSqlSet()).contains("platform");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void disabledOnlyUpdateDoesNotTouchPlatform() {
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
when(userMapper.selectById(11L)).thenReturn(target(11L, "admin"));
|
||||
when(userMapper.update(any(), any(LambdaUpdateWrapper.class))).thenReturn(1);
|
||||
|
||||
AdminUserUpdateRequest request = new AdminUserUpdateRequest();
|
||||
request.setDisabled(true);
|
||||
|
||||
userService.updateUser(operator, 11L, request);
|
||||
|
||||
LambdaUpdateWrapper<AdminUserEntity> update = capturedUserUpdate();
|
||||
assertThat(update.getSqlSet()).contains("disabled_at");
|
||||
assertThat(update.getSqlSet()).doesNotContain("platform");
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateUserRejectsIllegalPlatformValue() {
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
when(userMapper.selectById(11L)).thenReturn(target(11L, "admin"));
|
||||
|
||||
AdminUserUpdateRequest request = new AdminUserUpdateRequest();
|
||||
request.setPlatform("taobao");
|
||||
|
||||
assertThatThrownBy(() -> userService.updateUser(operator, 11L, request))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessageContaining("所属平台");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 公司目录过滤与落库
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void companyListPlatformFilterBecomesAQueryCondition() {
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
|
||||
standaloneCompanyService.listVisible(operator, "jd");
|
||||
|
||||
ArgumentCaptor<LambdaQueryWrapper> captor = ArgumentCaptor.forClass((Class) LambdaQueryWrapper.class);
|
||||
verify(companyMapper).selectList(captor.capture());
|
||||
// MP 的参数是惰性入表的:先渲染 SQL 段再断参数值
|
||||
assertThat(captor.getValue().getSqlSegment()).contains("platform");
|
||||
assertThat(captor.getValue().getParamNameValuePairs()).containsValue("jd");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void companyListWithoutPlatformAddsNoCondition() {
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
|
||||
standaloneCompanyService.listVisible(operator);
|
||||
|
||||
ArgumentCaptor<LambdaQueryWrapper> captor = ArgumentCaptor.forClass((Class) LambdaQueryWrapper.class);
|
||||
verify(companyMapper).selectList(captor.capture());
|
||||
assertThat(captor.getValue().getParamNameValuePairs()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void createCompanyWithoutPlatformFallsBackToAmazon() {
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
AtomicReference<CompanyEntity> inserted = captureCompanyInsert();
|
||||
|
||||
CompanySaveRequest request = new CompanySaveRequest();
|
||||
request.setCompanyName("京东事业部");
|
||||
|
||||
standaloneCompanyService.create(operator, request);
|
||||
|
||||
assertThat(inserted.get().getPlatform()).isEqualTo(AdminPlatformScope.AMAZON);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateCompanyKeepsPlatformWhenRequestOmitsIt() {
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
CompanyEntity existing = companyRow(2L, "京东事业部");
|
||||
existing.setPlatform(AdminPlatformScope.JD);
|
||||
when(companyMapper.selectById(2L)).thenReturn(existing);
|
||||
when(companyMapper.updateById(any(CompanyEntity.class))).thenReturn(1);
|
||||
|
||||
CompanySaveRequest request = new CompanySaveRequest();
|
||||
request.setCompanyName("京东事业部");
|
||||
|
||||
CompanyEntity saved = standaloneCompanyService.update(operator, 2L, request);
|
||||
|
||||
assertThat(saved.getPlatform()).isEqualTo(AdminPlatformScope.JD);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateCompanyWithExplicitPlatformReassignsIt() {
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
CompanyEntity existing = companyRow(2L, "老公司");
|
||||
existing.setPlatform(AdminPlatformScope.AMAZON);
|
||||
when(companyMapper.selectById(2L)).thenReturn(existing);
|
||||
when(companyMapper.updateById(any(CompanyEntity.class))).thenReturn(1);
|
||||
|
||||
CompanySaveRequest request = new CompanySaveRequest();
|
||||
request.setCompanyName("老公司");
|
||||
request.setPlatform("jd");
|
||||
|
||||
CompanyEntity saved = standaloneCompanyService.update(operator, 2L, request);
|
||||
|
||||
assertThat(saved.getPlatform()).isEqualTo(AdminPlatformScope.JD);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 分组列表过滤与落库
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void groupListPlatformFilterBecomesAQueryCondition() {
|
||||
groupService.list(null, null, "jd");
|
||||
|
||||
ArgumentCaptor<LambdaQueryWrapper> captor = ArgumentCaptor.forClass((Class) LambdaQueryWrapper.class);
|
||||
verify(groupMapper).selectList(captor.capture());
|
||||
// MP 的参数是惰性入表的:先渲染 SQL 段再断参数值
|
||||
assertThat(captor.getValue().getSqlSegment()).contains("platform");
|
||||
assertThat(captor.getValue().getParamNameValuePairs()).containsValue("jd");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void groupListWithoutPlatformAddsNoCondition() {
|
||||
groupService.list(null, null);
|
||||
|
||||
ArgumentCaptor<LambdaQueryWrapper> captor = ArgumentCaptor.forClass((Class) LambdaQueryWrapper.class);
|
||||
verify(groupMapper).selectList(captor.capture());
|
||||
assertThat(captor.getValue().getParamNameValuePairs()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void groupListRejectsIllegalPlatformValue() {
|
||||
assertThatThrownBy(() -> groupService.list(null, null, "taobao"))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessageContaining("所属平台");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createGroupWithExplicitPlatformStoresJd() {
|
||||
stubGroupInsertCapturing();
|
||||
AdminUserEntity leader = operator(2L, "admin", 5L);
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(groupAdminUserMapper.selectById(2L)).thenReturn(leader);
|
||||
when(groupAdminUserMapper.selectById(1L)).thenReturn(operator);
|
||||
|
||||
ShopManageGroupCreateRequest request = new ShopManageGroupCreateRequest();
|
||||
request.setGroupName("京东采集组");
|
||||
request.setCreatedById(2L);
|
||||
request.setPlatform("jd");
|
||||
|
||||
groupService.create(request, 1L, true);
|
||||
|
||||
assertThat(groupInsertCaptor.get().getPlatform()).isEqualTo(AdminPlatformScope.JD);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createGroupWithoutPlatformFallsBackToAmazon() {
|
||||
stubGroupInsertCapturing();
|
||||
AdminUserEntity leader = operator(2L, "admin", 5L);
|
||||
AdminUserEntity operator = operator(1L, "super_admin", 5L);
|
||||
when(groupAdminUserMapper.selectById(2L)).thenReturn(leader);
|
||||
when(groupAdminUserMapper.selectById(1L)).thenReturn(operator);
|
||||
|
||||
ShopManageGroupCreateRequest request = new ShopManageGroupCreateRequest();
|
||||
request.setGroupName("亚马逊采集组");
|
||||
request.setCreatedById(2L);
|
||||
|
||||
groupService.create(request, 1L, true);
|
||||
|
||||
assertThat(groupInsertCaptor.get().getPlatform()).isEqualTo(AdminPlatformScope.AMAZON);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateGroupKeepsPlatformWhenRequestOmitsIt() {
|
||||
ShopManageGroupEntity existing = groupRow(9L, "采集组");
|
||||
existing.setPlatform(AdminPlatformScope.JD);
|
||||
when(groupMapper.selectById(9L)).thenReturn(existing);
|
||||
AdminUserEntity leader = operator(2L, "admin", 5L);
|
||||
when(groupAdminUserMapper.selectById(2L)).thenReturn(leader);
|
||||
// validateManageAccess(超管档)还要按操作者再查一次公司:漏桩会让 requireCompanyId
|
||||
// 拿到 null 账号、any(AdminUserEntity.class) 匹配不上 null ⇒ 组长/操作者公司判不一致
|
||||
when(groupAdminUserMapper.selectById(1L)).thenReturn(operator(1L, "super_admin", 5L));
|
||||
when(groupMapper.updateById(any(ShopManageGroupEntity.class))).thenReturn(1);
|
||||
when(groupAdminUserMapper.selectBatchIds(any())).thenReturn(List.of());
|
||||
|
||||
ShopManageGroupUpdateRequest request = new ShopManageGroupUpdateRequest();
|
||||
request.setGroupName("采集组");
|
||||
|
||||
groupService.update(9L, 1L, true, request);
|
||||
|
||||
ArgumentCaptor<ShopManageGroupEntity> captor = ArgumentCaptor.forClass(ShopManageGroupEntity.class);
|
||||
verify(groupMapper).updateById(captor.capture());
|
||||
assertThat(captor.getValue().getPlatform()).isEqualTo(AdminPlatformScope.JD);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateGroupWithExplicitPlatformReassignsIt() {
|
||||
ShopManageGroupEntity existing = groupRow(9L, "采集组");
|
||||
existing.setPlatform(AdminPlatformScope.AMAZON);
|
||||
when(groupMapper.selectById(9L)).thenReturn(existing);
|
||||
AdminUserEntity leader = operator(2L, "admin", 5L);
|
||||
when(groupAdminUserMapper.selectById(2L)).thenReturn(leader);
|
||||
// 同上:validateManageAccess(超管档)按操作者再查一次公司
|
||||
when(groupAdminUserMapper.selectById(1L)).thenReturn(operator(1L, "super_admin", 5L));
|
||||
when(groupMapper.updateById(any(ShopManageGroupEntity.class))).thenReturn(1);
|
||||
when(groupAdminUserMapper.selectBatchIds(any())).thenReturn(List.of());
|
||||
|
||||
ShopManageGroupUpdateRequest request = new ShopManageGroupUpdateRequest();
|
||||
request.setGroupName("采集组");
|
||||
request.setPlatform("jd");
|
||||
|
||||
groupService.update(9L, 1L, true, request);
|
||||
|
||||
ArgumentCaptor<ShopManageGroupEntity> captor = ArgumentCaptor.forClass(ShopManageGroupEntity.class);
|
||||
verify(groupMapper).updateById(captor.capture());
|
||||
assertThat(captor.getValue().getPlatform()).isEqualTo(AdminPlatformScope.JD);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 取值出口自身
|
||||
|
||||
@Test
|
||||
void normalizeOrCreateTrimsAndDefaultsBlankToAmazon() {
|
||||
assertThat(AdminPlatformScope.normalizeOrCreate(null)).isEqualTo(AdminPlatformScope.AMAZON);
|
||||
assertThat(AdminPlatformScope.normalizeOrCreate(" ")).isEqualTo(AdminPlatformScope.AMAZON);
|
||||
assertThat(AdminPlatformScope.normalizeOrCreate(" jd ")).isEqualTo(AdminPlatformScope.JD);
|
||||
assertThatThrownBy(() -> AdminPlatformScope.normalizeOrCreate(" taobao "))
|
||||
.isInstanceOf(BusinessException.class)
|
||||
.hasMessageContaining("所属平台");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- 夹具
|
||||
|
||||
private final AtomicReference<AdminUserEntity> userInsertCaptor = new AtomicReference<>();
|
||||
private final AtomicReference<CompanyEntity> companyInsertCaptor = new AtomicReference<>();
|
||||
private final AtomicReference<ShopManageGroupEntity> groupInsertCaptor = new AtomicReference<>();
|
||||
|
||||
private AtomicReference<AdminUserEntity> captureUserInsert() {
|
||||
when(userMapper.insert(any(AdminUserEntity.class))).thenAnswer(inv -> {
|
||||
AdminUserEntity entity = inv.getArgument(0);
|
||||
entity.setId(99L);
|
||||
userInsertCaptor.set(entity);
|
||||
return 1;
|
||||
});
|
||||
return userInsertCaptor;
|
||||
}
|
||||
|
||||
private AtomicReference<CompanyEntity> captureCompanyInsert() {
|
||||
when(companyMapper.insert(any(CompanyEntity.class))).thenAnswer(inv -> {
|
||||
CompanyEntity entity = inv.getArgument(0);
|
||||
entity.setId(99L);
|
||||
companyInsertCaptor.set(entity);
|
||||
return 1;
|
||||
});
|
||||
return companyInsertCaptor;
|
||||
}
|
||||
|
||||
private void stubGroupInsertCapturing() {
|
||||
when(groupMapper.insert(any(ShopManageGroupEntity.class))).thenAnswer(inv -> {
|
||||
ShopManageGroupEntity entity = inv.getArgument(0);
|
||||
entity.setId(9L);
|
||||
groupInsertCaptor.set(entity);
|
||||
return 1;
|
||||
});
|
||||
// create() 末尾 toVo(getById(id)) 会按新 id 回读同一行
|
||||
when(groupMapper.selectById(any())).thenAnswer(inv -> groupInsertCaptor.get());
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private LambdaQueryWrapper<AdminUserEntity> capturedUserCountQuery() {
|
||||
ArgumentCaptor<LambdaQueryWrapper> captor = ArgumentCaptor.forClass((Class) LambdaQueryWrapper.class);
|
||||
verify(userMapper).selectCount(captor.capture());
|
||||
return captor.getValue();
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private LambdaUpdateWrapper<AdminUserEntity> capturedUserUpdate() {
|
||||
ArgumentCaptor<LambdaUpdateWrapper> captor = ArgumentCaptor.forClass((Class) LambdaUpdateWrapper.class);
|
||||
verify(userMapper).update(any(), captor.capture());
|
||||
return captor.getValue();
|
||||
}
|
||||
|
||||
private AdminUserEntity operator(Long id, String role, Long companyId) {
|
||||
AdminUserEntity entity = new AdminUserEntity();
|
||||
entity.setId(id);
|
||||
entity.setUsername("op" + id);
|
||||
entity.setRole(role);
|
||||
entity.setIsAdmin("normal".equals(role) ? 0 : 1);
|
||||
entity.setCompanyId(companyId);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private AdminUserEntity target(Long id, String role) {
|
||||
AdminUserEntity entity = new AdminUserEntity();
|
||||
entity.setId(id);
|
||||
entity.setUsername("u" + id);
|
||||
entity.setRole(role);
|
||||
entity.setIsAdmin("normal".equals(role) ? 0 : 1);
|
||||
entity.setCompanyId(5L);
|
||||
entity.setCreatedById(1L);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private CompanyEntity companyRow(Long id, String name) {
|
||||
CompanyEntity entity = new CompanyEntity();
|
||||
entity.setId(id);
|
||||
entity.setCompanyName(name);
|
||||
entity.setStatus(CompanyService.STATUS_ACTIVE);
|
||||
return entity;
|
||||
}
|
||||
|
||||
private ShopManageGroupEntity groupRow(Long id, String name) {
|
||||
ShopManageGroupEntity entity = new ShopManageGroupEntity();
|
||||
entity.setId(id);
|
||||
entity.setGroupName(name);
|
||||
entity.setCreatedById(2L);
|
||||
entity.setCompanyId(5L);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
+19
@@ -60,6 +60,25 @@ class AdminUserServiceCompanySuperAdminTest {
|
||||
when(permissionService.hasAnyAdminMenu(any(), any())).thenReturn(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
void 京东额度允许零并拒绝负数和普通账号() {
|
||||
AdminUserEntity operator = user(1L, "super_admin", 1L, null);
|
||||
AdminUserEntity target = user(10L, "admin", 1L, 1L);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
when(userMapper.selectById(10L)).thenReturn(target);
|
||||
AdminUserUpdateRequest request = new AdminUserUpdateRequest();
|
||||
request.setJdPublishQuota(0);
|
||||
service.updateUser(operator, 10L, request);
|
||||
verify(userMapper).update(any(), any());
|
||||
request.setJdPublishQuota(-1);
|
||||
assertThatThrownBy(() -> service.updateUser(operator, 10L, request))
|
||||
.isInstanceOf(BusinessException.class).hasMessageContaining("不能为负数");
|
||||
request.setJdPublishQuota(1);
|
||||
target.setRole("normal");
|
||||
assertThatThrownBy(() -> service.updateUser(operator, 10L, request))
|
||||
.isInstanceOf(BusinessException.class).hasMessageContaining("只能为管理员");
|
||||
}
|
||||
|
||||
// ---------- 建号 ----------
|
||||
|
||||
@Test
|
||||
|
||||
+4
-4
@@ -57,7 +57,7 @@ class CompanyControllerEndpointTest {
|
||||
body.setRemark("二期");
|
||||
|
||||
when(adminAuthSupport.requireAdminOrInternal(request)).thenReturn(operator);
|
||||
when(companyService.listVisible(operator)).thenReturn(List.of(company(1L, "厦门米椿花")));
|
||||
when(companyService.listVisible(operator, null)).thenReturn(List.of(company(1L, "厦门米椿花")));
|
||||
when(companyService.create(any(), any())).thenReturn(company(2L, "福州数富"));
|
||||
when(companyService.update(any(), any(), any())).thenReturn(company(2L, "福州数富科技"));
|
||||
}
|
||||
@@ -73,13 +73,13 @@ class CompanyControllerEndpointTest {
|
||||
@Test
|
||||
@DisplayName("每个端点先鉴权再进 service,顺序不能反")
|
||||
void everyEndpointAuthenticatesBeforeTouchingTheDirectory() {
|
||||
controller.listCompanies(request);
|
||||
controller.listCompanies(request, null);
|
||||
controller.createCompany(request, body);
|
||||
controller.updateCompany(request, 2L, body);
|
||||
|
||||
InOrder order = inOrder(adminAuthSupport, companyService);
|
||||
order.verify(adminAuthSupport).requireAdminOrInternal(request);
|
||||
order.verify(companyService).listVisible(operator);
|
||||
order.verify(companyService).listVisible(operator, null);
|
||||
order.verify(adminAuthSupport).requireAdminOrInternal(request);
|
||||
order.verify(companyService).create(operator, body);
|
||||
order.verify(adminAuthSupport).requireAdminOrInternal(request);
|
||||
@@ -108,7 +108,7 @@ class CompanyControllerEndpointTest {
|
||||
@Test
|
||||
@DisplayName("列表回包是 CompanyVo 而不是实体:实体字段是 camelCase,前端解析不到公司名")
|
||||
void listReturnsVoItemsNotEntities() {
|
||||
ApiResponse<List<CompanyVo>> response = controller.listCompanies(request);
|
||||
ApiResponse<List<CompanyVo>> response = controller.listCompanies(request, null);
|
||||
|
||||
assertThat(response.getData()).hasSize(1);
|
||||
assertThat(response.getData().get(0).getCompanyName()).isEqualTo("厦门米椿花");
|
||||
|
||||
+19
-4
@@ -88,10 +88,12 @@ class JdPublishQuotaServiceTest {
|
||||
@Test
|
||||
void 上限为0_整体放行且不查库() {
|
||||
JdPublishQuotaService service = newService();
|
||||
service.maxProductsPerAdmin = 0L;
|
||||
|
||||
assertThatCode(() -> service.assertWithinQuota(admin(5L), 999_999)).doesNotThrowAnyException();
|
||||
verifyNoInteractions(jdProductMapper, userDataScopeSupport, adminUserMapper);
|
||||
AdminUserEntity operator = admin(5L);
|
||||
operator.setJdPublishQuota(0);
|
||||
when(userDataScopeSupport.resolveVisibleUserIds(argThat((AdminUserEntity u) -> u != null && u.getId() == 5L)))
|
||||
.thenReturn(List.of());
|
||||
assertThatCode(() -> service.assertWithinQuota(operator, 999_999)).doesNotThrowAnyException();
|
||||
verifyNoInteractions(jdProductMapper, adminUserMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,6 +137,19 @@ class JdPublishQuotaServiceTest {
|
||||
assertThat(snapshot.unlimited()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void 员工使用所属管理员的独立额度() {
|
||||
JdPublishQuotaService service = newService();
|
||||
AdminUserEntity manager = admin(5L);
|
||||
manager.setJdPublishQuota(12);
|
||||
when(adminUserMapper.selectById(5L)).thenReturn(manager);
|
||||
when(userDataScopeSupport.resolveVisibleUserIds(argThat((AdminUserEntity u) -> u != null && u.getId() == 5L)))
|
||||
.thenReturn(List.of(5L, 9L));
|
||||
when(jdProductMapper.countByUserIds(List.of(5L, 9L))).thenReturn(12L);
|
||||
assertThatThrownBy(() -> service.assertWithinQuota(employee(9L, 5L), 1))
|
||||
.isInstanceOf(BusinessException.class).hasMessageContaining("12");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 普通账号读不到主管_回退按自己计() {
|
||||
JdPublishQuotaService service = newService();
|
||||
|
||||
Reference in New Issue
Block a user