...
|
...
|
@@ -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{}
|
...
|
...
|
|