正在显示
10 个修改的文件
包含
214 行增加
和
4 行删除
@@ -383,7 +383,7 @@ func (statisticsService *StatisticsService) EmployeesContributionsStatistics(emp | @@ -383,7 +383,7 @@ func (statisticsService *StatisticsService) EmployeesContributionsStatistics(emp | ||
383 | } | 383 | } |
384 | } | 384 | } |
385 | 385 | ||
386 | -// 员工排行榜统计 | 386 | +// TODO 员工排行榜统计 |
387 | func (statisticsService *StatisticsService) EmployeesRankingListStatistics(employeesRankingListStatisticsCommand *command.EmployeesRankingListStatisticsCommand) (interface{}, error) { | 387 | func (statisticsService *StatisticsService) EmployeesRankingListStatistics(employeesRankingListStatisticsCommand *command.EmployeesRankingListStatisticsCommand) (interface{}, error) { |
388 | if err := employeesRankingListStatisticsCommand.ValidateCommand(); err != nil { | 388 | if err := employeesRankingListStatisticsCommand.ValidateCommand(); err != nil { |
389 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 389 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
1 | +package query | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "github.com/astaxie/beego/validation" | ||
6 | +) | ||
7 | + | ||
8 | +type ExchangeListRankingQuery struct { | ||
9 | + ActivityId int64 `json:"activityId"` | ||
10 | + CompanyId int64 `json:"companyId"` // 公司ID | ||
11 | + Offset int `json:"offset,omitempty"` // 查询偏离量 | ||
12 | + Limit int `json:"limit,omitempty"` // 查询限制 | ||
13 | + Uid int64 `json:"uid"` // 统一用户id | ||
14 | +} | ||
15 | + | ||
16 | +func (exchangeListRankingQuery *ExchangeListRankingQuery) ValidateCommand() error { | ||
17 | + valid := validation.Validation{} | ||
18 | + b, err := valid.Valid(exchangeListRankingQuery) | ||
19 | + if err != nil { | ||
20 | + return err | ||
21 | + } | ||
22 | + if !b { | ||
23 | + for _, validErr := range valid.Errors { | ||
24 | + return fmt.Errorf("%s %s", validErr.Key, validErr.Message) | ||
25 | + } | ||
26 | + } | ||
27 | + return nil | ||
28 | +} |
@@ -1060,7 +1060,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer | @@ -1060,7 +1060,7 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer | ||
1060 | // | 1060 | // |
1061 | //} | 1061 | //} |
1062 | 1062 | ||
1063 | -// 返回兑换素币清单列表 | 1063 | +// TODO 返回兑换素币清单列表 |
1064 | func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashPersonQuery *query.ListExchangeCashPersonQuery) (interface{}, error) { | 1064 | func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashPersonQuery *query.ListExchangeCashPersonQuery) (interface{}, error) { |
1065 | if err := listExchangeCashPersonQuery.ValidateQuery(); err != nil { | 1065 | if err := listExchangeCashPersonQuery.ValidateQuery(); err != nil { |
1066 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | 1066 | return nil, application.ThrowError(application.ARG_ERROR, err.Error()) |
@@ -1598,6 +1598,41 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang | @@ -1598,6 +1598,41 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang | ||
1598 | } | 1598 | } |
1599 | } | 1599 | } |
1600 | 1600 | ||
1601 | +// TODO 员工兑换清单榜单 | ||
1602 | +func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQuery *query.ExchangeListRankingQuery) (interface{}, error) { | ||
1603 | + if err := exchangeListRankingQuery.ValidateCommand(); err != nil { | ||
1604 | + return nil, application.ThrowError(application.ARG_ERROR, err.Error()) | ||
1605 | + } | ||
1606 | + transactionContext, err := factory.CreateTransactionContext(nil) | ||
1607 | + if err != nil { | ||
1608 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
1609 | + } | ||
1610 | + if err := transactionContext.StartTransaction(); err != nil { | ||
1611 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
1612 | + } | ||
1613 | + defer func() { | ||
1614 | + transactionContext.RollbackTransaction() | ||
1615 | + }() | ||
1616 | + | ||
1617 | + var cashPoolDao *dao.CashPoolDao | ||
1618 | + if value, err := factory.CreateCashPoolDao(map[string]interface{}{ | ||
1619 | + "transactionContext": transactionContext, | ||
1620 | + }); err != nil { | ||
1621 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
1622 | + } else { | ||
1623 | + cashPoolDao = value | ||
1624 | + } | ||
1625 | + | ||
1626 | + if exchangeCashListRankingStatistics, err := cashPoolDao.ExchangeCashListRanking(tool_funs.SimpleStructToMap(exchangeListRankingQuery)); err != nil { | ||
1627 | + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) | ||
1628 | + } else { | ||
1629 | + if err := transactionContext.CommitTransaction(); err != nil { | ||
1630 | + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) | ||
1631 | + } | ||
1632 | + return exchangeCashListRankingStatistics, nil | ||
1633 | + } | ||
1634 | +} | ||
1635 | + | ||
1601 | func NewCashPoolService(options map[string]interface{}) *CashPoolService { | 1636 | func NewCashPoolService(options map[string]interface{}) *CashPoolService { |
1602 | newCashPoolService := &CashPoolService{} | 1637 | newCashPoolService := &CashPoolService{} |
1603 | return newCashPoolService | 1638 | return newCashPoolService |
@@ -13,6 +13,8 @@ type SearchTaskCommand struct { | @@ -13,6 +13,8 @@ type SearchTaskCommand struct { | ||
13 | Sponsor int64 `json:"sponsor,omitempty"` | 13 | Sponsor int64 `json:"sponsor,omitempty"` |
14 | // 任务内容匹配 | 14 | // 任务内容匹配 |
15 | TaskContentMatch string `json:"taskContentMatch,omitempty"` | 15 | TaskContentMatch string `json:"taskContentMatch,omitempty"` |
16 | + // 任务名称匹配 | ||
17 | + TaskNameMatch string `json:"taskNameMatch,omitempty"` | ||
16 | // 任务类型 | 18 | // 任务类型 |
17 | TaskType int `json:"taskType,omitempty"` | 19 | TaskType int `json:"taskType,omitempty"` |
18 | // 任务类型ID列表 | 20 | // 任务类型ID列表 |
@@ -77,6 +77,133 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map | @@ -77,6 +77,133 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map | ||
77 | }, nil | 77 | }, nil |
78 | } | 78 | } |
79 | 79 | ||
80 | +// TODO 返回兑换清单榜单 | ||
81 | +func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interface{}) (map[string]interface{}, error) { | ||
82 | + var retPeople []struct { | ||
83 | + Uid int | ||
84 | + EmployeeName string | ||
85 | + SuMoney float64 | ||
86 | + Cash float64 | ||
87 | + Ranking int | ||
88 | + } | ||
89 | + | ||
90 | + var retEmployee []struct { | ||
91 | + Uid int | ||
92 | + EmployeeName string | ||
93 | + SuMoney float64 | ||
94 | + Cash float64 | ||
95 | + Ranking int | ||
96 | + } | ||
97 | + | ||
98 | + tx := dao.transactionContext.PgTx | ||
99 | + | ||
100 | + // 清单人员排名 | ||
101 | + exchangeCashPersonListModels := new(models.ExchangeCashPersonList) | ||
102 | + queryPeople := tx.Model(exchangeCashPersonListModels) | ||
103 | + queryPeople = queryPeople.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid") | ||
104 | + queryPeople = queryPeople.ColumnExpr("exchange_cash_person_list.uid AS uid") | ||
105 | + queryPeople = queryPeople.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name") | ||
106 | + queryPeople = queryPeople.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash") | ||
107 | + queryPeople = queryPeople.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money") | ||
108 | + queryPeople = queryPeople.ColumnExpr("RANK() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC) AS ranking") | ||
109 | + if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { | ||
110 | + queryPeople = queryPeople.Where("e.company_id = ?", companyId) | ||
111 | + } | ||
112 | + if activityId, ok := queryOptions["activityId"]; ok && (activityId.(int64) != 0){ | ||
113 | + queryPeople = queryPeople.Where("exchange_cash_person_list.activity_id = ?", activityId) | ||
114 | + } | ||
115 | + queryPeople = queryPeople.Group("exchange_cash_person_list.uid") | ||
116 | + queryPeople = queryPeople.Group("exchange_cash_person_list.employee_name") | ||
117 | + if offset, ok := queryOptions["offset"]; ok { | ||
118 | + offset := offset.(int) | ||
119 | + if offset > -1 { | ||
120 | + queryPeople = queryPeople.Offset(offset) | ||
121 | + } | ||
122 | + } else { | ||
123 | + queryPeople = queryPeople.Offset(0) | ||
124 | + } | ||
125 | + if limit, ok := queryOptions["limit"]; ok { | ||
126 | + limit := limit.(int) | ||
127 | + if limit > -1 { | ||
128 | + queryPeople = queryPeople.Limit(limit) | ||
129 | + } | ||
130 | + } else { | ||
131 | + queryPeople = queryPeople.Limit(20) | ||
132 | + } | ||
133 | + | ||
134 | + if err := queryPeople.Order("su_money DESC").Select(&retPeople); err != nil { | ||
135 | + return nil, err | ||
136 | + } | ||
137 | + | ||
138 | + // 当前员工排名 | ||
139 | + queryEmployee := tx.Model(exchangeCashPersonListModels) | ||
140 | + queryEmployee = queryEmployee.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid") | ||
141 | + queryEmployee = queryEmployee.ColumnExpr("exchange_cash_person_list.uid AS uid") | ||
142 | + queryEmployee = queryEmployee.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name") | ||
143 | + queryEmployee = queryEmployee.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash") | ||
144 | + queryEmployee = queryEmployee.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money") | ||
145 | + queryEmployee = queryEmployee.ColumnExpr("RANK() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC) AS ranking") | ||
146 | + if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { | ||
147 | + queryEmployee = queryEmployee.Where("e.company_id = ?", companyId) | ||
148 | + } | ||
149 | + if activityId, ok := queryOptions["activityId"]; ok && (activityId.(int64) != 0) { | ||
150 | + queryEmployee = queryEmployee.Where("exchange_cash_person_list.activity_id = ?", activityId) | ||
151 | + } | ||
152 | + if uid, ok := queryOptions["uid"]; ok { | ||
153 | + queryEmployee = queryEmployee.Where("exchange_cash_person_list.uid = ?", uid) | ||
154 | + } | ||
155 | + queryEmployee = queryEmployee.Group("exchange_cash_person_list.uid") | ||
156 | + queryEmployee = queryEmployee.Group("exchange_cash_person_list.employee_name") | ||
157 | + if err := queryEmployee.Order("su_money DESC").Select(&retEmployee); err != nil { | ||
158 | + return nil, err | ||
159 | + } | ||
160 | + | ||
161 | + // 清单已兑换素币 | ||
162 | + var activityExchangedSuMoney float64 | ||
163 | + queryListSuMoney := tx.Model(exchangeCashPersonListModels) | ||
164 | + queryListSuMoney = queryListSuMoney.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid") | ||
165 | + queryListSuMoney = queryListSuMoney.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS activity_exchanged_su_money") | ||
166 | + if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { | ||
167 | + queryListSuMoney = queryListSuMoney.Where("e.company_id = ?", companyId) | ||
168 | + } | ||
169 | + if activityId, ok := queryOptions["activityId"]; ok && (activityId.(int64) != 0) { | ||
170 | + queryListSuMoney = queryListSuMoney.Where("exchange_cash_person_list.activity_id = ?", activityId) | ||
171 | + } | ||
172 | + if err := queryListSuMoney.Select(&activityExchangedSuMoney); err != nil { | ||
173 | + return nil, err | ||
174 | + } | ||
175 | + | ||
176 | + // 清单已兑换现金 | ||
177 | + var activityExchangedCash float64 | ||
178 | + queryListCash := tx.Model(exchangeCashPersonListModels) | ||
179 | + queryListCash = queryListCash.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid") | ||
180 | + queryListCash = queryListCash.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS activity_exchanged_cash") | ||
181 | + if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { | ||
182 | + queryListCash = queryListCash.Where("e.company_id = ?", companyId) | ||
183 | + } | ||
184 | + if activityId, ok := queryOptions["activityId"]; ok && (activityId.(int64) != 0) { | ||
185 | + queryListCash = queryListCash.Where("exchange_cash_person_list.activity_id = ?", activityId) | ||
186 | + } | ||
187 | + if err := queryListCash.Select(&activityExchangedCash); err != nil { | ||
188 | + return nil, err | ||
189 | + } | ||
190 | + | ||
191 | + // 清单计数 | ||
192 | + queryCount := tx.Model(exchangeCashPersonListModels) | ||
193 | + count, err := queryCount.Count() | ||
194 | + if err != nil { | ||
195 | + return nil, err | ||
196 | + } | ||
197 | + | ||
198 | + return map[string]interface{} { | ||
199 | + "people": retPeople, // 员工排行榜 | ||
200 | + "count": count, // 计数 | ||
201 | + "currentEmployee": retEmployee[0], // 当前员工排名 | ||
202 | + "exchangedSuMoney": activityExchangedSuMoney, // 清单已兑换素币 | ||
203 | + "exchangedCash": activityExchangedCash, // 清单已兑换现金 | ||
204 | + }, nil | ||
205 | +} | ||
206 | + | ||
80 | func NewCashPoolDao(transactionContext *pgTransaction.TransactionContext) (*CashPoolDao, error) { | 207 | func NewCashPoolDao(transactionContext *pgTransaction.TransactionContext) (*CashPoolDao, error) { |
81 | if transactionContext == nil { | 208 | if transactionContext == nil { |
82 | return nil, fmt.Errorf("transactionContext参数不能为nil") | 209 | return nil, fmt.Errorf("transactionContext参数不能为nil") |
@@ -283,7 +283,7 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. | @@ -283,7 +283,7 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. | ||
283 | // }, nil | 283 | // }, nil |
284 | //} | 284 | //} |
285 | 285 | ||
286 | -// 排行榜统计 | 286 | +// TODO 排行榜统计,排名 |
287 | func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time, offset int, limit int) (map[string]interface{}, error) { | 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 { | 288 | var retWealth []struct { |
289 | Uid int | 289 | Uid int |
@@ -288,7 +288,6 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro | @@ -288,7 +288,6 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (map[string]interface{}, erro | ||
288 | } else { | 288 | } else { |
289 | completedAsParticipator = int64(count) | 289 | completedAsParticipator = int64(count) |
290 | } | 290 | } |
291 | - // TODO 已过期竞标任务统计 | ||
292 | if count, err := tx.Model(taskModel). | 291 | if count, err := tx.Model(taskModel). |
293 | Where(`task.sponsor @> '{"uid":?}'`, uid). | 292 | Where(`task.sponsor @> '{"uid":?}'`, uid). |
294 | //Where(`task.task_type = ? `, domain.TASK_STATUS_EXPIRED). | 293 | //Where(`task.task_type = ? `, domain.TASK_STATUS_EXPIRED). |
@@ -95,6 +95,8 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( | @@ -95,6 +95,8 @@ func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) ( | ||
95 | return repository.transformPgModelToDomainModel(taskModel) | 95 | return repository.transformPgModelToDomainModel(taskModel) |
96 | } | 96 | } |
97 | } | 97 | } |
98 | + | ||
99 | +// TODO 添加任务名称搜索 | ||
98 | func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Task, error) { | 100 | func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Task, error) { |
99 | tx := repository.transactionContext.PgTx | 101 | tx := repository.transactionContext.PgTx |
100 | var taskModels []*models.Task | 102 | var taskModels []*models.Task |
@@ -480,3 +480,19 @@ func (controller *SuMoneyController) ExportExchangeList() { | @@ -480,3 +480,19 @@ func (controller *SuMoneyController) ExportExchangeList() { | ||
480 | func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() { | 480 | func (controller *SuMoneyController) ExportSuMoneyTransactionRecord() { |
481 | 481 | ||
482 | } | 482 | } |
483 | + | ||
484 | +// 返回兑换素币清单排行榜 | ||
485 | +func (controller *SuMoneyController) ExchangeCashListRanking() { | ||
486 | + cashPoolService := service.NewCashPoolService(nil) | ||
487 | + exchangeListRankingQuery := &query.ExchangeListRankingQuery{} | ||
488 | + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), exchangeListRankingQuery) | ||
489 | + data, err := cashPoolService.ExchangeListRanking(exchangeListRankingQuery) | ||
490 | + var response utils.JsonResponse | ||
491 | + if err != nil { | ||
492 | + response = utils.ResponseError(controller.Ctx, err) | ||
493 | + } else { | ||
494 | + response = utils.ResponseData(controller.Ctx, data) | ||
495 | + } | ||
496 | + controller.Data["json"] = response | ||
497 | + controller.ServeJSON() | ||
498 | +} |
@@ -34,4 +34,5 @@ func init() { | @@ -34,4 +34,5 @@ func init() { | ||
34 | beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "Delete:RemoveExchangeCashPerson") // 删除素币兑换清单 | 34 | beego.Router("/cash-pool/activity/exchange-list/:listId", &controllers.SuMoneyController{}, "Delete:RemoveExchangeCashPerson") // 删除素币兑换清单 |
35 | beego.Router("/cash-pool/activity/exchange-list/import", &controllers.SuMoneyController{}, "Post:ImportExchangeList") // 导入素币兑换清单 | 35 | beego.Router("/cash-pool/activity/exchange-list/import", &controllers.SuMoneyController{}, "Post:ImportExchangeList") // 导入素币兑换清单 |
36 | beego.Router("/cash-pool/activity/exchange-list/export", &controllers.SuMoneyController{}, "Post:ExportExchangeList") // 导出素币兑换清单 | 36 | beego.Router("/cash-pool/activity/exchange-list/export", &controllers.SuMoneyController{}, "Post:ExportExchangeList") // 导出素币兑换清单 |
37 | + beego.Router("/cash-pool/activity/exchange-list/ranking", &controllers.SuMoneyController{}, "Post:ExchangeCashListRanking") // 兑换素币清单排行榜 | ||
37 | } | 38 | } |
-
请 注册 或 登录 后发表评论