Merge branch 'iot'

# Conflicts:
#	apps/develop/api/gen.go
#	apps/develop/api/table.go
#	apps/develop/router/gen.go
#	apps/develop/router/table.go
#	apps/job/api/job.go
#	apps/job/entity/job.go
#	apps/job/entity/log_job.go
#	apps/job/jobs/jobbase.go
#	apps/job/router/job.go
#	apps/log/api/log_job.go
#	apps/log/api/log_login.go
#	apps/log/api/log_oper.go
#	apps/log/router/log.go
#	apps/log/services/log_job.go
#	apps/resource/api/email.go
#	apps/resource/api/oss.go
#	apps/resource/router/email.go
#	apps/resource/router/oss.go
#	apps/system/api/api.go
#	apps/system/api/config.go
#	apps/system/api/dept.go
#	apps/system/api/dict.go
#	apps/system/api/menu.go
#	apps/system/api/notice.go
#	apps/system/api/post.go
#	apps/system/api/role.go
#	apps/system/api/system.go
#	apps/system/api/tenant.go
#	apps/system/api/user.go
#	apps/system/router/api.go
#	apps/system/router/config.go
#	apps/system/router/dept.go
#	apps/system/router/dict.go
#	apps/system/router/menu.go
#	apps/system/router/notice.go
#	apps/system/router/post.go
#	apps/system/router/role.go
#	apps/system/router/tenant.go
#	apps/system/router/user.go
#	go.mod
#	go.sum
#	main.go
#	pkg/config/app.go
#	pkg/config/casbin.go
#	pkg/config/config.go
#	pkg/config/db.go
#	pkg/config/gen.go
#	pkg/config/jwt.go
#	pkg/config/log.go
#	pkg/config/redis.go
#	pkg/config/server.go
#	pkg/global/global.go
#	pkg/initialize/table.go
#	pkg/middleware/log.go
#	pkg/middleware/oper.go
#	pkg/middleware/permission.go
#	resource/template/go/api.template
#	resource/template/go/router.template
#	resource/template/go/service.template
This commit is contained in:
XM-GO
2023-08-22 15:47:45 +08:00
227 changed files with 19473 additions and 17369 deletions

View File

@@ -1,9 +1,9 @@
package api
import (
"github.com/XM-GO/PandaKit/ginx"
"pandax/apps/develop/gen"
"pandax/apps/develop/services"
"pandax/base/ginx"
)
type GenApi struct {

View File

@@ -1,11 +1,11 @@
package api
import (
"github.com/XM-GO/PandaKit/ginx"
"github.com/XM-GO/PandaKit/utils"
"pandax/apps/develop/entity"
"pandax/apps/develop/gen"
"pandax/apps/develop/services"
"pandax/base/ginx"
"pandax/base/utils"
"strings"
"sync"
)

View File

@@ -0,0 +1,14 @@
package vo
import "pandax/apps/develop/entity"
/**
* @Description
* @Author 熊猫
* @Date 2022/8/4 15:52
**/
type TableInfoVo struct {
List []entity.DevGenTableColumn `json:"list"`
Info entity.DevGenTable `json:"info"`
}

View File

@@ -44,3 +44,18 @@ type DBColumns struct {
Extra string `gorm:"column:EXTRA" json:"extra"`
ColumnComment string `gorm:"column:COLUMN_COMMENT" json:"columnComment"`
}
type DBColumnsP 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:udt_name" json:"columnType"`
ColumnKey string ` json:"columnKey"` // 判断自增比较困难
Extra string ` json:"extra"`
ColumnComment string ` json:"columnComment"`
}

View File

@@ -22,8 +22,8 @@ import (
var (
ToolsGenTableColumn = &toolsGenTableColumn{
ColumnTypeStr: []string{"char", "varchar", "narchar", "varchar2", "tinytext", "text", "mediumtext", "longtext"},
ColumnTypeTime: []string{"datetime", "time", "date", "timestamp"},
ColumnTypeNumber: []string{"tinyint", "smallint", "mediumint", "int", "number", "integer", "bigint", "float", "float", "double", "decimal"},
ColumnTypeTime: []string{"datetime", "time", "date", "timestamp", "timestamptz"},
ColumnTypeNumber: []string{"tinyint", "smallint", "mediumint", "int", "int2", "int4", "int8", "number", "integer", "numeric", "bigint", "float", "float4", "float8", "double", "decimal"},
ColumnNameNotEdit: []string{"create_by", "update_by", "create_time", "update_time", "delete_time"},
ColumnNameNotList: []string{"create_by", "update_by", "update_time", "delete_time"},
ColumnNameNotQuery: []string{"create_by", "update_by", "create_time", "update_time", "delete_time", "remark"},
@@ -182,6 +182,7 @@ func (s *toolsGenTableColumn) GenTableInit(tableName string) entity.DevGenTable
// js函数名和权限标识使用
if i >= 1 {
data.BusinessName += strings.ToLower(strStart) + strEnd
data.FunctionName = strings.ToUpper(strStart) + strEnd
}
}
data.PackageName = "system"
@@ -189,30 +190,25 @@ func (s *toolsGenTableColumn) GenTableInit(tableName string) entity.DevGenTable
// 中横线表名称接口路径、前端文件夹名称和js名称使用
data.ModuleName = strings.Replace(tableName, "_", "-", -1)
dbTable := services.DevGenTableModelDao.FindDbTableOne(tableName)
dbColumn := services.DevTableColumnModelDao.FindDbTableColumnList(tableName)
data.TableComment = dbTable.TableComment //表描述
if dbTable.TableComment == "" {
data.TableComment = data.ClassName
}
data.FunctionName = strings.ToUpper(data.BusinessName)
data.TableComment = data.ClassName
data.FunctionAuthor = "panda"
wg := sync.WaitGroup{}
dcs := *dbColumn
for i := 0; i < len(dcs); i++ {
index := i
for x := 0; x < len(dcs); x++ {
index := x
wg.Add(1)
go func(wg *sync.WaitGroup, i int) {
log.Println(dcs[i].ColumnName)
go func(wg *sync.WaitGroup, y int) {
defer wg.Done()
var column entity.DevGenTableColumn
column.ColumnComment = dcs[i].ColumnComment
column.ColumnName = dcs[i].ColumnName
column.ColumnType = dcs[i].ColumnType
column.Sort = i + 1
column.ColumnComment = dcs[y].ColumnComment
column.ColumnName = dcs[y].ColumnName
column.ColumnType = dcs[y].ColumnType
column.Sort = y + 1
column.IsPk = "0"
nameList := strings.Split(dcs[i].ColumnName, "_")
nameList := strings.Split(dcs[y].ColumnName, "_")
for i := 0; i < len(nameList); i++ {
strStart := string([]byte(nameList[i])[:1])
strend := string([]byte(nameList[i])[1:])
@@ -223,13 +219,12 @@ func (s *toolsGenTableColumn) GenTableInit(tableName string) entity.DevGenTable
column.JsonField += strings.ToUpper(strStart) + strend
}
}
if strings.Contains(dcs[i].ColumnKey, "PR") {
if strings.Contains(dcs[y].ColumnKey, "PR") {
column.IsPk = "1"
data.PkColumn = dcs[i].ColumnName
data.PkColumn = dcs[y].ColumnName
data.PkGoField = column.GoField
data.PkJsonField = column.JsonField
global.Log.Info("是否自增主键", dcs[i].Extra)
if dcs[i].Extra == "auto_increment" {
if dcs[y].Extra == "auto_increment" {
column.IsIncrement = "1"
}
}
@@ -255,26 +250,38 @@ func (s *toolsGenTableColumn) GenTableInit(tableName string) entity.DevGenTable
} else if s.IsNumberObject(dataType) {
//字段为数字类型
column.HtmlType = "input"
t, _ := utils.ReplaceString(`\(.+\)`, "", column.ColumnType)
t = strings.Split(strings.TrimSpace(t), " ")[0]
t = strings.ToLower(t)
column.HtmlType = "input"
t := ""
if global.Conf.Server.DbType == "postgresql" {
t = column.ColumnType
} else {
t, _ := utils.ReplaceString(`\(.+\)`, "", column.ColumnType)
t = strings.Split(strings.TrimSpace(t), " ")[0]
t = strings.ToLower(t)
}
// 如果是浮点型
switch t {
case "float", "double", "decimal":
case "float", "float4", "float8", "double", "decimal":
column.GoType = "float64"
case "bit", "int", "tinyint", "small_int", "smallint", "medium_int", "mediumint":
case "bit", "int", "int2", "int4", "tinyint", "small_int", "smallint", "medium_int", "mediumint":
if utils.Contains(column.ColumnType, "unsigned") != -1 {
column.GoType = "uint"
} else {
column.GoType = "int"
}
case "big_int", "bigint":
case "big_int", "int8", "bigint", "numeric":
if utils.Contains(column.ColumnType, "unsigned") != -1 {
column.GoType = "uint64"
} else {
column.GoType = "int64"
}
}
} else {
switch dataType {
case "bool":
column.GoType = "bool"
column.HtmlType = "switch"
}
}
//新增字段
if s.IsNotEdit(column.ColumnName) {
@@ -323,8 +330,8 @@ func (s *toolsGenTableColumn) GenTableInit(tableName string) entity.DevGenTable
// 类型&性别字段设置下拉框
column.HtmlType = "select"
}
global.Log.Info(y)
data.Columns = append(data.Columns, column)
wg.Done()
}(&wg, index)
}
wg.Wait()
@@ -435,7 +442,7 @@ func GenCode(tableId int64) {
kgo.KFile.WriteFile("./apps/"+tab.PackageName+"/services/"+tab.TableName+".go", b2.Bytes())
kgo.KFile.WriteFile("./apps/"+tab.PackageName+"/api/"+tab.TableName+".go", b3.Bytes())
kgo.KFile.WriteFile("./apps/"+tab.PackageName+"/router/"+tab.TableName+".go", b4.Bytes())
kgo.KFile.WriteFile(global.Conf.Gen.Frontpath+"/api/"+tab.PackageName+"/"+tab.BusinessName+".js", b5.Bytes())
kgo.KFile.WriteFile(global.Conf.Gen.Frontpath+"/api/"+tab.PackageName+"/"+tab.BusinessName+".ts", b5.Bytes())
kgo.KFile.WriteFile(global.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/index.vue", b6.Bytes())
kgo.KFile.WriteFile(global.Conf.Gen.Frontpath+"/views/"+tab.PackageName+"/"+tab.BusinessName+"/"+"component"+"/editModule.vue", b7.Bytes())
}

View File

@@ -1,10 +1,10 @@
package router
import (
"github.com/XM-GO/PandaKit/ginx"
"github.com/gin-gonic/gin"
"pandax/apps/develop/api"
"pandax/apps/develop/services"
"pandax/base/ginx"
)
func InitGenRouter(router *gin.RouterGroup) {

View File

@@ -1,10 +1,10 @@
package router
import (
"github.com/XM-GO/PandaKit/ginx"
"github.com/gin-gonic/gin"
"pandax/apps/develop/api"
"pandax/apps/develop/services"
"pandax/base/ginx"
)
func InitGenTableRouter(router *gin.RouterGroup) {

View File

@@ -77,10 +77,10 @@ func (m *devGenTableModelImpl) FindDbTableOne(tableName string) *entity.DBTables
biz.ErrIsNil(errors.New("只支持mysql和postgresql数据库"), "只支持mysql和postgresql数据库")
}
db := global.Db.Table("information_schema.tables")
if global.Conf.Server.DbType != "mysql" {
if global.Conf.Server.DbType == "mysql" {
db = db.Where("table_schema= ? ", global.Conf.Gen.Dbname)
}
if global.Conf.Server.DbType != "postgresql" {
if global.Conf.Server.DbType == "postgresql" {
db = db.Where("table_schema= ? ", "public")
}
db = db.Where("table_name = ?", tableName)
@@ -187,7 +187,7 @@ func (m *devGenTableModelImpl) Update(data entity.DevGenTable) *entity.DevGenTab
t, ok := tableMap[data.Columns[i].LinkTableName]
if ok {
data.Columns[i].LinkTableClass = t.ClassName
data.Columns[i].LinkTablePackage = t.PackageName
data.Columns[i].LinkTablePackage = t.BusinessName
data.Columns[i].LinkLabelId = t.PkColumn
data.Columns[i].LinkLabelName = t.PkGoField
}