作者 陈志颖

fix:修复员工贡献值统计

... ... @@ -249,29 +249,31 @@ func (dao *EmployeeDao) CalculateEmployeesContributions(companyId int, startTime
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// 增加的贡献值
if err := tx.Model(suMoneyTransactionRecordModel).Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint").
//Column("su_money_transaction_record.employee").
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid, su_money_transaction_record.employee->>'employeeName' AS employeeName, sum(su_money_transaction_record.su_money) AS employees_contributions_increase").
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_increase DESC").
Order("employees_contributions DESC").
Select(&ret); 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").
//Column("su_money_transaction_record.employee").
ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid, su_money_transaction_record.employee->>'employeeName' AS employeeName, sum(su_money_transaction_record.su_money) AS employees_contributions_decrease").
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_decrease DESC").
Order("employees_contributions DESC").
Select(&retDecrease); err != nil {
return nil, err
}
... ...