- pgsql 获取表名, 获取表字段(todo), 获取数据库名
refactor:
- 自动化代码与自动化代码历史 代码规范化
- mysql 获取表名, 获取表字段, 获取数据库名
- enter 代码优化
This commit is contained in:
SliverHorn
2021-11-20 22:46:05 +08:00
parent 77a9b20346
commit 6cc495de95
28 changed files with 449 additions and 250 deletions
+41 -27
View File
@@ -3,6 +3,7 @@ package system
import (
"errors"
"fmt"
"github.com/flipped-aurora/gin-vue-admin/server/model/system/response"
"path/filepath"
"strings"
"time"
@@ -17,19 +18,14 @@ import (
var RepeatErr = errors.New("重复创建")
type AutoCodeHistoryService struct {
}
type AutoCodeHistoryService struct{}
var AutoCodeHistoryServiceApp = new(AutoCodeHistoryService)
func (autoCodeHistoryService *AutoCodeHistoryService) Repeat(structName string) bool {
var count int64
global.GVA_DB.Model(&system.SysAutoCodeHistory{}).Where("struct_name = ? and flag = 0", structName).Count(&count)
return count > 0
}
// CreateAutoCodeHistory RouterPath : RouterPath@RouterString;RouterPath2@RouterString2
// CreateAutoCodeHistory 创建代码生成器历史记录
// RouterPath : RouterPath@RouterString;RouterPath2@RouterString2
// Author [SliverHorn](https://github.com/SliverHorn)
// Author [songzhibin97](https://github.com/songzhibin97)
func (autoCodeHistoryService *AutoCodeHistoryService) CreateAutoCodeHistory(meta, structName, structCNName, autoCodePath string, injectionMeta string, tableName string, apiIds string) error {
return global.GVA_DB.Create(&system.SysAutoCodeHistory{
RequestMeta: meta,
@@ -42,10 +38,29 @@ func (autoCodeHistoryService *AutoCodeHistoryService) CreateAutoCodeHistory(meta
}).Error
}
// First 根据id获取代码生成器历史的数据
// Author [SliverHorn](https://github.com/SliverHorn)
// Author [songzhibin97](https://github.com/songzhibin97)
func (autoCodeHistoryService *AutoCodeHistoryService) First(info *request.GetById) (string, error) {
var meta string
return meta, global.GVA_DB.Model(system.SysAutoCodeHistory{}).Select("request_meta").Where("id = ?", info.Uint()).First(&meta).Error
}
// Repeat 检测重复
// Author [SliverHorn](https://github.com/SliverHorn)
// Author [songzhibin97](https://github.com/songzhibin97)
func (autoCodeHistoryService *AutoCodeHistoryService) Repeat(structName string) bool {
var count int64
global.GVA_DB.Model(&system.SysAutoCodeHistory{}).Where("struct_name = ? and flag = 0", structName).Count(&count)
return count > 0
}
// RollBack 回滚
func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(id uint) error {
// Author [SliverHorn](https://github.com/SliverHorn)
// Author [songzhibin97](https://github.com/songzhibin97)
func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(info *request.GetById) error {
md := system.SysAutoCodeHistory{}
if err := global.GVA_DB.First(&md, id).Error; err != nil {
if err := global.GVA_DB.Where("id = ?", info.Uint()).First(&md).Error; err != nil {
return err
}
// 清除API表
@@ -54,7 +69,7 @@ func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(id uint) error {
global.GVA_LOG.Error("ClearTag DeleteApiByIds:", zap.Error(err))
}
// 获取全部表名
err, dbNames := AutoCodeServiceApp.GetTables(global.GVA_CONFIG.Mysql.Dbname)
dbNames, err := AutoCodeServiceApp.Database().GetTables(global.GVA_CONFIG.Mysql.Dbname)
if err != nil {
global.GVA_LOG.Error("ClearTag GetTables:", zap.Error(err))
}
@@ -104,26 +119,25 @@ func (autoCodeHistoryService *AutoCodeHistoryService) RollBack(id uint) error {
return global.GVA_DB.Save(&md).Error
}
func (autoCodeHistoryService *AutoCodeHistoryService) GetMeta(id uint) (string, error) {
var meta string
return meta, global.GVA_DB.Model(system.SysAutoCodeHistory{}).Select("request_meta").First(&meta, id).Error
// Delete 删除历史数据
// Author [SliverHorn](https://github.com/SliverHorn)
// Author [songzhibin97](https://github.com/songzhibin97)
func (autoCodeHistoryService *AutoCodeHistoryService) Delete(info *request.GetById) error {
return global.GVA_DB.Where("id = ?", info.Uint()).Delete(&system.SysAutoCodeHistory{}).Error
}
// GetSysHistoryPage 获取系统历史数据
func (autoCodeHistoryService *AutoCodeHistoryService) GetSysHistoryPage(info request.PageInfo) (err error, list interface{}, total int64) {
// GetList 获取系统历史数据
// Author [SliverHorn](https://github.com/SliverHorn)
// Author [songzhibin97](https://github.com/songzhibin97)
func (autoCodeHistoryService *AutoCodeHistoryService) GetList(info request.PageInfo) (list []response.AutoCodeHistory, total int64, err error) {
limit := info.PageSize
offset := info.PageSize * (info.Page - 1)
db := global.GVA_DB.Model(&system.SysAutoCodeHistory{})
var fileLists []system.SysAutoCodeHistory
var entities []response.AutoCodeHistory
err = db.Count(&total).Error
if err != nil {
return
return nil, total, err
}
err = db.Limit(limit).Offset(offset).Order("updated_at desc").Select("id,created_at,updated_at,struct_name,struct_cn_name,flag,table_name").Find(&fileLists).Error
return err, fileLists, total
}
// DeletePage 删除历史数据
func (autoCodeHistoryService *AutoCodeHistoryService) DeletePage(id uint) error {
return global.GVA_DB.Delete(&system.SysAutoCodeHistory{}, id).Error
err = db.Limit(limit).Offset(offset).Order("updated_at desc").Find(&entities).Error
return entities, total, err
}