...
|
...
|
@@ -5,6 +5,8 @@ import ( |
|
|
"github.com/tiptok/gocomm/pkg/log"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/infrastructure/utils"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol"
|
|
|
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_files"
|
|
|
"path/filepath"
|
...
|
...
|
@@ -37,7 +39,7 @@ func (svr *ProjectModuleFilesService) CreateProjectModuleFiles(header *protocol. |
|
|
ParentId: request.ParentId,
|
|
|
FileType: request.FileType,
|
|
|
FileName: request.FileName,
|
|
|
FileKey: request.FileKey,
|
|
|
FileKey: request.FileName,
|
|
|
CodeBlock: request.CodeBlock,
|
|
|
Remark: request.Remark,
|
|
|
CreateTime: time.Now(),
|
...
|
...
|
@@ -49,6 +51,7 @@ func (svr *ProjectModuleFilesService) CreateProjectModuleFiles(header *protocol. |
|
|
err = protocol.NewCustomMessage(1, "项目版本不存在")
|
|
|
return
|
|
|
}
|
|
|
// TODO:判断是否重名
|
|
|
var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
|
|
|
if rsp, err = svr.save(newProjectModuleFiles, ProjectModuleFilesRepository); err != nil {
|
|
|
return
|
...
|
...
|
@@ -60,10 +63,12 @@ func (svr *ProjectModuleFilesService) CreateProjectModuleFiles(header *protocol. |
|
|
func (svr *ProjectModuleFilesService) UpdateProjectModuleFiles(header *protocol.RequestHeader, request *protocolx.UpdateProjectModuleFilesRequest) (rsp interface{}, err error) {
|
|
|
var (
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
ProjectModuleFilesDao, _ = dao.NewProjectModuleFilesDao(transactionContext)
|
|
|
)
|
|
|
rsp = &protocolx.UpdateProjectModuleFilesResponse{}
|
|
|
if err = request.ValidateCommand(); err != nil {
|
|
|
err = protocol.NewCustomMessage(2, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -75,15 +80,36 @@ func (svr *ProjectModuleFilesService) UpdateProjectModuleFiles(header *protocol. |
|
|
|
|
|
var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
|
|
|
var projectModuleFiles *domain.ProjectModuleFiles
|
|
|
if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(common.ObjectToMap(request)); err != nil {
|
|
|
var oldFileName string
|
|
|
if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil {
|
|
|
return
|
|
|
}
|
|
|
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 {
|
|
|
newPath = projectModuleFiles.Path[:index] + request.FileName
|
|
|
projectModuleFiles.Path = newPath
|
|
|
}
|
|
|
if projectModuleFiles.FileType == domain.Dir {
|
|
|
if err = ProjectModuleFilesDao.UpdateFilesPath(projectModuleFiles.ProjectModuleId, projectModuleFiles.ProjectModuleVersionId, oldPath, newPath); err != nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// TODO:移动文件文件夹时pid变更,底下路径需要都变掉
|
|
|
|
|
|
// TODO:变更记录
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -132,9 +158,16 @@ func (svr *ProjectModuleFilesService) DeleteProjectModuleFiles(header *protocol. |
|
|
|
|
|
var ProjectModuleFilesRepository, _ = factory.CreateProjectModuleFilesRepository(transactionContext)
|
|
|
var projectModuleFiles *domain.ProjectModuleFiles
|
|
|
if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(common.ObjectToMap(request)); err != nil {
|
|
|
if projectModuleFiles, err = ProjectModuleFilesRepository.FindOne(map[string]interface{}{"id": request.Id}); err != nil {
|
|
|
err = protocol.NewCustomMessage(1, "文件不存在")
|
|
|
return
|
|
|
}
|
|
|
if projectModuleFiles.FileType == domain.Dir {
|
|
|
if count, _, e := ProjectModuleFilesRepository.Find(map[string]interface{}{"parentId": request.Id}); e == nil && count > 0 {
|
|
|
err = protocol.NewCustomMessage(1, "文件夹不为空")
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
if projectModuleFiles, err = ProjectModuleFilesRepository.Remove(projectModuleFiles); err != nil {
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -168,7 +201,13 @@ func (svr *ProjectModuleFilesService) ListProjectModuleFiles(header *protocol.Re |
|
|
}
|
|
|
rsp = map[string]interface{}{
|
|
|
"total": total,
|
|
|
"list": projectModuleFiles,
|
|
|
"list": utils.LoadCustomField(projectModuleFiles, "Id", "FileType", "FileName", "ParentId", "Path", "CodeBlock"),
|
|
|
}
|
|
|
if request.StructType == "tree" {
|
|
|
rsp = map[string]interface{}{
|
|
|
"total": total,
|
|
|
"list": svr.traverseModuleFiles(projectModuleFiles),
|
|
|
}
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
...
|
...
|
@@ -298,6 +337,30 @@ func (svr *ProjectModuleFilesService) mkdirF(fileDir string, mid, vid, pid int64 |
|
|
return
|
|
|
}
|
|
|
|
|
|
func (svr *ProjectModuleFilesService) traverseModuleFiles(files []*domain.ProjectModuleFiles) interface{} {
|
|
|
|
|
|
retSlice := make([]*protocolx.ModuleFiles, 0)
|
|
|
|
|
|
for i := range files {
|
|
|
if files[i].ParentId == 0 {
|
|
|
retSlice = append(retSlice, &protocolx.ModuleFiles{ModuleFile: protocolx.NewModuleFile(files[i]), List: make([]*protocolx.ModuleFiles, 0)})
|
|
|
continue
|
|
|
}
|
|
|
traverse(retSlice, files[i])
|
|
|
}
|
|
|
return retSlice
|
|
|
}
|
|
|
|
|
|
func traverse(list []*protocolx.ModuleFiles, file *domain.ProjectModuleFiles) {
|
|
|
for i := range list {
|
|
|
if list[i].Id == file.ParentId {
|
|
|
list[i].List = append(list[i].List, &protocolx.ModuleFiles{ModuleFile: protocolx.NewModuleFile(file), List: make([]*protocolx.ModuleFiles, 0)})
|
|
|
return
|
|
|
}
|
|
|
traverse(list[i].List, file)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
func NewProjectModuleFilesService(options map[string]interface{}) *ProjectModuleFilesService {
|
|
|
svr := &ProjectModuleFilesService{}
|
|
|
return svr
|
...
|
...
|
|