作者 陈志颖

fix:个人素币收支

@@ -309,6 +309,7 @@ func (statisticsService *StatisticsService) EmployeesSuMoneyStatistics(employees @@ -309,6 +309,7 @@ func (statisticsService *StatisticsService) EmployeesSuMoneyStatistics(employees
309 if err := employeesSuMoneyStatisticsCommand.ValidateCommand(); err != nil { 309 if err := employeesSuMoneyStatisticsCommand.ValidateCommand(); err != nil {
310 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 310 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
311 } 311 }
  312 +
312 transactionContext, err := factory.CreateTransactionContext(nil) 313 transactionContext, err := factory.CreateTransactionContext(nil)
313 if err != nil { 314 if err != nil {
314 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 315 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -389,6 +390,7 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut @@ -389,6 +390,7 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
389 if err := contributionsWealthRankingQuery.ValidateQuery(); err != nil { 390 if err := contributionsWealthRankingQuery.ValidateQuery(); err != nil {
390 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 391 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
391 } 392 }
  393 +
392 transactionContext, err := factory.CreateTransactionContext(nil) 394 transactionContext, err := factory.CreateTransactionContext(nil)
393 if err != nil { 395 if err != nil {
394 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 396 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -400,6 +402,17 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut @@ -400,6 +402,17 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
400 transactionContext.RollbackTransaction() 402 transactionContext.RollbackTransaction()
401 }() 403 }()
402 404
  405 + // 员工仓储初始化
  406 + var employeeRepository domain.EmployeeRepository
  407 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  408 + "transactionContext": transactionContext,
  409 + }); err != nil {
  410 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  411 + } else {
  412 + employeeRepository = value
  413 + }
  414 +
  415 + // 员工DAO初始化
403 var employeeDao *dao.EmployeeDao 416 var employeeDao *dao.EmployeeDao
404 if value, err := factory.CreateEmployeeDao(map[string]interface{}{ 417 if value, err := factory.CreateEmployeeDao(map[string]interface{}{
405 "transactionContext": transactionContext, 418 "transactionContext": transactionContext,
@@ -425,8 +438,6 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut @@ -425,8 +438,6 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
425 438
426 listListIntervalQuery := map[string]interface{} { 439 listListIntervalQuery := map[string]interface{} {
427 "companyId": contributionsWealthRankingQuery.CompanyId, 440 "companyId": contributionsWealthRankingQuery.CompanyId,
428 - //"offset": 0,  
429 - //"limit": 1,  
430 } 441 }
431 442
432 if _, listIntervals, err := listIntervalRepository.Find(listListIntervalQuery); err != nil { 443 if _, listIntervals, err := listIntervalRepository.Find(listListIntervalQuery); err != nil {
@@ -444,8 +455,7 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut @@ -444,8 +455,7 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
444 contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local) 455 contributionsWealthRankingQuery.StartTime = time.Date(0001, 01, 02, 0, 0, 0, 0, time.Local)
445 contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 23, 59, 59, 0, time.Local) 456 contributionsWealthRankingQuery.EndTime = time.Date(0001, 01, 02, 23, 59, 59, 0, time.Local)
446 } 457 }
447 - } else { // 配置了多个年榜  
448 - // 判断当前时间是否在榜单里 458 + } else { // 配置了多个年榜,判断当前时间是否在榜单里
449 currentTime := time.Now().Local() 459 currentTime := time.Now().Local()
450 for _, listInterval := range listIntervals { 460 for _, listInterval := range listIntervals {
451 if currentTime.After(listInterval.IntervalStartTime.Local()) && currentTime.Before(listInterval.IntervalEndTime.Local()) || currentTime.Equal(listInterval.IntervalStartTime.Local()) || currentTime.Equal(listInterval.IntervalEndTime.Local()) { // 当前时间在榜单内 461 if currentTime.After(listInterval.IntervalStartTime.Local()) && currentTime.Before(listInterval.IntervalEndTime.Local()) || currentTime.Equal(listInterval.IntervalStartTime.Local()) || currentTime.Equal(listInterval.IntervalEndTime.Local()) { // 当前时间在榜单内
@@ -469,6 +479,21 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut @@ -469,6 +479,21 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
469 if err := transactionContext.CommitTransaction(); err != nil { 479 if err := transactionContext.CommitTransaction(); err != nil {
470 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 480 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
471 } 481 }
  482 +
  483 + // TODO 排行榜姓名获取
  484 + //if count, employees, err := employeeRepository.Find(map[string]interface{}{
  485 + // "companyId": contributionsWealthRankingQuery.CompanyId,
  486 + // "offset": contributionsWealthRankingQuery.Offset,
  487 + // "limit": contributionsWealthRankingQuery.Limit,
  488 + //}); err != nil {
  489 + // return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  490 + //}
  491 + // 财富值排行榜
  492 +
  493 +
  494 + // 贡献值排行版
  495 +
  496 +
472 return contributionsWealthRankingStatistics, nil 497 return contributionsWealthRankingStatistics, nil
473 } 498 }
474 } 499 }
@@ -234,7 +234,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -234,7 +234,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
234 if err := tx.Model(suMoneyTransactionRecordModel). 234 if err := tx.Model(suMoneyTransactionRecordModel).
235 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money"). 235 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
236 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 236 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
237 - Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4, 5})). 237 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{1, 4})).
238 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime). 238 Where(`su_money_transaction_record.create_time > ?`, transactionStartTime).
239 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime). 239 Where(`su_money_transaction_record.create_time < ?`, transactionEndTime).
240 Select(&expendSuMoney); err != nil { 240 Select(&expendSuMoney); err != nil {
@@ -261,8 +261,8 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -261,8 +261,8 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
261 return nil, err 261 return nil, err
262 } 262 }
263 return map[string]interface{}{ 263 return map[string]interface{}{
264 - "incomeSuMoney": incomeSuMoney + incomeSuMoneyExchangeRestore, // 个人素币收入  
265 - "expendSuMoney": expendSuMoney, // 个人素币支出 264 + "incomeSuMoney": incomeSuMoney, // 个人素币收入
  265 + "expendSuMoney": expendSuMoney + (expendSuMoneyExchange - incomeSuMoneyExchangeRestore), // 个人素币支出
266 }, nil 266 }, nil
267 } 267 }
268 268
@@ -340,11 +340,12 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -340,11 +340,12 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
340 queryWealth := tx.Model(suMoneyTransactionRecordModel) 340 queryWealth := tx.Model(suMoneyTransactionRecordModel)
341 queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint") 341 queryWealth = queryWealth.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
342 queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid") 342 queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
343 - queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name") 343 + //queryWealth = queryWealth.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
344 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") 344 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")
345 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") 345 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")
346 queryWealth = queryWealth.Where(`e.status = ?`, 1) 346 queryWealth = queryWealth.Where(`e.status = ?`, 1)
347 - queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'") 347 + //queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
  348 + queryWealth = queryWealth.GroupExpr("su_money_transaction_record.employee->>'uid'")
348 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { 349 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
349 queryWealth = queryWealth.Where("e.company_id = ?", companyId) 350 queryWealth = queryWealth.Where("e.company_id = ?", companyId)
350 } 351 }
@@ -417,11 +418,12 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter @@ -417,11 +418,12 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
417 queryContributions := tx.Model(suMoneyTransactionRecordModel) 418 queryContributions := tx.Model(suMoneyTransactionRecordModel)
418 queryContributions = queryContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint") 419 queryContributions = queryContributions.Join("JOIN employees AS e ON e.uid = (su_money_transaction_record.employee->>'uid')::bigint")
419 queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid") 420 queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'uid' AS uid")
420 - queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name") 421 + //queryContributions = queryContributions.ColumnExpr("su_money_transaction_record.employee->>'employeeName' AS employee_name")
421 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") 422 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")
422 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") 423 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")
423 queryContributions = queryContributions.Where(`e.status = ?`, 1) 424 queryContributions = queryContributions.Where(`e.status = ?`, 1)
424 - queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'") 425 + //queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid',su_money_transaction_record.employee->>'employeeName'")
  426 + queryContributions = queryContributions.GroupExpr("su_money_transaction_record.employee->>'uid'")
425 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) { 427 if companyId, ok := queryOptions["companyId"]; ok && (companyId.(int64) != 0) {
426 queryContributions = queryContributions.Where("e.company_id = ?", companyId) 428 queryContributions = queryContributions.Where("e.company_id = ?", companyId)
427 } 429 }