...
|
...
|
@@ -283,7 +283,7 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. |
|
|
// }, nil
|
|
|
//}
|
|
|
|
|
|
// TODO 贡献值、财富值排行榜
|
|
|
// 贡献值、财富值排行榜
|
|
|
func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
var retWealth []struct {
|
|
|
Uid int
|
...
|
...
|
@@ -291,12 +291,24 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
EmployeeSuMoney float64
|
|
|
Ranking int
|
|
|
}
|
|
|
var retEmployeeWealth []struct {
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
|
|
Ranking int
|
|
|
}
|
|
|
var retContributions []struct { // 员工贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
Ranking int
|
|
|
}
|
|
|
var retEmployeeContributions []struct { // 员工贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
Ranking int
|
|
|
}
|
|
|
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
...
|
...
|
@@ -341,8 +353,32 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
}
|
|
|
|
|
|
// 当前员工财富值排名
|
|
|
queryEmployeeWealth := tx.Model(suMoneyTransactionRecordModel)
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
|
|
|
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) 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) {
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Where("e.company_id = ?", companyId)
|
|
|
}
|
|
|
if startTime, ok := queryOptions["startTime"]; ok {
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Where(`su_money_transaction_record.create_time > ?`, startTime)
|
|
|
}
|
|
|
if endTime, ok := queryOptions["endTime"]; ok {
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
|
|
}
|
|
|
if uid, ok := queryOptions["uid"]; ok {
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid)
|
|
|
}
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Group("su_money_transaction_record.employee")
|
|
|
if err := queryEmployeeWealth.Order("employee_su_money DESC").Select(&retEmployeeWealth); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 扣除的贡献值子查询
|
|
|
// 贡献值排名
|
|
|
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")
|
...
|
...
|
@@ -380,7 +416,6 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
//}
|
|
|
//contributionsDecrease := queryWealth.Order("employee_contributions_decrease DESC")
|
|
|
|
|
|
// 贡献值排名
|
|
|
queryContributions := tx.Model()
|
|
|
queryContributions = queryContributions.With("t", contributionsDecrease)
|
|
|
queryContributions = queryContributions.Table("t")
|
...
|
...
|
@@ -424,14 +459,63 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
}
|
|
|
|
|
|
// 当前员工贡献值排名
|
|
|
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")
|
|
|
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.Group("su_money_transaction_record.employee")
|
|
|
|
|
|
queryEmployeeContributions := tx.Model()
|
|
|
queryEmployeeContributions = queryEmployeeContributions.With("t", employeeContributionsDecrease)
|
|
|
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("RANK() 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)
|
|
|
}
|
|
|
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")
|
|
|
if err := queryEmployeeContributions.Order("employees_contributions DESC").Select(&retEmployeeContributions); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"employeesWealth": retWealth,
|
|
|
"employeesContributions": retContributions,
|
|
|
"currentEmployeeContributions": retEmployeeContributions,
|
|
|
"currentEmployeeWealth": retEmployeeWealth,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 排行榜统计,排名
|
|
|
// 排行榜统计,排名(弃用)
|
|
|
func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time, offset int, limit int) (map[string]interface{}, error) {
|
|
|
var retWealth []struct {
|
|
|
Uid int
|
...
|
...
|
|