From 22c5f37a587bfb3363534fed05647faf5f93c8fe Mon Sep 17 00:00:00 2001
From: wangrong <wangrong@shsening.com>
Date: 星期六, 26 九月 2026 11:42:42 +0800
Subject: [PATCH] 修改首页显示和统计任务
---
src/modules/report/service/taskservicesite.ts | 47 ++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 40 insertions(+), 7 deletions(-)
diff --git a/src/modules/report/service/taskservicesite.ts b/src/modules/report/service/taskservicesite.ts
index d457fd6..6966bf4 100644
--- a/src/modules/report/service/taskservicesite.ts
+++ b/src/modules/report/service/taskservicesite.ts
@@ -55,18 +55,33 @@
// 3. 鍐呭瓨鑱氬悎鏍稿績锛氬畾涔夋敮鎸佸姩鎬侀敭鍚嶇疮鍔犵殑瀵硅薄瀛楀吀
const siteAggMap = new Map<string, any>();
- // 鏄犲皠琛細灏嗘槑缁嗛噷鐨� garbageType 鏄犲皠鍒颁綘 Entity 閲岀殑瀛楁鍚庣紑
+ // 婧愭暟鎹� garbageType 涓哄ぇ鍐� SW62001鈥W62007锛屾病鏈夊崟鐙殑 SW62 娴佹按銆�
+ // 鍏堟寜 7 涓瓙绫诲垎鍒疮璁★紝鍐嶆妸閲嶉噺/纰虫帓/閿�鍞姹囨�昏繘 SW62銆�
+ const SW62_SUB_CODES = [
+ 'SW62001', 'SW62002', 'SW62003', 'SW62004',
+ 'SW62005', 'SW62006', 'SW62007',
+ ];
+ const SW62_SUB_SUFFIXES = SW62_SUB_CODES.map(code => `Sw${code.slice(2)}`);
+ const typeSuffixes = [
+ 'Sw60', 'Sw61', 'Sw62', 'Sw63', 'Sw64',
+ ...SW62_SUB_SUFFIXES,
+ ];
const typeKeyMap: Record<string, string> = {
- 'SW60': 'Sw60', 'SW61': 'Sw61', 'SW62': 'Sw62', 'SW63': 'Sw63', 'SW64': 'Sw64',
- 'Sw62001': 'Sw62001', 'Sw62002': 'Sw62002', 'Sw62003': 'Sw62003',
- 'Sw62004': 'Sw62004', 'Sw62005': 'Sw62005', 'Sw62006': 'Sw62006', 'Sw62007': 'Sw62007'
+ SW60: 'Sw60',
+ SW61: 'Sw61',
+ SW63: 'Sw63',
+ SW64: 'Sw64',
};
-
+ for (const code of SW62_SUB_CODES) {
+ const suffix = `Sw${code.slice(2)}`;
+ typeKeyMap[code] = suffix;
+ typeKeyMap[suffix] = suffix;
+ }
for (const row of rawDetails) {
const siteId = row.siteId;
const weight = Number(row.weight) || 0;
- const gType = row.garbageType || 'SW64';
+ const gType = String(row.garbageType || 'SW64').trim().toUpperCase();
const fieldSuffix = typeKeyMap[gType];
// 鍒濆鍖栬绔欑偣鐨勮仛鍚堢粨鏋�
@@ -79,7 +94,7 @@
weightTotal: 0, timeTotal: 0, carbonTotal: 0
};
// 鍔ㄦ�佸垵濮嬪寲瀹借〃閲屽悇瀛愮被鍨嬬殑 0 鍊�
- Object.values(typeKeyMap).forEach(suffix => {
+ typeSuffixes.forEach(suffix => {
initData[`weight${suffix}`] = 0;
initData[`time${suffix}`] = 0;
initData[`carbon${suffix}`] = 0;
@@ -119,6 +134,24 @@
}
}
+ // SW62 娌℃湁鐙珛娴佹按锛岀敤 7 涓瓙绫婚噸閲�/纰虫帓/閿�鍞鍔犳�诲啓鍏ョ埗绫诲瓧娈�
+ for (const agg of siteAggMap.values()) {
+ let weightSw62 = 0;
+ let carbonSw62 = 0;
+ let salesSw62 = 0;
+ let timeSw62 = 0;
+ for (const suffix of SW62_SUB_SUFFIXES) {
+ weightSw62 += Number(agg[`weight${suffix}`]) || 0;
+ carbonSw62 += Number(agg[`carbon${suffix}`]) || 0;
+ salesSw62 += Number(agg[`estimatedSales${suffix}`]) || 0;
+ timeSw62 = Math.max(timeSw62, Number(agg[`time${suffix}`]) || 0);
+ }
+ agg.weightSw62 = weightSw62;
+ agg.carbonSw62 = carbonSw62;
+ agg.estimatedSalesSw62 = salesSw62;
+ agg.timeSw62 = timeSw62;
+ }
+
// 4. 楂樻�ц兘鍐欏叆锛氳浆鎹负鏁扮粍锛屽埄鐢ㄦ壒閲忔彃鍏� + ON DUPLICATE KEY UPDATE 鎻愪氦缁� MySQL
const finalRecords = Array.from(siteAggMap.values()).map(item => {
// 娴偣鏁伴槻绮惧害涓㈠け澶勭悊锛屼繚鐣欎袱浣嶅皬鏁�
--
Gitblit v1.9.1