作者 陈志颖

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

@@ -120,9 +120,11 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop @@ -120,9 +120,11 @@ func (cooperationApplicationService *CooperationApplicationService) ApplyForCoop
120 } 120 }
121 121
122 // 校验:判断用户类型是否属于承接对象 122 // 校验:判断用户类型是否属于承接对象
  123 + if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, 4) { // 非公开类型校验
123 if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) { 124 if !utils.IsContain(cooperationProject.CooperationProjectUndertakerTypes, applicant.UserType) {
124 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象") 125 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
125 } 126 }
  127 + }
126 128
127 newCooperationApplication = &domain.CooperationApplication{ 129 newCooperationApplication = &domain.CooperationApplication{
128 CooperationApplicationApplicant: applicant, 130 CooperationApplicationApplicant: applicant,
@@ -646,6 +648,7 @@ func (cooperationApplicationService *CooperationApplicationService) ListCooperat @@ -646,6 +648,7 @@ func (cooperationApplicationService *CooperationApplicationService) ListCooperat
646 } else { 648 } else {
647 cooperationApplicationRepository = value 649 cooperationApplicationRepository = value
648 } 650 }
  651 + // 获取共创申请
649 if count, cooperationApplications, err := cooperationApplicationRepository.Find(tool_funs.SimpleStructToMap(listCooperationApplicationQuery)); err != nil { 652 if count, cooperationApplications, err := cooperationApplicationRepository.Find(tool_funs.SimpleStructToMap(listCooperationApplicationQuery)); err != nil {
650 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 653 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
651 } else { 654 } else {
@@ -158,10 +158,12 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC @@ -158,10 +158,12 @@ func (cooperationContractService *CooperationContractService) CreateCooperationC
158 undertakerDomain = data 158 undertakerDomain = data
159 } 159 }
160 160
161 - // 校验承接人是否属于承接对象 161 + // 校验承接人是否属于承接对象,1员工,2共创用户,4公开
  162 + if !utils.IsContain(createCooperationContractCommand.CooperationContractUndertakerTypes, 4) {
162 if !utils.IsContain(createCooperationContractCommand.CooperationContractUndertakerTypes, undertakerDomain.UserType) { 163 if !utils.IsContain(createCooperationContractCommand.CooperationContractUndertakerTypes, undertakerDomain.UserType) {
163 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "承接人"+undertakerDomain.UserName+"不属于承接对象") 164 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "承接人"+undertakerDomain.UserName+"不属于承接对象")
164 } 165 }
  166 + }
165 167
166 // 获取推荐人 168 // 获取推荐人
167 var referrerDomain *domain.Referrer 169 var referrerDomain *domain.Referrer
@@ -1017,6 +1019,13 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC @@ -1017,6 +1019,13 @@ func (cooperationContractService *CooperationContractService) UpdateCooperationC
1017 undertakerDomain = data 1019 undertakerDomain = data
1018 } 1020 }
1019 1021
  1022 + // 校验:判断用户类型是否属于承接对象
  1023 + if !utils.IsContain(cooperationContract.CooperationContractUndertakerTypes, 4) { // 非公开类型校验
  1024 + if !utils.IsContain(cooperationContract.CooperationContractUndertakerTypes, undertakerDomain.UserType) {
  1025 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "抱歉,您不属于当前项目的承接对象")
  1026 + }
  1027 + }
  1028 +
1020 // 获取推荐人 1029 // 获取推荐人
1021 var referrerDomain *domain.Referrer 1030 var referrerDomain *domain.Referrer
1022 if undertaker.ReferrerId != "" { 1031 if undertaker.ReferrerId != "" {
@@ -459,29 +459,91 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro @@ -459,29 +459,91 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro
459 cooperationProjectRepository = value 459 cooperationProjectRepository = value
460 } 460 }
461 461
  462 + // 共创申请仓储初始化
  463 + var cooperationApplicationRepository domain.CooperationApplicationRepository
  464 + if value, err := factory.CreateCooperationApplicationRepository(map[string]interface{}{
  465 + "transactionContext": transactionContext,
  466 + }); err != nil {
  467 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  468 + } else {
  469 + cooperationApplicationRepository = value
  470 + }
  471 +
  472 + // 共创项目ID类型转换
462 cooperationProjectId, err := strconv.ParseInt(updateCooperationProjectCommand.CooperationProjectId, 10, 64) 473 cooperationProjectId, err := strconv.ParseInt(updateCooperationProjectCommand.CooperationProjectId, 10, 64)
463 if err != nil { 474 if err != nil {
464 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创项目编号类型错误") 475 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "共创项目编号类型错误")
465 } 476 }
466 477
467 // 查找共创项目 478 // 查找共创项目
468 - cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{"cooperationProjectId": cooperationProjectId}) 479 + cooperationProject, err := cooperationProjectRepository.FindOne(map[string]interface{}{
  480 + "cooperationProjectId": cooperationProjectId,
  481 + })
469 if err != nil { 482 if err != nil {
470 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 483 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
471 } 484 }
472 if cooperationProject == nil { 485 if cooperationProject == nil {
473 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationProjectCommand.CooperationProjectId))) 486 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateCooperationProjectCommand.CooperationProjectId)))
474 } 487 }
  488 +
  489 + applicantTypes := make(map[int32]interface{})
  490 +
  491 + // 获取所有申请人
  492 + if count, cooperationApplications, err := cooperationApplicationRepository.Find(map[string]interface{}{
  493 + "cooperationProjectNumber": cooperationProject.CooperationProjectNumber,
  494 + "offsetLimit": false,
  495 + "companyId": updateCooperationProjectCommand.CompanyId,
  496 + "cooperationApplicationStatus": 2, // 共创申请审核状态,1待审核,2已同意,3已拒绝
  497 + }); err != nil {
  498 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  499 + } else {
  500 + if count > 0 {
  501 + for _, cooperationApplication := range cooperationApplications {
  502 + applicantTypes[cooperationApplication.CooperationApplicationApplicant.UserType] = cooperationApplication.CooperationApplicationApplicant.UserType
  503 + }
  504 + }
  505 + }
  506 + var undertakerTypes []int32
  507 + var k1, k2 int32
  508 + if len(applicantTypes) > 0 {
  509 + for k, _ := range applicantTypes {
  510 + if k == 1 {
  511 + k1 = k
  512 + } else if k == 2 {
  513 + k2 = k
  514 + }
  515 + undertakerTypes = append(undertakerTypes, k)
  516 + }
  517 + }
  518 + if k1 != 0 && k2 != 0 {
  519 + undertakerTypes = append(undertakerTypes, 4)
  520 + }
  521 +
  522 + // 校验可以修改的承接人(申请人)类型
  523 + for _, t := range undertakerTypes {
  524 + if !utils.IsContain(updateCooperationProjectCommand.CooperationProjectUndertakerTypes, t) {
  525 + switch t {
  526 + case 1:
  527 + return nil, application.ThrowError(application.BUSINESS_ERROR, "承接对象'员工'存在业务数据,不可取消勾选")
  528 + case 2:
  529 + return nil, application.ThrowError(application.BUSINESS_ERROR, "承接对象'共创用户'存在业务数据,不可取消勾选")
  530 + case 4:
  531 + return nil, application.ThrowError(application.BUSINESS_ERROR, "承接对象'公开'存在业务数据,不可取消勾选")
  532 + }
  533 + }
  534 + }
  535 +
  536 + // 更新共创项目
475 if err := cooperationProject.Update(tool_funs.SimpleStructToMap(updateCooperationProjectCommand)); err != nil { 537 if err := cooperationProject.Update(tool_funs.SimpleStructToMap(updateCooperationProjectCommand)); err != nil {
476 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 538 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
477 } 539 }
478 - if cooperationProject, err := cooperationProjectRepository.Save(cooperationProject); err != nil { 540 + if cooperationProjectSaved, err := cooperationProjectRepository.Save(cooperationProject); err != nil {
479 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 541 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
480 } else { 542 } else {
481 if err := transactionContext.CommitTransaction(); err != nil { 543 if err := transactionContext.CommitTransaction(); err != nil {
482 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 544 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
483 } 545 }
484 - return cooperationProject, nil 546 + return cooperationProjectSaved, nil
485 } 547 }
486 } 548 }
487 549