作者 陈志颖

feat:增加金额激励信息阶段和承接人

@@ -1364,9 +1364,22 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE @@ -1364,9 +1364,22 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
1364 cooperationContractRepository = value 1364 cooperationContractRepository = value
1365 } 1365 }
1366 1366
1367 - // TODO 阶段承接人列表 1367 + // 分红预算仓储初始化
  1368 + var dividendsEstimateRepository domain.DividendsEstimateRepository
  1369 + if value, err := factory.CreateDividendsEstimateRepository(map[string]interface{}{
  1370 + "transactionContext": transactionContext,
  1371 + }); err != nil {
  1372 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1373 + } else {
  1374 + dividendsEstimateRepository = value
  1375 + }
  1376 +
  1377 + // 阶段承接人列表
1368 stageAndUndertaker := make([]*dto.StageAndUndertaker, 0) 1378 stageAndUndertaker := make([]*dto.StageAndUndertaker, 0)
1369 1379
  1380 + // 阶段承接人map
  1381 + stageUndertakerMap := make(map[int32][]*domain.Undertaker)
  1382 +
1370 // 查找共创合约 1383 // 查找共创合约
1371 searchMoneyIncentivesEstimateQuery.IncentivesType = 2 1384 searchMoneyIncentivesEstimateQuery.IncentivesType = 2
1372 if count, cooperationContracts, err := cooperationContractRepository.Find(tool_funs.SimpleStructToMap(searchMoneyIncentivesEstimateQuery)); err != nil { 1385 if count, cooperationContracts, err := cooperationContractRepository.Find(tool_funs.SimpleStructToMap(searchMoneyIncentivesEstimateQuery)); err != nil {
@@ -1374,10 +1387,39 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE @@ -1374,10 +1387,39 @@ func (dividendsEstimateService *DividendsEstimateService) SearchMoneyIncentivesE
1374 } else { 1387 } else {
1375 var moneyIncentivesEstimateDtos []*dto.MoneyIncentivesEstimateDto 1388 var moneyIncentivesEstimateDtos []*dto.MoneyIncentivesEstimateDto
1376 for _, cooperationContract := range cooperationContracts { 1389 for _, cooperationContract := range cooperationContracts {
1377 - // TODO 判断承接人是否已分红  
1378 - //for _, undertaker := range cooperationContract.Undertakers {  
1379 - //  
1380 - //} 1390 + for _, rule := range cooperationContract.MoneyIncentivesRules {
  1391 + stageUndertakerMap[rule.MoneyIncentivesStage] = make([]*domain.Undertaker, 0)
  1392 + }
  1393 + for _, undertaker := range cooperationContract.Undertakers {
  1394 + // 查询承接人分红预算单
  1395 + if countDividendsEstimates, dividendsEstimates, err := dividendsEstimateRepository.Find(map[string]interface{}{
  1396 + "cooperationContractNumber": cooperationContract.CooperationContractNumber,
  1397 + "companyId": cooperationContract.Company.CompanyId,
  1398 + "orgId": cooperationContract.Org.OrgId,
  1399 + "dividendsUserId": undertaker.UserId,
  1400 + }); err != nil {
  1401 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  1402 + } else {
  1403 + if countDividendsEstimates > 0 {
  1404 + for _, dividendsEstimate := range dividendsEstimates {
  1405 + if dividendsEstimate.DividendsAccountStatus == 1 || dividendsEstimate.IsCanceled { // 分红预算单状态为待结算或已取消
  1406 + stageUndertakerMap[dividendsEstimate.DividendsStage] = append(stageUndertakerMap[dividendsEstimate.DividendsStage], undertaker)
  1407 + }
  1408 + }
  1409 + } else if countDividendsEstimates == 0 { // 未分红,可以加入任意阶段进行金额激励
  1410 + for i, _ := range stageUndertakerMap {
  1411 + stageUndertakerMap[i] = append(stageUndertakerMap[i], undertaker)
  1412 + }
  1413 + }
  1414 + }
  1415 + }
  1416 +
  1417 + for k, v := range stageUndertakerMap {
  1418 + stageAndUndertaker = append(stageAndUndertaker, &dto.StageAndUndertaker{
  1419 + Stage: k,
  1420 + Undertakers: v,
  1421 + })
  1422 + }
1381 1423
1382 moneyIncentivesEstimateDto := &dto.MoneyIncentivesEstimateDto{} 1424 moneyIncentivesEstimateDto := &dto.MoneyIncentivesEstimateDto{}
1383 if err := moneyIncentivesEstimateDto.LoadDto(cooperationContract, stageAndUndertaker); err != nil { 1425 if err := moneyIncentivesEstimateDto.LoadDto(cooperationContract, stageAndUndertaker); err != nil {
@@ -308,6 +308,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte @@ -308,6 +308,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
308 if v, ok := queryOptions["cooperationContractNumbers"]; ok && len(v.([]string)) > 0 { 308 if v, ok := queryOptions["cooperationContractNumbers"]; ok && len(v.([]string)) > 0 {
309 query.Where("cooperation_contract_number in (?)", pg.In(v)) 309 query.Where("cooperation_contract_number in (?)", pg.In(v))
310 } 310 }
  311 + if dividendsUserId, ok := queryOptions["dividendsUserId"]; ok && dividendsUserId.(int64) != 0 {
  312 + query.Where(`dividends_user @> '{"uid":"?"}'`, dividendsUserId)
  313 + }
311 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { 314 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
312 query.Where("company->>'companyId' = '?'", companyId) 315 query.Where("company->>'companyId' = '?'", companyId)
313 } 316 }