作者 陈志颖

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

@@ -2898,11 +2898,12 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang @@ -2898,11 +2898,12 @@ func (cashPoolService *CashPoolService) ListExchangeCashPersonById(exportExchang
2898 } 2898 }
2899 } 2899 }
2900 2900
2901 -// 员工兑换清单榜单 2901 +// 素币兑换清单榜单
2902 func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQuery *query.ExchangeListRankingQuery) (interface{}, error) { 2902 func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQuery *query.ExchangeListRankingQuery) (interface{}, error) {
2903 if err := exchangeListRankingQuery.ValidateCommand(); err != nil { 2903 if err := exchangeListRankingQuery.ValidateCommand(); err != nil {
2904 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 2904 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
2905 } 2905 }
  2906 +
2906 transactionContext, err := factory.CreateTransactionContext(nil) 2907 transactionContext, err := factory.CreateTransactionContext(nil)
2907 if err != nil { 2908 if err != nil {
2908 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 2909 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -2914,6 +2915,16 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ @@ -2914,6 +2915,16 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ
2914 transactionContext.RollbackTransaction() 2915 transactionContext.RollbackTransaction()
2915 }() 2916 }()
2916 2917
  2918 + // 员工仓储初始化
  2919 + var employeeRepository domain.EmployeeRepository
  2920 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  2921 + "transactionContext": transactionContext,
  2922 + }); err != nil {
  2923 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  2924 + } else {
  2925 + employeeRepository = value
  2926 + }
  2927 +
2917 // 现金池DAO初始化 2928 // 现金池DAO初始化
2918 var cashPoolDao *dao.CashPoolDao 2929 var cashPoolDao *dao.CashPoolDao
2919 if value, err := factory.CreateCashPoolDao(map[string]interface{}{ 2930 if value, err := factory.CreateCashPoolDao(map[string]interface{}{
@@ -2928,9 +2939,39 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ @@ -2928,9 +2939,39 @@ func (cashPoolService *CashPoolService) ExchangeListRanking(exchangeListRankingQ
2928 if exchangeCashListRankingStatistics, err := cashPoolDao.ExchangeCashListRanking(tool_funs.SimpleStructToMap(exchangeListRankingQuery)); err != nil { 2939 if exchangeCashListRankingStatistics, err := cashPoolDao.ExchangeCashListRanking(tool_funs.SimpleStructToMap(exchangeListRankingQuery)); err != nil {
2929 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 2940 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
2930 } else { 2941 } else {
  2942 + uidName := map[int64]interface{}{}
  2943 + if _, employees, err := employeeRepository.FindAll(map[string]interface{}{
  2944 + "companyId": exchangeListRankingQuery.CompanyId,
  2945 + }); err != nil {
  2946 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  2947 + } else {
  2948 + for _, employee := range employees {
  2949 + uidName[employee.EmployeeInfo.Uid] = employee.EmployeeInfo.EmployeeName
  2950 + }
  2951 + }
  2952 +
  2953 + // 兑换素币清单排行榜
  2954 + for i, _ := range exchangeCashListRankingStatistics["people"].([]struct{Uid int64; EmployeeName string; SuMoney float64; Cash float64; Ranking int}) {
  2955 + uid := exchangeCashListRankingStatistics["people"].([]struct{Uid int64; EmployeeName string; SuMoney float64; Cash float64; Ranking int})[i].Uid
  2956 + if uidName[uid] != nil {
  2957 + exchangeCashListRankingStatistics["people"].([]struct{Uid int64; EmployeeName string; SuMoney float64; Cash float64; Ranking int})[i].EmployeeName = uidName[uid].(string)
  2958 + }
  2959 + }
  2960 +
  2961 + // 个人素币兑换清单
  2962 + if exchangeCashListRankingStatistics["currentEmployee"] != nil {
  2963 + currentEmployeeExchangeCashList := exchangeCashListRankingStatistics["currentEmployee"].(struct{Uid int64;EmployeeName string;SuMoney float64; Cash float64;Ranking int})
  2964 + uidExchangeCashList := exchangeCashListRankingStatistics["currentEmployee"].(struct{Uid int64;EmployeeName string;SuMoney float64; Cash float64;Ranking int}).Uid
  2965 + if uidName[uidExchangeCashList] != nil {
  2966 + currentEmployeeExchangeCashList.EmployeeName = uidName[uidExchangeCashList].(string)
  2967 + }
  2968 + exchangeCashListRankingStatistics["currentEmployee"] = currentEmployeeExchangeCashList
  2969 + }
  2970 +
2931 if err := transactionContext.CommitTransaction(); err != nil { 2971 if err := transactionContext.CommitTransaction(); err != nil {
2932 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 2972 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
2933 } 2973 }
  2974 +
2934 return exchangeCashListRankingStatistics, nil 2975 return exchangeCashListRankingStatistics, nil
2935 } 2976 }
2936 } 2977 }
@@ -37,7 +37,7 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map @@ -37,7 +37,7 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map
37 // 返回兑换活动清单榜单 37 // 返回兑换活动清单榜单
38 func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interface{}) (map[string]interface{}, error) { 38 func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interface{}) (map[string]interface{}, error) {
39 var retPeople []struct { 39 var retPeople []struct {
40 - Uid int 40 + Uid int64
41 EmployeeName string 41 EmployeeName string
42 SuMoney float64 42 SuMoney float64
43 Cash float64 43 Cash float64
@@ -45,7 +45,7 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac @@ -45,7 +45,7 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
45 } 45 }
46 46
47 var retEmployee []struct { 47 var retEmployee []struct {
48 - Uid int 48 + Uid int64
49 EmployeeName string 49 EmployeeName string
50 SuMoney float64 50 SuMoney float64
51 Cash float64 51 Cash float64
@@ -53,13 +53,13 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac @@ -53,13 +53,13 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
53 } 53 }
54 54
55 tx := dao.transactionContext.PgTx 55 tx := dao.transactionContext.PgTx
  56 + exchangeCashPersonListModels := new(models.ExchangeCashPersonList)
56 57
57 // 清单人员排名 58 // 清单人员排名
58 - exchangeCashPersonListModels := new(models.ExchangeCashPersonList)  
59 queryPeople := tx.Model(exchangeCashPersonListModels) 59 queryPeople := tx.Model(exchangeCashPersonListModels)
60 queryPeople = queryPeople.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid") 60 queryPeople = queryPeople.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid")
61 queryPeople = queryPeople.ColumnExpr("exchange_cash_person_list.uid AS uid") 61 queryPeople = queryPeople.ColumnExpr("exchange_cash_person_list.uid AS uid")
62 - queryPeople = queryPeople.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name") 62 + //queryPeople = queryPeople.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name")
63 queryPeople = queryPeople.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash") 63 queryPeople = queryPeople.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash")
64 queryPeople = queryPeople.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money") 64 queryPeople = queryPeople.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money")
65 queryPeople = queryPeople.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC) AS ranking") 65 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 @@ -71,7 +71,7 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
71 queryPeople = queryPeople.Where("exchange_cash_person_list.activity_id = ?", activityId) 71 queryPeople = queryPeople.Where("exchange_cash_person_list.activity_id = ?", activityId)
72 } 72 }
73 queryPeople = queryPeople.Group("exchange_cash_person_list.uid") 73 queryPeople = queryPeople.Group("exchange_cash_person_list.uid")
74 - queryPeople = queryPeople.Group("exchange_cash_person_list.employee_name") 74 + //queryPeople = queryPeople.Group("exchange_cash_person_list.employee_name")
75 if offset, ok := queryOptions["offset"]; ok { 75 if offset, ok := queryOptions["offset"]; ok {
76 offset := offset.(int) 76 offset := offset.(int)
77 if offset > -1 { 77 if offset > -1 {
@@ -88,7 +88,7 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac @@ -88,7 +88,7 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
88 } else { 88 } else {
89 queryPeople = queryPeople.Limit(20) 89 queryPeople = queryPeople.Limit(20)
90 } 90 }
91 - if err := queryPeople.Order("su_money DESC").Select(&retPeople); err != nil { 91 + if err := queryPeople.Order("ranking ASC").Select(&retPeople); err != nil {
92 return nil, err 92 return nil, err
93 } 93 }
94 94
@@ -96,7 +96,7 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac @@ -96,7 +96,7 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
96 queryPeopleAll := tx.Model(exchangeCashPersonListModels) 96 queryPeopleAll := tx.Model(exchangeCashPersonListModels)
97 queryPeopleAll = queryPeopleAll.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid") 97 queryPeopleAll = queryPeopleAll.Join("JOIN employees AS e ON e.uid = exchange_cash_person_list.uid")
98 queryPeopleAll = queryPeopleAll.ColumnExpr("exchange_cash_person_list.uid AS uid") 98 queryPeopleAll = queryPeopleAll.ColumnExpr("exchange_cash_person_list.uid AS uid")
99 - queryPeopleAll = queryPeopleAll.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name") 99 + //queryPeopleAll = queryPeopleAll.ColumnExpr("exchange_cash_person_list.employee_name AS employee_name")
100 queryPeopleAll = queryPeopleAll.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash") 100 queryPeopleAll = queryPeopleAll.ColumnExpr("sum(exchange_cash_person_list.exchanged_cash) AS cash")
101 queryPeopleAll = queryPeopleAll.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money") 101 queryPeopleAll = queryPeopleAll.ColumnExpr("sum(exchange_cash_person_list.exchanged_su_money) AS su_money")
102 queryPeopleAll = queryPeopleAll.ColumnExpr("ROW_NUMBER() OVER (ORDER BY sum(exchange_cash_person_list.exchanged_su_money) DESC) AS ranking") 102 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 @@ -107,19 +107,20 @@ func (dao *CashPoolDao) ExchangeCashListRanking(queryOptions map[string]interfac
107 queryPeopleAll = queryPeopleAll.Where("exchange_cash_person_list.activity_id = ?", activityId) 107 queryPeopleAll = queryPeopleAll.Where("exchange_cash_person_list.activity_id = ?", activityId)
108 } 108 }
109 queryPeopleAll = queryPeopleAll.Group("exchange_cash_person_list.uid") 109 queryPeopleAll = queryPeopleAll.Group("exchange_cash_person_list.uid")
110 - queryPeopleAll = queryPeopleAll.Group("exchange_cash_person_list.employee_name") 110 + //queryPeopleAll = queryPeopleAll.Group("exchange_cash_person_list.employee_name")
111 queryPeopleAllWith := queryPeopleAll.Order("su_money DESC") 111 queryPeopleAllWith := queryPeopleAll.Order("su_money DESC")
112 queryEmployee := tx.Model() 112 queryEmployee := tx.Model()
113 queryEmployee = queryEmployee.With("t", queryPeopleAllWith) 113 queryEmployee = queryEmployee.With("t", queryPeopleAllWith)
114 queryEmployee = queryEmployee.Table("t") 114 queryEmployee = queryEmployee.Table("t")
115 queryEmployee = queryEmployee.ColumnExpr("t.uid AS uid") 115 queryEmployee = queryEmployee.ColumnExpr("t.uid AS uid")
116 - queryEmployee = queryEmployee.ColumnExpr("t.employee_name AS employee_name") 116 + //queryEmployee = queryEmployee.ColumnExpr("t.employee_name AS employee_name")
117 queryEmployee = queryEmployee.ColumnExpr("t.cash AS cash") 117 queryEmployee = queryEmployee.ColumnExpr("t.cash AS cash")
118 queryEmployee = queryEmployee.ColumnExpr("t.su_money AS su_money") 118 queryEmployee = queryEmployee.ColumnExpr("t.su_money AS su_money")
119 queryEmployee = queryEmployee.ColumnExpr("t.ranking AS ranking") 119 queryEmployee = queryEmployee.ColumnExpr("t.ranking AS ranking")
120 if uid, ok := queryOptions["uid"]; ok { 120 if uid, ok := queryOptions["uid"]; ok {
121 queryEmployee = queryEmployee.Where("t.uid::bigint = ?", uid) 121 queryEmployee = queryEmployee.Where("t.uid::bigint = ?", uid)
122 } 122 }
  123 +
123 if err := queryEmployee.Select(&retEmployee); err != nil { 124 if err := queryEmployee.Select(&retEmployee); err != nil {
124 return nil, err 125 return nil, err
125 } 126 }