Files
yunrui_asset/backend/models/Ticket.js
T
zhang1106 63f0cb570e refactor: 统一代码风格并迁移至 ESLint 新配置
style(backend): 格式化模型文件代码
style(frontend): 调整组件代码格式
chore: 删除旧 ESLint 配置并添加新配置
refactor(backend): 重构模型定义语法
style: 统一箭头函数和对象属性简写
2026-03-27 19:12:16 +08:00

139 lines
3.2 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;