作者 陈志颖

fix:共创合约创建、编辑承接对象错误问题

... ... @@ -120,8 +120,10 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
}
// 校验:判断用户类型是否属于承接对象
if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, 4) { // 非公开类型校验
if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
}
}
newCooperationApplication = &domain.CooperationApplication{
... ... @@ -646,6 +648,7 @@ func (cooperationApplicationService *CooperationApplicationService) ListCooperat
} else {
cooperationApplicationRepository = value
}
// 获取共创申请
if count, cooperationApplications, err := cooperationApplicationRepository.Find(tool_funs.SimpleStructToMap(listCooperationApplicationQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -158,9 +158,11 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
undertakerDomain = data
}
// 校验承接人是否属于承接对象
if !utils.IsContain(createCooperationContractCommand.CooperationContractUndertakerTypes, undertakerDomain.UserType) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "承接人"+undertakerDomain.UserName+"不属于承接对象")
// 校验承接人是否属于承接对象,1员工,2共创用户,4公开
if !utils.IsContain(createCooperationContractCommand.CooperationContractUndertakerTypes, 4) {
if !utils.IsContain(createCooperationContractCommand.CooperationContractUndertakerTypes, undertakerDomain.UserType) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "承接人"+undertakerDomain.UserName+"不属于承接对象")
}
}
// 获取推荐人
... ... @@ -1017,6 +1019,13 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
undertakerDomain = data
}
// 校验:判断用户类型是否属于承接对象
if !utils.IsContain(cooperationContract.CooperationContractUndertakerTypes, 4) { // 非公开类型校验
if !utils.IsContain(cooperationContract.CooperationContractUndertakerTypes, undertakerDomain.UserType) {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
}
}
// 获取推荐人
var referrerDomain *domain.Referrer
if undertaker.ReferrerId != "" {
... ...
... ... @@ -459,29 +459,91 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro
cooperationProjectRepository = value
}
// 共创申请仓储初始化
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
}
// 共创项目ID类型转换
cooperationProjectId, err := strconv.ParseInt(updateCooperationProjectCommand.CooperationProjectId, 10, 64)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创项目编号类型错误")
}
// 查找共创项目
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": cooperationProjectId})
cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
"cooperationProjectId": cooperationProjectId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if cooperationProject == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationProjectCommand.CooperationProjectId)))
}
applicantTypes := make(map[int32]interface{})
// 获取所有申请人
if count, cooperationApplications, err := cooperationApplicationRepository.Find(map[string]interface{}{
"cooperationProjectNumber": cooperationProject.CooperationProjectNumber,
"offsetLimit": false,
"companyId": updateCooperationProjectCommand.CompanyId,
"cooperationApplicationStatus": 2, // 共创申请审核状态,1待审核,2已同意,3已拒绝
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if count > 0 {
for _, cooperationApplication := range cooperationApplications {
applicantTypes[cooperationApplication.CooperationApplicationApplicant.UserType] = cooperationApplication.CooperationApplicationApplicant.UserType
}
}
}
var undertakerTypes []int32
var k1, k2 int32
if len(applicantTypes) > 0 {
for k, _ := range applicantTypes {
if k == 1 {
k1 = k
} else if k == 2 {
k2 = k
}
undertakerTypes = append(undertakerTypes, k)
}
}
if k1 != 0 && k2 != 0 {
undertakerTypes = append(undertakerTypes, 4)
}
// 校验可以修改的承接人(申请人)类型
for _, t := range undertakerTypes {
if !utils.IsContain(updateCooperationProjectCommand.CooperationProjectUndertakerTypes, t) {
switch t {
case 1:
return nil, application.ThrowError(application.BUSINESS_ERROR, "承接对象'员工'存在业务数据,不可取消勾选")
case 2:
return nil, application.ThrowError(application.BUSINESS_ERROR, "承接对象'共创用户'存在业务数据,不可取消勾选")
case 4:
return nil, application.ThrowError(application.BUSINESS_ERROR, "承接对象'公开'存在业务数据,不可取消勾选")
}
}
}
// 更新共创项目
if err := cooperationProject.Update(tool_funs.SimpleStructToMap(updateCooperationProjectCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if cooperationProject, err := cooperationProjectRepository.Save(cooperationProject); err != nil {
if cooperationProjectSaved, err := cooperationProjectRepository.Save(cooperationProject); 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 cooperationProjectSaved, nil
}
}
... ...