hotfix: 修复OA任务时间与页面刷新入口 #790

Merged
yueyang merged 1 commits from hotfix/yueyang-oa-task-time-refresh into main 2026-10-30 15:43:11 +08:00
6 changed files with 80 additions and 5 deletions

View File

@ -964,6 +964,17 @@ class Pages extends Controller
public function show(string $section, ?string $page = null, ?string $tab = null)
{
if ($section === 'process-data' && $page === 'oa-process') {
if (request()->boolean('refresh_current')) {
return app(\Modules\EcommerceFinance\Http\Controllers\ProcessDetails::class)
->requestRefresh(request());
}
if (request()->filled('refresh_status')) {
return app(\Modules\EcommerceFinance\Http\Controllers\ProcessDetails::class)
->refreshStatus((string) request()->query('refresh_status'));
}
}
if ($section === 'refunds' && $page === 'small-payment-work-orders') {
$url = route('business.pages.show', [
'section' => self::SMALL_PAYMENT_SECTION,

View File

@ -1533,7 +1533,7 @@ class DingProcessDetailMirrorSynchronizer
private function taskDateTime(mixed $value): ?Carbon
{
$parsed = OaProcessTime::parse($value);
$parsed = OaProcessTime::parseDingTalkTask($value);
return $parsed === null ? null : Carbon::instance($parsed);
}

View File

@ -35,6 +35,23 @@ final class OaProcessTime
}
}
public static function parseDingTalkTask(mixed $value): ?CarbonImmutable
{
$text = trim((string) $value);
if ($text === '') {
return null;
}
try {
return CarbonImmutable::parse(
str_replace('T', ' ', preg_replace('/Z$/', '', $text)),
self::timezone(),
);
} catch (Throwable) {
return null;
}
}
public static function formatDateTime(mixed $value): string
{
return self::parse($value)?->format('Y-m-d H:i') ?? '-';

View File

@ -2,7 +2,9 @@
namespace Tests\Feature\Business;
use App\Http\Controllers\Business\Pages;
use App\Models\Auth\Permission;
use Illuminate\Http\Request;
use Mockery;
use Modules\EcommerceFinance\Repositories\DingProcessDetailMirrorRepository;
use Modules\EcommerceFinance\Services\DingProcessRefreshQueue;
@ -199,6 +201,43 @@ class ProcessDetailsPageTest extends FeatureTestCase
->assertJsonPath('refresh.count', 1);
}
public function test_generic_business_page_controller_handles_refresh_requests(): void
{
$moduleController = Mockery::mock(\Modules\EcommerceFinance\Http\Controllers\ProcessDetails::class);
$moduleController->shouldReceive('requestRefresh')
->once()
->andReturn(response()->json(['success' => true, 'queued' => true]));
$moduleController->shouldReceive('refreshStatus')
->once()
->with('00000000-0000-4000-8000-000000000001')
->andReturn(response()->json(['success' => true, 'refresh' => ['status' => 'completed']]));
$this->app->instance(
\Modules\EcommerceFinance\Http\Controllers\ProcessDetails::class,
$moduleController,
);
$genericPage = (new \ReflectionClass(Pages::class))->newInstanceWithoutConstructor();
$this->app->instance('request', Request::create(
'/1/workspace/process-data/oa-process',
'GET',
['refresh_current' => '1'],
));
$this->assertSame(
200,
$genericPage->show('process-data', 'oa-process')->getStatusCode(),
);
$this->app->instance('request', Request::create(
'/1/workspace/process-data/oa-process',
'GET',
['refresh_status' => '00000000-0000-4000-8000-000000000001'],
));
$this->assertSame(
200,
$genericPage->show('process-data', 'oa-process')->getStatusCode(),
);
}
public function test_page_stays_readable_when_mirror_is_not_ready(): void
{
$this->user->attachPermission(Permission::where('name', 'read-admin-panel')->firstOrFail());

View File

@ -282,9 +282,9 @@ class DingProcessDetailMirrorSynchronizerTest extends TestCase
->first();
$this->assertSame('财务审批 / 出纳打款', $row->current_task_name);
$this->assertSame('王五', $row->current_approver_name);
$this->assertSame('2026-06-03 23:00:00', (string) $row->current_task_started_at);
$this->assertSame('2026-06-03 15:00:00', (string) $row->current_task_started_at);
$this->assertSame('出纳打款', $row->cashier_task_name);
$this->assertSame('2026-06-03 23:34:00', (string) $row->cashier_task_started_at);
$this->assertSame('2026-06-03 15:34:00', (string) $row->cashier_task_started_at);
$this->assertSame('pending', $row->cashier_status);
$this->assertSame(
'待付款',
@ -332,7 +332,7 @@ class DingProcessDetailMirrorSynchronizerTest extends TestCase
->first();
$this->assertSame('出纳打款', $row->current_task_name);
$this->assertSame('王五', $row->current_approver_name);
$this->assertSame('2026-10-30 02:50:00', (string) $row->current_task_started_at);
$this->assertSame('2026-10-29 18:50:00', (string) $row->current_task_started_at);
}
public function test_running_workflow_without_payment_fields_resolves_current_task_and_approver(): void
@ -380,7 +380,7 @@ class DingProcessDetailMirrorSynchronizerTest extends TestCase
->first();
$this->assertSame('行政核价', $row->current_task_name);
$this->assertSame('赵六', $row->current_approver_name);
$this->assertSame('2026-10-30 03:20:00', (string) $row->current_task_started_at);
$this->assertSame('2026-10-29 19:20:00', (string) $row->current_task_started_at);
$this->assertSame('not_applicable', $row->payment_source_state);
}

View File

@ -58,6 +58,14 @@ class OaProcessTimeTest extends TestCase
);
}
public function test_dingtalk_task_suffix_is_treated_as_local_wall_time(): void
{
$this->assertSame(
'10:56',
OaProcessTime::parseDingTalkTask('2026-10-30T10:56Z')?->format('H:i'),
);
}
public function test_future_timestamp_is_not_shown_as_less_than_one_minute(): void
{
$now = CarbonImmutable::parse('2026-10-30 12:00:00', 'Asia/Shanghai');