作者 陈志颖

test:年榜重叠

... ... @@ -211,14 +211,14 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateListIntervalCommand.ListIntervalId)))
}
// 获取上一个榜单
// 获取榜单命令
listListIntervalQuery := &query.ListListIntervalQuery {
CompanyId: listIntervalFound.CompanyId,
Offset: 1,
Limit: 1,
}
//获取上个年榜时间
//获取所有年榜
_, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -226,27 +226,29 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
// 判断年榜时间是否和上个年榜重叠
if len(listIntervals) > 0 {
if updateListIntervalCommand.ListIntervalStartTime.Before(listIntervals[0].IntervalEndTime) || updateListIntervalCommand.ListIntervalStartTime.Equal(listIntervals[0].IntervalEndTime){
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜开始时间必须大于上一个年榜结束时间")
} else { // 正常更新
if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if listIntervalUpdated, err := listIntervalRepository.Save(listIntervalFound); 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())
for _, listInterval := range listIntervals {
// 排除当前年榜
if !listInterval.IntervalStartTime.Equal(listIntervalFound.IntervalStartTime) && listInterval.IntervalEndTime.Equal(listIntervalFound.IntervalEndTime) {
if updateListIntervalCommand.ListIntervalStartTime.Before(listInterval.IntervalEndTime) && updateListIntervalCommand.ListIntervalStartTime.After(listInterval.IntervalEndTime) { // 时间段重叠判断
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
}
return listIntervalUpdated, nil
}
}
if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if listIntervalUpdated, err := listIntervalRepository.Save(listIntervalFound); 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 listIntervalUpdated, nil
}
} else { // 正常更新
if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
if listIntervalUpdated, err := listIntervalRepository.Save(listIntervalFound); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
} else {
... ...
... ... @@ -29,23 +29,18 @@ func (cashPool *CashPool) Update(data map[string]interface{}) error {
cashPool.Cash = cash.(float64)
}
if exchangedCash, ok := data["exchangedCash"]; ok {
//cashPool.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedCash.(float64)), 64)
cashPool.ExchangedCash = exchangedCash.(float64)
}
if unExchangeCash, ok := data["unExchangeCash"]; ok {
//cashPool.UnExchangeCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", unExchangeCash.(float64)), 64)
cashPool.UnExchangeCash = unExchangeCash.(float64)
}
if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok {
//cashPool.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedSuMoney.(float64)), 64)
cashPool.ExchangedSuMoney = exchangedSuMoney.(float64)
}
if unExchangeSuMoney, ok := data["unExchangeSuMoney"]; ok {
//cashPool.UnExchangeSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", unExchangeSuMoney.(float64)), 64)
cashPool.UnExchangeSuMoney = unExchangeSuMoney.(float64)
}
if rate, ok := data["rate"]; ok {
//cashPool.Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", rate.(float64)), 64)
cashPool.Rate = rate.(float64)
}
return nil
... ...
... ... @@ -100,7 +100,6 @@ func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]i
}
if nearest, ok := queryOptions["nearest"]; ok && nearest.(bool) != false {
t := time.Now().Local()
//endTime := time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, time.Local)
query = query.Where(`exchange_cash_activity.deadline <= ?`, t)
query = query.Where(`exchange_cash_activity.count_down = ?`, 0)
}
... ...