作者 陈志颖

fix:完善贡献值、财富值榜单参数

... ... @@ -28,11 +28,13 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt
defer func() {
transactionContext.RollbackTransaction()
}()
newListInterval := &domain.ListInterval {
CompanyId: createListIntervalCommand.CompanyId,
IntervalStartTime: createListIntervalCommand.ListIntervalStartTime,
IntervalEndTime: createListIntervalCommand.ListIntervalEndTime,
}
var listIntervalRepository domain.ListIntervalRepository
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -41,6 +43,7 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt
} else {
listIntervalRepository = value
}
if listInterval, err := listIntervalRepository.Save(newListInterval); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -66,6 +69,7 @@ func (listIntervalService *ListIntervalService) ListListInterval(listListInterva
defer func() {
transactionContext.RollbackTransaction()
}()
var listIntervalRepository domain.ListIntervalRepository
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -74,6 +78,7 @@ func (listIntervalService *ListIntervalService) ListListInterval(listListInterva
} else {
listIntervalRepository = value
}
if count, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -102,6 +107,7 @@ func (listIntervalService *ListIntervalService) GetListInterval(getListIntervalQ
defer func() {
transactionContext.RollbackTransaction()
}()
var listIntervalRepository domain.ListIntervalRepository
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -110,6 +116,7 @@ func (listIntervalService *ListIntervalService) GetListInterval(getListIntervalQ
} else {
listIntervalRepository = value
}
listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": getListIntervalQuery.ListIntervalId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -139,6 +146,7 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
defer func() {
transactionContext.RollbackTransaction()
}()
var listIntervalRepository domain.ListIntervalRepository
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -147,6 +155,7 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
} else {
listIntervalRepository = value
}
listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": updateListIntervalCommand.ListIntervalId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -157,6 +166,7 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
if err := listInterval.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if listInterval, err := listIntervalRepository.Save(listInterval); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ... @@ -182,6 +192,7 @@ func (listIntervalService *ListIntervalService) RemoveListInterval(removeListInt
defer func() {
transactionContext.RollbackTransaction()
}()
var listIntervalRepository domain.ListIntervalRepository
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
"transactionContext": transactionContext,
... ... @@ -190,6 +201,7 @@ func (listIntervalService *ListIntervalService) RemoveListInterval(removeListInt
} else {
listIntervalRepository = value
}
listInterval, err := listIntervalRepository.FindOne(map[string]interface{}{"listId": removeListIntervalCommand.ListIntervalId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -197,6 +209,7 @@ func (listIntervalService *ListIntervalService) RemoveListInterval(removeListInt
if listInterval == nil {
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeListIntervalCommand.ListIntervalId)))
}
if listInterval, err := listIntervalRepository.Remove(listInterval); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -384,7 +384,7 @@ func (statisticsService *StatisticsService) EmployeesContributionsStatistics(emp
}
}
// TODO 员工排行榜统计
// 员工排行榜统计 (弃用)
func (statisticsService *StatisticsService) EmployeesRankingListStatistics(employeesRankingListStatisticsCommand *command.EmployeesRankingListStatisticsCommand) (interface{}, error) {
if err := employeesRankingListStatisticsCommand.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
... ... @@ -449,6 +449,44 @@ func (statisticsService *StatisticsService) ContributionsWealthRanking(contribut
employeeDao = value
}
// 返回年榜开始时间、结束时间
if contributionsWealthRankingQuery.RankingType == 2 {
// 获取公司最新年榜
var listIntervalRepository domain.ListIntervalRepository
if value, err := factory.CreateListIntervalRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
listIntervalRepository = value
}
listListIntervalQuery := map[string]interface{} {
"companyId": contributionsWealthRankingQuery.CompanyId,
"offset": 0,
"limit": 1,
}
if _, listIntervals, err := listIntervalRepository.Find(listListIntervalQuery); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if len(listIntervals) == 0 {
contributionsWealthRankingQuery.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())
contributionsWealthRankingQuery.EndTime = time.Now()
} else {
contributionsWealthRankingQuery.StartTime = listIntervals[0].IntervalStartTime
contributionsWealthRankingQuery.EndTime = listIntervals[0].IntervalEndTime
}
}
}
// 返回总榜
if contributionsWealthRankingQuery.RankingType == 1 {
contributionsWealthRankingQuery.StartTime = time.Date(1971, time.Month(1), 1, 0, 0, 0, 0, time.Now().Location())
contributionsWealthRankingQuery.EndTime = time.Now()
}
// 默认返回总榜
if contributionsWealthRankingStatistics, err := employeeDao.ContributionsWealthRanking(tool_funs.SimpleStructToMap(contributionsWealthRankingQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -3,13 +3,17 @@ package query
import (
"fmt"
"github.com/astaxie/beego/validation"
"time"
)
type ContributionsWealthRankingQuery struct {
CompanyId int64 `json:"companyId"` // 公司ID
Offset int `json:"offset,omitempty"` // 查询偏离量
Limit int `json:"limit,omitempty"` // 查询限制
Uid int64 `json:"uid"` // 统一用户id
CompanyId int64 `json:"companyId" valid:"Required"` // 公司ID
RankingType int `json:"rankingType" valid:"Required"` // 榜单类型,区分总榜和年榜 1:总榜,2:年榜
Offset int `json:"offset,omitempty"` // 查询偏离量
Limit int `json:"limit,omitempty"` // 查询限制
Uid int64 `json:"uid" valid:"Required"` // 统一用户id
StartTime time.Time `json:"startTime"` // 榜单开始时间,由后台根据榜单类型后去
EndTime time.Time `json:"endTime"` // 榜单结束更新,由后台根据榜单类型获取
}
func (contributionsWealthRankingQuery *ContributionsWealthRankingQuery) ValidateQuery() error {
... ...
... ... @@ -283,7 +283,7 @@ func (dao *EmployeeDao) CalculateEmployeesSuMoney(companyId int, startTime time.
// }, nil
//}
// 贡献值、财富值排行
// 贡献值、财富值总榜和年
func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]interface{}) (interface{}, error) {
var retWealth []struct {
Uid int
... ... @@ -313,7 +313,7 @@ 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")
... ... @@ -377,8 +377,14 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if err := queryEmployeeWealth.Order("employee_su_money DESC").Select(&retEmployeeWealth); err != nil {
return nil, err
}
var retCurrentEmployeeWealth interface{}
if len(retEmployeeWealth) == 0 {
retCurrentEmployeeWealth = nil
} else {
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")
... ... @@ -506,12 +512,18 @@ func (dao *EmployeeDao) ContributionsWealthRanking(queryOptions map[string]inter
if err := queryEmployeeContributions.Order("employees_contributions DESC").Select(&retEmployeeContributions); err != nil {
return nil, err
}
var retCurrentEmployeeContributions interface{}
if len(retEmployeeContributions) == 0 {
retCurrentEmployeeContributions = nil
} else {
retCurrentEmployeeContributions = retEmployeeContributions[0]
}
return map[string]interface{}{
"employeesWealth": retWealth,
"employeesContributions": retContributions,
"currentEmployeeContributions": retEmployeeContributions,
"currentEmployeeWealth": retEmployeeWealth,
"currentEmployeeContributions": retCurrentEmployeeContributions,
"currentEmployeeWealth": retCurrentEmployeeWealth,
}, nil
}
... ...
... ... @@ -141,11 +141,8 @@ func (controller *StatisticsController) EmployeesContributionsStatistics() {
// 员工财富值、贡献值排行榜
func (controller *StatisticsController) RankingListStatistics() {
statisticsService := service.NewStatisticsService(nil)
//employeesRankingListStatisticsCommand := &command.EmployeesRankingListStatisticsCommand{}
//json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), employeesRankingListStatisticsCommand)
contributionsWealthRankingQuery := &query.ContributionsWealthRankingQuery{}
json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), contributionsWealthRankingQuery)
//data, err := statisticsService.EmployeesRankingListStatistics(employeesRankingListStatisticsCommand)
data, err := statisticsService.ContributionsWealthRanking(contributionsWealthRankingQuery)
var response utils.JsonResponse
if err != nil {
... ...