diff --git a/api/admin/department.api b/api/admin/department.api index f5ce585f..7e781804 100644 --- a/api/admin/department.api +++ b/api/admin/department.api @@ -56,7 +56,7 @@ type ( type ( CreateDepartmentRequest { DepName string `json:"depName"` - LeaderId int64 `json:"leaderId"` + LeaderUuid string `json:"leaderUuid"` PId int64 `json:"pId"` Desc string `json:"desc,optional"` PhoneNumber string `json:"phoneNumber,optional"` diff --git a/api/admin/user.api b/api/admin/user.api index 03188ba0..e34d27f1 100644 --- a/api/admin/user.api +++ b/api/admin/user.api @@ -21,7 +21,7 @@ service PowerX { @doc "查询员工" @handler GetUser - get /users/:id (GetUserRequest) returns (GetUserReply) + get /users/:uuid (GetUserRequest) returns (GetUserReply) @doc "List员工" @handler ListUsers @@ -33,11 +33,11 @@ service PowerX { @doc "编辑员工信息" @handler UpdateUser - patch /users/:id (UpdateUserRequest) returns (UpdateUserReply) + patch /users/:uuid (UpdateUserRequest) returns (UpdateUserReply) @doc "删除员工" @handler DeleteUser - delete /users/:id (DeleteUserRequest) returns (DeleteUserReply) + delete /users/:uuid (DeleteUserRequest) returns (DeleteUserReply) @doc "重设密码" @handler ResetPassword @@ -46,7 +46,7 @@ service PowerX { type ( GetUserRequest { - Id int64 `path:"id"` + Uuid string `path:"uuid"` } GetUserReply { @@ -136,7 +136,7 @@ type ( type ( UpdateUserRequest { - Id int64 `path:"id"` + Uuid string `path:"uuid"` Name string `json:"name,optional"` NickName string `json:"nickName,optional"` Desc string `json:"desc,optional"` @@ -159,17 +159,17 @@ type ( type ( DeleteUserRequest { - Id int64 `path:"id"` + Uuid string `path:"uuid"` } DeleteUserReply { - Id int64 `json:"id"` + Uuid string `json:"uuid"` } ) type ( ResetPasswordRequest { - UserId int64 `json:"userId"` + UserUuid string `json:"userUuid"` } ResetPasswordReply { diff --git a/api/openapi/provider/brainx/demo.api b/api/openapi/provider/brainx/demo.api new file mode 100644 index 00000000..5a0613a9 --- /dev/null +++ b/api/openapi/provider/brainx/demo.api @@ -0,0 +1,40 @@ +syntax = "v1" + +info( + title: "Provider Demo Open API of BrainX" + desc: "This is a api of Open API in Artisan Cloud" + author: "Matrix-X" + email: "matrix-x@artisan-cloud.com" + version: "v1" +) + +@server( + group: openapi/provider/brainx + prefix: /openapi/v1/provider/brainx + middleware: OpenAPIJWTAuth +) + +service PowerX { + @doc "hello world api for provider demo" + @handler HelloWorld + get /hello-world returns (HelloWorldResponse) + + @doc "timeout api for provider demo" + @handler EchoLongTime + post /echo-long-time (EchoLongTimeRequest) returns (EchoLongTimeResponse) +} + + + +type ( + HelloWorldResponse { + Message string `json:"message"` + } + + EchoLongTimeRequest { + Timeout int `json:"timeout"` + } + EchoLongTimeResponse { + Message string `json:"message"` + } +) \ No newline at end of file diff --git a/cmd/ctl/database/seed/mediaresource.go b/cmd/ctl/database/seed/mediaresource.go index d1323baf..7643399c 100644 --- a/cmd/ctl/database/seed/mediaresource.go +++ b/cmd/ctl/database/seed/mediaresource.go @@ -3,8 +3,10 @@ package seed import ( "PowerX/internal/config" "PowerX/internal/model/media" + "PowerX/internal/model/powermodel" "PowerX/internal/uc/powerx" "PowerX/pkg/httpx" + "PowerX/pkg/securityx" "PowerX/pkg/slicex" "fmt" "github.com/pkg/errors" @@ -37,6 +39,7 @@ func DefaultMediaResource(db *gorm.DB, conf *config.Config) (data []*media.Media path := path2.Join(powerx.DefaultStoragePath, "shop") coverImage := ProductCoverImage(ucMediaResource.LocalStorageUrl, path) detailImages := ProductDetailImages(ucMediaResource.LocalStorageUrl, path) + //fmt2.Dump(coverImage, detailImages) data = slicex.Concatenate(data, coverImage, detailImages) return data @@ -46,6 +49,9 @@ func ProductCoverImage(url string, name string) []*media.MediaResource { imageUrl, _ := httpx.AppendURIs(url, fmt.Sprintf("%s/0.png", name)) return []*media.MediaResource{ { + PowerUUIDModel: powermodel.PowerUUIDModel{ + UUID: securityx.GenerateUUID(), + }, Url: imageUrl, IsLocalStored: true, }, @@ -58,6 +64,9 @@ func ProductDetailImages(url string, path string) []*media.MediaResource { imageUrl, _ := httpx.AppendURIs(url, path, fmt.Sprintf("%d.png", i+1)) urls = append(urls, &media.MediaResource{ + PowerUUIDModel: powermodel.PowerUUIDModel{ + UUID: securityx.GenerateUUID(), + }, Url: imageUrl, IsLocalStored: true, }) diff --git a/internal/handler/routes.go b/internal/handler/routes.go index 29118615..4e6af409 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -1415,21 +1415,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { rest.WithPrefix("/api/v1/admin/position"), ) - server.AddRoutes( - rest.WithMiddlewares( - []rest.Middleware{serverCtx.UserJWTAuth}, - []rest.Route{ - { - // App发送图文信息 - Method: http.MethodPost, - Path: "/message/articles", - Handler: adminscrmapp.SendWeWorkAppArticleMessageHandler(serverCtx), - }, - }..., - ), - rest.WithPrefix("/api/v1/admin/scrm/app/wechat"), - ) - server.AddRoutes( rest.WithMiddlewares( []rest.Middleware{serverCtx.UserJWTAuth}, @@ -1457,6 +1442,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { rest.WithPrefix("/api/v1/admin/scrm/app/wechat"), ) + server.AddRoutes( + rest.WithMiddlewares( + []rest.Middleware{serverCtx.UserJWTAuth}, + []rest.Route{ + { + // App发送图文信息 + Method: http.MethodPost, + Path: "/message/articles", + Handler: adminscrmapp.SendWeWorkAppArticleMessageHandler(serverCtx), + }, + }..., + ), + rest.WithPrefix("/api/v1/admin/scrm/app/wechat"), + ) + server.AddRoutes( rest.WithMiddlewares( []rest.Middleware{serverCtx.UserJWTAuth}, @@ -1543,16 +1543,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { []rest.Middleware{serverCtx.UserJWTAuth}, []rest.Route{ { - // 客户群列表/limit + // 所有客户列表/page Method: http.MethodPost, - Path: "/group/list", - Handler: adminscrmcustomer.ListWeWorkCustomerGroupLimitHandler(serverCtx), + Path: "/page", + Handler: adminscrmcustomer.ListWeWorkCustomerPageHandler(serverCtx), }, { - // 客户群发信息 + // 批量同步客户信息(根据员工ID同步/节流) Method: http.MethodPost, - Path: "/group/message/template", - Handler: adminscrmcustomer.SendWeWorkCustomerGroupMessageHandler(serverCtx), + Path: "/sync", + Handler: adminscrmcustomer.SyncWeWorkCustomerOptionHandler(serverCtx), }, }..., ), @@ -1564,16 +1564,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { []rest.Middleware{serverCtx.UserJWTAuth}, []rest.Route{ { - // 所有客户列表/page + // 客户群列表/limit Method: http.MethodPost, - Path: "/page", - Handler: adminscrmcustomer.ListWeWorkCustomerPageHandler(serverCtx), + Path: "/group/list", + Handler: adminscrmcustomer.ListWeWorkCustomerGroupLimitHandler(serverCtx), }, { - // 批量同步客户信息(根据员工ID同步/节流) + // 客户群发信息 Method: http.MethodPost, - Path: "/sync", - Handler: adminscrmcustomer.SyncWeWorkCustomerOptionHandler(serverCtx), + Path: "/group/message/template", + Handler: adminscrmcustomer.SendWeWorkCustomerGroupMessageHandler(serverCtx), }, }..., ), @@ -1585,16 +1585,10 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { []rest.Middleware{serverCtx.UserJWTAuth}, []rest.Route{ { - // 同步组织架构/department&user - Method: http.MethodGet, - Path: "/sync", - Handler: adminscrmorganization.SyncWeWorkUserHandler(serverCtx), - }, - { - // 员工列表/page + // 部门列表/page Method: http.MethodPost, - Path: "/user/page", - Handler: adminscrmorganization.ListWeWorkUserPageHandler(serverCtx), + Path: "/partment/page", + Handler: adminscrmorganization.ListWeWorkDepartMentPageHandler(serverCtx), }, }..., ), @@ -1606,10 +1600,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { []rest.Middleware{serverCtx.UserJWTAuth}, []rest.Route{ { - // 部门列表/page + // 同步组织架构/department&user + Method: http.MethodGet, + Path: "/sync", + Handler: adminscrmorganization.SyncWeWorkUserHandler(serverCtx), + }, + { + // 员工列表/page Method: http.MethodPost, - Path: "/partment/page", - Handler: adminscrmorganization.ListWeWorkDepartMentPageHandler(serverCtx), + Path: "/user/page", + Handler: adminscrmorganization.ListWeWorkUserPageHandler(serverCtx), }, }..., ), @@ -1821,19 +1821,19 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { { // 查询员工 Method: http.MethodGet, - Path: "/users/:id", + Path: "/users/:uuid", Handler: adminuser.GetUserHandler(serverCtx), }, { // 编辑员工信息 Method: http.MethodPatch, - Path: "/users/:id", + Path: "/users/:uuid", Handler: adminuser.UpdateUserHandler(serverCtx), }, { // 删除员工 Method: http.MethodDelete, - Path: "/users/:id", + Path: "/users/:uuid", Handler: adminuser.DeleteUserHandler(serverCtx), }, { @@ -2057,16 +2057,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ { - // 查询产品详情 + // 查询产品品类列表 Method: http.MethodGet, - Path: "/products/:id", - Handler: mpcrmproduct.GetProductHandler(serverCtx), + Path: "/product-categories", + Handler: mpcrmproduct.ListProductCategoriesHandler(serverCtx), }, { - // 产品列表 + // 查询产品品类树形表 Method: http.MethodGet, - Path: "/products/page-list", - Handler: mpcrmproduct.ListProductsPageHandler(serverCtx), + Path: "/product-category-tree", + Handler: mpcrmproduct.ListProductCategoryTreeHandler(serverCtx), }, }, rest.WithPrefix("/api/v1/mp/product"), @@ -2075,16 +2075,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { server.AddRoutes( []rest.Route{ { - // 查询产品品类列表 + // 查询产品详情 Method: http.MethodGet, - Path: "/product-categories", - Handler: mpcrmproduct.ListProductCategoriesHandler(serverCtx), + Path: "/products/:id", + Handler: mpcrmproduct.GetProductHandler(serverCtx), }, { - // 查询产品品类树形表 + // 产品列表 Method: http.MethodGet, - Path: "/product-category-tree", - Handler: mpcrmproduct.ListProductCategoryTreeHandler(serverCtx), + Path: "/products/page-list", + Handler: mpcrmproduct.ListProductsPageHandler(serverCtx), }, }, rest.WithPrefix("/api/v1/mp/product"), @@ -2395,6 +2395,36 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { rest.WithPrefix("/api/v1/mp/trade/token"), ) + server.AddRoutes( + []rest.Route{ + { + // 获取字典项列表 + Method: http.MethodGet, + Path: "/items", + Handler: mpdictionary.ListDictionaryItemsHandler(serverCtx), + }, + { + // 获取字典项 + Method: http.MethodGet, + Path: "/items/:type/:key", + Handler: mpdictionary.GetDictionaryItemHandler(serverCtx), + }, + { + // 获取字典类型 + Method: http.MethodGet, + Path: "/types/:type", + Handler: mpdictionary.GetDictionaryTypeHandler(serverCtx), + }, + { + // 获取字典类型列表 + Method: http.MethodGet, + Path: "/types/page-list", + Handler: mpdictionary.ListDictionaryPageTypesHandler(serverCtx), + }, + }, + rest.WithPrefix("/api/v1/mp/dictionary"), + ) + server.AddRoutes( rest.WithMiddlewares( []rest.Middleware{serverCtx.WebCustomerJWTAuth}, @@ -2428,36 +2458,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { rest.WithPrefix("/api/v1/web/dictionary"), ) - server.AddRoutes( - []rest.Route{ - { - // 获取字典项列表 - Method: http.MethodGet, - Path: "/items", - Handler: mpdictionary.ListDictionaryItemsHandler(serverCtx), - }, - { - // 获取字典项 - Method: http.MethodGet, - Path: "/items/:type/:key", - Handler: mpdictionary.GetDictionaryItemHandler(serverCtx), - }, - { - // 获取字典类型 - Method: http.MethodGet, - Path: "/types/:type", - Handler: mpdictionary.GetDictionaryTypeHandler(serverCtx), - }, - { - // 获取字典类型列表 - Method: http.MethodGet, - Path: "/types/page-list", - Handler: mpdictionary.ListDictionaryPageTypesHandler(serverCtx), - }, - }, - rest.WithPrefix("/api/v1/mp/dictionary"), - ) - server.AddRoutes( []rest.Route{ { diff --git a/internal/logic/admin/crm/customerdomain/customer/createcustomerlogic.go b/internal/logic/admin/crm/customerdomain/customer/createcustomerlogic.go index aece7050..a2f95005 100644 --- a/internal/logic/admin/crm/customerdomain/customer/createcustomerlogic.go +++ b/internal/logic/admin/crm/customerdomain/customer/createcustomerlogic.go @@ -29,7 +29,7 @@ func (l *CreateCustomerLogic) CreateCustomer(req *types.CreateCustomerRequest) ( Name: req.Name, Mobile: req.Mobile, Email: req.Email, - Uuid: securityx.GenerateUUID(), + Uuid: securityx.GenerateUUIDString(), InviterId: req.InviterId, Source: req.Source, Type: req.Type, diff --git a/internal/logic/admin/crm/customerdomain/customer/putcustomerlogic.go b/internal/logic/admin/crm/customerdomain/customer/putcustomerlogic.go index a735a588..150c9b12 100644 --- a/internal/logic/admin/crm/customerdomain/customer/putcustomerlogic.go +++ b/internal/logic/admin/crm/customerdomain/customer/putcustomerlogic.go @@ -32,7 +32,7 @@ func (l *PutCustomerLogic) PutCustomer(req *types.PutCustomerRequest) (resp *typ } // 如果当前数据库的用户已经有了UUID if cCustomer.Uuid == "" { - mdlCustomer.Uuid = securityx.GenerateUUID() + mdlCustomer.Uuid = securityx.GenerateUUIDString() mdlCustomer.InviteCode = securityx.GenerateInviteCode(mdlCustomer.Uuid) } diff --git a/internal/logic/admin/department/createdepartmentlogic.go b/internal/logic/admin/department/createdepartmentlogic.go index ce4c37b1..84e26f6f 100644 --- a/internal/logic/admin/department/createdepartmentlogic.go +++ b/internal/logic/admin/department/createdepartmentlogic.go @@ -27,7 +27,7 @@ func (l *CreateDepartmentLogic) CreateDepartment(req *types.CreateDepartmentRequ dep := organization.Department{ Name: req.DepName, PId: req.PId, - LeaderId: req.LeaderId, + LeaderUuid: req.LeaderUuid, Desc: req.Desc, PhoneNumber: req.PhoneNumber, Email: req.Email, diff --git a/internal/logic/admin/user/deleteuserlogic.go b/internal/logic/admin/user/deleteuserlogic.go index 492a544f..b9947ba9 100644 --- a/internal/logic/admin/user/deleteuserlogic.go +++ b/internal/logic/admin/user/deleteuserlogic.go @@ -24,11 +24,11 @@ func NewDeleteUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Delete } func (l *DeleteUserLogic) DeleteUser(req *types.DeleteUserRequest) (resp *types.DeleteUserReply, err error) { - err = l.svcCtx.PowerX.Organization.DeleteUserById(l.ctx, req.Id) + err = l.svcCtx.PowerX.Organization.DeleteUserByUuid(l.ctx, req.Uuid) if err != nil { return nil, err } return &types.DeleteUserReply{ - Id: req.Id, + Uuid: req.Uuid, }, nil } diff --git a/internal/logic/admin/user/getuserlogic.go b/internal/logic/admin/user/getuserlogic.go index 1ab77661..dd369fb2 100644 --- a/internal/logic/admin/user/getuserlogic.go +++ b/internal/logic/admin/user/getuserlogic.go @@ -28,7 +28,7 @@ func NewGetUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserLo } func (l *GetUserLogic) GetUser(req *types.GetUserRequest) (resp *types.GetUserReply, err error) { - user, err := l.svcCtx.PowerX.Organization.FindOneUserById(l.ctx, req.Id) + user, err := l.svcCtx.PowerX.Organization.FindOneUserByUuid(l.ctx, req.Uuid) if err != nil { return nil, err } diff --git a/internal/logic/admin/user/resetpasswordlogic.go b/internal/logic/admin/user/resetpasswordlogic.go index f479caf4..4532f1c1 100644 --- a/internal/logic/admin/user/resetpasswordlogic.go +++ b/internal/logic/admin/user/resetpasswordlogic.go @@ -5,6 +5,7 @@ import ( "PowerX/internal/model/powermodel" "PowerX/internal/types" "context" + "github.com/google/uuid" "github.com/pkg/errors" "PowerX/internal/svc" @@ -27,9 +28,13 @@ func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Res } func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (resp *types.ResetPasswordReply, err error) { + userUuid, err := uuid.Parse(req.UserUuid) + if err != nil { + return nil, err + } user := organization.User{ - PowerModel: powermodel.PowerModel{ - Id: req.UserId, + PowerUUIDModel: powermodel.PowerUUIDModel{ + UUID: userUuid, }, Password: "123456", } @@ -39,7 +44,7 @@ func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (res panic(errors.Wrap(err, "create user hash password failed")) } - if err := l.svcCtx.PowerX.Organization.UpdateUserById(l.ctx, &user, req.UserId); err != nil { + if err := l.svcCtx.PowerX.Organization.UpdateUserByUuid(l.ctx, &user, req.UserUuid); err != nil { return nil, err } diff --git a/internal/logic/admin/user/updateuserlogic.go b/internal/logic/admin/user/updateuserlogic.go index cd4c4f15..690271dc 100644 --- a/internal/logic/admin/user/updateuserlogic.go +++ b/internal/logic/admin/user/updateuserlogic.go @@ -5,6 +5,7 @@ import ( "PowerX/internal/model/powermodel" "PowerX/internal/types" "context" + "github.com/google/uuid" "github.com/pkg/errors" "time" @@ -28,9 +29,13 @@ func NewUpdateUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Update } func (l *UpdateUserLogic) UpdateUser(req *types.UpdateUserRequest) (resp *types.UpdateUserReply, err error) { + userUuid, err := uuid.Parse(req.Uuid) + if err != nil { + return nil, err + } user := organization.User{ - PowerModel: powermodel.PowerModel{ - Id: req.Id, + PowerUUIDModel: powermodel.PowerUUIDModel{ + UUID: userUuid, }, Name: req.Name, NickName: req.NickName, @@ -51,7 +56,7 @@ func (l *UpdateUserLogic) UpdateUser(req *types.UpdateUserRequest) (resp *types. panic(errors.Wrap(err, "create user hash password failed")) } - if err := l.svcCtx.PowerX.Organization.UpdateUserById(l.ctx, &user, req.Id); err != nil { + if err := l.svcCtx.PowerX.Organization.UpdateUserByUuid(l.ctx, &user, req.Uuid); err != nil { return nil, err } diff --git a/internal/logic/web/customer/auth/registercustomerbyphoneininvitecodelogic.go b/internal/logic/web/customer/auth/registercustomerbyphoneininvitecodelogic.go index 6688af2d..9c4bb0d9 100644 --- a/internal/logic/web/customer/auth/registercustomerbyphoneininvitecodelogic.go +++ b/internal/logic/web/customer/auth/registercustomerbyphoneininvitecodelogic.go @@ -48,7 +48,7 @@ func (l *RegisterCustomerByPhoneInInviteCodeLogic) RegisterCustomerByPhoneInInvi customerTypeId := l.svcCtx.PowerX.DataDictionary.GetCachedDDId(l.ctx, customerdomain.TypeCustomerType, customerdomain.CustomerPersonal) // upsert 客户 - uuid := securityx.GenerateUUID() + uuid := securityx.GenerateUUIDString() inviteCode := securityx.GenerateInviteCode(uuid) customer := &customerdomain.Customer{ Mobile: req.Phone, diff --git a/internal/logic/web/customer/auth/registercustomerbyphoneinregistercodelogic.go b/internal/logic/web/customer/auth/registercustomerbyphoneinregistercodelogic.go index 80f01339..1ad44313 100644 --- a/internal/logic/web/customer/auth/registercustomerbyphoneinregistercodelogic.go +++ b/internal/logic/web/customer/auth/registercustomerbyphoneinregistercodelogic.go @@ -55,7 +55,7 @@ func (l *RegisterCustomerByPhoneInRegisterCodeLogic) RegisterCustomerByPhoneInRe customerTypeId := l.svcCtx.PowerX.DataDictionary.GetCachedDDId(l.ctx, customerdomain.TypeCustomerType, customerdomain.CustomerPersonal) // upsert 客户 - uuid := securityx.GenerateUUID() + uuid := securityx.GenerateUUIDString() inviteCode := securityx.GenerateInviteCode(uuid) customer := &customerdomain.Customer{ Mobile: req.Phone, diff --git a/internal/logic/web/customer/auth/registercustomerbyphonelogic.go b/internal/logic/web/customer/auth/registercustomerbyphonelogic.go index 2e932a3e..474da18f 100644 --- a/internal/logic/web/customer/auth/registercustomerbyphonelogic.go +++ b/internal/logic/web/customer/auth/registercustomerbyphonelogic.go @@ -42,7 +42,7 @@ func (l *RegisterCustomerByPhoneLogic) RegisterCustomerByPhone(req *types.Custom customerTypeId := l.svcCtx.PowerX.DataDictionary.GetCachedDDId(l.ctx, customerdomain.TypeCustomerType, customerdomain.CustomerPersonal) // upsert 客户 - uuid := securityx.GenerateUUID() + uuid := securityx.GenerateUUIDString() inviteCode := securityx.GenerateInviteCode(uuid) customer := &customerdomain.Customer{ Mobile: req.Phone, diff --git a/internal/model/media/mediaresource.go b/internal/model/media/mediaresource.go index 146422a5..4c1763f0 100644 --- a/internal/model/media/mediaresource.go +++ b/internal/model/media/mediaresource.go @@ -7,7 +7,7 @@ import ( ) type MediaResource struct { - powermodel.PowerModel + powermodel.PowerUUIDModel CustomerId int64 `gorm:"comment:客户Id; index" json:"customerId"` Filename string `gorm:"comment:名称" json:"filename"` @@ -25,7 +25,7 @@ type MediaSet struct { } func (mdl *MediaResource) TableName() string { - return model.PowerXSchema + "." + model.TableNameMediaResource + return "public." + model.TableNameMediaResource } func (mdl *MediaResource) GetTableName(needFull bool) string { diff --git a/internal/model/organization/department.go b/internal/model/organization/department.go index eaff941c..fd264e82 100644 --- a/internal/model/organization/department.go +++ b/internal/model/organization/department.go @@ -11,11 +11,11 @@ type Department struct { powermodel.PowerModel PDep *Department `gorm:"foreignKey:PId"` - Leader *User `gorm:"foreignKey:LeaderId"` + Leader *User `gorm:"foreignKey:LeaderUuid"` Ancestors []*Department `gorm:"many2many:department_ancestors;"` Name string `gorm:"comment:部门名称;column:name" json:"name"` PId int64 `gorm:"comment:部门名ID;column:pid" json:"pid"` - LeaderId int64 `gorm:"comment:领导ID;column:leader_id" json:"leader_id"` + LeaderUuid *string `gorm:"comment:领导ID;column:leader_id;type:uuid;default:null" json:"leader_id"` Desc string `gorm:"comment:描述;column:desc" json:"desc"` PhoneNumber string `gorm:"comment:部门电话;column:phone_number" json:"phone_number"` Email string `gorm:"comment:部门邮箱;column:email" json:"email"` diff --git a/internal/model/organization/user.go b/internal/model/organization/user.go index a2f272e1..965ebeda 100644 --- a/internal/model/organization/user.go +++ b/internal/model/organization/user.go @@ -10,9 +10,8 @@ import ( ) type User struct { - powermodel.PowerModel + powermodel.PowerUUIDModel - UUID string `json:"comment:唯一标识;column:uuid;unique;type:uuid" json:"uuid"` Account string `gorm:"comment:账户;column:account unique;type:varchar" json:"account"` Name string `gorm:"comment:名称;column:name;type:varchar" json:"name"` NickName string `gorm:"comment:别称;column:nick_name;type:varchar" json:"nick_name"` diff --git a/internal/model/powermodel/pivot.go b/internal/model/powermodel/pivot.go index d44b89e5..10187f40 100644 --- a/internal/model/powermodel/pivot.go +++ b/internal/model/powermodel/pivot.go @@ -4,6 +4,7 @@ import ( fmt2 "PowerX/pkg/printx" "errors" "fmt" + "github.com/google/uuid" "gorm.io/gorm" "gorm.io/gorm/clause" "time" @@ -47,7 +48,11 @@ func (mdl *PowerPivot) GetID() int64 { return mdl.Id } -func (mdl *PowerPivot) GetUUID() string { +func (mdl *PowerPivot) GetUUID() *uuid.UUID { + return nil +} + +func (mdl *PowerPivot) GetUUIDString() string { return "" } diff --git a/internal/model/powermodel/powermodel.go b/internal/model/powermodel/powermodel.go index 220ed8f4..b26f49cb 100644 --- a/internal/model/powermodel/powermodel.go +++ b/internal/model/powermodel/powermodel.go @@ -4,6 +4,7 @@ import ( "PowerX/pkg/securityx" "database/sql" "github.com/ArtisanCloud/PowerLibs/v3/object" + "github.com/google/uuid" "gorm.io/gorm" "gorm.io/gorm/clause" "gorm.io/gorm/schema" @@ -21,7 +22,8 @@ type ModelInterface interface { GetTableName(needFull bool) string GetPowerModel() ModelInterface GetID() int64 - GetUUID() string + GetUUID() *uuid.UUID + GetUUIDString() string GetPrimaryKey() string GetForeignRefer() string GetForeignReferValue() int64 @@ -37,7 +39,7 @@ type PowerModel struct { type PowerUUIDModel struct { Id int64 `gorm:"autoIncrement:true;unique; column:id; ->;<-:create" json:"-"` - UUID string `gorm:"primaryKey;autoIncrement:false;unique; column:uuid; ->;<-:create " json:"uuid" sql:"index"` + UUID uuid.UUID `gorm:"type:uuid;primaryKey;autoIncrement:false;unique; column:uuid; ->;<-:create " json:"uuid" sql:"index"` CreatedAt time.Time `gorm:"column:created_at; ->;<-:create " json:"createdAt"` UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"` DeletedAt gorm.DeletedAt `gorm:"index"` @@ -83,8 +85,12 @@ func (mdl *PowerUUIDModel) GetPowerModel() ModelInterface { return mdl } -func (mdl *PowerUUIDModel) GetUUID() string { - return mdl.UUID +func (mdl *PowerUUIDModel) GetUUID() *uuid.UUID { + return &mdl.UUID +} + +func (mdl *PowerUUIDModel) GetUUIDString() string { + return mdl.UUID.String() } func (mdl *PowerUUIDModel) GetPrimaryKey() string { @@ -113,7 +119,11 @@ func (mdl *PowerModel) GetPowerModel() ModelInterface { func (mdl *PowerModel) GetID() int64 { return mdl.Id } -func (mdl *PowerModel) GetUUID() string { +func (mdl *PowerModel) GetUUID() *uuid.UUID { + return nil +} + +func (mdl *PowerModel) GetUUIDString() string { return "" } @@ -344,7 +354,7 @@ func IsPowerModelLoaded(mdl ModelInterface) bool { return false } - if mdl.GetUUID() == "" { + if mdl.GetUUID() == nil { return false } diff --git a/internal/types/types.go b/internal/types/types.go index ec23d536..259eeed6 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -464,7 +464,7 @@ type CreateDepartmentReply struct { type CreateDepartmentRequest struct { DepName string `json:"depName"` - LeaderId int64 `json:"leaderId"` + LeaderUuid string `json:"leaderUuid"` PId int64 `json:"pId"` Desc string `json:"desc,optional"` PhoneNumber string `json:"phoneNumber,optional"` @@ -1063,11 +1063,11 @@ type DeleteTagRequest struct { } type DeleteUserReply struct { - Id int64 `json:"id"` + Uuid string `json:"uuid"` } type DeleteUserRequest struct { - Id int64 `path:"id"` + Uuid string `path:"uuid"` } type DeliveryAddress struct { @@ -1639,7 +1639,7 @@ type GetUserReply struct { } type GetUserRequest struct { - Id int64 `path:"id"` + Uuid string `path:"uuid"` } type GetVersionResponse struct { @@ -3062,7 +3062,7 @@ type ResetPasswordReply struct { } type ResetPasswordRequest struct { - UserId int64 `json:"userId"` + UserUuid string `json:"userUuid"` } type Resource struct { @@ -3426,7 +3426,7 @@ type UpdateUserReply struct { } type UpdateUserRequest struct { - Id int64 `path:"id"` + Uuid string `path:"uuid"` Name string `json:"name,optional"` NickName string `json:"nickName,optional"` Desc string `json:"desc,optional"` @@ -3647,7 +3647,7 @@ type WechatCustomersWithFollowUser struct { UserId string `json:"userId"` Remark string `json:"remark"` Description string `json:"description"` - CreatedTime int `json:"createtime"` + CreatedTime int `json:"createtime"` Tags []WechatCustomersFollowUserWithTags `json:"tags"` TagIds []string `json:"tagIds"` WechatChannels WechatCustomersFollowUserWithWechatChannels `json:"wechatChannels"` diff --git a/internal/uc/powerx/authorizationadmin.go b/internal/uc/powerx/authorizationadmin.go index 561f8bf5..91b586e8 100644 --- a/internal/uc/powerx/authorizationadmin.go +++ b/internal/uc/powerx/authorizationadmin.go @@ -4,6 +4,7 @@ import ( "PowerX/internal/config" "PowerX/internal/model/organization" "PowerX/internal/model/permission" + "PowerX/internal/model/powermodel" "PowerX/internal/types/errorx" "PowerX/pkg/mapx" "PowerX/pkg/slicex" @@ -162,7 +163,9 @@ func (uc *AdminPermsUseCase) Init() { rooName = "超级管理员" } root := organization.User{ - UUID: uuid.New().String(), + PowerUUIDModel: powermodel.PowerUUIDModel{ + UUID: uuid.New(), + }, Account: rooAccount, Password: rooPass, Name: rooName, diff --git a/internal/uc/powerx/crm/customerdomain/customer.go b/internal/uc/powerx/crm/customerdomain/customer.go index fcb7d357..9b9b7104 100644 --- a/internal/uc/powerx/crm/customerdomain/customer.go +++ b/internal/uc/powerx/crm/customerdomain/customer.go @@ -127,7 +127,7 @@ func (uc *CustomerUseCase) UpsertCustomer(ctx context.Context, customer *custome } // 如果是新增用户,那么需要给一个唯一识别号 if customer.Uuid == "" { - customer.Uuid = securityx.GenerateUUID() + customer.Uuid = securityx.GenerateUUIDString() err = powermodel.UpsertModelsOnUniqueID(tx, &customerdomain.Customer{}, customerdomain.CustomerUniqueId, customer, []string{"uuid"}, false) if err != nil { return err diff --git a/internal/uc/powerx/organization.go b/internal/uc/powerx/organization.go index a82850b7..9b4bb878 100644 --- a/internal/uc/powerx/organization.go +++ b/internal/uc/powerx/organization.go @@ -10,6 +10,7 @@ import ( "PowerX/pkg/slicex" "context" "fmt" + "github.com/google/uuid" "github.com/pkg/errors" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -161,10 +162,27 @@ func (uc *OrganizationUseCase) FindOneUserById(ctx context.Context, id int64) (u return } -func (uc *OrganizationUseCase) UpdateUserById(ctx context.Context, user *organization.User, userId int64) error { +func (uc *OrganizationUseCase) FindOneUserByUuid(ctx context.Context, userUUid string) (user *organization.User, err error) { + if err = uc.db.WithContext(ctx). + Where("uuid = ?", userUUid). + Preload("Department"). + Preload("Position").First(&user).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, errorx.WithCause(errorx.ErrBadRequest, "用户不存在") + } + panic(err) + } + return +} + +func (uc *OrganizationUseCase) UpdateUserByUuid(ctx context.Context, user *organization.User, strUuid string) error { + userUuid, err := uuid.Parse(strUuid) + if err != nil { + return err + } whereCase := organization.User{ - PowerModel: powermodel.PowerModel{ - Id: userId, + PowerUUIDModel: powermodel.PowerUUIDModel{ + UUID: userUuid, }, IsReserved: false, } @@ -172,15 +190,17 @@ func (uc *OrganizationUseCase) UpdateUserById(ctx context.Context, user *organiz if result.RowsAffected == 0 { return errorx.WithCause(errorx.ErrBadRequest, "更新失败, 用户保留或不存在") } - err := result.Error + err = result.Error if err != nil { panic(errors.Wrap(err, "delete user failed")) } return nil } -func (uc *OrganizationUseCase) DeleteUserById(ctx context.Context, id int64) error { - result := uc.db.WithContext(ctx).Where(organization.User{IsReserved: false}, "is_reserved").Delete(&organization.User{}, id) +func (uc *OrganizationUseCase) DeleteUserByUuid(ctx context.Context, strUuid string) error { + result := uc.db.WithContext(ctx). + Where("uuid = ? AND is_reserved = ?", strUuid, false). + Delete(&organization.User{}) err := result.Error if err != nil { panic(errors.Wrap(err, "delete user failed")) diff --git a/pkg/securityx/security.go b/pkg/securityx/security.go index 7f5304b9..f4e10474 100644 --- a/pkg/securityx/security.go +++ b/pkg/securityx/security.go @@ -100,7 +100,10 @@ func CheckPassword(hashedPassword string, encodedPassword string) (isPasswordVal return true } -func GenerateUUID() string { +func GenerateUUID() uuid.UUID { + return uuid.New() +} +func GenerateUUIDString() string { return uuid.New().String() }