From 22c5f37a587bfb3363534fed05647faf5f93c8fe Mon Sep 17 00:00:00 2001
From: wangrong <wangrong@shsening.com>
Date: 星期六, 26 九月 2026 11:42:42 +0800
Subject: [PATCH] 修改首页显示和统计任务
---
src/config/config.local.ts | 4 +-
src/modules/report/service/screen.ts | 13 ++++--
src/modules/report/service/taskservicesite.ts | 47 ++++++++++++++++++++---
src/config/config.prod.ts | 4 +-
4 files changed, 52 insertions(+), 16 deletions(-)
diff --git a/src/config/config.local.ts b/src/config/config.local.ts
index 15f8f75..4ac7f25 100644
--- a/src/config/config.local.ts
+++ b/src/config/config.local.ts
@@ -15,10 +15,10 @@
default: {
type: 'mysql',
host: '127.0.0.1',
- port: 8806,
+ port: 3306,
username: 'womp',
password: 'Sening@2023',
- database: 'womp-shop',
+ database: 'womp_shop',
// 鑷姩寤鸿〃 娉ㄦ剰锛氱嚎涓婇儴缃茬殑鏃跺�欎笉瑕佷娇鐢紝鏈夊彲鑳藉鑷存暟鎹涪澶�
synchronize: false,
// 鎵撳嵃鏃ュ織
diff --git a/src/config/config.prod.ts b/src/config/config.prod.ts
index c2bd76a..19da1e4 100644
--- a/src/config/config.prod.ts
+++ b/src/config/config.prod.ts
@@ -27,10 +27,10 @@
default: {
type: 'mysql',
host: '127.0.0.1',
- port: 8806,
+ port: 3306,
username: 'womp',
password: 'Sening@2023',
- database: 'womp-shop',
+ database: 'womp_shop',
// 鑷姩寤鸿〃 娉ㄦ剰锛氱嚎涓婇儴缃茬殑鏃跺�欎笉瑕佷娇鐢紝鏈夊彲鑳藉鑷存暟鎹涪澶�
synchronize: false,
// 鎵撳嵃鏃ュ織
diff --git a/src/modules/report/service/screen.ts b/src/modules/report/service/screen.ts
index c3ba06b..3f1ab70 100644
--- a/src/modules/report/service/screen.ts
+++ b/src/modules/report/service/screen.ts
@@ -371,17 +371,19 @@
return (await qb.getRawOne()) || {};
}
+ /** 鍚嶇О鍙栧叏閮ㄧ绫伙紱codes 浠嶅彧鍚惎鐢ㄩ」锛屼緵 KPI/瓒嬪娍娌跨敤鍘熷彛寰勩�傚垎绫诲浘涓嶅啀鐢� codes 杩囨护銆� */
private async enabledWaste() {
const list = await this.wasteTypeRepo.find({
- where: { status: 1 },
- select: ['code', 'name'],
+ select: ['code', 'name', 'status'],
});
const names = new Map<string, string>();
const codes = new Set<string>();
list.forEach(e => {
const code = String(e.code).toUpperCase();
- codes.add(code);
names.set(code, e.name);
+ if (Number(e.status) === 1) {
+ codes.add(code);
+ }
});
return { names, codes };
}
@@ -412,6 +414,7 @@
return cols.map(col => `IFNULL(a.${col},0)`).join(' + ');
}
+ /** 棣栭〉鍒嗙被鍏ㄩ噺杩斿洖锛屼笉鎸夌绫诲惎鐢ㄧ姸鎬佽鍓紱0 鍊肩敱鍓嶇鍥捐〃闅愯棌銆� */
private buildWasteMix(row: any, waste: { names: Map<string, string>; codes: Set<string> }) {
const items = [
{ code: 'SW62', key: 'Sw62' },
@@ -419,7 +422,7 @@
{ code: 'SW63', key: 'Sw63' },
{ code: 'SW61', key: 'Sw61' },
{ code: 'SW60', key: 'Sw60' },
- ].filter(e => waste.codes.has(e.code));
+ ];
return items.map(e => ({
name: waste.names.get(e.code) || this.defaultWasteName(e.code),
code: e.code,
@@ -442,11 +445,11 @@
);
}
+ /** 鍙洖鏀� 7 瀛愮被鍏ㄩ噺杩斿洖锛涚⒊鍊间繚鐣欑鍙凤紙鍑忔帓鍙负璐燂級锛屽浘琛ㄤ晶鍙栫粷瀵瑰�煎睍绀恒�� */
private buildRecycleItems(row: any, waste: { names: Map<string, string>; codes: Set<string> }) {
const fallback = ['搴熺焊', '濉戞枡', '閲戝睘', '缁囩墿', '鐜荤拑', '鐢靛瓙浜у搧', '鍏朵粬鍙洖鏀�'];
return ['001', '002', '003', '004', '005', '006', '007']
.map((idx, i) => ({ idx, i, code: `SW62${idx}` }))
- .filter(e => waste.codes.has(e.code))
.map(e => ({
name: waste.names.get(e.code) || fallback[e.i],
code: e.code,
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