feat: 同步OA发起人部门 #796
@ -30,6 +30,7 @@ return new class extends Migration
|
||||
$table->unsignedInteger('line_no');
|
||||
$table->string('business_month', 6)->index();
|
||||
$table->string('originator_name', 100)->nullable()->index();
|
||||
$table->string('originator_department', 255)->nullable();
|
||||
$table->string('status', 20)->nullable()->index();
|
||||
$table->string('document_type', 100)->nullable()->index();
|
||||
$table->text('purpose')->nullable();
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private function connection(): string
|
||||
{
|
||||
return (string) config('upstream_mirrors.connection', 'business_mirror');
|
||||
}
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
if (app()->environment('testing')
|
||||
|| (string) config('system_database.mode', 'bootstrap') === 'bootstrap') {
|
||||
return;
|
||||
}
|
||||
|
||||
$schema = Schema::connection($this->connection());
|
||||
if (! $schema->hasTable('ding_process_detail_mirror')
|
||||
|| $schema->hasColumn('ding_process_detail_mirror', 'originator_department')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$schema->table('ding_process_detail_mirror', function (Blueprint $table): void {
|
||||
$table->string('originator_department', 255)
|
||||
->nullable()
|
||||
->after('originator_name');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (app()->environment('testing')
|
||||
|| (string) config('system_database.mode', 'bootstrap') === 'bootstrap') {
|
||||
return;
|
||||
}
|
||||
|
||||
$schema = Schema::connection($this->connection());
|
||||
if ($schema->hasTable('ding_process_detail_mirror')
|
||||
&& $schema->hasColumn('ding_process_detail_mirror', 'originator_department')) {
|
||||
$schema->table('ding_process_detail_mirror', function (Blueprint $table): void {
|
||||
$table->dropColumn('originator_department');
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -33,7 +33,7 @@
|
||||
| 已接入待首次同步 | 店铺营销账户余额的京东账户读取 `js_data_middle_platform.dbo.jd_jzt_finance_records` 镜像 `jsm_jd_jzt_finance_records`;按 `id` 稳定断点、`updated_at` 重叠增量,页面不直连上游。 |
|
||||
| 本次接入 | 普通商品资料的工作平台采购价格接入 `jiansun.dbo.pm_priceAdjustment`(镜像 `js_pm_price_adjustment`):按 `skuCode` 关联 `jst_sku.sku_id`,取 `effectTime` 不晚于当前时间的最新 `purchasePrice`,并在页面和导出中标记“工作平台价格”;源表没有可靠更新时间,按 `Id` 稳定键追加,首次全量完成前只显示普通商品自身采购价。 |
|
||||
| 待有效凭据后首次同步 | 普通商品当前成本价、商品类型和更新时间继续读取 `operations_replica.rpt.jst_sku`;`rpt.fys_skuCostPriceUpdate` 是一 SKU 一行的旧快照,不能充当变价历史。完整成本价变更仍读取聚水潭经典开放平台“商品操作日志查询”接口 `worklog.query`,只镜像操作内容含“采购价”的记录到 `jushuitan_cost_price_history_rows`;经典接口必须在服务器私有配置中使用同一应用的 `JUSHUITAN_PARTNER_ID / JUSHUITAN_PARTNER_KEY / JUSHUITAN_TOKEN`,不得把新开放平台的 App Key / App Secret / Access Token 混用。页面在首次同步完成前明确显示待同步或失败,不把 0 条解释为真实无历史。 |
|
||||
| 本次接入 | 流程明细读取 `operations_replica/rpt.ding_Workflow + rpt.ding_WorkflowScheme` 的结构化审批主表、费用明细和付款明细,写入 `ding_process_detail_mirror` 与 `ding_process_payment_mirror`。禁止先把明细表和付款表铺平成 CSV 后逐行求和;付款明细必须按“对应序号”关联到代表明细行,但合计始终读取独立付款事实。每个纳入范围的源审批至少保留一条页面记录,没有费用金额的审批以空金额显示,不静默隐藏。首次全量先运行 `business-mirror:sync-ding-process-details --full --dry-run` 校验,再使用 `business-mirror:sync-ding-process-details --full` 发布;日常通过 `updateAt/createAt` 48 小时重叠增量同步。当前纳入日常报销、应付、线上代发、种菜、快递面单、固定资产、日常物品、样品、一次性采买、板材、工资、外贸费用和种菜充值等 14 个财务流程;发现新的明细流程编码时全量同步报错并保留上一版。 |
|
||||
| 本次接入 | 流程明细读取 `operations_replica/rpt.ding_Workflow + rpt.ding_WorkflowScheme` 的结构化审批主表、费用明细和付款明细,写入 `ding_process_detail_mirror` 与 `ding_process_payment_mirror`;主表的 `originatorDeptName` 作为发起人部门单独保留。禁止先把明细表和付款表铺平成 CSV 后逐行求和;付款明细必须按“对应序号”关联到代表明细行,但合计始终读取独立付款事实。每个纳入范围的源审批至少保留一条页面记录,没有费用金额的审批以空金额显示,不静默隐藏。首次全量先运行 `business-mirror:sync-ding-process-details --full --dry-run` 校验,再使用 `business-mirror:sync-ding-process-details --full` 发布;日常通过 `updateAt/createAt` 48 小时重叠增量同步。当前纳入日常报销、应付、线上代发、种菜、快递面单、固定资产、日常物品、样品、一次性采买、板材、工资、外贸费用和种菜充值等 14 个财务流程;发现新的明细流程编码时全量同步报错并保留上一版。 |
|
||||
|
||||
流程明细另设独立定时任务,避免与每分钟科目映射消费争用同一上游目录时被静默跳过。正式发布脚本会覆盖安装 `/etc/cron.d/caiwu-ding-process-details`:每 5 分钟尝试运行 `business-mirror:sync-ding-process-details`,使用独立调度锁并在共用上游锁上最多等待 15 分钟;`scripts/install-ding-process-sync-cron.ps1` 仅作为手工修复入口。任务时间和镜像状态统一使用平台固定时区,审批等待时长按实际小时展示。OA 页面每小时最多把一次当前页“审批中”的审批编号写入定向刷新队列,由每分钟检查一次的批处理命令消费;其他时间直接展示最近镜像,已完成流程不进入即时刷新链路,仍由常规增量和每周全量校准处理付款等后续变化。增量同步除跟进审批主表更新时间外,还以 `ding_WorkflowScheme` 的数字 `id` 高水位发现后补表单行,避免付款明细等新组件写入后主审批 `updateAt` 不变而被漏掉;原地改写同一组件仍由每周全量校准兜底。付款状态只按钉钉“出纳打款”节点判断,分为“出纳状态待同步 / 出纳未开始 / 出纳待打款 / 出纳退回 / 出纳已打款 / 流程终止 / 不涉及付款”。金额差异不参与付款状态判断,另以“付款差额 = 费用合计 − 已付款合计”展示。不能因为金额存在少量差异就覆盖出纳节点事实,也不能因为出纳已通过就隐藏金额差异。
|
||||
|
||||
|
||||
@ -119,7 +119,9 @@ class ProcessDetails extends Controller
|
||||
return response()->streamDownload(function () use ($filters): void {
|
||||
$stream = fopen('php://output', 'wb');
|
||||
fwrite($stream, "\xEF\xBB\xBF");
|
||||
fputcsv($stream, [...DingProcessDetailMirrorImporter::HEADERS, '付款状态', '付款差额']);
|
||||
$headers = DingProcessDetailMirrorImporter::HEADERS;
|
||||
array_splice($headers, 2, 0, ['发起人部门']);
|
||||
fputcsv($stream, [...$headers, '付款状态', '付款差额']);
|
||||
|
||||
$number = 0;
|
||||
foreach ($this->repository->exportRows($filters) as $row) {
|
||||
@ -127,6 +129,7 @@ class ProcessDetails extends Controller
|
||||
fputcsv($stream, [
|
||||
$number,
|
||||
(string) ($row['business_id'] ?? ''),
|
||||
(string) ($row['originator_department'] ?? ''),
|
||||
(string) ($row['originator_name'] ?? ''),
|
||||
(string) ($row['status'] ?? ''),
|
||||
(string) ($row['document_type'] ?? ''),
|
||||
|
||||
@ -1683,6 +1683,11 @@ class DingProcessDetailMirrorSynchronizer
|
||||
'line_no' => $lineNo,
|
||||
'business_month' => $businessMonth,
|
||||
'originator_name' => mb_substr($originator, 0, 100),
|
||||
'originator_department' => mb_substr(
|
||||
trim((string) ($workflow['originatorDeptName'] ?? '')),
|
||||
0,
|
||||
255,
|
||||
),
|
||||
'status' => mb_substr($status, 0, 20),
|
||||
'payment_source_state' => mb_substr($paymentSourceState, 0, 24),
|
||||
'cashier_status' => mb_substr($cashierStatus, 0, 32),
|
||||
|
||||
@ -599,7 +599,7 @@
|
||||
|
||||
.process-details-table {
|
||||
width: 100%;
|
||||
min-width: 104rem;
|
||||
min-width: 106rem;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
font-size: .78rem;
|
||||
@ -1213,6 +1213,7 @@
|
||||
<tr>
|
||||
<th>序号</th>
|
||||
<th>审批编号</th>
|
||||
<th>发起人部门</th>
|
||||
<th>发起人</th>
|
||||
<th>审批状态</th>
|
||||
<th>付款状态</th>
|
||||
@ -1238,6 +1239,7 @@
|
||||
<tr>
|
||||
<td class="num">{{ ($processRows->currentPage() - 1) * $processRows->perPage() + $loop->iteration }}</td>
|
||||
<td>{{ $row->business_id }}</td>
|
||||
<td class="wide" title="{{ $row->originator_department ?? '' }}">{{ $text($row->originator_department ?? null) }}</td>
|
||||
<td>{{ $text($row->originator_name) }}</td>
|
||||
<td class="center">
|
||||
<span class="process-details-status {{ $statusClass((string) $row->status) }}">{{ $text($row->status) }}</span>
|
||||
@ -1263,7 +1265,7 @@
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="20" class="process-details-empty">
|
||||
<td colspan="21" class="process-details-empty">
|
||||
当前筛选条件没有OA流程数据。可以调整月份、单据类型、状态或关键词后重试。
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@ -25,6 +25,7 @@ class ProcessDetailsPageTest extends FeatureTestCase
|
||||
(object) [
|
||||
'business_id' => '202601011200000000001',
|
||||
'line_no' => 1,
|
||||
'originator_department' => '销售中心',
|
||||
'originator_name' => '张三',
|
||||
'status' => '已完成',
|
||||
'payment_state' => '已付款',
|
||||
@ -94,6 +95,7 @@ class ProcessDetailsPageTest extends FeatureTestCase
|
||||
->assertSee('流程数据')
|
||||
->assertSee('OA流程')
|
||||
->assertSee('审批编号')
|
||||
->assertSee('发起人部门')
|
||||
->assertSee('发起人')
|
||||
->assertSee('单据类型')
|
||||
->assertSee('打款时间')
|
||||
@ -147,6 +149,7 @@ class ProcessDetailsPageTest extends FeatureTestCase
|
||||
->assertDontSee('银行付款合计')
|
||||
->assertSee('流程数据已超过 15 分钟未成功同步')
|
||||
->assertSee('202601011200000000001')
|
||||
->assertSee('销售中心')
|
||||
->assertSee('张三')
|
||||
->assertSee('管理费用_办公费')
|
||||
->assertSee('100.00')
|
||||
@ -309,6 +312,7 @@ class ProcessDetailsPageTest extends FeatureTestCase
|
||||
$repository->shouldReceive('exportRows')->once()->andReturnUsing(function (): \Generator {
|
||||
yield [
|
||||
'business_id' => '202601011200000000001',
|
||||
'originator_department' => '销售中心',
|
||||
'originator_name' => '张三',
|
||||
'status' => '已完成',
|
||||
'payment_state' => '已付款',
|
||||
@ -336,7 +340,9 @@ class ProcessDetailsPageTest extends FeatureTestCase
|
||||
$response->assertOk();
|
||||
$content = $response->streamedContent();
|
||||
$this->assertStringContainsString('审批编号', $content);
|
||||
$this->assertStringContainsString('发起人部门', $content);
|
||||
$this->assertStringContainsString('202601011200000000001', $content);
|
||||
$this->assertStringContainsString('销售中心', $content);
|
||||
$this->assertStringContainsString('张三', $content);
|
||||
$this->assertStringContainsString('管理费用_办公费', $content);
|
||||
$this->assertStringContainsString('付款状态', $content);
|
||||
|
||||
@ -235,6 +235,7 @@ class ImportDingProcessDetailsTest extends TestCase
|
||||
$table->unsignedInteger('line_no');
|
||||
$table->string('business_month', 6)->index();
|
||||
$table->string('originator_name', 100)->nullable()->index();
|
||||
$table->string('originator_department', 255)->nullable();
|
||||
$table->string('status', 20)->nullable()->index();
|
||||
$table->string('document_type', 100)->nullable()->index();
|
||||
$table->text('purpose')->nullable();
|
||||
|
||||
@ -474,6 +474,7 @@ class DingProcessDetailMirrorRepositoryTest extends TestCase
|
||||
'line_no' => $lineNo,
|
||||
'business_month' => $month,
|
||||
'originator_name' => $originator,
|
||||
'originator_department' => $businessId === '202601011200000000001' ? '销售部' : '财务部',
|
||||
'status' => $status,
|
||||
'payment_source_state' => 'present',
|
||||
'cashier_status' => $status === '已完成' ? 'completed' : 'pending',
|
||||
@ -536,6 +537,7 @@ class DingProcessDetailMirrorRepositoryTest extends TestCase
|
||||
$table->unsignedInteger('line_no');
|
||||
$table->string('business_month', 6)->index();
|
||||
$table->string('originator_name', 100)->nullable()->index();
|
||||
$table->string('originator_department', 255)->nullable();
|
||||
$table->string('status', 20)->nullable()->index();
|
||||
$table->string('payment_source_state', 24)->nullable();
|
||||
$table->string('cashier_status', 32)->nullable();
|
||||
|
||||
@ -82,6 +82,7 @@ class DingProcessDetailMirrorSynchronizerTest extends TestCase
|
||||
'title' => '陈芝豹提交的线上代发业务报销',
|
||||
'status' => 'COMPLETED',
|
||||
'originatorUserId' => 'user-1',
|
||||
'originatorDeptName' => '线上代发部',
|
||||
'joinAt' => '2026-05-04 18:12:20',
|
||||
'updateAt' => '2026-05-08 09:00:00',
|
||||
]];
|
||||
@ -103,6 +104,8 @@ class DingProcessDetailMirrorSynchronizerTest extends TestCase
|
||||
->table('ding_process_detail_mirror')->sum('bank_amount'), 0.001);
|
||||
$this->assertSame('present', DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')->value('payment_source_state'));
|
||||
$this->assertSame('线上代发部', DB::connection('business_mirror')
|
||||
->table('ding_process_detail_mirror')->value('originator_department'));
|
||||
|
||||
$summary = app(DingProcessDetailMirrorRepository::class)
|
||||
->paginate(['status' => '已完成'], 1, 50)['summary'];
|
||||
@ -969,6 +972,7 @@ class DingProcessDetailMirrorSynchronizerTest extends TestCase
|
||||
$table->unsignedInteger('line_no');
|
||||
$table->string('business_month', 6);
|
||||
$table->string('originator_name', 100)->nullable();
|
||||
$table->string('originator_department', 255)->nullable();
|
||||
$table->string('status', 20)->nullable();
|
||||
$table->string('payment_source_state', 24)->nullable();
|
||||
$table->string('cashier_status', 32)->nullable();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user