Merge branch 'feature-exchange_list' into dev
正在显示
16 个修改的文件
包含
426 行增加
和
9 行删除
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/astaxie/beego/validation" | ||
| 6 | + "time" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +type EmployeesRankingListStatisticsCommand struct { | ||
| 10 | + CompanyId int `json:"companyId" valid:"Required"` // 公司id | ||
| 11 | + StartTime time.Time `json:"startTime"` // 年榜开始时间 | ||
| 12 | + EndTime time.Time `json:"endTime"` // 年榜结束时间 | ||
| 13 | + Offset int `json:"offset,omitempty"` // 查询偏离量 | ||
| 14 | + Limit int `json:"limit,omitempty"` // 查询限制 | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +func (employeesRankingListStatisticsCommand *EmployeesRankingListStatisticsCommand) ValidateCommand() error { | ||
| 18 | + valid := validation.Validation{} | ||
| 19 | + b, err := valid.Valid(employeesRankingListStatisticsCommand) | ||
| 20 | + if err != nil { | ||
| 21 | + return err | ||
| 22 | + } | ||
| 23 | + if !b { | ||
| 24 | + for _, validErr := range valid.Errors { | ||
| 25 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
| 26 | + } | ||
| 27 | + } | ||
| 28 | + return nil | ||
| 29 | +} | ||
| 30 | + |
| @@ -361,6 +361,46 @@ func (statisticsService *StatisticsService) EmployeesContributionsStatistics(emp | @@ -361,6 +361,46 @@ func (statisticsService *StatisticsService) EmployeesContributionsStatistics(emp | ||
| 361 | } | 361 | } |
| 362 | } | 362 | } |
| 363 | 363 | ||
| 364 | +// 员工排行榜统计 | ||
| 365 | +func (statisticsService *StatisticsService) EmployeesRankingListStatistics(employeesRankingListStatisticsCommand *command.EmployeesRankingListStatisticsCommand) (interface{}, error) { | ||
| 366 | + if err := employeesRankingListStatisticsCommand.ValidateCommand(); err != nil { | ||
| 367 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 368 | + } | ||
| 369 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 370 | + if err != nil { | ||
| 371 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 372 | + } | ||
| 373 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 374 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 375 | + } | ||
| 376 | + defer func() { | ||
| 377 | + transactionContext.RollbackTransaction() | ||
| 378 | + }() | ||
| 379 | + | ||
| 380 | + var employeeDao *dao.EmployeeDao | ||
| 381 | + if value, err := factory.CreateEmployeeDao(map[string]interface{}{ | ||
| 382 | + "transactionContext": transactionContext, | ||
| 383 | + }); err != nil { | ||
| 384 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 385 | + } else { | ||
| 386 | + employeeDao = value | ||
| 387 | + } | ||
| 388 | + | ||
| 389 | + if employeesRankingListStatisticsCommand.StartTime.IsZero() && employeesRankingListStatisticsCommand.EndTime.IsZero() { | ||
| 390 | + employeesRankingListStatisticsCommand.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location()) | ||
| 391 | + employeesRankingListStatisticsCommand.EndTime = time.Now().Local() | ||
| 392 | + } | ||
| 393 | + | ||
| 394 | + if employeesRankingListStatistics, err := employeeDao.CalculateEmployeesRankingList(employeesRankingListStatisticsCommand.CompanyId, employeesRankingListStatisticsCommand.StartTime, employeesRankingListStatisticsCommand.EndTime, employeesRankingListStatisticsCommand.Offset, employeesRankingListStatisticsCommand.Limit); err != nil { | ||
| 395 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 396 | + } else { | ||
| 397 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 398 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 399 | + } | ||
| 400 | + return employeesRankingListStatistics, nil | ||
| 401 | + } | ||
| 402 | +} | ||
| 403 | + | ||
| 364 | func NewStatisticsService(options map[string]interface{}) *StatisticsService { | 404 | func NewStatisticsService(options map[string]interface{}) *StatisticsService { |
| 365 | newStatisticsService := &StatisticsService{} | 405 | newStatisticsService := &StatisticsService{} |
| 366 | return newStatisticsService | 406 | return newStatisticsService |
| 1 | +package command | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/astaxie/beego/validation" | ||
| 6 | +) | ||
| 7 | + | ||
| 8 | +type ExportExchangeCashListCommand struct { | ||
| 9 | + IDs []int `json:"iDs"` | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +func (exportExchangeCashListCommand *ExportExchangeCashListCommand) ValidateCommand() error { | ||
| 13 | + valid := validation.Validation{} | ||
| 14 | + b, err := valid.Valid(exportExchangeCashListCommand) | ||
| 15 | + if err != nil { | ||
| 16 | + return err | ||
| 17 | + } | ||
| 18 | + if !b { | ||
| 19 | + for _, validErr := range valid.Errors { | ||
| 20 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
| 21 | + } | ||
| 22 | + } | ||
| 23 | + return nil | ||
| 24 | +} | ||
| 25 | + |
| @@ -7,6 +7,7 @@ import ( | @@ -7,6 +7,7 @@ import ( | ||
| 7 | 7 | ||
| 8 | // 获取兑换活动兑换清单 | 8 | // 获取兑换活动兑换清单 |
| 9 | type ListExchangeCashPersonQuery struct { | 9 | type ListExchangeCashPersonQuery struct { |
| 10 | + CompanyId int64 `json:"companyId"` // 公司id | ||
| 10 | ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id | 11 | ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id |
| 11 | ExchangeCashPersonNameMatch string `json:"exchangeCashPersonNameMatch,omitempty"` // 兑换活动名称匹配 | 12 | ExchangeCashPersonNameMatch string `json:"exchangeCashPersonNameMatch,omitempty"` // 兑换活动名称匹配 |
| 12 | Offset int `json:"offset,omitempty"` // 查询偏离量 | 13 | Offset int `json:"offset,omitempty"` // 查询偏离量 |
| @@ -57,7 +57,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | @@ -57,7 +57,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | ||
| 57 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司id") | 57 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "无效的公司id") |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | - // 获取平台素币兑换情况 | ||
| 61 | var employeeDao *dao.EmployeeDao | 60 | var employeeDao *dao.EmployeeDao |
| 62 | if value, err := factory.CreateEmployeeDao(map[string]interface{}{ | 61 | if value, err := factory.CreateEmployeeDao(map[string]interface{}{ |
| 63 | "transactionContext": transactionContext, | 62 | "transactionContext": transactionContext, |
| @@ -66,7 +65,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | @@ -66,7 +65,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | ||
| 66 | } else { | 65 | } else { |
| 67 | employeeDao = value | 66 | employeeDao = value |
| 68 | } | 67 | } |
| 69 | - | 68 | + // 获取平台素币兑换情况 |
| 70 | systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId) | 69 | systemSuMoneyStatistics, err := employeeDao.CalculateSystemSuMoney(createCashPoolCommand.CompanyId) |
| 71 | if err != nil { | 70 | if err != nil { |
| 72 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 71 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| @@ -93,7 +92,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | @@ -93,7 +92,6 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co | ||
| 93 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 92 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 94 | } | 93 | } |
| 95 | 94 | ||
| 96 | - // 新建现金池 | ||
| 97 | newCashPool := &domain.CashPool{ | 95 | newCashPool := &domain.CashPool{ |
| 98 | CompanyId: createCashPoolCommand.CompanyId, | 96 | CompanyId: createCashPoolCommand.CompanyId, |
| 99 | Cash: createCashPoolCommand.Cash, | 97 | Cash: createCashPoolCommand.Cash, |
| @@ -998,6 +996,11 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer | @@ -998,6 +996,11 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer | ||
| 998 | } | 996 | } |
| 999 | } | 997 | } |
| 1000 | 998 | ||
| 999 | +// 返回素币兑换现金活动总清单 | ||
| 1000 | +//func (cashPoolService *CashPoolService) ListSystemExchangeCashPerson(listSystemExchangeCashPersonQuery *query.ListSystemExchangeCashPersonQuery) (interface{}, error) { | ||
| 1001 | +// | ||
| 1002 | +//} | ||
| 1003 | + | ||
| 1001 | // 返回兑换素币清单列表 | 1004 | // 返回兑换素币清单列表 |
| 1002 | func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashPersonQuery *query.ListExchangeCashPersonQuery) (interface{}, error) { | 1005 | func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashPersonQuery *query.ListExchangeCashPersonQuery) (interface{}, error) { |
| 1003 | if err := listExchangeCashPersonQuery.ValidateQuery(); err != nil { | 1006 | if err := listExchangeCashPersonQuery.ValidateQuery(); err != nil { |
| @@ -1023,7 +1026,46 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP | @@ -1023,7 +1026,46 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP | ||
| 1023 | exchangeCashPersonListRepository = value | 1026 | exchangeCashPersonListRepository = value |
| 1024 | } | 1027 | } |
| 1025 | 1028 | ||
| 1026 | - // TODO 增加总榜单查询 | 1029 | + // 返回兑换现金活动总榜 |
| 1030 | + if listExchangeCashPersonQuery.ExchangeCashActivityId == 0 && listExchangeCashPersonQuery.CompanyId != 0 { | ||
| 1031 | + // 找到该公司下的所有活动id | ||
| 1032 | + var exchangeActivityRepository domain.ExchangeActivityRepository | ||
| 1033 | + if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{ | ||
| 1034 | + "transactionContext": transactionContext, | ||
| 1035 | + }); err != nil { | ||
| 1036 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 1037 | + } else { | ||
| 1038 | + exchangeActivityRepository = value | ||
| 1039 | + } | ||
| 1040 | + | ||
| 1041 | + if _, activities, err := exchangeActivityRepository.FindAll(map[string]interface{}{ | ||
| 1042 | + "companyId": listExchangeCashPersonQuery.CompanyId, | ||
| 1043 | + }); err != nil { | ||
| 1044 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 1045 | + } else { | ||
| 1046 | + var activityIds []int64 | ||
| 1047 | + for _, activity := range activities { | ||
| 1048 | + activityIds = append(activityIds, activity.ActivityId) | ||
| 1049 | + } | ||
| 1050 | + | ||
| 1051 | + if count, people, err := exchangeCashPersonListRepository.FindAll(map[string]interface{}{ | ||
| 1052 | + "exchangeCashActivityIds": activityIds, | ||
| 1053 | + "offset": listExchangeCashPersonQuery.Offset, | ||
| 1054 | + "limit": listExchangeCashPersonQuery.Limit, | ||
| 1055 | + }); err != nil { | ||
| 1056 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 1057 | + } else { | ||
| 1058 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 1059 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 1060 | + } | ||
| 1061 | + return map[string]interface{}{ | ||
| 1062 | + "count": count, | ||
| 1063 | + "people": people, | ||
| 1064 | + }, nil | ||
| 1065 | + } | ||
| 1066 | + } | ||
| 1067 | + } | ||
| 1068 | + | ||
| 1027 | if count, people, err := exchangeCashPersonListRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashPersonQuery)); err != nil { | 1069 | if count, people, err := exchangeCashPersonListRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashPersonQuery)); err != nil { |
| 1028 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | 1070 | return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) |
| 1029 | } else { | 1071 | } else { |
| @@ -1462,6 +1504,45 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC | @@ -1462,6 +1504,45 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashPerson(updateExchangeC | ||
| 1462 | } | 1504 | } |
| 1463 | } | 1505 | } |
| 1464 | 1506 | ||
| 1507 | +// 根据id获取兑换清单 | ||
| 1508 | +func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchangeCashListCommand *command.ExportExchangeCashListCommand) ([]*domain.ExchangeCashPersonList, error) { | ||
| 1509 | + if err := exportExchangeCashListCommand.ValidateCommand(); err != nil { | ||
| 1510 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
| 1511 | + } | ||
| 1512 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
| 1513 | + if err != nil { | ||
| 1514 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 1515 | + } | ||
| 1516 | + if err := transactionContext.StartTransaction(); err != nil { | ||
| 1517 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 1518 | + } | ||
| 1519 | + defer func() { | ||
| 1520 | + transactionContext.RollbackTransaction() | ||
| 1521 | + }() | ||
| 1522 | + | ||
| 1523 | + var exchangeCashPersonListRepository domain.ExchangeCashPersonListRepository | ||
| 1524 | + if value, err := factory.CreateExchangeCashPersonListRepository(map[string]interface{}{ | ||
| 1525 | + "transactionContext": transactionContext, | ||
| 1526 | + }); err != nil { | ||
| 1527 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 1528 | + } else { | ||
| 1529 | + exchangeCashPersonListRepository = value | ||
| 1530 | + } | ||
| 1531 | + | ||
| 1532 | + if _, people, err := exchangeCashPersonListRepository.FindById(tool_funs.SimpleStructToMap(exportExchangeCashListCommand)); err != nil { | ||
| 1533 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
| 1534 | + } else { | ||
| 1535 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
| 1536 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
| 1537 | + } | ||
| 1538 | + //return map[string]interface{}{ | ||
| 1539 | + // "count": count, | ||
| 1540 | + // "people": people, | ||
| 1541 | + //}, nil | ||
| 1542 | + return people, nil | ||
| 1543 | + } | ||
| 1544 | +} | ||
| 1545 | + | ||
| 1465 | func NewCashPoolService(options map[string]interface{}) *CashPoolService { | 1546 | func NewCashPoolService(options map[string]interface{}) *CashPoolService { |
| 1466 | newCashPoolService := &CashPoolService{} | 1547 | newCashPoolService := &CashPoolService{} |
| 1467 | return newCashPoolService | 1548 | return newCashPoolService |
| @@ -14,6 +14,8 @@ type ExchangeCashPersonListRepository interface { | @@ -14,6 +14,8 @@ type ExchangeCashPersonListRepository interface { | ||
| 14 | Remove(exchangeCashPersonList *ExchangeCashPersonList) (*ExchangeCashPersonList, error) | 14 | Remove(exchangeCashPersonList *ExchangeCashPersonList) (*ExchangeCashPersonList, error) |
| 15 | FindOne(queryOptions map[string]interface{}) (*ExchangeCashPersonList, error) | 15 | FindOne(queryOptions map[string]interface{}) (*ExchangeCashPersonList, error) |
| 16 | Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error) | 16 | Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error) |
| 17 | + FindAll(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error) | ||
| 18 | + FindById(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error) | ||
| 17 | } | 19 | } |
| 18 | 20 | ||
| 19 | func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} { | 21 | func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} { |
| @@ -156,7 +156,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf | @@ -156,7 +156,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf | ||
| 156 | // 系统未兑换现金 | 156 | // 系统未兑换现金 |
| 157 | cashPool := new(models.CashPool) | 157 | cashPool := new(models.CashPool) |
| 158 | if err := tx.Model(cashPool). | 158 | if err := tx.Model(cashPool). |
| 159 | - ColumnExpr("exchanged_cash"). | 159 | + Column("exchanged_cash"). |
| 160 | Where("cash_pool.company_id = ?", companyId). | 160 | Where("cash_pool.company_id = ?", companyId). |
| 161 | Order("id DESC"). | 161 | Order("id DESC"). |
| 162 | Limit(1). | 162 | Limit(1). |
| @@ -164,7 +164,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf | @@ -164,7 +164,7 @@ func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interf | ||
| 164 | return nil, err | 164 | return nil, err |
| 165 | } | 165 | } |
| 166 | if err := tx.Model(cashPool). | 166 | if err := tx.Model(cashPool). |
| 167 | - ColumnExpr("un_exchange_cash"). | 167 | + Column("un_exchange_cash"). |
| 168 | Where("cash_pool.company_id = ?", companyId). | 168 | Where("cash_pool.company_id = ?", companyId). |
| 169 | Order("id DESC"). | 169 | Order("id DESC"). |
| 170 | Limit(1). | 170 | Limit(1). |
| @@ -283,6 +283,95 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. | @@ -283,6 +283,95 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. | ||
| 283 | // }, nil | 283 | // }, nil |
| 284 | //} | 284 | //} |
| 285 | 285 | ||
| 286 | +// TODO 排行榜统计,增加分页 | ||
| 287 | +func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time, offset int, limit int) (map[string]interface{}, error) { | ||
| 288 | + var retWealth []struct { | ||
| 289 | + Uid int | ||
| 290 | + EmployeeName string | ||
| 291 | + EmployeeSuMoney float64 | ||
| 292 | + } | ||
| 293 | + var retContributions []struct { // 员工贡献值 | ||
| 294 | + Uid int | ||
| 295 | + EmployeeName string | ||
| 296 | + EmployeesContributions float64 | ||
| 297 | + } | ||
| 298 | + var retContributionDecrease []struct { // 员工减少的贡献值 | ||
| 299 | + Uid int | ||
| 300 | + EmployeeName string | ||
| 301 | + EmployeesContributions float64 | ||
| 302 | + } | ||
| 303 | + tx := dao.transactionContext.PgTx | ||
| 304 | + suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) | ||
| 305 | + if limit < -1 { | ||
| 306 | + limit = 20 | ||
| 307 | + } | ||
| 308 | + if offset < -1 { | ||
| 309 | + offset = 0 | ||
| 310 | + } | ||
| 311 | + // 员工财富值 | ||
| 312 | + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint"). | ||
| 313 | + ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid"). | ||
| 314 | + ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name"). | ||
| 315 | + ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money"). | ||
| 316 | + Where(`e.company_id = ?`, companyId). | ||
| 317 | + Where(`e.status = ?`, 1). | ||
| 318 | + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的 | ||
| 319 | + Where(`su_money_transaction_record.create_time > ?`, startTime). | ||
| 320 | + Where(`su_money_transaction_record.create_time < ?`, endTime). | ||
| 321 | + Group("su_money_transaction_record.employee"). | ||
| 322 | + Order("employee_su_money DESC"). | ||
| 323 | + Limit(limit). | ||
| 324 | + Offset(offset). | ||
| 325 | + Select(&retWealth); err != nil { | ||
| 326 | + return nil, err | ||
| 327 | + } | ||
| 328 | + // 增加的贡献值 | ||
| 329 | + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint"). | ||
| 330 | + ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid"). | ||
| 331 | + ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name"). | ||
| 332 | + ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions"). | ||
| 333 | + Where(`e.company_id = ?`, companyId). | ||
| 334 | + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). | ||
| 335 | + Where(`e.status = ?`, 1). | ||
| 336 | + Where(`su_money_transaction_record.create_time > ?`, startTime). | ||
| 337 | + Where(`su_money_transaction_record.create_time < ?`, endTime). | ||
| 338 | + Group("su_money_transaction_record.employee"). | ||
| 339 | + Order("employees_contributions DESC"). | ||
| 340 | + Limit(limit). | ||
| 341 | + Offset(offset). | ||
| 342 | + Select(&retContributions); err != nil { | ||
| 343 | + return nil, err | ||
| 344 | + } | ||
| 345 | + // 减少的贡献值 | ||
| 346 | + if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint"). | ||
| 347 | + ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid"). | ||
| 348 | + ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name"). | ||
| 349 | + ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions"). | ||
| 350 | + Where(`e.company_id = ?`, companyId). | ||
| 351 | + Where(`su_money_transaction_record.record_type = ?`, 4). | ||
| 352 | + Where(`e.status = ?`, 1). | ||
| 353 | + Where(`su_money_transaction_record.create_time > ?`, startTime). | ||
| 354 | + Where(`su_money_transaction_record.create_time < ?`, endTime). | ||
| 355 | + Group("su_money_transaction_record.employee"). | ||
| 356 | + Order("employees_contributions DESC"). | ||
| 357 | + Limit(limit). | ||
| 358 | + Offset(offset). | ||
| 359 | + Select(&retContributionDecrease); err != nil { | ||
| 360 | + return nil, err | ||
| 361 | + } | ||
| 362 | + for i := 0; i < len(retContributions); i++ { | ||
| 363 | + for j := 0; j < len(retContributionDecrease); j++ { | ||
| 364 | + if retContributions[i].Uid == retContributionDecrease[j].Uid { | ||
| 365 | + retContributions[i].EmployeesContributions -= retContributionDecrease[j].EmployeesContributions | ||
| 366 | + } | ||
| 367 | + } | ||
| 368 | + } | ||
| 369 | + return map[string]interface{}{ | ||
| 370 | + "employeesContributions": retContributions, | ||
| 371 | + "employeesWealth": retWealth, | ||
| 372 | + }, nil | ||
| 373 | +} | ||
| 374 | + | ||
| 286 | // 员工贡献值统计 | 375 | // 员工贡献值统计 |
| 287 | func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) { | 376 | func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) { |
| 288 | var ret []struct { // 员工贡献值 | 377 | var ret []struct { // 员工贡献值 |
| @@ -54,6 +54,68 @@ func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[str | @@ -54,6 +54,68 @@ func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[str | ||
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | 56 | ||
| 57 | +// 根据id获取兑换活动清单 | ||
| 58 | +func (repository *ExchangeCashPersonListRepository) FindById(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) { | ||
| 59 | + tx := repository.transactionContext.PgTx | ||
| 60 | + var exchangeCashListModels []*models.ExchangeCashPersonList | ||
| 61 | + exchangeCashPeople := make([]*domain.ExchangeCashPersonList, 0) | ||
| 62 | + query := tx.Model(&exchangeCashListModels) | ||
| 63 | + if iDs, ok := queryOptions["iDs"]; ok && len(iDs.([]int)) != 0 { | ||
| 64 | + query = query.Where("exchange_cash_person_list.id IN (?)", pg.In(iDs.([]int)) ) | ||
| 65 | + } | ||
| 66 | + if count, err := query.Order("id DESC").SelectAndCount(); err != nil { | ||
| 67 | + return 0, exchangeCashPeople, err | ||
| 68 | + } else { | ||
| 69 | + for _, exchangeCashListModel := range exchangeCashListModels { | ||
| 70 | + if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashListModel); err != nil { | ||
| 71 | + return 0, exchangeCashPeople, err | ||
| 72 | + } else { | ||
| 73 | + exchangeCashPeople = append(exchangeCashPeople, taskNature) | ||
| 74 | + } | ||
| 75 | + } | ||
| 76 | + return int64(count), exchangeCashPeople, nil | ||
| 77 | + } | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +// 获取平台所有兑换活动清单(兑换现金活动总清单) | ||
| 81 | +func (repository *ExchangeCashPersonListRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) { | ||
| 82 | + tx := repository.transactionContext.PgTx | ||
| 83 | + var exchangeCashListModels []*models.ExchangeCashPersonList | ||
| 84 | + exchangeCashPeople := make([]*domain.ExchangeCashPersonList, 0) | ||
| 85 | + query := tx.Model(&exchangeCashListModels) | ||
| 86 | + if exchangeCashActivityIds, ok := queryOptions["exchangeCashActivityIds"]; ok && len(exchangeCashActivityIds.([]int64)) != 0 { | ||
| 87 | + query = query.Where("exchange_cash_person_list.activity_id IN (?)", pg.In(exchangeCashActivityIds.([]int64)) ) | ||
| 88 | + } | ||
| 89 | + if offset, ok := queryOptions["offset"]; ok { | ||
| 90 | + offset := offset.(int) | ||
| 91 | + if offset > -1 { | ||
| 92 | + query = query.Offset(offset) | ||
| 93 | + } | ||
| 94 | + } else { | ||
| 95 | + query = query.Offset(0) | ||
| 96 | + } | ||
| 97 | + if limit, ok := queryOptions["limit"]; ok { | ||
| 98 | + limit := limit.(int) | ||
| 99 | + if limit > -1 { | ||
| 100 | + query = query.Limit(limit) | ||
| 101 | + } | ||
| 102 | + } else { | ||
| 103 | + query = query.Limit(20) | ||
| 104 | + } | ||
| 105 | + if count, err := query.Order("id DESC").SelectAndCount(); err != nil { | ||
| 106 | + return 0, exchangeCashPeople, err | ||
| 107 | + } else { | ||
| 108 | + for _, exchangeCashListModel := range exchangeCashListModels { | ||
| 109 | + if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashListModel); err != nil { | ||
| 110 | + return 0, exchangeCashPeople, err | ||
| 111 | + } else { | ||
| 112 | + exchangeCashPeople = append(exchangeCashPeople, taskNature) | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | + return int64(count), exchangeCashPeople, nil | ||
| 116 | + } | ||
| 117 | +} | ||
| 118 | + | ||
| 57 | func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) { | 119 | func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) { |
| 58 | tx := repository.transactionContext.PgTx | 120 | tx := repository.transactionContext.PgTx |
| 59 | var exchangeCashListModels []*models.ExchangeCashPersonList | 121 | var exchangeCashListModels []*models.ExchangeCashPersonList |
| @@ -126,7 +126,6 @@ func (controller *StatisticsController) EmployeesContributionsStatistics() { | @@ -126,7 +126,6 @@ func (controller *StatisticsController) EmployeesContributionsStatistics() { | ||
| 126 | statisticsService := service.NewStatisticsService(nil) | 126 | statisticsService := service.NewStatisticsService(nil) |
| 127 | employeesContributionsStatisticsCommand := &command.EmployeesContributionsStatisticsCommand{} | 127 | employeesContributionsStatisticsCommand := &command.EmployeesContributionsStatisticsCommand{} |
| 128 | json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesContributionsStatisticsCommand) | 128 | json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesContributionsStatisticsCommand) |
| 129 | - fmt.Print(employeesContributionsStatisticsCommand, "\n") | ||
| 130 | data, err := statisticsService.EmployeesContributionsStatistics(employeesContributionsStatisticsCommand) | 129 | data, err := statisticsService.EmployeesContributionsStatistics(employeesContributionsStatisticsCommand) |
| 131 | var response utils.JsonResponse | 130 | var response utils.JsonResponse |
| 132 | if err != nil { | 131 | if err != nil { |
| @@ -137,3 +136,19 @@ func (controller *StatisticsController) EmployeesContributionsStatistics() { | @@ -137,3 +136,19 @@ func (controller *StatisticsController) EmployeesContributionsStatistics() { | ||
| 137 | controller.Data["json"] = response | 136 | controller.Data["json"] = response |
| 138 | controller.ServeJSON() | 137 | controller.ServeJSON() |
| 139 | } | 138 | } |
| 139 | + | ||
| 140 | +// TODO 合并员工财富值、贡献值排行榜 | ||
| 141 | +func (controller *StatisticsController) RankingListStatistics() { | ||
| 142 | + statisticsService := service.NewStatisticsService(nil) | ||
| 143 | + employeesRankingListStatisticsCommand := &command.EmployeesRankingListStatisticsCommand{} | ||
| 144 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesRankingListStatisticsCommand) | ||
| 145 | + data, err := statisticsService.EmployeesRankingListStatistics(employeesRankingListStatisticsCommand) | ||
| 146 | + var response utils.JsonResponse | ||
| 147 | + if err != nil { | ||
| 148 | + response = utils.ResponseError(controller.Ctx, err) | ||
| 149 | + } else { | ||
| 150 | + response = utils.ResponseData(controller.Ctx, data) | ||
| 151 | + } | ||
| 152 | + controller.Data["json"] = response | ||
| 153 | + controller.ServeJSON() | ||
| 154 | +} |
| @@ -231,6 +231,8 @@ func (controller *SuMoneyController) ListExchangeList () { | @@ -231,6 +231,8 @@ func (controller *SuMoneyController) ListExchangeList () { | ||
| 231 | listExchangeCashListQuery := &query.ListExchangeCashPersonQuery{} | 231 | listExchangeCashListQuery := &query.ListExchangeCashPersonQuery{} |
| 232 | activityId, _ := controller.GetInt64("activityId") | 232 | activityId, _ := controller.GetInt64("activityId") |
| 233 | listExchangeCashListQuery.ExchangeCashActivityId = activityId | 233 | listExchangeCashListQuery.ExchangeCashActivityId = activityId |
| 234 | + companyId, _ := controller.GetInt64("companyId") | ||
| 235 | + listExchangeCashListQuery.CompanyId = companyId | ||
| 234 | exchangeCashPersonNameMatch := controller.GetString("personNameMatch") | 236 | exchangeCashPersonNameMatch := controller.GetString("personNameMatch") |
| 235 | listExchangeCashListQuery.ExchangeCashPersonNameMatch = exchangeCashPersonNameMatch | 237 | listExchangeCashListQuery.ExchangeCashPersonNameMatch = exchangeCashPersonNameMatch |
| 236 | offset, _ := controller.GetInt("offset") | 238 | offset, _ := controller.GetInt("offset") |
| @@ -396,9 +398,73 @@ func (controller *SuMoneyController) ListDeadline() { | @@ -396,9 +398,73 @@ func (controller *SuMoneyController) ListDeadline() { | ||
| 396 | controller.ServeJSON() | 398 | controller.ServeJSON() |
| 397 | } | 399 | } |
| 398 | 400 | ||
| 399 | -// TODO 导出素币兑换清单,选择导出(ids),增加导出失败信息 | 401 | +// 导出素币兑换清单,选择导出(ids),增加导出失败信息 |
| 400 | func (controller *SuMoneyController) ExportExchangeList() { | 402 | func (controller *SuMoneyController) ExportExchangeList() { |
| 401 | - | 403 | + cashPoolService := service.NewCashPoolService(nil) |
| 404 | + exportExchangeCashListCommand := &command.ExportExchangeCashListCommand{} | ||
| 405 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exportExchangeCashListCommand) | ||
| 406 | + fmt.Print(exportExchangeCashListCommand, "\n") | ||
| 407 | + // 列标题 | ||
| 408 | + titles := []string{ | ||
| 409 | + "姓名","手机账号","已兑换现金","已兑换素币", | ||
| 410 | + } | ||
| 411 | + // 列单元 | ||
| 412 | + cells := []string{ | ||
| 413 | + "A","B","C","D", | ||
| 414 | + } | ||
| 415 | + // 数据源 | ||
| 416 | + var data []map[string]interface{} | ||
| 417 | + people, err := cashPoolService.ListExchangeCashPersonById(exportExchangeCashListCommand) | ||
| 418 | + for _, person := range people { | ||
| 419 | + p := map[string]interface{} { | ||
| 420 | + "name": person.EmployeeInfo.EmployeeName, | ||
| 421 | + "account": person.EmployeeInfo.EmployeeAccount, | ||
| 422 | + "exchanged_cash": person.ExchangedCash, | ||
| 423 | + "exchanged_su_money": person.ExchangedSuMoney, | ||
| 424 | + } | ||
| 425 | + data = append(data, p) | ||
| 426 | + } | ||
| 427 | + fmt.Print(data, "\n") | ||
| 428 | + var response utils.JsonResponse | ||
| 429 | + if err != nil { | ||
| 430 | + response = utils.ResponseError(controller.Ctx, err) | ||
| 431 | + controller.Data["json"] = response | ||
| 432 | + controller.ServeJSON() | ||
| 433 | + } else { | ||
| 434 | + // 新建文件 | ||
| 435 | + f := excelize.NewFile() | ||
| 436 | + // 新建工作簿 | ||
| 437 | + index := f.NewSheet("Sheet1") | ||
| 438 | + //列标题赋值 | ||
| 439 | + for column, v := range titles { | ||
| 440 | + f.SetCellValue("Sheet1", cells[column]+"1", v) | ||
| 441 | + } | ||
| 442 | + for lineNum, v := range data { //行数 lineNum 行内容 v | ||
| 443 | + columnNum := 0 //列数 | ||
| 444 | + for _, vv := range v { | ||
| 445 | + sheetPosition := cells[columnNum] + strconv.Itoa(lineNum+2) | ||
| 446 | + switch vv.(type) { | ||
| 447 | + case string: | ||
| 448 | + f.SetCellValue("Sheet1", sheetPosition, vv.(string)) | ||
| 449 | + break | ||
| 450 | + case int: | ||
| 451 | + f.SetCellValue("Sheet1", sheetPosition, vv.(int)) | ||
| 452 | + break | ||
| 453 | + case float64: | ||
| 454 | + f.SetCellValue("Sheet1", sheetPosition, vv.(float64)) | ||
| 455 | + break | ||
| 456 | + } | ||
| 457 | + columnNum++ | ||
| 458 | + } | ||
| 459 | + } | ||
| 460 | + f.SetActiveSheet(index) | ||
| 461 | + //保存为文件 | ||
| 462 | + f.Path="public/file/素币兑换清单.xlsx" | ||
| 463 | + if err := f.Save(); err != nil { | ||
| 464 | + fmt.Println(err) | ||
| 465 | + } | ||
| 466 | + controller.Ctx.Output.Download(f.Path,"素币兑换清单.xlsx") | ||
| 467 | + } | ||
| 402 | } | 468 | } |
| 403 | 469 | ||
| 404 | // TODO 导出素币流水记录,选择导出(ids),增加导出失败信息 | 470 | // TODO 导出素币流水记录,选择导出(ids),增加导出失败信息 |
| @@ -14,4 +14,5 @@ func init() { | @@ -14,4 +14,5 @@ func init() { | ||
| 14 | beego.Router("/statistics/system-cash", &controllers.StatisticsController{}, "Post:SystemCashStatistics") // 系统现金统计 | 14 | beego.Router("/statistics/system-cash", &controllers.StatisticsController{}, "Post:SystemCashStatistics") // 系统现金统计 |
| 15 | beego.Router("/statistics/employees-su-money", &controllers.StatisticsController{}, "Post:EmployeesSuMoneyStatistics") // 员工财富值统计 | 15 | beego.Router("/statistics/employees-su-money", &controllers.StatisticsController{}, "Post:EmployeesSuMoneyStatistics") // 员工财富值统计 |
| 16 | beego.Router("/statistics/employees-contributions", &controllers.StatisticsController{}, "Post:EmployeesContributionsStatistics") // 员工贡献值统计 | 16 | beego.Router("/statistics/employees-contributions", &controllers.StatisticsController{}, "Post:EmployeesContributionsStatistics") // 员工贡献值统计 |
| 17 | + beego.Router("/statistics/employees-ranking-list", &controllers.StatisticsController{}, "Post:RankingListStatistics") // 员工财富值、贡献值排行榜 | ||
| 17 | } | 18 | } |
public/README.md
0 → 100644
| 1 | +#mmm-worth 1 |
public/file/素币兑换清单.xlsx
0 → 100644
不能预览此文件类型
public/file/订单表.xlsx
0 → 100644
不能预览此文件类型
public/兑换素币清单-导入模板.xlsx
0 → 100644
不能预览此文件类型
-
请 注册 或 登录 后发表评论