From 98ce961272c596468a4cb4b2498a3c70048e4aed Mon Sep 17 00:00:00 2001
From: wangrong <wangrong@shsening.com>
Date: 星期四, 24 九月 2026 15:57:31 +0800
Subject: [PATCH] bug修复
---
src/modules/push/controller/admin/deviceonoff.ts | 2
src/modules/report/service/screen.ts | 175 +++++++++++++++++++++++-----------
src/modules/report/controller/admin/dailydepartment.ts | 4
src/modules/shop/service/transaction.ts | 9 +
src/modules/push/controller/admin/siteweight.ts | 6 +
src/modules/report/controller/admin/dailysite.ts | 4
src/modules/basicdata/controller/admin/wastetype.ts | 1
src/modules/report/controller/admin/dailyvehicle.ts | 4
src/modules/report/controller/admin/joblog.ts | 10 +
src/modules/push/controller/admin/weight.ts | 11 ++
src/modules/push/controller/admin/devicealarm.ts | 13 ++
src/modules/push/controller/admin/cameragps.ts | 5
src/modules/push/controller/admin/vehiclegps.ts | 5
13 files changed, 180 insertions(+), 69 deletions(-)
diff --git a/src/modules/basicdata/controller/admin/wastetype.ts b/src/modules/basicdata/controller/admin/wastetype.ts
index 9c70412..ff97d5a 100644
--- a/src/modules/basicdata/controller/admin/wastetype.ts
+++ b/src/modules/basicdata/controller/admin/wastetype.ts
@@ -10,6 +10,7 @@
entity: BasicdataWastetypeEntity,
service: BasicdataWastetypeService,
listQueryOp: {
+ fieldEq: ['a.status', 'a.isRecyclable'],
addOrderBy: {
'a.code': 'ASC',
},
diff --git a/src/modules/push/controller/admin/cameragps.ts b/src/modules/push/controller/admin/cameragps.ts
index 66cf769..6b7f721 100644
--- a/src/modules/push/controller/admin/cameragps.ts
+++ b/src/modules/push/controller/admin/cameragps.ts
@@ -14,8 +14,11 @@
keyWordLikeFields: ['a.sn'],
fieldEq: ['a.status'],
where: async (ctx) => {
- const { createDate, gpsTime } = ctx.request.body;
+ const { createDate, gpsTime, startTime, endTime } = ctx.request.body;
const condition:any[][] = [];
+ if (startTime && endTime) {
+ condition.push(['a.createDate BETWEEN :startTime AND :endTime', { startTime, endTime }]);
+ }
if (createDate && createDate.length === 2) {
condition.push(['a.createDate BETWEEN :createStartDate AND :createEndDate', { createStartDate: createDate[0], createEndDate: createDate[1] }]);
}
diff --git a/src/modules/push/controller/admin/devicealarm.ts b/src/modules/push/controller/admin/devicealarm.ts
index 27a6d0f..80758fd 100644
--- a/src/modules/push/controller/admin/devicealarm.ts
+++ b/src/modules/push/controller/admin/devicealarm.ts
@@ -33,12 +33,19 @@
],
fieldEq: [
{ column: 'a.devSerial', requestParam: 'devSerial' },
- { column: 'a.alarmType', requestParam: 'alarmType' },
- { column: 'c.name', requestParam: 'departmentName' }
+ { column: 'a.alarmType', requestParam: 'alarmType' }
],
fieldLike: [
{ column: 'c.name', requestParam: 'departmentName' }
- ]
+ ],
+ where: async ctx => {
+ const { startTime, endTime } = ctx.request.body;
+ const conditions: any[][] = [];
+ if (startTime && endTime) {
+ conditions.push(['a.alarmTime BETWEEN :startTime AND :endTime', { startTime, endTime }]);
+ }
+ return conditions;
+ }
}
})
export class AdminPushDevicealarmController extends BaseController {}
\ No newline at end of file
diff --git a/src/modules/push/controller/admin/deviceonoff.ts b/src/modules/push/controller/admin/deviceonoff.ts
index 833f934..3dae204 100644
--- a/src/modules/push/controller/admin/deviceonoff.ts
+++ b/src/modules/push/controller/admin/deviceonoff.ts
@@ -22,7 +22,7 @@
const condition = [];
if (startTime && endTime) {
condition.push([
- 'a.occurTime BETWEEN :startTime AND :endTime',
+ 'a.messageTime BETWEEN :startTime AND :endTime',
{ startTime, endTime }
]);
}
diff --git a/src/modules/push/controller/admin/siteweight.ts b/src/modules/push/controller/admin/siteweight.ts
index 3a27caa..9e16013 100644
--- a/src/modules/push/controller/admin/siteweight.ts
+++ b/src/modules/push/controller/admin/siteweight.ts
@@ -21,7 +21,7 @@
'd.businessName AS businessName', 'd.siteType AS siteType', // 鍨冨溇鍚嶇О
],
- fieldEq: ['a.deviceNo','d.siteType'],
+ fieldEq: ['d.siteType'],
fieldLike: ['a.deviceNo'],
join: [
{
@@ -44,7 +44,11 @@
},
],
where: async ctx => {
+ const { startTime, endTime } = ctx.request.body;
const conditions: any[][] = [];
+ if (startTime && endTime) {
+ conditions.push(['a.uploadTime BETWEEN :startTime AND :endTime', { startTime, endTime }]);
+ }
conditions.push(...(await WithDeptFilterWhere(ctx, { alias: 'a', field: 'departmentId' })));
// 鍏朵粬鍏宠仈琛紙涓句緥锛�
diff --git a/src/modules/push/controller/admin/vehiclegps.ts b/src/modules/push/controller/admin/vehiclegps.ts
index 3545e19..7f3c7de 100644
--- a/src/modules/push/controller/admin/vehiclegps.ts
+++ b/src/modules/push/controller/admin/vehiclegps.ts
@@ -25,8 +25,11 @@
},
],
where: async (ctx) => {
- const { createDate, gpsTime } = ctx.request.body;
+ const { createDate, gpsTime, startTime, endTime } = ctx.request.body;
const conditions: any[][] = [];
+ if (startTime && endTime) {
+ conditions.push(['a.gpsTime BETWEEN :startTime AND :endTime', { startTime, endTime }]);
+ }
if (createDate && createDate.length === 2) {
conditions.push(['a.createDate BETWEEN :createStartDate AND :createEndDate', { createStartDate: createDate[0], createEndDate: createDate[1] }]);
}
diff --git a/src/modules/push/controller/admin/weight.ts b/src/modules/push/controller/admin/weight.ts
index e617517..3fca2e5 100644
--- a/src/modules/push/controller/admin/weight.ts
+++ b/src/modules/push/controller/admin/weight.ts
@@ -1,6 +1,7 @@
import { CoolController, BaseController } from '@cool-midway/core';
import { PushWeightEntity } from '../../entity/weight';
import { PushWeightService } from '../../service/weight';
+import { BasicdataWastetypeEntity } from '../../../basicdata/entity/wastetype';
/**
* 鍘熷绉伴噸鏁版嵁绠$悊
@@ -10,8 +11,16 @@
entity: PushWeightEntity,
service: PushWeightService,
pageQueryOp: {
- select: ['a.*'],
+ select: ['a.*', 'b.name AS garbageName'],
fieldEq: ['a.deviceNo', 'a.garbageType'],
+ join: [
+ {
+ entity: BasicdataWastetypeEntity,
+ alias: 'b',
+ condition: 'a.garbageType = b.code',
+ type: 'leftJoin',
+ },
+ ],
where: async ctx => {
const { startTime, endTime } = ctx.request.body;
const conditions = [];
diff --git a/src/modules/report/controller/admin/dailydepartment.ts b/src/modules/report/controller/admin/dailydepartment.ts
index 1dbd914..054e7ad 100644
--- a/src/modules/report/controller/admin/dailydepartment.ts
+++ b/src/modules/report/controller/admin/dailydepartment.ts
@@ -14,7 +14,11 @@
keyWordLikeFields: ['a.departmentName'],
fieldEq: ['a.date', 'a.departmentId'],
where: async (ctx) => {
+ const { startTime, endTime } = ctx.request.body;
const conditions: any[][] = [];
+ if (startTime && endTime) {
+ conditions.push(['a.date BETWEEN :startTime AND :endTime', { startTime, endTime }]);
+ }
conditions.push(...(await WithDeptFilterWhere(ctx, { alias: 'a', field: 'departmentId' })));
return conditions;
}
diff --git a/src/modules/report/controller/admin/dailysite.ts b/src/modules/report/controller/admin/dailysite.ts
index 2907c7a..19881c0 100644
--- a/src/modules/report/controller/admin/dailysite.ts
+++ b/src/modules/report/controller/admin/dailysite.ts
@@ -25,7 +25,11 @@
],
where: async (ctx) => {
+ const { startTime, endTime } = ctx.request.body;
const conditions: any[][] = [];
+ if (startTime && endTime) {
+ conditions.push(['a.date BETWEEN :startTime AND :endTime', { startTime, endTime }]);
+ }
conditions.push(...(await WithDeptFilterWhere(ctx, { alias: 'a', field: 'departmentId' })));
return conditions;
}
diff --git a/src/modules/report/controller/admin/dailyvehicle.ts b/src/modules/report/controller/admin/dailyvehicle.ts
index 95c5e7c..824989c 100644
--- a/src/modules/report/controller/admin/dailyvehicle.ts
+++ b/src/modules/report/controller/admin/dailyvehicle.ts
@@ -25,7 +25,11 @@
],
where: async (ctx) => {
+ const { startTime, endTime } = ctx.request.body;
const conditions: any[][] = [];
+ if (startTime && endTime) {
+ conditions.push(['a.date BETWEEN :startTime AND :endTime', { startTime, endTime }]);
+ }
conditions.push(...(await WithDeptFilterWhere(ctx, { alias: 'a', field: 'departmentId' })));
return conditions;
}
diff --git a/src/modules/report/controller/admin/joblog.ts b/src/modules/report/controller/admin/joblog.ts
index c6339e5..3336b66 100644
--- a/src/modules/report/controller/admin/joblog.ts
+++ b/src/modules/report/controller/admin/joblog.ts
@@ -11,7 +11,15 @@
service: ReportJoblogService,
pageQueryOp: {
keyWordLikeFields: ['a.jobName'],
- fieldEq: ['a.dataDate', 'a.status']
+ fieldEq: ['a.dataDate', 'a.status'],
+ where: async ctx => {
+ const { startTime, endTime } = ctx.request.body;
+ const conditions: any[][] = [];
+ if (startTime && endTime) {
+ conditions.push(['a.dataDate BETWEEN :startTime AND :endTime', { startTime, endTime }]);
+ }
+ return conditions;
+ }
}
})
export class AdminReportJoblogController extends BaseController {}
\ No newline at end of file
diff --git a/src/modules/report/service/screen.ts b/src/modules/report/service/screen.ts
index 9e42234..c3ba06b 100644
--- a/src/modules/report/service/screen.ts
+++ b/src/modules/report/service/screen.ts
@@ -28,6 +28,30 @@
const ITEM_COLORS = ['#3b82f6', '#22c55e', '#f59e0b', '#a855f7', '#06b6d4', '#ef4444', '#94a3b8'];
+/** 鏃ヨ〃鍒椾笌鍨冨溇绉嶇被缂栫爜銆傞椤靛垎绫荤粺璁″彧绱姞鍏朵腑鐘舵�佷负鍚敤鐨勭紪鐮併�� */
+const WASTE_FIELDS: {
+ code: string;
+ weight: string;
+ carbon: string;
+ time: string;
+ sales?: string;
+ group?: 'recyclable' | 'bulk' | 'elec' | 'fabric';
+}[] = [
+ { code: 'SW60', weight: 'weightSw60', carbon: 'carbonSw60', time: 'timeSw60' },
+ { code: 'SW61', weight: 'weightSw61', carbon: 'carbonSw61', time: 'timeSw61' },
+ { code: 'SW62', weight: 'weightSw62', carbon: 'carbonSw62', time: 'timeSw62', sales: 'estimatedSalesSw62', group: 'recyclable' },
+ { code: 'SW63', weight: 'weightSw63', carbon: 'carbonSw63', time: 'timeSw63', group: 'bulk' },
+ { code: 'SW64', weight: 'weightSw64', carbon: 'carbonSw64', time: 'timeSw64' },
+ ...['001', '002', '003', '004', '005', '006', '007'].map(idx => ({
+ code: `SW62${idx}`,
+ weight: `weightSw62${idx}`,
+ carbon: `carbonSw62${idx}`,
+ time: `timeSw62${idx}`,
+ sales: `estimatedSalesSw62${idx}`,
+ group: (idx === '006' ? 'elec' : idx === '004' ? 'fabric' : undefined) as 'elec' | 'fabric' | undefined,
+ })),
+];
+
type OrdersByType = {
axis: string[];
'鐜板満鍥炴敹': number[];
@@ -119,15 +143,23 @@
safe('骞村害绔欑偣鏃ユ眹鎬�', () => this.sumSite(yearStart, yearEnd), emptySum),
]);
- const wasteNames = await safe('鍨冨溇绉嶇被鍚嶇О', () => this.wasteNameMap(), new Map<string, string>());
- const wasteMix = this.buildWasteMix(period, wasteNames);
- const recycleItems = this.buildRecycleItems(period, wasteNames);
+ const enabledWaste = await safe(
+ '鍚敤鍨冨溇绉嶇被',
+ () => this.enabledWaste(),
+ { names: new Map<string, string>(), codes: new Set<string>() }
+ );
+ const wasteMix = this.buildWasteMix(period, enabledWaste);
+ const recycleItems = this.buildRecycleItems(period, enabledWaste);
const { axis, trend } = await safe(
'鍥炴敹瓒嬪娍',
- () => this.buildTrend(range || 'month', dates),
+ () => this.buildTrend(range || 'month', dates, enabledWaste.codes),
{ axis: [], trend: { weight: [], value: [], carbon: [] } }
);
- const yearCarbon = await safe('骞村害纰冲噺鎺�', () => this.buildYearCarbon(), Array.from({ length: 12 }, () => 0));
+ const yearCarbon = await safe(
+ '骞村害纰冲噺鎺�',
+ () => this.buildYearCarbon(enabledWaste.codes),
+ Array.from({ length: 12 }, () => 0)
+ );
const ranks = await safe(
'鐝骇/涓撲笟/闄㈢郴鎺掕',
() => this.buildOrgRanks(dates.startTime, dates.endTime, unavailable),
@@ -176,30 +208,30 @@
sites: [],
});
- const weightKg = n(period.weightTotal);
- const recyclableKg = n(period.weightSw62);
- const carbonKg = n(period.carbonTotal);
- const totalCarbonKg = n(totalRow.carbonTotal);
+ const periodStat = this.statEnabled(period, enabledWaste.codes);
+ const todayStat = this.statEnabled(todayRow, enabledWaste.codes);
+ const totalStat = this.statEnabled(totalRow, enabledWaste.codes);
+ const yearStat = this.statEnabled(yearRow, enabledWaste.codes);
return {
range: range || 'month',
axis,
kpis: {
- todayWeightKg: round(n(todayRow.weightTotal), 1),
- periodWeightTon: round(weightKg / 1000, 2),
- resourceRate: weightKg > 0 ? round((recyclableKg / weightKg) * 100, 1) : 0,
- periodValue: round(n(period.estimatedSalesSw62), 0),
- periodCarbonTon: round(carbonKg / 1000, 2),
- totalWeightTon: round(n(totalRow.weightTotal) / 1000, 1),
+ todayWeightKg: round(todayStat.weight, 1),
+ periodWeightTon: round(periodStat.weight / 1000, 2),
+ resourceRate: periodStat.weight > 0 ? round((periodStat.recyclable / periodStat.weight) * 100, 1) : 0,
+ periodValue: round(periodStat.sales, 0),
+ periodCarbonTon: round(periodStat.carbon / 1000, 2),
+ totalWeightTon: round(totalStat.weight / 1000, 1),
totalParticipants: users.totalParticipants,
totalPoints: users.balance,
- recyclableTon: round(recyclableKg / 1000, 2),
- bulkTon: round(n(period.weightSw63) / 1000, 2),
- elecTon: round(n(period.weightSw62006) / 1000, 2),
- fabricTon: round(n(period.weightSw62004) / 1000, 2),
- yearCarbonTon: round(n(yearRow.carbonTotal) / 1000, 1),
- monthCarbonTon: round(carbonKg / 1000, 2),
- totalCarbonTon: round(totalCarbonKg / 1000, 1),
+ recyclableTon: round(periodStat.recyclable / 1000, 2),
+ bulkTon: round(periodStat.bulk / 1000, 2),
+ elecTon: round(periodStat.elec / 1000, 2),
+ fabricTon: round(periodStat.fabric / 1000, 2),
+ yearCarbonTon: round(yearStat.carbon / 1000, 1),
+ monthCarbonTon: round(periodStat.carbon / 1000, 2),
+ totalCarbonTon: round(totalStat.carbon / 1000, 1),
greenActions: users.greenActions,
newParticipants: users.newParticipants,
participateRate: users.participateRate,
@@ -339,23 +371,57 @@
return (await qb.getRawOne()) || {};
}
- private async wasteNameMap() {
- const list = await this.wasteTypeRepo.find({ select: ['code', 'name'] });
- const map = new Map<string, string>();
- list.forEach(e => map.set(String(e.code).toUpperCase(), e.name));
- return map;
+ private async enabledWaste() {
+ const list = await this.wasteTypeRepo.find({
+ where: { status: 1 },
+ select: ['code', 'name'],
+ });
+ 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);
+ });
+ return { names, codes };
}
- private buildWasteMix(row: any, names: Map<string, string>) {
+ /** 鍙疮鍔犲惎鐢ㄧ绫诲搴旂殑鏃ヨ〃鍒楋紝閬垮厤绂佺敤绉嶇被杩涘叆閲嶉噺銆佺⒊鎺掑拰閿�鍞銆� */
+ private statEnabled(row: any, codes: Set<string>) {
+ const on = WASTE_FIELDS.filter(f => codes.has(f.code));
+ const sum = (pick: (f: (typeof WASTE_FIELDS)[number]) => string | undefined) =>
+ on.reduce((s, f) => s + n(row?.[pick(f)]), 0);
+ const ofGroup = (group: 'recyclable' | 'bulk' | 'elec' | 'fabric') =>
+ on.filter(f => f.group === group).reduce((s, f) => s + n(row?.[f.weight]), 0);
+ return {
+ weight: sum(f => f.weight),
+ carbon: sum(f => f.carbon),
+ sales: sum(f => f.sales),
+ recyclable: ofGroup('recyclable'),
+ bulk: ofGroup('bulk'),
+ elec: ofGroup('elec'),
+ fabric: ofGroup('fabric'),
+ };
+ }
+
+ private enabledExpr(codes: Set<string>, pick: (f: (typeof WASTE_FIELDS)[number]) => string | undefined) {
+ const cols = WASTE_FIELDS.filter(f => codes.has(f.code))
+ .map(pick)
+ .filter((col): col is string => !!col);
+ if (!cols.length) return '0';
+ return cols.map(col => `IFNULL(a.${col},0)`).join(' + ');
+ }
+
+ private buildWasteMix(row: any, waste: { names: Map<string, string>; codes: Set<string> }) {
const items = [
{ code: 'SW62', key: 'Sw62' },
{ code: 'SW64', key: 'Sw64' },
{ code: 'SW63', key: 'Sw63' },
{ code: 'SW61', key: 'Sw61' },
{ code: 'SW60', key: 'Sw60' },
- ];
+ ].filter(e => waste.codes.has(e.code));
return items.map(e => ({
- name: names.get(e.code) || this.defaultWasteName(e.code),
+ name: waste.names.get(e.code) || this.defaultWasteName(e.code),
code: e.code,
weight: round(n(row[`weight${e.key}`]), 1),
value: e.code === 'SW62' ? round(n(row.estimatedSalesSw62), 0) : 0,
@@ -376,31 +442,26 @@
);
}
- private buildRecycleItems(row: any, names: Map<string, string>) {
- const codes = [
- '900-001-S62',
- '900-002-S62',
- '900-003-S62',
- '900-004-S62',
- '900-005-S62',
- '900-006-S62',
- '900-007-S62',
- ];
+ private buildRecycleItems(row: any, waste: { names: Map<string, string>; codes: Set<string> }) {
const fallback = ['搴熺焊', '濉戞枡', '閲戝睘', '缁囩墿', '鐜荤拑', '鐢靛瓙浜у搧', '鍏朵粬鍙洖鏀�'];
- return codes.map((code, i) => {
- const idx = String(i + 1).padStart(3, '0');
- return {
- name: names.get(code.toUpperCase()) || names.get(code) || fallback[i],
- code,
- weight: round(n(row[`weightSw62${idx}`]), 1),
- value: round(n(row[`estimatedSalesSw62${idx}`]), 0),
- carbon: round(n(row[`carbonSw62${idx}`]), 1),
- color: ITEM_COLORS[i],
- };
- });
+ 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,
+ weight: round(n(row[`weightSw62${e.idx}`]), 1),
+ value: round(n(row[`estimatedSalesSw62${e.idx}`]), 0),
+ carbon: round(n(row[`carbonSw62${e.idx}`]), 1),
+ color: ITEM_COLORS[e.i],
+ }));
}
- private async buildTrend(range: string, dates: { start: string; end: string; startTime: string; endTime: string }) {
+ private async buildTrend(
+ range: string,
+ dates: { start: string; end: string; startTime: string; endTime: string },
+ codes: Set<string>
+ ) {
const trendStart =
range === 'today' ? moment().subtract(6, 'day').format('YYYY-MM-DD') : dates.start;
const trendEnd = dates.end;
@@ -408,9 +469,9 @@
const qb = this.dailySite
.createQueryBuilder('a')
.select('a.date', 'date')
- .addSelect('SUM(a.weightTotal)', 'weight')
- .addSelect('SUM(a.estimatedSalesSw62)', 'value')
- .addSelect('SUM(a.carbonTotal)', 'carbon')
+ .addSelect(`SUM(${this.enabledExpr(codes, f => f.weight)})`, 'weight')
+ .addSelect(`SUM(${this.enabledExpr(codes, f => f.sales)})`, 'value')
+ .addSelect(`SUM(${this.enabledExpr(codes, f => f.carbon)})`, 'carbon')
.where('a.date BETWEEN :start AND :end', { start: trendStart, end: trendEnd })
.groupBy('a.date')
.orderBy('a.date', 'ASC');
@@ -463,13 +524,13 @@
return { axis, trend: { weight, value, carbon } };
}
- private async buildYearCarbon() {
+ private async buildYearCarbon(codes: Set<string>) {
const start = moment().startOf('year').format('YYYY-MM-DD');
const end = moment().endOf('year').format('YYYY-MM-DD');
const qb = this.dailySite
.createQueryBuilder('a')
.select('MONTH(a.date)', 'm')
- .addSelect('SUM(a.carbonTotal)', 'carbon')
+ .addSelect(`SUM(${this.enabledExpr(codes, f => f.carbon)})`, 'carbon')
.where('a.date BETWEEN :start AND :end', { start, end })
.groupBy('MONTH(a.date)');
this.applyDept(qb, 'a');
diff --git a/src/modules/shop/service/transaction.ts b/src/modules/shop/service/transaction.ts
index 26639b5..2f342f2 100644
--- a/src/modules/shop/service/transaction.ts
+++ b/src/modules/shop/service/transaction.ts
@@ -19,7 +19,12 @@
/**
* App 绔垎椤碉細杞禒 tab 鍙湅璧犻��/鎺ュ彈锛屾敹鏀� tab 鐪嬪叾浣欑被鍨�
*/
- async page(query: any) {
+ async page(query: any, option?: any, connectionName?: any) {
+ // 绠$悊绔垪琛ㄤ笉甯� tab锛岃蛋閫氱敤鍒嗛〉锛屾绱㈡潯浠剁敱 pageQueryOp 鐢熸晥
+ if (!query?.tab) {
+ return super.page(query, option, connectionName);
+ }
+
const { userId, tab, page = 1, size = 10 } = query || {};
const find = this.recycleTransactionEntity.createQueryBuilder('a');
@@ -41,8 +46,6 @@
find.orderBy('a.createTime', 'DESC');
find.addOrderBy('a.id', 'DESC');
-
- console.log(find)
return this.entityRenderPage(find, { ...query, page, size }, false);
}
--
Gitblit v1.9.1