作者 陈志颖

feat:增加兑换清单总榜

... ... @@ -7,6 +7,7 @@ import (
// 获取兑换活动兑换清单
type ListExchangeCashPersonQuery struct {
CompanyId int64 `json:"companyId"` // 公司id
ExchangeCashActivityId int64 `json:"exchangeCashActivityId"` // 兑换现金活动id
ExchangeCashPersonNameMatch string `json:"exchangeCashPersonNameMatch,omitempty"` // 兑换活动名称匹配
Offset int `json:"offset,omitempty"` // 查询偏离量
... ...
... ... @@ -998,6 +998,11 @@ func (cashPoolService *CashPoolService) GetExchangeCashPerson(getExchangeCashPer
}
}
// 返回素币兑换现金活动总清单
//func (cashPoolService *CashPoolService) ListSystemExchangeCashPerson(listSystemExchangeCashPersonQuery *query.ListSystemExchangeCashPersonQuery) (interface{}, error) {
//
//}
// 返回兑换素币清单列表
func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashPersonQuery *query.ListExchangeCashPersonQuery) (interface{}, error) {
if err := listExchangeCashPersonQuery.ValidateQuery(); err != nil {
... ... @@ -1023,7 +1028,48 @@ func (cashPoolService *CashPoolService) ListExchangeCashPerson(listExchangeCashP
exchangeCashPersonListRepository = value
}
// TODO 增加总榜单查询
fmt.Print(listExchangeCashPersonQuery, "\n")
// TODO 返回兑换现金活动总榜
if listExchangeCashPersonQuery.ExchangeCashActivityId == 0 && listExchangeCashPersonQuery.CompanyId != 0 {
// 找到该公司下的所有活动id
var exchangeActivityRepository domain.ExchangeActivityRepository
if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
"transactionContext": transactionContext,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
exchangeActivityRepository = value
}
if _, activities, err := exchangeActivityRepository.Find(map[string]interface{}{
"companyId": listExchangeCashPersonQuery.CompanyId,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
var activityIds []int64
for _, activity := range activities {
activityIds = append(activityIds, activity.ActivityId)
}
if count, people, err := exchangeCashPersonListRepository.FindAll(map[string]interface{}{
"exchangeCashActivityIds": activityIds,
"offset": listExchangeCashPersonQuery.Offset,
"limit": listExchangeCashPersonQuery.Limit,
}); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{
"count": count,
"people": people,
}, nil
}
}
}
if count, people, err := exchangeCashPersonListRepository.Find(tool_funs.SimpleStructToMap(listExchangeCashPersonQuery)); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -14,6 +14,7 @@ type ExchangeCashPersonListRepository interface {
Remove(exchangeCashPersonList *ExchangeCashPersonList) (*ExchangeCashPersonList, error)
FindOne(queryOptions map[string]interface{}) (*ExchangeCashPersonList, error)
Find(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error)
FindAll(queryOptions map[string]interface{}) (int64, []*ExchangeCashPersonList, error)
}
func (exchangeCashPersonList *ExchangeCashPersonList) Identity() interface{} {
... ...
... ... @@ -54,6 +54,45 @@ func (repository *ExchangeCashPersonListRepository) FindOne(queryOptions map[str
}
}
// 获取平台所有兑换活动清单(兑换现金活动总清单)
func (repository *ExchangeCashPersonListRepository) FindAll(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) {
tx := repository.transactionContext.PgTx
var exchangeCashListModels []*models.ExchangeCashPersonList
exchangeCashPeople := make([]*domain.ExchangeCashPersonList, 0)
query := tx.Model(&exchangeCashListModels)
if exchangeCashActivityIds, ok := queryOptions["exchangeCashActivityIds"]; ok && len(exchangeCashActivityIds.([]int64)) != 0 {
query = query.Where("exchange_cash_person_list.activity_id IN (?)", pg.In(exchangeCashActivityIds.([]int64)) )
}
if offset, ok := queryOptions["offset"]; ok {
offset := offset.(int)
if offset > -1 {
query = query.Offset(offset)
}
} else {
query = query.Offset(0)
}
if limit, ok := queryOptions["limit"]; ok {
limit := limit.(int)
if limit > -1 {
query = query.Limit(limit)
}
} else {
query = query.Limit(20)
}
if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
return 0, exchangeCashPeople, err
} else {
for _, exchangeCashListModel := range exchangeCashListModels {
if taskNature, err := repository.transformPgModelToDomainModel(exchangeCashListModel); err != nil {
return 0, exchangeCashPeople, err
} else {
exchangeCashPeople = append(exchangeCashPeople, taskNature)
}
}
return int64(count), exchangeCashPeople, nil
}
}
func (repository *ExchangeCashPersonListRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.ExchangeCashPersonList, error) {
tx := repository.transactionContext.PgTx
var exchangeCashListModels []*models.ExchangeCashPersonList
... ...
... ... @@ -231,6 +231,8 @@ func (controller *SuMoneyController) ListExchangeList () {
listExchangeCashListQuery := &query.ListExchangeCashPersonQuery{}
activityId, _ := controller.GetInt64("activityId")
listExchangeCashListQuery.ExchangeCashActivityId = activityId
companyId, _ := controller.GetInt64("companyId")
listExchangeCashListQuery.CompanyId = companyId
exchangeCashPersonNameMatch := controller.GetString("personNameMatch")
listExchangeCashListQuery.ExchangeCashPersonNameMatch = exchangeCashPersonNameMatch
offset, _ := controller.GetInt("offset")
... ...