Exemplo n.º 1
0
class AssetsDict(db.Model, BaseMix):
    """字典表."""
    __tablename__ = 'assets_dict'
    name = db.Column(db.String(80),
                     nullable=False,
                     comment="资产名 ex: 联想X1, 仓库, 未受理")
    code = db.Column(db.String(40),
                     nullable=True,
                     comment="资产编码 ex: DZSB-171101, 722, W")
    pre_type = db.Column(db.String(80),
                         default='',
                         nullable=True,
                         comment="大类 ex: 电子设备,存放位置,设备状态,申请状态")
    type_ = db.Column(db.String(80),
                      default='',
                      nullable=True,
                      comment="类型 ex: 笔记本电脑, 台式机, Null")
    # 与设备表建关系
    devices = db.relationship('AssetsInfo',
                              lazy='dynamic',
                              backref=db.backref('assets_dict'))
    # 预申请表建关系
    applys = db.relationship('ApplyInfo',
                             lazy='joined',
                             backref=db.backref('assets_dict'))
Exemplo n.º 2
0
class EmployeeInfo(db.Model, BaseMix):
    """员工信息表"""
    __tablename__ = 'employee_info'
    phone = db.Column(db.String(15),
                      unique=True,
                      nullable=False,
                      comment="电话 用户唯一id")
    password = db.Column(db.String(100), nullable=True, comment="密码")
    permission = db.Column(db.SmallInteger,
                           default=1,
                           comment="权限 3种:admin=3, hr=2, normal=1")
    name = db.Column(db.String(40), index=True, nullable=False, comment="员工姓名")
    entry_time = db.Column(db.Date, nullable=True, comment="入职时间 人力手动填写")
    department = db.Column(db.String(40), nullable=True, comment="所属部门")
    # 注: Boolean到MySQL中就变成TinyInteger了
    is_work = db.Column(db.String(1),
                        default='1',
                        nullable=True,
                        comment="是否在职 1:在职, 0:离职")
    # 与apply_info表建立关系, 员工的全部申请
    applys = db.relationship('ApplyInfo',
                             lazy='joined',
                             foreign_keys=[ApplyInfo.employee_id],
                             backref=db.backref('employee'))
    # 与apply_info表建立关系, 申请发送者的全部申请
    send_applys = db.relationship('ApplyInfo',
                                  lazy='joined',
                                  foreign_keys=[ApplyInfo.send_employee_id],
                                  backref=db.backref('send_employee'))
    # 与assets_info建立关系
    devices = db.relationship('AssetsInfo',
                              lazy='dynamic',
                              backref=db.backref('employee'))

    def check_password(self, password):
        """检查hash过的password

        :return Bool type
        """
        return check_password_hash(self.password, password)
Exemplo n.º 3
0
class BaseMix(object):
    """"That is a base model of other models"""
    id = db.Column(db.Integer,
                   primary_key=True,
                   autoincrement=True,
                   comment="主键")
    create_time = db.Column(db.DateTime, default=datetime.now, comment="创建时间")
    change_time = db.Column(db.DateTime,
                            default=datetime.now,
                            onupdate=datetime.now,
                            comment="更改时间")
    specifications = db.Column(db.String(200),
                               nullable=True,
                               default='',
                               comment="备注")  # 默认空字符串
Exemplo n.º 4
0
class ApplyInfo(db.Model, BaseMix):
    """员工申请表.

    注意: 提交申请时候, 如果没有这个员工, 那么会先在employee表中创建, 再在apply表中创建.
    """
    __tablename__ = 'apply_info'
    apply_time = db.Column(db.Date, default=datetime.now, comment="申请时间")
    status = db.Column(db.String(2), default='W', comment="申请状态 W 未受理;S 受理中;O 已完成")
    # 外键关联employee_info表, 具体使用人
    employee_id = db.Column(db.Integer, db.ForeignKey('employee_info.id'), nullable=True, comment="员工表外键, 具体使用人")
    # 外键关联assets_dict表
    assets_dict_id = db.Column(db.Integer, db.ForeignKey('assets_dict.id'), nullable=True, comment="资产表外键")
    # 外键关联employee_info表, 申请发送者
    send_employee_id = db.Column(db.Integer, db.ForeignKey('employee_info.id'), nullable=True, comment="员工表外键 申请发送者")
    # 创建联合索引
    __table_args__ = (
        db.Index('ix_employee_assets_dict_id', 'employee_id', 'assets_dict_id'),  # 员工id与字典表id
        db.Index('ix_send_employee_employee_id', 'send_employee_id', 'employee_id')  # 发送申请人与申请人
    )
Exemplo n.º 5
0
class AssetsInfo(db.Model, BaseMix):
    """设备信息表."""
    __tablename__ = 'assets_info'
    code = db.Column(db.String(50), unique=True, comment="设备唯一键: 设备编码")
    sn = db.Column(db.String(100), default='', nullable=True, comment="设备sn序列号")
    # specification: 设备具体规格记录 ex: 显卡,CPU 等等
    status = db.Column(db.String(1), default='1', comment="设备状态 ex: 1入库,2出库,3维修中")
    storage_time = db.Column(db.Date, default=datetime.now, comment="入库时间")
    location = db.Column(db.String(80), default='', nullable=True, comment="仓库位置")
    # last_employee info
    last_employee_name = db.Column(db.String(40), default='', nullable=True, comment="上一个使用人姓名")
    last_employee_department = db.Column(db.String(40), default='', nullable=True, comment="上一个使用人地址")
    # 外键关联employee_info表, 关联上一个使用人, 可以为空,当为空时说明设备在仓库
    employee_id = db.Column(db.Integer, db.ForeignKey('employee_info.id'), nullable=True, comment="员工外键 可以为空,当为空时说明设备在仓库")
    # 外键关联资产字典表
    assets_dict_id = db.Column(db.Integer, db.ForeignKey('assets_dict.id'), nullable=False, comment="字典表外键")