作者 yangfu

1.branch fix_bug

... ... @@ -48,7 +48,7 @@ func (svr *AuthService) Login(header *protocol.RequestHeader, request *protocolx
}
token, _ := common.GenerateToken(fmt.Sprintf("%v", user.Id), user.Passwd, common.WithExpire(domain.TokenExpire), common.WithAddData(map[string]interface{}{"UserName": user.Name}))
rsp.Access = map[string]interface{}{
"accessToken": "Bearer " + token,
"accessToken": token, //"Bearer " + token,
"expiresIn": domain.TokenExpire,
}
... ...
... ... @@ -28,6 +28,7 @@ func (svr *CacheService) CacheUserAccess(userId int64) func() (interface{}, erro
AccessRepository, _ = factory.CreateAccessRepository(transactionContext)
err error
)
transactionContext.SetTransactionClose()
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return nil, err
... ... @@ -54,6 +55,7 @@ func (svr *CacheService) ValidUser(userId int64) (isAdmin bool, err error) {
transactionContext, _ = factory.CreateTransactionContext(nil)
UserRepository, _ = factory.CreateUserRepository(transactionContext)
)
transactionContext.SetTransactionClose()
if err = transactionContext.StartTransaction(); err != nil {
log.Error(err)
return isAdmin, err
... ...
... ... @@ -175,7 +175,7 @@ func (svr *RoleService) ListRole(header *protocol.RequestHeader, request *protoc
var RoleRepository, _ = factory.CreateRoleRepository(transactionContext)
var role []*domain.Role
var total int64
if _, role, err = RoleRepository.Find(map[string]interface{}{"orderById": "DESC"}); err != nil {
if total, role, err = RoleRepository.Find(map[string]interface{}{"orderById": "DESC"}); err != nil {
return
}
rsp = map[string]interface{}{
... ...
... ... @@ -47,7 +47,7 @@ func (repository *AccessRepository) Remove(Access *domain.Access) (*domain.Acces
}
func (repository *AccessRepository) FindOne(queryOptions map[string]interface{}) (*domain.Access, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
AccessModel := new(models.Access)
query := NewQuery(tx.Model(AccessModel), queryOptions)
query.SetWhere("id = ?", "id")
... ... @@ -61,7 +61,7 @@ func (repository *AccessRepository) FindOne(queryOptions map[string]interface{})
}
func (repository *AccessRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Access, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
var AccessModels []*models.Access
Accesss := make([]*domain.Access, 0)
query := NewQuery(tx.Model(&AccessModels), queryOptions).
... ...
... ... @@ -46,7 +46,7 @@ func (repository *CasbinRuleRepository) Remove(CasbinRule *domain.CasbinRule) (*
}
func (repository *CasbinRuleRepository) FindOne(queryOptions map[string]interface{}) (*domain.CasbinRule, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
CasbinRuleModel := new(models.CasbinRule)
query := NewQuery(tx.Model(CasbinRuleModel), queryOptions)
query.SetWhere("id = ?", "id")
... ... @@ -60,7 +60,7 @@ func (repository *CasbinRuleRepository) FindOne(queryOptions map[string]interfac
}
func (repository *CasbinRuleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.CasbinRule, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
var CasbinRuleModels []*models.CasbinRule
CasbinRules := make([]*domain.CasbinRule, 0)
query := NewQuery(tx.Model(&CasbinRuleModels), queryOptions).
... ...
... ... @@ -90,7 +90,7 @@ func (repository *ClientVersionRepository) FindOne(queryOptions map[string]inter
}
func (repository *ClientVersionRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ClientVersion, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
var ClientVersionModels []*models.ClientVersion
ClientVersions := make([]*domain.ClientVersion, 0)
query := NewQuery(tx.Model(&ClientVersionModels), queryOptions).
... ...
... ... @@ -46,7 +46,7 @@ func (repository *MenuRepository) Remove(Menu *domain.Menu) (*domain.Menu, error
}
func (repository *MenuRepository) FindOne(queryOptions map[string]interface{}) (*domain.Menu, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
MenuModel := new(models.Menu)
query := NewQuery(tx.Model(MenuModel), queryOptions)
query.SetWhere("id = ?", "id")
... ... @@ -60,7 +60,7 @@ func (repository *MenuRepository) FindOne(queryOptions map[string]interface{}) (
}
func (repository *MenuRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Menu, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
var MenuModels []*models.Menu
Menus := make([]*domain.Menu, 0)
query := NewQuery(tx.Model(&MenuModels), queryOptions).
... ...
... ... @@ -89,7 +89,7 @@ func (repository *OperatorLogRepository) FindOne(queryOptions map[string]interfa
}
func (repository *OperatorLogRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.OperatorLog, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
var OperatorLogModels []*models.OperatorLog
OperatorLogs := make([]*domain.OperatorLog, 0)
query := NewQuery(tx.Model(&OperatorLogModels), queryOptions).
... ...
... ... @@ -47,7 +47,7 @@ func (repository *ProjectModuleFilesRepository) Remove(ProjectModuleFiles *domai
}
func (repository *ProjectModuleFilesRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModuleFiles, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
ProjectModuleFilesModel := new(models.ProjectModuleFiles)
query := NewQuery(tx.Model(ProjectModuleFilesModel), queryOptions)
query.SetWhere("id = ?", "id")
... ... @@ -66,7 +66,7 @@ func (repository *ProjectModuleFilesRepository) FindOne(queryOptions map[string]
}
func (repository *ProjectModuleFilesRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectModuleFiles, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
var ProjectModuleFilesModels []*models.ProjectModuleFiles
ProjectModuleFiless := make([]*domain.ProjectModuleFiles, 0)
query := NewQuery(tx.Model(&ProjectModuleFilesModels), queryOptions).
... ...
... ... @@ -48,7 +48,7 @@ func (repository *ProjectModuleRepository) Remove(ProjectModule *domain.ProjectM
}
func (repository *ProjectModuleRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModule, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
ProjectModuleModel := new(models.ProjectModule)
query := NewQuery(tx.Model(ProjectModuleModel).Relation("ProjectModuleVersion", func(q *orm.Query) (*orm.Query, error) {
q.Where("status=0")
... ... @@ -66,7 +66,7 @@ func (repository *ProjectModuleRepository) FindOne(queryOptions map[string]inter
}
func (repository *ProjectModuleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectModule, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
var ProjectModuleModels []*models.ProjectModule
ProjectModules := make([]*domain.ProjectModule, 0)
query := NewQuery(tx.Model(&ProjectModuleModels), queryOptions).
... ...
... ... @@ -57,7 +57,7 @@ func (repository *ProjectModuleVersionRepository) Remove(ProjectModuleVersion *d
}
func (repository *ProjectModuleVersionRepository) FindOne(queryOptions map[string]interface{}) (*domain.ProjectModuleVersion, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
ProjectModuleVersionModel := new(models.ProjectModuleVersion)
query := NewQuery(tx.Model(ProjectModuleVersionModel), queryOptions)
query.SetWhere("id = ?", "id")
... ... @@ -73,7 +73,7 @@ func (repository *ProjectModuleVersionRepository) FindOne(queryOptions map[strin
}
func (repository *ProjectModuleVersionRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ProjectModuleVersion, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
var ProjectModuleVersionModels []*models.ProjectModuleVersion
ProjectModuleVersions := make([]*domain.ProjectModuleVersion, 0)
query := NewQuery(tx.Model(&ProjectModuleVersionModels), queryOptions).
... ...
... ... @@ -46,7 +46,7 @@ func (repository *RoleAccessRepository) Remove(RoleAccess *domain.RoleAccess) (*
}
func (repository *RoleAccessRepository) FindOne(queryOptions map[string]interface{}) (*domain.RoleAccess, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
RoleAccessModel := new(models.RoleAccess)
query := NewQuery(tx.Model(RoleAccessModel), queryOptions)
query.SetWhere("id = ?", "id")
... ... @@ -60,7 +60,7 @@ func (repository *RoleAccessRepository) FindOne(queryOptions map[string]interfac
}
func (repository *RoleAccessRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.RoleAccess, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
var RoleAccessModels []*models.RoleAccess
RoleAccesss := make([]*domain.RoleAccess, 0)
query := NewQuery(tx.Model(&RoleAccessModels), queryOptions).
... ...
... ... @@ -87,7 +87,7 @@ func (repository *RoleRepository) FindOne(queryOptions map[string]interface{}) (
}
func (repository *RoleRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Role, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
var RoleModels []*models.Role
Roles := make([]*domain.Role, 0)
query := NewQuery(tx.Model(&RoleModels), queryOptions).
... ...
... ... @@ -89,7 +89,7 @@ func (repository *UsersRepository) FindOne(queryOptions map[string]interface{})
}
func (repository *UsersRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Users, error) {
tx := repository.transactionContext.PgTx
tx := repository.transactionContext.PgDd
var UserModels []*models.Users
Users := make([]*domain.Users, 0)
query := NewQuery(tx.Model(&UserModels), queryOptions).
... ...
... ... @@ -9,7 +9,7 @@ import (
func init() {
beego.InsertFilter("*", beego.BeforeRouter, middleware.AllowCors())
beego.InsertFilter("/*", beego.BeforeExec, middleware.CreateRequstLogFilter())
beego.InsertFilter("/*", beego.BeforeExec, middleware.CreateRequestLogFilter())
beego.InsertFilter("/*", beego.AfterExec, middleware.CreateResponseLogFilter(), false)
beego.InsertFilter("/v1/auth/profile", beego.BeforeExec, middleware.CheckAuthorization)
... ...
... ... @@ -99,13 +99,13 @@ func InspectRoleAccess(parentObject string, skipUrl ...string) func(*context.Con
}
}
func CreateRequstLogFilter() func(ctx *context.Context) {
func CreateRequestLogFilter() func(ctx *context.Context) {
return func(ctx *context.Context) {
requestId := fmt.Sprintf("%v.%v.%v ", ctx.Input.Method(), ctx.Input.URI(), time.Now().UnixNano())
ctx.Request.Header.Add("requestId", requestId)
var body string = "{}"
if ctx.Input.GetData("requestBody") != nil {
body = string(ctx.Input.GetData("requestBody").([]byte))
if len(ctx.Input.RequestBody) > 0 {
body = string(ctx.Input.RequestBody)
}
log.Debug(fmt.Sprintf("====>Recv RequestId:%s \nBodyData:%s", requestId, body))
}
... ... @@ -118,7 +118,7 @@ func CreateResponseLogFilter() func(ctx *context.Context) {
if len(body) > 1000 {
body = body[:1000]
}
log.Debug(fmt.Sprintf("<====Send User:%v RequestId:%v BodyData:%s", ctx.Input.GetData("x-mmm-id"), requestId, body))
log.Debug(fmt.Sprintf("<====Send User:%v RequestId:%v \nResponseData:%s", ctx.Input.GetData("x-mmm-id"), requestId, body))
}
}
... ...