Files
yunrui_asset/backend/models/Ticket.js
T
zhang1106 a7499de748 feat(系统设置): 新增系统设置模块
- 添加SystemSetting模型用于存储系统配置
- 实现系统设置API路由,支持CRUD操作
- 新增系统设置前端页面,包含全局配置、外观设置、数据备份和关于页面
- 设备批量操作增强,支持批量移动、状态变更和导出
- 工单模型允许deviceId为空
2025-12-29 16:10:42 +08:00

135 lines
2.9 KiB
JavaScript

const { DataTypes } = require('sequelize');
const { sequelize } = require('../db');
const User = require('./User');
const Device = require('./Device');
const Ticket = sequelize.define('Ticket', {
ticketId: {
type: DataTypes.STRING,
primaryKey: true,
allowNull: false,
unique: true
},
title: {
type: DataTypes.STRING,
allowNull: false,
comment: '工单标题'
},
deviceId: {
type: DataTypes.STRING,
allowNull: true,
comment: '关联设备ID'
},
deviceName: {
type: DataTypes.STRING,
allowNull: false,
comment: '设备名称'
},
deviceModel: {
type: DataTypes.STRING,
comment: '设备型号'
},
serialNumber: {
type: DataTypes.STRING,
comment: '设备序列号'
},
faultCategory: {
type: DataTypes.STRING,
allowNull: false,
comment: '故障分类'
},
faultSubCategory: {
type: DataTypes.STRING,
comment: '故障子分类'
},
priority: {
type: DataTypes.STRING,
defaultValue: 'medium',
comment: '优先级: critical/high/medium/low'
},
status: {
type: DataTypes.STRING,
defaultValue: 'pending',
comment: '工单状态: pending/in_progress/completed/closed/cancelled'
},
description: {
type: DataTypes.TEXT,
comment: '故障描述'
},
expectedCompletionDate: {
type: DataTypes.DATE,
comment: '期望完成时间'
},
reporterId: {
type: DataTypes.STRING,
allowNull: false,
comment: '报修人ID'
},
reporterName: {
type: DataTypes.STRING,
allowNull: false,
comment: '报修人姓名'
},
assigneeId: {
type: DataTypes.STRING,
comment: '处理人ID'
},
assigneeName: {
type: DataTypes.STRING,
comment: '处理人姓名'
},
location: {
type: DataTypes.STRING,
comment: '设备位置'
},
resolution: {
type: DataTypes.TEXT,
comment: '解决方案'
},
completionDate: {
type: DataTypes.DATE,
comment: '实际完成时间'
},
evaluation: {
type: DataTypes.TEXT,
comment: '用户评价'
},
evaluationRating: {
type: DataTypes.INTEGER,
comment: '评价星级(1-5)'
},
attachments: {
type: DataTypes.JSON,
defaultValue: [],
comment: '附件列表'
},
tags: {
type: DataTypes.JSON,
defaultValue: [],
comment: '标签'
},
metadata: {
type: DataTypes.JSON,
defaultValue: {},
comment: '扩展字段'
}
}, {
tableName: 'tickets',
timestamps: true,
indexes: [
{ fields: ['deviceId'] },
{ fields: ['status'] },
{ fields: ['faultCategory'] },
{ fields: ['priority'] },
{ fields: ['reporterId'] },
{ fields: ['assigneeId'] },
{ fields: ['createdAt'] }
]
});
Ticket.belongsTo(User, { foreignKey: 'reporterId', as: 'reporter', constraints: false });
Ticket.belongsTo(User, { foreignKey: 'assigneeId', as: 'assignee', constraints: false });
Ticket.belongsTo(Device, { foreignKey: 'deviceId', constraints: false });
module.exports = Ticket;