作者 陈志颖

fix:财富值、贡献值排行版

... ... @@ -425,8 +425,8 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
listListIntervalQuery := map[string]interface{} {
"companyId": contributionsWealthRankingQuery.CompanyId,
"offset": 0,
"limit": 1,
//"offset": 0,
//"limit": 1,
}
if _, listIntervals, err := listIntervalRepository.Find(listListIntervalQuery); err != nil {
... ...
... ... @@ -328,6 +328,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
}
tx := dao.transactionContext.PgTx
suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
// 财富值排行榜
... ... @@ -338,6 +339,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
queryWealth = queryWealth.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) AS employee_su_money")
queryWealth = queryWealth.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) DESC) AS ranking")
queryWealth = queryWealth.Where(`e.status = ?`, 1)
queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryWealth = queryWealth.Where("e.company_id = ?", companyId)
}
... ... @@ -347,8 +349,6 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
queryWealth = queryWealth.Where(`su_money_transaction_record.create_time < ?`, endTime)
}
// 财富值排行榜子查询
queryWealthRestoreWith := queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
... ... @@ -369,7 +369,25 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if err := queryWealth.Select(&retWealth); err != nil {
return nil, err
}
// 个人财富值排名
queryWealthWith := tx.Model(suMoneyTransactionRecordModel)
queryWealthWith = queryWealthWith.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
queryWealthWith = queryWealthWith.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
queryWealthWith = queryWealthWith.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
queryWealthWith = queryWealthWith.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) AS employee_su_money")
queryWealthWith = queryWealthWith.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3, 6) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type IN (4, 1, 5) THEN su_money_transaction_record.su_money ELSE 0 end) DESC) AS ranking")
queryWealthWith = queryWealthWith.Where(`e.status = ?`, 1)
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryWealthWith = queryWealthWith.Where("e.company_id = ?", companyId)
}
if startTime, ok := queryOptions["startTime"]; ok && !startTime.(time.Time).IsZero() {
queryWealthWith = queryWealthWith.Where(`su_money_transaction_record.create_time > ?`, startTime)
}
if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
queryWealthWith = queryWealthWith.Where(`su_money_transaction_record.create_time < ?`, endTime)
}
queryWealthRestoreWith := queryWealthWith.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
querySelfWealth := tx.Model()
querySelfWealth = querySelfWealth.With("t", queryWealthRestoreWith)
querySelfWealth = querySelfWealth.Table("t")
... ... @@ -383,7 +401,6 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if err := querySelfWealth.Select(&retEmployeeWealth); err != nil {
return nil, err
}
var retCurrentEmployeeWealth interface{}
if len(retEmployeeWealth) == 0 {
retCurrentEmployeeWealth = nil
... ... @@ -391,14 +408,14 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
retCurrentEmployeeWealth = retEmployeeWealth[0]
}
// 贡献值
// 贡献值排行榜
queryContributions := tx.Model(suMoneyTransactionRecordModel)
queryContributions = queryContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
queryContributions = queryContributions.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) AS employees_contributions")
queryContributions = queryContributions.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) DESC) AS ranking")
queryContributions = queryContributions.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
//queryContributions = queryContributions.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
queryContributions = queryContributions.Where(`e.status = ?`, 1)
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryContributions = queryContributions.Where("e.company_id = ?", companyId)
... ... @@ -409,8 +426,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
queryContributions = queryContributions.Where(`su_money_transaction_record.create_time < ?`, endTime)
}
// 贡献值子查询
contributions := queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
... ... @@ -430,9 +446,28 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if err := queryContributions.Order("employees_contributions DESC").Select(&retContributions); err != nil {
return nil, err
}
// 个人贡献值
// 个人贡献值排名
queryContributionsWith := tx.Model(suMoneyTransactionRecordModel)
queryContributionsWith = queryContributionsWith.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
queryContributionsWith = queryContributionsWith.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
queryContributionsWith = queryContributionsWith.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
queryContributionsWith = queryContributionsWith.ColumnExpr("sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) AS employees_contributions")
queryContributionsWith = queryContributionsWith.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(case WHEN su_money_transaction_record.record_type IN (2, 3) THEN su_money_transaction_record.su_money ELSE 0 end) - sum(case WHEN su_money_transaction_record.record_type = 4 THEN su_money_transaction_record.su_money ELSE 0 end) DESC) AS ranking")
//queryContributionsWith = queryContributionsWith.Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3}))
queryContributionsWith = queryContributionsWith.Where(`e.status = ?`, 1)
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
queryContributionsWith = queryContributionsWith.Where("e.company_id = ?", companyId)
}
if startTime, ok := queryOptions["startTime"]; ok && !startTime.(time.Time).IsZero() {
queryContributionsWith = queryContributionsWith.Where(`su_money_transaction_record.create_time > ?`, startTime)
}
if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
queryContributionsWith = queryContributionsWith.Where(`su_money_transaction_record.create_time < ?`, endTime)
}
contributionsWith := queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
querySelfContributions := tx.Model()
querySelfContributions = querySelfContributions.With("t", contributions)
querySelfContributions = querySelfContributions.With("t", contributionsWith)
querySelfContributions = querySelfContributions.Table("t")
querySelfContributions = querySelfContributions.ColumnExpr("t.uid AS uid")
querySelfContributions = querySelfContributions.ColumnExpr("t.employee_name AS employee_name")
... ...