| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- package tools
- import (
- "IotAdmin/common/models"
- "IotAdmin/core/tools/utils"
- "gorm.io/gorm"
- )
- type SysColumns struct {
- ColumnId int `gorm:"primaryKey;autoIncrement" json:"columnId"`
- TableId int `gorm:"" json:"tableId"`
- ColumnName string `gorm:"size:128;" json:"columnName"`
- ColumnComment string `gorm:"column:column_comment;size:128;" json:"columnComment"`
- ColumnType string `gorm:"column:column_type;size:128;" json:"columnType"`
- GoType string `gorm:"column:go_type;size:128;" json:"goType"`
- GoField string `gorm:"column:go_field;size:128;" json:"goField"`
- JsonField string `gorm:"column:json_field;size:128;" json:"jsonField"`
- BJsonField string `gorm:"-" json:"-"`
- IsPk string `gorm:"column:is_pk;size:4;" json:"isPk"`
- IsIncrement string `gorm:"column:is_increment;size:4;" json:"isIncrement"`
- IsRequired string `gorm:"column:is_required;size:4;" json:"isRequired"`
- IsInsert string `gorm:"column:is_insert;size:4;" json:"isInsert"`
- IsSort string `gorm:"column:is_sort;size:4;" json:"isSort"`
- IsList string `gorm:"column:is_list;size:4;" json:"isList"`
- IsQuery string `gorm:"column:is_query;size:4;" json:"isQuery"`
- Required bool `gorm:"column:required;size:1;" json:"required"`
- QueryType string `gorm:"column:query_type;size:128;" json:"queryType"`
- HtmlType string `gorm:"column:html_type;size:128;" json:"htmlType"`
- DictType string `gorm:"column:dict_type;size:128;" json:"dictType"`
- Sort int `gorm:"column:sort;" json:"sort"`
- Pk bool `gorm:"column:pk;size:1;" json:"pk"`
- Remark string `gorm:"column:remark;size:255;" json:"remark"`
- FkTableName string `gorm:"" json:"fkTableName"`
- BFkTableName string `gorm:"-" json:"-"`
- FkTableNameClass string `gorm:"" json:"fkTableNameClass"`
- BFkTableNameClass string `gorm:"-" json:"-"`
- FkTableNamePackage string `gorm:"" json:"fkTableNamePackage"`
- BFkTableNamePackage string `gorm:"-" json:"-"`
- FkTableNameBusiness string `gorm:"" json:"fkTableNameBusiness"`
- BFkTableNameBusiness string `gorm:"-" json:"-"`
- FkCol []SysColumns `gorm:"-" json:"fkCol"`
- FkLabelId string `gorm:"" json:"fkLabelId"`
- FkLabelName string `gorm:"size:255;" json:"fkLabelName"`
- CreateBy int `gorm:"column:create_by;size:20;" json:"createBy"`
- UpdateBy int `gorm:"column:update_By;size:20;" json:"updateBy"`
- models.ModelTime
- }
- func (*SysColumns) TableName() string {
- return "__gen_columns"
- }
- func (e *SysColumns) GetList(tx *gorm.DB, exclude bool) ([]SysColumns, error) {
- var doc []SysColumns
- table := tx.Table(e.TableName())
- table = table.Where("table_id = ? ", e.TableId)
- if exclude {
- notIn := make([]string, 0, 6)
- notIn = append(notIn, "id")
- notIn = append(notIn, "create_by")
- notIn = append(notIn, "update_by")
- notIn = append(notIn, "created_at")
- notIn = append(notIn, "updated_at")
- notIn = append(notIn, "deleted_at")
- table = table.Where(" column_name not in(?)", notIn)
- }
- if err := table.Find(&doc).Error; err != nil {
- return nil, err
- }
- for i := range doc {
- doc[i].BJsonField = utils.FirstUpper(doc[i].JsonField)
- doc[i].BFkTableNamePackage = utils.FirstUpper(doc[i].FkTableNamePackage)
- doc[i].BFkTableName = utils.FirstUpper(doc[i].FkTableName)
- doc[i].BFkTableNameClass = utils.FirstUpper(doc[i].FkTableNameClass)
- doc[i].BFkTableNameBusiness = utils.FirstUpper(doc[i].FkTableNameBusiness)
- }
- return doc, nil
- }
- func (e *SysColumns) Create(tx *gorm.DB) (SysColumns, error) {
- var doc SysColumns
- e.CreateBy = 0
- result := tx.Table(e.TableName()).Create(&e)
- if result.Error != nil {
- err := result.Error
- return doc, err
- }
- doc = *e
- return doc, nil
- }
- func (e *SysColumns) Update(tx *gorm.DB) (update SysColumns, err error) {
- if err = tx.Table(e.TableName()).First(&update, e.ColumnId).Error; err != nil {
- return
- }
- //参数1:是要修改的数据
- //参数2:是修改的数据
- e.UpdateBy = 0
- if err = tx.Table(e.TableName()).Model(&update).Save(&e).Error; err != nil {
- return
- }
- return
- }
|