作者 yangfu

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.查询操作不使用事务
... ... @@ -7,9 +7,12 @@ require (
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/tiptok/gocomm v1.0.4
//github.com/tal-tech/go-zero v1.0.11
github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9
//github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e
//github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5
//github.com/openzipkin/zipkin-go v0.2.5
github.com/tiptok/gocomm v1.0.4
)
//replace github.com/tiptok/gocomm v1.0.3 => F:\go\src\learn_project\gocomm
... ...
... ... @@ -21,5 +21,30 @@ func main() {
Filename: constant.LOG_File,
Level: constant.LOG_LEVEL,
})
//{
// // set up a span reporter
// reporter := zipkinhttp.NewReporter("http://106.52.15.41:9411/api/v2/spans")
// defer reporter.Close()
//
// // create our local service endpoint
// endpoint, err := zipkin.NewEndpoint("godevp", "127.0.0.1:8080")
// if err != nil {
// log.Error("unable to create local endpoint: %+v\n", err)
// }
//
// // initialize our tracer
// nativeTracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(endpoint))
// if err != nil {
// log.Error("unable to create tracer: %+v\n", err)
// }
//
// // use zipkin-go-opentracing to wrap our tracer
// tracer := zipkinot.Wrap(nativeTracer)
//
// // optionally set as Global OpenTracing tracer instance
// opentracing.SetGlobalTracer(tracer)
//}
beego.Run()
}
... ...
... ... @@ -46,6 +46,10 @@ func (svr *AuthService) Login(header *protocol.RequestHeader, request *protocolx
err = protocol.NewCustomMessage(1, "密码有误!")
return
}
if user.Status != domain.StatusNormal {
err = protocol.NewCustomMessage(1, "该账号已被禁用!")
return
}
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": token, //"Bearer " + token,
... ... @@ -115,11 +119,15 @@ func (svr *AuthService) Profile(header *protocol.RequestHeader, request *protoco
"adminType": user.AdminType,
"roles": utils.LoadCustomField(roles, "Id", "RoleName"),
}
accessIds, _ := RoleAccessDao.GetRoleAccess(user.Roles...)
if len(accessIds) > 0 {
_, accesses, _ := AccessRepository.Find(map[string]interface{}{"inAccessIds": accessIds})
if user.AdminType == domain.UserAdmin {
_, accesses, _ := AccessRepository.Find(map[string]interface{}{})
rspMap["menus"] = accesses
} else {
accessIds, _ := RoleAccessDao.GetRoleAccess(user.Roles...)
if len(accessIds) > 0 {
_, accesses, _ := AccessRepository.Find(map[string]interface{}{"inAccessIds": accessIds})
rspMap["menus"] = accesses
}
}
rsp = rspMap
err = transactionContext.CommitTransaction()
... ...
... ... @@ -78,7 +78,7 @@ func (svr *CacheService) ValidUserAccess(userId int64, object string, method str
var userAccess []*domain.Access
var isAdmin bool
defer func() {
//log.Info(fmt.Sprintf("ValidUserAccess user:%v object:%v method:%v result:%v", userId, object, method, result))
log.Info(fmt.Sprintf("ValidUserAccess user:%v object:%v method:%v result:%v", userId, object, method, result))
}()
if isAdmin, err = svr.ValidUser(userId); err != nil {
return
... ... @@ -105,12 +105,28 @@ func KeyMatch3(key1 string, key2 string) bool {
re := regexp.MustCompile(`\{[^/]+\}`)
key2 = re.ReplaceAllString(key2, "$1[^/]+$2")
if RegexMatch(key1HasVersion(key1)+"/", "^"+key2+"$") {
return true
}
if RegexMatch(key1HasVersion(key1), "^"+key2+"$") {
return true
}
if RegexMatch(key1+"/", "^"+key2+"$") {
return true
}
return RegexMatch(key1, "^"+key2+"$")
}
func key1HasVersion(key1 string) string {
vTags := []string{"v1", "v2", "v3", "v4"} //,"v5","v6","v7","v8","v9"
for _, tag := range vTags {
if index := strings.Index(key1, tag); index >= 0 {
return key1[index+len(tag):]
}
}
return key1
}
// KeyEqual case key1='*' or key1=' ' result=true
func ActionEqual(key1 string, key2 string) bool {
if key1 == "*" {
... ...
package cachex
import "testing"
func TestKeyMatch3(t *testing.T) {
inputObject := []struct {
ReqObject string
CmpObject string
Result bool
}{
{
"/a/b",
"/a/b",
true,
},
{
"/v1/a/b",
"/a/b",
true,
},
}
for _, v := range inputObject {
if KeyMatch3(v.ReqObject, v.CmpObject) != v.Result {
t.Fatal(v.ReqObject, " not match ", v.CmpObject, "except:", v.Result)
}
}
}
... ...
... ... @@ -72,7 +72,7 @@ func (svr *ClientVersionService) UpdateClientVersion(header *protocol.RequestHea
if clientVersion, err = ClientVersionRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil {
return
}
if err = clientVersion.Update(common.ObjectToMap(request)); err != nil {
if err = clientVersion.Update((utils.LoadCustomField(request, header.BodyKeys...)).(map[string]interface{})); err != nil {
return
}
if clientVersion, err = ClientVersionRepository.Save(clientVersion); err != nil {
... ... @@ -165,7 +165,7 @@ func (svr *ClientVersionService) ListClientVersion(header *protocol.RequestHeade
rsp = map[string]interface{}{
"totalRow": total,
"pageNumber": (request.Offset + request.Limit) / request.Limit,
"list": utils.LoadCustomField(clientVersion, "Id", "ProjectName", "Version", "Title", "Remark", "CreateTime"),
"lists": utils.LoadCustomField(clientVersion, "Id", "ProjectName", "Version", "Title", "Remark", "CreateTime"),
}
err = transactionContext.CommitTransaction()
return
... ...
... ... @@ -41,7 +41,7 @@ func (svr *ProjectModuleService) CreateProjectModule(header *protocol.RequestHea
}
var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext)
if _, err = ProjectModuleRepository.FindOne(map[string]interface{}{"projectKey": request.ProjectKey}); err == nil {
if _, err = ProjectModuleRepository.FindOne(map[string]interface{}{"projectKey": request.ProjectKey, "status": domain.StatusNormal}); err == nil {
err = protocol.NewCustomMessage(1, "项目键值已存在:"+request.ProjectKey)
return
}
... ... @@ -87,9 +87,11 @@ func (svr *ProjectModuleService) UpdateProjectModule(header *protocol.RequestHea
err = protocol.NewCustomMessage(1, "模板项目不存在")
return
}
if _, err = ProjectModuleRepository.FindOne(map[string]interface{}{"projectKey": request.ProjectKey}); err == nil {
err = protocol.NewCustomMessage(1, "项目键值已存在:"+request.ProjectKey)
return
if projectModule.ProjectKey != request.ProjectKey {
if _, err = ProjectModuleRepository.FindOne(map[string]interface{}{"projectKey": request.ProjectKey, "status": domain.StatusNormal}); err == nil {
err = protocol.NewCustomMessage(1, "项目键值已存在:"+request.ProjectKey)
return
}
}
if err = projectModule.Update(common.ObjectToMap(request)); err != nil {
return
... ... @@ -181,13 +183,13 @@ func (svr *ProjectModuleService) ListProjectModule(header *protocol.RequestHeade
var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext)
var projectModule []*domain.ProjectModule
var total int64
if total, projectModule, err = ProjectModuleRepository.Find(map[string]interface{}{"offset": (request.PageNumber - 1) * request.PageSize, "limit": request.PageSize, "sortByCreateTime": "DESC", "status": domain.StatusNormal}); err != nil {
if total, projectModule, err = ProjectModuleRepository.Find(map[string]interface{}{"offset": (request.PageNumber - 1) * request.PageSize, "limit": request.PageSize, "sortByCreateTime": "DESC", "status": domain.StatusNormal, "searchByText": request.ProjectName}); err != nil {
return
}
rsp = map[string]interface{}{
"totalRow": total,
"pageNumber": request.PageNumber,
"list": utils.LoadCustomField(projectModule, "Id", "ProjectName", "ProjectKey", "Description", "Status", "CreateTime", "UpdateTime"), //listProjectModuleResponse.LoadDto(projectModule),
"lists": utils.LoadCustomField(projectModule, "Id", "ProjectName", "ProjectKey", "Description", "Status", "CreateTime", "UpdateTime"), //listProjectModuleResponse.LoadDto(projectModule),
}
err = transactionContext.CommitTransaction()
return
... ...
... ... @@ -45,7 +45,7 @@ func (svr *ProjectModuleFilesService) CreateProjectModuleFiles(header *protocol.
Remark: request.Remark,
CreateTime: time.Now(),
UpdateTime: time.Now(),
Path: request.FileKey,
Path: request.FileName,
}
if _, err = ProjectModuleVersion.FindOne(map[string]interface{}{"id": request.ProjectModuleVersionId, "projectModuleId": request.ProjectModuleId}); err != nil {
... ... @@ -85,20 +85,18 @@ func (svr *ProjectModuleFilesService) UpdateProjectModuleFiles(header *protocol.
if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil {
return
}
var oldProjectModuleFiles = *projectModuleFiles
oldFileName = projectModuleFiles.FileName
if err = projectModuleFiles.Update(common.ObjectToMap(request)); err != nil {
return
}
if projectModuleFiles, err = ProjectModuleFilesRepository.Save(projectModuleFiles); err != nil {
return
}
// 更新文件名称,修改子节点跟本身的路径 1.文件夹 2.文件
if request.FileName != oldFileName {
// TODO:判断是否重名
var oldPath = projectModuleFiles.Path
var newPath string
if index := strings.LastIndex(projectModuleFiles.Path, oldFileName); index > 0 {
if index := strings.LastIndex(projectModuleFiles.Path, oldFileName); index >= 0 {
newPath = projectModuleFiles.Path[:index] + request.FileName
projectModuleFiles.Path = newPath
}
... ... @@ -108,25 +106,26 @@ func (svr *ProjectModuleFilesService) UpdateProjectModuleFiles(header *protocol.
}
}
}
// TODO:移动文件文件夹时pid变更,底下路径需要都变掉
if projectModuleFiles, err = ProjectModuleFilesRepository.Save(projectModuleFiles); err != nil {
return
}
// TODO:移动文件文件夹时pid变更,底下路径需要都变掉,单独提取一个移动文件的接口
// 变更记录
var OperatorLogRepository, _ = factory.CreateOperatorLogRepository(transactionContext)
//var UserRepository, _ = factory.CreateUserRepository(transactionContext)
//user, _ := UserRepository.FindOne(map[string]interface{}{"id": header.UserId})
//if user == nil {
// return
//}
var OpLog *domain.OperatorLog = &domain.OperatorLog{
UserId: header.UserId,
Operator: header.UserName,
Code: domain.LogCodeEditModuleFile,
ResourceId: request.Id,
Content: changeLog(request, projectModuleFiles),
Content: changeLog(request, &oldProjectModuleFiles),
CreateTime: time.Now(),
}
if _, err = OperatorLogRepository.Save(OpLog); err != nil {
return
if len(OpLog.Content) > 0 {
if _, err = OperatorLogRepository.Save(OpLog); err != nil {
return
}
}
err = transactionContext.CommitTransaction()
... ... @@ -212,6 +211,25 @@ func (svr *ProjectModuleFilesService) ListProjectModuleFiles(header *protocol.Re
transactionContext.RollbackTransaction()
}()
// 通过project_key version_key 获取列表
if len(request.ProjectKey) > 0 && len(request.VersionKey) > 0 {
var ProjectModuleRepository, _ = factory.CreateProjectModuleRepository(transactionContext)
if project, _ := ProjectModuleRepository.FindOne(map[string]interface{}{"projectKey": request.ProjectKey, "status": domain.StatusNormal}); project != nil {
for _, v := range project.ProjectModuleVersion {
if v.Version == request.VersionKey {
request.ProjectModuleId = project.Id
request.ProjectModuleVersionId = v.Id
break
}
}
}
}
if request.ProjectModuleVersionId == 0 && request.ProjectModuleId == 0 {
err = protocol.NewCustomMessage(1, "不存在")
return
}
var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
var projectModuleFiles []*domain.ProjectModuleFiles
var total int64
... ... @@ -261,9 +279,9 @@ func (svr *ProjectModuleFilesService) Import(header *protocol.RequestHeader, req
fileDir := filepath.Dir(f.FileName)
fileBase := filepath.Base(f.FileName)
filename := strings.Split(fileBase, ".")[0]
var parentNode *domain.ProjectModuleFiles = &domain.ProjectModuleFiles{Path: "", ProjectModuleId: request.ProjectModuleId, ProjectModuleVersionId: request.ProjectModuleVersionId, Id: 0}
var parentNode *domain.ProjectModuleFiles = &domain.ProjectModuleFiles{Path: "", ProjectModuleId: request.ProjectModuleId, ProjectModuleVersionId: request.ProjectModuleVersionId, Id: request.ParentId}
var ok bool
if len(fileDir) > 0 {
if len(fileDir) > 0 && f.FileName != fileBase { //如果文件名跟路径一致,说明path是空
// create dir node
if parentNode, ok = mapParent[fileDir]; !ok {
parentNodes, _ := svr.mkdirF(fileDir, request.ProjectModuleId, request.ProjectModuleVersionId, request.ParentId, ProjectModuleFilesRepository)
... ... @@ -291,9 +309,10 @@ func (svr *ProjectModuleFilesService) Import(header *protocol.RequestHeader, req
UpdateTime: time.Now(),
Path: filename,
}
if _, e := svr.save(newItem, ProjectModuleFilesRepository); e != nil {
log.Error(e)
continue
if _, err = svr.save(newItem, ProjectModuleFilesRepository); err != nil {
log.Error(err)
//continue
return
}
}
... ... @@ -311,8 +330,8 @@ func (svr *ProjectModuleFilesService) save(request *domain.ProjectModuleFiles, P
request.Path = filepath.Join(pfile.Path, request.Path)
}
}
if m, e := ProjectModuleFilesRepository.FindOne(map[string]interface{}{"fileKey": request.FileKey, "projectModuleId": request.ProjectModuleId, "projectModuleVersionId": request.ProjectModuleVersionId, "parentId": request.ParentId}); e == nil && m != nil {
err = protocol.NewCustomMessage(1, "已存在 filekey:"+request.FileKey)
if m, e := ProjectModuleFilesRepository.FindOne(map[string]interface{}{"path": request.Path, "projectModuleId": request.ProjectModuleId, "projectModuleVersionId": request.ProjectModuleVersionId, "parentId": request.ParentId}); e == nil && m != nil {
err = protocol.NewCustomMessage(1, "已存在:"+request.Path)
rsp = m
return
}
... ... @@ -382,14 +401,14 @@ func traverse(list []*protocolx.ModuleFiles, file *domain.ProjectModuleFiles) {
}
func changeLog(request *protocolx.UpdateProjectModuleFilesRequest, old *domain.ProjectModuleFiles) string {
buf := bytes.NewBuffer(nil)
if len(request.FileName) > 0 {
buf.WriteString(" 修改文件名为:" + request.FileName + "\n")
if len(request.FileName) > 0 && request.FileName != old.FileName {
buf.WriteString("【文件名】修改为:" + request.FileName + "\n")
}
if len(request.Remark) > 0 {
buf.WriteString(" 修改描述信息为:" + request.Remark + "\n")
if len(request.Remark) > 0 && request.Remark != old.Remark {
buf.WriteString("【描述信息】修改为:" + request.Remark + "\n")
}
if len(request.CodeBlock) > 0 {
buf.WriteString(" 修改模板代码")
if len(request.CodeBlock) > 0 && request.CodeBlock != old.CodeBlock {
buf.WriteString("【模板代码】修改为:\n" + old.CodeBlock)
}
return buf.String()
}
... ...
... ... @@ -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)}); e == nil {
if _, e := ProjectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleId": srcVersion.ProjectModuleId, "version": strings.TrimSpace(request.Version), "status": 0}); e == nil {
err = protocol.NewCustomMessage(1, fmt.Sprintf("当前版本已存在:"+request.Version))
return
}
... ... @@ -62,7 +62,7 @@ func (svr *ProjectModuleVersionService) CreateProjectModuleVersion(header *proto
}
var ProjectModuleDao, _ = dao.NewProjectModuleDao(transactionContext)
if err = ProjectModuleDao.DuplicateVersion(srcVersion.ProjectModuleId, srcVersion.ProjectModuleId, currentPMVersionId); err != nil {
if err = ProjectModuleDao.DuplicateVersion(srcVersion.ProjectModuleId, srcVersion.Id, currentPMVersionId); err != nil {
return
}
err = transactionContext.CommitTransaction()
... ...
... ... @@ -90,7 +90,7 @@ func (svr *UserService) UpdateUser(header *protocol.RequestHeader, request *prot
err = protocol.NewCustomMessage(1, "用户不存在")
return
}
if request.Phone != "" {
if request.Phone != "" && request.Phone != user.Phone {
if _, err = UserRepository.FindOne(map[string]interface{}{"phone": request.Phone}); err == nil {
err = protocol.NewCustomMessage(1, "手机号已存在")
return
... ... @@ -226,7 +226,7 @@ func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protoc
}
userList := make([]map[string]interface{}, 0)
for _, v := range user {
item := map[string]interface{}{"id": v.Id, "name": v.Name, "adminType": v.AdminType, "status": v.Status, "createTime": v.CreateTime.Local().Format("2006-01-02 15:04:05")}
item := map[string]interface{}{"id": v.Id, "name": v.Name, "phone": v.Phone, "adminType": v.AdminType, "status": v.Status, "createTime": v.CreateTime.Local().Format("2006-01-02 15:04:05")}
item["roles"] = getRoles(v.Roles)
userList = append(userList, item)
}
... ... @@ -234,7 +234,7 @@ func (svr *UserService) ListUser(header *protocol.RequestHeader, request *protoc
rsp = map[string]interface{}{
"totalRow": total,
"pageNumber": request.PageNumber,
"list": userList,
"lists": userList,
}
if err = transactionContext.CommitTransaction(); err != nil {
err = application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
package domain
import "time"
import (
"time"
)
// ClientVersion
type ClientVersion struct {
... ...
... ... @@ -12,8 +12,8 @@ type ProjectModuleFilesDao struct {
func (dao *ProjectModuleFilesDao) UpdateFilesPath(srcProjectId, srcVersionId int64, oldPath, newPath string) error {
tx := dao.transactionContext.PgTx
_, err := tx.Exec(fmt.Sprintf(`update project_module_files set "path"= replace("path",?,?) where project_module_id=? and project_module_version_id=? and "path" like '%%%v%%'`, strings.Replace(oldPath, "\\", "\\\\", -1)),
oldPath, newPath, srcProjectId, srcVersionId)
_, err := tx.Exec(fmt.Sprintf(`update project_module_files set "path"= regexp_replace("path",'^%v',?) where project_module_id=? and project_module_version_id=? and "path" like '%%%v%%'`, oldPath, strings.Replace(oldPath, "\\", "\\\\", -1)),
newPath, srcProjectId, srcVersionId)
return err
}
... ...
... ... @@ -97,6 +97,10 @@ func (repository *ClientVersionRepository) Find(queryOptions map[string]interfac
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime").
SetLimit()
if searchByText, ok := queryOptions["searchByText"]; ok && len(searchByText.(string)) > 0 {
query.Where(fmt.Sprintf(`project_name like '%%%v%%'`, searchByText))
}
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, ClientVersions, err
... ...
... ... @@ -75,9 +75,11 @@ func (repository *ProjectModuleFilesRepository) Find(queryOptions map[string]int
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime").
SetOrder("parent_id", "sortByParentId").
SetOrder("file_type", "sortByFileType").
SetOrder("id", "sortById")
query.SetWhere("parent_id = ?", "parentId")
query.SetWhere("file_name = ?", "fileName")
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, ProjectModuleFiless, err
... ...
... ... @@ -56,6 +56,8 @@ func (repository *ProjectModuleRepository) FindOne(queryOptions map[string]inter
}), queryOptions)
query.SetWhere("id = ?", "id")
query.SetWhere("project_key = ?", "projectKey")
query.SetWhere("status=?", "status")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
... ... @@ -77,6 +79,11 @@ func (repository *ProjectModuleRepository) Find(queryOptions map[string]interfac
SetWhere("status=?", "status").
SetOrder("create_time", "sortByCreateTime").
SetOrder("update_time", "sortByUpdateTime").SetLimit()
if searchByText, ok := queryOptions["searchByText"]; ok && len(searchByText.(string)) > 0 {
query.Where(fmt.Sprintf(`project_name like '%%%v%%'`, searchByText))
}
var err error
if query.AffectRow, err = query.SelectAndCount(); err != nil {
return 0, ProjectModules, err
... ...
... ... @@ -63,6 +63,7 @@ func (repository *ProjectModuleVersionRepository) FindOne(queryOptions map[strin
query.SetWhere("id = ?", "id")
query.SetWhere("project_module_id = ?", "projectModuleId")
query.SetWhere("version = ?", "version")
query.SetWhere("status = ?", "status")
if err := query.First(); err != nil {
return nil, fmt.Errorf("query row not found")
}
... ...
... ... @@ -8,6 +8,7 @@ import (
func init() {
beego.InsertFilter("*", beego.BeforeRouter, middleware.AllowCors())
//beego.InsertFilter("*", beego.BeforeRouter, middleware.OpenTracingAdapter)
beego.InsertFilter("/*", beego.BeforeExec, middleware.CreateRequestLogFilter())
beego.InsertFilter("/*", beego.AfterExec, middleware.CreateResponseLogFilter(), false)
... ...
... ... @@ -5,6 +5,7 @@ import (
"encoding/json"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/tiptok/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
)
... ... @@ -23,6 +24,19 @@ func (controller BaseController) JsonUnmarshal(v interface{}) error {
return err
}
func (controller BaseController) BodyKeys(firstCaseToUpper bool) []string {
var bodyKV map[string]json.RawMessage
controller.JsonUnmarshal(&bodyKV)
if len(bodyKV) == 0 {
return []string{}
}
var list []string
for k, _ := range bodyKV {
list = append(list, common.CamelCase(k, true))
}
return list
}
func (controller *BaseController) Resp(msg *protocol.ResponseMessage) {
if msg.Errno != 0 {
msg.Errno = -1
... ... @@ -51,6 +65,6 @@ func (controller *BaseController) GetRequestHeader(ctx *context.Context) *protoc
if v := ctx.Input.GetData("x-mmm-uname"); v != nil {
h.UserName = v.(string)
}
h.BodyKeys = controller.BodyKeys(true)
return h
}
... ...
... ... @@ -45,6 +45,10 @@ func (controller *ClientVersionController) UpdateClientVersion() {
defer func() {
controller.Resp(msg)
}()
if err := controller.JsonUnmarshal(&request); err != nil {
msg = protocol.NewResponseMessage(2, err.Error())
return
}
request.Id, _ = controller.GetInt64(":clientVersionId")
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.UpdateClientVersion(header, request)
... ... @@ -106,6 +110,7 @@ func (controller *ClientVersionController) ListClientVersion() {
controller.Resp(msg)
}()
request.Offset, request.Limit = controller.GetLimitInfo()
request.SearchByText = controller.GetString("projectName")
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.ListClientVersion(header, request)
if err != nil {
... ...
... ... @@ -119,6 +119,7 @@ func (controller *OperatorLogController) ListOperatorLog() {
// return
//}
request.Offset, request.Limit = controller.GetLimitInfo()
request.ResourceId, _ = controller.GetInt64("resourceId")
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.ListOperatorLog(header, request)
if err != nil {
... ...
... ... @@ -115,6 +115,7 @@ func (controller *ProjectModuleController) ListProjectModule() {
}
request.PageNumber, _ = controller.GetInt("pageNumber")
request.PageSize, _ = controller.GetInt("pageSize")
request.ProjectName = controller.GetString("projectName")
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.ListProjectModule(header, request)
if err != nil {
... ...
... ... @@ -115,6 +115,10 @@ func (controller *ProjectModuleFilesController) ListProjectModuleFiles() {
request.ProjectModuleVersionId, _ = controller.GetInt64("projectModuleVersionId")
request.ProjectModuleId, _ = controller.GetInt64("projectModuleId")
request.StructType = controller.GetString("structType")
request.ProjectKey = controller.GetString("projectKey")
request.VersionKey = controller.GetString("versionKey")
request.FileName = controller.GetString("fileName")
header := controller.GetRequestHeader(controller.Ctx)
data, err := svr.ListProjectModuleFiles(header, request)
if err != nil {
... ...
... ... @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"github.com/astaxie/beego/context"
//"github.com/opentracing/opentracing-go"
"github.com/tiptok/gocomm/common"
"github.com/tiptok/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/cachex"
... ... @@ -136,3 +137,19 @@ func AllowCors() func(ctx *context.Context) {
}
}
}
//func OpenTracingAdapter(ctx *context.Context) {
// var sp opentracing.Span
// opName := ctx.Input.URL()
// // Attempt to join a trace by getting trace context from the headers.
// wireContext, err := opentracing.GlobalTracer().Extract(
// opentracing.HTTPHeaders,
// opentracing.HTTPHeadersCarrier(ctx.Request.Header))
// if err != nil {
// // If for whatever reason we can't join, go ahead an start a new root span.
// sp = opentracing.StartSpan(opName)
// } else {
// sp = opentracing.StartSpan(opName, opentracing.ChildOf(wireContext))
// }
// defer sp.Finish()
//}
... ...
... ... @@ -13,4 +13,6 @@ func init() {
beego.Router("/v1/project_module_files/", &controllers.ProjectModuleFilesController{}, "GET:ListProjectModuleFiles")
beego.Router("/v1/project_module_files/import", &controllers.ProjectModuleFilesController{}, "post:Import")
beego.Router("/v1/client/project_module_files/", &controllers.ProjectModuleFilesController{}, "GET:ListProjectModuleFiles")
}
... ...
... ... @@ -6,8 +6,9 @@ import (
)
type ListClientVersionRequest struct {
Offset int `json:"offset"`
Limit int `json:"limit"`
Offset int `json:"offset"`
Limit int `json:"limit"`
SearchByText string `json:"projectName,omitempty"` //按名称搜索
}
func (ListClientVersionRequest *ListClientVersionRequest) ValidateCommand() error {
... ...
... ... @@ -6,8 +6,9 @@ import (
)
type ListProjectModuleRequest struct {
PageSize int `json:"pageSize" valid:"Required"`
PageNumber int `json:"pageNumber" valid:"Required"`
PageSize int `json:"pageSize" valid:"Required"`
PageNumber int `json:"pageNumber" valid:"Required"`
ProjectName string `json:"projectName,omitempty"` //按名称搜索
}
func (ListProjectModuleRequest *ListProjectModuleRequest) ValidateCommand() error {
... ...
... ... @@ -7,15 +7,24 @@ import (
type ListProjectModuleFilesRequest struct {
// 项目模块编号
ProjectModuleId int64 `json:"projectModuleId,omitempty" valid:"Required"`
ProjectModuleId int64 `json:"projectModuleId,omitempty"`
// 项目模块版本编号
ProjectModuleVersionId int64 `json:"projectModuleVersionId,omitempty" valid:"Required"`
ProjectModuleVersionId int64 `json:"projectModuleVersionId,omitempty"`
// 返回结构类型 tree list 默认list
StructType string `json:"structType,omitempty"`
// 按父级Id排序
SortByParentId string `json:"sortByParentId,omitempty"`
// 按Id排序
SortById string `json:"sortById,omitempty"`
// 按文件类型
SortByFileType string `json:"sortByFileType,omitempty"`
// 项目模块编号
ProjectKey string `json:"projectKey,omitempty"`
// 项目模块版本编号
VersionKey string `json:"versionKey,omitempty"`
// 项目模块文件
FileName string `json:"fileName,omitempty"`
}
func (ListProjectModuleFilesRequest *ListProjectModuleFilesRequest) ValidateCommand() error {
... ... @@ -27,6 +36,9 @@ func (ListProjectModuleFilesRequest *ListProjectModuleFilesRequest) ValidateComm
if len(ListProjectModuleFilesRequest.SortById) == 0 {
ListProjectModuleFilesRequest.SortById = "ASC"
}
if len(ListProjectModuleFilesRequest.SortByFileType) == 0 {
ListProjectModuleFilesRequest.SortByFileType = "ASC"
}
if err != nil {
return err
}
... ...
... ... @@ -133,4 +133,5 @@ var errmessge ErrorMap = map[int]string{
type RequestHeader struct {
UserId int64 //UserId 唯一标识
UserName string
BodyKeys []string
}
... ...