...
|
...
|
@@ -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()
|
|
|
}
|
...
|
...
|
|