...
|
...
|
@@ -349,14 +349,14 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
}
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
|
|
|
|
|
// 财富值榜单
|
|
|
queryWealth := tx.Model(suMoneyTransactionRecordModel)
|
|
|
queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
|
|
|
queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
|
|
|
queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
|
|
|
queryWealth = queryWealth.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money")
|
|
|
queryWealth = queryWealth.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC, su_money_transaction_record.create_time) AS ranking")
|
|
|
//queryWealth = queryWealth.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC, su_money_transaction_record.create_time) AS ranking")
|
|
|
queryWealth = queryWealth.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
|
|
|
queryWealth = queryWealth.Where(`e.status = ?`, 1)
|
|
|
queryWealth = queryWealth.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
|
|
|
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
...
|
...
|
@@ -368,8 +368,12 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
if endTime, ok := queryOptions["endTime"]; ok {
|
|
|
queryWealth = queryWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
|
|
}
|
|
|
queryWealth = queryWealth.Group("su_money_transaction_record.employee")
|
|
|
queryWealth = queryWealth.Group("su_money_transaction_record.create_time")
|
|
|
//queryWealth = queryWealth.Group("su_money_transaction_record.employee")
|
|
|
//queryWealth = queryWealth.Group("su_money_transaction_record.employee #>> '{uid}'")
|
|
|
|
|
|
queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
|
|
|
//queryWealth = queryWealth.Group("su_money_transaction_record.create_time")
|
|
|
//queryWealth = queryWealth.Group(`su_money_transaction_record->'employee'->>'employeeName'`)
|
|
|
if offset, ok := queryOptions["offset"]; ok {
|
|
|
offset := offset.(int)
|
|
|
if offset > -1 {
|
...
|
...
|
@@ -396,7 +400,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
|
|
|
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
|
|
|
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money")
|
|
|
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC, su_money_transaction_record.create_time) AS ranking")
|
|
|
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Where(`e.status = ?`, 1)
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
|
|
|
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
...
|
...
|
@@ -408,8 +412,10 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
if endTime, ok := queryOptions["endTime"]; ok {
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
|
|
}
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Group("su_money_transaction_record.employee")
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Group("su_money_transaction_record.create_time")
|
|
|
//queryEmployeeWealth = queryEmployeeWealth.Group("su_money_transaction_record.employee")
|
|
|
//queryEmployeeWealth = queryEmployeeWealth.Group("su_money_transaction_record.employee #>> '{uid}' ")
|
|
|
//queryEmployeeWealth = queryEmployeeWealth.Group("su_money_transaction_record.create_time")
|
|
|
queryEmployeeWealth = queryEmployeeWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
|
|
|
if uid, ok := queryOptions["uid"]; ok {
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid)
|
|
|
}
|
...
|
...
|
@@ -423,13 +429,13 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
retCurrentEmployeeWealth = retEmployeeWealth[0]
|
|
|
}
|
|
|
|
|
|
// 贡献值榜单
|
|
|
// 贡献值榜单-减少的贡献致富
|
|
|
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("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC, su_money_transaction_record.create_time) AS ranking")
|
|
|
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)
|
|
|
}
|
...
|
...
|
@@ -441,8 +447,11 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
if endTime, ok := queryOptions["endTime"]; ok {
|
|
|
queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
|
|
}
|
|
|
contributionsDecrease := queryContributionsDecrease.Group("su_money_transaction_record.employee").Group("su_money_transaction_record.create_time")
|
|
|
//contributionsDecrease := queryContributionsDecrease.Group("su_money_transaction_record.employee").Group("su_money_transaction_record.create_time")
|
|
|
//contributionsDecrease := queryContributionsDecrease.Group("su_money_transaction_record.employee #>> '{uid}'").Group("su_money_transaction_record.create_time")
|
|
|
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")
|
...
|
...
|
@@ -451,7 +460,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
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("RANK() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC,su_money_transaction_records.create_time) AS ranking")
|
|
|
queryContributions = queryContributions.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) {
|
|
|
queryContributions = queryContributions.Where("e.company_id = ?", companyId)
|
|
|
}
|
...
|
...
|
@@ -463,9 +472,11 @@ 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.Group("su_money_transaction_records.employee")
|
|
|
queryContributions = queryContributions.Group("t.employee_contributions_decrease")
|
|
|
queryContributions = queryContributions.Group("su_money_transaction_records.create_time")
|
|
|
//queryContributions = queryContributions.Group("su_money_transaction_records.employee")
|
|
|
//queryContributions = queryContributions.Group("su_money_transaction_records.employee #>> '{uid}'")
|
|
|
//queryContributions = queryContributions.Group("t.employee_contributions_decrease")
|
|
|
//queryContributions = queryContributions.Group("su_money_transaction_records.create_time")
|
|
|
queryContributions = queryContributions.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',t.employee_contributions_decrease")
|
|
|
if offset, ok := queryOptions["offset"]; ok {
|
|
|
offset := offset.(int)
|
|
|
if offset > -1 {
|
...
|
...
|
@@ -486,13 +497,13 @@ 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("RANK() OVER (ORDER BY sum(su_money_transaction_record.su_money) DESC) AS ranking")
|
|
|
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)
|
|
|
}
|
...
|
...
|
@@ -504,8 +515,10 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
if endTime, ok := queryOptions["endTime"]; ok {
|
|
|
queryEmployeeContributionsDecrease = queryEmployeeContributionsDecrease.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
|
|
}
|
|
|
employeeContributionsDecrease := queryEmployeeContributionsDecrease.Group("su_money_transaction_record.employee")
|
|
|
//employeeContributionsDecrease := queryEmployeeContributionsDecrease.Group("su_money_transaction_record.employee")
|
|
|
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.Table("t")
|
...
|
...
|
@@ -514,7 +527,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
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("RANK() OVER (ORDER BY sum(su_money_transaction_records.su_money) - t.employee_contributions_decrease DESC) AS ranking")
|
|
|
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)
|
|
|
}
|
...
|
...
|
@@ -529,8 +542,9 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
if uid, ok := queryOptions["uid"]; ok {
|
|
|
queryEmployeeContributions = queryEmployeeContributions.Where(`su_money_transaction_records.employee @> '{"uid":?}'`, uid)
|
|
|
}
|
|
|
queryEmployeeContributions = queryEmployeeContributions.Group("su_money_transaction_records.employee")
|
|
|
queryEmployeeContributions = queryEmployeeContributions.Group("t.employee_contributions_decrease")
|
|
|
//queryEmployeeContributions = queryEmployeeContributions.Group("su_money_transaction_records.employee")
|
|
|
queryEmployeeContributions = queryEmployeeContributions.GroupExpr("su_money_transaction_records.employee->>'uid',su_money_transaction_records.employee->>'employeeName',t.employee_contributions_decrease")
|
|
|
//queryEmployeeContributions = queryEmployeeContributions.Group("t.employee_contributions_decrease")
|
|
|
if err := queryEmployeeContributions.Order("employees_contributions DESC").Select(&retEmployeeContributions); err != nil {
|
|
|
return nil, err
|
|
|
}
|
...
|
...
|
|