github.com/johnnyeven/libtools@v0.0.0-20191126065708-61829c1adf46/gen_method/examples/test.go (about)

     1  package examples
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/johnnyeven/libtools/courier/enumeration"
     7  	"github.com/johnnyeven/libtools/timelib"
     8  )
     9  
    10  //go:generate tools gen method --no-table-name User
    11  type User struct {
    12  	Id uint64 `gorm:"primary_key;column:F_id" sql:"type:bigint(64) unsigned auto_increment;not null" json:"-"`
    13  	////Id1        uint64                 `gorm:"primary_key;column:F_id1" sql:"type:bigint(64) unsigned auto_increment;not null" json:"-"`
    14  	Phone      string                 `gorm:"column:F_phone" sql:"type:varchar(16);not null;unique_index:I_phone" json:"phone"`
    15  	UserID     uint64                 `gorm:"column:F_user_id" sql:"type:bigint(64) unsigned;not null;unique_index:I_user_id" json:"user_id"`
    16  	Name       string                 `gorm:"column:F_name" sql:"type:varchar(32) ;not null;unique_index:I_user_id" json:"name"`
    17  	CityID     uint64                 `gorm:"column:F_city_id" sql:"type:bigint(64) ;not null;index:I_city_id;default:0" json:"city_id"`
    18  	AreaID     int                    `gorm:"column:F_area_id" sql:"type:bigint(64) ;not null;index:I_city_id;default:0" json:"area_id"`
    19  	Enabled    uint8                  `gorm:"column:F_enabled" sql:"type:tinyint(8) unsigned;not null;default:1" json:"-"`
    20  	CreateTime time.Time              `gorm:"column:F_create_time" sql:"type:bigint(64) unsigned;not null;default:0" json:"-"`
    21  	UpdateTime timelib.MySQLTimestamp `gorm:"column:F_update_time" sql:"type:bigint(64) unsigned;not null;default:0" json:"-"`
    22  }
    23  
    24  func (cg User) TableName() string {
    25  	table_name := "t_user_test"
    26  	if DBTable.Name == "" {
    27  		return table_name
    28  	}
    29  	return DBTable.Name + "." + table_name
    30  }
    31  
    32  //go:generate tools gen method CustomerG7
    33  type CustomerG7 struct {
    34  	// 客户id
    35  	CustomerID uint64 `json:"customerID,string" gorm:"primary_key;column:F_customer_id" sql:"type:bigint(64) unsigned;not null;unique_index:I_user_customer[1]"`
    36  	// g7s机构
    37  	G7sOrgCode string `json:"orgCode" gorm:"primary_key;column:F_g7s_org_code" sql:"type:varchar(32);not null"`
    38  	// g7s用户id
    39  	G7sUserID string `json:"userID,string" gorm:"primary_key;column:F_g7s_user_id" sql:"type:varchar(32);not null;unique_index:I_user_customer[0]"`
    40  	// 记录创建时间
    41  	CreateTime timelib.MySQLTimestamp `json:"createTime" gorm:"column:F_create_time" sql:"type:bigint(64);not null;index:I_create_time"`
    42  	// 记录更新时间
    43  	UpdateTime timelib.MySQLTimestamp `json:"updateTime" gorm:"column:F_update_time" sql:"type:bigint(64);not null;index:I_update_time"`
    44  	Enabled    enumeration.Bool       `json:"-" gorm:"primary_key;column:F_enabled" sql:"type:tinyint(8) unsigned;not null;default:1;unique_index:I_user_customer[2]"`
    45  }
    46  
    47  //go:generate tools gen method PhysicsDeleteByUniquustomerG7
    48  type PhysicsDeleteByUniquustomerG7 struct {
    49  	// g7s用户id
    50  	G7sUserID string `json:"userID,string" gorm:"primary_key;column:F_g7s_user_id" sql:"type:varchar(32);not null"`
    51  	//// 客户id
    52  	CustomerID uint64 `json:"customerID,string" gorm:"primary_key;column:F_customer_id" sql:"type:bigint(64) unsigned;not null;index:I_customer"`
    53  	// g7s机构
    54  	G7sOrgCode string `json:"orgCode" gorm:"column:F_g7s_org_code" sql:"type:varchar(32);not null;index:I_org_code"`
    55  	// 记录创建时间
    56  	CreateTime timelib.MySQLTimestamp `json:"createTime" gorm:"column:F_create_time" sql:"type:bigint(64);not null;index:I_create_time"`
    57  	// 记录更新时间
    58  	UpdateTime timelib.MySQLTimestamp `json:"updateTime" gorm:"column:F_update_time" sql:"type:bigint(64);not null;index:I_update_time"`
    59  	Enabled    enumeration.Bool       `json:"-" gorm:"primary_key;column:F_enabled" sql:"type:tinyint(8) unsigned;not null;default:1"`
    60  }