feat: 支持OA流程每页50、100、200条

This commit is contained in:
yueyang 2026-10-27 15:59:58 +08:00
parent 1083d9485c
commit aa67844b18
7 changed files with 149 additions and 4 deletions

View File

@ -8,6 +8,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Routing\Controller;
use Modules\EcommerceFinance\Repositories\DingProcessDetailMirrorRepository;
use Modules\EcommerceFinance\Services\DingProcessDetailMirrorImporter;
use Modules\EcommerceFinance\View\ProcessDetailsPageData;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Throwable;
@ -21,7 +22,7 @@ class ProcessDetails extends Controller
{
$filters = $this->filters($request);
$page = max((int) $request->query('page', 1), 1);
$perPage = 50;
$perPage = ProcessDetailsPageData::normalizePerPage($request->query('per_page'));
try {
$result = $this->repository->paginate($filters, $page, $perPage);

View File

@ -103,7 +103,7 @@ class DingProcessDetailMirrorRepository
}
$page = max($page, 1);
$perPage = min(max($perPage, 1), 100);
$perPage = min(max($perPage, 1), 200);
$query = $this->filteredQuery($filters);
$total = (clone $query)->count();

View File

@ -9,16 +9,29 @@ use Throwable;
class ProcessDetailsPageData
{
public const PER_PAGE_OPTIONS = [50, 100, 200];
public const DEFAULT_PER_PAGE = 50;
public function __construct(
private readonly DingProcessDetailMirrorRepository $repository,
) {}
public static function normalizePerPage(mixed $value): int
{
$perPage = (int) $value;
return in_array($perPage, self::PER_PAGE_OPTIONS, true)
? $perPage
: self::DEFAULT_PER_PAGE;
}
/** @return array<string,mixed> */
public function page(Request $request): array
{
$filters = $this->filters($request);
$page = max((int) $request->query('page', 1), 1);
$perPage = 50;
$perPage = self::normalizePerPage($request->query('per_page'));
try {
$result = $this->repository->paginate($filters, $page, $perPage);

View File

@ -7,6 +7,7 @@
$paymentStates = $paymentStates ?? ($pageData['paymentStates'] ?? []);
$mirrorStale = $mirrorStale ?? ($pageData['mirrorStale'] ?? false);
$mirrorStaleAfterMinutes = $mirrorStaleAfterMinutes ?? ($pageData['mirrorStaleAfterMinutes'] ?? 15);
$perPageOptions = \Modules\EcommerceFinance\View\ProcessDetailsPageData::PER_PAGE_OPTIONS;
$scopeLabel ??= (($scope ?? null) === 'personal_permission'
? '当前账号权限范围'
: ($scope ?? ''));
@ -386,6 +387,32 @@
font-variant-numeric: tabular-nums;
}
.process-details-page-size {
display: inline-flex;
align-items: center;
gap: .3rem;
margin: 0;
}
.process-details-page-size select {
width: 4.5rem;
height: 2rem;
padding: 0 .35rem;
border: 1px solid var(--vip-border, #D8D2C7);
border-radius: .45rem;
background: #fff;
color: var(--vip-content-ink, #171717);
font: inherit;
font-size: .75rem;
font-variant-numeric: tabular-nums;
}
.process-details-page-size select:focus {
border-color: var(--vip-content-accent-dark, #856632);
outline: 0;
box-shadow: 0 0 0 3px rgba(133, 102, 50, .2);
}
.process-details-pagination {
display: inline-flex;
align-items: center;
@ -552,6 +579,10 @@
flex-wrap: wrap;
}
.process-details-page-size {
width: 100%;
}
.process-details-page-jump {
margin-left: 0;
}
@ -582,6 +613,7 @@
@endif
<form method="GET" action="{{ $pageUrl }}" class="process-details-toolbar" aria-label="OA流程筛选">
<input type="hidden" name="per_page" value="{{ $processRows->perPage() }}">
<div class="process-details-field">
<label for="process-details-paid-date">打款日期</label>
<input id="process-details-paid-date" type="date" name="paid_date" value="{{ $filters['paid_date'] ?? '' }}">
@ -722,6 +754,22 @@
<span>共 <b>{{ number_format($processRows->total()) }}</b> 行</span>
<span>第 <b>{{ number_format($processDetailsCurrentPage) }}</b> / {{ number_format($processDetailsLastPage) }} 页</span>
<span>本页 <b>{{ number_format($processRows->count()) }}</b> 行</span>
<form class="process-details-page-size" method="GET" action="{{ $pageUrl }}">
@foreach ($filters as $filterName => $filterValue)
@if ($filterValue !== '')
<input type="hidden" name="{{ $filterName }}" value="{{ $filterValue }}">
@endif
@endforeach
<label for="process-details-per-page">每页</label>
<select id="process-details-per-page" name="per_page" onchange="this.form.submit()">
@foreach ($perPageOptions as $perPageOption)
<option value="{{ $perPageOption }}" @selected($processRows->perPage() === $perPageOption)>
{{ $perPageOption }}
</option>
@endforeach
</select>
<span>行</span>
</form>
</div>
<nav class="process-details-pagination" aria-label="OA流程分页">
@ -763,6 +811,7 @@
@if ($processDetailsLastPage > 1)
<form class="process-details-page-jump" method="GET" action="{{ $pageUrl }}">
<input type="hidden" name="per_page" value="{{ $processRows->perPage() }}">
@foreach ($filters as $filterName => $filterValue)
@if ($filterValue !== '')
<input type="hidden" name="{{ $filterName }}" value="{{ $filterValue }}">

View File

@ -15,7 +15,9 @@ class ProcessDetailsPageTest extends FeatureTestCase
$this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());
$repository = Mockery::mock(DingProcessDetailMirrorRepository::class);
$repository->shouldReceive('paginate')->once()->andReturn([
$repository->shouldReceive('paginate')->once()
->with(Mockery::type('array'), 1, 100)
->andReturn([
'data' => [
(object) [
'business_id' => '202601011200000000001',
@ -75,6 +77,7 @@ class ProcessDetailsPageTest extends FeatureTestCase
$this->loginAs()->get(route('business.pages.show', [
'section' => 'process-data',
'page' => 'oa-process',
'per_page' => 100,
]))->assertOk()
->assertSee('流程数据')
->assertSee('OA流程')
@ -100,6 +103,10 @@ class ProcessDetailsPageTest extends FeatureTestCase
->assertSee('100.00')
->assertSee('当前账号权限范围')
->assertSee('同一笔付款不会因关联多条费用而重复计算')
->assertSee('name="per_page"', false)
->assertSee('value="50"', false)
->assertSee('value="100" selected', false)
->assertSee('value="200"', false)
->assertSee('导出');
}

View File

@ -194,6 +194,32 @@ class DingProcessDetailMirrorRepositoryTest extends TestCase
$this->assertSame('202601011200000000001', (string) $rows[0]['business_id']);
}
public function test_paginate_supports_two_hundred_rows_per_page(): void
{
$rows = [];
for ($index = 1; $index <= 97; $index++) {
$rows[] = $this->row(
'20260301' . str_pad((string) $index, 14, '0', STR_PAD_LEFT),
1,
'202603',
'批量测试',
'审批中',
'公摊日常报销',
'分页容量测试',
1.00,
'2026-03-01 00:00',
);
}
DB::connection('business_mirror')
->table('ding_process_detail_mirror')
->insert($rows);
$result = $this->repository->paginate([], 1, 200);
$this->assertSame(101, $result['total']);
$this->assertCount(101, $result['data']);
}
public function test_not_ready_when_state_is_missing(): void
{
DB::connection('business_mirror')

View File

@ -6,6 +6,7 @@ use Illuminate\Http\Request;
use Illuminate\Pagination\LengthAwarePaginator;
use Modules\EcommerceFinance\Repositories\DingProcessDetailMirrorRepository;
use Modules\EcommerceFinance\View\ProcessDetailsPageData;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class ProcessDetailsPageDataTest extends TestCase
@ -114,4 +115,52 @@ class ProcessDetailsPageDataTest extends TestCase
$this->assertArrayNotHasKey('months', $data);
$this->assertNull($data['error']);
}
#[DataProvider('perPageProvider')]
public function test_page_size_only_accepts_supported_options(mixed $requested, int $expected): void
{
$repository = $this->createMock(DingProcessDetailMirrorRepository::class);
$repository->expects($this->once())
->method('paginate')
->with($this->isType('array'), 1, $expected)
->willReturn([
'data' => [],
'total' => 0,
'summary' => [
'rows' => 0,
'approvals' => 0,
'amount_total' => 0,
'bank_amount_total' => 0,
],
'status' => 'succeeded',
'last_synced_at' => null,
'scope' => 'personal_permission',
]);
$repository->expects($this->once())
->method('filterOptions')
->willReturn([
'document_types' => [],
'statuses' => [],
'payment_states' => [],
]);
$data = (new ProcessDetailsPageData($repository))->page(Request::create(
'/1/workspace/process-data/oa-process',
'GET',
['per_page' => $requested],
));
$this->assertSame($expected, $data['processRows']->perPage());
}
/** @return array<string,array{mixed,int}> */
public static function perPageProvider(): array
{
return [
'50 条' => ['50', 50],
'100 条' => ['100', 100],
'200 条' => ['200', 200],
'非法值回退' => ['500', 50],
];
}
}