...
|
...
|
@@ -309,25 +309,25 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans |
|
|
// 贡献值、财富值总榜和年榜,
|
|
|
func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
|
|
|
var retWealth []struct { // 个人财富值
|
|
|
Uid int
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
|
|
Ranking int
|
|
|
}
|
|
|
var retEmployeeWealth []struct { // 个人贡献值
|
|
|
Uid int
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
EmployeeSuMoney float64
|
|
|
Ranking int
|
|
|
}
|
|
|
var retContributions []struct { // 员工贡献值
|
|
|
Uid int
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
Ranking int
|
|
|
}
|
|
|
var retEmployeeContributions []struct { // 员工贡献值
|
|
|
Uid int
|
|
|
Uid int64
|
|
|
EmployeeName string
|
|
|
EmployeesContributions float64
|
|
|
Ranking int
|
...
|
...
|
@@ -342,7 +342,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
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(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), e.create_time DESC) AS ranking")
|
|
|
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'")
|
|
|
queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid'")
|
...
|
...
|
@@ -371,7 +371,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
} else {
|
|
|
queryWealth = queryWealth.Limit(20)
|
|
|
}
|
|
|
queryWealth = queryWealth.Order("employee_su_money DESC")
|
|
|
queryWealth = queryWealth.Order("ranking ASC")
|
|
|
if err := queryWealth.Select(&retWealth); err != nil {
|
|
|
return nil, err
|
|
|
}
|
...
|
...
|
@@ -380,9 +380,9 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
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("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), e.create_time DESC) AS ranking")
|
|
|
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)
|
...
|
...
|
@@ -393,12 +393,13 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
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'")
|
|
|
//queryWealthRestoreWith := queryWealthWith.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName', e.create_time")
|
|
|
queryWealthRestoreWith := queryWealthWith.GroupExpr("su_money_transaction_record.employee->>'uid'")
|
|
|
querySelfWealth := tx.Model()
|
|
|
querySelfWealth = querySelfWealth.With("t", queryWealthRestoreWith)
|
|
|
querySelfWealth = querySelfWealth.Table("t")
|
|
|
querySelfWealth = querySelfWealth.ColumnExpr("t.uid AS uid")
|
|
|
querySelfWealth = querySelfWealth.ColumnExpr("t.employee_name AS employee_name")
|
|
|
//querySelfWealth = querySelfWealth.ColumnExpr("t.employee_name AS employee_name")
|
|
|
querySelfWealth = querySelfWealth.ColumnExpr("t.employee_su_money AS employee_su_money")
|
|
|
querySelfWealth = querySelfWealth.ColumnExpr("t.ranking AS ranking")
|
|
|
if uid, ok := queryOptions["uid"]; ok {
|
...
|
...
|
@@ -420,7 +421,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
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), e.create_time DESC) AS ranking")
|
|
|
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(`e.status = ?`, 1)
|
|
|
//queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
|
|
|
queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid'")
|
...
|
...
|
@@ -449,7 +450,7 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
} else {
|
|
|
queryContributions = queryContributions.Limit(20)
|
|
|
}
|
|
|
if err := queryContributions.Order("employees_contributions DESC").Select(&retContributions); err != nil {
|
|
|
if err := queryContributions.Order("ranking ASC").Select(&retContributions); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
...
|
...
|
@@ -457,9 +458,9 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
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("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), e.create_time AS ranking")
|
|
|
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(`e.status = ?`, 1)
|
|
|
if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
|
|
|
queryContributionsWith = queryContributionsWith.Where("e.company_id = ?", companyId)
|
...
|
...
|
@@ -470,12 +471,13 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter |
|
|
if endTime, ok := queryOptions["endTime"]; ok && !endTime.(time.Time).IsZero() {
|
|
|
queryContributionsWith = queryContributionsWith.Where(`su_money_transaction_record.create_time < ?`, endTime)
|
|
|
}
|
|
|
contributionsWith := queryContributionsWith.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
|
|
|
//contributionsWith := queryContributionsWith.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName', e.create_time")
|
|
|
contributionsWith := queryContributionsWith.GroupExpr("su_money_transaction_record.employee->>'uid'")
|
|
|
querySelfContributions := tx.Model()
|
|
|
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")
|
|
|
//querySelfContributions = querySelfContributions.ColumnExpr("t.employee_name AS employee_name")
|
|
|
querySelfContributions = querySelfContributions.ColumnExpr("t.employees_contributions AS employees_contributions")
|
|
|
querySelfContributions = querySelfContributions.ColumnExpr("t.ranking AS ranking")
|
|
|
if uid, ok := queryOptions["uid"]; ok {
|
...
|
...
|
|