...
|
...
|
@@ -283,6 +283,83 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time. |
|
|
// }, nil
|
|
|
//}
|
|
|
|
|
|
// 排行榜统计
|
|
|
func (dao *EmployeeDao) CalculateEmployeesRankingList(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
|
|
|
var retWealth []struct {
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
|
|
}
|
|
|
var retContributions []struct { // 员工贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
}
|
|
|
var retContributionDecrease []struct { // 员工减少的贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
}
|
|
|
tx := dao.transactionContext.PgTx
|
|
|
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
|
|
|
// 员工财富值
|
|
|
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
|
|
|
ColumnExpr("sum(su_money_transaction_record.su_money) AS employee_su_money").
|
|
|
Where(`e.company_id = ?`, companyId).
|
|
|
Where(`e.status = ?`, 1).
|
|
|
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). // 增加,任务奖励的
|
|
|
Where(`su_money_transaction_record.create_time > ?`, startTime).
|
|
|
Where(`su_money_transaction_record.create_time < ?`, endTime).
|
|
|
Group("su_money_transaction_record.employee").
|
|
|
Order("employee_su_money DESC").
|
|
|
Select(&retWealth); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 增加的贡献值
|
|
|
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
|
|
|
ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").
|
|
|
Where(`e.company_id = ?`, companyId).
|
|
|
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
|
|
|
Where(`e.status = ?`, 1).
|
|
|
Where(`su_money_transaction_record.create_time > ?`, startTime).
|
|
|
Where(`su_money_transaction_record.create_time < ?`, endTime).
|
|
|
Group("su_money_transaction_record.employee").
|
|
|
Order("employees_contributions DESC").
|
|
|
Select(&retContributions); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
// 减少的贡献值
|
|
|
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid").
|
|
|
ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name").
|
|
|
ColumnExpr("sum(su_money_transaction_record.su_money) AS employees_contributions").
|
|
|
Where(`e.company_id = ?`, companyId).
|
|
|
Where(`su_money_transaction_record.record_type = ?`, 4).
|
|
|
Where(`e.status = ?`, 1).
|
|
|
Where(`su_money_transaction_record.create_time > ?`, startTime).
|
|
|
Where(`su_money_transaction_record.create_time < ?`, endTime).
|
|
|
Group("su_money_transaction_record.employee").
|
|
|
Order("employees_contributions DESC").
|
|
|
Select(&retContributionDecrease); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
for i := 0; i < len(retContributions); i++ {
|
|
|
for j := 0; j < len(retContributionDecrease); j++ {
|
|
|
if retContributions[i].Uid == retContributionDecrease[j].Uid {
|
|
|
retContributions[i].EmployeesContributions -= retContributionDecrease[j].EmployeesContributions
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return map[string]interface{}{
|
|
|
"employeesContributions": retContributions,
|
|
|
"employeesWealth": retWealth,
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
// 员工贡献值统计
|
|
|
func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime time.Time, endTime time.Time) (map[string]interface{}, error) {
|
|
|
var ret []struct { // 员工贡献值
|
...
|
...
|
|