作者 陈志颖

Merge branch 'fix-activity' into dev

@@ -384,46 +384,6 @@ func (statisticsService *StatisticsService) EmployeesContributionsStatistics(emp @@ -384,46 +384,6 @@ func (statisticsService *StatisticsService) EmployeesContributionsStatistics(emp
384 } 384 }
385 } 385 }
386 386
387 -// 员工排行榜统计 (弃用)  
388 -//func (statisticsService *StatisticsService) EmployeesRankingListStatistics(employeesRankingListStatisticsCommand *command.EmployeesRankingListStatisticsCommand) (interface{}, error) {  
389 -// if err := employeesRankingListStatisticsCommand.ValidateCommand(); err != nil {  
390 -// return nil, application.ThrowError(application.ARG_ERROR, err.Error())  
391 -// }  
392 -// transactionContext, err := factory.CreateTransactionContext(nil)  
393 -// if err != nil {  
394 -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
395 -// }  
396 -// if err := transactionContext.StartTransaction(); err != nil {  
397 -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
398 -// }  
399 -// defer func() {  
400 -// transactionContext.RollbackTransaction()  
401 -// }()  
402 -//  
403 -// var employeeDao *dao.EmployeeDao  
404 -// if value, err := factory.CreateEmployeeDao(map[string]interface{}{  
405 -// "transactionContext": transactionContext,  
406 -// }); err != nil {  
407 -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
408 -// } else {  
409 -// employeeDao = value  
410 -// }  
411 -//  
412 -// if employeesRankingListStatisticsCommand.StartTime.IsZero() && employeesRankingListStatisticsCommand.EndTime.IsZero() {  
413 -// employeesRankingListStatisticsCommand.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())  
414 -// employeesRankingListStatisticsCommand.EndTime = time.Now().Local()  
415 -// }  
416 -//  
417 -// if employeesRankingListStatistics, err := employeeDao.CalculateEmployeesRankingList(employeesRankingListStatisticsCommand.CompanyId, employeesRankingListStatisticsCommand.StartTime, employeesRankingListStatisticsCommand.EndTime, employeesRankingListStatisticsCommand.Offset, employeesRankingListStatisticsCommand.Limit); err != nil {  
418 -// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
419 -// } else {  
420 -// if err := transactionContext.CommitTransaction(); err != nil {  
421 -// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())  
422 -// }  
423 -// return employeesRankingListStatistics, nil  
424 -// }  
425 -//}  
426 -  
427 // 贡献值、财富值榜单 387 // 贡献值、财富值榜单
428 func (statisticsService *StatisticsService) ContributionsWealthRanking(contributionsWealthRankingQuery *query.ContributionsWealthRankingQuery) (interface{}, error) { 388 func (statisticsService *StatisticsService) ContributionsWealthRanking(contributionsWealthRankingQuery *query.ContributionsWealthRankingQuery) (interface{}, error) {
429 if err := contributionsWealthRankingQuery.ValidateQuery(); err != nil { 389 if err := contributionsWealthRankingQuery.ValidateQuery(); err != nil {
@@ -449,8 +409,10 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut @@ -449,8 +409,10 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
449 employeeDao = value 409 employeeDao = value
450 } 410 }
451 411
452 - // 返回年榜开始时间、结束时间  
453 - if contributionsWealthRankingQuery.RankingType == 2 { 412 + if contributionsWealthRankingQuery.RankingType == 1 { // 返回总榜
  413 + contributionsWealthRankingQuery.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())
  414 + contributionsWealthRankingQuery.EndTime = time.Now()
  415 + } else if contributionsWealthRankingQuery.RankingType == 2 { // 返回年榜
454 // 获取公司最新年榜 416 // 获取公司最新年榜
455 var listIntervalRepository domain.ListIntervalRepository 417 var listIntervalRepository domain.ListIntervalRepository
456 if value, err := factory.CreateListIntervalRepository(map[string]interface{}{ 418 if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
@@ -470,22 +432,36 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut @@ -470,22 +432,36 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
470 if _, listIntervals, err := listIntervalRepository.Find(listListIntervalQuery); err != nil { 432 if _, listIntervals, err := listIntervalRepository.Find(listListIntervalQuery); err != nil {
471 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 433 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
472 } else { 434 } else {
473 - if len(listIntervals) == 0 {  
474 - contributionsWealthRankingQuery.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())  
475 - contributionsWealthRankingQuery.EndTime = time.Now()  
476 - } else {  
477 - contributionsWealthRankingQuery.StartTime = listIntervals[0].IntervalStartTime  
478 - contributionsWealthRankingQuery.EndTime = listIntervals[0].IntervalEndTime 435 + if len(listIntervals) == 0 { // 未配置年榜
  436 + contributionsWealthRankingQuery.StartTime = time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.UTC)
  437 + contributionsWealthRankingQuery.EndTime = time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.UTC)
  438 + } else if len(listIntervals) == 1 { // 只配置了一个年榜
  439 + currentTime := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.UTC)
  440 + if currentTime.Before(listIntervals[0].IntervalStartTime) && currentTime.After(listIntervals[0].IntervalEndTime) || currentTime.Equal(listIntervals[0].IntervalStartTime) || currentTime.Equal(listIntervals[0].IntervalEndTime) { // 当前时间在榜单内
  441 + contributionsWealthRankingQuery.StartTime = listIntervals[0].IntervalStartTime
  442 + contributionsWealthRankingQuery.EndTime = listIntervals[0].IntervalEndTime
  443 + } else { // 当前时间处于空档期
  444 + contributionsWealthRankingQuery.StartTime = time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.UTC)
  445 + contributionsWealthRankingQuery.EndTime = time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.UTC)
  446 + }
  447 + } else { // 配置了多个年榜
  448 + // 判断当前时间是否在榜单里
  449 + currentTime := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.UTC)
  450 + for _, listInterval := range listIntervals {
  451 + if currentTime.Before(listInterval.IntervalStartTime) && currentTime.After(listInterval.IntervalEndTime) || currentTime.Equal(listInterval.IntervalStartTime) || currentTime.Equal(listInterval.IntervalEndTime) { // 当前时间在榜单内
  452 + contributionsWealthRankingQuery.StartTime = listInterval.IntervalStartTime
  453 + contributionsWealthRankingQuery.EndTime = listInterval.IntervalEndTime
  454 + break
  455 + } else { // 当前时间处于空档期
  456 + contributionsWealthRankingQuery.StartTime = time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.UTC)
  457 + contributionsWealthRankingQuery.EndTime = time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.UTC)
  458 + break
  459 + }
  460 + }
479 } 461 }
480 } 462 }
481 } 463 }
482 464
483 - // 返回总榜  
484 - if contributionsWealthRankingQuery.RankingType == 1 {  
485 - contributionsWealthRankingQuery.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())  
486 - contributionsWealthRankingQuery.EndTime = time.Now()  
487 - }  
488 -  
489 // 默认返回总榜 465 // 默认返回总榜
490 if contributionsWealthRankingStatistics, err := employeeDao.ContributionsWealthRanking(tool_funs.SimpleStructToMap(contributionsWealthRankingQuery)); err != nil { 466 if contributionsWealthRankingStatistics, err := employeeDao.ContributionsWealthRanking(tool_funs.SimpleStructToMap(contributionsWealthRankingQuery)); err != nil {
491 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 467 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -190,7 +190,7 @@ func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMon @@ -190,7 +190,7 @@ func (suMoneyService *SuMoneyService) SearchSuMoneyTransactionRecord(searchSuMon
190 } 190 }
191 } 191 }
192 192
193 -// 素币事务记录统计 193 +// 素币事务记录统计(个人素币)
194 func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoneyTransactionRecordStatisticsCommand *command.SuMoneyTransactionRecordStatisticsCommand) (interface{}, error) { 194 func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoneyTransactionRecordStatisticsCommand *command.SuMoneyTransactionRecordStatisticsCommand) (interface{}, error) {
195 if err := suMoneyTransactionRecordStatisticsCommand.ValidateCommand(); err != nil { 195 if err := suMoneyTransactionRecordStatisticsCommand.ValidateCommand(); err != nil {
196 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 196 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -226,7 +226,7 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney @@ -226,7 +226,7 @@ func (suMoneyService *SuMoneyService) SuMoneyTransactionRecordStatistics(suMoney
226 } 226 }
227 } 227 }
228 228
229 -// 贡献值事务记录统计 229 +// 贡献值事务记录统计(个人贡献值)
230 func (suMoneyService *SuMoneyService) ContributionsTransactionRecordStatistics(contributionsTransactionRecordStatisticsCommand *command.ContributionsTransactionRecordStatisticsCommand) (interface{}, error) { 230 func (suMoneyService *SuMoneyService) ContributionsTransactionRecordStatistics(contributionsTransactionRecordStatisticsCommand *command.ContributionsTransactionRecordStatisticsCommand) (interface{}, error) {
231 if err := contributionsTransactionRecordStatisticsCommand.ValidateCommand(); err != nil { 231 if err := contributionsTransactionRecordStatisticsCommand.ValidateCommand(); err != nil {
232 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 232 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
@@ -98,17 +98,17 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ @@ -98,17 +98,17 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{
98 tx := dao.transactionContext.PgTx 98 tx := dao.transactionContext.PgTx
99 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 99 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
100 yesterday := time.Now().AddDate(0, 0, -1) 100 yesterday := time.Now().AddDate(0, 0, -1)
101 - // 昨日收益 101 + // 昨日收益
102 if err := tx.Model(suMoneyTransactionRecordModel). 102 if err := tx.Model(suMoneyTransactionRecordModel).
103 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 103 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
104 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 104 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
105 - Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). 105 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6})).
106 Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())). 106 Where(`su_money_transaction_record.create_time > ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 0, 0, 0, 0, yesterday.Location())).
107 Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())). 107 Where(`su_money_transaction_record.create_time < ?`, time.Date(yesterday.Year(), yesterday.Month(), yesterday.Day(), 23, 59, 59, 0, yesterday.Location())).
108 Select(&incomeSuMoneyOfYesterday); err != nil { 108 Select(&incomeSuMoneyOfYesterday); err != nil {
109 return nil, err 109 return nil, err
110 } 110 }
111 - // 昨日支出 111 + // 昨日支出
112 if err := tx.Model(suMoneyTransactionRecordModel). 112 if err := tx.Model(suMoneyTransactionRecordModel).
113 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 113 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
114 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 114 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
@@ -122,7 +122,7 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{ @@ -122,7 +122,7 @@ func (dao *EmployeeDao) CalculatePersonSuMoney(uid int64) (map[string]interface{
122 if err := tx.Model(suMoneyTransactionRecordModel). 122 if err := tx.Model(suMoneyTransactionRecordModel).
123 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 123 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
124 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 124 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
125 - Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3})). 125 + Where(`su_money_transaction_record.record_type IN (?)`, pg.In([]int{2, 3, 6})).
126 Select(&incomeSuMoney); err != nil { 126 Select(&incomeSuMoney); err != nil {
127 return nil, err 127 return nil, err
128 } 128 }
@@ -180,7 +180,7 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int @@ -180,7 +180,7 @@ func (dao *EmployeeDao) CalculateSystemSuMoney(companyId int64) (map[string] int
180 },nil 180 },nil
181 } 181 }
182 182
183 -// 计算系统已兑换现金、未兑换现金 183 +// 计算现金池已兑换现金、未兑换现金
184 func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interface{}, error) { 184 func (dao *EmployeeDao) CalculateSystemCash(companyId int64) (map[string] interface{}, error) {
185 tx := dao.transactionContext.PgTx 185 tx := dao.transactionContext.PgTx
186 var ( 186 var (
@@ -220,7 +220,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -220,7 +220,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
220 ) 220 )
221 tx := dao.transactionContext.PgTx 221 tx := dao.transactionContext.PgTx
222 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 222 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
223 - // 收入素币 223 + // 收入素币
224 if err := tx.Model(suMoneyTransactionRecordModel). 224 if err := tx.Model(suMoneyTransactionRecordModel).
225 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 225 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
226 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 226 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
@@ -230,7 +230,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -230,7 +230,7 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
230 Select(&incomeSuMoney); err != nil { 230 Select(&incomeSuMoney); err != nil {
231 return nil, err 231 return nil, err
232 } 232 }
233 - // 支出素币 233 + // 支出素币
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).
@@ -241,20 +241,20 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction @@ -241,20 +241,20 @@ func (dao *EmployeeDao) CalculateSuMoneyTransactionRecord(uid int64, transaction
241 return nil, err 241 return nil, err
242 } 242 }
243 return map[string]interface{}{ 243 return map[string]interface{}{
244 - "incomeSuMoney": incomeSuMoney,  
245 - "expendSuMoney": expendSuMoney, 244 + "incomeSuMoney": incomeSuMoney - expendSuMoney, // 个人素币盈利
  245 + "expendSuMoney": expendSuMoney, // 个人素币支出
246 }, nil 246 }, nil
247 } 247 }
248 248
249 // 计算个人贡献值收支 249 // 计算个人贡献值收支
250 func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) { 250 func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, transactionStartTime time.Time, transactionEndTime time.Time) (map[string]interface{}, error) {
251 var ( 251 var (
252 - incomeContributions float64 // 增加的贡献值(2:任务奖励,3:增加)  
253 - expendContributions float64 // 扣除的贡献值 (4: 扣除) 252 + incomeContributions float64 // 收入的贡献值(2:任务奖励,3:增加)
  253 + expendContributions float64 // 支出的贡献值 (4: 扣除)
254 ) 254 )
255 tx := dao.transactionContext.PgTx 255 tx := dao.transactionContext.PgTx
256 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord) 256 suMoneyTransactionRecordModel := new(models.SuMoneyTransactionRecord)
257 - // 增加的贡献值 257 + // 总收入的贡献值
258 if err := tx.Model(suMoneyTransactionRecordModel). 258 if err := tx.Model(suMoneyTransactionRecordModel).
259 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money"). 259 ColumnExpr("sum(su_money_transaction_record.su_money) AS income_su_money").
260 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 260 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
@@ -264,7 +264,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans @@ -264,7 +264,7 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans
264 Select(&incomeContributions); err != nil { 264 Select(&incomeContributions); err != nil {
265 return nil, err 265 return nil, err
266 } 266 }
267 - // 扣除的贡献值 267 + // 总支出的贡献值
268 if err := tx.Model(suMoneyTransactionRecordModel). 268 if err := tx.Model(suMoneyTransactionRecordModel).
269 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money"). 269 ColumnExpr("sum(su_money_transaction_record.su_money) AS expend_su_money").
270 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid). 270 Where(`su_money_transaction_record.employee @> '{"uid":?}'`, uid).
@@ -275,8 +275,8 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans @@ -275,8 +275,8 @@ func (dao *EmployeeDao) CalculateContributionsTransactionRecord(uid int64, trans
275 return nil, err 275 return nil, err
276 } 276 }
277 return map[string]interface{}{ 277 return map[string]interface{}{
278 - "incomeContributions": incomeContributions,  
279 - "expendContributions": expendContributions, 278 + "incomeContributions": incomeContributions - expendContributions, // 个人贡献值盈利
  279 + "expendContributions": expendContributions, // 个人贡献支出
280 }, nil 280 }, nil
281 } 281 }
282 282