作者 陈志颖

fix:兑换素币清单榜单姓名重复处理

... ... @@ -2898,11 +2898,12 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang
}
}
// 员工兑换清单榜单
// 素币兑换清单榜单
func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQuery *query.ExchangeListRankingQuery) (interface{}, error) {
if err := exchangeListRankingQuery.ValidateCommand(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -2914,6 +2915,16 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ
transactionContext.RollbackTransaction()
}()
// 员工仓储初始化
var employeeRepository domain.EmployeeRepository
if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
employeeRepository = value
}
// 现金池DAO初始化
var cashPoolDao *dao.CashPoolDao
if value, err := factory.CreateCashPoolDao(map[string]interface{}{
... ... @@ -2928,9 +2939,39 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ
if exchangeCashListRankingStatistics, err := cashPoolDao.ExchangeCashListRanking(tool_funs.SimpleStructToMap(exchangeListRankingQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
uidName := map[int64]interface{}{}
if _, employees, err := employeeRepository.FindAll(map[string]interface{}{
"companyId": exchangeListRankingQuery.CompanyId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
for _, employee := range employees {
uidName[employee.EmployeeInfo.Uid] = employee.EmployeeInfo.EmployeeName
}
}
// 兑换素币清单排行榜
for i, _ := range exchangeCashListRankingStatistics["people"].([]struct{Uid int64; EmployeeName string; SuMoney float64; Cash float64; Ranking int}) {
uid := exchangeCashListRankingStatistics["people"].([]struct{Uid int64; EmployeeName string; SuMoney float64; Cash float64; Ranking int})[i].Uid
if uidName[uid] != nil {
exchangeCashListRankingStatistics["people"].([]struct{Uid int64; EmployeeName string; SuMoney float64; Cash float64; Ranking int})[i].EmployeeName = uidName[uid].(string)
}
}
// 个人素币兑换清单
if exchangeCashListRankingStatistics["currentEmployee"] != nil {
currentEmployeeExchangeCashList := exchangeCashListRankingStatistics["currentEmployee"].(struct{Uid int64;EmployeeName string;SuMoney float64; Cash float64;Ranking int})
uidExchangeCashList := exchangeCashListRankingStatistics["currentEmployee"].(struct{Uid int64;EmployeeName string;SuMoney float64; Cash float64;Ranking int}).Uid
if uidName[uidExchangeCashList] != nil {
currentEmployeeExchangeCashList.EmployeeName = uidName[uidExchangeCashList].(string)
}
exchangeCashListRankingStatistics["currentEmployee"] = currentEmployeeExchangeCashList
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return exchangeCashListRankingStatistics, nil
}
}
... ...
... ... @@ -37,7 +37,7 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map
// 返回兑换活动清单榜单
func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interface{}) (map[string]interface{}, error) {
var retPeople []struct {
Uid int
Uid int64
EmployeeName string
SuMoney float64
Cash float64
... ... @@ -45,7 +45,7 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
}
var retEmployee []struct {
Uid int
Uid int64
EmployeeName string
SuMoney float64
Cash float64
... ... @@ -53,13 +53,13 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
}
tx := dao.transactionContext.PgTx
exchangeCashPersonListModels := new(models.ExchangeCashPersonList)
// 清单人员排名
exchangeCashPersonListModels := new(models.ExchangeCashPersonList)
queryPeople := tx.Model(exchangeCashPersonListModels)
queryPeople = queryPeople.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid")
queryPeople = queryPeople.ColumnExpr("exchange_cash_person_list.uid AS uid")
queryPeople = queryPeople.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name")
//queryPeople = queryPeople.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name")
queryPeople = queryPeople.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash")
queryPeople = queryPeople.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money")
queryPeople = queryPeople.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC) AS ranking")
... ... @@ -71,7 +71,7 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
queryPeople = queryPeople.Where("exchange_cash_person_list.activity_id = ?", activityId)
}
queryPeople = queryPeople.Group("exchange_cash_person_list.uid")
queryPeople = queryPeople.Group("exchange_cash_person_list.employee_name")
//queryPeople = queryPeople.Group("exchange_cash_person_list.employee_name")
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
... ... @@ -88,7 +88,7 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
} else {
queryPeople = queryPeople.Limit(20)
}
if err := queryPeople.Order("su_money DESC").Select(&retPeople); err != nil {
if err := queryPeople.Order("ranking ASC").Select(&retPeople); err != nil {
return nil, err
}
... ... @@ -96,7 +96,7 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
queryPeopleAll := tx.Model(exchangeCashPersonListModels)
queryPeopleAll = queryPeopleAll.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid")
queryPeopleAll = queryPeopleAll.ColumnExpr("exchange_cash_person_list.uid AS uid")
queryPeopleAll = queryPeopleAll.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name")
//queryPeopleAll = queryPeopleAll.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name")
queryPeopleAll = queryPeopleAll.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash")
queryPeopleAll = queryPeopleAll.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money")
queryPeopleAll = queryPeopleAll.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC) AS ranking")
... ... @@ -107,19 +107,20 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
queryPeopleAll = queryPeopleAll.Where("exchange_cash_person_list.activity_id = ?", activityId)
}
queryPeopleAll = queryPeopleAll.Group("exchange_cash_person_list.uid")
queryPeopleAll = queryPeopleAll.Group("exchange_cash_person_list.employee_name")
//queryPeopleAll = queryPeopleAll.Group("exchange_cash_person_list.employee_name")
queryPeopleAllWith := queryPeopleAll.Order("su_money DESC")
queryEmployee := tx.Model()
queryEmployee = queryEmployee.With("t", queryPeopleAllWith)
queryEmployee = queryEmployee.Table("t")
queryEmployee = queryEmployee.ColumnExpr("t.uid AS uid")
queryEmployee = queryEmployee.ColumnExpr("t.employee_name AS employee_name")
//queryEmployee = queryEmployee.ColumnExpr("t.employee_name AS employee_name")
queryEmployee = queryEmployee.ColumnExpr("t.cash AS cash")
queryEmployee = queryEmployee.ColumnExpr("t.su_money AS su_money")
queryEmployee = queryEmployee.ColumnExpr("t.ranking AS ranking")
if uid, ok := queryOptions["uid"]; ok {
queryEmployee = queryEmployee.Where("t.uid::bigint = ?", uid)
}
if err := queryEmployee.Select(&retEmployee); err != nil {
return nil, err
}
... ...