...
|
...
|
@@ -8,6 +8,7 @@ import ( |
|
|
"github.com/tiptok/gocomm/pkg/log"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/utils"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
|
|
|
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/user"
|
|
|
)
|
...
|
...
|
@@ -31,13 +32,12 @@ func (svr *UserService) CreateUser(header *protocol.RequestHeader, request *prot |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
newUser := &domain.User{
|
|
|
Name: request.Name,
|
|
|
Address: request.Address,
|
|
|
Phone: request.Phone,
|
|
|
//Passwd: request.Passwd,
|
|
|
Roles: request.Roles,
|
|
|
IsAdmin: request.IsAdmin,
|
|
|
newUser := &domain.Users{
|
|
|
Name: request.Name,
|
|
|
Phone: request.Phone,
|
|
|
Roles: request.Roles,
|
|
|
Status: 1,
|
|
|
AdminType: request.AdminType,
|
|
|
}
|
|
|
|
|
|
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
|
...
|
...
|
@@ -81,7 +81,7 @@ func (svr *UserService) UpdateUser(header *protocol.RequestHeader, request *prot |
|
|
}()
|
|
|
|
|
|
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
|
|
|
var user *domain.User
|
|
|
var user *domain.Users
|
|
|
if user, err = UserRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil {
|
|
|
err = protocol.NewCustomMessage(1, "用户不存在")
|
|
|
return
|
...
|
...
|
@@ -110,6 +110,7 @@ func (svr *UserService) UpdateUser(header *protocol.RequestHeader, request *prot |
|
|
func (svr *UserService) GetUser(header *protocol.RequestHeader, request *protocolx.GetUserRequest) (rsp interface{}, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
RoleRepository, _ = factory.CreateRoleRepository(transactionContext)
|
|
|
)
|
|
|
rsp = &protocolx.GetUserResponse{}
|
|
|
if err = request.ValidateCommand(); err != nil {
|
...
|
...
|
@@ -125,12 +126,18 @@ func (svr *UserService) GetUser(header *protocol.RequestHeader, request *protoco |
|
|
}()
|
|
|
|
|
|
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
|
|
|
var user *domain.User
|
|
|
var user *domain.Users
|
|
|
if user, err = UserRepository.FindOne(common.ObjectToMap(request)); err != nil {
|
|
|
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
rsp = user
|
|
|
retMap := map[string]interface{}{"id": user.Id, "name": user.Name, "phone": user.Phone, "adminType": user.AdminType, "status": user.Status}
|
|
|
if len(user.Roles) > 0 {
|
|
|
if _, roles, e := RoleRepository.Find(map[string]interface{}{"inRoleIds": user.Roles}); len(roles) > 0 && e == nil {
|
|
|
retMap["roles"] = utils.LoadCustomField(roles, "Id", "RoleName")
|
|
|
}
|
|
|
}
|
|
|
rsp = map[string]interface{}{"user": retMap}
|
|
|
if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
return
|
...
|
...
|
@@ -156,7 +163,7 @@ func (svr *UserService) DeleteUser(header *protocol.RequestHeader, request *prot |
|
|
}()
|
|
|
|
|
|
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
|
|
|
var user *domain.User
|
|
|
var user *domain.Users
|
|
|
if user, err = UserRepository.FindOne(common.ObjectToMap(request)); err != nil {
|
|
|
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return
|
...
|
...
|
@@ -191,15 +198,16 @@ func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protoc |
|
|
}()
|
|
|
|
|
|
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
|
|
|
var user []*domain.User
|
|
|
var user []*domain.Users
|
|
|
var total int64
|
|
|
if total, user, err = UserRepository.Find(common.ObjectToMap(request)); err != nil {
|
|
|
if total, user, err = UserRepository.Find(map[string]interface{}{"offset": request.PageNumber * request.PageSize, "limit": request.PageSize, "sortById": "DESC"}); err != nil {
|
|
|
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
rsp = map[string]interface{}{
|
|
|
"total": total,
|
|
|
"list": user,
|
|
|
"totalRow": total,
|
|
|
"pageNumber": request.PageNumber,
|
|
|
"list": utils.LoadCustomField(user, "Id", "Name", "Phone", "IsAdmin", "Status"),
|
|
|
}
|
|
|
if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
...
|
...
|
|