作者 yangfu

分红统计

... ... @@ -43,6 +43,10 @@ func (svr *CooperationStatisticsService) CooperationContractStatistics(contractS
res, err = statisticsService.CooperationModeStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.CompanyDividendsStatistics:
res, err = statisticsService.CompanyDividendsStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.DividendsStatistics:
res, err = statisticsService.DividendsStatistics(contractStatisticsQuery.QueryOptions)
case domain_service.SearchDividendsEstimates:
res, err = statisticsService.SearchDividendsEstimates(contractStatisticsQuery.QueryOptions)
}
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
... ...
... ... @@ -53,6 +53,26 @@ func (dao *CreditAccountDao) CheckCreditAccountNumberAvailable(queryOptions map[
return !ok, err
}
// 分红统计(分红明细)
func (dao *CreditAccountDao) DividendsStatistics(queryOptions map[string]interface{}, v interface{}) error {
sql := `
select
sum(settlement_amount) total,
sum((case when payment_status = 1 then actually_paid_amount else 0 end)) paid,
sum((case when settlement_time is not null then settlement_amount else 0 end)) accounted
from credit_accounts
where created_at>? and created_at<?
`
if v, ok := queryOptions["userBaseId"]; ok {
sql += fmt.Sprintf(`and participator->>'userBaseId'='%v'`, v)
}
if v, ok := queryOptions["orgId"]; ok {
sql += fmt.Sprintf(`and org->>'orgId'= '%v'`, v)
}
_, err := dao.transactionContext.PgDd.Query(v, sql, queryOptions["beginTime"], queryOptions["endTime"])
return err
}
func NewCreditAccountDao(transactionContext *pgTransaction.TransactionContext) (*CreditAccountDao, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为空")
... ...
... ... @@ -7,7 +7,9 @@ import (
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/repository"
"time"
)
const (
... ... @@ -24,6 +26,8 @@ const (
CooperationModeStatistics = "CooperationModeStatistics"
// 企业-分红统计
CompanyDividendsStatistics = "CompanyDividendsStatistics"
// 企业、个人 - 分红预算列表
SearchDividendsEstimates = "SearchDividendsEstimates"
)
// CooperationStatisticsService 共创统计服务
... ... @@ -196,7 +200,78 @@ func (ptr *CooperationStatisticsService) GetContractDividends(queryOptions map[s
// 分红统计(分红明细)
func (ptr *CooperationStatisticsService) DividendsStatistics(queryOptions map[string]interface{}) (interface{}, error) {
return nil, nil
// 参数验证
var request = struct {
//企业
CompanyId int64 `json:"companyId"`
OrgId int64 `json:"orgId"`
//个人
UserBaseId int64 `json:"userBaseId"`
}{}
if err := LoadQueryObject(queryOptions, &request); err != nil {
return nil, err
}
queryOptions = tool_funs.SimpleStructToMap(&request)
type response struct {
Total float64 `json:"total"`
Accounting float64 `json:"accounting"`
Accounted float64 `json:"accounted"`
Paid float64 `json:"paid"`
}
creditAccountDao, _ := dao.NewCreditAccountDao(ptr.transactionContext)
var allDividends = &response{}
if err := creditAccountDao.DividendsStatistics(queryOptions, allDividends); err != nil {
return nil, err
}
allDividends.Accounting = allDividends.Total - allDividends.Accounted
var annualDividends = &response{}
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 {
return nil, err
}
annualDividends.Accounting = annualDividends.Total - annualDividends.Accounted
var quarterDividends = &response{}
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,
"annualDividends": annualDividends,
"quarterDividends": quarterDividends,
}
return ret, nil
}
func quarterBeginEnd() (time.Time, time.Time) {
y := time.Now().Year()
m := time.Now().Month()
var mBegin, mEnd int
var begin, end time.Time
switch m {
case 4, 5, 6:
mBegin = 4
mEnd = 6
case 7, 8, 9:
mBegin = 7
mEnd = 9
case 10, 11, 12:
mBegin = 10
mEnd = 12
case 1, 2, 3:
mBegin = 1
mEnd = 3
}
begin = time.Date(y, time.Month(mBegin), 1, 0, 0, 0, 0, time.Local)
end = time.Date(y, time.Month(mEnd), 1, 0, 0, 0, 0, time.Local)
return begin, end
}
// 分红预算列表
... ...