* feat: Add slack support. Signed-off-by: IRONICBo <47499836+IRONICBo@users.noreply.github.com> * fix: Update lint. Signed-off-by: IRONICBo <47499836+IRONICBo@users.noreply.github.com> * fix: Split modules to client and cmd. Signed-off-by: IRONICBo <47499836+IRONICBo@users.noreply.github.com> * fix: Add slack goroutine. Signed-off-by: IRONICBo <47499836+IRONICBo@users.noreply.github.com> --------- Signed-off-by: IRONICBo <47499836+IRONICBo@users.noreply.github.com>main
| @@ -19,6 +19,7 @@ import ( | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/config" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/conn/db" | |||
| customerroles "github.com/OpenIMSDK/OpenKF/server/internal/models/customer_roles" | |||
| systemroles "github.com/OpenIMSDK/OpenKF/server/internal/models/system_roles" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/utils" | |||
| "github.com/OpenIMSDK/OpenKF/server/pkg/log" | |||
| @@ -52,6 +53,8 @@ func main() { | |||
| systemroles.SysCustomer{}, | |||
| systemroles.SysCommunity{}, | |||
| systemroles.SysBot{}, | |||
| customerroles.CustomerSlack{}, | |||
| } | |||
| // drop tables if exist. | |||
| @@ -19,6 +19,7 @@ import ( | |||
| "gorm.io/gen" | |||
| customerroles "github.com/OpenIMSDK/OpenKF/server/internal/models/customer_roles" | |||
| systemroles "github.com/OpenIMSDK/OpenKF/server/internal/models/system_roles" | |||
| ) | |||
| @@ -38,6 +39,8 @@ func main() { | |||
| systemroles.SysCustomer{}, | |||
| systemroles.SysCommunity{}, | |||
| systemroles.SysBot{}, | |||
| customerroles.CustomerSlack{}, | |||
| } | |||
| // Generate basic dao | |||
| @@ -18,6 +18,7 @@ import ( | |||
| "flag" | |||
| "github.com/OpenIMSDK/OpenKF/server/cmd/gendao/pkg" | |||
| customerroles "github.com/OpenIMSDK/OpenKF/server/internal/models/customer_roles" | |||
| systemroles "github.com/OpenIMSDK/OpenKF/server/internal/models/system_roles" | |||
| ) | |||
| @@ -30,6 +31,8 @@ func main() { | |||
| systemroles.SysCustomer{}, | |||
| systemroles.SysCommunity{}, | |||
| systemroles.SysBot{}, | |||
| customerroles.CustomerSlack{}, | |||
| } | |||
| for _, model := range models { | |||
| @@ -5,7 +5,6 @@ go 1.19 | |||
| require ( | |||
| github.com/Delta456/box-cli-maker/v2 v2.3.0 | |||
| github.com/antonfisher/nested-logrus-formatter v1.3.1 | |||
| github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 | |||
| github.com/gin-gonic/gin v1.9.1 | |||
| github.com/go-redis/redis/v8 v8.11.5 | |||
| github.com/go-resty/resty/v2 v2.7.0 | |||
| @@ -16,6 +15,7 @@ require ( | |||
| github.com/minio/minio-go/v7 v7.0.57 | |||
| github.com/pkg/errors v0.9.1 | |||
| github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5 | |||
| github.com/shomali11/slacker v1.4.1 | |||
| github.com/sirupsen/logrus v1.9.3 | |||
| github.com/spf13/viper v1.16.0 | |||
| github.com/swaggo/files v1.0.1 | |||
| @@ -48,6 +48,7 @@ require ( | |||
| github.com/goccy/go-json v0.10.2 // indirect | |||
| github.com/google/uuid v1.3.0 // indirect | |||
| github.com/gookit/color v1.5.3 // indirect | |||
| github.com/gorilla/websocket v1.4.2 // indirect | |||
| github.com/hashicorp/hcl v1.0.0 // indirect | |||
| github.com/huandu/xstrings v1.4.0 // indirect | |||
| github.com/jinzhu/inflection v1.0.0 // indirect | |||
| @@ -72,8 +73,12 @@ require ( | |||
| github.com/onsi/gomega v1.27.6 // indirect | |||
| github.com/pelletier/go-toml/v2 v2.0.8 // indirect | |||
| github.com/rivo/uniseg v0.2.0 // indirect | |||
| github.com/robfig/cron v1.2.0 // indirect | |||
| github.com/rogpeppe/go-internal v1.11.0 // indirect | |||
| github.com/rs/xid v1.5.0 // indirect | |||
| github.com/shomali11/commander v0.0.0-20220716022157-b5248c76541a // indirect | |||
| github.com/shomali11/proper v0.0.0-20180607004733-233a9a872c30 // indirect | |||
| github.com/slack-go/slack v0.12.1 // indirect | |||
| github.com/spf13/afero v1.9.5 // indirect | |||
| github.com/spf13/cast v1.5.1 // indirect | |||
| github.com/spf13/jwalterweatherman v1.1.0 // indirect | |||
| @@ -77,8 +77,6 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 | |||
| github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= | |||
| github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= | |||
| github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= | |||
| github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 h1:6VSn3hB5U5GeA6kQw4TwWIWbOhtvR2hmbBJnTOtqTWc= | |||
| github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6/go.mod h1:YxOVT5+yHzKvwhsiSIWmbAYM3Dr9AEEbER2dVayfBkg= | |||
| github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= | |||
| github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= | |||
| github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4= | |||
| @@ -117,6 +115,8 @@ github.com/go-resty/resty/v2 v2.7.0/go.mod h1:9PWDzw47qPphMRFfhsyk0NnSgvluHcljSM | |||
| github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= | |||
| github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= | |||
| github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= | |||
| github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho= | |||
| github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= | |||
| github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= | |||
| github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= | |||
| github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= | |||
| @@ -163,6 +163,7 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ | |||
| github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | |||
| github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | |||
| github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | |||
| github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= | |||
| github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | |||
| github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= | |||
| github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= | |||
| @@ -189,6 +190,8 @@ github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8 | |||
| github.com/gookit/color v1.5.2/go.mod h1:w8h4bGiHeeBpvQVePTutdbERIUf3oJE5lZ8HM0UgXyg= | |||
| github.com/gookit/color v1.5.3 h1:twfIhZs4QLCtimkP7MOxlF3A0U/5cDPseRT9M/+2SCE= | |||
| github.com/gookit/color v1.5.3/go.mod h1:NUzwzeehUfl7GIb36pqId+UGmRfQcU/WiiyTTeNjHtE= | |||
| github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= | |||
| github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | |||
| github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= | |||
| github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= | |||
| github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= | |||
| @@ -293,13 +296,23 @@ github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5/go.mod h1:GEXHk5H | |||
| github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= | |||
| github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= | |||
| github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= | |||
| github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ= | |||
| github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k= | |||
| github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= | |||
| github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= | |||
| github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= | |||
| github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= | |||
| github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= | |||
| github.com/shomali11/commander v0.0.0-20220716022157-b5248c76541a h1:NCmAZOmyqKwf+0KzhY6I6CPndU3qkLRp47RwTyLdMW8= | |||
| github.com/shomali11/commander v0.0.0-20220716022157-b5248c76541a/go.mod h1:bYyJw/Aj9fK+qoFmRbPJeWsDgq7WGO8f/Qof95qPug4= | |||
| github.com/shomali11/proper v0.0.0-20180607004733-233a9a872c30 h1:56awf1OXG6Jc2Pk1saojpCzpzkoBvlqecCyNLY+wwkc= | |||
| github.com/shomali11/proper v0.0.0-20180607004733-233a9a872c30/go.mod h1:O723XwIZBX3FR45rBic/Eyp/DKo/YtchYFURzpUWY2c= | |||
| github.com/shomali11/slacker v1.4.1 h1:t2R5Drx1MJXmgNejhf2cIfVmFfwEu4tRSbpYn4jfwwI= | |||
| github.com/shomali11/slacker v1.4.1/go.mod h1:Crk6eTJrfV158YuGDbbJ8yzRS/guH7Snw4c9c/nIuE4= | |||
| github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= | |||
| github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= | |||
| github.com/slack-go/slack v0.12.1 h1:X97b9g2hnITDtNsNe5GkGx6O2/Sz/uC20ejRZN6QxOw= | |||
| github.com/slack-go/slack v0.12.1/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw= | |||
| github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= | |||
| github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= | |||
| github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA= | |||
| @@ -313,6 +326,7 @@ github.com/spf13/viper v1.16.0/go.mod h1:yg78JgCJcbrQOvV9YLXgkLaZqUidkY9K+Dd1Fof | |||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | |||
| github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= | |||
| github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= | |||
| github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | |||
| github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | |||
| github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | |||
| github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= | |||
| @@ -0,0 +1,37 @@ | |||
| // Copyright © 2023 OpenIM open source community. All rights reserved. | |||
| // | |||
| // Licensed under the Apache License, Version 2.0 (the "License"); | |||
| // you may not use this file except in compliance with the License. | |||
| // You may obtain a copy of the License at | |||
| // | |||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software | |||
| // distributed under the License is distributed on an "AS IS" BASIS, | |||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| // See the License for the specific language governing permissions and | |||
| // limitations under the License. | |||
| package client | |||
| import ( | |||
| "github.com/shomali11/slacker" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/config" | |||
| "github.com/OpenIMSDK/OpenKF/server/pkg/log" | |||
| ) | |||
| // SlackBot slack client. | |||
| var SlackBot *slacker.Slacker | |||
| // InitSlack init slack client. | |||
| func InitSlack() *slacker.Slacker { | |||
| botToken := config.Config.Slack.BotToken | |||
| appToken := config.Config.Slack.AppToken | |||
| debug := config.Config.App.Debug | |||
| SlackBot = slacker.NewClient(botToken, appToken, slacker.WithDebug(debug)) | |||
| log.Info("Slack", "init config ok") | |||
| return SlackBot | |||
| } | |||
| @@ -0,0 +1,584 @@ | |||
| // Copyright © 2023 OpenIM open source community. All rights reserved. | |||
| // | |||
| // Licensed under the Apache License, Version 2.0 (the "License"); | |||
| // you may not use this file except in compliance with the License. | |||
| // You may obtain a copy of the License at | |||
| // | |||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software | |||
| // distributed under the License is distributed on an "AS IS" BASIS, | |||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| // See the License for the specific language governing permissions and | |||
| // limitations under the License. | |||
| package dao | |||
| import ( | |||
| "context" | |||
| "time" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/conn/db" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/dal/cache" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/dal/gen" | |||
| customerroles "github.com/OpenIMSDK/OpenKF/server/internal/models/customer_roles" | |||
| ) | |||
| // CustomerSlackDao customerslack dao. | |||
| type CustomerSlackDao struct { | |||
| Dao | |||
| } | |||
| // NewCustomerSlackDao return a customerslack dao. | |||
| func NewCustomerSlackDao() *CustomerSlackDao { | |||
| query := gen.Use(db.GetMysqlDB()) | |||
| cache := cache.Use(db.GetRedis()) | |||
| return &CustomerSlackDao{ | |||
| Dao: Dao{ | |||
| ctx: context.Background(), | |||
| query: query, | |||
| cache: &cache, | |||
| }, | |||
| } | |||
| } | |||
| // Create create one or multi models. | |||
| func (d *CustomerSlackDao) Create(m ...*customerroles.CustomerSlack) error { | |||
| return d.query.WithContext(d.ctx).CustomerSlack.Create(m...) | |||
| } | |||
| // First get first matched result. | |||
| func (d *CustomerSlackDao) First() (*customerroles.CustomerSlack, error) { | |||
| return d.query.WithContext(d.ctx).CustomerSlack.First() | |||
| } | |||
| // FindAll get all matched results. | |||
| func (d *CustomerSlackDao) FindAll() ([]*customerroles.CustomerSlack, error) { | |||
| return d.query.WithContext(d.ctx).CustomerSlack.Find() | |||
| } | |||
| // FindFirstById get first matched result by id. | |||
| func (d *CustomerSlackDao) FindFirstById(id uint) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Id.Eq(id)).First() | |||
| } | |||
| // FindByIdPage get page by Id. | |||
| func (d *CustomerSlackDao) FindByIdPage(id uint, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Id.Eq(id)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByCreatedAt get first matched result by createdat. | |||
| func (d *CustomerSlackDao) FindFirstByCreatedAt(createdat time.Time) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.CreatedAt.Eq(createdat)).First() | |||
| } | |||
| // FindByCreatedAtPage get page by CreatedAt. | |||
| func (d *CustomerSlackDao) FindByCreatedAtPage(createdat time.Time, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.CreatedAt.Eq(createdat)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByUpdatedAt get first matched result by updatedat. | |||
| func (d *CustomerSlackDao) FindFirstByUpdatedAt(updatedat time.Time) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.UpdatedAt.Eq(updatedat)).First() | |||
| } | |||
| // FindByUpdatedAtPage get page by UpdatedAt. | |||
| func (d *CustomerSlackDao) FindByUpdatedAtPage(updatedat time.Time, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.UpdatedAt.Eq(updatedat)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByDeletedAt get first matched result by deletedat. | |||
| func (d *CustomerSlackDao) FindFirstByDeletedAt(deletedat time.Time) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.DeletedAt.Eq(deletedat)).First() | |||
| } | |||
| // FindByDeletedAtPage get page by DeletedAt. | |||
| func (d *CustomerSlackDao) FindByDeletedAtPage(deletedat time.Time, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.DeletedAt.Eq(deletedat)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByUUID get first matched result by uuid. | |||
| func (d *CustomerSlackDao) FindFirstByUUID(uuid string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.UUID.Eq(uuid)).First() | |||
| } | |||
| // FindByUUIDPage get page by UUID. | |||
| func (d *CustomerSlackDao) FindByUUIDPage(uuid string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.UUID.Eq(uuid)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByEmail get first matched result by email. | |||
| func (d *CustomerSlackDao) FindFirstByEmail(email string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Email.Eq(email)).First() | |||
| } | |||
| // FindByEmailPage get page by Email. | |||
| func (d *CustomerSlackDao) FindByEmailPage(email string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Email.Eq(email)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByNickname get first matched result by nickname. | |||
| func (d *CustomerSlackDao) FindFirstByNickname(nickname string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Nickname.Eq(nickname)).First() | |||
| } | |||
| // FindByNicknamePage get page by Nickname. | |||
| func (d *CustomerSlackDao) FindByNicknamePage(nickname string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Nickname.Eq(nickname)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByAvatar get first matched result by avatar. | |||
| func (d *CustomerSlackDao) FindFirstByAvatar(avatar string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Avatar.Eq(avatar)).First() | |||
| } | |||
| // FindByAvatarPage get page by Avatar. | |||
| func (d *CustomerSlackDao) FindByAvatarPage(avatar string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Avatar.Eq(avatar)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByDescription get first matched result by description. | |||
| func (d *CustomerSlackDao) FindFirstByDescription(description string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Description.Eq(description)).First() | |||
| } | |||
| // FindByDescriptionPage get page by Description. | |||
| func (d *CustomerSlackDao) FindByDescriptionPage(description string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Description.Eq(description)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByFirstName get first matched result by firstname. | |||
| func (d *CustomerSlackDao) FindFirstByFirstName(firstname string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.FirstName.Eq(firstname)).First() | |||
| } | |||
| // FindByFirstNamePage get page by FirstName. | |||
| func (d *CustomerSlackDao) FindByFirstNamePage(firstname string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.FirstName.Eq(firstname)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByLastName get first matched result by lastname. | |||
| func (d *CustomerSlackDao) FindFirstByLastName(lastname string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.LastName.Eq(lastname)).First() | |||
| } | |||
| // FindByLastNamePage get page by LastName. | |||
| func (d *CustomerSlackDao) FindByLastNamePage(lastname string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.LastName.Eq(lastname)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByRealName get first matched result by realname. | |||
| func (d *CustomerSlackDao) FindFirstByRealName(realname string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.RealName.Eq(realname)).First() | |||
| } | |||
| // FindByRealNamePage get page by RealName. | |||
| func (d *CustomerSlackDao) FindByRealNamePage(realname string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.RealName.Eq(realname)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByRealNameNormalized get first matched result by realnamenormalized. | |||
| func (d *CustomerSlackDao) FindFirstByRealNameNormalized(realnamenormalized string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.RealNameNormalized.Eq(realnamenormalized)).First() | |||
| } | |||
| // FindByRealNameNormalizedPage get page by RealNameNormalized. | |||
| func (d *CustomerSlackDao) FindByRealNameNormalizedPage(realnamenormalized string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.RealNameNormalized.Eq(realnamenormalized)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByDisplayName get first matched result by displayname. | |||
| func (d *CustomerSlackDao) FindFirstByDisplayName(displayname string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.DisplayName.Eq(displayname)).First() | |||
| } | |||
| // FindByDisplayNamePage get page by DisplayName. | |||
| func (d *CustomerSlackDao) FindByDisplayNamePage(displayname string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.DisplayName.Eq(displayname)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByDisplayNameNormalized get first matched result by displaynamenormalized. | |||
| func (d *CustomerSlackDao) FindFirstByDisplayNameNormalized(displaynamenormalized string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.DisplayNameNormalized.Eq(displaynamenormalized)).First() | |||
| } | |||
| // FindByDisplayNameNormalizedPage get page by DisplayNameNormalized. | |||
| func (d *CustomerSlackDao) FindByDisplayNameNormalizedPage(displaynamenormalized string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.DisplayNameNormalized.Eq(displaynamenormalized)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstBySkype get first matched result by skype. | |||
| func (d *CustomerSlackDao) FindFirstBySkype(skype string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Skype.Eq(skype)).First() | |||
| } | |||
| // FindBySkypePage get page by Skype. | |||
| func (d *CustomerSlackDao) FindBySkypePage(skype string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Skype.Eq(skype)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByPhone get first matched result by phone. | |||
| func (d *CustomerSlackDao) FindFirstByPhone(phone string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Phone.Eq(phone)).First() | |||
| } | |||
| // FindByPhonePage get page by Phone. | |||
| func (d *CustomerSlackDao) FindByPhonePage(phone string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Phone.Eq(phone)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByImage24 get first matched result by image24. | |||
| func (d *CustomerSlackDao) FindFirstByImage24(image24 string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Image24.Eq(image24)).First() | |||
| } | |||
| // FindByImage24Page get page by Image24. | |||
| func (d *CustomerSlackDao) FindByImage24Page(image24 string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Image24.Eq(image24)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByImage32 get first matched result by image32. | |||
| func (d *CustomerSlackDao) FindFirstByImage32(image32 string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Image32.Eq(image32)).First() | |||
| } | |||
| // FindByImage32Page get page by Image32. | |||
| func (d *CustomerSlackDao) FindByImage32Page(image32 string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Image32.Eq(image32)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByImage48 get first matched result by image48. | |||
| func (d *CustomerSlackDao) FindFirstByImage48(image48 string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Image48.Eq(image48)).First() | |||
| } | |||
| // FindByImage48Page get page by Image48. | |||
| func (d *CustomerSlackDao) FindByImage48Page(image48 string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Image48.Eq(image48)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByImage72 get first matched result by image72. | |||
| func (d *CustomerSlackDao) FindFirstByImage72(image72 string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Image72.Eq(image72)).First() | |||
| } | |||
| // FindByImage72Page get page by Image72. | |||
| func (d *CustomerSlackDao) FindByImage72Page(image72 string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Image72.Eq(image72)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByImage192 get first matched result by image192. | |||
| func (d *CustomerSlackDao) FindFirstByImage192(image192 string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Image192.Eq(image192)).First() | |||
| } | |||
| // FindByImage192Page get page by Image192. | |||
| func (d *CustomerSlackDao) FindByImage192Page(image192 string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Image192.Eq(image192)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByImage512 get first matched result by image512. | |||
| func (d *CustomerSlackDao) FindFirstByImage512(image512 string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Image512.Eq(image512)).First() | |||
| } | |||
| // FindByImage512Page get page by Image512. | |||
| func (d *CustomerSlackDao) FindByImage512Page(image512 string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Image512.Eq(image512)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByImageOriginal get first matched result by imageoriginal. | |||
| func (d *CustomerSlackDao) FindFirstByImageOriginal(imageoriginal string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.ImageOriginal.Eq(imageoriginal)).First() | |||
| } | |||
| // FindByImageOriginalPage get page by ImageOriginal. | |||
| func (d *CustomerSlackDao) FindByImageOriginalPage(imageoriginal string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.ImageOriginal.Eq(imageoriginal)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByTitle get first matched result by title. | |||
| func (d *CustomerSlackDao) FindFirstByTitle(title string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Title.Eq(title)).First() | |||
| } | |||
| // FindByTitlePage get page by Title. | |||
| func (d *CustomerSlackDao) FindByTitlePage(title string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Title.Eq(title)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByBotID get first matched result by botid. | |||
| func (d *CustomerSlackDao) FindFirstByBotID(botid string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.BotID.Eq(botid)).First() | |||
| } | |||
| // FindByBotIDPage get page by BotID. | |||
| func (d *CustomerSlackDao) FindByBotIDPage(botid string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.BotID.Eq(botid)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByApiAppID get first matched result by apiappid. | |||
| func (d *CustomerSlackDao) FindFirstByApiAppID(apiappid string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.ApiAppID.Eq(apiappid)).First() | |||
| } | |||
| // FindByApiAppIDPage get page by ApiAppID. | |||
| func (d *CustomerSlackDao) FindByApiAppIDPage(apiappid string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.ApiAppID.Eq(apiappid)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByStatusText get first matched result by statustext. | |||
| func (d *CustomerSlackDao) FindFirstByStatusText(statustext string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.StatusText.Eq(statustext)).First() | |||
| } | |||
| // FindByStatusTextPage get page by StatusText. | |||
| func (d *CustomerSlackDao) FindByStatusTextPage(statustext string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.StatusText.Eq(statustext)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByStatusEmoji get first matched result by statusemoji. | |||
| func (d *CustomerSlackDao) FindFirstByStatusEmoji(statusemoji string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.StatusEmoji.Eq(statusemoji)).First() | |||
| } | |||
| // FindByStatusEmojiPage get page by StatusEmoji. | |||
| func (d *CustomerSlackDao) FindByStatusEmojiPage(statusemoji string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.StatusEmoji.Eq(statusemoji)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByStatusExpiration get first matched result by statusexpiration. | |||
| func (d *CustomerSlackDao) FindFirstByStatusExpiration(statusexpiration int) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.StatusExpiration.Eq(statusexpiration)).First() | |||
| } | |||
| // FindByStatusExpirationPage get page by StatusExpiration. | |||
| func (d *CustomerSlackDao) FindByStatusExpirationPage(statusexpiration int, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.StatusExpiration.Eq(statusexpiration)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // FindFirstByTeam get first matched result by team. | |||
| func (d *CustomerSlackDao) FindFirstByTeam(team string) (*customerroles.CustomerSlack, error) { | |||
| m := d.query.CustomerSlack | |||
| return m.WithContext(d.ctx).Where(m.Team.Eq(team)).First() | |||
| } | |||
| // FindByTeamPage get page by Team. | |||
| func (d *CustomerSlackDao) FindByTeamPage(team string, offset int, limit int) ([]*customerroles.CustomerSlack, int64, error) { | |||
| m := d.query.CustomerSlack | |||
| result, count, err := m.WithContext(d.ctx).Where(m.Team.Eq(team)).FindByPage(offset, limit) | |||
| return result, count, err | |||
| } | |||
| // Update update model. | |||
| func (d *CustomerSlackDao) Update(m *customerroles.CustomerSlack) error { | |||
| res, err := d.query.WithContext(d.ctx).CustomerSlack.Updates(m) | |||
| if err != nil && res.Error != nil { | |||
| return err | |||
| } | |||
| return nil | |||
| } | |||
| // Delete delete model. | |||
| func (d *CustomerSlackDao) Delete(m ...*customerroles.CustomerSlack) error { | |||
| res, err := d.query.WithContext(d.ctx).CustomerSlack.Delete(m...) | |||
| if err != nil && res.Error != nil { | |||
| return err | |||
| } | |||
| return nil | |||
| } | |||
| // Count count matched records. | |||
| func (d *CustomerSlackDao) Count() (int64, error) { | |||
| return d.query.WithContext(d.ctx).CustomerSlack.Count() | |||
| } | |||
| /////////////////////////////////////////////////////////// | |||
| // Append your code here. // | |||
| /////////////////////////////////////////////////////////// | |||
| @@ -0,0 +1,516 @@ | |||
| // Code generated by gorm.io/gen. DO NOT EDIT. | |||
| // Code generated by gorm.io/gen. DO NOT EDIT. | |||
| // Code generated by gorm.io/gen. DO NOT EDIT. | |||
| package gen | |||
| import ( | |||
| "context" | |||
| "gorm.io/gorm" | |||
| "gorm.io/gorm/clause" | |||
| "gorm.io/gorm/schema" | |||
| "gorm.io/gen" | |||
| "gorm.io/gen/field" | |||
| "gorm.io/plugin/dbresolver" | |||
| customerroles "github.com/OpenIMSDK/OpenKF/server/internal/models/customer_roles" | |||
| ) | |||
| func newCustomerSlack(db *gorm.DB, opts ...gen.DOOption) customerSlack { | |||
| _customerSlack := customerSlack{} | |||
| _customerSlack.customerSlackDo.UseDB(db, opts...) | |||
| _customerSlack.customerSlackDo.UseModel(&customerroles.CustomerSlack{}) | |||
| tableName := _customerSlack.customerSlackDo.TableName() | |||
| _customerSlack.ALL = field.NewAsterisk(tableName) | |||
| _customerSlack.Id = field.NewUint(tableName, "id") | |||
| _customerSlack.CreatedAt = field.NewTime(tableName, "created_at") | |||
| _customerSlack.UpdatedAt = field.NewTime(tableName, "updated_at") | |||
| _customerSlack.DeletedAt = field.NewTime(tableName, "deleted_at") | |||
| _customerSlack.UUID = field.NewString(tableName, "uuid") | |||
| _customerSlack.Email = field.NewString(tableName, "email") | |||
| _customerSlack.Nickname = field.NewString(tableName, "nickname") | |||
| _customerSlack.Avatar = field.NewString(tableName, "avatar") | |||
| _customerSlack.Description = field.NewString(tableName, "description") | |||
| _customerSlack.IsEnable = field.NewBool(tableName, "is_enable") | |||
| _customerSlack.FirstName = field.NewString(tableName, "first_name") | |||
| _customerSlack.LastName = field.NewString(tableName, "last_name") | |||
| _customerSlack.RealName = field.NewString(tableName, "real_name") | |||
| _customerSlack.RealNameNormalized = field.NewString(tableName, "real_name_normalized") | |||
| _customerSlack.DisplayName = field.NewString(tableName, "display_name") | |||
| _customerSlack.DisplayNameNormalized = field.NewString(tableName, "display_name_normalized") | |||
| _customerSlack.Skype = field.NewString(tableName, "skype") | |||
| _customerSlack.Phone = field.NewString(tableName, "phone") | |||
| _customerSlack.Image24 = field.NewString(tableName, "image24") | |||
| _customerSlack.Image32 = field.NewString(tableName, "image32") | |||
| _customerSlack.Image48 = field.NewString(tableName, "image48") | |||
| _customerSlack.Image72 = field.NewString(tableName, "image72") | |||
| _customerSlack.Image192 = field.NewString(tableName, "image192") | |||
| _customerSlack.Image512 = field.NewString(tableName, "image512") | |||
| _customerSlack.ImageOriginal = field.NewString(tableName, "image_original") | |||
| _customerSlack.Title = field.NewString(tableName, "title") | |||
| _customerSlack.BotID = field.NewString(tableName, "bot_id") | |||
| _customerSlack.ApiAppID = field.NewString(tableName, "api_app_id") | |||
| _customerSlack.StatusText = field.NewString(tableName, "status_text") | |||
| _customerSlack.StatusEmoji = field.NewString(tableName, "status_emoji") | |||
| _customerSlack.StatusExpiration = field.NewInt(tableName, "status_expiration") | |||
| _customerSlack.Team = field.NewString(tableName, "team") | |||
| _customerSlack.fillFieldMap() | |||
| return _customerSlack | |||
| } | |||
| type customerSlack struct { | |||
| customerSlackDo customerSlackDo | |||
| ALL field.Asterisk | |||
| Id field.Uint | |||
| CreatedAt field.Time | |||
| UpdatedAt field.Time | |||
| DeletedAt field.Time | |||
| UUID field.String | |||
| Email field.String | |||
| Nickname field.String | |||
| Avatar field.String | |||
| Description field.String | |||
| IsEnable field.Bool | |||
| FirstName field.String | |||
| LastName field.String | |||
| RealName field.String | |||
| RealNameNormalized field.String | |||
| DisplayName field.String | |||
| DisplayNameNormalized field.String | |||
| Skype field.String | |||
| Phone field.String | |||
| Image24 field.String | |||
| Image32 field.String | |||
| Image48 field.String | |||
| Image72 field.String | |||
| Image192 field.String | |||
| Image512 field.String | |||
| ImageOriginal field.String | |||
| Title field.String | |||
| BotID field.String | |||
| ApiAppID field.String | |||
| StatusText field.String | |||
| StatusEmoji field.String | |||
| StatusExpiration field.Int | |||
| Team field.String | |||
| fieldMap map[string]field.Expr | |||
| } | |||
| func (c customerSlack) Table(newTableName string) *customerSlack { | |||
| c.customerSlackDo.UseTable(newTableName) | |||
| return c.updateTableName(newTableName) | |||
| } | |||
| func (c customerSlack) As(alias string) *customerSlack { | |||
| c.customerSlackDo.DO = *(c.customerSlackDo.As(alias).(*gen.DO)) | |||
| return c.updateTableName(alias) | |||
| } | |||
| func (c *customerSlack) updateTableName(table string) *customerSlack { | |||
| c.ALL = field.NewAsterisk(table) | |||
| c.Id = field.NewUint(table, "id") | |||
| c.CreatedAt = field.NewTime(table, "created_at") | |||
| c.UpdatedAt = field.NewTime(table, "updated_at") | |||
| c.DeletedAt = field.NewTime(table, "deleted_at") | |||
| c.UUID = field.NewString(table, "uuid") | |||
| c.Email = field.NewString(table, "email") | |||
| c.Nickname = field.NewString(table, "nickname") | |||
| c.Avatar = field.NewString(table, "avatar") | |||
| c.Description = field.NewString(table, "description") | |||
| c.IsEnable = field.NewBool(table, "is_enable") | |||
| c.FirstName = field.NewString(table, "first_name") | |||
| c.LastName = field.NewString(table, "last_name") | |||
| c.RealName = field.NewString(table, "real_name") | |||
| c.RealNameNormalized = field.NewString(table, "real_name_normalized") | |||
| c.DisplayName = field.NewString(table, "display_name") | |||
| c.DisplayNameNormalized = field.NewString(table, "display_name_normalized") | |||
| c.Skype = field.NewString(table, "skype") | |||
| c.Phone = field.NewString(table, "phone") | |||
| c.Image24 = field.NewString(table, "image24") | |||
| c.Image32 = field.NewString(table, "image32") | |||
| c.Image48 = field.NewString(table, "image48") | |||
| c.Image72 = field.NewString(table, "image72") | |||
| c.Image192 = field.NewString(table, "image192") | |||
| c.Image512 = field.NewString(table, "image512") | |||
| c.ImageOriginal = field.NewString(table, "image_original") | |||
| c.Title = field.NewString(table, "title") | |||
| c.BotID = field.NewString(table, "bot_id") | |||
| c.ApiAppID = field.NewString(table, "api_app_id") | |||
| c.StatusText = field.NewString(table, "status_text") | |||
| c.StatusEmoji = field.NewString(table, "status_emoji") | |||
| c.StatusExpiration = field.NewInt(table, "status_expiration") | |||
| c.Team = field.NewString(table, "team") | |||
| c.fillFieldMap() | |||
| return c | |||
| } | |||
| func (c *customerSlack) WithContext(ctx context.Context) ICustomerSlackDo { | |||
| return c.customerSlackDo.WithContext(ctx) | |||
| } | |||
| func (c customerSlack) TableName() string { return c.customerSlackDo.TableName() } | |||
| func (c customerSlack) Alias() string { return c.customerSlackDo.Alias() } | |||
| func (c *customerSlack) GetFieldByName(fieldName string) (field.OrderExpr, bool) { | |||
| _f, ok := c.fieldMap[fieldName] | |||
| if !ok || _f == nil { | |||
| return nil, false | |||
| } | |||
| _oe, ok := _f.(field.OrderExpr) | |||
| return _oe, ok | |||
| } | |||
| func (c *customerSlack) fillFieldMap() { | |||
| c.fieldMap = make(map[string]field.Expr, 32) | |||
| c.fieldMap["id"] = c.Id | |||
| c.fieldMap["created_at"] = c.CreatedAt | |||
| c.fieldMap["updated_at"] = c.UpdatedAt | |||
| c.fieldMap["deleted_at"] = c.DeletedAt | |||
| c.fieldMap["uuid"] = c.UUID | |||
| c.fieldMap["email"] = c.Email | |||
| c.fieldMap["nickname"] = c.Nickname | |||
| c.fieldMap["avatar"] = c.Avatar | |||
| c.fieldMap["description"] = c.Description | |||
| c.fieldMap["is_enable"] = c.IsEnable | |||
| c.fieldMap["first_name"] = c.FirstName | |||
| c.fieldMap["last_name"] = c.LastName | |||
| c.fieldMap["real_name"] = c.RealName | |||
| c.fieldMap["real_name_normalized"] = c.RealNameNormalized | |||
| c.fieldMap["display_name"] = c.DisplayName | |||
| c.fieldMap["display_name_normalized"] = c.DisplayNameNormalized | |||
| c.fieldMap["skype"] = c.Skype | |||
| c.fieldMap["phone"] = c.Phone | |||
| c.fieldMap["image24"] = c.Image24 | |||
| c.fieldMap["image32"] = c.Image32 | |||
| c.fieldMap["image48"] = c.Image48 | |||
| c.fieldMap["image72"] = c.Image72 | |||
| c.fieldMap["image192"] = c.Image192 | |||
| c.fieldMap["image512"] = c.Image512 | |||
| c.fieldMap["image_original"] = c.ImageOriginal | |||
| c.fieldMap["title"] = c.Title | |||
| c.fieldMap["bot_id"] = c.BotID | |||
| c.fieldMap["api_app_id"] = c.ApiAppID | |||
| c.fieldMap["status_text"] = c.StatusText | |||
| c.fieldMap["status_emoji"] = c.StatusEmoji | |||
| c.fieldMap["status_expiration"] = c.StatusExpiration | |||
| c.fieldMap["team"] = c.Team | |||
| } | |||
| func (c customerSlack) clone(db *gorm.DB) customerSlack { | |||
| c.customerSlackDo.ReplaceConnPool(db.Statement.ConnPool) | |||
| return c | |||
| } | |||
| func (c customerSlack) replaceDB(db *gorm.DB) customerSlack { | |||
| c.customerSlackDo.ReplaceDB(db) | |||
| return c | |||
| } | |||
| type customerSlackDo struct{ gen.DO } | |||
| type ICustomerSlackDo interface { | |||
| gen.SubQuery | |||
| Debug() ICustomerSlackDo | |||
| WithContext(ctx context.Context) ICustomerSlackDo | |||
| WithResult(fc func(tx gen.Dao)) gen.ResultInfo | |||
| ReplaceDB(db *gorm.DB) | |||
| ReadDB() ICustomerSlackDo | |||
| WriteDB() ICustomerSlackDo | |||
| As(alias string) gen.Dao | |||
| Session(config *gorm.Session) ICustomerSlackDo | |||
| Columns(cols ...field.Expr) gen.Columns | |||
| Clauses(conds ...clause.Expression) ICustomerSlackDo | |||
| Not(conds ...gen.Condition) ICustomerSlackDo | |||
| Or(conds ...gen.Condition) ICustomerSlackDo | |||
| Select(conds ...field.Expr) ICustomerSlackDo | |||
| Where(conds ...gen.Condition) ICustomerSlackDo | |||
| Order(conds ...field.Expr) ICustomerSlackDo | |||
| Distinct(cols ...field.Expr) ICustomerSlackDo | |||
| Omit(cols ...field.Expr) ICustomerSlackDo | |||
| Join(table schema.Tabler, on ...field.Expr) ICustomerSlackDo | |||
| LeftJoin(table schema.Tabler, on ...field.Expr) ICustomerSlackDo | |||
| RightJoin(table schema.Tabler, on ...field.Expr) ICustomerSlackDo | |||
| Group(cols ...field.Expr) ICustomerSlackDo | |||
| Having(conds ...gen.Condition) ICustomerSlackDo | |||
| Limit(limit int) ICustomerSlackDo | |||
| Offset(offset int) ICustomerSlackDo | |||
| Count() (count int64, err error) | |||
| Scopes(funcs ...func(gen.Dao) gen.Dao) ICustomerSlackDo | |||
| Unscoped() ICustomerSlackDo | |||
| Create(values ...*customerroles.CustomerSlack) error | |||
| CreateInBatches(values []*customerroles.CustomerSlack, batchSize int) error | |||
| Save(values ...*customerroles.CustomerSlack) error | |||
| First() (*customerroles.CustomerSlack, error) | |||
| Take() (*customerroles.CustomerSlack, error) | |||
| Last() (*customerroles.CustomerSlack, error) | |||
| Find() ([]*customerroles.CustomerSlack, error) | |||
| FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*customerroles.CustomerSlack, err error) | |||
| FindInBatches(result *[]*customerroles.CustomerSlack, batchSize int, fc func(tx gen.Dao, batch int) error) error | |||
| Pluck(column field.Expr, dest interface{}) error | |||
| Delete(...*customerroles.CustomerSlack) (info gen.ResultInfo, err error) | |||
| Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error) | |||
| UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) | |||
| Updates(value interface{}) (info gen.ResultInfo, err error) | |||
| UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error) | |||
| UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error) | |||
| UpdateColumns(value interface{}) (info gen.ResultInfo, err error) | |||
| UpdateFrom(q gen.SubQuery) gen.Dao | |||
| Attrs(attrs ...field.AssignExpr) ICustomerSlackDo | |||
| Assign(attrs ...field.AssignExpr) ICustomerSlackDo | |||
| Joins(fields ...field.RelationField) ICustomerSlackDo | |||
| Preload(fields ...field.RelationField) ICustomerSlackDo | |||
| FirstOrInit() (*customerroles.CustomerSlack, error) | |||
| FirstOrCreate() (*customerroles.CustomerSlack, error) | |||
| FindByPage(offset int, limit int) (result []*customerroles.CustomerSlack, count int64, err error) | |||
| ScanByPage(result interface{}, offset int, limit int) (count int64, err error) | |||
| Scan(result interface{}) (err error) | |||
| Returning(value interface{}, columns ...string) ICustomerSlackDo | |||
| UnderlyingDB() *gorm.DB | |||
| schema.Tabler | |||
| } | |||
| func (c customerSlackDo) Debug() ICustomerSlackDo { | |||
| return c.withDO(c.DO.Debug()) | |||
| } | |||
| func (c customerSlackDo) WithContext(ctx context.Context) ICustomerSlackDo { | |||
| return c.withDO(c.DO.WithContext(ctx)) | |||
| } | |||
| func (c customerSlackDo) ReadDB() ICustomerSlackDo { | |||
| return c.Clauses(dbresolver.Read) | |||
| } | |||
| func (c customerSlackDo) WriteDB() ICustomerSlackDo { | |||
| return c.Clauses(dbresolver.Write) | |||
| } | |||
| func (c customerSlackDo) Session(config *gorm.Session) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Session(config)) | |||
| } | |||
| func (c customerSlackDo) Clauses(conds ...clause.Expression) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Clauses(conds...)) | |||
| } | |||
| func (c customerSlackDo) Returning(value interface{}, columns ...string) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Returning(value, columns...)) | |||
| } | |||
| func (c customerSlackDo) Not(conds ...gen.Condition) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Not(conds...)) | |||
| } | |||
| func (c customerSlackDo) Or(conds ...gen.Condition) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Or(conds...)) | |||
| } | |||
| func (c customerSlackDo) Select(conds ...field.Expr) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Select(conds...)) | |||
| } | |||
| func (c customerSlackDo) Where(conds ...gen.Condition) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Where(conds...)) | |||
| } | |||
| func (c customerSlackDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) ICustomerSlackDo { | |||
| return c.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB())) | |||
| } | |||
| func (c customerSlackDo) Order(conds ...field.Expr) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Order(conds...)) | |||
| } | |||
| func (c customerSlackDo) Distinct(cols ...field.Expr) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Distinct(cols...)) | |||
| } | |||
| func (c customerSlackDo) Omit(cols ...field.Expr) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Omit(cols...)) | |||
| } | |||
| func (c customerSlackDo) Join(table schema.Tabler, on ...field.Expr) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Join(table, on...)) | |||
| } | |||
| func (c customerSlackDo) LeftJoin(table schema.Tabler, on ...field.Expr) ICustomerSlackDo { | |||
| return c.withDO(c.DO.LeftJoin(table, on...)) | |||
| } | |||
| func (c customerSlackDo) RightJoin(table schema.Tabler, on ...field.Expr) ICustomerSlackDo { | |||
| return c.withDO(c.DO.RightJoin(table, on...)) | |||
| } | |||
| func (c customerSlackDo) Group(cols ...field.Expr) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Group(cols...)) | |||
| } | |||
| func (c customerSlackDo) Having(conds ...gen.Condition) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Having(conds...)) | |||
| } | |||
| func (c customerSlackDo) Limit(limit int) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Limit(limit)) | |||
| } | |||
| func (c customerSlackDo) Offset(offset int) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Offset(offset)) | |||
| } | |||
| func (c customerSlackDo) Scopes(funcs ...func(gen.Dao) gen.Dao) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Scopes(funcs...)) | |||
| } | |||
| func (c customerSlackDo) Unscoped() ICustomerSlackDo { | |||
| return c.withDO(c.DO.Unscoped()) | |||
| } | |||
| func (c customerSlackDo) Create(values ...*customerroles.CustomerSlack) error { | |||
| if len(values) == 0 { | |||
| return nil | |||
| } | |||
| return c.DO.Create(values) | |||
| } | |||
| func (c customerSlackDo) CreateInBatches(values []*customerroles.CustomerSlack, batchSize int) error { | |||
| return c.DO.CreateInBatches(values, batchSize) | |||
| } | |||
| // Save : !!! underlying implementation is different with GORM | |||
| // The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values) | |||
| func (c customerSlackDo) Save(values ...*customerroles.CustomerSlack) error { | |||
| if len(values) == 0 { | |||
| return nil | |||
| } | |||
| return c.DO.Save(values) | |||
| } | |||
| func (c customerSlackDo) First() (*customerroles.CustomerSlack, error) { | |||
| if result, err := c.DO.First(); err != nil { | |||
| return nil, err | |||
| } else { | |||
| return result.(*customerroles.CustomerSlack), nil | |||
| } | |||
| } | |||
| func (c customerSlackDo) Take() (*customerroles.CustomerSlack, error) { | |||
| if result, err := c.DO.Take(); err != nil { | |||
| return nil, err | |||
| } else { | |||
| return result.(*customerroles.CustomerSlack), nil | |||
| } | |||
| } | |||
| func (c customerSlackDo) Last() (*customerroles.CustomerSlack, error) { | |||
| if result, err := c.DO.Last(); err != nil { | |||
| return nil, err | |||
| } else { | |||
| return result.(*customerroles.CustomerSlack), nil | |||
| } | |||
| } | |||
| func (c customerSlackDo) Find() ([]*customerroles.CustomerSlack, error) { | |||
| result, err := c.DO.Find() | |||
| return result.([]*customerroles.CustomerSlack), err | |||
| } | |||
| func (c customerSlackDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*customerroles.CustomerSlack, err error) { | |||
| buf := make([]*customerroles.CustomerSlack, 0, batchSize) | |||
| err = c.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error { | |||
| defer func() { results = append(results, buf...) }() | |||
| return fc(tx, batch) | |||
| }) | |||
| return results, err | |||
| } | |||
| func (c customerSlackDo) FindInBatches(result *[]*customerroles.CustomerSlack, batchSize int, fc func(tx gen.Dao, batch int) error) error { | |||
| return c.DO.FindInBatches(result, batchSize, fc) | |||
| } | |||
| func (c customerSlackDo) Attrs(attrs ...field.AssignExpr) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Attrs(attrs...)) | |||
| } | |||
| func (c customerSlackDo) Assign(attrs ...field.AssignExpr) ICustomerSlackDo { | |||
| return c.withDO(c.DO.Assign(attrs...)) | |||
| } | |||
| func (c customerSlackDo) Joins(fields ...field.RelationField) ICustomerSlackDo { | |||
| for _, _f := range fields { | |||
| c = *c.withDO(c.DO.Joins(_f)) | |||
| } | |||
| return &c | |||
| } | |||
| func (c customerSlackDo) Preload(fields ...field.RelationField) ICustomerSlackDo { | |||
| for _, _f := range fields { | |||
| c = *c.withDO(c.DO.Preload(_f)) | |||
| } | |||
| return &c | |||
| } | |||
| func (c customerSlackDo) FirstOrInit() (*customerroles.CustomerSlack, error) { | |||
| if result, err := c.DO.FirstOrInit(); err != nil { | |||
| return nil, err | |||
| } else { | |||
| return result.(*customerroles.CustomerSlack), nil | |||
| } | |||
| } | |||
| func (c customerSlackDo) FirstOrCreate() (*customerroles.CustomerSlack, error) { | |||
| if result, err := c.DO.FirstOrCreate(); err != nil { | |||
| return nil, err | |||
| } else { | |||
| return result.(*customerroles.CustomerSlack), nil | |||
| } | |||
| } | |||
| func (c customerSlackDo) FindByPage(offset int, limit int) (result []*customerroles.CustomerSlack, count int64, err error) { | |||
| result, err = c.Offset(offset).Limit(limit).Find() | |||
| if err != nil { | |||
| return | |||
| } | |||
| if size := len(result); 0 < limit && 0 < size && size < limit { | |||
| count = int64(size + offset) | |||
| return | |||
| } | |||
| count, err = c.Offset(-1).Limit(-1).Count() | |||
| return | |||
| } | |||
| func (c customerSlackDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) { | |||
| count, err = c.Count() | |||
| if err != nil { | |||
| return | |||
| } | |||
| err = c.Offset(offset).Limit(limit).Scan(result) | |||
| return | |||
| } | |||
| func (c customerSlackDo) Scan(result interface{}) (err error) { | |||
| return c.DO.Scan(result) | |||
| } | |||
| func (c customerSlackDo) Delete(models ...*customerroles.CustomerSlack) (result gen.ResultInfo, err error) { | |||
| return c.DO.Delete(models) | |||
| } | |||
| func (c *customerSlackDo) withDO(do gen.Dao) *customerSlackDo { | |||
| c.DO = *do.(*gen.DO) | |||
| return c | |||
| } | |||
| @@ -16,15 +16,17 @@ import ( | |||
| ) | |||
| var ( | |||
| Q = new(Query) | |||
| SysBot *sysBot | |||
| SysCommunity *sysCommunity | |||
| SysCustomer *sysCustomer | |||
| SysUser *sysUser | |||
| Q = new(Query) | |||
| CustomerSlack *customerSlack | |||
| SysBot *sysBot | |||
| SysCommunity *sysCommunity | |||
| SysCustomer *sysCustomer | |||
| SysUser *sysUser | |||
| ) | |||
| func SetDefault(db *gorm.DB, opts ...gen.DOOption) { | |||
| *Q = *Use(db, opts...) | |||
| CustomerSlack = &Q.CustomerSlack | |||
| SysBot = &Q.SysBot | |||
| SysCommunity = &Q.SysCommunity | |||
| SysCustomer = &Q.SysCustomer | |||
| @@ -33,32 +35,35 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) { | |||
| func Use(db *gorm.DB, opts ...gen.DOOption) *Query { | |||
| return &Query{ | |||
| db: db, | |||
| SysBot: newSysBot(db, opts...), | |||
| SysCommunity: newSysCommunity(db, opts...), | |||
| SysCustomer: newSysCustomer(db, opts...), | |||
| SysUser: newSysUser(db, opts...), | |||
| db: db, | |||
| CustomerSlack: newCustomerSlack(db, opts...), | |||
| SysBot: newSysBot(db, opts...), | |||
| SysCommunity: newSysCommunity(db, opts...), | |||
| SysCustomer: newSysCustomer(db, opts...), | |||
| SysUser: newSysUser(db, opts...), | |||
| } | |||
| } | |||
| type Query struct { | |||
| db *gorm.DB | |||
| SysBot sysBot | |||
| SysCommunity sysCommunity | |||
| SysCustomer sysCustomer | |||
| SysUser sysUser | |||
| CustomerSlack customerSlack | |||
| SysBot sysBot | |||
| SysCommunity sysCommunity | |||
| SysCustomer sysCustomer | |||
| SysUser sysUser | |||
| } | |||
| func (q *Query) Available() bool { return q.db != nil } | |||
| func (q *Query) clone(db *gorm.DB) *Query { | |||
| return &Query{ | |||
| db: db, | |||
| SysBot: q.SysBot.clone(db), | |||
| SysCommunity: q.SysCommunity.clone(db), | |||
| SysCustomer: q.SysCustomer.clone(db), | |||
| SysUser: q.SysUser.clone(db), | |||
| db: db, | |||
| CustomerSlack: q.CustomerSlack.clone(db), | |||
| SysBot: q.SysBot.clone(db), | |||
| SysCommunity: q.SysCommunity.clone(db), | |||
| SysCustomer: q.SysCustomer.clone(db), | |||
| SysUser: q.SysUser.clone(db), | |||
| } | |||
| } | |||
| @@ -72,27 +77,30 @@ func (q *Query) WriteDB() *Query { | |||
| func (q *Query) ReplaceDB(db *gorm.DB) *Query { | |||
| return &Query{ | |||
| db: db, | |||
| SysBot: q.SysBot.replaceDB(db), | |||
| SysCommunity: q.SysCommunity.replaceDB(db), | |||
| SysCustomer: q.SysCustomer.replaceDB(db), | |||
| SysUser: q.SysUser.replaceDB(db), | |||
| db: db, | |||
| CustomerSlack: q.CustomerSlack.replaceDB(db), | |||
| SysBot: q.SysBot.replaceDB(db), | |||
| SysCommunity: q.SysCommunity.replaceDB(db), | |||
| SysCustomer: q.SysCustomer.replaceDB(db), | |||
| SysUser: q.SysUser.replaceDB(db), | |||
| } | |||
| } | |||
| type queryCtx struct { | |||
| SysBot ISysBotDo | |||
| SysCommunity ISysCommunityDo | |||
| SysCustomer ISysCustomerDo | |||
| SysUser ISysUserDo | |||
| CustomerSlack ICustomerSlackDo | |||
| SysBot ISysBotDo | |||
| SysCommunity ISysCommunityDo | |||
| SysCustomer ISysCustomerDo | |||
| SysUser ISysUserDo | |||
| } | |||
| func (q *Query) WithContext(ctx context.Context) *queryCtx { | |||
| return &queryCtx{ | |||
| SysBot: q.SysBot.WithContext(ctx), | |||
| SysCommunity: q.SysCommunity.WithContext(ctx), | |||
| SysCustomer: q.SysCustomer.WithContext(ctx), | |||
| SysUser: q.SysUser.WithContext(ctx), | |||
| CustomerSlack: q.CustomerSlack.WithContext(ctx), | |||
| SysBot: q.SysBot.WithContext(ctx), | |||
| SysCommunity: q.SysCommunity.WithContext(ctx), | |||
| SysCustomer: q.SysCustomer.WithContext(ctx), | |||
| SysUser: q.SysUser.WithContext(ctx), | |||
| } | |||
| } | |||
| @@ -0,0 +1,50 @@ | |||
| // Copyright © 2023 OpenIM open source community. All rights reserved. | |||
| // | |||
| // Licensed under the Apache License, Version 2.0 (the "License"); | |||
| // you may not use this file except in compliance with the License. | |||
| // You may obtain a copy of the License at | |||
| // | |||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software | |||
| // distributed under the License is distributed on an "AS IS" BASIS, | |||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| // See the License for the specific language governing permissions and | |||
| // limitations under the License. | |||
| package customerroles | |||
| import "github.com/OpenIMSDK/OpenKF/server/internal/models/base" | |||
| // CustomerSlack customer from slack model. | |||
| type CustomerSlack struct { | |||
| base.UserBase // UserID in uuid => type+userid. example: slackU05BL9CAN7N | |||
| FirstName string `json:"first_name" gorm:"column:first_name;type:varchar(256);comment:'First name'"` | |||
| LastName string `json:"last_name" gorm:"column:last_name;type:varchar(256);comment:'Last name'"` | |||
| RealName string `json:"real_name" gorm:"column:real_name;type:varchar(256);comment:'Real name'"` | |||
| RealNameNormalized string `json:"real_name_normalized" gorm:"column:real_name_normalized;type:varchar(256);comment:'Real name normalized'"` | |||
| DisplayName string `json:"display_name" gorm:"column:display_name;type:varchar(256);comment:'Display name'"` | |||
| DisplayNameNormalized string `json:"display_name_normalized" gorm:"column:display_name_normalized;type:varchar(256);comment:'Display name normalized'"` | |||
| Skype string `json:"skype" gorm:"column:skype;type:varchar(256);comment:'Skype'"` | |||
| Phone string `json:"phone" gorm:"column:phone;type:varchar(256);comment:'Phone'"` | |||
| Image24 string `json:"image_24" gorm:"column:image_24;type:varchar(256);comment:'Image 24'"` | |||
| Image32 string `json:"image_32" gorm:"column:image_32;type:varchar(256);comment:'Image 32'"` | |||
| Image48 string `json:"image_48" gorm:"column:image_48;type:varchar(256);comment:'Image 48'"` | |||
| Image72 string `json:"image_72" gorm:"column:image_72;type:varchar(256);comment:'Image 72'"` | |||
| Image192 string `json:"image_192" gorm:"column:image_192;type:varchar(256);comment:'Image 192'"` | |||
| Image512 string `json:"image_512" gorm:"column:image_512;type:varchar(256);comment:'Image 512'"` | |||
| ImageOriginal string `json:"image_original" gorm:"column:image_original;type:varchar(256);comment:'Image original'"` | |||
| Title string `json:"title" gorm:"column:title;type:varchar(256);comment:'Title'"` | |||
| BotID string `json:"bot_id,omitempty" gorm:"column:bot_id;type:varchar(256);comment:'Bot id'"` | |||
| ApiAppID string `json:"api_app_id,omitempty" gorm:"column:api_app_id;type:varchar(256);comment:'Api app id'"` | |||
| StatusText string `json:"status_text,omitempty" gorm:"column:status_text;type:varchar(256);comment:'Status text'"` | |||
| StatusEmoji string `json:"status_emoji,omitempty" gorm:"column:status_emoji;type:varchar(256);comment:'Status emoji'"` | |||
| StatusExpiration int `json:"status_expiration" gorm:"column:status_expiration;type:int(11);comment:'Status expiration'"` | |||
| Team string `json:"team" gorm:"column:team;type:varchar(256);comment:'Team'"` | |||
| } | |||
| // TableName table name. | |||
| func (CustomerSlack) TableName() string { | |||
| return "customer_slack" | |||
| } | |||
| @@ -0,0 +1,64 @@ | |||
| // Copyright © 2023 OpenIM open source community. All rights reserved. | |||
| // | |||
| // Licensed under the Apache License, Version 2.0 (the "License"); | |||
| // you may not use this file except in compliance with the License. | |||
| // You may obtain a copy of the License at | |||
| // | |||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software | |||
| // distributed under the License is distributed on an "AS IS" BASIS, | |||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| // See the License for the specific language governing permissions and | |||
| // limitations under the License. | |||
| package slackcmd | |||
| import ( | |||
| "context" | |||
| "strings" | |||
| "github.com/shomali11/slacker" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/conn/client" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/service" | |||
| "github.com/OpenIMSDK/OpenKF/server/pkg/log" | |||
| ) | |||
| // InitSlackListen init slack socket listen. | |||
| func InitSlackListen() { | |||
| bot := client.InitSlack() | |||
| svc := service.NewSlackService(context.Background()) | |||
| // receive all @ message | |||
| bot.Command("<question>", &slacker.CommandDefinition{ | |||
| Handler: func(bc slacker.BotContext, r slacker.Request, w slacker.ResponseWriter) { | |||
| // find or create a customer | |||
| messageEvent := bc.Event() | |||
| senderId, _, err := svc.CreateCustomer(messageEvent.UserID, messageEvent.UserProfile) | |||
| if err != nil { | |||
| log.Errorf("Slack", "CreateCustomer failed: %s", err.Error()) | |||
| return | |||
| } | |||
| question := r.Param("question") | |||
| // TODO: remove id from question | |||
| words := strings.Split(question, " ") | |||
| question = strings.Join(words[1:], " ") | |||
| // TODO: get staff id and get into im process. | |||
| _ = senderId | |||
| _ = question | |||
| _ = w.Reply("senderId", slacker.WithThreadReply(true)) | |||
| }, | |||
| }) | |||
| ctx, cancel := context.WithCancel(context.Background()) | |||
| defer cancel() | |||
| if err := bot.Listen(ctx); err != nil { | |||
| log.Panicf("Slack Client", "Connection failed: %s", err.Error()) | |||
| } | |||
| } | |||
| @@ -0,0 +1,15 @@ | |||
| // Copyright © 2023 OpenIM open source community. All rights reserved. | |||
| // | |||
| // Licensed under the Apache License, Version 2.0 (the "License"); | |||
| // you may not use this file except in compliance with the License. | |||
| // You may obtain a copy of the License at | |||
| // | |||
| // http://www.apache.org/licenses/LICENSE-2.0 | |||
| // | |||
| // Unless required by applicable law or agreed to in writing, software | |||
| // distributed under the License is distributed on an "AS IS" BASIS, | |||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
| // See the License for the specific language governing permissions and | |||
| // limitations under the License. | |||
| package staffdispatch | |||
| @@ -15,22 +15,37 @@ | |||
| package service | |||
| import ( | |||
| "context" | |||
| "fmt" | |||
| "github.com/slack-go/slack" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/config" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/dal/dao" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/models/base" | |||
| customerroles "github.com/OpenIMSDK/OpenKF/server/internal/models/customer_roles" | |||
| responseparams "github.com/OpenIMSDK/OpenKF/server/internal/params/response" | |||
| "github.com/gin-gonic/gin" | |||
| "github.com/OpenIMSDK/OpenKF/server/pkg/openim/param/request" | |||
| "github.com/OpenIMSDK/OpenKF/server/pkg/utils" | |||
| ) | |||
| // SLACK_PERFIX do not use separator. | |||
| const SLACK_PERFIX = "slack" | |||
| // SlackService bot service. | |||
| type SlackService struct { | |||
| Service | |||
| CustomerSlackDao *dao.CustomerSlackDao | |||
| } | |||
| // NewSlackService return new service with gin context. | |||
| func NewSlackService(c *gin.Context) *SlackService { | |||
| // NewSlackService return new service with Background context. | |||
| func NewSlackService(ctx context.Context) *SlackService { | |||
| return &SlackService{ | |||
| Service: Service{ | |||
| ctx: c, | |||
| ctx: ctx, | |||
| }, | |||
| CustomerSlackDao: dao.NewCustomerSlackDao(), | |||
| } | |||
| } | |||
| @@ -46,3 +61,76 @@ func (svc *SlackService) GetSlackConfig() (*responseparams.SlackConfigResponse, | |||
| VerificationToken: config.Config.Slack.VerificationToken, | |||
| }, nil | |||
| } | |||
| // CreateCustomer create customer if not exists. | |||
| func (svc *SlackService) CreateCustomer(userId string, profile *slack.UserProfile) (string, uint, error) { | |||
| // check if exists | |||
| temp, err := svc.CustomerSlackDao.FindFirstByUUID(userId) | |||
| if temp != nil || err == nil { | |||
| return temp.UUID, temp.Id, err | |||
| } | |||
| // Set unique email | |||
| if profile.Email == "" { | |||
| profile.Email = fmt.Sprintf("%s %s", "NOEMAIL", utils.GenUUIDWithoutHyphen()) | |||
| } | |||
| customerSlack := customerroles.CustomerSlack{ | |||
| UserBase: base.UserBase{ | |||
| // UUID: fmt.Sprintf("%s%s", SLACK_PERFIX, userId), | |||
| UUID: userId, | |||
| Email: profile.Email, | |||
| Nickname: profile.FirstName, | |||
| Avatar: profile.Image512, | |||
| Description: profile.Title, | |||
| IsEnable: true, | |||
| }, | |||
| FirstName: profile.FirstName, | |||
| LastName: profile.LastName, | |||
| RealName: profile.RealName, | |||
| RealNameNormalized: profile.RealNameNormalized, | |||
| DisplayName: profile.DisplayName, | |||
| DisplayNameNormalized: profile.DisplayNameNormalized, | |||
| Skype: profile.Skype, | |||
| Phone: profile.Phone, | |||
| Image24: profile.Image24, | |||
| Image32: profile.Image32, | |||
| Image48: profile.Image48, | |||
| Image72: profile.Image72, | |||
| Image192: profile.Image192, | |||
| Image512: profile.Image512, | |||
| ImageOriginal: profile.ImageOriginal, | |||
| Title: profile.Title, | |||
| BotID: profile.BotID, | |||
| ApiAppID: profile.ApiAppID, | |||
| StatusText: profile.StatusText, | |||
| StatusEmoji: profile.StatusEmoji, | |||
| StatusExpiration: profile.StatusExpiration, | |||
| Team: profile.Team, | |||
| } | |||
| if err = svc.CustomerSlackDao.Create(&customerSlack); err != nil { | |||
| return customerSlack.UUID, 0, err | |||
| } | |||
| s, _ := svc.CustomerSlackDao.FindFirstByUUID(userId) | |||
| param := &request.RegisterUserParams{ | |||
| Secret: config.Config.OpenIM.Secret, | |||
| Users: []request.User{ | |||
| { | |||
| UserID: userId, | |||
| Nickname: customerSlack.Nickname, | |||
| FaceURL: "", // Use OpenKF avatar | |||
| }, | |||
| }, | |||
| } | |||
| ok, err := registerUserToOpenIM(param) | |||
| if err != nil || !ok { | |||
| // Assume that the user has been created/deleted successfully | |||
| _ = svc.CustomerSlackDao.Delete(s) | |||
| return userId, s.Id, err | |||
| } | |||
| return userId, s.Id, nil | |||
| } | |||
| @@ -22,6 +22,7 @@ import ( | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/conn/client" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/conn/db" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/middleware/hooks" | |||
| slackcmd "github.com/OpenIMSDK/OpenKF/server/internal/msg/slack_cmd" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/router" | |||
| "github.com/OpenIMSDK/OpenKF/server/internal/utils" | |||
| "github.com/OpenIMSDK/OpenKF/server/pkg/log" | |||
| @@ -58,6 +59,9 @@ func init() { | |||
| func main() { | |||
| serverAddress := fmt.Sprintf("%s:%d", config.Config.Server.Ip, config.Config.Server.Port) | |||
| // Add slack server | |||
| go slackcmd.InitSlackListen() | |||
| r := router.InitRouter() | |||
| s := server.InitServer(serverAddress, r) | |||
| log.Error("server start error: %v", s.ListenAndServe().Error()) | |||