diff --git a/server/.vscode/settings.json b/server/.vscode/settings.json index a207a72..8e75494 100644 --- a/server/.vscode/settings.json +++ b/server/.vscode/settings.json @@ -6,6 +6,7 @@ "dcloudio", "endregion", "excelize", + "fatih", "fontsize", "freetype", "gocode", @@ -31,6 +32,7 @@ "tinyint", "tinytext", "typeof", + "uaparser", "uniapp", "varchar", "Warnf", diff --git a/server/app/service/generatorService/tpl_utils/templates/gocode/controller.go.tpl b/server/app/service/generatorService/tpl_utils/templates/gocode/controller.go.tpl index 44f2ace..83d61c4 100644 --- a/server/app/service/generatorService/tpl_utils/templates/gocode/controller.go.tpl +++ b/server/app/service/generatorService/tpl_utils/templates/gocode/controller.go.tpl @@ -11,6 +11,8 @@ import ( "x_admin/util" "x_admin/util/excel2" "golang.org/x/sync/singleflight" + "x_admin/app/schema" + "x_admin/app/service" ) diff --git a/server/app/service/generatorService/tpl_utils/tpl.go b/server/app/service/generatorService/tpl_utils/tpl.go index 155ec15..ab84070 100644 --- a/server/app/service/generatorService/tpl_utils/tpl.go +++ b/server/app/service/generatorService/tpl_utils/tpl.go @@ -189,9 +189,10 @@ func (tu templateUtil) GetTemplatePaths(genTpl string) []string { "uniapp/search.vue.tpl", "uniapp/pages.json.tpl", } - if genTpl == GenConstants.TplCrud { + switch genTpl { + case GenConstants.TplCrud: tplPaths = append(tplPaths, "vue/index.vue.tpl") - } else if genTpl == GenConstants.TplTree { + case GenConstants.TplTree: tplPaths = append(tplPaths, "vue/index-tree.vue.tpl") } return tplPaths @@ -233,9 +234,9 @@ func (tu templateUtil) GetFilePaths(tplCodeMap map[string]string, ModuleName str "gocode/model.go.tpl": strings.Join([]string{"server/model/", ModuleName, ".go"}, ""), "gocode/route.go.tpl": strings.Join([]string{"server/router/adminRoute/", ModuleName, "_route.go"}, ""), - "gocode/schema.go.tpl": strings.Join([]string{"server/schema/", ModuleName, "_schema.go"}, ""), //"server/schema/%s_schema.go" - "gocode/service.go.tpl": strings.Join([]string{"server/service/", ModuleName, "_service.go"}, ""), //"server/service/%s_service.go", - "gocode/controller.go.tpl": strings.Join([]string{"server/controller/admin_ctl/", ModuleName, "_ctl.go"}, ""), //"server/controller/admin_ctl/%s_ctl.go", + "gocode/schema.go.tpl": strings.Join([]string{"server/app/schema/", ModuleName, "_schema.go"}, ""), //"server/app/schema/%s_schema.go" + "gocode/service.go.tpl": strings.Join([]string{"server/app/service/", ModuleName, "_service.go"}, ""), //"server/app/service/%s_service.go", + "gocode/controller.go.tpl": strings.Join([]string{"server/app/controller/admin_ctl/", ModuleName, "_ctl.go"}, ""), //"server/app/controller/admin_ctl/%s_ctl.go", "vue/api.ts.tpl": strings.Join([]string{"admin/src/api/", GenUtil.NameToPath(ModuleName), ".ts"}, ""), // "admin/src/api/%s.ts", "vue/edit.vue.tpl": strings.Join([]string{"admin/src/views/", GenUtil.NameToPath(ModuleName), "/edit.vue"}, ""), // "admin/src/views/%s/edit.vue", diff --git a/server/app/service/generatorService/tpl_utils/utils.go b/server/app/service/generatorService/tpl_utils/utils.go index 053a825..b5c77c7 100644 --- a/server/app/service/generatorService/tpl_utils/utils.go +++ b/server/app/service/generatorService/tpl_utils/utils.go @@ -219,25 +219,26 @@ func (gu genUtil) GetTablePriCol(columns []gen_model.GenTableColumn) (res gen_mo * @description: Go类型转TS类型 */ func (gu genUtil) GoToTsType(s string) string { - if s == "int" || s == "int8" || s == "int16" || s == "int32" || s == "int64" { + switch s { + case "int", "int8", "int16", "int32", "int64": return "number" - } else if s == "float" || s == "float32" || s == "float64" { + case "float", "float32", "float64": return "number" - } else if s == "string" { + case "string": return "string" - } else if s == "bool" { + case "bool": return "boolean" - } else if s == "time.Time" { + case "time.Time": return "Date" - } else if s == "[]byte" { + case "[]byte": return "string" - } else if s == "[]string" { + case "[]string": return "string[]" - } else if s == "[]int" { + case "[]int": return "number[]" - } else if s == "[]float" { + case "[]float": return "number[]" - } else if s == "core.NullTime" { + case "core.NullTime": return "string" } return "string" @@ -247,17 +248,18 @@ func (gu genUtil) GoToTsType(s string) string { * @description: Go类型转 添加编辑 类型 */ func (gu genUtil) GoWithAddEditType(s string) string { - if s == "int" || s == "int8" || s == "int16" || s == "int32" || s == "int64" { + switch s { + case "int", "int8", "int16", "int32", "int64": return "core.NullInt" - } else if s == "float" || s == "float32" || s == "float64" { + case "float", "float32", "float64": return "core.NullFloat" - } else if s == "string" { + case "string": return "*string" - } else if s == "bool" { + case "bool": return "*int" - } else if s == "time.Time" { + case "time.Time": return "core.NullTime" - } else if s == "core.NullTime" { + case "core.NullTime": return "core.NullTime" } return "string" @@ -267,17 +269,18 @@ func (gu genUtil) GoWithAddEditType(s string) string { * @description: Go类型转 添加编辑 类型 */ func (gu genUtil) GoWithRespType(s string) string { - if s == "int" || s == "int8" || s == "int16" || s == "int32" || s == "int64" { + switch s { + case "int", "int8", "int16", "int32", "int64": return "core.NullInt" - } else if s == "float" || s == "float32" || s == "float64" { + case "float", "float32", "float64": return "core.NullFloat" - } else if s == "string" { + case "string": return "string" - } else if s == "bool" { + case "bool": return "int" - } else if s == "time.Time" { + case "time.Time": return "core.NullTime" - } else if s == "core.NullTime" { + case "core.NullTime": return "core.NullTime" } return "string" diff --git a/server/app/service/monitorService/monitor_project_service.go b/server/app/service/monitorService/monitor_project_service.go index 1a94de8..af3dbe7 100644 --- a/server/app/service/monitorService/monitor_project_service.go +++ b/server/app/service/monitorService/monitor_project_service.go @@ -128,7 +128,7 @@ func (service monitorProjectService) Detail(Id int) (res monitorSchema.MonitorPr func (service monitorProjectService) Add(addReq monitorSchema.MonitorProjectAddReq) (createId int, e error) { var obj model.MonitorProject convert_util.StructToStruct(addReq, &obj) - obj.ProjectKey = util.ToolsUtil.MakeUuid() + obj.ProjectKey = util.ToolsUtil.MakeUuidV7() err := service.db.Create(&obj).Error e = response.CheckMysqlErr(err) if e != nil { diff --git a/server/app/service/systemService/permService.go b/server/app/service/systemService/permService.go index 637b3ca..253db3b 100644 --- a/server/app/service/systemService/permService.go +++ b/server/app/service/systemService/permService.go @@ -83,7 +83,7 @@ func (service systemAuthPermService) BatchSaveByMenuIds(roleId uint, menuIds str var perms []system_model.SystemAuthPerm for _, menuIdStr := range strings.Split(menuIds, ",") { menuId, _ := strconv.ParseUint(menuIdStr, 10, 32) - perms = append(perms, system_model.SystemAuthPerm{ID: util.ToolsUtil.MakeUuid(), RoleId: roleId, MenuId: uint(menuId)}) + perms = append(perms, system_model.SystemAuthPerm{ID: util.ToolsUtil.MakeUuidV7(), RoleId: roleId, MenuId: uint(menuId)}) } txErr := tx.Create(&perms).Error var te = response.CheckErr(txErr, "BatchSaveByMenuIds Create in tx err") diff --git a/server/plugin/storage.go b/server/plugin/storage.go index 37966df..6524775 100644 --- a/server/plugin/storage.go +++ b/server/plugin/storage.go @@ -112,7 +112,7 @@ func (sd storageDriver) buildSaveName(file *multipart.FileHeader) string { name := file.Filename ext := strings.ToLower(path.Ext(name)) date := time.Now().Format("20060102") - return path.Join(date, util.ToolsUtil.MakeUuid()+ext) + return path.Join(date, util.ToolsUtil.MakeUuidV7()+ext) } // getFileExt 获取文件扩展名 diff --git a/server/util/tools.go b/server/util/tools.go index c132a98..ea4d160 100644 --- a/server/util/tools.go +++ b/server/util/tools.go @@ -36,9 +36,13 @@ func (tu toolsUtil) RandomString(length int) string { return string(byteList) } -// MakeUuid 制作UUID -func (tu toolsUtil) MakeUuid() string { - return strings.ReplaceAll(uuid.New().String(), "-", "") +// MakeUuidV7 制作UUID v7 +func (tu toolsUtil) MakeUuidV7() string { + v7, err := uuid.NewV7() + if err != nil { + return "" + } + return strings.ReplaceAll(v7.String(), "-", "") } // MakeMd5 制作MD5 @@ -64,7 +68,7 @@ func (tu toolsUtil) GetFileMD5(file *multipart.FileHeader) (string, error) { // MakeToken 生成唯一Token func (tu toolsUtil) MakeToken() string { ms := time.Now().UnixMilli() - token := tu.MakeMd5(tu.MakeUuid() + strconv.FormatInt(ms, 10) + tu.RandomString(8)) + token := tu.MakeMd5(tu.MakeUuidV7() + strconv.FormatInt(ms, 10) + tu.RandomString(8)) tokenSecret := token + config.AppConfig.Secret return tu.MakeMd5(tokenSecret) + tu.RandomString(6) }