作者 陈志颖

feat:添加财富值榜单总榜

1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "fmt"
4 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
5 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory" 6 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
6 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/statistics/command" 7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/statistics/command"
7 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain" 8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
8 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao" 9 "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/dao"
  10 + "time"
9 ) 11 )
10 12
11 // 数据统计服务 13 // 数据统计服务
@@ -305,6 +307,15 @@ func (statisticsService *StatisticsService) EmployeesSuMoneyStatistics(employees @@ -305,6 +307,15 @@ func (statisticsService *StatisticsService) EmployeesSuMoneyStatistics(employees
305 employeeDao = value 307 employeeDao = value
306 } 308 }
307 309
  310 + fmt.Print(employeesSuMoneyStatisticsCommand, "\n")
  311 +
  312 + if employeesSuMoneyStatisticsCommand.StartTime.IsZero() && employeesSuMoneyStatisticsCommand.EndTime.IsZero() {
  313 + employeesSuMoneyStatisticsCommand.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())
  314 + employeesSuMoneyStatisticsCommand.EndTime = time.Now().Local()
  315 + }
  316 +
  317 + fmt.Print(employeesSuMoneyStatisticsCommand, "\n")
  318 +
308 if employeesSuMoneyStatistics, err := employeeDao.CalculateEmployeesSuMoney(employeesSuMoneyStatisticsCommand.CompanyId, employeesSuMoneyStatisticsCommand.StartTime, employeesSuMoneyStatisticsCommand.EndTime); err != nil { 319 if employeesSuMoneyStatistics, err := employeeDao.CalculateEmployeesSuMoney(employeesSuMoneyStatisticsCommand.CompanyId, employeesSuMoneyStatisticsCommand.StartTime, employeesSuMoneyStatisticsCommand.EndTime); err != nil {
309 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 320 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
310 } else { 321 } else {
@@ -57,6 +57,7 @@ func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error { @@ -57,6 +57,7 @@ func (dao *EmployeeDao) TransferSuMoney(uid int64, suMoney float64) error {
57 return err 57 return err
58 } 58 }
59 59
  60 +// 计算个人未读消息
60 func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string]int, error) { 61 func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string]int, error) {
61 var unReadSystemNotification int 62 var unReadSystemNotification int
62 var unReadInteractionNotification int 63 var unReadInteractionNotification int
@@ -86,6 +87,7 @@ func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string @@ -86,6 +87,7 @@ func (dao *EmployeeDao) CalculatePersonUnReadNotification(uid int64) (map[string
86 }, nil 87 }, nil
87 } 88 }
88 89
  90 +// 计算个人素币情况
89 func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) { 91 func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{}, error) {
90 var incomeSuMoney float64 92 var incomeSuMoney float64
91 var incomeSuMoneyOfYesterday float64 93 var incomeSuMoneyOfYesterday float64
@@ -233,6 +235,54 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. @@ -233,6 +235,54 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.
233 }, nil 235 }, nil
234 } 236 }
235 237
  238 +//func (dao *EmployeeDao) CalculateEmployeesSuMoney(queryOptions map[string]interface{}) (map[string]interface{}, error) {
  239 +// var ret []struct {
  240 +// Uid int
  241 +// EmployeeName string
  242 +// EmployeeSuMoney float64
  243 +// }
  244 +// tx := dao.transactionContext.PgTx
  245 +// var (
  246 +// startTime time.Time
  247 +// endTime time.Time
  248 +// companyId int
  249 +// )
  250 +// if company, ok := queryOptions["companyId"].(int); ok {
  251 +// companyId = company
  252 +// }
  253 +// if start, ok := queryOptions["startTime"].(time.Time); ok {
  254 +// startTime = start
  255 +// } else {
  256 +// startTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())
  257 +// }
  258 +// if end, ok := queryOptions["endTime"].(time.Time); ok {
  259 +// endTime = end
  260 +// } else {
  261 +// endTime = time.Now()
  262 +// }
  263 +// fmt.Print(startTime, "\n")
  264 +// fmt.Print(endTime, "\n")
  265 +// fmt.Print(companyId, "\n")
  266 +// suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
  267 +// if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
  268 +// ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
  269 +// ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
  270 +// ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").
  271 +// Where(`e.company_id = ?`, companyId).
  272 +// Where(`e.status = ?`, 1).
  273 +// Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
  274 +// Where(`su_money_transaction_record.create_time > ?`, startTime).
  275 +// Where(`su_money_transaction_record.create_time < ?`, endTime).
  276 +// Group("su_money_transaction_record.employee").
  277 +// Order("employee_su_money DESC").
  278 +// Select(&ret); err != nil {
  279 +// return nil, err
  280 +// }
  281 +// return map[string]interface{}{
  282 +// "employeesSuMoney": ret,
  283 +// }, nil
  284 +//}
  285 +
236 // 员工贡献值统计 286 // 员工贡献值统计
237 func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) { 287 func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
238 var ret []struct { // 员工贡献值 288 var ret []struct { // 员工贡献值
@@ -2,6 +2,7 @@ package controllers @@ -2,6 +2,7 @@ package controllers
2 2
3 import ( 3 import (
4 "encoding/json" 4 "encoding/json"
  5 + "fmt"
5 6
6 "github.com/astaxie/beego" 7 "github.com/astaxie/beego"
7 "github.com/linmadan/egglib-go/web/beego/utils" 8 "github.com/linmadan/egglib-go/web/beego/utils"
@@ -108,6 +109,7 @@ func (controller *StatisticsController) EmployeesSuMoneyStatistics() { @@ -108,6 +109,7 @@ func (controller *StatisticsController) EmployeesSuMoneyStatistics() {
108 statisticsService := service.NewStatisticsService(nil) 109 statisticsService := service.NewStatisticsService(nil)
109 employeesSuMoneyStatisticsCommand := &command.EmployeesSuMoneyStatisticsCommand{} 110 employeesSuMoneyStatisticsCommand := &command.EmployeesSuMoneyStatisticsCommand{}
110 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesSuMoneyStatisticsCommand) 111 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesSuMoneyStatisticsCommand)
  112 + fmt.Print(employeesSuMoneyStatisticsCommand, "\n")
111 data, err := statisticsService.EmployeesSuMoneyStatistics(employeesSuMoneyStatisticsCommand) 113 data, err := statisticsService.EmployeesSuMoneyStatistics(employeesSuMoneyStatisticsCommand)
112 var response utils.JsonResponse 114 var response utils.JsonResponse
113 if err != nil { 115 if err != nil {
@@ -124,6 +126,7 @@ func (controller *StatisticsController) EmployeesContributionsStatistics() { @@ -124,6 +126,7 @@ func (controller *StatisticsController) EmployeesContributionsStatistics() {
124 statisticsService := service.NewStatisticsService(nil) 126 statisticsService := service.NewStatisticsService(nil)
125 employeesContributionsStatisticsCommand := &command.EmployeesContributionsStatisticsCommand{} 127 employeesContributionsStatisticsCommand := &command.EmployeesContributionsStatisticsCommand{}
126 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesContributionsStatisticsCommand) 128 json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesContributionsStatisticsCommand)
  129 + fmt.Print(employeesContributionsStatisticsCommand, "\n")
127 data, err := statisticsService.EmployeesContributionsStatistics(employeesContributionsStatisticsCommand) 130 data, err := statisticsService.EmployeesContributionsStatistics(employeesContributionsStatisticsCommand)
128 var response utils.JsonResponse 131 var response utils.JsonResponse
129 if err != nil { 132 if err != nil {