作者 陈志颖

fix:修复兑换清单个人排行

... ... @@ -114,6 +114,10 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
}
queryPeople = queryPeople.Group("exchange_cash_person_list.uid")
queryPeople = queryPeople.Group("exchange_cash_person_list.employee_name")
// 子清单查询
queryPeopleWith := queryPeople.Order("su_money DESC")
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
... ... @@ -130,31 +134,23 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
} else {
queryPeople = queryPeople.Limit(20)
}
//queryPeopleWith := queryPeople.Order("su_money DESC") // 子查询
if err := queryPeople.Order("su_money DESC").Select(&retPeople); err != nil {
return nil, err
}
// 个人排名
queryEmployee := tx.Model(exchangeCashPersonListModels)
queryEmployee = queryEmployee.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid")
queryEmployee = queryEmployee.ColumnExpr("exchange_cash_person_list.uid AS uid")
queryEmployee = queryEmployee.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name")
queryEmployee = queryEmployee.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash")
queryEmployee = queryEmployee.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money")
queryEmployee = queryEmployee.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC) AS ranking")
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryEmployee = queryEmployee.Where("e.company_id = ?", companyId)
}
if activityId, ok := queryOptions["activityId"]; ok && (activityId.(int64) != 0) {
queryEmployee = queryEmployee.Where("exchange_cash_person_list.activity_id = ?", activityId)
}
// 个人清单排名
queryEmployee := tx.Model()
queryEmployee = queryEmployee.With("t", queryPeopleWith)
queryEmployee = queryEmployee.Table("t")
queryEmployee = queryEmployee.ColumnExpr("t.uid AS uid")
queryEmployee = queryEmployee.ColumnExpr("t.employee_name AS employee_name")
queryEmployee = queryEmployee.ColumnExpr("t.cash AS cash")
queryEmployee = queryEmployee.ColumnExpr("t.su_money AS su_money")
queryEmployee = queryEmployee.ColumnExpr("t.ranking AS ranking")
if uid, ok := queryOptions["uid"]; ok {
queryEmployee = queryEmployee.Where("exchange_cash_person_list.uid = ?", uid)
queryEmployee = queryEmployee.Where("t.uid::bigint = ?", uid)
}
queryEmployee = queryEmployee.Group("exchange_cash_person_list.uid")
queryEmployee = queryEmployee.Group("exchange_cash_person_list.employee_name")
if err := queryEmployee.Order("su_money DESC").Select(&retEmployee); err != nil {
if err := queryEmployee.Select(&retEmployee); err != nil {
return nil, err
}
var currentEmployee interface{}
... ...
... ... @@ -365,7 +365,10 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
queryWealth = queryWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
}
queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
queryWealthWith := queryWealth.Order("employee_su_money DESC") // 个人财富值子查询
// 个人财富值子查询
queryWealthWith := queryWealth.Order("employee_su_money DESC")
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
... ... @@ -450,7 +453,10 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
queryContributions = queryContributions.Where(`su_money_transaction_records.create_time < ?`, endTime)
}
queryContributions = queryContributions.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',t.employee_contributions_decrease")
//queryContributionsWith := queryContributions.Order("employees_contributions DESC") // 个人贡献值子查询
// 个人贡献值子查询
queryContributionsWith := queryContributions.Order("employees_contributions DESC")
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
... ... @@ -471,52 +477,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
return nil, err
}
// 个人贡献值子查询-减少的贡献值排名
queryEmployeeContributionsDecrease := tx.Model(suMoneyTransactionRecordModel)
queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_contributions_decrease")
queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Where("e.company_id = ?", companyId)
}
queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Where(`e.status = ?`, 1)
queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Where(`su_money_transaction_record.record_type = ?`, 4)
if startTime, ok := queryOptions["startTime"]; ok {
queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Where(`su_money_transaction_record.create_time > ?`, startTime)
}
if endTime, ok := queryOptions["endTime"]; ok {
queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Where(`su_money_transaction_record.create_time < ?`, endTime)
}
employeeContributionsDecrease := queryEmployeeContributionsDecrease.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
// 个人贡献值排名
// 个人贡献值
queryEmployeeContributions := tx.Model()
queryEmployeeContributions = queryEmployeeContributions.With("t", employeeContributionsDecrease)
queryEmployeeContributions = queryEmployeeContributions.With("t", queryContributionsWith)
queryEmployeeContributions = queryEmployeeContributions.Table("t")
queryEmployeeContributions = queryEmployeeContributions.Table("su_money_transaction_records")
queryEmployeeContributions = queryEmployeeContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint")
queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid")
queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("su_money_transaction_records.employee->>'employeeName' AS employee_name")
queryEmployeeContributions = queryEmployeeContributions.ColumnExpr(`(sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease) AS employees_contributions`)
queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC) AS ranking")
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryEmployeeContributions = queryContributions.Where("e.company_id = ?", companyId)
}
queryEmployeeContributions = queryEmployeeContributions.Where(`e.status = ?`, 1)
queryEmployeeContributions = queryEmployeeContributions.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3}))
if startTime, ok := queryOptions["startTime"]; ok {
queryEmployeeContributions = queryEmployeeContributions.Where(`su_money_transaction_records.create_time > ?`, startTime)
}
if endTime, ok := queryOptions["endTime"]; ok {
queryEmployeeContributions = queryEmployeeContributions.Where(`su_money_transaction_records.create_time < ?`, endTime)
}
queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("t.uid AS uid")
queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("t.employee_name AS employee_name")
queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("t.employees_contributions AS employees_contributions")
queryEmployeeContributions = queryEmployeeContributions.ColumnExpr("t.ranking AS ranking")
if uid, ok := queryOptions["uid"]; ok {
queryEmployeeContributions = queryEmployeeContributions.Where(`su_money_transaction_records.employee @> '{"uid":?}'`, uid)
queryEmployeeContributions = queryEmployeeContributions.Where("t.uid::bigint = ?", uid)
}
queryEmployeeContributions = queryEmployeeContributions.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',t.employee_contributions_decrease")
if err := queryEmployeeContributions.Order("employees_contributions DESC").Select(&retEmployeeContributions); err != nil {
if err := queryEmployeeContributions.Select(&retEmployeeContributions); err != nil {
return nil, err
}
var retCurrentEmployeeContributions interface{}
... ...