...
|
...
|
@@ -10,6 +10,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain/service"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
|
|
|
"strconv"
|
|
|
"time"
|
...
|
...
|
@@ -53,14 +54,6 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop |
|
|
userService = value
|
|
|
}
|
|
|
|
|
|
// 获取申请人
|
|
|
var applicant *domain.User
|
|
|
if data, err := userService.UserFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId, applyForCooperationCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
|
|
|
} else {
|
|
|
applicant = data
|
|
|
}
|
|
|
|
|
|
// 公司REST服务初始化
|
|
|
var companyService service.CompanyService
|
|
|
if value, err := factory.CreateCompanyService(map[string]interface{}{}); err != nil {
|
...
|
...
|
@@ -69,14 +62,6 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop |
|
|
companyService = value
|
|
|
}
|
|
|
|
|
|
// 获取公司信息
|
|
|
var company *domain.Company
|
|
|
if data, err := companyService.CompanyFrom(applyForCooperationCommand.CompanyId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司信息失败")
|
|
|
} else {
|
|
|
company = data
|
|
|
}
|
|
|
|
|
|
// 组织机构REST服务初始化
|
|
|
var organizationService service.OrgService
|
|
|
if value, err := factory.CreateOrganizationService(map[string]interface{}{}); err != nil {
|
...
|
...
|
@@ -85,12 +70,24 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop |
|
|
organizationService = value
|
|
|
}
|
|
|
|
|
|
// 获取组织机构信息
|
|
|
var organization *domain.Org
|
|
|
if data, err := organizationService.OrgFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取组织机构数据失败")
|
|
|
// 共创申请仓储初始化
|
|
|
var cooperationApplicationRepository domain.CooperationApplicationRepository
|
|
|
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
organization = data
|
|
|
cooperationApplicationRepository = value
|
|
|
}
|
|
|
|
|
|
// 共创申请DAO初始化
|
|
|
var cooperationApplicationDao *dao.CooperationApplicationDao
|
|
|
if value, err := factory.CreateCooperationApplicationDao(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationApplicationDao = value
|
|
|
}
|
|
|
|
|
|
// 获取共创项目
|
...
|
...
|
@@ -102,36 +99,95 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop |
|
|
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", strconv.FormatInt(applyForCooperationCommand.CooperationProjectId, 10)))
|
|
|
}
|
|
|
|
|
|
// TODO 校验:同一个用户,不能多次申请同一个项目
|
|
|
var newCooperationApplication *domain.CooperationApplication
|
|
|
|
|
|
if applyForCooperationCommand.CompanyId == 0 && applyForCooperationCommand.OrgId == 0 && applyForCooperationCommand.UserId == 0 { // 游客操作
|
|
|
// TODO 获取申请人信息
|
|
|
|
|
|
// TODO 校验:同一个用户,不能多次申请同一个项目
|
|
|
|
|
|
// TODO 校验:判断用户类型是否属于承接对象
|
|
|
//if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
|
|
|
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
|
|
|
//}
|
|
|
|
|
|
newCooperationApplication = &domain.CooperationApplication{
|
|
|
CooperationApplicationApplicant: nil, // TODO 获取游客(申请人)信息
|
|
|
CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
|
|
|
CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,
|
|
|
CooperationApplicationStatus: 1,
|
|
|
CooperationApplicationVerifier: nil,
|
|
|
CooperationApplicationVerifyDescription: "",
|
|
|
CooperationApplicationVerifyTime: time.Time{},
|
|
|
CooperationApplyTime: time.Now(),
|
|
|
CooperationProject: cooperationProject,
|
|
|
Org: cooperationProject.Org,
|
|
|
IsCanceled: 1,
|
|
|
Company: cooperationProject.Company,
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
} else {
|
|
|
// 获取申请人
|
|
|
var applicant *domain.User
|
|
|
if data, err := userService.UserFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId, applyForCooperationCommand.UserId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取申请人失败")
|
|
|
} else {
|
|
|
applicant = data
|
|
|
}
|
|
|
|
|
|
// TODO 校验:判断用户类型是否属于承接对象
|
|
|
// 获取公司信息
|
|
|
var company *domain.Company
|
|
|
if data, err := companyService.CompanyFrom(applyForCooperationCommand.CompanyId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取公司信息失败")
|
|
|
} else {
|
|
|
company = data
|
|
|
}
|
|
|
|
|
|
newCooperationApplication := &domain.CooperationApplication{
|
|
|
CooperationApplicationApplicant: applicant,
|
|
|
CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
|
|
|
CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,
|
|
|
CooperationApplicationStatus: 1,
|
|
|
CooperationApplicationVerifier: nil,
|
|
|
CooperationApplicationVerifyDescription: "",
|
|
|
CooperationApplicationVerifyTime: time.Time{},
|
|
|
CooperationApplyTime: time.Now(),
|
|
|
CooperationProject: cooperationProject,
|
|
|
Org: organization,
|
|
|
IsCanceled: 1,
|
|
|
Company: company,
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
// 获取组织机构信息
|
|
|
var organization *domain.Org
|
|
|
if data, err := organizationService.OrgFrom(applyForCooperationCommand.CompanyId, applyForCooperationCommand.OrgId); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取组织机构数据失败")
|
|
|
} else {
|
|
|
organization = data
|
|
|
}
|
|
|
|
|
|
var cooperationApplicationRepository domain.CooperationApplicationRepository
|
|
|
if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
|
|
|
"transactionContext": transactionContext,
|
|
|
}); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
|
|
cooperationApplicationRepository = value
|
|
|
// 校验:同一个用户,不能多次申请同一个项目
|
|
|
applicationExist, _ := cooperationApplicationDao.CheckApplicationExist(map[string]interface{}{
|
|
|
"companyId": applyForCooperationCommand.CompanyId,
|
|
|
"orgId": applyForCooperationCommand.OrgId,
|
|
|
"cooperationApplicationId": cooperationProject.CooperationProjectId,
|
|
|
})
|
|
|
if applicationExist {
|
|
|
return nil, application.ThrowError(application.TRANSACTION_ERROR, "抱歉,您已经申请过该项目")
|
|
|
}
|
|
|
|
|
|
// 校验:判断用户类型是否属于承接对象
|
|
|
if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
|
|
|
}
|
|
|
|
|
|
newCooperationApplication = &domain.CooperationApplication{
|
|
|
CooperationApplicationApplicant: applicant,
|
|
|
CooperationApplicationAttachment: applyForCooperationCommand.CooperationApplicationAttachment,
|
|
|
CooperationApplicationDescription: applyForCooperationCommand.CooperationApplicationDescription,
|
|
|
CooperationApplicationStatus: 1,
|
|
|
CooperationApplicationVerifier: nil,
|
|
|
CooperationApplicationVerifyDescription: "",
|
|
|
CooperationApplicationVerifyTime: time.Time{},
|
|
|
CooperationApplyTime: time.Now(),
|
|
|
CooperationProject: cooperationProject,
|
|
|
Org: organization,
|
|
|
IsCanceled: 1,
|
|
|
Company: company,
|
|
|
CreatedAt: time.Now(),
|
|
|
DeletedAt: time.Time{},
|
|
|
UpdatedAt: time.Time{},
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 保存共创申请
|
|
|
if cooperationApplication, err := cooperationApplicationRepository.Save(newCooperationApplication); err != nil {
|
|
|
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
|
|
|
} else {
|
...
|
...
|
|