...
|
...
|
@@ -432,18 +432,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
|
|
|
/**********************************************贡献值排行榜****************************************/
|
|
|
|
|
|
// 减少的贡献值
|
|
|
// 贡献值
|
|
|
queryContributionsDecrease := tx.Model(suMoneyTransactionRecordModel)
|
|
|
queryContributionsDecrease = queryContributionsDecrease.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
|
|
|
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
|
|
|
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
|
|
|
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_contributions_decrease")
|
|
|
queryContributionsDecrease = queryContributionsDecrease.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_contributions")
|
|
|
queryContributionsDecrease = queryContributionsDecrease.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) {
|
|
|
queryContributionsDecrease = queryContributionsDecrease.Where("e.company_id = ?", companyId)
|
|
|
}
|
|
|
queryContributionsDecrease = queryContributionsDecrease.Where(`e.status = ?`, 1)
|
|
|
queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.record_type = ?`, 4)
|
|
|
queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
|
|
|
if startTime, ok := queryOptions["startTime"]; ok {
|
|
|
queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time > ?`, startTime)
|
|
|
}
|
...
|
...
|
@@ -454,19 +454,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
// 贡献值子查询
|
|
|
contributionsDecrease := queryContributionsDecrease.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
|
|
|
|
|
|
// 贡献值排行榜
|
|
|
// 减少的贡献值
|
|
|
queryContributions := tx.Model()
|
|
|
queryContributions = queryContributions.With("t", contributionsDecrease)
|
|
|
queryContributions = queryContributions.Table("t")
|
|
|
queryContributions = queryContributions.Table("su_money_transaction_records")
|
|
|
queryContributions = queryContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_records.employee->>'uid')::bigint")
|
|
|
queryContributions = queryContributions.ColumnExpr("su_money_transaction_records.employee->>'uid' AS uid")
|
|
|
queryContributions = queryContributions.ColumnExpr("su_money_transaction_records.employee->>'employeeName' AS employee_name")
|
|
|
queryContributions = queryContributions.ColumnExpr(`(sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease) AS employees_contributions`)
|
|
|
queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC) AS ranking")
|
|
|
queryContributions = queryContributions.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3}))
|
|
|
queryContributions = queryContributions.ColumnExpr("t.uid AS uid")
|
|
|
queryContributions = queryContributions.ColumnExpr("t.employee_name AS employee_name")
|
|
|
queryContributions = queryContributions.ColumnExpr(`t.employee_contributions - sum(su_money_transaction_records.su_money) AS employees_contributions`)
|
|
|
queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY t.employee_contributions - sum(su_money_transaction_records.su_money) DESC) AS ranking")
|
|
|
queryContributions = queryContributions.Where(`su_money_transaction_records.record_type = ?`, 4)
|
|
|
queryContributions = queryContributions.Where(`e.status = ?`, 1)
|
|
|
queryContributions = queryContributions.Where("su_money_transaction_records.employee->>'uid' = t.uid")
|
|
|
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
|
|
queryContributions = queryContributions.Where("e.company_id = ?", companyId)
|
|
|
}
|
...
|
...
|
@@ -476,7 +475,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
if endTime, ok := queryOptions["endTime"]; ok {
|
|
|
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")
|
|
|
queryContributions = queryContributions.GroupExpr("t.uid, t.employee_name, t.employee_contributions")
|
|
|
|
|
|
// 个人贡献值子查询
|
|
|
queryContributionsWith := queryContributions.Order("employees_contributions DESC")
|
...
|
...
|
|