作者 linmadan

修复统计bug

@@ -141,7 +141,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone @@ -141,7 +141,7 @@ func (statisticsService *StatisticsService) PersonSuMoneyStatistics(personSuMone
141 if err := transactionContext.CommitTransaction(); err != nil { 141 if err := transactionContext.CommitTransaction(); err != nil {
142 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 142 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
143 } 143 }
144 - personSuMoneyStatistics.CurrentSuMoney = employee.SuMoney 144 + personSuMoneyStatistics["currentSuMoney"] = employee.SuMoney
145 return personSuMoneyStatistics, nil 145 return personSuMoneyStatistics, nil
146 } 146 }
147 } 147 }
1 -package domain  
2 -  
3 -// 个人素币统计  
4 -type PersonSuMoneyStatistics struct {  
5 - // 当前素币  
6 - CurrentSuMoney float64 `json:"currentSuMoney"`  
7 - // 昨日收益  
8 - IncomeSuMoneyOfYesterday float64 `json:"incomeSuMoneyOfYesterday"`  
9 -}  
1 -package domain  
2 -  
3 -// 系统任务统计  
4 -type SystemTaskStatistics struct {  
5 - // 系统已发布任务  
6 - Released int64 `json:"released"`  
7 - // 系统进行中任务  
8 - Underway int64 `json:"underway"`  
9 - // 系统已完成任务  
10 - Completed int64 `json:"completed"`  
11 -}  
@@ -4,7 +4,6 @@ import ( @@ -4,7 +4,6 @@ import (
4 "fmt" 4 "fmt"
5 "github.com/go-pg/pg" 5 "github.com/go-pg/pg"
6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg" 6 pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
7 - "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"  
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models" 7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
9 "time" 8 "time"
10 ) 9 )
@@ -22,10 +21,11 @@ func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error { @@ -22,10 +21,11 @@ func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error {
22 return err 21 return err
23 } 22 }
24 23
25 -func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (*domain.PersonSuMoneyStatistics, error) { 24 +func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) {
  25 + var incomeSuMoney float64
  26 + var incomeSuMoneyOfYesterday float64
26 tx := dao.transactionContext.PgTx 27 tx := dao.transactionContext.PgTx
27 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 28 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
28 - personSuMoneyStatistics := &domain.PersonSuMoneyStatistics{}  
29 yesterday := time.Now().AddDate(0, 0, -1) 29 yesterday := time.Now().AddDate(0, 0, -1)
30 if err := tx.Model(suMoneyTransactionRecordModel). 30 if err := tx.Model(suMoneyTransactionRecordModel).
31 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 31 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
@@ -33,18 +33,27 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (*domain.PersonSuMoney @@ -33,18 +33,27 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (*domain.PersonSuMoney
33 Where(`su_money_transaction_record.record_type = ?`, 2). 33 Where(`su_money_transaction_record.record_type = ?`, 2).
34 Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())). 34 Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
35 Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())). 35 Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
36 - Select(&personSuMoneyStatistics.IncomeSuMoneyOfYesterday); err != nil { 36 + Select(&incomeSuMoneyOfYesterday); err != nil {
  37 + return nil, err
  38 + }
  39 + if err := tx.Model(suMoneyTransactionRecordModel).
  40 + ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
  41 + Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
  42 + Where(`su_money_transaction_record.record_type = ?`, 2).
  43 + Select(&incomeSuMoney); err != nil {
37 return nil, err 44 return nil, err
38 - } else {  
39 - return personSuMoneyStatistics, nil  
40 } 45 }
  46 + return map[string]interface{}{
  47 + "incomeSuMoney": incomeSuMoney,
  48 + "incomeSuMoneyOfYesterday": incomeSuMoneyOfYesterday,
  49 + }, nil
41 } 50 }
42 51
43 func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) { 52 func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
44 - tx := dao.transactionContext.PgTx  
45 - suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)  
46 var incomeSuMoney float64 53 var incomeSuMoney float64
47 var expendSuMoney float64 54 var expendSuMoney float64
  55 + tx := dao.transactionContext.PgTx
  56 + suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
48 if err := tx.Model(suMoneyTransactionRecordModel). 57 if err := tx.Model(suMoneyTransactionRecordModel).
49 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 58 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
50 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 59 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
@@ -50,17 +50,19 @@ func (dao *TaskDao) SetSuccessfulBidder(taskId int64, successfulBidder *domain.E @@ -50,17 +50,19 @@ func (dao *TaskDao) SetSuccessfulBidder(taskId int64, successfulBidder *domain.E
50 return err 50 return err
51 } 51 }
52 52
53 -func (dao *TaskDao) CalculateSystemTask(companyId int64) (*domain.SystemTaskStatistics, error) { 53 +func (dao *TaskDao) CalculateSystemTask(companyId int64) (map[string]interface{}, error) {
  54 + var released int64
  55 + var underway int64
  56 + var completed int64
54 tx := dao.transactionContext.PgTx 57 tx := dao.transactionContext.PgTx
55 taskModel := new(models.Task) 58 taskModel := new(models.Task)
56 - systemTaskStatistics := &domain.SystemTaskStatistics{}  
57 if count, err := tx.Model(taskModel). 59 if count, err := tx.Model(taskModel).
58 Where("task.company_id = ?", companyId). 60 Where("task.company_id = ?", companyId).
59 Where("task.task_status = ? ", domain.TASK_STATUS_UNCLAIMED). 61 Where("task.task_status = ? ", domain.TASK_STATUS_UNCLAIMED).
60 Count(); err != nil { 62 Count(); err != nil {
61 return nil, err 63 return nil, err
62 } else { 64 } else {
63 - systemTaskStatistics.Released = int64(count) 65 + released = int64(count)
64 } 66 }
65 if count, err := tx.Model(taskModel). 67 if count, err := tx.Model(taskModel).
66 Where("task.company_id = ?", companyId). 68 Where("task.company_id = ?", companyId).
@@ -68,7 +70,7 @@ func (dao *TaskDao) CalculateSystemTask(companyId int64) (*domain.SystemTaskStat @@ -68,7 +70,7 @@ func (dao *TaskDao) CalculateSystemTask(companyId int64) (*domain.SystemTaskStat
68 Count(); err != nil { 70 Count(); err != nil {
69 return nil, err 71 return nil, err
70 } else { 72 } else {
71 - systemTaskStatistics.Underway = int64(count) 73 + underway = int64(count)
72 } 74 }
73 if count, err := tx.Model(taskModel). 75 if count, err := tx.Model(taskModel).
74 Where("task.company_id = ?", companyId). 76 Where("task.company_id = ?", companyId).
@@ -76,9 +78,13 @@ func (dao *TaskDao) CalculateSystemTask(companyId int64) (*domain.SystemTaskStat @@ -76,9 +78,13 @@ func (dao *TaskDao) CalculateSystemTask(companyId int64) (*domain.SystemTaskStat
76 Count(); err != nil { 78 Count(); err != nil {
77 return nil, err 79 return nil, err
78 } else { 80 } else {
79 - systemTaskStatistics.Completed = int64(count) 81 + completed = int64(count)
80 } 82 }
81 - return systemTaskStatistics, nil 83 + return map[string]interface{}{
  84 + "released": released + underway + completed,
  85 + "underway": underway,
  86 + "completed": completed,
  87 + }, nil
82 } 88 }
83 89
84 func (dao *TaskDao) CalculatePersonTask(uid int64) (*domain.PersonTaskStatistics, error) { 90 func (dao *TaskDao) CalculatePersonTask(uid int64) (*domain.PersonTaskStatistics, error) {