作者 陈志颖

fix:修复合约查询

@@ -281,6 +281,16 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -281,6 +281,16 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
281 cooperationApplicationRepository = value 281 cooperationApplicationRepository = value
282 } 282 }
283 283
  284 + // 共创合约仓储初始化
  285 + var cooperationContractRepository domain.CooperationContractRepository
  286 + if value, err := factory.CreateCooperationContractRepository(map[string]interface{}{
  287 + "transactionContext": transactionContext,
  288 + }); err != nil {
  289 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  290 + } else {
  291 + cooperationContractRepository = value
  292 + }
  293 +
284 var getCooperationProjectQuerySpecific *query.GetCooperationProjectQuery 294 var getCooperationProjectQuerySpecific *query.GetCooperationProjectQuery
285 if getCooperationProjectQuery.CooperationProjectId != 0 { // 根据ID查询 295 if getCooperationProjectQuery.CooperationProjectId != 0 { // 根据ID查询
286 getCooperationProjectQuerySpecific = &query.GetCooperationProjectQuery{ 296 getCooperationProjectQuerySpecific = &query.GetCooperationProjectQuery{
@@ -349,6 +359,37 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -349,6 +359,37 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
349 undertakerTypesUncheckedAvailable = append(undertakerTypesUncheckedAvailable, 3) 359 undertakerTypesUncheckedAvailable = append(undertakerTypesUncheckedAvailable, 3)
350 } 360 }
351 361
  362 + // TODO 判断项目关联的合约承接人类型
  363 + undertakers := make([]*domain.Undertaker, 0)
  364 + if countContracts, cooperationContracts, err := cooperationContractRepository.Find(map[string]interface{}{
  365 + "offsetLimit": false,
  366 + }); err != nil {
  367 +
  368 + } else {
  369 + if countContracts > 0 {
  370 + for _, cooperationContract := range cooperationContracts {
  371 + undertakers = append(undertakers, cooperationContract.Undertakers...)
  372 + }
  373 + }
  374 + }
  375 +
  376 + var undertakerUserTypes []int32
  377 + for _, undertaker := range undertakers {
  378 + undertakerUserTypes = append(undertakerUserTypes, undertaker.UserType)
  379 + }
  380 +
  381 + undertakerUserTypes = utils.RemoveDuplicationInt32(undertakerUserTypes)
  382 +
  383 + for i, userType := range undertakerUserTypes {
  384 + if userType == 1025 {
  385 + undertakerUserTypes[i] = 2
  386 + }
  387 + }
  388 +
  389 + log.Logger.Info("承接人类型", map[string]interface{}{
  390 + "undertakerUserTypes": undertakerUserTypes,
  391 + })
  392 +
352 // 返回所有员工类型的申请通过人 393 // 返回所有员工类型的申请通过人
353 applicants := make([]*domain.User, 0) 394 applicants := make([]*domain.User, 0)
354 395
@@ -357,6 +398,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec @@ -357,6 +398,7 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
357 "cooperationProjectNumberExact": cooperationProject.CooperationProjectNumber, 398 "cooperationProjectNumberExact": cooperationProject.CooperationProjectNumber,
358 "companyId": cooperationProject.Company.CompanyId, 399 "companyId": cooperationProject.Company.CompanyId,
359 "orgId": cooperationProject.Org.OrgId, 400 "orgId": cooperationProject.Org.OrgId,
  401 + "offsetLimit": false,
360 }); err != nil { 402 }); err != nil {
361 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 403 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
362 } else { 404 } else {
@@ -521,6 +521,7 @@ func (dividendsEstimateService *DividendsEstimateService) CreateDividendsEstimat @@ -521,6 +521,7 @@ func (dividendsEstimateService *DividendsEstimateService) CreateDividendsEstimat
521 521
522 // ConfirmDividendsIncentivesEstimate 确定业绩激励分红预算 522 // ConfirmDividendsIncentivesEstimate 确定业绩激励分红预算
523 func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncentivesEstimate(confirmDividendsIncentivesEstimateCommand *command.ConfirmDividendsIncentivesEstimateCommand) (interface{}, error) { 523 func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncentivesEstimate(confirmDividendsIncentivesEstimateCommand *command.ConfirmDividendsIncentivesEstimateCommand) (interface{}, error) {
  524 + start := time.Now() // 获取当前时间
524 if err := confirmDividendsIncentivesEstimateCommand.ValidateCommand(); err != nil { 525 if err := confirmDividendsIncentivesEstimateCommand.ValidateCommand(); err != nil {
525 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 526 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
526 } 527 }
@@ -676,10 +677,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -676,10 +677,10 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
676 } 677 }
677 678
678 var countDividendsEstimate int64 679 var countDividendsEstimate int64
  680 +
679 for _, orderGood := range orderGoods { 681 for _, orderGood := range orderGoods {
680 dividendsEstimate := &domain.DividendsEstimate{} 682 dividendsEstimate := &domain.DividendsEstimate{}
681 if orderGood.DividendsOrderNumber != "" { // 查询分红订单 683 if orderGood.DividendsOrderNumber != "" { // 查询分红订单
682 - // 临时方案  
683 orderGoodsToConfirm := make([]*domain.OrderGood, 0) 684 orderGoodsToConfirm := make([]*domain.OrderGood, 0)
684 orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood) 685 orderGoodsToConfirm = append(orderGoodsToConfirm, orderGood)
685 // 分红订单产品预算 686 // 分红订单产品预算
@@ -957,6 +958,9 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent @@ -957,6 +958,9 @@ func (dividendsEstimateService *DividendsEstimateService) ConfirmDividendsIncent
957 failedReasonStr = "无" 958 failedReasonStr = "无"
958 } 959 }
959 960
  961 + elapsed := time.Since(start)
  962 + fmt.Println("该函数执行完成耗时:", elapsed)
  963 +
960 return map[string]interface{}{ 964 return map[string]interface{}{
961 "report": fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReasonStr), 965 "report": fmt.Sprintf("已完成%d单订单分红预算,生成%d单分红预算,%d笔订单分红预算失败,失败原因:%s", len(estimateSuccessfullyDividendsOrders), successfullyCount, len(estimateFailedDividendsOrders), failedReasonStr),
962 }, nil 966 }, nil
@@ -144,6 +144,16 @@ func (dao *CooperationContractDao) SearchCooperationContractByUndertaker(queryOp @@ -144,6 +144,16 @@ func (dao *CooperationContractDao) SearchCooperationContractByUndertaker(queryOp
144 if sponsorName, ok := queryOptions["sponsorName"]; ok && sponsorName != "" { 144 if sponsorName, ok := queryOptions["sponsorName"]; ok && sponsorName != "" {
145 query = query.Where(`A.cooperation_contract_sponsor->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", sponsorName)) 145 query = query.Where(`A.cooperation_contract_sponsor->>'userName')::text LIKE ?`, fmt.Sprintf("%%%s%%", sponsorName))
146 } 146 }
  147 + if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
  148 + query.Where("A.company->>'companyId' = '?'", companyId)
  149 + }
  150 + if orgId, ok := queryOptions["orgId"]; ok && orgId.(int64) != 0 {
  151 + query.Where("A.org->>'orgId' = '?'", orgId)
  152 + }
  153 + if orgIds, ok := queryOptions["orgIds"]; ok && len(orgIds.([]int64)) > 0 {
  154 + newOrgIds := utils.SliceItoa(orgIds.([]int64))
  155 + query.Where("A.org->>'orgId' in (?)", pg.In(newOrgIds))
  156 + }
147 query.Join("JOIN cooperation_contracts AS A ON A.cooperation_contract_number = cooperation_contract_undertaker.cooperation_contract_number") 157 query.Join("JOIN cooperation_contracts AS A ON A.cooperation_contract_number = cooperation_contract_undertaker.cooperation_contract_number")
148 query.Join("JOIN cooperation_modes AS B ON B.cooperation_mode_number = A.cooperation_mode_number") 158 query.Join("JOIN cooperation_modes AS B ON B.cooperation_mode_number = A.cooperation_mode_number")
149 query = query.Order("cooperation_contract_undertaker_id DESC") 159 query = query.Order("cooperation_contract_undertaker_id DESC")
@@ -144,6 +144,21 @@ func RemoveDuplicationInt64(arr []int64) []int64 { @@ -144,6 +144,21 @@ func RemoveDuplicationInt64(arr []int64) []int64 {
144 return arr[:j] 144 return arr[:j]
145 } 145 }
146 146
  147 +func RemoveDuplicationInt32(arr []int32) []int32 {
  148 + set := make(map[int32]struct{}, len(arr))
  149 + j := 0
  150 + for _, v := range arr {
  151 + _, ok := set[v]
  152 + if ok {
  153 + continue
  154 + }
  155 + set[v] = struct{}{}
  156 + arr[j] = v
  157 + j++
  158 + }
  159 + return arr[:j]
  160 +}
  161 +
147 // IsContain 判断int32数组是否包含 162 // IsContain 判断int32数组是否包含
148 func IsContain(items []int32, item int32) bool { 163 func IsContain(items []int32, item int32) bool {
149 for _, eachItem := range items { 164 for _, eachItem := range items {