作者 陈志颖

fix:修复个人财富值排名

... ... @@ -456,10 +456,6 @@ func (cashPoolService *CashPoolService) ListExchangeCashActivity(listExchangeCas
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, activity := range activities {
//var timeNow = time.Now()
//var deadline = activity.Deadline
//var t1 = time.Date(timeNow.Year(), timeNow.Month(), timeNow.Day(), 0, 0, 0, 0, time.Local)
//var t2 = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 23, 59, 59, 0, time.Local)
var t1 = time.Now()
var t2 = activity.Deadline
... ...
... ... @@ -105,7 +105,7 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
queryPeople = queryPeople.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name")
queryPeople = queryPeople.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash")
queryPeople = queryPeople.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money")
queryPeople = queryPeople.ColumnExpr("RANK() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC) AS ranking")
queryPeople = queryPeople.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC) AS ranking")
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryPeople = queryPeople.Where("e.company_id = ?", companyId)
}
... ... @@ -130,18 +130,19 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
} else {
queryPeople = queryPeople.Limit(20)
}
//queryPeopleWith := queryPeople.Order("su_money DESC") // 子查询
if err := queryPeople.Order("su_money DESC").Select(&retPeople); err != nil {
return nil, err
}
// 当前员工排名
// 个人排名
queryEmployee := tx.Model(exchangeCashPersonListModels)
queryEmployee = queryEmployee.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid")
queryEmployee = queryEmployee.ColumnExpr("exchange_cash_person_list.uid AS uid")
queryEmployee = queryEmployee.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name")
queryEmployee = queryEmployee.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash")
queryEmployee = queryEmployee.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money")
queryEmployee = queryEmployee.ColumnExpr("RANK() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC) AS ranking")
queryEmployee = queryEmployee.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC) AS ranking")
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryEmployee = queryEmployee.Where("e.company_id = ?", companyId)
}
... ...
... ... @@ -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
}
... ...
... ... @@ -87,16 +87,7 @@ func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]i
if activityNameMatch, ok := queryOptions["activityNameMatch"]; ok && (activityNameMatch != "") {
query = query.Where(`exchange_cash_activity.activity_name LIKE ?`, fmt.Sprintf("%%%s%%", activityNameMatch.(string)))
}
//if deadline, ok := queryOptions["deadline"]; ok && !deadline.(time.Time).IsZero() {
// query = query.Where(`exchange_cash_activity.deadline > ?`, deadline)
//}
if deadline, ok := queryOptions["deadline"]; ok && !deadline.(time.Time).IsZero() {
//var layout string = "2006-01-02"
////deadline, _:= time.Parse(layout, deadlineStr.(string))
//deadline, _:= time.ParseInLocation(layout, deadlineStr.(string), time.Local)
//fmt.Print(deadline, "\n")
//var t = time.Date(deadline.Year(), deadline.Month(), deadline.Day(), 0, 0, 0, 0, time.Local)
//fmt.Print(t, "\n")
query = query.Where(`exchange_cash_activity.deadline >= ?`, deadline)
}
if offset, ok := queryOptions["offset"]; ok {
... ...
... ... @@ -62,9 +62,6 @@ func (repository *ExchangeCashPersonListRepository) FindById(queryOptions map[st
if iDs, ok := queryOptions["iDs"]; ok && len(iDs.([]int)) != 0 {
query = query.Where("exchange_cash_person_list.id IN (?)", pg.In(iDs.([]int)) )
}
//if iDs, ok := queryOptions["iDs"]; ok {
// query = query.Where("exchange_cash_person_list.id IN (?)", pg.In(iDs.([]int)) )
//}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, exchangeCashPeople, err
} else {
... ...