This commit is contained in:
2025-06-20 17:13:51 +08:00
parent 1b55403cd6
commit fd0345a034
472 changed files with 52560 additions and 77 deletions

11
modules/dict/README.MD Normal file
View File

@@ -0,0 +1,11 @@
# dict
字典模块
## 资源打包命令
```bash
gf pack modules/dict/resource modules/dict/packed/packed.go -p modules/dict/resource
```

View File

@@ -0,0 +1,40 @@
package admin
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/dict/service"
"github.com/gogf/gf/v2/frame/g"
)
type DictInfoController struct {
*cool.Controller
}
func init() {
var dict_info_controller = &DictInfoController{
&cool.Controller{
Prefix: "/admin/dict/info",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewDictInfoService(),
},
}
// 注册路由
cool.RegisterController(dict_info_controller)
}
// Data 方法请求
type DictInfoDataReq struct {
g.Meta `path:"/data" method:"POST"`
Types []string `json:"types"`
}
// Data 方法 获得字典数据
func (c *DictInfoController) Data(ctx context.Context, req *DictInfoDataReq) (res *cool.BaseRes, err error) {
service := service.NewDictInfoService()
data, err := service.Data(ctx, req.Types)
res = cool.Ok(data)
return
}

View File

@@ -0,0 +1,22 @@
package admin
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/dict/service"
)
type DictTypeController struct {
*cool.Controller
}
func init() {
var dict_type_controller = &DictTypeController{
&cool.Controller{
Prefix: "/admin/dict/type",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewDictTypeService(),
},
}
// 注册路由
cool.RegisterController(dict_type_controller)
}

View File

@@ -0,0 +1,5 @@
package controller
import (
_ "github.com/cool-team-official/cool-admin-go/modules/dict/controller/admin"
)

21
modules/dict/dict.go Normal file
View File

@@ -0,0 +1,21 @@
package dict
import (
"github.com/cool-team-official/cool-admin-go/cool"
_ "github.com/cool-team-official/cool-admin-go/modules/dict/packed"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx"
_ "github.com/cool-team-official/cool-admin-go/modules/dict/controller"
"github.com/cool-team-official/cool-admin-go/modules/dict/model"
)
func init() {
var (
ctx = gctx.GetInitCtx()
)
g.Log().Debug(ctx, "module dict init start ...")
cool.FillInitData(ctx, "dict", &model.DictInfo{})
cool.FillInitData(ctx, "dict", &model.DictType{})
g.Log().Debug(ctx, "module dict init finished ...")
}

39
modules/dict/go.mod Normal file
View File

@@ -0,0 +1,39 @@
module github.com/cool-team-official/cool-admin-go/modules/dict
go 1.18
require (
github.com/cool-team-official/cool-admin-go/cool v1.5.9
github.com/gogf/gf/v2 v2.6.3
)
require (
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/clbanning/mxj/v2 v2.7.0 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rogpeppe/go-internal v1.6.1 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/gorm v1.25.7 // indirect
)

79
modules/dict/go.sum Normal file
View File

@@ -0,0 +1,79 @@
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
github.com/cool-team-official/cool-admin-go/cool v1.5.9 h1:mvZkckumdnhkr8BGRbB+FKmUeP3tbxmyvSxfNyZAlhE=
github.com/cool-team-official/cool-admin-go/cool v1.5.9/go.mod h1:kle9oSJM+yl8ZtQwZFL8PWbz7ByI8Glj1431njGbWPo=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/gogf/gf/v2 v2.6.3 h1:DoqeuwU98wotpFoDSQEx8RZbmJdK8KdGiJtzJeqpyIo=
github.com/gogf/gf/v2 v2.6.3/go.mod h1:x2XONYcI4hRQ/4gMNbWHmZrNzSEIg20s2NULbzom5k0=
github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg=
github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtgzltlQbOBae4=
github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo=
go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo=
go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI=
go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco=
go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw=
go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg=
go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI=
go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/gorm v1.25.7 h1:VsD6acwRjz2zFxGO50gPO6AkNs7KKnvfzUjHQhZDz/A=
gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=

View File

@@ -0,0 +1,39 @@
package model
import (
"github.com/cool-team-official/cool-admin-go/cool"
)
const TableNameDictInfo = "dict_info"
// DictInfo mapped from table <dict_info>
type DictInfo struct {
*cool.Model
TypeID int32 `gorm:"column:typeId;type:int;not null" json:"typeId"` // 类型ID
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 名称
OrderNum int32 `gorm:"column:orderNum;type:int;not null" json:"orderNum"` // 排序
Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注
ParentID *int32 `gorm:"column:parentId;type:int" json:"parentId"` // 父ID
}
// TableName DictInfo's table name
func (*DictInfo) TableName() string {
return TableNameDictInfo
}
// GroupName DictInfo's table group
func (*DictInfo) GroupName() string {
return "default"
}
// NewDictInfo create a new DictInfo
func NewDictInfo() *DictInfo {
return &DictInfo{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&DictInfo{})
}

View File

@@ -0,0 +1,36 @@
package model
import (
"github.com/cool-team-official/cool-admin-go/cool"
)
const TableNameDictType = "dict_type"
// DictType mapped from table <dict_type>
type DictType struct {
*cool.Model
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 名称
Key string `gorm:"column:key;type:varchar(255);not null" json:"key"` // 标识
}
// TableName DictType's table name
func (*DictType) TableName() string {
return TableNameDictType
}
// GroupName DictType's table group
func (*DictType) GroupName() string {
return "default"
}
// NewDictType create a new DictType
func NewDictType() *DictType {
return &DictType{
Model: cool.NewModel(),
}
}
// init 创建表
func init() {
cool.CreateTable(&DictType{})
}

View File

@@ -0,0 +1,9 @@
package packed
import "github.com/gogf/gf/v2/os/gres"
func init() {
if err := gres.Add("H4sIAAAAAAAC/wrwZmYRYeBgYGBgjRYNZUACcgycDLn5KaU5qcX6KZnJJfpFqcX5pUXJqfqZeZklWcX5eaEhrAyMt0WZkgO82TmQtcIM5WD4FYVqqC5BQ8HC8Zl5afl6cDtOijIlr7lk6H3EQOTAx73zH038qfdkr0r52ei5LB/FzAs1zA4/3DrtAp9Sn5/Sjp0dCs9VLH53iryP7ohrXbxNYEWy3H+VPw9k1RmmczI0RDxrYlS/fTjzQ+Tb/mmt4jxNIhdDzi7PYsuQCN4WtYxtatCit7O15N/JLp50btbcfftW/Pn3rj11295fP7f8q9jx9+w553eHE4M52LLcD4pHWgjzpG6O2rpZi3vfmvp7v+epMYRP5utRSvRbduvIoapfiTd+/fz7dR172+MEK7ZnEZkv5/S1Wrppn0ziyflccZn/8uMENSa3E2l6EzWE3I6YTF5RnXil9e7+nHX3/9WL5vL0SASvnNrd/vcle2J199GDP1x9/PYxMTD8/w8K7Bds/55wMjIw2LIgBzZ6DBIb2CWVBal6KBHa9SwoYMWzoICAgIBTPoGbggyuNBZM6g4S9g5yNioOnrpGZEoPT09PCe+ZUt4zIjy+a3h01/jwfNU5o8vLwzNlwStv7iCPoPnTOQJ/1jx+t1x2deKimyunKhycdKopRFWPtTVK1uS6pOBDK2Vn7eRk2+JibqXYdl/bM6X+6uZ27984FscGBSbFcd2ojNnYwADz8YJNgQ19DAwM9owwH4MAF5qPxXD6GOy1p+C0Ckvw6JpFcWlG0os9nWOaxYNmFhlGsCOMwKObkUmEGXf+hQABhreOIJro3AwzFJJ/kRObLtxQBoYljaEEDcWVm5HtADkcOXpR7TjEyEBmIobZgSuhwALnv+MWJgbCyQYR0tgSDsKwj7gMI8osHhSzbJkZcCUj3EawoxjRgDACSTcrG0QlO4M5EwPDPmYQDxAAAP//BVSc8gsGAAA="); err != nil {
panic("add binary content to resource manager failed: " + err.Error())
}
}

View File

@@ -0,0 +1,52 @@
[
{
"id": 1,
"createTime": "2022-07-06 14:18:53.841000",
"updateTime": "2022-07-06 14:19:10.954000",
"typeId": 1,
"name": "衣服",
"orderNum": 2,
"remark": null,
"parentId": null
},
{
"id": 2,
"createTime": "2022-07-06 14:18:59.834000",
"updateTime": "2022-07-06 14:18:59.834000",
"typeId": 1,
"name": "裤子",
"orderNum": 1,
"remark": null,
"parentId": null
},
{
"id": 3,
"createTime": "2022-07-06 14:19:03.993000",
"updateTime": "2022-07-06 14:19:15.251000",
"typeId": 1,
"name": "鞋子",
"orderNum": 3,
"remark": null,
"parentId": null
},
{
"id": 4,
"createTime": "2022-07-06 14:21:47.122000",
"updateTime": "2022-07-06 14:22:26.131000",
"typeId": 2,
"name": "闪酷",
"orderNum": 2,
"remark": null,
"parentId": null
},
{
"id": 5,
"createTime": "2022-07-06 14:22:18.309000",
"updateTime": "2022-07-06 14:22:18.309000",
"typeId": 2,
"name": "COOL",
"orderNum": 1,
"remark": null,
"parentId": null
}
]

View File

@@ -0,0 +1,16 @@
[
{
"id": 1,
"createTime": "2022-07-06 14:18:41.879000",
"updateTime": "2022-07-06 14:18:41.879000",
"name": "类别",
"key": "type"
},
{
"id": 2,
"createTime": "2022-07-06 14:21:33.778000",
"updateTime": "2022-07-06 14:21:33.778000",
"name": "品牌",
"key": "brand"
}
]

View File

@@ -0,0 +1,98 @@
package service
import (
"context"
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/dict/model"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/util/gconv"
)
type DictInfoService struct {
*cool.Service
}
// Data方法, 用于获取数据
func (s *DictInfoService) Data(ctx context.Context, types []string) (data interface{}, err error) {
var (
dictInfoModel = model.NewDictInfo()
dictTypeModel = model.NewDictType()
)
mType := cool.DBM(dictTypeModel)
// 如果types不为空, 则查询指定类型的数据
if len(types) > 0 {
mType = mType.Where("type in (?)", types)
}
// 查询所有类型
typeData, err := mType.All()
// 如果typeData为空, 则返回空
if typeData.IsEmpty() {
return g.Map{}, nil
}
data = g.Map{}
for _, v := range typeData {
m := cool.DBM(dictInfoModel)
result, err := m.Where("typeId=?", v["id"]).Fields("id", "name", "parentId", "typeId").Order("orderNum asc").All()
if err != nil {
return nil, err
}
if result.IsEmpty() {
continue
}
data.(g.Map)[v["key"].String()] = result
}
return
}
// ModifyAfter 修改后
func (s *DictInfoService) ModifyAfter(ctx context.Context, method string, param map[string]interface{}) (err error) {
if method == "Delete" {
// 删除后,同时删除子节点
ids, ok := param["ids"]
if !ok {
return
}
for _, v := range ids.([]interface{}) {
err = delChildDict(gconv.Int64(v))
if err != nil {
return
}
}
}
return
}
// delChildDict 删除子字典
func delChildDict(id int64) error {
var (
dictInfoModel = model.NewDictInfo()
)
m := cool.DBM(dictInfoModel)
result, err := m.Where("parentId=?", id).Fields("id").All()
if err != nil {
return err
}
if result.IsEmpty() {
return nil
}
for _, v := range result {
delChildDict(v["id"].Int64())
}
_, err = m.Where("parentId=?", id).Delete()
return err
}
// NewDictInfoService 初始化 DictInfoService
func NewDictInfoService() *DictInfoService {
return &DictInfoService{
&cool.Service{
Model: model.NewDictInfo(),
ListQueryOp: &cool.QueryOp{
FieldEQ: []string{"typeId"},
KeyWordField: []string{"name"},
AddOrderby: g.MapStrStr{"createTime": "ASC"},
},
},
}
}

View File

@@ -0,0 +1,21 @@
package service
import (
"github.com/cool-team-official/cool-admin-go/cool"
"github.com/cool-team-official/cool-admin-go/modules/dict/model"
)
type DictTypeService struct {
*cool.Service
}
func NewDictTypeService() *DictTypeService {
return &DictTypeService{
Service: &cool.Service{
Model: model.NewDictType(),
ListQueryOp: &cool.QueryOp{
KeyWordField: []string{"name"},
},
},
}
}