作者 yangfu

账期结算相关人过滤

@@ -63,6 +63,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS @@ -63,6 +63,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
63 res, err = statisticsService.PersonCompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions) 63 res, err = statisticsService.PersonCompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions)
64 case domain_service.CreditAccountStatistics: 64 case domain_service.CreditAccountStatistics:
65 res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions) 65 res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions)
  66 + case domain_service.RelevantCooperationContractNumbers:
  67 + res, err = statisticsService.RelevantCooperationContractNumbers(contractStatisticsQuery.QueryOptions)
66 } 68 }
67 if err != nil { 69 if err != nil {
68 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 70 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
@@ -36,6 +36,8 @@ type SearchCreditAccountQuery struct { @@ -36,6 +36,8 @@ type SearchCreditAccountQuery struct {
36 BeginTime time.Time `json:"beginTime"` 36 BeginTime time.Time `json:"beginTime"`
37 // 账期创建-结束时间 37 // 账期创建-结束时间
38 EndTime time.Time `json:"endTime"` 38 EndTime time.Time `json:"endTime"`
  39 + // 合约编号列表
  40 + CooperationContractNumbers []string `json:"cooperationContractNumbers"`
39 } 41 }
40 42
41 func (searchCreditAccountQuery *SearchCreditAccountQuery) Valid(validation *validation.Validation) { 43 func (searchCreditAccountQuery *SearchCreditAccountQuery) Valid(validation *validation.Validation) {
@@ -2,6 +2,7 @@ package dao @@ -2,6 +2,7 @@ package dao
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "github.com/go-pg/pg/v10"
5 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models" 7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
7 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils" 8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
@@ -84,6 +85,10 @@ func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interfa @@ -84,6 +85,10 @@ func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interfa
84 if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 { 85 if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 {
85 query.Where(fmt.Sprintf(` org->>'orgId'= '%v'`, v)) 86 query.Where(fmt.Sprintf(` org->>'orgId'= '%v'`, v))
86 } 87 }
  88 + if v, ok := queryOptions["cooperationContractNumbers"]; ok && len(v.([]string)) > 0 {
  89 + query.Where("cooperation_contract_number in (?)", pg.In(v))
  90 + }
  91 + query.Where("deleted_at is null")
87 err := query.Select(v) 92 err := query.Select(v)
88 return err 93 return err
89 } 94 }
@@ -51,7 +51,7 @@ func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId @@ -51,7 +51,7 @@ func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId
51 } 51 }
52 52
53 // 2.相关合约统计 53 // 2.相关合约统计
54 - cooperationContractRelevantRepository, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext) 54 + cooperationContractRelevantRepository, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext)
55 cooperationContractCount, _, err := cooperationContractRelevantRepository.Find(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId, 55 cooperationContractCount, _, err := cooperationContractRelevantRepository.Find(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId,
56 "limit": 1}) 56 "limit": 1})
57 if err != nil { 57 if err != nil {
@@ -70,7 +70,7 @@ func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId @@ -70,7 +70,7 @@ func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId
70 OrgId: orgId, 70 OrgId: orgId,
71 CooperationProjectCount: cooperationProjectCount, 71 CooperationProjectCount: cooperationProjectCount,
72 CooperationContractCount: cooperationContractCount, 72 CooperationContractCount: cooperationContractCount,
73 - DividendsIncome: utils.Round(allDividends.Total, 2), 73 + DividendsIncome: utils.Round(allDividends.Accounted, 2),
74 } 74 }
75 return ret, nil 75 return ret, nil
76 } 76 }
@@ -99,7 +99,7 @@ func (ptr *CooperationStatisticsService) PersonCooperationContractStatistics(que @@ -99,7 +99,7 @@ func (ptr *CooperationStatisticsService) PersonCooperationContractStatistics(que
99 } 99 }
100 queryOptions = tool_funs.SimpleStructToMap(&request) 100 queryOptions = tool_funs.SimpleStructToMap(&request)
101 101
102 - cooperationContractUndertaker, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext) 102 + cooperationContractUndertaker, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext)
103 _, contractUndertakers, err := cooperationContractUndertaker.Find(queryOptions) 103 _, contractUndertakers, err := cooperationContractUndertaker.Find(queryOptions)
104 if err != nil { 104 if err != nil {
105 return nil, nil 105 return nil, nil
@@ -47,6 +47,8 @@ const ( @@ -47,6 +47,8 @@ const (
47 CreditAccountStatistics = "CreditAccountStatistics" 47 CreditAccountStatistics = "CreditAccountStatistics"
48 // 公司/个人 - 支付历史统计直方图 48 // 公司/个人 - 支付历史统计直方图
49 PaymentHistoryHistogramStatistics = "PaymentHistoryHistogramStatistics" 49 PaymentHistoryHistogramStatistics = "PaymentHistoryHistogramStatistics"
  50 + // 用户相关的项目合约编号列表查询
  51 + RelevantCooperationContractNumbers = "RelevantCooperationContractNumbers"
50 ) 52 )
51 53
52 // CooperationStatisticsService 共创统计服务 54 // CooperationStatisticsService 共创统计服务
@@ -181,7 +183,6 @@ func (ptr *CooperationStatisticsService) getRelevantContracts(queryOptions map[s @@ -181,7 +183,6 @@ func (ptr *CooperationStatisticsService) getRelevantContracts(queryOptions map[s
181 if len(numbers) == 0 { 183 if len(numbers) == 0 {
182 return []string{}, nil 184 return []string{}, nil
183 } 185 }
184 - queryOptions["cooperationContractNumbers"] = numbers  
185 return numbers, err 186 return numbers, err
186 } 187 }
187 188
@@ -348,6 +349,7 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st @@ -348,6 +349,7 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st
348 //企业 349 //企业
349 CompanyId int64 `json:"companyId"` 350 CompanyId int64 `json:"companyId"`
350 OrgId int64 `json:"orgId"` 351 OrgId int64 `json:"orgId"`
  352 + UserId int64 `json:"userId"`
351 //个人 353 //个人
352 UserBaseId int64 `json:"userBaseId"` 354 UserBaseId int64 `json:"userBaseId"`
353 }{} 355 }{}
@@ -363,27 +365,45 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st @@ -363,27 +365,45 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st
363 Paid float64 `json:"paid"` 365 Paid float64 `json:"paid"`
364 } 366 }
365 creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext) 367 creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
366 -  
367 - var allDividends = &CreditAccountStatisticsResponse{}  
368 - if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil {  
369 - return nil, err 368 + var contractNumbers []string
  369 + var err error
  370 + if request.OrgId > 0 && request.UserId > 0 {
  371 + contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"orgId": request.OrgId, "userId": request.UserId})
  372 + if err != nil {
  373 + return struct{}{}, err
  374 + }
  375 + } else if request.UserBaseId > 0 {
  376 + contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"orgId": request.OrgId, "userBaseId": request.UserBaseId})
  377 + if err != nil {
  378 + return struct{}{}, err
  379 + }
370 } 380 }
371 - allDividends.Accounting = allDividends.Total - allDividends.Accounted  
372 381
373 - var annualDividends = &CreditAccountStatisticsResponse{}  
374 - queryOptions["beginTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local)  
375 - queryOptions["endTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local).AddDate(1, 0, 0)  
376 - if err := creditAccountDao.DividendsStatistics(queryOptions, annualDividends); err != nil {  
377 - return nil, err  
378 - }  
379 - annualDividends.Accounting = annualDividends.Total - annualDividends.Accounted 382 + queryOptions["cooperationContractNumbers"] = contractNumbers
380 383
  384 + var allDividends = &CreditAccountStatisticsResponse{}
  385 + var annualDividends = &CreditAccountStatisticsResponse{}
381 var quarterDividends = &CreditAccountStatisticsResponse{} 386 var quarterDividends = &CreditAccountStatisticsResponse{}
382 - queryOptions["beginTime"], queryOptions["endTime"] = quarterBeginEnd()  
383 - if err := creditAccountDao.DividendsStatistics(queryOptions, quarterDividends); err != nil {  
384 - return nil, err 387 +
  388 + if len(contractNumbers) > 0 {
  389 + if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil {
  390 + return nil, err
  391 + }
  392 + allDividends.Accounting = allDividends.Total - allDividends.Accounted
  393 +
  394 + queryOptions["beginTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local)
  395 + queryOptions["endTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local).AddDate(1, 0, 0)
  396 + if err := creditAccountDao.DividendsStatistics(queryOptions, annualDividends); err != nil {
  397 + return nil, err
  398 + }
  399 + annualDividends.Accounting = annualDividends.Total - annualDividends.Accounted
  400 +
  401 + queryOptions["beginTime"], queryOptions["endTime"] = quarterBeginEnd()
  402 + if err := creditAccountDao.DividendsStatistics(queryOptions, quarterDividends); err != nil {
  403 + return nil, err
  404 + }
  405 + quarterDividends.Accounting = quarterDividends.Total - quarterDividends.Accounted
385 } 406 }
386 - quarterDividends.Accounting = quarterDividends.Total - quarterDividends.Accounted  
387 407
388 ret := map[string]interface{}{ 408 ret := map[string]interface{}{
389 "allDividends": allDividends, 409 "allDividends": allDividends,
@@ -421,8 +441,10 @@ func quarterBeginEnd() (time.Time, time.Time) { @@ -421,8 +441,10 @@ func quarterBeginEnd() (time.Time, time.Time) {
421 func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions map[string]interface{}) (interface{}, error) { 441 func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions map[string]interface{}) (interface{}, error) {
422 // 参数验证 442 // 参数验证
423 var request = struct { 443 var request = struct {
424 - CompanyId int64 `json:"companyId"`  
425 - OrgId int64 `json:"orgId"` 444 + CompanyId int64 `json:"companyId"`
  445 + OrgId int64 `json:"orgId"`
  446 + UserId int64 `json:"userId"`
  447 +
426 UserBaseId int64 `json:"userBaseId"` 448 UserBaseId int64 `json:"userBaseId"`
427 DividendsAccountStatus int32 `json:"dividendsAccountStatus"` // 分红结算状态 449 DividendsAccountStatus int32 `json:"dividendsAccountStatus"` // 分红结算状态
428 Offset int64 `json:"offset"` 450 Offset int64 `json:"offset"`
@@ -433,10 +455,18 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m @@ -433,10 +455,18 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
433 } 455 }
434 queryOptions = tool_funs.SimpleStructToMap(&request) 456 queryOptions = tool_funs.SimpleStructToMap(&request)
435 457
436 - dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)  
437 - _, estimates, err := dividendsEstimateRepository.Find(queryOptions)  
438 - if err != nil {  
439 - return nil, err 458 + var contractNumbers []string
  459 + var err error
  460 + if request.OrgId > 0 && request.UserId > 0 {
  461 + contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"orgId": request.OrgId, "userId": request.UserId})
  462 + if err != nil {
  463 + return struct{}{}, err
  464 + }
  465 + } else if request.UserBaseId > 0 {
  466 + contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"orgId": request.OrgId, "userBaseId": request.UserBaseId})
  467 + if err != nil {
  468 + return struct{}{}, err
  469 + }
440 } 470 }
441 type response struct { 471 type response struct {
442 // 承接人分红预算记录ID 472 // 承接人分红预算记录ID
@@ -457,6 +487,18 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m @@ -457,6 +487,18 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
457 CustomerName string `json:"customerName"` 487 CustomerName string `json:"customerName"`
458 } 488 }
459 var results = make([]response, 0) 489 var results = make([]response, 0)
  490 + if len(contractNumbers) == 0 {
  491 + return results, nil
  492 + }
  493 +
  494 + queryOptions["cooperationContractNumbers"] = contractNumbers
  495 +
  496 + dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
  497 + _, estimates, err := dividendsEstimateRepository.Find(queryOptions)
  498 + if err != nil {
  499 + return nil, err
  500 + }
  501 +
460 dividendsOrderRepository, _ := repository.NewDividendsOrderRepository(ptr.transactionContext) 502 dividendsOrderRepository, _ := repository.NewDividendsOrderRepository(ptr.transactionContext)
461 dividendsReturnedOrderRepository, _ := repository.NewDividendsReturnedOrderRepository(ptr.transactionContext) 503 dividendsReturnedOrderRepository, _ := repository.NewDividendsReturnedOrderRepository(ptr.transactionContext)
462 for i := range estimates { 504 for i := range estimates {
@@ -469,6 +511,7 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m @@ -469,6 +511,7 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
469 DividendsType: item.DividendsType, 511 DividendsType: item.DividendsType,
470 DividendsUser: item.DividendsUser, 512 DividendsUser: item.DividendsUser,
471 } 513 }
  514 + // TODO:优化查询 统一查询到map里面
472 if item.DividendsType == 1 { 515 if item.DividendsType == 1 {
473 order, err := dividendsOrderRepository.FindOne(map[string]interface{}{ 516 order, err := dividendsOrderRepository.FindOne(map[string]interface{}{
474 "dividendsOrderNumber": item.OrderOrReturnedOrderNum, 517 "dividendsOrderNumber": item.OrderOrReturnedOrderNum,
@@ -499,6 +542,8 @@ func (ptr *CooperationStatisticsService) CreditAccountStatistics(queryOptions ma @@ -499,6 +542,8 @@ func (ptr *CooperationStatisticsService) CreditAccountStatistics(queryOptions ma
499 UserBaseId int64 `json:"userBaseId"` 542 UserBaseId int64 `json:"userBaseId"`
500 BeginTime time.Time `json:"beginTime"` 543 BeginTime time.Time `json:"beginTime"`
501 EndTime time.Time `json:"endTime"` 544 EndTime time.Time `json:"endTime"`
  545 + // 合约编号列表
  546 + CooperationContractNumbers []string `json:"cooperationContractNumbers"`
502 }{} 547 }{}
503 if err := LoadQueryObject(queryOptions, &request); err != nil { 548 if err := LoadQueryObject(queryOptions, &request); err != nil {
504 return nil, err 549 return nil, err
@@ -522,3 +567,24 @@ type CreditAccountStatisticsResponse struct { @@ -522,3 +567,24 @@ type CreditAccountStatisticsResponse struct {
522 Paid float64 `json:"paid"` 567 Paid float64 `json:"paid"`
523 Unpaid float64 `json:"unpaid"` 568 Unpaid float64 `json:"unpaid"`
524 } 569 }
  570 +
  571 +//getRelevantContracts 获取相关人的合约
  572 +func (ptr *CooperationStatisticsService) RelevantCooperationContractNumbers(queryOptions map[string]interface{}) (interface{}, error) {
  573 + var request = struct {
  574 + //企业
  575 + CompanyId int64 `json:"companyId" valid:"Required"`
  576 + OrgId int64 `json:"orgId" valid:"Required"`
  577 + UserId int64 `json:"userId" valid:"Required"`
  578 + //个人
  579 + //UserBaseId int64 `json:"userBaseId"`
  580 + //Offset int `json:"offset"`
  581 + //Limit int `json:"limit"`
  582 + }{}
  583 + if err := LoadQueryObject(queryOptions, &request); err != nil {
  584 + return nil, err
  585 + }
  586 + queryOptions = tool_funs.SimpleStructToMap(&request)
  587 +
  588 + contractNumbers, err := ptr.getRelevantContracts(queryOptions)
  589 + return contractNumbers, err
  590 +}
@@ -302,6 +302,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte @@ -302,6 +302,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
302 if dividendsAccountStatus, ok := queryOptions["dividendsAccountStatus"]; ok && (dividendsAccountStatus.(int32)) > 0 { 302 if dividendsAccountStatus, ok := queryOptions["dividendsAccountStatus"]; ok && (dividendsAccountStatus.(int32)) > 0 {
303 query.Where("dividends_account_status = ?", dividendsAccountStatus) 303 query.Where("dividends_account_status = ?", dividendsAccountStatus)
304 } 304 }
  305 + if v, ok := queryOptions["cooperationContractNumbers"]; ok && len(v.([]string)) > 0 {
  306 + query.Where("cooperation_contract_number in (?)", pg.In(v))
  307 + }
305 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 { 308 if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
306 query.Where("company->>'companyId' = '?'", companyId) 309 query.Where("company->>'companyId' = '?'", companyId)
307 } 310 }