package model

import (
	"time"
	"ulink-admin/pkg/base"
)

type Run struct {
	Id            int64     `excel:"name=主键id   " xorm:"pk autoincr    notnull    comment('主键id')" json:"id"  `                                   //主键id
	ServiceNo     string    `excel:"name=服务资格证号   " xorm:"varchar(255)      comment('服务资格证号')" json:"serviceNo"  `                                //服务资格证号
	Card          string    `excel:"name=卡号   " xorm:"varchar(255)      comment('卡号')" json:"card"  binding:"required"`                           //卡号
	Driver        string    `excel:"name=驾驶员姓名   " xorm:"varchar(64)      comment('驾驶员姓名')" json:"driver"  binding:"required"`                    //驾驶员姓名
	IdCard        string    `excel:"name=身份证号   " xorm:"varchar(255)      comment('身份证号')" json:"idCard"  binding:"required"`                     //身份证号
	CompanyId     int64     `excel:"name=现属公司   " xorm:"bigint(20)    notnull  default(0)  comment('现属公司')" json:"companyId"  binding:"required"` //现属公司
	CarNo         string    `excel:"name=车牌号   " xorm:"varchar(255)      comment('车牌号')" json:"carNo"  binding:"required"`                        //车牌号
	Address       string    `excel:"name=违章地点   " xorm:"varchar(255)      comment('违章地点')" json:"address"  `                                      //违章地点
	ViolationDate string    `excel:"name=违章日期   " xorm:"varchar(255)      comment('违章日期')" json:"violationDate"  `                                //违章日期
	Content       string    `excel:"name=违章内容   " xorm:"text      comment('违章内容')" json:"content"  `                                              //违章内容
	Score         int       `excel:"name=加减分   " xorm:"int(10)    notnull  default(0)  comment('加减分')" json:"score"  binding:"required"`          //加减分
	Company       string    `excel:"name=执法单位   " xorm:"varchar(255)      comment('执法单位')" json:"company"  `                                      //执法单位
	HandlerDate   string    `excel:"name=处理时间   " xorm:"varchar(255)      comment('处理时间')" json:"handlerDate"  `                                  //处理时间
	Remark        string    `excel:"name=备注   " xorm:"text      comment('备注')" json:"remark"  `                                                   //备注
	CreateTime    time.Time `excel:"name=创建时间   " xorm:"datetime      comment('创建时间')" json:"createTime"  `                                       //创建时间
	CreateBy      string    `excel:"name=创建人   " xorm:"varchar(255)      comment('创建人')" json:"createBy"  `                                       //创建人
	UpdateTime    time.Time `excel:"name=更新时间   " xorm:"datetime      comment('更新时间')" json:"updateTime"  `                                       //更新时间
	UpdateBy      string    `excel:"name=更新人   " xorm:"varchar(255)      comment('更新人')" json:"updateBy"  `                                       //更新人
}

func (this Run) TableName() string {
	return "run"
}

func (this *Run) Key() int64 {
	return this.Id
}

func (this *Run) Model() interface{} {
	return this
}

func (this *Run) BeforeUpdate() {
	user := base.GetCurUser()
	if user != nil {
		this.UpdateBy = user.Name
	}
	if user.ComponyId > 0 {
		this.CompanyId = user.ComponyId
	}
}

func (this *Run) BeforeInsert() {
	user := base.GetCurUser()
	if user != nil {
		this.CreateBy = user.Name
		this.UpdateBy = user.Name
	}
	if user.ComponyId > 0 {
		this.CompanyId = user.ComponyId
	}
}