...
|
...
|
@@ -102,7 +102,6 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ |
|
|
if err := tx.Model(suMoneyTransactionRecordModel).
|
|
|
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
|
|
|
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
|
|
|
//Where(`su_money_transaction_record.record_type = ?`, 2).
|
|
|
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
|
|
|
Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
|
|
|
Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
|
...
|
...
|
@@ -113,7 +112,6 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ |
|
|
if err := tx.Model(suMoneyTransactionRecordModel).
|
|
|
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
|
|
|
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
|
|
|
//Where(`su_money_transaction_record.record_type = ?`, 2).
|
|
|
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})).
|
|
|
Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
|
|
|
Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
|
...
|
...
|
@@ -124,7 +122,6 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ |
|
|
if err := tx.Model(suMoneyTransactionRecordModel).
|
|
|
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
|
|
|
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
|
|
|
//Where(`su_money_transaction_record.record_type = ?`, 2).
|
|
|
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})).
|
|
|
Select(&incomeSuMoney); err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -133,7 +130,6 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ |
|
|
if err := tx.Model(suMoneyTransactionRecordModel).
|
|
|
ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
|
|
|
Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
|
|
|
//Where(`su_money_transaction_record.record_type = ?`, 2).
|
|
|
Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})).
|
|
|
Select(&expendSuMoney); err != nil {
|
|
|
return nil, err
|
...
|
...
|
@@ -323,13 +319,13 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans |
|
|
|
|
|
// 贡献值、财富值总榜和年榜,
|
|
|
func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
var retWealth []struct {
|
|
|
var retWealth []struct { // 个人财富值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
|
|
Ranking int
|
|
|
}
|
|
|
var retEmployeeWealth []struct {
|
|
|
var retEmployeeWealth []struct { // 个人贡献值
|
|
|
Uid int
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
...
|
...
|
@@ -349,13 +345,13 @@ 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("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}))
|
...
|
...
|
@@ -368,12 +364,8 @@ 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.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'`)
|
|
|
queryWealthWith := queryWealth.Order("employee_su_money DESC") // 个人财富值子查询
|
|
|
if offset, ok := queryOptions["offset"]; ok {
|
|
|
offset := offset.(int)
|
|
|
if offset > -1 {
|
...
|
...
|
@@ -390,36 +382,23 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
} else {
|
|
|
queryWealth = queryWealth.Limit(20)
|
|
|
}
|
|
|
if err := queryWealth.Order("employee_su_money DESC").Select(&retWealth); err != nil {
|
|
|
queryWealth = queryWealth.Order("employee_su_money DESC")
|
|
|
if err := queryWealth.Select(&retWealth); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// 当前员工财富值排名
|
|
|
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("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) {
|
|
|
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)
|
|
|
}
|
|
|
//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'")
|
|
|
// 个人财富值排名
|
|
|
queryEmployeeWealth := tx.Model()
|
|
|
queryEmployeeWealth = queryEmployeeWealth.With("t", queryWealthWith)
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Table("t")
|
|
|
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("t.uid AS uid")
|
|
|
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("t.employee_name AS employee_name")
|
|
|
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("t.employee_su_money AS employee_su_money")
|
|
|
queryEmployeeWealth = queryEmployeeWealth.ColumnExpr("t.ranking AS ranking")
|
|
|
if uid, ok := queryOptions["uid"]; ok {
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid)
|
|
|
queryEmployeeWealth = queryEmployeeWealth.Where("t.uid::bigint = ?", uid)
|
|
|
}
|
|
|
if err := queryEmployeeWealth.Order("employee_su_money DESC").Select(&retEmployeeWealth); err != nil {
|
|
|
if err := queryEmployeeWealth.Select(&retEmployeeWealth); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
var retCurrentEmployeeWealth interface{}
|
...
|
...
|
@@ -429,7 +408,7 @@ 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")
|
...
|
...
|
@@ -447,8 +426,6 @@ 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 #>> '{uid}'").Group("su_money_transaction_record.create_time")
|
|
|
contributionsDecrease := queryContributionsDecrease.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
|
|
|
|
|
|
// 贡献值排行榜
|
...
|
...
|
@@ -472,11 +449,8 @@ 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("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")
|
|
|
//queryContributionsWith := queryContributions.Order("employees_contributions DESC") // 个人贡献值子查询
|
|
|
if offset, ok := queryOptions["offset"]; ok {
|
|
|
offset := offset.(int)
|
|
|
if offset > -1 {
|
...
|
...
|
@@ -497,7 +471,7 @@ 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")
|
...
|
...
|
@@ -515,10 +489,9 @@ 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.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")
|
...
|
...
|
@@ -542,9 +515,7 @@ 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.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
|
|
|
}
|
...
|
...
|
|