作者 yangfu

branch fix bug

Squashed commit of the following:

commit 65f30f27951df5823526895d94c89ab0b8b49871
Author: yangfu <785409885@qq.com>
Date:   Wed Nov 18 15:14:17 2020 +0800

    1.操作日志修改
    2.客户端公共接口

commit 5602dfb1b9961cce87a9e08480e281d3fdad2771
Author: yangfu <785409885@qq.com>
Date:   Mon Nov 16 14:24:19 2020 +0800

    1.修复功能异常

commit 779c973def3e3c1ac9b0aa02e289aa3a24600ede
Author: yangfu <785409885@qq.com>
Date:   Wed Nov 11 16:00:19 2020 +0800

    1.token修改  2.查询操作不使用事务
... ... @@ -4,10 +4,10 @@ go 1.15
require (
github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2
//github.com/GeeTeam/gt3-golang-sdk v0.0.0-20200116043922-446ca8a507d2
github.com/astaxie/beego v1.12.2
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/go-pg/pg/v10 v10.0.0-beta.2
//github.com/tal-tech/go-zero v1.0.11
github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9
github.com/stretchr/testify v1.5.1
//github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e
... ...
... ... @@ -156,7 +156,7 @@ func (svr *AuthService) Profile(header *protocol.RequestHeader, request *protoco
_, accesses, _ := AccessRepository.Find(map[string]interface{}{})
rspMap["menus"] = accesses
} else {
accessIds, _ := RoleAccessDao.GetRoleAccess(user.Roles...)
accessIds, _ := RoleAccessDao.GetRoleAccess((domain.Roles(roles)).RoleIds()...)
if len(accessIds) > 0 {
_, accesses, _ := AccessRepository.Find(map[string]interface{}{"inAccessIds": accessIds})
rspMap["menus"] = accesses
... ...
... ... @@ -55,7 +55,7 @@ func (svr *ProjectModuleService) CreateProjectModule(header *protocol.RequestHea
ProjectModuleId: newProjectModule.Id,
Version: "latest",
Description: "latest version",
Status: 0,
Status: domain.StatusNormal,
CreateTime: time.Now(),
UpdateTime: time.Now(),
}); err != nil {
... ...
... ... @@ -89,7 +89,7 @@ func (svr *ProjectModuleFilesService) UpdateProjectModuleFiles(header *protocol.
}
var oldProjectModuleFiles = *projectModuleFiles
oldFileName = projectModuleFiles.FileName
if err = projectModuleFiles.Update(common.ObjectToMap(request)); err != nil {
if err = projectModuleFiles.Update(utils.LoadCustomFieldToMap(request, header.BodyKeys...)); err != nil {
return
}
... ... @@ -353,7 +353,10 @@ func (svr *ProjectModuleFilesService) ReviseTag(header *protocol.RequestHeader,
if len(request.Tag) == 0 {
if lastProjectModuleFiles, e := ProjectModuleFilesRepository.FindOne(map[string]interface{}{
"projectModuleId": projectModuleFiles.ProjectModuleId,
"projectModuleVersionId": projectModuleFiles.ProjectModuleVersionId, "path": projectModuleFiles.Path, "orderByTag": "DESC"}); e == nil {
"projectModuleVersionId": projectModuleFiles.ProjectModuleVersionId, "path": projectModuleFiles.Path,
//"orderByTag": "DESC",
"sortById": "DESC",
}); e == nil {
lastTag = lastProjectModuleFiles.Tag
}
}
... ...
... ... @@ -36,7 +36,7 @@ func (svr *ProjectModuleVersionService) CreateProjectModuleVersion(header *proto
newProjectModuleVersion := &domain.ProjectModuleVersion{
Version: strings.TrimSpace(request.Version),
Description: request.Description,
Status: 0,
Status: domain.StatusNormal,
CreateTime: time.Now(),
UpdateTime: time.Now(),
}
... ... @@ -50,7 +50,7 @@ func (svr *ProjectModuleVersionService) CreateProjectModuleVersion(header *proto
}
newProjectModuleVersion.ProjectModuleId = srcVersion.ProjectModuleId
if _, e := ProjectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleId": srcVersion.ProjectModuleId, "version": strings.TrimSpace(request.Version), "status": 0}); e == nil {
if _, e := ProjectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleId": srcVersion.ProjectModuleId, "version": strings.TrimSpace(request.Version), "status": domain.StatusNormal}); e == nil {
err = protocol.NewCustomMessage(1, fmt.Sprintf("当前版本已存在:"+request.Version))
return
}
... ... @@ -162,7 +162,7 @@ func (svr *ProjectModuleVersionService) DeleteProjectModuleVersion(header *proto
err = protocol.NewCustomMessage(1, "版本信息不存在")
return
}
if projectModuleVersion.Status == 1 {
if projectModuleVersion.Status == domain.StatusDelete {
err = protocol.NewCustomMessage(1, "已删除")
return
}
... ... @@ -194,7 +194,7 @@ func (svr *ProjectModuleVersionService) ListProjectModuleVersion(header *protoco
var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext)
var projectModuleVersion []*domain.ProjectModuleVersion
var total int64
if total, projectModuleVersion, err = ProjectModuleVersionRepository.Find(map[string]interface{}{"projectModuleId": request.ProjectModuleId, "status": 0}); err != nil {
if total, projectModuleVersion, err = ProjectModuleVersionRepository.Find(map[string]interface{}{"projectModuleId": request.ProjectModuleId, "status": domain.StatusNormal}); err != nil {
return
}
rsp = map[string]interface{}{
... ...
... ... @@ -115,11 +115,7 @@ func (svr *RbacService) SetRoleAccess(header *protocol.RequestHeader, request *p
}
var accessMap = make(map[int64]*domain.Access)
_, access, e := AccessRepository.Find(map[string]interface{}{"inAccessIds": request.AccessIds})
if e != nil {
err = e
return
}
_, access, _ := AccessRepository.Find(map[string]interface{}{"inAccessIds": request.AccessIds})
for _, v := range access {
accessMap[v.Id] = v
}
... ...
... ... @@ -96,7 +96,8 @@ func (svr *UserService) UpdateUser(header *protocol.RequestHeader, request *prot
return
}
}
if err = user.Update(common.ObjectToMap(request)); err != nil {
// common.ObjectToMap(request)
if err = user.Update(utils.LoadCustomFieldToMap(request, header.BodyKeys...)); err != nil {
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
return
}
... ... @@ -136,11 +137,13 @@ func (svr *UserService) GetUser(header *protocol.RequestHeader, request *protoco
return
}
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")
var roles []*domain.Role
for _, v := range user.Roles {
if role, e := RoleRepository.FindOne(map[string]interface{}{"id": v}); e == nil {
roles = append(roles, role)
}
}
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())
... ... @@ -202,25 +205,31 @@ func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protoc
transactionContext.RollbackTransaction()
}()
_, roles, _ := RoleRepository.Find(map[string]interface{}{})
roleMap := domain.Roles(roles).RoleMap()
getRoles := func(roleIds []int64) string {
if len(roleIds) == 0 {
return ""
}
var role []string
var roles []string
var mapRoles = make(map[int64]*domain.Role)
for _, id := range roleIds {
if v, ok := roleMap[id]; ok {
role = append(role, v.RoleName)
if _, ok := mapRoles[id]; ok {
continue
}
if roleItem, _ := RoleRepository.FindOne(map[string]interface{}{"id": id}); roleItem != nil {
roles = append(roles, roleItem.RoleName)
} else {
mapRoles[id] = nil
}
continue
}
return strings.Join(role, ",")
return strings.Join(roles, ",")
}
// TODO:可优化,每次只查询 user.id 列表 ,通过缓存查询user对象
var UserRepository, _ = factory.CreateUserRepository(transactionContext)
var user []*domain.Users
var total int64
if total, user, err = UserRepository.Find(map[string]interface{}{"offset": (request.PageNumber - 1) * request.PageSize, "limit": request.PageSize, "searchByText": request.SearchByText, "sortById": "DESC"}); err != nil {
if total, user, err = UserRepository.Find(common.ObjectToMap(request)); err != nil {
err = application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
return
}
... ...
... ... @@ -12,7 +12,7 @@ type ProjectModuleVersion struct {
Version string `json:"version"`
// 项目描述信息
Description string `json:"description"`
// 状态 0:正常 1:删除
// 状态 1:正常 2:删除
Status int `json:"status"`
// 创建时间
CreateTime time.Time `json:"createTime"`
... ... @@ -48,5 +48,5 @@ func (m *ProjectModuleVersion) Update(data map[string]interface{}) error {
}
func (m *ProjectModuleVersion) SetStatusDelete() {
m.Status = 1
m.Status = StatusDelete
}
... ...
... ... @@ -51,6 +51,13 @@ func (roles Roles) RoleMap() map[int64]*Role {
}
return retMap
}
func (roles Roles) RoleIds() []int64 {
var ids []int64
for _, v := range roles {
ids = append(ids, v.Id)
}
return ids
}
//func(roles Roles)RolesWithMap(roleMap map[int64]*Role,roleIds []int64)string{
// var role []string
... ...
... ... @@ -13,7 +13,7 @@ type ProjectModuleVersion struct {
Version string
// 项目描述信息
Description string
// 状态 0:正常 1:删除
// 状态 1:正常 2:删除
Status int
// 创建时间
CreateTime time.Time
... ...
... ... @@ -17,7 +17,7 @@ func (repository *ProjectModuleFilesRepository) Save(dm *domain.ProjectModuleFil
var (
err error
m = &models.ProjectModuleFiles{}
tx = repository.transactionContext.PgTx
tx = repository.transactionContext.PgDd
)
if err = common.GobModelTransform(m, dm); err != nil {
return nil, err
... ... @@ -58,6 +58,7 @@ func (repository *ProjectModuleFilesRepository) FindOne(queryOptions map[string]
query.SetWhere("path = ?", "path")
query.SetOrder("tag", "orderByTag")
query.SetOrder("id", "sortById")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
... ... @@ -78,6 +79,8 @@ func (repository *ProjectModuleFilesRepository) Find(queryOptions map[string]int
SetOrder("update_time", "sortByUpdateTime").
SetOrder("parent_id", "sortByParentId").
SetOrder("file_type", "sortByFileType").
SetOrder("file_name", "sortByFileName").
//SetOrder("tag", "sortByTag").
SetOrder("id", "sortById")
query.SetWhere("parent_id = ?", "parentId")
... ...
... ... @@ -6,6 +6,14 @@ import (
"time"
)
func LoadCustomFieldToMap(src interface{}, fields ...string) map[string]interface{} {
rsp := LoadCustomField(src, fields...)
if rsp == nil {
return map[string]interface{}{}
}
return rsp.(map[string]interface{})
}
func LoadCustomField(src interface{}, fields ...string) interface{} {
typeSrc := reflect.TypeOf(src)
valueSrc := reflect.ValueOf(src)
... ...
... ... @@ -71,5 +71,10 @@ func (controller *BaseController) GetRequestHeader(ctx *context.Context) *protoc
h.Token = strings.Split(h.Token, " ")[1]
}
h.BodyKeys = controller.BodyKeys(true)
if v := ctx.Request.URL.Query(); len(v) > 0 {
for k, _ := range v {
h.BodyKeys = append(h.BodyKeys, common.CamelCase(k, true))
}
}
return h
}
... ...
... ... @@ -110,7 +110,9 @@ func (controller *UserController) ListUser() {
controller.Resp(msg)
}()
request.PageNumber, _ = controller.GetInt("pageNumber")
request.PageSize, _ = controller.GetInt("pageSize")
//request.PageSize, _ = controller.GetInt("pageSize")
request.Offset, request.Limit = controller.GetLimitInfo()
request.SearchByText = controller.GetString("searchByText")
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.ListUser(header, request)
... ...
... ... @@ -18,6 +18,8 @@ type ListProjectModuleFilesRequest struct {
SortById string `json:"sortById,omitempty"`
// 按文件类型
SortByFileType string `json:"sortByFileType,omitempty"`
// 按文件名
SortByFileName string `json:"sortByFileName,omitempty"`
// 项目模块编号
ProjectKey string `json:"projectKey,omitempty"`
... ... @@ -36,6 +38,9 @@ func (ListProjectModuleFilesRequest *ListProjectModuleFilesRequest) ValidateComm
if len(ListProjectModuleFilesRequest.SortById) == 0 {
ListProjectModuleFilesRequest.SortById = "ASC"
}
if len(ListProjectModuleFilesRequest.SortByFileName) == 0 {
ListProjectModuleFilesRequest.SortByFileName = "ASC"
}
if len(ListProjectModuleFilesRequest.SortByFileType) == 0 {
ListProjectModuleFilesRequest.SortByFileType = "ASC"
}
... ...
... ... @@ -7,14 +7,21 @@ import (
type ListUserRequest struct {
SearchByText string `json:"searchByText,omitempty"` //按名称搜索
PageSize int `json:"pageSize" valid:"Required"`
PageNumber int `json:"pageNumber" valid:"Required"`
//PageSize int `json:"pageSize" valid:"Required"`
PageNumber int `json:"pageNumber" valid:"Required"`
Offset int `json:"offset"`
Limit int `json:"limit"`
SortById string `json:"sortById"`
}
func (ListUserRequest *ListUserRequest) ValidateCommand() error {
valid := validation.Validation{}
if ListUserRequest.PageSize == 0 {
ListUserRequest.PageSize = 20
//if ListUserRequest.PageSize == 0 {
// ListUserRequest.PageSize = 20
//}
if len(ListUserRequest.SortById) == 0 {
ListUserRequest.SortById = "DESC"
}
b, err := valid.Valid(ListUserRequest)
if err != nil {
... ...