作者 陈志颖

fix:新建共创项目

... ... @@ -138,6 +138,26 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
department = data
}
// 共创项目仓储初始化
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
}
// 共创项目DAO初始化
var cooperationProjectDao *dao.CooperationProjectDao
if value, err := factory.CreateCooperationProjectDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
cooperationProjectDao = value
}
// 查找共创模式
var cooperationModeRepository domain.CooperationModeRepository
if value, err := factory.CreateCooperationModeRepository(map[string]interface{}{
... ... @@ -147,22 +167,17 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
} else {
cooperationModeRepository = value
}
cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{"cooperationModeNumber": createCooperationProjectCommand.CooperationModeNumber})
cooperationMode, err := cooperationModeRepository.FindOne(map[string]interface{}{
"companyId": createCooperationProjectCommand.CompanyId,
"orgId": createCooperationProjectCommand.OrgId,
"cooperationModeNumber": createCooperationProjectCommand.CooperationModeNumber,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创模式不存在")
}
if cooperationMode == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", createCooperationProjectCommand.CooperationModeNumber))
} else {
// 共创项目DAO初始化
var cooperationProjectDao *dao.CooperationProjectDao
if value, err := factory.CreateCooperationProjectDao(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
cooperationProjectDao = value
}
// 生成共创项目编号
projectNumber, err2 := cooperationProjectDao.GenerateProjectNumber(map[string]interface{}{
"companyId": createCooperationProjectCommand.CompanyId,
... ... @@ -172,21 +187,27 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
}
// 校验共创项目编号是否唯一
numberAvailable, _ := cooperationProjectDao.CheckProjectNumberAvailable(map[string]interface{}{
numberAvailable, err := cooperationProjectDao.CheckProjectNumberAvailable(map[string]interface{}{
"companyId": createCooperationProjectCommand.CompanyId,
"orgId": createCooperationProjectCommand.OrgId,
"cooperationProjectNumber": projectNumber,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if !numberAvailable {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "新增共创项目异常")
}
// 校验共创项目名称是否唯一
nameAvailable, _ := cooperationProjectDao.CheckProjectNameAvailable(map[string]interface{}{
nameAvailable, err := cooperationProjectDao.CheckProjectNameAvailable(map[string]interface{}{
"companyId": createCooperationProjectCommand.CompanyId,
"orgId": createCooperationProjectCommand.OrgId,
"cooperationProjectName": createCooperationProjectCommand.CooperationProjectName,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if !nameAvailable {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "共创项目名称重复")
}
... ... @@ -212,14 +233,7 @@ func (cooperationProjectService *CooperationProjectService) CreateCooperationPro
CreatedAt: time.Now(),
ApplicantCount: 0,
}
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 {
... ...
... ... @@ -118,7 +118,7 @@ func (dao *CooperationProjectDao) CheckProjectNameAvailable(queryOptions map[str
if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
query = query.Where(`cooperation_project.org @> '{"orgId":"?"}'`, orgId)
}
query.Where("cooperation_project.status = ", 1)
query.Where("cooperation_project.status = ?", 1)
ok, err := query.Exists()
return !ok, err
}
... ...