...
|
...
|
@@ -3,6 +3,7 @@ package user |
|
|
import (
|
|
|
"crypto/sha1"
|
|
|
"fmt"
|
|
|
"github.com/linmadan/egglib-go/core/application"
|
|
|
"github.com/tiptok/gocomm/common"
|
|
|
"github.com/tiptok/gocomm/pkg/log"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
|
...
|
...
|
@@ -20,12 +21,12 @@ func (svr *UserService) CreateUser(header *protocol.RequestHeader, request *prot |
|
|
)
|
|
|
rsp = &protocolx.CreateUserResponse{}
|
|
|
if err = request.ValidateCommand(); err != nil {
|
|
|
err = protocol.NewCustomMessage(2, err.Error())
|
|
|
err = application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
log.Error(err)
|
|
|
return nil, err
|
|
|
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
...
|
...
|
@@ -49,12 +50,16 @@ func (svr *UserService) CreateUser(header *protocol.RequestHeader, request *prot |
|
|
if len(newUser.Passwd) == 0 {
|
|
|
newUser.Passwd = fmt.Sprintf("%x", sha1.Sum([]byte("123456")))
|
|
|
}
|
|
|
if m, err := UserRepository.Save(newUser); err != nil {
|
|
|
return nil, err
|
|
|
if m, e := UserRepository.Save(newUser); e != nil {
|
|
|
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, e.Error())
|
|
|
return
|
|
|
} else {
|
|
|
rsp = m
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -64,7 +69,7 @@ func (svr *UserService) UpdateUser(header *protocol.RequestHeader, request *prot |
|
|
)
|
|
|
rsp = &protocolx.UpdateUserResponse{}
|
|
|
if err = request.ValidateCommand(); err != nil {
|
|
|
err = protocol.NewCustomMessage(2, err.Error())
|
|
|
err = application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
...
|
...
|
@@ -88,12 +93,17 @@ func (svr *UserService) UpdateUser(header *protocol.RequestHeader, request *prot |
|
|
}
|
|
|
}
|
|
|
if err = user.Update(common.ObjectToMap(request)); err != nil {
|
|
|
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if user, err = UserRepository.Save(user); err != nil {
|
|
|
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -103,12 +113,12 @@ func (svr *UserService) GetUser(header *protocol.RequestHeader, request *protoco |
|
|
)
|
|
|
rsp = &protocolx.GetUserResponse{}
|
|
|
if err = request.ValidateCommand(); err != nil {
|
|
|
err = protocol.NewCustomMessage(2, err.Error())
|
|
|
err = application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
log.Error(err)
|
|
|
return nil, err
|
|
|
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
...
|
...
|
@@ -117,10 +127,14 @@ func (svr *UserService) GetUser(header *protocol.RequestHeader, request *protoco |
|
|
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
|
|
|
var user *domain.User
|
|
|
if user, err = UserRepository.FindOne(common.ObjectToMap(request)); err != nil {
|
|
|
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
rsp = user
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -130,12 +144,12 @@ func (svr *UserService) DeleteUser(header *protocol.RequestHeader, request *prot |
|
|
)
|
|
|
rsp = &protocolx.DeleteUserResponse{}
|
|
|
if err = request.ValidateCommand(); err != nil {
|
|
|
err = protocol.NewCustomMessage(2, err.Error())
|
|
|
err = application.ThrowError(application.ARG_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
log.Error(err)
|
|
|
return nil, err
|
|
|
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
...
|
...
|
@@ -144,13 +158,18 @@ func (svr *UserService) DeleteUser(header *protocol.RequestHeader, request *prot |
|
|
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
|
|
|
var user *domain.User
|
|
|
if user, err = UserRepository.FindOne(common.ObjectToMap(request)); err != nil {
|
|
|
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if user, err = UserRepository.Remove(user); err != nil {
|
|
|
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
rsp = user
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -160,7 +179,8 @@ func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protoc |
|
|
)
|
|
|
rsp = &protocolx.ListUserResponse{}
|
|
|
if err = request.ValidateCommand(); err != nil {
|
|
|
err = protocol.NewCustomMessage(2, err.Error())
|
|
|
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -174,13 +194,17 @@ func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protoc |
|
|
var user []*domain.User
|
|
|
var total int64
|
|
|
if total, user, err = UserRepository.Find(common.ObjectToMap(request)); err != nil {
|
|
|
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
rsp = map[string]interface{}{
|
|
|
"total": total,
|
|
|
"list": user,
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
if err = transactionContext.CommitTransaction(); err != nil {
|
|
|
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
return
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
|