作者 陈志颖

feat:共创项目增加共创模式

... ... @@ -5,7 +5,6 @@ import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/command"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/dto"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/query"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
... ... @@ -119,39 +118,57 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
organization = data
}
newCooperationProject := &domain.CooperationProject{
CooperationProjectNumber: createCooperationProjectCommand.CooperationModeNumber,
CooperationProjectName: createCooperationProjectCommand.CooperationProjectName,
CooperationProjectUndertakerTypes: createCooperationProjectCommand.CooperationProjectUndertakerTypes,
CooperationProjectSponsor: sponsor,
CooperationProjectPublisher: publisher,
CooperationProjectDescription: createCooperationProjectCommand.CooperationProjectDescription,
CooperationProjectPublishTime: time.Now(),
Company: company,
Department: organization.ToDepartment(),
Org: organization,
Operator: operator,
OperateTime: time.Now(),
Status: 0,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
}
var cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
// 查找共创模式
var cooperationModeRepository domain.CooperationModeRepository
if value, err := factory.CreateCooperationModeRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationProjectRepository = value
cooperationModeRepository = value
}
if cooperationProject, err := cooperationProjectRepository.Save(newCooperationProject); err != nil {
cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{"cooperationModeNumber": createCooperationProjectCommand.CooperationModeNumber})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationMode == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationProjectCommand.CooperationModeNumber))
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
newCooperationProject := &domain.CooperationProject{
CooperationProjectNumber: createCooperationProjectCommand.CooperationModeNumber,
CooperationProjectName: createCooperationProjectCommand.CooperationProjectName,
CooperationProjectUndertakerTypes: createCooperationProjectCommand.CooperationProjectUndertakerTypes,
CooperationProjectSponsor: sponsor,
CooperationMode: cooperationMode,
CooperationProjectPublisher: publisher,
CooperationProjectDescription: createCooperationProjectCommand.CooperationProjectDescription,
CooperationProjectPublishTime: time.Now(),
Company: company,
Department: organization.ToDepartment(),
Org: organization,
Operator: operator,
OperateTime: time.Now(),
Status: 0,
UpdatedAt: time.Time{},
DeletedAt: time.Time{},
CreatedAt: time.Now(),
}
var cooperationProjectRepository domain.CooperationProjectRepository
if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
cooperationProjectRepository = value
}
if cooperationProject, err := cooperationProjectRepository.Save(newCooperationProject); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cooperationProject, nil
}
return cooperationProject, nil
}
}
... ... @@ -192,7 +209,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
}
}
// ListCooperationProject 返回共创项目服务列表
// ListCooperationProject 返回共创项目列表
func (cooperationProjectService *CooperationProjectService) ListCooperationProject(listCooperationProjectQuery *query.ListCooperationProjectQuery) (interface{}, error) {
if err := listCooperationProjectQuery.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -218,7 +235,6 @@ func (cooperationProjectService *CooperationProjectService) ListCooperationProje
if count, cooperationProjects, err := cooperationProjectRepository.Find(tool_funs.SimpleStructToMap(listCooperationProjectQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
//var cooperationModeRepository domain.CooperationModeRepository
//if value, err := factory.CreateCooperationProjectRepository(map[string]interface{}{
// "transactionContext": transactionContext,
... ... @@ -237,22 +253,23 @@ func (cooperationProjectService *CooperationProjectService) ListCooperationProje
// }
//}
//
var res []*dto.CooperationProjectsDto
for i := range cooperationProjects {
p := cooperationProjects[i]
tp := &dto.CooperationProjectsDto{}
tp.LoadDto(p, &domain.CooperationMode{})
res = append(res, tp)
}
//var res []*dto.CooperationProjectsDto
//for i := range cooperationProjects {
// p := cooperationProjects[i]
// tp := &dto.CooperationProjectsDto{}
// tp.LoadDto(p, &domain.CooperationMode{})
// res = append(res, tp)
//}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
//"grid": map[string]interface{}{
"total": count,
"list": res,
//"total": count,
//"list": res,
//},
"list": cooperationProjects,
"total": count,
}, nil
}
}
... ...
... ... @@ -18,6 +18,8 @@ type CooperationProject struct {
CooperationProjectPublisher *User `json:"cooperationProjectPublisher"`
// 共创项目发起人
CooperationProjectSponsor *User `json:"cooperationProjectSponsor"`
// 共创模式
CooperationMode *CooperationMode `json:"cooperationMode"`
// 共创项目发起部门
Department *Department `json:"department"`
// 共创项目承接对象,1员工,2共创用户,3公开,可以多选
... ...
... ... @@ -21,6 +21,8 @@ type CooperationProject struct {
CooperationProjectPublisher *domain.User `comment:"共创项目发布人"`
// 共创项目发起人
CooperationProjectSponsor *domain.User `comment:"共创项目发起人"`
// 共创模式编码
CooperationModeNumber string `comment:"共创模式编号"`
// 共创项目发起部门
Department *domain.Department `comment:"共创项目发起部门"`
// 共创项目承接对象,1员工,2共创用户,3公开,可以多选
... ...
... ... @@ -5,15 +5,31 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
)
func TransformToCooperationProjectDomainModelFromPgModels(cooperationProjectModel *models.CooperationProject) (*domain.CooperationProject, error) {
func TransformToCooperationProjectDomainModelFromPgModels(
cooperationProjectModel *models.CooperationProject,
cooperationMode *models.CooperationMode) (*domain.CooperationProject, error) {
return &domain.CooperationProject{
CooperationProjectId: cooperationProjectModel.CooperationProjectId,
CooperationProjectNumber: cooperationProjectModel.CooperationProjectNumber,
CooperationProjectDescription: cooperationProjectModel.CooperationProjectDescription,
CooperationProjectName: cooperationProjectModel.CooperationProjectName,
CooperationProjectPublishTime: cooperationProjectModel.CooperationProjectPublishTime,
CooperationProjectPublisher: cooperationProjectModel.CooperationProjectPublisher,
CooperationProjectSponsor: cooperationProjectModel.CooperationProjectSponsor,
CooperationProjectId: cooperationProjectModel.CooperationProjectId,
CooperationProjectNumber: cooperationProjectModel.CooperationProjectNumber,
CooperationProjectDescription: cooperationProjectModel.CooperationProjectDescription,
CooperationProjectName: cooperationProjectModel.CooperationProjectName,
CooperationProjectPublishTime: cooperationProjectModel.CooperationProjectPublishTime,
CooperationProjectPublisher: cooperationProjectModel.CooperationProjectPublisher,
CooperationProjectSponsor: cooperationProjectModel.CooperationProjectSponsor,
CooperationMode: &domain.CooperationMode{
CooperationModeId: cooperationMode.CooperationModeId,
CooperationModeNumber: cooperationMode.CooperationModeNumber,
CooperationModeName: cooperationMode.CooperationModeName,
Status: cooperationMode.Status,
Org: cooperationMode.Org,
Company: cooperationMode.Company,
Remarks: cooperationMode.Remarks,
Operator: cooperationMode.Operator,
OperateTime: cooperationMode.OperateTime,
UpdatedAt: cooperationMode.UpdatedAt,
DeletedAt: cooperationMode.DeletedAt,
CreatedAt: cooperationMode.CreatedAt,
},
Department: cooperationProjectModel.Department,
CooperationProjectUndertakerTypes: cooperationProjectModel.CooperationProjectUndertakerTypes,
Org: cooperationProjectModel.Org,
... ...
... ... @@ -34,6 +34,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
"cooperation_project_publish_time",
"cooperation_project_publisher",
"cooperation_project_sponsor",
"cooperation_mode_number",
"department",
"cooperation_project_undertaker_types",
"org",
... ... @@ -67,6 +68,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
&cooperationProject.CooperationProjectPublishTime,
&cooperationProject.CooperationProjectPublisher,
&cooperationProject.CooperationProjectSponsor,
&cooperationProject.CooperationMode.CooperationModeNumber,
&cooperationProject.Department,
pg.Array(&cooperationProject.CooperationProjectUndertakerTypes),
&cooperationProject.Org,
... ... @@ -86,6 +88,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
cooperationProject.CooperationProjectPublishTime,
cooperationProject.CooperationProjectPublisher,
cooperationProject.CooperationProjectSponsor,
cooperationProject.CooperationMode.CooperationModeNumber,
cooperationProject.Department,
pg.Array(cooperationProject.CooperationProjectUndertakerTypes),
cooperationProject.Org,
... ... @@ -109,6 +112,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
&cooperationProject.CooperationProjectPublishTime,
&cooperationProject.CooperationProjectPublisher,
&cooperationProject.CooperationProjectSponsor,
&cooperationProject.CooperationMode.CooperationModeNumber,
&cooperationProject.Department,
pg.Array(&cooperationProject.CooperationProjectUndertakerTypes),
&cooperationProject.Org,
... ... @@ -128,6 +132,7 @@ func (repository *CooperationProjectRepository) Save(cooperationProject *domain.
cooperationProject.CooperationProjectPublishTime,
cooperationProject.CooperationProjectPublisher,
cooperationProject.CooperationProjectSponsor,
cooperationProject.CooperationMode.CooperationModeNumber,
cooperationProject.Department,
pg.Array(cooperationProject.CooperationProjectUndertakerTypes),
cooperationProject.Org,
... ... @@ -171,7 +176,13 @@ func (repository *CooperationProjectRepository) FindOne(queryOptions map[string]
if cooperationProjectModel.CooperationProjectId == 0 {
return nil, nil
} else {
return transform.TransformToCooperationProjectDomainModelFromPgModels(cooperationProjectModel)
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).First(); err != nil {
return nil, err
}
return transform.TransformToCooperationProjectDomainModelFromPgModels(cooperationProjectModel, cooperationModeModel)
}
}
... ... @@ -186,7 +197,13 @@ func (repository *CooperationProjectRepository) Find(queryOptions map[string]int
return 0, cooperationProjects, err
} else {
for _, cooperationProjectModel := range cooperationProjectModels {
if cooperationProject, err := transform.TransformToCooperationProjectDomainModelFromPgModels(cooperationProjectModel); err != nil {
// 获取共创模式
cooperationModeModel := new(models.CooperationMode)
cooperationModeQuery := tx.Model(cooperationModeModel)
if err := cooperationModeQuery.Where("cooperation_mode_number = ?", cooperationProjectModel.CooperationModeNumber).First(); err != nil {
return 0, nil, err
}
if cooperationProject, err := transform.TransformToCooperationProjectDomainModelFromPgModels(cooperationProjectModel, cooperationModeModel); err != nil {
return 0, cooperationProjects, err
} else {
cooperationProjects = append(cooperationProjects, cooperationProject)
... ...