feat: 添加工单统计自动刷新功能并优化设备选择逻辑
refactor(工单管理): 重构设备选择表单并优化UI体验 fix(工单统计): 修复每日完成工单统计不准确的问题 perf(后端): 添加批量导出接口优化大数据量查询性能 chore: 添加react-transition-group依赖支持动画效果 feat(设备管理): 添加设备全量查询接口支持导出功能 style(工单管理): 优化表单布局和样式提升用户体验 refactor(工单字段): 优化字段管理组件处理空值情况 fix(机柜管理): 修复机柜列表查询接口参数问题 docs: 移除不再使用的工单字段管理页面
This commit is contained in:
@@ -60,6 +60,55 @@ router.get('/', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
const MAX_EXPORT_SIZE = 50000;
|
||||
|
||||
router.get('/export', async (req, res) => {
|
||||
try {
|
||||
const { keyword, category, status } = req.query;
|
||||
|
||||
const where = {};
|
||||
|
||||
if (keyword) {
|
||||
where[Op.or] = [
|
||||
{ consumableId: { [Op.like]: `%${keyword}%` } },
|
||||
{ name: { [Op.like]: `%${keyword}%` } },
|
||||
{ category: { [Op.like]: `%${keyword}%` } },
|
||||
{ supplier: { [Op.like]: `%${keyword}%` } },
|
||||
{ location: { [Op.like]: `%${keyword}%` } }
|
||||
];
|
||||
}
|
||||
|
||||
if (category && category !== 'all') {
|
||||
where.category = category;
|
||||
}
|
||||
|
||||
if (status && status !== 'all') {
|
||||
where.status = status;
|
||||
}
|
||||
|
||||
const consumables = await Consumable.findAll({
|
||||
where,
|
||||
limit: MAX_EXPORT_SIZE,
|
||||
order: [['createdAt', 'DESC']]
|
||||
});
|
||||
|
||||
const result = consumables.map(item => {
|
||||
const data = item.toJSON();
|
||||
if (!Array.isArray(data.snList)) {
|
||||
data.snList = [];
|
||||
}
|
||||
return data;
|
||||
});
|
||||
|
||||
res.json({
|
||||
consumables: result,
|
||||
total: result.length
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', async (req, res) => {
|
||||
const transaction = await sequelize.transaction();
|
||||
try {
|
||||
|
||||
@@ -584,6 +584,67 @@ router.get('/', validateQuery(queryDeviceSchema), async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
const MAX_EXPORT_SIZE = 50000;
|
||||
|
||||
router.get('/all', async (req, res) => {
|
||||
try {
|
||||
const { keyword, status, type, rackId, roomId } = req.query;
|
||||
|
||||
const where = {};
|
||||
|
||||
if (keyword) {
|
||||
const escapedKeyword = keyword.replace(/'/g, "''");
|
||||
where[Op.or] = [
|
||||
{ deviceId: { [Op.like]: `%${escapedKeyword}%` } },
|
||||
{ name: { [Op.like]: `%${escapedKeyword}%` } },
|
||||
{ type: { [Op.like]: `%${escapedKeyword}%` } },
|
||||
{ model: { [Op.like]: `%${escapedKeyword}%` } },
|
||||
{ serialNumber: { [Op.like]: `%${escapedKeyword}%` } },
|
||||
{ ipAddress: { [Op.like]: `%${escapedKeyword}%` } }
|
||||
];
|
||||
}
|
||||
|
||||
if (status && status !== 'all') {
|
||||
where.status = status;
|
||||
}
|
||||
|
||||
if (type && type !== 'all') {
|
||||
where.type = type;
|
||||
}
|
||||
|
||||
if (rackId) {
|
||||
where.rackId = rackId;
|
||||
}
|
||||
|
||||
if (roomId && roomId !== 'all') {
|
||||
where['$Rack.roomId$'] = roomId;
|
||||
}
|
||||
|
||||
const devices = await Device.findAll({
|
||||
where,
|
||||
include: [
|
||||
{
|
||||
model: Rack,
|
||||
include: [{ model: Room }],
|
||||
separate: false
|
||||
}
|
||||
],
|
||||
limit: MAX_EXPORT_SIZE,
|
||||
order: [['createdAt', 'DESC']],
|
||||
distinct: true,
|
||||
subQuery: false
|
||||
});
|
||||
|
||||
res.json({
|
||||
devices,
|
||||
total: devices.length
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('获取设备列表失败:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// 生成设备ID的辅助函数
|
||||
async function generateDeviceId() {
|
||||
// 获取当前最大的设备ID序号
|
||||
|
||||
@@ -79,6 +79,59 @@ router.get('/', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
const MAX_EXPORT_SIZE = 50000;
|
||||
|
||||
router.get('/all', async (req, res) => {
|
||||
try {
|
||||
const { roomId, status, keyword } = req.query;
|
||||
|
||||
const where = {};
|
||||
if (roomId && roomId !== 'all') {
|
||||
where.roomId = roomId;
|
||||
}
|
||||
if (status && status !== 'all') {
|
||||
where.status = status;
|
||||
}
|
||||
if (keyword) {
|
||||
where[require('sequelize').Op.or] = [
|
||||
{ rackId: { [require('sequelize').Op.like]: `%${keyword}%` } },
|
||||
{ name: { [require('sequelize').Op.like]: `%${keyword}%` } }
|
||||
];
|
||||
}
|
||||
|
||||
const racks = await Rack.findAll({
|
||||
where,
|
||||
include: [{ model: Room, separate: false }],
|
||||
limit: MAX_EXPORT_SIZE
|
||||
});
|
||||
|
||||
const rackIds = racks.map(r => r.rackId);
|
||||
const devices = await Device.findAll({
|
||||
where: { rackId: rackIds },
|
||||
attributes: ['deviceId', 'rackId', 'name', 'powerConsumption', 'height']
|
||||
});
|
||||
|
||||
const deviceMap = {};
|
||||
devices.forEach(d => {
|
||||
if (!deviceMap[d.rackId]) {
|
||||
deviceMap[d.rackId] = [];
|
||||
}
|
||||
deviceMap[d.rackId].push(d);
|
||||
});
|
||||
|
||||
racks.forEach(rack => {
|
||||
rack.dataValues.Devices = deviceMap[rack.rackId] || [];
|
||||
});
|
||||
|
||||
res.json({
|
||||
racks,
|
||||
total: racks.length
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
});
|
||||
|
||||
// 导出机柜导入模板 - 必须放在 /:rackId 路由之前,避免被当作 rackId 参数
|
||||
router.get('/import-template', async (req, res) => {
|
||||
try {
|
||||
|
||||
@@ -23,7 +23,7 @@ router.get('/stats', async (req, res) => {
|
||||
|
||||
const Sequelize = require('sequelize');
|
||||
|
||||
const [total, statusStats, priorityStats, categoryStats, monthlyStats, deviceStats, dailyStats] = await Promise.all([
|
||||
const [total, statusStats, priorityStats, categoryStats, monthlyStats, deviceStats, dailyCreatedStats, dailyCompletedStats] = await Promise.all([
|
||||
Ticket.count({ where }),
|
||||
Ticket.findAll({
|
||||
where,
|
||||
@@ -68,11 +68,29 @@ router.get('/stats', async (req, res) => {
|
||||
Ticket.findAll({
|
||||
where,
|
||||
attributes: [
|
||||
[Sequelize.fn('DATE', Sequelize.col('createdAt')), 'date'],
|
||||
[dbDialect === 'mysql'
|
||||
? Sequelize.fn('DATE_FORMAT', Sequelize.col('createdAt'), '%Y-%m-%d')
|
||||
: Sequelize.fn('date', Sequelize.col('createdAt')),
|
||||
'date'],
|
||||
[Sequelize.fn('COUNT', '*'), 'created']
|
||||
],
|
||||
group: ['date'],
|
||||
order: [['date', 'ASC']]
|
||||
}),
|
||||
Ticket.findAll({
|
||||
where: {
|
||||
...where,
|
||||
status: 'completed'
|
||||
},
|
||||
attributes: [
|
||||
[dbDialect === 'mysql'
|
||||
? Sequelize.fn('DATE_FORMAT', Sequelize.col('updatedAt'), '%Y-%m-%d')
|
||||
: Sequelize.fn('date', Sequelize.col('updatedAt')),
|
||||
'date'],
|
||||
[Sequelize.fn('COUNT', '*'), 'completed']
|
||||
],
|
||||
group: ['date'],
|
||||
order: [['date', 'ASC']]
|
||||
})
|
||||
]);
|
||||
|
||||
@@ -110,16 +128,42 @@ router.get('/stats', async (req, res) => {
|
||||
deviceType: ''
|
||||
}));
|
||||
|
||||
const trend = dailyStats.map(d => ({
|
||||
date: d.dataValues.date,
|
||||
created: d.dataValues.created,
|
||||
completed: 0,
|
||||
const createdMap = {};
|
||||
dailyCreatedStats.forEach(d => {
|
||||
createdMap[d.dataValues.date] = d.dataValues.created;
|
||||
});
|
||||
const completedMap = {};
|
||||
dailyCompletedStats.forEach(d => {
|
||||
completedMap[d.dataValues.date] = d.dataValues.completed;
|
||||
});
|
||||
|
||||
const allDates = [...new Set([...Object.keys(createdMap), ...Object.keys(completedMap)])].sort();
|
||||
const trend = allDates.map(date => ({
|
||||
date,
|
||||
created: createdMap[date] || 0,
|
||||
completed: completedMap[date] || 0,
|
||||
closed: 0,
|
||||
inProgress: 0,
|
||||
pending: 0
|
||||
}));
|
||||
|
||||
const avgProcessingTime = 0;
|
||||
const completedTickets = await Ticket.findAll({
|
||||
where: {
|
||||
...where,
|
||||
status: 'completed'
|
||||
},
|
||||
attributes: ['createdAt', 'updatedAt']
|
||||
});
|
||||
|
||||
let avgProcessingTime = 0;
|
||||
if (completedTickets.length > 0) {
|
||||
const totalProcessingTime = completedTickets.reduce((sum, ticket) => {
|
||||
const created = new Date(ticket.createdAt);
|
||||
const updated = new Date(ticket.updatedAt);
|
||||
return sum + (updated - created);
|
||||
}, 0);
|
||||
avgProcessingTime = (totalProcessingTime / completedTickets.length / (1000 * 60 * 60)).toFixed(1);
|
||||
}
|
||||
|
||||
res.json({
|
||||
total,
|
||||
@@ -127,7 +171,7 @@ router.get('/stats', async (req, res) => {
|
||||
inProgress,
|
||||
completed,
|
||||
closed,
|
||||
avgProcessingTime,
|
||||
avgProcessingTime: parseFloat(avgProcessingTime),
|
||||
byStatus,
|
||||
byPriority,
|
||||
byCategory,
|
||||
|
||||
Reference in New Issue
Block a user