|
|
package project_module_version
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"github.com/tiptok/gocomm/common"
|
|
|
"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/protocol"
|
|
|
protocolx "gitlab.fjmaimaimai.com/mmm-go/godevp/pkg/protocol/project_module_version"
|
|
|
"strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -20,6 +23,7 @@ func (svr *ProjectModuleVersionService) CreateProjectModuleVersion(header *proto |
|
|
rsp = &protocolx.CreateProjectModuleVersionResponse{}
|
|
|
if err = request.ValidateCommand(); err != nil {
|
|
|
err = protocol.NewCustomMessage(2, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -29,18 +33,36 @@ func (svr *ProjectModuleVersionService) CreateProjectModuleVersion(header *proto |
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
newProjectModuleVersion := &domain.ProjectModuleVersion{
|
|
|
Version: request.Version,
|
|
|
Version: strings.TrimSpace(request.Version),
|
|
|
Description: request.Description,
|
|
|
Status: request.Status,
|
|
|
Status: 0,
|
|
|
CreateTime: time.Now(),
|
|
|
UpdateTime: time.Now(),
|
|
|
}
|
|
|
|
|
|
var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext)
|
|
|
if m, err := ProjectModuleVersionRepository.Save(newProjectModuleVersion); err != nil {
|
|
|
return nil, err
|
|
|
var srcVersion, dstVersion *domain.ProjectModuleVersion
|
|
|
var currentPMVersionId int64
|
|
|
if srcVersion, err = ProjectModuleVersionRepository.FindOne(map[string]interface{}{"id": request.CurrentProjectModuleVersionId}); err != nil {
|
|
|
err = protocol.NewCustomMessage(1, fmt.Sprintf("当前版本不存在,请重试"))
|
|
|
return
|
|
|
}
|
|
|
newProjectModuleVersion.ProjectModuleId = srcVersion.ProjectModuleId
|
|
|
|
|
|
if _, e := ProjectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleId": srcVersion.ProjectModuleId, "version": strings.TrimSpace(request.Version)}); e == nil {
|
|
|
err = protocol.NewCustomMessage(1, fmt.Sprintf("当前版本已存在:"+request.Version))
|
|
|
return
|
|
|
}
|
|
|
if dstVersion, err = ProjectModuleVersionRepository.Save(newProjectModuleVersion); err != nil {
|
|
|
return
|
|
|
} else {
|
|
|
rsp = m
|
|
|
currentPMVersionId = dstVersion.Id
|
|
|
rsp = dstVersion
|
|
|
}
|
|
|
|
|
|
var ProjectModuleDao, _ = dao.NewProjectModuleDao(transactionContext)
|
|
|
if err = ProjectModuleDao.DuplicateVersion(srcVersion.ProjectModuleId, srcVersion.ProjectModuleId, currentPMVersionId); err != nil {
|
|
|
return
|
|
|
}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
...
|
...
|
@@ -53,6 +75,7 @@ func (svr *ProjectModuleVersionService) UpdateProjectModuleVersion(header *proto |
|
|
rsp = &protocolx.UpdateProjectModuleVersionResponse{}
|
|
|
if err = request.ValidateCommand(); err != nil {
|
|
|
err = protocol.NewCustomMessage(2, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -64,9 +87,17 @@ func (svr *ProjectModuleVersionService) UpdateProjectModuleVersion(header *proto |
|
|
|
|
|
var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext)
|
|
|
var projectModuleVersion *domain.ProjectModuleVersion
|
|
|
if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(common.ObjectToMap(request)); err != nil {
|
|
|
if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(map[string]interface{}{"id": request.ProjectModuleVersionId}); err != nil {
|
|
|
err = protocol.NewCustomMessage(1, "版本信息不存在")
|
|
|
return
|
|
|
}
|
|
|
// 修改版本号
|
|
|
if len(request.Version) > 0 && projectModuleVersion.Version != request.Version {
|
|
|
if _, err = ProjectModuleVersionRepository.FindOne(map[string]interface{}{"projectModuleId": projectModuleVersion.ProjectModuleId, "version": request.Version}); err == nil {
|
|
|
err = protocol.NewCustomMessage(1, "版本信息已存在:"+request.Version)
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
if err = projectModuleVersion.Update(common.ObjectToMap(request)); err != nil {
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -84,6 +115,7 @@ func (svr *ProjectModuleVersionService) GetProjectModuleVersion(header *protocol |
|
|
rsp = &protocolx.GetProjectModuleVersionResponse{}
|
|
|
if err = request.ValidateCommand(); err != nil {
|
|
|
err = protocol.NewCustomMessage(2, err.Error())
|
|
|
return
|
|
|
}
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -96,6 +128,7 @@ func (svr *ProjectModuleVersionService) GetProjectModuleVersion(header *protocol |
|
|
var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext)
|
|
|
var projectModuleVersion *domain.ProjectModuleVersion
|
|
|
if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(common.ObjectToMap(request)); err != nil {
|
|
|
err = protocol.NewCustomMessage(1, "版本信息不存在")
|
|
|
return
|
|
|
}
|
|
|
rsp = projectModuleVersion
|
...
|
...
|
@@ -122,9 +155,15 @@ func (svr *ProjectModuleVersionService) DeleteProjectModuleVersion(header *proto |
|
|
var ProjectModuleVersionRepository, _ = factory.CreateProjectModuleVersionRepository(transactionContext)
|
|
|
var projectModuleVersion *domain.ProjectModuleVersion
|
|
|
if projectModuleVersion, err = ProjectModuleVersionRepository.FindOne(common.ObjectToMap(request)); err != nil {
|
|
|
err = protocol.NewCustomMessage(1, "版本信息不存在")
|
|
|
return
|
|
|
}
|
|
|
if projectModuleVersion.Status == 1 {
|
|
|
err = protocol.NewCustomMessage(1, "已删除")
|
|
|
return
|
|
|
}
|
|
|
if projectModuleVersion, err = ProjectModuleVersionRepository.Remove(projectModuleVersion); err != nil {
|
|
|
projectModuleVersion.SetStatusDelete()
|
|
|
if projectModuleVersion, err = ProjectModuleVersionRepository.Save(projectModuleVersion); err != nil {
|
|
|
return
|
|
|
}
|
|
|
rsp = projectModuleVersion
|
...
|
...
|
@@ -151,7 +190,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(common.ObjectToMap(request)); err != nil {
|
|
|
if total, projectModuleVersion, err = ProjectModuleVersionRepository.Find(map[string]interface{}{"projectModuleId": request.ProjectModuleId, "status": 0}); err != nil {
|
|
|
return
|
|
|
}
|
|
|
rsp = map[string]interface{}{
|
...
|
...
|
|