From 920cec41cedfde27f89d7c19b78e03147b926ab5 Mon Sep 17 00:00:00 2001
From: wangzhibo <wangzhibo@shsening.com>
Date: 星期二, 28 七月 2026 10:58:45 +0800
Subject: [PATCH] add pdfjs and traderecord
---
src/modules/report/service/taskservice.ts | 121 ++++++++--------------------------------
1 files changed, 25 insertions(+), 96 deletions(-)
diff --git a/src/modules/report/service/taskservice.ts b/src/modules/report/service/taskservice.ts
index 9536abe..56c3a21 100644
--- a/src/modules/report/service/taskservice.ts
+++ b/src/modules/report/service/taskservice.ts
@@ -3,8 +3,8 @@
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository, In } from 'typeorm';
import { ReportJoblogEntity } from '../entity/joblog';
-import { TaskSiteService } from './tasksiteservice'
-import { TaskDepartmentService } from './taskdepartmentservice'
+import { ExecutorSiteDeptDaily } from './ExecutorSiteDeptDaily'
+import { ExecutorVehicleDaily } from './ExecutorVehicleDaily'
/**
* 瀹氭椂浠诲姟-姹囨�荤珯鐐�/鍚勪釜鍗曚綅鐨勫悇绫诲瀮鍦炬眹鎬绘暟鎹�
@@ -17,12 +17,13 @@
@InjectEntityModel(ReportJoblogEntity)
reportJoblogEntity: Repository<ReportJoblogEntity>;
- // 娉ㄥ叆浣犲叿浣撶殑涓氬姟 Service锛岀敤浜庤窇鐪熸鐨勬眹鎬� SQL
@Inject()
- taskSiteService: TaskSiteService;
+ executorSiteDeptDaily: ExecutorSiteDeptDaily;
@Inject()
- departmentCubeService: TaskDepartmentService;
+ executorVehicleDaily: ExecutorVehicleDaily;
+
+
/**
* 澶栭儴瀹氭椂浠诲姟锛圕rontab锛夋瘡灏忔椂璋冪敤鐨勬�诲叆鍙�
@@ -32,10 +33,17 @@
// 1. 鑷姩鐪嬮棬鐙楋細纭繚鏄ㄥぉ鍜屼粖澶╃殑浠诲姟瀹炰緥宸茬粡鍦ㄨ〃閲屽垵濮嬪寲浜�
await this.ensureJobInstancesCreated();
- // 2. 鎵ц寮曟搸锛氭崬鍑洪渶瑕佹墽琛屾垨閲嶈瘯鐨勪换鍔�
- await this.executePendingJobs();
+ // 2. 涓ょ被浠诲姟鍚屾椂鎵ц
+ // 鍚庣画澧炲姞鏂扮殑 task service 姣斿 鏇存柊 钀ょ煶浜� token锛� 缁熻鍒嗘嫞鍛樿涓虹瓑绛夈��
- return '浠诲姟鎵ц鎴愬姛:ReportTaskService';
+ await Promise.all([
+ this.executorSiteDeptDaily.execute(),
+ this.executorVehicleDaily.execute()
+
+ ]);
+
+
+ return '浠诲姟鎵ц:ReportTaskService';
}
/**
@@ -56,10 +64,14 @@
// 鎴戜滑闇�瑕佸畧鎶ょ殑鐩爣鏃ユ湡鍜屼换鍔$被鍨嬬粍鍚�
const targets = [
- { date: yesterdayStr, type: 'SITE_DAILY',isToday: false},
- { date: yesterdayStr, type: 'DEPT_DAILY',isToday: false},
- { date: todayStr, type: 'SITE_DAILY' ,isToday: true},
- { date: todayStr, type: 'DEPT_DAILY' ,isToday: true},
+ { date: yesterdayStr, type: 'SITE_DAILY', isToday: false },
+ { date: yesterdayStr, type: 'DEPT_DAILY', isToday: false },
+ { date: yesterdayStr, type: 'VEHICLE_DAILY', isToday: false }, // 鏂板
+
+ { date: todayStr, type: 'SITE_DAILY', isToday: true },
+ { date: todayStr, type: 'DEPT_DAILY', isToday: true },
+ { date: todayStr, type: 'VEHICLE_DAILY', isToday: true }, // 鏂板
+
];
for (const target of targets) {
@@ -75,7 +87,7 @@
job.dataDate = target.date;
job.status = 'INIT';
await this.reportJoblogEntity.save(job);
- }else if (target.isToday && exist.status === 'SUCCESS') {
+ } else if (target.isToday && exist.status === 'SUCCESS') {
// 2. 銆愭牳蹇冧慨澶嶃�戝鏋滄槸浠婂ぉ鐨勪换鍔★紝涓斿凡缁忔槸 SUCCESS 鐘舵�侊紝寮鸿娲楀洖 INIT 鍙備笌鏈皬鏃剁殑閲嶇畻
await this.reportJoblogEntity.update(exist.id, {
status: 'INIT'
@@ -87,88 +99,5 @@
}
}
- /**
- * 鎹炲嚭 INIT 鍜� FAILED 鐨勪换鍔★紝骞朵覆琛屼弗鏍兼寜椤哄簭鎵ц
- */
- private async executePendingJobs() {
- // 鎹炲嚭鎵�鏈夊緟澶勭悊浠诲姟
- const pendingJobs = await this.reportJoblogEntity.find({
- where: {
- status: In(['INIT', 'FAILED']),
- },
- order: {
- dataDate: 'ASC', // 鍏堢畻鍘嗗彶锛屽悗绠椾粖澶�
- // 纭繚鍦ㄥ悓涓�澶╁唴锛孲ITE_DAILY 鍏堣窇锛孌EPT_DAILY 鍚庤窇
- // 鍦� JS 鏁扮粍涓垜浠彲浠ヨ繘涓�姝ユ帶鍒舵帓搴忥紝鎴栬�呯敱涓氬姟閫昏緫涓ユ牸鎺у埗渚濊禆
- },
- });
- for (const job of pendingJobs) {
- // 涓ユ牸渚濊禆妫�鏌ワ細濡傛灉鏄儴闂ㄦ棩琛ㄤ换鍔★紝蹇呴』纭繚鍚屽ぉ鐨勭珯鐐规棩琛ㄤ换鍔″凡缁忔槸 SUCCESS
- if (job.jobName === 'DEPT_DAILY') {
- const siteJob = await this.reportJoblogEntity.findOneBy({
- dataDate: job.dataDate,
- jobName: 'SITE_DAILY',
- });
- if (!siteJob || siteJob.status !== 'SUCCESS') {
- // 婧愬ご鏄庣粏杩樻病绠楀ソ/鎴栬繕鍦ㄨ繍琛岋紝閮ㄩ棬琛ㄤ换鍔″繀椤荤瓑寰咃紝璺宠繃鏈鎵ц
- continue;
- }
- }
-
- // 閿佸畾浠诲姟鐘舵�佷负 RUNNING锛堣交閲忕骇涔愯閿侀攣鏈哄埗锛�
- const lockResult = await this.reportJoblogEntity.update(
- { id: job.id, status: job.status }, // 甯︽湁鍘熷鐘舵�佹鏌ワ紝闃叉琚埆鐨勭嚎绋嬫姠璺�
- { status: 'RUNNING', startTime: new Date() }
- );
-
- if (lockResult.affected === 0) {
- continue; // 娌℃姠鍒伴攣锛岃鏄庡埆鐨勫畾鏃跺櫒鍦ㄨ窇瀹冿紝璺宠繃
- }
-
- // 鐪熸寮�濮嬭窇鏁版嵁
- try {
- let recordsProcessed = 0 ;
-
- if (job.jobName === 'SITE_DAILY') {
- // 璋冪敤浣犲啓鐨� 绔欑偣鏃ヨ〃 鎻愬彇閫昏緫
- recordsProcessed = await this.taskSiteService.aggregateDailyData(job.dataDate) || 0;
- } else if (job.jobName === 'DEPT_DAILY') {
- // 璋冪敤浣犲啓鐨� 閮ㄩ棬鏍戣桨鐐� 鎻愬彇閫昏緫
- recordsProcessed = await this.departmentCubeService.aggregateDailyData(job.dataDate) || 0;
- }
-
- // 鎴愬姛锛氭洿鏂扮姸鎬�
- await this.reportJoblogEntity.update(job.id, {
- status: 'SUCCESS',
- recordsProcessed:recordsProcessed,
- endTime: new Date(),
- errorMessage: '',
- });
-
- } catch (error) {
- // 澶辫触锛氳褰曞爢鏍堬紝绛夊緟涓嬩竴灏忔椂閲嶈瘯
-
- var errorMessage = '';
- if (error instanceof Error) {
- errorMessage = error.stack ?? error.message;
- }
- if (typeof error === 'string') {
- errorMessage = error;
- }
- try {
- errorMessage = JSON.stringify(error);
- } catch {
- errorMessage = String(error);
- }
-
- await this.reportJoblogEntity.update(job.id, {
- status: 'FAILED',
- endTime: new Date(),
- errorMessage: errorMessage,
- failedCount: () => 'failedCount + 1',
- });
- }
- }
- }
}
\ No newline at end of file
--
Gitblit v1.9.1