作者 陈志颖

test:年榜重叠

@@ -211,14 +211,14 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt @@ -211,14 +211,14 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
211 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateListIntervalCommand.ListIntervalId))) 211 return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateListIntervalCommand.ListIntervalId)))
212 } 212 }
213 213
214 - // 获取上一个榜单 214 + // 获取榜单命令
215 listListIntervalQuery := &query.ListListIntervalQuery { 215 listListIntervalQuery := &query.ListListIntervalQuery {
216 CompanyId: listIntervalFound.CompanyId, 216 CompanyId: listIntervalFound.CompanyId,
217 Offset: 1, 217 Offset: 1,
218 Limit: 1, 218 Limit: 1,
219 } 219 }
220 220
221 - //获取上个年榜时间 221 + //获取所有年榜
222 _, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery)) 222 _, listIntervals, err := listIntervalRepository.Find(tool_funs.SimpleStructToMap(listListIntervalQuery))
223 if err != nil { 223 if err != nil {
224 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 224 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -226,27 +226,29 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt @@ -226,27 +226,29 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
226 226
227 // 判断年榜时间是否和上个年榜重叠 227 // 判断年榜时间是否和上个年榜重叠
228 if len(listIntervals) > 0 { 228 if len(listIntervals) > 0 {
229 - if updateListIntervalCommand.ListIntervalStartTime.Before(listIntervals[0].IntervalEndTime) || updateListIntervalCommand.ListIntervalStartTime.Equal(listIntervals[0].IntervalEndTime){  
230 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜开始时间必须大于上一个年榜结束时间")  
231 - } else { // 正常更新  
232 - if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {  
233 - return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())  
234 - }  
235 -  
236 - if listIntervalUpdated, err := listIntervalRepository.Save(listIntervalFound); err != nil {  
237 - return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())  
238 - } else {  
239 - if err := transactionContext.CommitTransaction(); err != nil {  
240 - return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 229 + for _, listInterval := range listIntervals {
  230 + // 排除当前年榜
  231 + if !listInterval.IntervalStartTime.Equal(listIntervalFound.IntervalStartTime) && listInterval.IntervalEndTime.Equal(listIntervalFound.IntervalEndTime) {
  232 + if updateListIntervalCommand.ListIntervalStartTime.Before(listInterval.IntervalEndTime) && updateListIntervalCommand.ListIntervalStartTime.After(listInterval.IntervalEndTime) { // 时间段重叠判断
  233 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
241 } 234 }
242 - return listIntervalUpdated, nil  
243 } 235 }
244 } 236 }
  237 + if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
  238 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  239 + }
  240 + if listIntervalUpdated, err := listIntervalRepository.Save(listIntervalFound); err != nil {
  241 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  242 + } else {
  243 + if err := transactionContext.CommitTransaction(); err != nil {
  244 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  245 + }
  246 + return listIntervalUpdated, nil
  247 + }
245 } else { // 正常更新 248 } else { // 正常更新
246 if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil { 249 if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
247 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 250 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
248 } 251 }
249 -  
250 if listIntervalUpdated, err := listIntervalRepository.Save(listIntervalFound); err != nil { 252 if listIntervalUpdated, err := listIntervalRepository.Save(listIntervalFound); err != nil {
251 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 253 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
252 } else { 254 } else {
@@ -29,23 +29,18 @@ func (cashPool *CashPool) Update(data map[string]interface{}) error { @@ -29,23 +29,18 @@ func (cashPool *CashPool) Update(data map[string]interface{}) error {
29 cashPool.Cash = cash.(float64) 29 cashPool.Cash = cash.(float64)
30 } 30 }
31 if exchangedCash, ok := data["exchangedCash"]; ok { 31 if exchangedCash, ok := data["exchangedCash"]; ok {
32 - //cashPool.ExchangedCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedCash.(float64)), 64)  
33 cashPool.ExchangedCash = exchangedCash.(float64) 32 cashPool.ExchangedCash = exchangedCash.(float64)
34 } 33 }
35 if unExchangeCash, ok := data["unExchangeCash"]; ok { 34 if unExchangeCash, ok := data["unExchangeCash"]; ok {
36 - //cashPool.UnExchangeCash, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", unExchangeCash.(float64)), 64)  
37 cashPool.UnExchangeCash = unExchangeCash.(float64) 35 cashPool.UnExchangeCash = unExchangeCash.(float64)
38 } 36 }
39 if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok { 37 if exchangedSuMoney, ok := data["exchangedSuMoney"]; ok {
40 - //cashPool.ExchangedSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", exchangedSuMoney.(float64)), 64)  
41 cashPool.ExchangedSuMoney = exchangedSuMoney.(float64) 38 cashPool.ExchangedSuMoney = exchangedSuMoney.(float64)
42 } 39 }
43 if unExchangeSuMoney, ok := data["unExchangeSuMoney"]; ok { 40 if unExchangeSuMoney, ok := data["unExchangeSuMoney"]; ok {
44 - //cashPool.UnExchangeSuMoney, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", unExchangeSuMoney.(float64)), 64)  
45 cashPool.UnExchangeSuMoney = unExchangeSuMoney.(float64) 41 cashPool.UnExchangeSuMoney = unExchangeSuMoney.(float64)
46 } 42 }
47 if rate, ok := data["rate"]; ok { 43 if rate, ok := data["rate"]; ok {
48 - //cashPool.Rate, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", rate.(float64)), 64)  
49 cashPool.Rate = rate.(float64) 44 cashPool.Rate = rate.(float64)
50 } 45 }
51 return nil 46 return nil
@@ -100,7 +100,6 @@ func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]i @@ -100,7 +100,6 @@ func (repository *ExchangeCashActivityRepository) Find(queryOptions map[string]i
100 } 100 }
101 if nearest, ok := queryOptions["nearest"]; ok && nearest.(bool) != false { 101 if nearest, ok := queryOptions["nearest"]; ok && nearest.(bool) != false {
102 t := time.Now().Local() 102 t := time.Now().Local()
103 - //endTime := time.Date(t.Year(), t.Month(), t.Day(), 23, 59, 59, 0, time.Local)  
104 query = query.Where(`exchange_cash_activity.deadline <= ?`, t) 103 query = query.Where(`exchange_cash_activity.deadline <= ?`, t)
105 query = query.Where(`exchange_cash_activity.count_down = ?`, 0) 104 query = query.Where(`exchange_cash_activity.count_down = ?`, 0)
106 } 105 }