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

65 lines
2.0 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 DBTables struct {
TableName string `gorm:"column:TABLE_NAME" json:"tableName"`
Engine string `gorm:"column:ENGINE" json:"engine"`
TableRows string `gorm:"column:TABLE_ROWS" json:"tableRows"`
TableCollation string `gorm:"column:TABLE_COLLATION" json:"tableCollation"`
CreateTime string `gorm:"column:CREATE_TIME" json:"createTime"`
UpdateTime string `gorm:"column:UPDATE_TIME" json:"updateTime"`
TableComment string `gorm:"column:TABLE_COMMENT" json:"tableComment"`
}
func (e *DBTables) GetPage(pageSize int, pageIndex int) ([]DBTables, int, error) {
var doc []DBTables
table := new(gorm.DB)
var count int64
if config2.DatabaseConfig.Driver == "mysql" {
table = orm.Eloquent.Table("information_schema.tables")
table = table.Where("TABLE_NAME not in (select table_name from " + config2.GenConfig.DBName + ".sys_tables) ")
table = table.Where("table_schema= ? ", config2.GenConfig.DBName)
if e.TableName != "" {
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
}
} else {
tools.Assert(true, "目前只支持mysql数据库", 500)
}
//table.Total(&count)
return doc, int(count), nil
}
func (e *DBTables) Get() (DBTables, error) {
var doc DBTables
table := new(gorm.DB)
if config2.DatabaseConfig.Driver == "mysql" {
table = orm.Eloquent.Table("information_schema.tables")
table = table.Where("table_schema= ? ", config2.GenConfig.DBName)
if e.TableName == "" {
return doc, errors.New("table name cannot be empty")
}
table = table.Where("TABLE_NAME = ?", e.TableName)
} else {
tools.Assert(true, "目前只支持mysql数据库", 500)
}
if err := table.First(&doc).Error; err != nil {
return doc, err
}
return doc, nil
}