作者 yangfu

账期结算相关人过滤

... ... @@ -63,6 +63,8 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
res, err = statisticsService.PersonCompanyPaymentHistoryStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CreditAccountStatistics:
res, err = statisticsService.CreditAccountStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.RelevantCooperationContractNumbers:
res, err = statisticsService.RelevantCooperationContractNumbers(contractStatisticsQuery.QueryOptions)
}
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -36,6 +36,8 @@ type SearchCreditAccountQuery struct {
BeginTime time.Time `json:"beginTime"`
// 账期创建-结束时间
EndTime time.Time `json:"endTime"`
// 合约编号列表
CooperationContractNumbers []string `json:"cooperationContractNumbers"`
}
func (searchCreditAccountQuery *SearchCreditAccountQuery) Valid(validation *validation.Validation) {
... ...
... ... @@ -2,6 +2,7 @@ package dao
import (
"fmt"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/utils"
... ... @@ -84,6 +85,10 @@ func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interfa
if v, ok := queryOptions["orgId"]; ok && v.(int64) > 0 {
query.Where(fmt.Sprintf(` org->>'orgId'= '%v'`, v))
}
if v, ok := queryOptions["cooperationContractNumbers"]; ok && len(v.([]string)) > 0 {
query.Where("cooperation_contract_number in (?)", pg.In(v))
}
query.Where("deleted_at is null")
err := query.Select(v)
return err
}
... ...
... ... @@ -51,7 +51,7 @@ func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId
}
// 2.相关合约统计
cooperationContractRelevantRepository, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
cooperationContractRelevantRepository, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext)
cooperationContractCount, _, err := cooperationContractRelevantRepository.Find(map[string]interface{}{"userBaseId": userBaseId, "orgId": orgId,
"limit": 1})
if err != nil {
... ... @@ -70,7 +70,7 @@ func (ptr *CooperationStatisticsService) cooperationCompanyStatistics(userBaseId
OrgId: orgId,
CooperationProjectCount: cooperationProjectCount,
CooperationContractCount: cooperationContractCount,
DividendsIncome: utils.Round(allDividends.Total, 2),
DividendsIncome: utils.Round(allDividends.Accounted, 2),
}
return ret, nil
}
... ... @@ -99,7 +99,7 @@ func (ptr *CooperationStatisticsService) PersonCooperationContractStatistics(que
}
queryOptions = tool_funs.SimpleStructToMap(&request)
cooperationContractUndertaker, _ := repository.NewCooperationContractUndertakerRepository(ptr.transactionContext)
cooperationContractUndertaker, _ := repository.NewCooperationContractRelevantRepository(ptr.transactionContext)
_, contractUndertakers, err := cooperationContractUndertaker.Find(queryOptions)
if err != nil {
return nil, nil
... ...
... ... @@ -47,6 +47,8 @@ const (
CreditAccountStatistics = "CreditAccountStatistics"
// 公司/个人 - 支付历史统计直方图
PaymentHistoryHistogramStatistics = "PaymentHistoryHistogramStatistics"
// 用户相关的项目合约编号列表查询
RelevantCooperationContractNumbers = "RelevantCooperationContractNumbers"
)
// CooperationStatisticsService 共创统计服务
... ... @@ -181,7 +183,6 @@ func (ptr *CooperationStatisticsService) getRelevantContracts(queryOptions map[s
if len(numbers) == 0 {
return []string{}, nil
}
queryOptions["cooperationContractNumbers"] = numbers
return numbers, err
}
... ... @@ -348,6 +349,7 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st
//企业
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
UserId int64 `json:"userId"`
//个人
UserBaseId int64 `json:"userBaseId"`
}{}
... ... @@ -363,14 +365,32 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st
Paid float64 `json:"paid"`
}
creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
var contractNumbers []string
var err error
if request.OrgId > 0 && request.UserId > 0 {
contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"orgId": request.OrgId, "userId": request.UserId})
if err != nil {
return struct{}{}, err
}
} else if request.UserBaseId > 0 {
contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"orgId": request.OrgId, "userBaseId": request.UserBaseId})
if err != nil {
return struct{}{}, err
}
}
queryOptions["cooperationContractNumbers"] = contractNumbers
var allDividends = &CreditAccountStatisticsResponse{}
var annualDividends = &CreditAccountStatisticsResponse{}
var quarterDividends = &CreditAccountStatisticsResponse{}
if len(contractNumbers) > 0 {
if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil {
return nil, err
}
allDividends.Accounting = allDividends.Total - allDividends.Accounted
var annualDividends = &CreditAccountStatisticsResponse{}
queryOptions["beginTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local)
queryOptions["endTime"] = time.Date(time.Now().Year(), 1, 1, 0, 0, 0, 0, time.Local).AddDate(1, 0, 0)
if err := creditAccountDao.DividendsStatistics(queryOptions, annualDividends); err != nil {
... ... @@ -378,12 +398,12 @@ func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[st
}
annualDividends.Accounting = annualDividends.Total - annualDividends.Accounted
var quarterDividends = &CreditAccountStatisticsResponse{}
queryOptions["beginTime"], queryOptions["endTime"] = quarterBeginEnd()
if err := creditAccountDao.DividendsStatistics(queryOptions, quarterDividends); err != nil {
return nil, err
}
quarterDividends.Accounting = quarterDividends.Total - quarterDividends.Accounted
}
ret := map[string]interface{}{
"allDividends": allDividends,
... ... @@ -423,6 +443,8 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
var request = struct {
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
UserId int64 `json:"userId"`
UserBaseId int64 `json:"userBaseId"`
DividendsAccountStatus int32 `json:"dividendsAccountStatus"` // 分红结算状态
Offset int64 `json:"offset"`
... ... @@ -433,10 +455,18 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
}
queryOptions = tool_funs.SimpleStructToMap(&request)
dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
_, estimates, err := dividendsEstimateRepository.Find(queryOptions)
var contractNumbers []string
var err error
if request.OrgId > 0 && request.UserId > 0 {
contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"orgId": request.OrgId, "userId": request.UserId})
if err != nil {
return nil, err
return struct{}{}, err
}
} else if request.UserBaseId > 0 {
contractNumbers, err = ptr.getRelevantContracts(map[string]interface{}{"orgId": request.OrgId, "userBaseId": request.UserBaseId})
if err != nil {
return struct{}{}, err
}
}
type response struct {
// 承接人分红预算记录ID
... ... @@ -457,6 +487,18 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
CustomerName string `json:"customerName"`
}
var results = make([]response, 0)
if len(contractNumbers) == 0 {
return results, nil
}
queryOptions["cooperationContractNumbers"] = contractNumbers
dividendsEstimateRepository, _ := repository.NewDividendsEstimateRepository(ptr.transactionContext)
_, estimates, err := dividendsEstimateRepository.Find(queryOptions)
if err != nil {
return nil, err
}
dividendsOrderRepository, _ := repository.NewDividendsOrderRepository(ptr.transactionContext)
dividendsReturnedOrderRepository, _ := repository.NewDividendsReturnedOrderRepository(ptr.transactionContext)
for i := range estimates {
... ... @@ -469,6 +511,7 @@ func (ptr *CooperationStatisticsService) SearchDividendsEstimates(queryOptions m
DividendsType: item.DividendsType,
DividendsUser: item.DividendsUser,
}
// TODO:优化查询 统一查询到map里面
if item.DividendsType == 1 {
order, err := dividendsOrderRepository.FindOne(map[string]interface{}{
"dividendsOrderNumber": item.OrderOrReturnedOrderNum,
... ... @@ -499,6 +542,8 @@ func (ptr *CooperationStatisticsService) CreditAccountStatistics(queryOptions ma
UserBaseId int64 `json:"userBaseId"`
BeginTime time.Time `json:"beginTime"`
EndTime time.Time `json:"endTime"`
// 合约编号列表
CooperationContractNumbers []string `json:"cooperationContractNumbers"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
... ... @@ -522,3 +567,24 @@ type CreditAccountStatisticsResponse struct {
Paid float64 `json:"paid"`
Unpaid float64 `json:"unpaid"`
}
//getRelevantContracts 获取相关人的合约
func (ptr *CooperationStatisticsService) RelevantCooperationContractNumbers(queryOptions map[string]interface{}) (interface{}, error) {
var request = struct {
//企业
CompanyId int64 `json:"companyId" valid:"Required"`
OrgId int64 `json:"orgId" valid:"Required"`
UserId int64 `json:"userId" valid:"Required"`
//个人
//UserBaseId int64 `json:"userBaseId"`
//Offset int `json:"offset"`
//Limit int `json:"limit"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
contractNumbers, err := ptr.getRelevantContracts(queryOptions)
return contractNumbers, err
}
... ...
... ... @@ -302,6 +302,9 @@ func (repository *DividendsEstimateRepository) Find(queryOptions map[string]inte
if dividendsAccountStatus, ok := queryOptions["dividendsAccountStatus"]; ok && (dividendsAccountStatus.(int32)) > 0 {
query.Where("dividends_account_status = ?", dividendsAccountStatus)
}
if v, ok := queryOptions["cooperationContractNumbers"]; ok && len(v.([]string)) > 0 {
query.Where("cooperation_contract_number in (?)", pg.In(v))
}
if companyId, ok := queryOptions["companyId"]; ok && companyId.(int64) != 0 {
query.Where("company->>'companyId' = '?'", companyId)
}
... ...