作者 tangxuhui
package dto
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
)
type UserBaseDto struct {
// 用户基础数据id
UserBaseId int64 `json:"userBaseId,omitempty"`
// 用户信息
UserInfo *domain.UserInfo `json:"userInfo,omitempty"`
// 手机号码
//Account string `json:"phone,omitempty"`
// 密码
//Password string `json:"password,omitempty"`
// IM信息
Im *domain.Im `json:"im,omitempty"`
// 关联的用户 (冗余)
//RelatedUsers []int64 `json:"relatedUsers,omitempty"`
// 账号状态 1:正常 2.禁用 3:注销
//Status int `json:"status,omitempty"`
// 创建时间
//CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
//UpdatedAt time.Time `json:"updatedAt,omitempty"`
}
func (u *UserBaseDto) LoadDto(ub *domain.UserBase) {
u.UserBaseId = ub.UserBaseId
u.UserInfo = ub.UserInfo
u.Im = ub.Im
}
... ...
... ... @@ -9,8 +9,7 @@ import (
)
type UserInfoQuery struct {
// 用户Id 用户唯一标识
UserId int64 `cname:"用户Id 用户唯一标识" json:"userId"`
Account string `cname:"账号" json:"account" valid:"Required"`
}
func (userInfoQuery *UserInfoQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -3,6 +3,7 @@ package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/auth/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/auth/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/auth/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
... ... @@ -317,10 +318,18 @@ func (authService *AuthService) UserInfo(userInfoQuery *query.UserInfoQuery) (in
defer func() {
transactionContext.RollbackTransaction()
}()
userBaseRepository, _, _ := factory.FastPgUserBase(transactionContext, 0)
userBase, err := userBaseRepository.FindOne(map[string]interface{}{"account": userInfoQuery.Account})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
ubDto := &dto.UserBaseDto{}
ubDto.LoadDto(userBase)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil, nil
return ubDto, nil
}
func NewAuthService(options map[string]interface{}) *AuthService {
... ...
... ... @@ -202,6 +202,7 @@ func (repository *UserRepository) Find(queryOptions map[string]interface{}) (int
}
query.SetWhereByQueryOption("user_base_id=?", "userBaseId")
query.SetWhereByQueryOption("(user_type & ?)>0", "userType")
query.SetWhereByQueryOption("enable_status=?", "enableStatus")
query.SetWhereByQueryOption(fmt.Sprintf(`user_role @> '[{"roleId":%v}]'`, queryOptions["roleId"]), "roleId")
if v, ok := queryOptions["depName"]; ok && len(v.(string)) > 0 {
... ...
... ... @@ -62,6 +62,7 @@ func (controller *AuthController) DestroyAccount() {
func (controller *AuthController) UserInfo() {
authService := service.NewAuthService(nil)
userInfoQuery := &query.UserInfoQuery{}
controller.Unmarshal(userInfoQuery)
data, err := authService.UserInfo(userInfoQuery)
controller.Response(data, err)
}
... ...
... ... @@ -13,4 +13,5 @@ func init() {
web.Router("/auth/reset-phone", &controllers.AuthController{}, "Post:PhoneAuthResetPhone")
web.Router("/auth/destroy-account", &controllers.AuthController{}, "Post:DestroyAccount")
web.Router("/auth/refresh-im", &controllers.AuthController{}, "Post:RefreshIM")
web.Router("/auth/user-base-info", &controllers.AuthController{}, "Post:UserInfo")
}
... ...