From 2228dcebe2b847a59a4b23926afd95314719b92c Mon Sep 17 00:00:00 2001 From: zhang1106 <849185023@qq.com> Date: Fri, 26 Dec 2025 15:17:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20MySQL=20=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE=E9=A2=98=20-=20st?= =?UTF-8?q?rftime=20=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/db.js | 2 +- backend/routes/tickets.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/backend/db.js b/backend/db.js index ce1549a..11c8455 100644 --- a/backend/db.js +++ b/backend/db.js @@ -31,4 +31,4 @@ if (DB_TYPE === 'mysql') { }); } -module.exports = { sequelize }; \ No newline at end of file +module.exports = { sequelize, DB_TYPE }; \ No newline at end of file diff --git a/backend/routes/tickets.js b/backend/routes/tickets.js index 9a4a178..8fc8738 100644 --- a/backend/routes/tickets.js +++ b/backend/routes/tickets.js @@ -5,6 +5,7 @@ const { v4: uuidv4 } = require('uuid'); const { Ticket, TicketOperationRecord } = require('../models/ticketIndex'); const Device = require('../models/Device'); const User = require('../models/User'); +const { DB_TYPE } = require('../db'); // 获取工单统计 (必须定义在 /:ticketId 之前) router.get('/stats', async (req, res) => { @@ -50,7 +51,10 @@ router.get('/stats', async (req, res) => { const monthlyStats = await Ticket.findAll({ where, attributes: [ - [require('sequelize').fn('strftime', '%Y-%m', require('sequelize').col('createdAt')), 'month'], + [DB_TYPE === 'mysql' + ? require('sequelize').fn('DATE_FORMAT', require('sequelize').col('createdAt'), '%Y-%m') + : require('sequelize').fn('strftime', '%Y-%m', require('sequelize').col('createdAt')), + 'month'], [require('sequelize').fn('COUNT', '*'), 'count'] ], group: ['month'],