mh_goadmin_server/app/admin/models/tools/dbcolumns.go
chenlin 9207440c53 1.修复缺陷,优化代码:
(1)库存调拨、库存变动中商品都拆分为单条数据;
(2)编辑商品资料时同步更新库存表和库存商品表的商品编号;
(3)租卡相关接口添加权限校验,只能查询对应门店权限的数据;
2024-05-31 17:51:41 +08:00

73 lines
2.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package tools
import (
"errors"
"gorm.io/gorm"
orm "go-admin/common/global"
"go-admin/tools"
config2 "go-admin/tools/config"
)
type DBColumns struct {
TableSchema string `gorm:"column:TABLE_SCHEMA" json:"tableSchema"`
TableName string `gorm:"column:TABLE_NAME" json:"tableName"`
ColumnName string `gorm:"column:COLUMN_NAME" json:"columnName"`
ColumnDefault string `gorm:"column:COLUMN_DEFAULT" json:"columnDefault"`
IsNullable string `gorm:"column:IS_NULLABLE" json:"isNullable"`
DataType string `gorm:"column:DATA_TYPE" json:"dataType"`
CharacterMaximumLength string `gorm:"column:CHARACTER_MAXIMUM_LENGTH" json:"characterMaximumLength"`
CharacterSetName string `gorm:"column:CHARACTER_SET_NAME" json:"characterSetName"`
ColumnType string `gorm:"column:COLUMN_TYPE" json:"columnType"`
ColumnKey string `gorm:"column:COLUMN_KEY" json:"columnKey"`
Extra string `gorm:"column:EXTRA" json:"extra"`
ColumnComment string `gorm:"column:COLUMN_COMMENT" json:"columnComment"`
}
func (e *DBColumns) GetPage(pageSize int, pageIndex int) ([]DBColumns, int, error) {
var doc []DBColumns
var count int64
table := new(gorm.DB)
if config2.DatabaseConfig.Driver == "mysql" {
table = orm.Eloquent.Table("information_schema.`COLUMNS`")
table = table.Where("table_schema= ? ", config2.GenConfig.DBName)
if e.TableName != "" {
return nil, 0, errors.New("table name cannot be empty")
}
table = table.Where("TABLE_NAME = ?", e.TableName)
}
if err := table.Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
return nil, 0, err
}
//table.Total(&count)
return doc, int(count), nil
}
func (e *DBColumns) GetList() ([]DBColumns, error) {
var doc []DBColumns
table := new(gorm.DB)
if e.TableName == "" {
return nil, errors.New("table name cannot be empty")
}
if config2.DatabaseConfig.Driver == "mysql" {
table = orm.Eloquent.Table("information_schema.columns")
table = table.Where("table_schema= ? ", config2.GenConfig.DBName)
table = table.Where("TABLE_NAME = ?", e.TableName).Order("ORDINAL_POSITION asc")
} else {
tools.Assert(true, "目前只支持mysql数据库", 500)
}
if err := table.Find(&doc).Error; err != nil {
return doc, err
}
return doc, nil
}