84 lines
3.1 KiB
Python
84 lines
3.1 KiB
Python
|
#!/usr/bin/env python
|
|||
|
# -*- coding: utf-8 -*-
|
|||
|
|
|||
|
"""
|
|||
|
任务输入参数模型模块
|
|||
|
包含任务输入参数相关的数据模型
|
|||
|
"""
|
|||
|
|
|||
|
import enum
|
|||
|
from sqlalchemy import Column, Integer, String, Text, Boolean, Enum, ForeignKey, JSON
|
|||
|
from sqlalchemy.orm import relationship
|
|||
|
from data.models.base import BaseModel
|
|||
|
|
|||
|
class InputParamType(enum.Enum):
|
|||
|
"""
|
|||
|
输入参数类型枚举
|
|||
|
"""
|
|||
|
STRING = 'string' # 字符串
|
|||
|
NUMBER = 'number' # 数字
|
|||
|
BOOLEAN = 'boolean' # 布尔值
|
|||
|
OBJECT = 'object' # 对象
|
|||
|
ARRAY = 'array' # 数组
|
|||
|
NULL = 'null' # 空值
|
|||
|
|
|||
|
class TaskInput(BaseModel):
|
|||
|
"""
|
|||
|
任务输入参数模型
|
|||
|
表示任务执行所需的输入参数
|
|||
|
"""
|
|||
|
__tablename__ = 'task_inputs'
|
|||
|
|
|||
|
task_id = Column(Integer, ForeignKey('tasks.id'), nullable=False, comment='任务ID')
|
|||
|
name = Column(String(100), nullable=False, comment='参数名称')
|
|||
|
param_type = Column(Enum(InputParamType), nullable=False, default=InputParamType.STRING, comment='参数类型')
|
|||
|
description = Column(String(500), nullable=True, comment='参数描述')
|
|||
|
is_required = Column(Boolean, default=False, comment='是否必填')
|
|||
|
default_value = Column(Text, nullable=True, comment='默认值')
|
|||
|
validation_rules = Column(JSON, nullable=True, comment='验证规则(JSON格式)')
|
|||
|
order = Column(Integer, default=0, comment='排序顺序')
|
|||
|
|
|||
|
def __repr__(self):
|
|||
|
return f"<TaskInput(id={self.id}, task_id={self.task_id}, name='{self.name}', type='{self.param_type}')>"
|
|||
|
|
|||
|
@classmethod
|
|||
|
def get_by_task(cls, task_id):
|
|||
|
"""
|
|||
|
获取任务的所有输入参数
|
|||
|
"""
|
|||
|
return cls.query.filter(cls.task_id == task_id, cls.is_deleted == False).order_by(cls.order).all()
|
|||
|
|
|||
|
@classmethod
|
|||
|
def get_by_task_and_name(cls, task_id, name):
|
|||
|
"""
|
|||
|
根据任务ID和参数名称获取输入参数
|
|||
|
"""
|
|||
|
return cls.query.filter(cls.task_id == task_id, cls.name == name, cls.is_deleted == False).first()
|
|||
|
|
|||
|
class TaskInputValue(BaseModel):
|
|||
|
"""
|
|||
|
任务输入参数值模型
|
|||
|
表示任务执行时的实际输入参数值
|
|||
|
"""
|
|||
|
__tablename__ = 'task_input_values'
|
|||
|
|
|||
|
task_record_id = Column(Integer, ForeignKey('task_records.id'), nullable=False, comment='任务记录ID')
|
|||
|
input_id = Column(Integer, ForeignKey('task_inputs.id'), nullable=False, comment='输入参数ID')
|
|||
|
value = Column(Text, nullable=True, comment='参数值')
|
|||
|
|
|||
|
def __repr__(self):
|
|||
|
return f"<TaskInputValue(id={self.id}, task_record_id={self.task_record_id}, input_id={self.input_id})>"
|
|||
|
|
|||
|
@classmethod
|
|||
|
def get_by_record(cls, task_record_id):
|
|||
|
"""
|
|||
|
获取任务记录的所有输入参数值
|
|||
|
"""
|
|||
|
return cls.query.filter(cls.task_record_id == task_record_id, cls.is_deleted == False).all()
|
|||
|
|
|||
|
@classmethod
|
|||
|
def get_by_record_and_input(cls, task_record_id, input_id):
|
|||
|
"""
|
|||
|
根据任务记录ID和输入参数ID获取输入参数值
|
|||
|
"""
|
|||
|
return cls.query.filter(cls.task_record_id == task_record_id, cls.input_id == input_id, cls.is_deleted == False).first()
|