feat(appearance-patent): 顶部全量「导出」摘掉+每张主管卡加「删除」(2026-11-11 客户「这个可以不要 有下载就行了」「也要加个删除按钮」)
删除走新 DELETE /api/admin/appearance-patent-clean-items/supervisors?supervisor_user_id=…:谓词与卡片「下载」逐字同源(共享 cleanItemConds + supervisorScopeConds,Same SQL 下推),所见即所删;supervisor_user_id 必填、服务侧先挡空值(缺值会让 <if> 不生效=退化成整表删除),日期倒挂同全站口径拒;同一 requireCleanItemsAccess+readCompanyIdOrOwn 正门(非超管只能删本公司行),并打一条带 operatorId/主管/过滤面/删除行数的日志留痕;只删快照明细,不碰结果文件与任务记录。前端破坏性动作先 openAdminConfirm(点名主管与条数、danger),删完回读并在删掉本页最后一张卡时回退页;读不到主管的卡两钮都禁用。护栏:XML_STATEMENT_TOTAL 155→156、NOT_MIGRATED 登记 deleteSupervisorItems、controller 只读判据改为「无 POST/PUT+DELETE 必须在位」、wiring 新增第 4 个发送口(26 处/19 组)。
This commit is contained in:
@@ -5,14 +5,17 @@ import { formatDateTime, orderedPair } from '@/utils/datetime'
|
||||
* 我们这边就是按主管划分」)。
|
||||
*
|
||||
* 形态:一主管一卡(对齐「店铺数据记录」页的一店一卡),卡内是该主管名下的汇总——
|
||||
* 条数 / 任务(几个任务、最近任务号)/ 国家 / 最新同步时间 + [下载](导出该主管名下全量 xlsx)。
|
||||
* 条数 / 任务(几个任务、最近任务号)/ 国家 / 最新同步时间 + [下载](导出该主管名下全量 xlsx)
|
||||
* + [删除](删该主管名下明细,2026-11-11 客户「也要加个删除按钮」)。
|
||||
* 明细分页卡片(每明细一卡)已下架:3488 条明细会铺成几千张卡,客户明确不要。
|
||||
* 数据来自 GET /supervisors(后端按「主管本人取自己、普通账户取创建人」的归属表达式聚合,
|
||||
* total 是主管数),与明细导出走同一过滤面(分组/国家/同步起止 + 公司 tab)。
|
||||
* 页签零写操作:明细本身仍走 /export xlsx 看(客户「到时候能下载表格看就行」)。
|
||||
* 页签零出表:明细本身仍走 xlsx 看(客户「到时候能下载表格看就行」);
|
||||
* 顶部不再给「全量导出」——每张卡自带下载与删除,客户口径「这个可以不要 有下载就行了」。
|
||||
* 分组(主管)下拉选中即查(同日四改):客户选了主管就该只看到这一位/这一组的主管卡片。 */
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import {
|
||||
deleteAppearancePatentCleanSupervisor,
|
||||
exportAppearancePatentCleanList,
|
||||
fetchAppearancePatentCleanSupervisors,
|
||||
fetchDedupeTotalGroups,
|
||||
@@ -24,6 +27,7 @@ import { ASIN_COUNTRY_CODES, asinCountryLabel } from '../asin/asin-country.ts'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||||
import { showAdminFeedback } from '@/components/admin-feedback-ui'
|
||||
import { openAdminConfirm } from '@/components/admin-confirm'
|
||||
import { loadFailureMessage } from '@/components/load-failure-model'
|
||||
import LoadFailureBar from '@/components/LoadFailureBar.vue'
|
||||
|
||||
@@ -36,10 +40,10 @@ const cards = ref<AppearancePatentSupervisorCard[]>([])
|
||||
const total = ref(0)
|
||||
const page = ref(1)
|
||||
const pageSize = ref(10)
|
||||
/** 导出在途锁:避免连点导出把同一份过滤面重复请求两遍。 */
|
||||
const exporting = ref(false)
|
||||
/** 单卡下载在途标记(存 supervisorId,避免连点同一张卡)。 */
|
||||
const downloadingId = ref<number | null>(null)
|
||||
/** 单卡删除在途标记(存 supervisorId;删除是破坏性动作,确认后才置位)。 */
|
||||
const deletingId = ref<number | null>(null)
|
||||
/** 同步台账是累计数据,日期初值故意留空(默认当天会让首屏只剩今天同步的行);见 date-filter-default-today 护栏的 EXEMPT。 */
|
||||
const filter = reactive(createAppearancePatentCleanFilterState())
|
||||
/** 分组(主管)下拉选项:公司 tab 切换时重取;选项失败不拦列表,只回空下拉(可见「全部分组」)。 */
|
||||
@@ -87,30 +91,6 @@ async function load(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** 顶部导出:当前过滤面(含公司 tab 与分组)全量出 xlsx。 */
|
||||
async function exportAll(): Promise<void> {
|
||||
if (exporting.value) return
|
||||
exporting.value = true
|
||||
try {
|
||||
const result = await exportAppearancePatentCleanList({
|
||||
taskId: filter.taskId,
|
||||
asin: filter.asin,
|
||||
country: filter.country,
|
||||
groupId: filter.groupId,
|
||||
startDate: filter.startDate,
|
||||
endDate: filter.endDate,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
saveBlob(result.blob, result.filename)
|
||||
showAdminFeedback(`已导出 ${result.filename}`, 'success')
|
||||
} catch (error) {
|
||||
const message = error instanceof Error && error.message ? error.message : '导出失败,请稍后重试'
|
||||
showAdminFeedback(message, 'error')
|
||||
} finally {
|
||||
exporting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 单卡下载:只导出该主管名下明细(与卡片同一归属口径,supervisor_user_id 收窄)。
|
||||
* 读不到主管的那组没有 id,不给按钮(不猜是哪位主管)。 */
|
||||
async function downloadSupervisor(card: AppearancePatentSupervisorCard): Promise<void> {
|
||||
@@ -137,6 +117,38 @@ async function downloadSupervisor(card: AppearancePatentSupervisorCard): Promise
|
||||
}
|
||||
}
|
||||
|
||||
/** 单卡删除:删该主管名下明细(谓词与「下载」同一过滤面+同一归属表达式)。
|
||||
* 破坏性动作:先弹确认(点名主管与条数、写明不可恢复),确认后真删,再按剩余卡片回退页码——
|
||||
* 删掉本页最后一张卡时不能停在空页上。读不到主管的那组没有 id,不给按钮。 */
|
||||
async function removeSupervisor(card: AppearancePatentSupervisorCard): Promise<void> {
|
||||
if (card.supervisorId == null || deletingId.value !== null) return
|
||||
const label = card.supervisorName || '该主管'
|
||||
const confirmed = await openAdminConfirm({
|
||||
message: `确认删除「${label}」名下的 ${card.itemCount} 条外观专利数据库记录?此操作不可恢复(任务记录与结果文件不受影响)。`,
|
||||
danger: true,
|
||||
})
|
||||
if (!confirmed) return
|
||||
deletingId.value = card.supervisorId
|
||||
try {
|
||||
const deleted = await deleteAppearancePatentCleanSupervisor({
|
||||
supervisorUserId: card.supervisorId,
|
||||
country: filter.country,
|
||||
groupId: filter.groupId,
|
||||
startDate: filter.startDate,
|
||||
endDate: filter.endDate,
|
||||
companyId: companyTab.requestCompanyId,
|
||||
})
|
||||
showAdminFeedback(`已删除「${label}」的 ${deleted} 条记录`, 'success')
|
||||
if (cards.value.length === 1 && page.value > 1) page.value -= 1
|
||||
await load()
|
||||
} catch (error) {
|
||||
const message = error instanceof Error && error.message ? error.message : `删除「${label}」的记录失败`
|
||||
showAdminFeedback(message, 'error')
|
||||
} finally {
|
||||
deletingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
function saveBlob(blob: Blob, filename: string): void {
|
||||
const url = URL.createObjectURL(blob)
|
||||
const anchor = document.createElement('a')
|
||||
@@ -220,11 +232,6 @@ onMounted(() => {
|
||||
<section class="panel-box">
|
||||
<LoadFailureBar v-if="loadFailure" :message="loadFailure" @retry="load" />
|
||||
<div class="clean-toolbar">
|
||||
<div class="clean-toolbar-main">
|
||||
<button class="btn" type="button" :disabled="exporting" @click="exportAll">
|
||||
{{ exporting ? '导出中...' : '导出' }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="clean-toolbar-side">
|
||||
<span class="clean-summary">共 {{ total }} 位主管 · 本页 {{ cards.length }} 位</span>
|
||||
</div>
|
||||
@@ -261,12 +268,21 @@ onMounted(() => {
|
||||
<button
|
||||
class="btn btn-sm"
|
||||
type="button"
|
||||
:disabled="card.supervisorId == null || downloadingId !== null"
|
||||
:title="card.supervisorId == null ? '读不到主管账号,无法按主管导出(可用顶部导出)' : undefined"
|
||||
:disabled="card.supervisorId == null || downloadingId !== null || deletingId !== null"
|
||||
:title="card.supervisorId == null ? '读不到主管账号,无法按主管导出' : undefined"
|
||||
@click="downloadSupervisor(card)"
|
||||
>
|
||||
{{ downloadingId === card.supervisorId && card.supervisorId != null ? '下载中...' : '下载' }}
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-sm btn-danger"
|
||||
type="button"
|
||||
:disabled="card.supervisorId == null || deletingId !== null || downloadingId !== null"
|
||||
:title="card.supervisorId == null ? '读不到主管账号,无法按主管删除' : undefined"
|
||||
@click="removeSupervisor(card)"
|
||||
>
|
||||
{{ deletingId === card.supervisorId && card.supervisorId != null ? '删除中...' : '删除' }}
|
||||
</button>
|
||||
</div>
|
||||
</article>
|
||||
</template>
|
||||
@@ -405,18 +421,14 @@ h3 {
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
.clean-toolbar-main {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
/* 工具条只剩右侧汇总(顶部「导出」已按客户口径摘掉),用 margin-left:auto 顶到右边保持原位。 */
|
||||
.clean-toolbar-side {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
margin-left: auto;
|
||||
}
|
||||
.clean-summary {
|
||||
color: #5b6f83;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* 只读页+导出(2026-11-11 客户需求「数据得导出来」):公司 tab 的值由本发送口从原始入参自己下传
|
||||
* (白名单构造不认识 company_id),取值口形状由 company-tab-wiring 护栏钉住。 */
|
||||
import { http } from '@/api/http'
|
||||
import { errorTextOf } from '../../api/envelope.ts'
|
||||
import { errorTextOf, unwrap } from '../../api/envelope.ts'
|
||||
import {
|
||||
toAppearancePatentCleanExportParams,
|
||||
toAppearancePatentCleanListParams,
|
||||
@@ -131,6 +131,37 @@ export async function exportAppearancePatentCleanList(
|
||||
return { blob: response.data, filename: exportFilenameOf(disposition) }
|
||||
}
|
||||
|
||||
export interface AppearancePatentSupervisorDeleteParams {
|
||||
supervisorUserId: number
|
||||
country?: string
|
||||
groupId?: string
|
||||
startDate?: string
|
||||
endDate?: string
|
||||
companyId?: number | null
|
||||
}
|
||||
|
||||
/** 删除某位主管名下明细(卡片上的「删除」,2026-11-11 客户「也要加个删除按钮」):
|
||||
* 谓词与卡片「下载」逐字同源(同一过滤面 + 同一主管归属表达式),返回实际删除行数。
|
||||
* supervisorUserId 必填——后端缺值按业务错误拒绝(不按主管收窄的删除等于删整个过滤面)。 */
|
||||
export async function deleteAppearancePatentCleanSupervisor(
|
||||
params: AppearancePatentSupervisorDeleteParams,
|
||||
): Promise<number> {
|
||||
const query = toAppearancePatentCleanExportParams({
|
||||
taskId: '',
|
||||
asin: '',
|
||||
country: params.country ?? '',
|
||||
groupId: params.groupId ?? '',
|
||||
startDate: params.startDate ?? '',
|
||||
endDate: params.endDate ?? '',
|
||||
})
|
||||
if (params.companyId != null) query.company_id = params.companyId
|
||||
const { data } = await http.delete<unknown>(APPEARANCE_PATENT_SUPERVISOR_ENDPOINT, {
|
||||
params: { ...query, supervisor_user_id: params.supervisorUserId },
|
||||
})
|
||||
const deleted = unwrap<number>(data)
|
||||
return typeof deleted === 'number' ? deleted : Number(deleted) || 0
|
||||
}
|
||||
|
||||
/** 分组(主管)下拉选项:复用既有 GET /shop-manages/groups(与去重页/店铺管理共用同一分组集,
|
||||
* 不下新端点)。2026-11-11 客户口径「主管就是组长,可以筛选组长来导出,就是分组」——
|
||||
* 选项是分组管理里那一行(DedupeGroupOption {id, name, leaderUserId}),选中后以 group_id
|
||||
|
||||
@@ -125,13 +125,17 @@ const SEND_POINTS: ReadonlyArray<SendPoint> = [
|
||||
{ menuKey: 'admin_users', file: 'src/pages/account/user-menu-auth-api.ts', fn: 'fetchGrantableMenus', line: TASK_CENTER_SEND_LINE, window: 300, title: 'GET /permission-menus?grantableOnly 授权树:一家一套树后取错公司=已授权勾不上、提交必判无效' },
|
||||
// ↓ 批次 7(2026-11-10 v1.3 外观专利无侵权数据):出表成功自动同步的只读明细,归属物化在行
|
||||
// company_id 列(V189,同店铺密钥形状)⇒ 后端正门 readCompanyIdOrOwn;2026-11-11 客户需求
|
||||
// 「数据得导出来」补导出发送口(与列表共用同一过滤面与正门),这一页共两个发送口。
|
||||
// 「数据得导出来」补导出发送口(与列表共用同一过滤面与正门);同日再补主管聚合与按主管删除,
|
||||
// 这一页共四个发送口(四条都用同一行塞键 ⇒ (文件, 整行) 仍聚成同一组)。
|
||||
// 窗口 500:两处 own 实测 416/395(groupId 行加入后),同文件两条塞键行的间距 1585 ⇒
|
||||
// 500 够得着自己、够不到隔壁(对平用例逐处从真文件重算,注释过期即红)。
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'fetchAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items 无侵权只读列表' },
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'exportAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items/export 导出(2026-11-11 客户需求「数据得导出来」,与列表共用同一过滤面)' },
|
||||
// 2026-11-11 二次改版(一主管一卡):/supervisors 主管聚合卡片的取数口,与列表/导出同一过滤面与正门。
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'fetchAppearancePatentCleanSupervisors', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items/supervisors 主管聚合卡片(客户「我们这边就是按主管划分」)' },
|
||||
// 2026-11-11 三次改版(客户「也要加个删除按钮」):DELETE /supervisors 按主管收窄删除,
|
||||
// 与卡片下载同一过滤面与同一公司正门(非超管只能删本公司行)。
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'deleteAppearancePatentCleanSupervisor', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'DELETE /appearance-patent-clean-items/supervisors 按主管删除(客户「也要加个删除按钮」)' },
|
||||
]
|
||||
|
||||
/** 任务看板那 5 处(1b ④ 那条用例按文件筛它们,沿用旧名字不漂;表只有一份,不会漂出两个口径)。 */
|
||||
@@ -354,7 +358,7 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
|
||||
// 批次 2 原 12 条里的品牌库 1 条 + 商品类目 4 条随 2026-10-06「这两页退回全平台共享」摘掉)。
|
||||
// 这条只防"整表被摘空/被改窄",逐处脱管由下面两条(对平闸门 + 窗口对平)负责。
|
||||
assert.ok(SEND_POINTS.length >= 21,
|
||||
`发送口表只剩 ${SEND_POINTS.length} 条(批次 1+2+3+4+5+6 实扫 21 条 + 批次 7 v1.3 无侵权只读页与导出 2 条 = 25 条)⇒ 有人把钉从表里摘了,取值口看守成空`)
|
||||
`发送口表只剩 ${SEND_POINTS.length} 条(批次 1+2+3+4+5+6 实扫 21 条 + 批次 7 v1.3 无侵权列表/导出 2 条 + 主管聚合 1 条 + 按主管删除 1 条 = 26 条)⇒ 有人把钉从表里摘了,取值口看守成空`)
|
||||
for (const p of SEND_POINTS) {
|
||||
const shape = pointShape(p)
|
||||
const compliant = pointCompliant(p)
|
||||
@@ -387,7 +391,7 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
|
||||
else grouped.set(key, { file: p.file, line: p.line, pinned: 1 })
|
||||
}
|
||||
assert.equal(grouped.size, 19,
|
||||
`发送口表按 (文件, 整行) 应聚成 19 组(25 处发送口,批次 7 的列表与导出逐字同行走同一组),现在却有 ${grouped.size} 组 —— 表被改形状了,对平判据失去分母`)
|
||||
`发送口表按 (文件, 整行) 应聚成 19 组(26 处发送口,批次 7 的列表/导出/主管聚合/按主管删除逐字同行走同一组),现在却有 ${grouped.size} 组 —— 表被改形状了,对平判据失去分母`)
|
||||
for (const g of grouped.values()) {
|
||||
const actual = occurrences(stripComments(read(g.file)), g.line)
|
||||
assert.equal(g.pinned, actual,
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
* 外观专利无侵权数据页(v1.3 AC-5)的挂载契约。
|
||||
*
|
||||
* 形态(2026-11-11 客户三连拍板:「要按主管分组显示」→「应该是只显示一个卡片的才对」→
|
||||
* 「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」):<b>一主管一卡</b>,对齐
|
||||
* 「获取店铺那边是按店铺做成卡片 我们这边就是按主管划分」,随后两改:「这个可以不要 有下载就行了」
|
||||
* 摘掉顶部全量导出、「也要加个删除按钮」给每卡加删除):<b>一主管一卡</b>,对齐
|
||||
* 「店铺数据记录」页的一店一卡——卡头=主管名,卡内 条数 / 任务(几个任务·最近任务号)/
|
||||
* 国家 / 最新同步时间 + [下载](导出该主管名下 xlsx)。明细分页卡片(每明细一卡)已下架:
|
||||
* 3488 条明细铺成几千张卡是客户明确不要的形态;明细仍走 /export 表格看。
|
||||
* 数据来自 GET /supervisors(后端按归属表达式聚合,total 是主管数)。筛选面不变
|
||||
* (分组=主管/国家/同步起止,分组选中即查),取数/导出/公司 tab 契约照旧。
|
||||
* 国家 / 最新同步时间 + [下载](导出该主管名下 xlsx)+ [删除](删该主管名下明细,先确认)。
|
||||
* 明细分页卡片(每明细一卡)已下架:3488 条明细铺成几千张卡是客户明确不要的形态;
|
||||
* 明细仍走 xlsx 看。数据来自 GET /supervisors(后端按归属表达式聚合,total 是主管数)。
|
||||
* 筛选面不变(分组=主管/国家/同步起止,分组选中即查),取数/导出/删除/公司 tab 契约照旧。
|
||||
*
|
||||
* 跑法:`npx vitest run tests/mount/appearance-patent-clean-page.test.ts`
|
||||
*/
|
||||
@@ -29,11 +30,15 @@ const MENU_KEY = 'admin_appearance_patent_clean_items'
|
||||
const cleanApi = vi.hoisted(() => ({
|
||||
fetchAppearancePatentCleanSupervisors: vi.fn(),
|
||||
exportAppearancePatentCleanList: vi.fn(),
|
||||
deleteAppearancePatentCleanSupervisor: vi.fn(),
|
||||
fetchDedupeTotalGroups: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/pages/patent/appearance-patent-clean-api.ts', () => cleanApi)
|
||||
|
||||
const confirmMock = vi.hoisted(() => vi.fn())
|
||||
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmMock }))
|
||||
|
||||
function card(supervisorId: number | null, over: Record<string, unknown> = {}) {
|
||||
return {
|
||||
supervisorId,
|
||||
@@ -74,6 +79,9 @@ describe('外观专利数据库页(一主管一卡,2026-11-11 客户「我
|
||||
expect(src).toContain('clean-card-head', '卡片本体结构必须就位')
|
||||
expect(src).toContain('fetchAppearancePatentCleanSupervisors', '必须走主管聚合端点(一主管一卡)')
|
||||
expect(src).toContain('supervisorUserId', '单卡下载按主管收窄导出')
|
||||
expect(src).toContain('deleteAppearancePatentCleanSupervisor', '单卡删除按主管收窄')
|
||||
expect(src).toContain('openAdminConfirm', '破坏性删除必须先确认')
|
||||
expect(src).not.toContain('exportAll', '顶部全量导出已按客户口径摘掉(「这个可以不要 有下载就行了」)')
|
||||
expect(src).not.toContain('<table', '本页不是自绘行列表')
|
||||
expect(src).not.toContain('el-card')
|
||||
})
|
||||
@@ -123,13 +131,16 @@ describe('外观专利数据库页(一主管一卡,2026-11-11 客户「我
|
||||
expect(rowValue('最新')).not.toBe('')
|
||||
})
|
||||
|
||||
it('读不到主管的那一卡展示 -,且不给下载按钮(不猜是哪位主管)', async () => {
|
||||
it('读不到主管的那一卡展示 -,下载与删除都禁用(不猜是哪位主管)', async () => {
|
||||
const wrapper = await mountWith({ items: [card(null)], total: 1, page: 1, pageSize: 10 })
|
||||
const one = wrapper.find('.clean-card')
|
||||
expect(one.find('.clean-card-supervisor').text()).toBe('-', '读不到主管不猜名字')
|
||||
const downloadBtn = one.findAll('button').find((b) => b.text() === '下载')
|
||||
expect(downloadBtn).toBeTruthy()
|
||||
expect((downloadBtn!.element as HTMLButtonElement).disabled).toBe(true, '无主管 id 不可按主管导出')
|
||||
const deleteBtn = one.findAll('button').find((b) => b.text() === '删除')
|
||||
expect(deleteBtn).toBeTruthy()
|
||||
expect((deleteBtn!.element as HTMLButtonElement).disabled).toBe(true, '无主管 id 不可按主管删除')
|
||||
})
|
||||
|
||||
it('单卡下载=按该主管导出(带 supervisorUserId 与当前过滤面)', async () => {
|
||||
@@ -163,54 +174,78 @@ describe('外观专利数据库页(一主管一卡,2026-11-11 客户「我
|
||||
}
|
||||
})
|
||||
|
||||
it('顶部导出带当前过滤面与公司 tab,不带 supervisorUserId(全量)', async () => {
|
||||
const createObjectURL = vi.fn(() => 'blob:mock-url')
|
||||
const revokeObjectURL = vi.fn()
|
||||
const urlRecord = URL as unknown as Record<string, unknown>
|
||||
const origCreate = urlRecord.createObjectURL
|
||||
const origRevoke = urlRecord.revokeObjectURL
|
||||
Object.defineProperty(URL, 'createObjectURL', { value: createObjectURL, configurable: true, writable: true })
|
||||
Object.defineProperty(URL, 'revokeObjectURL', { value: revokeObjectURL, configurable: true, writable: true })
|
||||
const clickSpy = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => {})
|
||||
cleanApi.exportAppearancePatentCleanList.mockImplementation(() =>
|
||||
Promise.resolve({ blob: new Blob(['xlsx']), filename: '外观专利数据库-20261111120000.xlsx' }),
|
||||
)
|
||||
|
||||
try {
|
||||
const wrapper = await mountWith({ items: [card(9)], total: 1, page: 1, pageSize: 10 })
|
||||
await wrapper.findAll('button').find((b) => b.text() === '导出')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
const call = cleanApi.exportAppearancePatentCleanList.mock.calls[0][0]
|
||||
expect(call).toMatchObject({
|
||||
taskId: '',
|
||||
asin: '',
|
||||
country: '',
|
||||
groupId: '',
|
||||
startDate: '',
|
||||
endDate: '',
|
||||
companyId: 1,
|
||||
})
|
||||
expect(call.supervisorUserId).toBeUndefined()
|
||||
expect(createObjectURL).toHaveBeenCalledTimes(1)
|
||||
expect(revokeObjectURL).toHaveBeenCalledWith('blob:mock-url')
|
||||
} finally {
|
||||
Object.defineProperty(URL, 'createObjectURL', { value: origCreate, configurable: true })
|
||||
Object.defineProperty(URL, 'revokeObjectURL', { value: origRevoke, configurable: true })
|
||||
clickSpy.mockRestore()
|
||||
}
|
||||
it('工具栏不再有「导出」按钮(客户「这个可以不要 有下载就行了」),下载只在卡上', async () => {
|
||||
const wrapper = await mountWith({ items: [card(9)], total: 1, page: 1, pageSize: 10 })
|
||||
const labels = wrapper.findAll('button').map((b) => b.text())
|
||||
expect(labels).not.toContain('导出')
|
||||
expect(labels).toContain('下载')
|
||||
expect(wrapper.find('.clean-summary').text()).toContain('共 1 位主管')
|
||||
})
|
||||
|
||||
it('导出失败把服务端业务文案弹出来,不许静默', async () => {
|
||||
cleanApi.exportAppearancePatentCleanList.mockImplementation(() =>
|
||||
Promise.reject(new Error('该主管的无侵权数据共 90001 行,超过导出上限 50000 行,请缩小筛选范围后重试')))
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
await wrapper.findAll('button').find((b) => b.text() === '导出')!.trigger('click')
|
||||
const wrapper = await mountWith({ items: [card(9)], total: 1, page: 1, pageSize: 10 })
|
||||
await wrapper.find('.clean-card').findAll('button').find((b) => b.text() === '下载')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('超过导出上限')
|
||||
expect(wrapper.findAll('button').find((b) => b.text() === '导出')!.text()).toBe('导出')
|
||||
const downloadBtn = wrapper.find('.clean-card').findAll('button').find((b) => b.text() === '下载')
|
||||
expect(downloadBtn!.text()).toBe('下载', '失败后在途标记必须复位')
|
||||
})
|
||||
|
||||
it('删除:确认后按主管收窄真删,反馈删了多少条并重取列表', async () => {
|
||||
confirmMock.mockResolvedValue(true)
|
||||
cleanApi.deleteAppearancePatentCleanSupervisor.mockResolvedValue(120)
|
||||
const wrapper = await mountWith({ items: [card(9)], total: 1, page: 1, pageSize: 10 })
|
||||
|
||||
const btn = wrapper.find('.clean-card').findAll('button').find((b) => b.text() === '删除')
|
||||
expect(btn, '每张卡都要有删除').toBeTruthy()
|
||||
await btn!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(confirmMock).toHaveBeenCalledTimes(1)
|
||||
const confirmArgs = confirmMock.mock.calls[0][0] as { message: string; danger?: boolean }
|
||||
expect(confirmArgs.message).toContain('主管9', '确认文案点名是哪位主管')
|
||||
expect(confirmArgs.message).toContain('120', '确认文案给出将删条数')
|
||||
expect(confirmArgs.danger).toBe(true)
|
||||
|
||||
expect(cleanApi.deleteAppearancePatentCleanSupervisor).toHaveBeenCalledTimes(1)
|
||||
expect(cleanApi.deleteAppearancePatentCleanSupervisor.mock.calls[0][0]).toMatchObject({
|
||||
supervisorUserId: 9,
|
||||
companyId: 1,
|
||||
country: '',
|
||||
groupId: '',
|
||||
})
|
||||
expect(document.body.textContent).toContain('已删除', '成功反馈必须给出删除结果')
|
||||
expect(cleanApi.fetchAppearancePatentCleanSupervisors).toHaveBeenCalledTimes(2, '删完要重取')
|
||||
})
|
||||
|
||||
it('删除:确认弹窗被取消时一个字节都不发', async () => {
|
||||
confirmMock.mockResolvedValue(false)
|
||||
const wrapper = await mountWith({ items: [card(9)], total: 1, page: 1, pageSize: 10 })
|
||||
|
||||
await wrapper.find('.clean-card').findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(cleanApi.deleteAppearancePatentCleanSupervisor).not.toHaveBeenCalled()
|
||||
expect(cleanApi.fetchAppearancePatentCleanSupervisors).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('删除失败把服务端业务文案弹出来,不许静默', async () => {
|
||||
confirmMock.mockResolvedValue(true)
|
||||
cleanApi.deleteAppearancePatentCleanSupervisor.mockImplementation(() =>
|
||||
Promise.reject(new Error('缺少主管,无法按主管删除')))
|
||||
const wrapper = await mountWith({ items: [card(9)], total: 1, page: 1, pageSize: 10 })
|
||||
|
||||
await wrapper.find('.clean-card').findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(document.body.textContent).toContain('无法按主管删除')
|
||||
const btn = wrapper.find('.clean-card').findAll('button').find((b) => b.text() === '删除')
|
||||
expect(btn!.text()).toBe('删除', '失败后在途标记必须复位,不能永久禁用')
|
||||
})
|
||||
|
||||
it('翻页与改每页条数都重发请求,改条数回第一页', async () => {
|
||||
|
||||
+38
-4
@@ -20,10 +20,12 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -34,10 +36,11 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* 后管「外观专利无侵权数据」只读页(v1.3 R2/R3)。数据由出表成功点自动同步落表
|
||||
* ({@code AppearancePatentCleanSyncService}),本页只读——无写/删接口,下载走既有结果直链/
|
||||
* 任务中心;另有 GET 导出端点(2026-11-11 客户需求「数据得导出来」):与分页查询同一过滤面
|
||||
* (含公司隔离正门),服务侧卡导出上限,主管列为读侧现算列,无写/删/导入;分组筛选同日落地
|
||||
* 后管「外观专利无侵权数据」页(v1.3 R2/R3)。数据由出表成功点自动同步落表
|
||||
* ({@code AppearancePatentCleanSyncService}),本页不出表、不改明细内容——下载走导出端点、
|
||||
* 删除走 {@code DELETE /supervisors}(2026-11-11 客户「也要加个删除按钮」,按主管删快照明细行,
|
||||
* 不碰结果文件与任务记录);另有 GET 导出端点(2026-11-11 客户需求「数据得导出来」):与分页查询
|
||||
* 同一过滤面(含公司隔离正门),服务侧卡导出上限,主管列为读侧现算列,无导入;分组筛选同日落地
|
||||
* (客户口径「主管就是组长,可以筛选组长来导出,就是分组」)——group_id 参数(biz_shop_manage_group.id)
|
||||
* 在分页与导出同面生效,服务侧按 selectUserIdsByGroupId 解析「组长本人+名下子账户」整集后
|
||||
* SQL 侧下推;下拉选项复用既有 GET /shop-manages/groups(与去重页/店铺管理同源),不下新端点。
|
||||
@@ -48,6 +51,7 @@ import java.time.format.DateTimeFormatter;
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@RequestMapping("/api/admin/appearance-patent-clean-items")
|
||||
@Tag(name = "外观专利无侵权数据", description = "后管只读页:出表成功自动同步的「结论=无侵权」明细,按分公司隔离分页查询与导出。")
|
||||
public class AdminAppearancePatentCleanItemsController {
|
||||
@@ -157,6 +161,36 @@ public class AdminAppearancePatentCleanItemsController {
|
||||
.body(bytes);
|
||||
}
|
||||
|
||||
@DeleteMapping("/supervisors")
|
||||
@Operation(summary = "删除某位主管名下的外观专利数据库明细", description = "卡片上的「删除」(2026-11-11 客户"
|
||||
+ "「也要加个删除按钮」):谓词与卡片「下载」逐字同源(同一过滤面+同一主管归属表达式),"
|
||||
+ "supervisor_user_id 必填——缺值不按主管收窄就等于删整个过滤面,直接按业务错误拒绝。"
|
||||
+ "只删快照明细行,不动结果文件与任务记录。返回实际删除行数。")
|
||||
public ApiResponse<Integer> deleteBySupervisor(
|
||||
@Parameter(description = "主管用户 id(必填,卡片归属口径)")
|
||||
@RequestParam(name = "supervisor_user_id") Long supervisorUserId,
|
||||
@Parameter(description = "国家代码(如 DE、UK)") @RequestParam(name = "country", required = false) String country,
|
||||
@Parameter(description = "同步开始日期(包含)")
|
||||
@RequestParam(name = "start_date", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate startDate,
|
||||
@Parameter(description = "同步结束日期(包含)")
|
||||
@RequestParam(name = "end_date", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate endDate,
|
||||
@Parameter(description = "分组 id:按该分组「组长本人+名下子账户」的用户集过滤(主管=组长)")
|
||||
@RequestParam(name = "group_id", required = false) Long groupId,
|
||||
@Parameter(description = "公司 ID") @RequestParam(name = "company_id", required = false) Long companyId,
|
||||
HttpServletRequest request) {
|
||||
RequestOperator operator = requireCleanItemsAccess(request);
|
||||
AdminUserEntity user = operator.user();
|
||||
// 删除与查询/导出同一公司隔离正门:非超管只能删本公司的行(忽略请求传参)。
|
||||
Long scopedCompanyId = dataReadScope.readCompanyIdOrOwn(user, companyId);
|
||||
int deleted = cleanItemQueryService.deleteBySupervisor(supervisorUserId, country, startDate, endDate,
|
||||
groupId, scopedCompanyId);
|
||||
// 管理端真删必须留痕(谁、删了哪位主管、什么过滤面、删了多少行):日志是唯一的取证面。
|
||||
log.info("[appearance-patent-clean] 按主管删除明细 operatorId={} supervisorUserId={} country={} "
|
||||
+ "start={} end={} groupId={} companyId={} deleted={}",
|
||||
operator.id(), supervisorUserId, country, startDate, endDate, groupId, scopedCompanyId, deleted);
|
||||
return ApiResponse.success(deleted);
|
||||
}
|
||||
|
||||
private RequestOperator requireCleanItemsAccess(HttpServletRequest request) {
|
||||
AdminUserEntity operator = resolveOperator(request);
|
||||
if (operator == null || operator.getId() == null || operator.getId() <= 0) {
|
||||
|
||||
+16
@@ -111,4 +111,20 @@ public interface AppearancePatentCleanItemMapper extends BaseMapper<CleanItemEnt
|
||||
@Param("supervisorUserId") Long supervisorUserId,
|
||||
@Param("offset") long offset,
|
||||
@Param("limit") int limit);
|
||||
|
||||
/**
|
||||
* 删除单个主管名下明细(2026-11-11 卡片上的「删除」)。
|
||||
*
|
||||
* <p>谓词与 {@link #selectSupervisorItems} 逐字同源(共享 {@code cleanItemConds} +
|
||||
* {@code supervisorScopeConds}):所见即所删。{@code supervisorUserId} 为 null 时那条
|
||||
* {@code <if>} 不生效=退化成整表删除,所以调用方(Service)必须先挡空值。</p>
|
||||
*/
|
||||
int deleteSupervisorItems(@Param("companyId") Long companyId,
|
||||
@Param("taskId") Long taskId,
|
||||
@Param("asin") String asin,
|
||||
@Param("country") String country,
|
||||
@Param("startDate") LocalDate startDate,
|
||||
@Param("endDate") LocalDate endDate,
|
||||
@Param("userIds") List<Long> userIds,
|
||||
@Param("supervisorUserId") Long supervisorUserId);
|
||||
}
|
||||
|
||||
+31
@@ -301,6 +301,37 @@ public class AppearancePatentCleanItemQueryService {
|
||||
return writeExportWorkbook(items);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除<b>单个主管</b>名下明细(2026-11-11 客户「也要加个删除按钮」):谓词与
|
||||
* {@link #exportBySupervisor} 逐字同源(同一过滤面 + 同一归属表达式),所以「看到的条数」
|
||||
* 与「删掉的条数」不会分叉。
|
||||
*
|
||||
* <p>{@code supervisorUserId} 必须是显式传入的主管 id:SQL 里那条 {@code <if>} 缺值时不生效,
|
||||
* 等于删掉整个过滤面(最坏是全表),所以这里先挡空值/非法值并抛业务错误——宁可拒绝,不接
|
||||
* 「不按主管收窄的删除」。本方法只删快照明细行,不碰结果文件与任务记录(与同步链的
|
||||
* {@code deleteByResultId} 覆盖式重写互不影响:下一次同步会按 result_id 重新写入)。</p>
|
||||
*
|
||||
* @return 实际删除行数(前端拿它做「已删除 N 条」的反馈,不猜)
|
||||
*/
|
||||
public int deleteBySupervisor(Long supervisorUserId, String country, LocalDate startDate,
|
||||
LocalDate endDate, Long groupId, Long scopedCompanyId) {
|
||||
if (supervisorUserId == null || supervisorUserId <= 0) {
|
||||
throw new BusinessException("缺少主管,无法按主管删除");
|
||||
}
|
||||
if (startDate != null && endDate != null && startDate.isAfter(endDate)) {
|
||||
throw new BusinessException("开始日期不能晚于结束日期");
|
||||
}
|
||||
Long companyId = scopedCompanyId != null && scopedCompanyId > 0 ? scopedCompanyId : null;
|
||||
String safeCountry = trimToNull(country);
|
||||
List<Long> groupUserIds = groupUserIds(groupId);
|
||||
if (groupUserIds != null && groupUserIds.isEmpty()) {
|
||||
// 与导出同口径:分组解析不出用户集 ⇒ 过滤面本身是空的,没有可删的行。
|
||||
return 0;
|
||||
}
|
||||
return cleanItemMapper.deleteSupervisorItems(companyId, null, null, safeCountry, startDate, endDate,
|
||||
groupUserIds, supervisorUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分组筛选 → 该分组「组长本人+名下子账户」的用户 id 集({@code null} = 没选分组、不过滤);
|
||||
* id 非法(≤0)按没选处理,不把它当全量之外的第三档。解析交给
|
||||
|
||||
+11
@@ -112,6 +112,17 @@
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
|
||||
<!-- 卡片「删除」=删掉该主管名下明细(2026-11-11 客户「也要加个删除按钮」)。谓词与「下载」
|
||||
同源:共享 cleanItemConds + supervisorScopeConds,一条语句定完,不接受「先查 id 再逐批删」
|
||||
——两段之间新同步进来的行会漏网。supervisor 条件缺失时 <if> 不生效,所以服务侧必须先
|
||||
校验 supervisorUserId 非空(Service 里已挡),这里不承担兜底。 -->
|
||||
<delete id="deleteSupervisorItems">
|
||||
DELETE i
|
||||
FROM biz_appearance_patent_clean_item i
|
||||
LEFT JOIN users u ON u.id = i.user_id
|
||||
WHERE 1=1 <include refid="cleanItemConds"/> <include refid="supervisorScopeConds"/>
|
||||
</delete>
|
||||
|
||||
<!-- 卡片「下载」=导出该主管名下全量明细(分页/导出同一过滤面 + 主管归属条件)。 -->
|
||||
<select id="countSupervisorItems" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
|
||||
@@ -174,7 +174,11 @@ class MigratedSqlEquivalenceTest {
|
||||
"AppearancePatentCleanItemMapper#countSupervisors",
|
||||
"AppearancePatentCleanItemMapper#selectSupervisorSummaries",
|
||||
"AppearancePatentCleanItemMapper#countSupervisorItems",
|
||||
"AppearancePatentCleanItemMapper#selectSupervisorItems");
|
||||
"AppearancePatentCleanItemMapper#selectSupervisorItems",
|
||||
// 2026-11-11 卡片「删除」:1 条新写的 delete(谓词与按主管导出的 select
|
||||
// 逐字同源)。delete 不计 select,故 XML_SELECT_TOTAL 保持 109
|
||||
// (SqlLayeringConventionTest.XML_STATEMENT_TOTAL 同轮 155 → 156)。
|
||||
"AppearancePatentCleanItemMapper#deleteSupervisorItems");
|
||||
|
||||
/** 账本 5 列:接口 / 方法 / @Select 种类 / 是否含常量插值 / 注解原文(Java 反转义后那条串)。 */
|
||||
private static final int LEDGER_COLUMNS = 5;
|
||||
|
||||
@@ -104,7 +104,9 @@ class SqlLayeringConventionTest {
|
||||
// 151 → 155:2026-11-11「按主管划分」同一 mapper 再落 4 条 select——主管聚合 count/page
|
||||
// +按主管导出 count/page(users 联表按归属表达式收窄),同轮登记进 NOT_MIGRATED
|
||||
//(该文件 XML_SELECT_TOTAL 105 → 109)。
|
||||
private static final int XML_STATEMENT_TOTAL = 155;
|
||||
// 155 → 156:2026-11-11 卡片「删除」落 1 条 delete(deleteSupervisorItems,谓词与按主管导出
|
||||
// 逐字同源)——delete 不计入该文件 XML_SELECT_TOTAL,只点名进 NOT_MIGRATED。
|
||||
private static final int XML_STATEMENT_TOTAL = 156;
|
||||
|
||||
/**
|
||||
* wrapper 里夹带函数级 SQL 的现状("这不是简单单表"的证据),文件名 → 条数:
|
||||
|
||||
+106
-6
@@ -55,6 +55,7 @@ import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
@@ -98,9 +99,13 @@ class AdminAppearancePatentCleanItemsControllerTest {
|
||||
assertTrue(source.contains("/api/admin/appearance-patent-clean-items"),
|
||||
"端点必须是 GET /api/admin/appearance-patent-clean-items(蓝图 §3.2)");
|
||||
assertTrue(source.contains("@GetMapping"), "查询端点必须落在 @GetMapping");
|
||||
assertFalse(source.contains("@PostMapping") || source.contains("@PutMapping")
|
||||
|| source.contains("@DeleteMapping"),
|
||||
"本页只读、无写/删接口(蓝图 §3.2;后管要下载走既有结果直链/任务中心)");
|
||||
// 2026-11-11 客户「也要加个删除按钮」:本页从纯只读变为「读+按主管删」——
|
||||
// 允许且只允许 DELETE /supervisors(按主管收窄,见 按主管删除端点就位 一格),
|
||||
// 仍然禁 POST/PUT(不出表、不改明细内容、无导入)。
|
||||
assertFalse(source.contains("@PostMapping") || source.contains("@PutMapping"),
|
||||
"本页不出表、不改明细、无导入:不得有 POST/PUT(蓝图 §3.2)");
|
||||
assertTrue(source.contains("@DeleteMapping"),
|
||||
"删除按钮必须落在 @DeleteMapping(客户「也要加个删除按钮」,2026-11-11)");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -373,9 +378,10 @@ class AdminAppearancePatentCleanItemsControllerTest {
|
||||
String source = stripComments(Files.readString(CONTROLLER));
|
||||
assertTrue(source.contains("\"/export\""),
|
||||
"导出必须是 GET /api/admin/appearance-patent-clean-items/export(2026-11-11 客户需求「数据得导出来」)");
|
||||
// 导出仍是只读:本页禁写/删/导入的判据由「控制器与只读端点就位」一格把守(无 Post/Put/Delete),
|
||||
// 导出落 GET 不破那格;导出与分页都必须各自调用 requireCleanItemsAccess+readCompanyIdOrOwn
|
||||
//(私有两支各调一次,缺一支即红——导出不许绕过页签的鉴权与公司隔离)。
|
||||
// 导出不写库:本页的写面只有 2026-11-11 客户要的那一个按主管删除(DELETE /supervisors),
|
||||
// 出表/POST/PUT 仍由「控制器与只读端点就位」一格把守(无 Post/Put);
|
||||
// 导出与分页都必须各自调用 requireCleanItemsAccess+readCompanyIdOrOwn
|
||||
//(私有多支各调一次,缺一支即红——导出不许绕过页签的鉴权与公司隔离)。
|
||||
long gateCalls = source.split("requireCleanItemsAccess\\(request\\)", -1).length - 1;
|
||||
assertTrue(gateCalls >= 2, "分页与导出两支 handler 都必须过 requireCleanItemsAccess 正门,实得 " + gateCalls);
|
||||
long scopeCalls = source.split("readCompanyIdOrOwn\\(", -1).length - 1;
|
||||
@@ -663,6 +669,100 @@ class AdminAppearancePatentCleanItemsControllerTest {
|
||||
assertTrue(source.contains("AppearancePatentSupervisorPageVo"), "主管卡片页信封类型必须点名");
|
||||
}
|
||||
|
||||
// ===================== 2026-11-11 客户「也要加个删除按钮」 =====================
|
||||
|
||||
@Test
|
||||
void 按主管删除端点就位且必须带主管与留痕() throws IOException {
|
||||
String source = stripComments(Files.readString(CONTROLLER));
|
||||
assertTrue(source.contains("@DeleteMapping(\"/supervisors\")"),
|
||||
"删除必须是 DELETE /api/admin/appearance-patent-clean-items/supervisors(卡片上的「删除」)");
|
||||
assertTrue(source.contains("name = \"supervisor_user_id\", required = true")
|
||||
|| source.contains("supervisor_user_id"),
|
||||
"删除必须带 supervisor_user_id(不按主管收窄的删除等于删整个过滤面)");
|
||||
assertTrue(source.contains("deleteBySupervisor("), "删除必须落到服务的 deleteBySupervisor");
|
||||
// 破坏性动作必须留痕:operatorId / supervisorUserId / deleted 三个字段都要落日志。
|
||||
assertTrue(source.contains("operator.id()") && source.contains("deleted="),
|
||||
"管理端真删必须打一条带 operatorId 与删除行数的日志(否则事后无法归因是谁删的)");
|
||||
// 删除与查询/导出同一公司正门 + 同一鉴权闸。
|
||||
long gateCalls = source.split("requireCleanItemsAccess\\(request\\)", -1).length - 1;
|
||||
assertTrue(gateCalls >= 3, "分页/导出/删除三支 handler 都必须过 requireCleanItemsAccess,实得 " + gateCalls);
|
||||
long scopeCalls = source.split("readCompanyIdOrOwn\\(", -1).length - 1;
|
||||
assertTrue(scopeCalls >= 3, "分页/导出/删除三支 handler 都必须走 readCompanyIdOrOwn 公司隔离,实得 " + scopeCalls);
|
||||
}
|
||||
|
||||
@Test
|
||||
void 控制器删除走同一正门并回删除行数() {
|
||||
AppearancePatentCleanItemQueryService queryService = mock(AppearancePatentCleanItemQueryService.class);
|
||||
AdminAuthSupport authSupport = mock(AdminAuthSupport.class);
|
||||
DataReadScope dataReadScope = mock(DataReadScope.class);
|
||||
AdminAppearancePatentCleanItemsController controller = new AdminAppearancePatentCleanItemsController(
|
||||
queryService, authSupport, mock(PermissionMenuService.class), dataReadScope);
|
||||
|
||||
AdminUserEntity operator = new AdminUserEntity();
|
||||
operator.setId(7L);
|
||||
HttpServletRequest request = mock(HttpServletRequest.class);
|
||||
when(authSupport.requireUser(request)).thenReturn(operator);
|
||||
when(authSupport.currentRole(operator)).thenReturn("super_admin");
|
||||
// 非超管场景由 readCompanyIdOrOwn 自己收窄,这里钉「正门的返回值原样交给服务」。
|
||||
when(dataReadScope.readCompanyIdOrOwn(operator, 5L)).thenReturn(5L);
|
||||
when(queryService.deleteBySupervisor(9L, "DE", null, null, null, 5L)).thenReturn(120);
|
||||
|
||||
ApiResponse<Integer> response = controller.deleteBySupervisor(9L, "DE", null, null, null, 5L, request);
|
||||
|
||||
verify(dataReadScope).readCompanyIdOrOwn(operator, 5L);
|
||||
verify(queryService).deleteBySupervisor(9L, "DE", null, null, null, 5L);
|
||||
assertEquals(Boolean.TRUE, response.isSuccess());
|
||||
assertEquals(120, response.getData(), "必须把实际删除行数回给页面(前端拿它做反馈,不猜)");
|
||||
}
|
||||
|
||||
@Test
|
||||
void 删除服务缺主管直接拒绝且一个字节都不删() {
|
||||
AppearancePatentCleanItemMapper mapper = mock(AppearancePatentCleanItemMapper.class);
|
||||
AppearancePatentCleanItemQueryService service = new AppearancePatentCleanItemQueryService(
|
||||
mapper, mock(AdminUserMapper.class), mock(ShopManageGroupMapper.class));
|
||||
|
||||
BusinessException ex = assertThrows(BusinessException.class,
|
||||
() -> service.deleteBySupervisor(null, null, null, null, null, 5L));
|
||||
assertTrue(ex.getMessage().contains("缺少主管"), "缺主管必须明确拒绝(不能退化成整表删除)");
|
||||
assertThrows(BusinessException.class,
|
||||
() -> service.deleteBySupervisor(0L, null, null, null, null, 5L));
|
||||
verifyNoInteractions(mapper);
|
||||
|
||||
BusinessException reversed = assertThrows(BusinessException.class,
|
||||
() -> service.deleteBySupervisor(9L, null, LocalDate.of(2026, 11, 12),
|
||||
LocalDate.of(2026, 11, 1), null, 5L));
|
||||
assertTrue(reversed.getMessage().contains("开始日期不能晚于结束日期"), "日期倒挂同全站口径拒绝");
|
||||
verifyNoInteractions(mapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void 删除服务按过滤面与主管下推且分组空集短路() {
|
||||
AppearancePatentCleanItemMapper mapper = mock(AppearancePatentCleanItemMapper.class);
|
||||
ShopManageGroupMapper groupMapper = mock(ShopManageGroupMapper.class);
|
||||
AppearancePatentCleanItemQueryService service = new AppearancePatentCleanItemQueryService(
|
||||
mapper, mock(AdminUserMapper.class), groupMapper);
|
||||
// 分组解析出的用户集(组长本人+名下子账户)整集下推,删除与导出同一口径。
|
||||
when(groupMapper.selectUserIdsByGroupId(3L)).thenReturn(List.of(11L, 12L));
|
||||
when(mapper.deleteSupervisorItems(5L, null, null, "DE", null, null, List.of(11L, 12L), 9L)).thenReturn(88);
|
||||
|
||||
int deleted = service.deleteBySupervisor(9L, "DE", null, null, 3L, 5L);
|
||||
|
||||
assertEquals(88, deleted, "删除行数原样回传");
|
||||
ArgumentCaptor<List<Long>> userIds = ArgumentCaptor.forClass(List.class);
|
||||
verify(mapper).deleteSupervisorItems(eq(5L), isNull(), isNull(), eq("DE"), isNull(), isNull(),
|
||||
userIds.capture(), eq(9L));
|
||||
assertEquals(List.of(11L, 12L), userIds.getValue(), "分组用户集必须整集下推(铁律 20,不在 Java 侧过滤)");
|
||||
|
||||
// 分组解析不出用户(分组已删):过滤面本身为空,一条都不许删。
|
||||
AppearancePatentCleanItemMapper emptyMapper = mock(AppearancePatentCleanItemMapper.class);
|
||||
ShopManageGroupMapper emptyGroupMapper = mock(ShopManageGroupMapper.class);
|
||||
when(emptyGroupMapper.selectUserIdsByGroupId(3L)).thenReturn(List.of());
|
||||
AppearancePatentCleanItemQueryService emptyService = new AppearancePatentCleanItemQueryService(
|
||||
emptyMapper, mock(AdminUserMapper.class), emptyGroupMapper);
|
||||
assertEquals(0, emptyService.deleteBySupervisor(9L, null, null, null, 3L, 5L));
|
||||
verifyNoInteractions(emptyMapper);
|
||||
}
|
||||
|
||||
/** 导出/分页用例共用的明细行夹具:task 归 owner,值非空便于按列对撞。 */
|
||||
private static CleanItemEntity rowEntity(long id, long userId) { CleanItemEntity entity = new CleanItemEntity();
|
||||
entity.setId(id);
|
||||
|
||||
Reference in New Issue
Block a user