...
|
...
|
@@ -283,22 +283,173 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. |
|
|
// }, nil
|
|
|
//}
|
|
|
|
|
|
// TODO 排行榜统计,排名
|
|
|
// TODO 贡献值、财富值排行榜
|
|
|
func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
var retWealth []struct {
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
|
|
Ranking int
|
|
|
}
|
|
|
var retContributions []struct { // 员工贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
Ranking int
|
|
|
}
|
|
|
|
|
|
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) 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) {
|
|
|
queryWealth = queryWealth.Where("e.company_id = ?", companyId)
|
|
|
}
|
|
|
if startTime, ok := queryOptions["startTime"]; ok {
|
|
|
queryWealth = queryWealth.Where(`su_money_transaction_record.create_time > ?`, startTime)
|
|
|
}
|
|
|
if endTime, ok := queryOptions["endTime"]; ok {
|
|
|
queryWealth = queryWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
|
|
}
|
|
|
queryWealth = queryWealth.Group("su_money_transaction_record.employee")
|
|
|
if offset, ok := queryOptions["offset"]; ok {
|
|
|
offset := offset.(int)
|
|
|
if offset > -1 {
|
|
|
queryWealth = queryWealth.Offset(offset)
|
|
|
}
|
|
|
} else {
|
|
|
queryWealth = queryWealth.Offset(0)
|
|
|
}
|
|
|
if limit, ok := queryOptions["limit"]; ok {
|
|
|
limit := limit.(int)
|
|
|
if limit > -1 {
|
|
|
queryWealth = queryWealth.Limit(limit)
|
|
|
}
|
|
|
} else {
|
|
|
queryWealth = queryWealth.Limit(20)
|
|
|
}
|
|
|
if err := queryWealth.Order("employee_su_money DESC").Select(&retWealth); 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")
|
|
|
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) 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)
|
|
|
if startTime, ok := queryOptions["startTime"]; ok {
|
|
|
queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time > ?`, startTime)
|
|
|
}
|
|
|
if endTime, ok := queryOptions["endTime"]; ok {
|
|
|
queryContributionsDecrease = queryContributionsDecrease.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
|
|
}
|
|
|
contributionsDecrease := queryContributionsDecrease.Group("su_money_transaction_record.employee")
|
|
|
|
|
|
//if offset, ok := queryOptions["offset"]; ok {
|
|
|
// offset := offset.(int)
|
|
|
// if offset > -1 {
|
|
|
// queryContributionsDecrease = queryContributionsDecrease.Offset(offset)
|
|
|
// }
|
|
|
//} else {
|
|
|
// queryContributionsDecrease = queryContributionsDecrease.Offset(0)
|
|
|
//}
|
|
|
//if limit, ok := queryOptions["limit"]; ok {
|
|
|
// limit := limit.(int)
|
|
|
// if limit > -1 {
|
|
|
// queryContributionsDecrease = queryContributionsDecrease.Limit(limit)
|
|
|
// }
|
|
|
//} else {
|
|
|
// queryContributionsDecrease = queryContributionsDecrease.Limit(20)
|
|
|
//}
|
|
|
//contributionsDecrease := queryWealth.Order("employee_contributions_decrease DESC")
|
|
|
|
|
|
// 贡献值排名
|
|
|
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("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) {
|
|
|
queryContributions = queryContributions.Where("e.company_id = ?", companyId)
|
|
|
}
|
|
|
queryContributions = queryContributions.Where(`e.status = ?`, 1)
|
|
|
queryContributions = queryContributions.Where(`su_money_transaction_records.record_type IN (?)`, pg.In([]int{2, 3}))
|
|
|
if startTime, ok := queryOptions["startTime"]; ok {
|
|
|
queryContributions = queryContributions.Where(`su_money_transaction_records.create_time > ?`, startTime)
|
|
|
}
|
|
|
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")
|
|
|
if offset, ok := queryOptions["offset"]; ok {
|
|
|
offset := offset.(int)
|
|
|
if offset > -1 {
|
|
|
queryContributions = queryContributions.Offset(offset)
|
|
|
}
|
|
|
} else {
|
|
|
queryContributions = queryContributions.Offset(0)
|
|
|
}
|
|
|
if limit, ok := queryOptions["limit"]; ok {
|
|
|
limit := limit.(int)
|
|
|
if limit > -1 {
|
|
|
queryContributions = queryContributions.Limit(limit)
|
|
|
}
|
|
|
} else {
|
|
|
queryContributions = queryContributions.Limit(20)
|
|
|
}
|
|
|
if err := queryContributions.Order("employees_contributions DESC").Select(&retContributions); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 当前员工贡献值排名
|
|
|
|
|
|
return map[string]interface{}{
|
|
|
"employeesWealth": retWealth,
|
|
|
"employeesContributions": retContributions,
|
|
|
}, 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
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
|
|
Ranking int
|
|
|
}
|
|
|
var retContributions []struct { // 员工贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
Ranking int
|
|
|
}
|
|
|
var retContributionDecrease []struct { // 员工减少的贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
Ranking int
|
|
|
}
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
...
|
...
|
|