作者 linmadan

修复统计bug

... ... @@ -141,7 +141,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
personSuMoneyStatistics.CurrentSuMoney = employee.SuMoney
personSuMoneyStatistics["currentSuMoney"] = employee.SuMoney
return personSuMoneyStatistics, nil
}
}
... ...
package domain
// 个人素币统计
type PersonSuMoneyStatistics struct {
// 当前素币
CurrentSuMoney float64 `json:"currentSuMoney"`
// 昨日收益
IncomeSuMoneyOfYesterday float64 `json:"incomeSuMoneyOfYesterday"`
}
package domain
// 系统任务统计
type SystemTaskStatistics struct {
// 系统已发布任务
Released int64 `json:"released"`
// 系统进行中任务
Underway int64 `json:"underway"`
// 系统已完成任务
Completed int64 `json:"completed"`
}
... ... @@ -4,7 +4,6 @@ import (
"fmt"
"github.com/go-pg/pg"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
"gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
"time"
)
... ... @@ -22,10 +21,11 @@ func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error {
return err
}
func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (*domain.PersonSuMoneyStatistics, error) {
func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) {
var incomeSuMoney float64
var incomeSuMoneyOfYesterday float64
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
personSuMoneyStatistics := &domain.PersonSuMoneyStatistics{}
yesterday := time.Now().AddDate(0, 0, -1)
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
... ... @@ -33,18 +33,27 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (*domain.PersonSuMoney
Where(`su_money_transaction_record.record_type = ?`, 2).
Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
Select(&personSuMoneyStatistics.IncomeSuMoneyOfYesterday); err != nil {
Select(&incomeSuMoneyOfYesterday); err != nil {
return nil, err
}
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
Where(`su_money_transaction_record.record_type = ?`, 2).
Select(&incomeSuMoney); err != nil {
return nil, err
} else {
return personSuMoneyStatistics, nil
}
return map[string]interface{}{
"incomeSuMoney": incomeSuMoney,
"incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday,
}, nil
}
func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
var incomeSuMoney float64
var expendSuMoney float64
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
if err := tx.Model(suMoneyTransactionRecordModel).
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
... ...
... ... @@ -50,17 +50,19 @@ func (dao *TaskDao) SetSuccessfulBidder(taskId int64, successfulBidder *domain.E
return err
}
func (dao *TaskDao) CalculateSystemTask(companyId int64) (*domain.SystemTaskStatistics, error) {
func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{}, error) {
var released int64
var underway int64
var completed int64
tx := dao.transactionContext.PgTx
taskModel := new(models.Task)
systemTaskStatistics := &domain.SystemTaskStatistics{}
if count, err := tx.Model(taskModel).
Where("task.company_id = ?", companyId).
Where("task.task_status = ? ", domain.TASK_STATUS_UNCLAIMED).
Count(); err != nil {
return nil, err
} else {
systemTaskStatistics.Released = int64(count)
released = int64(count)
}
if count, err := tx.Model(taskModel).
Where("task.company_id = ?", companyId).
... ... @@ -68,7 +70,7 @@ func (dao *TaskDao) CalculateSystemTask(companyId int64) (*domain.SystemTaskStat
Count(); err != nil {
return nil, err
} else {
systemTaskStatistics.Underway = int64(count)
underway = int64(count)
}
if count, err := tx.Model(taskModel).
Where("task.company_id = ?", companyId).
... ... @@ -76,9 +78,13 @@ func (dao *TaskDao) CalculateSystemTask(companyId int64) (*domain.SystemTaskStat
Count(); err != nil {
return nil, err
} else {
systemTaskStatistics.Completed = int64(count)
completed = int64(count)
}
return systemTaskStatistics, nil
return map[string]interface{}{
"released": released + underway + completed,
"underway": underway,
"completed": completed,
}, nil
}
func (dao *TaskDao) CalculatePersonTask(uid int64) (*domain.PersonTaskStatistics, error) {
... ...