From a392c4502a418c0951744d47d7e3d2ea7c63e84f Mon Sep 17 00:00:00 2001 From: RIceWqy <1840169763@qq.com> Date: Sun, 24 Dec 2023 17:25:10 +0800 Subject: [PATCH] init --- apps/fushouxian-server/config/dbconfig.json | 2 +- apps/fushouxian-server/fushouxian-server.go | 19 +++++++++---------- init/Category.go | 3 --- init/init.go | 7 +++++++ module/category/Category.go | 20 ++++++++++++++++++++ module/coupon/init.go | 12 ++++++++++++ module/goods/init.go | 11 +++++++++++ module/service/init.go | 12 ++++++++++++ module/skuPrice/init.go | 12 ++++++++++++ 9 files changed, 84 insertions(+), 14 deletions(-) delete mode 100644 init/Category.go create mode 100644 init/init.go create mode 100644 module/coupon/init.go create mode 100644 module/service/init.go create mode 100644 module/skuPrice/init.go diff --git a/apps/fushouxian-server/config/dbconfig.json b/apps/fushouxian-server/config/dbconfig.json index fcc97a9..8a1c955 100644 --- a/apps/fushouxian-server/config/dbconfig.json +++ b/apps/fushouxian-server/config/dbconfig.json @@ -2,7 +2,7 @@ { "DbType":"mysql", "IsMaster":true, - "Dsn":"server=127.0.0.1;user id=root;password=root;database=fushouxian", + "Dsn":"root:root@tcp(localhost:3306)/fushouxian?charset=utf8mb4", "sqlMaxIdleConns":1, "sqlMaxOpenConns":1, "sqlLogLevel":2 diff --git a/apps/fushouxian-server/fushouxian-server.go b/apps/fushouxian-server/fushouxian-server.go index b8ba53c..8e6113c 100644 --- a/apps/fushouxian-server/fushouxian-server.go +++ b/apps/fushouxian-server/fushouxian-server.go @@ -1,16 +1,13 @@ package main import ( - "fmt" "log" "net/http" - "os" _ "src/init" "github.com/towgo/towgo/dao/basedboperat" "github.com/towgo/towgo/dao/ormDriver/gormDriver" "github.com/towgo/towgo/dao/ormDriver/xormDriver" - "github.com/towgo/towgo/lib/processmanager" "github.com/towgo/towgo/lib/system" "github.com/towgo/towgo/towgo" ) @@ -18,17 +15,18 @@ import ( var appName string = "fushouxian-server" var appVersion string = "1.0.0" -var basePath = system.GetPathOfProgram() +// var basePath = system.GetPathOfProgram() +var basePath = "E:\\workfile\\FuShouXian-Backend\\apps\\fushouxian-server" func init() { //初始化xorm数据库驱动 var dbconfig []xormDriver.DsnConfig - system.ScanConfigJson(basePath+"/config/dbconfig.json", &dbconfig) + system.ScanConfigJson(basePath+"\\config\\dbconfig.json", &dbconfig) xormDriver.New(dbconfig) //初始化gorm数据库驱动 var gormdbconfig []gormDriver.DsnConfig - system.ScanConfigJson(basePath+"/config/dbconfig.json", &gormdbconfig) + system.ScanConfigJson(basePath+"\\config\\dbconfig.json", &gormdbconfig) gormDriver.New(gormdbconfig) //设定默认orm引擎 @@ -39,7 +37,7 @@ func init() { } func main() { - pm := processmanager.GetManager() + /*pm := processmanager.GetManager() for k, v := range os.Args { switch v { case "start": @@ -83,7 +81,8 @@ func main() { } } log.Print("参数传递错误,有效参数如下:\n" + os.Args[0] + " start | stop | reload | stop") - + */ + start() } func start() { @@ -93,7 +92,7 @@ func start() { conf := struct { Serverport string `json:"serverport"` }{} - system.ScanConfigJson(basePath+"/config/config.json", &conf) + system.ScanConfigJson(basePath+"\\config\\config.json", &conf) http.HandleFunc("/jsonrpc", towgo.HttpHandller) @@ -103,7 +102,7 @@ func start() { func moduleClientInit() { var node towgo.EdgeServerNodeConfig - system.ScanConfigJson(basePath+"config/togocdn.client.config.json", &node) + system.ScanConfigJson(basePath+"\\config\\togocdn.client.config.json", &node) node.Methods = towgo.GetMethods() node.ModuleName = appName for _, v := range node.ServerUrls { diff --git a/init/Category.go b/init/Category.go deleted file mode 100644 index 4bf5381..0000000 --- a/init/Category.go +++ /dev/null @@ -1,3 +0,0 @@ -package init - -import _ "src/module/category" diff --git a/init/init.go b/init/init.go new file mode 100644 index 0000000..79a2937 --- /dev/null +++ b/init/init.go @@ -0,0 +1,7 @@ +package init + +import _ "src/module/category" +import _ "src/module/coupon" +import _ "src/module/goods" +import _ "src/module/service" +import _ "src/module/skuPrice" diff --git a/module/category/Category.go b/module/category/Category.go index 486f3ea..ebd7f2a 100644 --- a/module/category/Category.go +++ b/module/category/Category.go @@ -17,10 +17,30 @@ type Category struct { } func (c *Category) AfterQuery(session basedboperat.DbTransactionSession) { + c.getChildens(session) + if len(c.Children) > 0 { + + } + +} +func (c *Category) getChildens(session basedboperat.DbTransactionSession) { var children []Category var list basedboperat.List list.Limit = -1 session.ListScan(&list, c, &children) c.Children = children +} + +// 递归查询子集方法 +func findChildren(categories []Category, parentId int64, session basedboperat.DbTransactionSession) []Category { + var result []Category + for _, category := range categories { + if category.ParentId == parentId { + children := findChildren(categories, category.Id) + category.Children = children + result = append(result, category) + } + } + return result } diff --git a/module/coupon/init.go b/module/coupon/init.go new file mode 100644 index 0000000..3838589 --- /dev/null +++ b/module/coupon/init.go @@ -0,0 +1,12 @@ +package goods + +import ( + "github.com/towgo/towgo/dao/ormDriver/xormDriver" + "github.com/towgo/towgo/towgo" +) + +func init() { + xormDriver.Sync2(new(Coupon)) + towgo.NewCRUDJsonrpcAPI("/coupon", Coupon{}, []Coupon{}).RegAPI() + +} diff --git a/module/goods/init.go b/module/goods/init.go index 81d4951..e820442 100644 --- a/module/goods/init.go +++ b/module/goods/init.go @@ -1 +1,12 @@ package goods + +import ( + "github.com/towgo/towgo/dao/ormDriver/xormDriver" + "github.com/towgo/towgo/towgo" +) + +func init() { + xormDriver.Sync2(new(Goods)) + towgo.NewCRUDJsonrpcAPI("/goods", Goods{}, []Goods{}).RegAPI() + +} diff --git a/module/service/init.go b/module/service/init.go new file mode 100644 index 0000000..ba847f0 --- /dev/null +++ b/module/service/init.go @@ -0,0 +1,12 @@ +package goods + +import ( + "github.com/towgo/towgo/dao/ormDriver/xormDriver" + "github.com/towgo/towgo/towgo" +) + +func init() { + xormDriver.Sync2(new(Service)) + towgo.NewCRUDJsonrpcAPI("/service", Service{}, []Service{}).RegAPI() + +} diff --git a/module/skuPrice/init.go b/module/skuPrice/init.go new file mode 100644 index 0000000..9500e8e --- /dev/null +++ b/module/skuPrice/init.go @@ -0,0 +1,12 @@ +package goods + +import ( + "github.com/towgo/towgo/dao/ormDriver/xormDriver" + "github.com/towgo/towgo/towgo" +) + +func init() { + xormDriver.Sync2(new(SKUPrice)) + towgo.NewCRUDJsonrpcAPI("/skuprice", SKUPrice{}, []SKUPrice{}).RegAPI() + +}