sys_columns.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package tools
  2. import (
  3. "go-admin/app/admin/models"
  4. "gorm.io/gorm"
  5. )
  6. type SysColumns struct {
  7. ColumnId int `gorm:"primaryKey;autoIncrement" json:"columnId"`
  8. TableId int `gorm:"" json:"tableId"`
  9. ColumnName string `gorm:"size:128;" json:"columnName"`
  10. ColumnComment string `gorm:"column:column_comment;size:128;" json:"columnComment"`
  11. ColumnType string `gorm:"column:column_type;size:128;" json:"columnType"`
  12. GoType string `gorm:"column:go_type;size:128;" json:"goType"`
  13. GoField string `gorm:"column:go_field;size:128;" json:"goField"`
  14. JsonField string `gorm:"column:json_field;size:128;" json:"jsonField"`
  15. IsPk string `gorm:"column:is_pk;size:4;" json:"isPk"`
  16. IsIncrement string `gorm:"column:is_increment;size:4;" json:"isIncrement"`
  17. IsRequired string `gorm:"column:is_required;size:4;" json:"isRequired"`
  18. IsInsert string `gorm:"column:is_insert;size:4;" json:"isInsert"`
  19. IsEdit string `gorm:"column:is_edit;size:4;" json:"isEdit"`
  20. IsList string `gorm:"column:is_list;size:4;" json:"isList"`
  21. IsQuery string `gorm:"column:is_query;size:4;" json:"isQuery"`
  22. QueryType string `gorm:"column:query_type;size:128;" json:"queryType"`
  23. HtmlType string `gorm:"column:html_type;size:128;" json:"htmlType"`
  24. DictType string `gorm:"column:dict_type;size:128;" json:"dictType"`
  25. Sort int `gorm:"column:sort;" json:"sort"`
  26. List string `gorm:"column:list;size:1;" json:"list"`
  27. Pk bool `gorm:"column:pk;size:1;" json:"pk"`
  28. Required bool `gorm:"column:required;size:1;" json:"required"`
  29. SuperColumn bool `gorm:"column:super_column;size:1;" json:"superColumn"`
  30. UsableColumn bool `gorm:"column:usable_column;size:1;" json:"usableColumn"`
  31. Increment bool `gorm:"column:increment;size:1;" json:"increment"`
  32. Insert bool `gorm:"column:insert;size:1;" json:"insert"`
  33. Edit bool `gorm:"column:edit;size:1;" json:"edit"`
  34. Query bool `gorm:"column:query;size:1;" json:"query"`
  35. Remark string `gorm:"column:remark;size:255;" json:"remark"`
  36. FkTableName string `gorm:"" json:"fkTableName"`
  37. FkTableNameClass string `gorm:"" json:"fkTableNameClass"`
  38. FkTableNamePackage string `gorm:"" json:"fkTableNamePackage"`
  39. FkCol []SysColumns `gorm:"-" json:"fkCol"`
  40. FkLabelId string `gorm:"" json:"fkLabelId"`
  41. FkLabelName string `gorm:"size:255;" json:"fkLabelName"`
  42. CreateBy int `gorm:"column:create_by;size:20;" json:"createBy"`
  43. UpdateBy int `gorm:"column:update_By;size:20;" json:"updateBy"`
  44. models.BaseModel
  45. }
  46. func (SysColumns) TableName() string {
  47. return "sys_columns"
  48. }
  49. func (e *SysColumns) GetList(tx *gorm.DB, exclude bool) ([]SysColumns, error) {
  50. var doc []SysColumns
  51. table := tx.Table("sys_columns")
  52. table = table.Where("table_id = ? ", e.TableId)
  53. if exclude {
  54. notIn := make([]string, 0, 6)
  55. notIn = append(notIn, "id")
  56. notIn = append(notIn, "create_by")
  57. notIn = append(notIn, "update_by")
  58. notIn = append(notIn, "created_at")
  59. notIn = append(notIn, "updated_at")
  60. notIn = append(notIn, "deleted_at")
  61. table = table.Where(" column_name not in(?)", notIn)
  62. }
  63. if err := table.Find(&doc).Error; err != nil {
  64. return nil, err
  65. }
  66. return doc, nil
  67. }
  68. func (e *SysColumns) Create(tx *gorm.DB) (SysColumns, error) {
  69. var doc SysColumns
  70. e.CreateBy = 0
  71. result := tx.Table("sys_columns").Create(&e)
  72. if result.Error != nil {
  73. err := result.Error
  74. return doc, err
  75. }
  76. doc = *e
  77. return doc, nil
  78. }
  79. func (e *SysColumns) Update(tx *gorm.DB) (update SysColumns, err error) {
  80. if err = tx.Table("sys_columns").First(&update, e.ColumnId).Error; err != nil {
  81. return
  82. }
  83. //参数1:是要修改的数据
  84. //参数2:是修改的数据
  85. e.UpdateBy = 0
  86. if err = tx.Table("sys_columns").Model(&update).Updates(&e).Error; err != nil {
  87. return
  88. }
  89. return
  90. }