...
|
...
|
@@ -2,6 +2,7 @@ package project_module_files |
|
|
|
|
|
import (
|
|
|
"bytes"
|
|
|
"fmt"
|
|
|
"github.com/tiptok/gocomm/common"
|
|
|
"github.com/tiptok/gocomm/pkg/log"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
|
...
|
...
|
@@ -11,6 +12,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
|
|
|
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_files"
|
|
|
"path/filepath"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
...
|
...
|
@@ -238,7 +240,7 @@ func (svr *ProjectModuleFilesService) ListProjectModuleFiles(header *protocol.Re |
|
|
}
|
|
|
rsp = map[string]interface{}{
|
|
|
"total": total,
|
|
|
"list": utils.LoadCustomField(projectModuleFiles, "Id", "FileType", "FileName", "ParentId", "Path", "CodeBlock"),
|
|
|
"list": utils.LoadCustomField(projectModuleFiles, "Id", "FileType", "FileName", "ParentId", "Path", "CodeBlock", "Tag"),
|
|
|
}
|
|
|
if request.StructType == "tree" {
|
|
|
rsp = map[string]interface{}{
|
...
|
...
|
@@ -321,6 +323,51 @@ func (svr *ProjectModuleFilesService) Import(header *protocol.RequestHeader, req |
|
|
return
|
|
|
}
|
|
|
|
|
|
// ReviseTag
|
|
|
// 修订标签
|
|
|
func (svr *ProjectModuleFilesService) ReviseTag(header *protocol.RequestHeader, request *protocolx.ReviseTagRequest) (rsp interface{}, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
)
|
|
|
rsp = &protocolx.ReviseTagResponse{}
|
|
|
if err = request.ValidateCommand(); err != nil {
|
|
|
err = protocol.NewCustomMessage(2, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
log.Error(err)
|
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
|
|
|
var projectModuleFiles *domain.ProjectModuleFiles
|
|
|
if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
var lastTag string
|
|
|
// 为传入tag,自动生成一个tag
|
|
|
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 {
|
|
|
lastTag = lastProjectModuleFiles.Tag
|
|
|
}
|
|
|
}
|
|
|
lastTag = makeTag(lastTag)
|
|
|
projectModuleFiles.Tag = lastTag
|
|
|
projectModuleFiles.Id = 0
|
|
|
if rsp, err = ProjectModuleFilesRepository.Save(projectModuleFiles); err != nil {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func (svr *ProjectModuleFilesService) save(request *domain.ProjectModuleFiles, ProjectModuleFilesRepository domain.ProjectModuleFilesRepository) (rsp *domain.ProjectModuleFiles, err error) {
|
|
|
if request.ParentId > 0 {
|
|
|
if pfile, e := ProjectModuleFilesRepository.FindOne(map[string]interface{}{"id": request.ParentId, "projectModuleId": request.ProjectModuleId, "projectModuleVersionId": request.ProjectModuleVersionId}); e != nil {
|
...
|
...
|
@@ -416,3 +463,27 @@ func NewProjectModuleFilesService(options map[string]interface{}) *ProjectModule |
|
|
svr := &ProjectModuleFilesService{}
|
|
|
return svr
|
|
|
}
|
|
|
|
|
|
func makeTag(lastTag string) string {
|
|
|
if len(lastTag) == 0 {
|
|
|
return "v0.1"
|
|
|
}
|
|
|
rspTag := lastTag + common.RandomString(1)
|
|
|
if strings.Index(lastTag, "v") < 0 {
|
|
|
return rspTag
|
|
|
}
|
|
|
lastTag = lastTag[1:]
|
|
|
rspTag = "v"
|
|
|
splitTag := strings.Split(lastTag, ".")
|
|
|
for i, v := range splitTag {
|
|
|
version, _ := strconv.Atoi(v)
|
|
|
if version > 0 {
|
|
|
return fmt.Sprintf("%v%v", rspTag, version+1)
|
|
|
}
|
|
|
rspTag += v
|
|
|
if i+1 != len(splitTag) {
|
|
|
rspTag += "."
|
|
|
}
|
|
|
}
|
|
|
return rspTag + common.RandomString(1)
|
|
|
} |
...
|
...
|
|