作者 陈志颖

test:更新重叠

@@ -185,3 +185,7 @@ @@ -185,3 +185,7 @@
185 BodyData:{} 185 BodyData:{}
186 2020/11/23 11:43:14.139 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/cash-pool?companyId=358.1606102993946891000 BodyData:{"code":0,"data":{"cashPoolId":10,"cash":2001,"companyId":358,"exchangedCash":4,"unExchangeCash":1997,"exchangedSuMoney":3,"unExchangeSuMoney":3498567.67,"rate":1.33,"lastRate":0,"createTime":"2020-11-17T11:02:21.013016+08:00"},"msg":"ok"} 186 2020/11/23 11:43:14.139 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/cash-pool?companyId=358.1606102993946891000 BodyData:{"code":0,"data":{"cashPoolId":10,"cash":2001,"companyId":358,"exchangedCash":4,"unExchangeCash":1997,"exchangedSuMoney":3,"unExchangeSuMoney":3498567.67,"rate":1.33,"lastRate":0,"createTime":"2020-11-17T11:02:21.013016+08:00"},"msg":"ok"}
187 2020/11/23 11:43:14.139 [D] [server.go:1925] | 127.0.0.1| 200 | 192.55553ms| match| GET  /cash-pool/cash-pool r:/cash-pool/cash-pool 187 2020/11/23 11:43:14.139 [D] [server.go:1925] | 127.0.0.1| 200 | 192.55553ms| match| GET  /cash-pool/cash-pool r:/cash-pool/cash-pool
  188 +2020/11/23 12:12:16.473 [I] [???:0] http server Running on http://:8082
  189 +2020/11/23 15:19:26.289 [I] [???:0] http server Running on http://:8082
  190 +2020/11/23 15:26:30.018 [I] [???:0] http server Running on http://:8082
  191 +2020/11/23 15:32:51.170 [I] [???:0] http server Running on http://:8082
@@ -59,7 +59,7 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt @@ -59,7 +59,7 @@ func (listIntervalService *ListIntervalService) CreateListInterval(createListInt
59 59
60 // 判断年榜时间是否和上个年榜重叠 60 // 判断年榜时间是否和上个年榜重叠
61 if len(listIntervals) > 0 { 61 if len(listIntervals) > 0 {
62 - if createListIntervalCommand.ListIntervalStartTime.Before(listIntervals[0].IntervalEndTime) || createListIntervalCommand.ListIntervalStartTime.Equal(listIntervals[0].IntervalEndTime){ 62 + if startTime.Before(listIntervals[0].IntervalEndTime.Local()) || startTime.Equal(listIntervals[0].IntervalEndTime.Local()){
63 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜开始时间必须大于上一个年榜结束时间") 63 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜开始时间必须大于上一个年榜结束时间")
64 } else { 64 } else {
65 // 创建排行榜时间命令 65 // 创建排行榜时间命令
@@ -211,6 +211,9 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt @@ -211,6 +211,9 @@ 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 + listIntervalFoundIntervalStartTime := listIntervalFound.IntervalStartTime.Local()
  215 + listIntervalFoundIntervalEndTime := listIntervalFound.IntervalEndTime.Local()
  216 +
214 // 获取榜单命令 217 // 获取榜单命令
215 listListIntervalQuery := &query.ListListIntervalQuery { 218 listListIntervalQuery := &query.ListListIntervalQuery {
216 CompanyId: listIntervalFound.CompanyId, 219 CompanyId: listIntervalFound.CompanyId,
@@ -224,16 +227,38 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt @@ -224,16 +227,38 @@ func (listIntervalService *ListIntervalService) UpdateListInterval(updateListInt
224 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 227 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
225 } 228 }
226 229
  230 + var currentListIntervalIndex int
  231 +
  232 + startTime := time.Date(updateListIntervalCommand.ListIntervalStartTime.Local().Year(), updateListIntervalCommand.ListIntervalStartTime.Local().Month(), updateListIntervalCommand.ListIntervalStartTime.Local().Day(), 0, 0, 0, 0, time.Local)
  233 + endTime := time.Date(updateListIntervalCommand.ListIntervalEndTime.Local().Year(), updateListIntervalCommand.ListIntervalEndTime.Local().Month(), updateListIntervalCommand.ListIntervalEndTime.Local().Day(), 23, 59, 59, 0, time.Local)
  234 +
227 // 判断年榜时间是否和上个年榜重叠 235 // 判断年榜时间是否和上个年榜重叠
228 if len(listIntervals) > 0 { 236 if len(listIntervals) > 0 {
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) { // 时间段重叠判断 237 + for i, listInterval := range listIntervals {
  238 + // 找到当前排行榜及排行榜所处位置
  239 + if listInterval.IntervalStartTime.Local().Equal(listIntervalFoundIntervalStartTime) && listInterval.IntervalEndTime.Local().Equal(listIntervalFoundIntervalEndTime) {
  240 + currentListIntervalIndex = i
  241 + }
  242 + }
  243 +
  244 + // 判断年榜时间重叠
  245 + if currentListIntervalIndex == 0 { // 当前排行榜时间为最新的,更新时开始时间不能小于等于上个活动结束时间
  246 + if startTime.Before(listIntervals[currentListIntervalIndex + 1].IntervalEndTime.Local()) || startTime.Equal(listIntervals[currentListIntervalIndex + 1].IntervalEndTime.Local()) { // 开始时间重叠判断
233 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠") 247 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
234 } 248 }
  249 + } else if currentListIntervalIndex > 0 { // 当前排行榜时间非最新,需要和上一个排行榜时间以及下一个排行榜时间对比
  250 +
  251 + // 结束时间不能大于下一个活动开始时间
  252 + if endTime.After(listIntervals[currentListIntervalIndex - 1].IntervalStartTime.Local()) || endTime.Equal(listIntervals[currentListIntervalIndex - 1].IntervalEndTime.Local()) { // 判断是否和上一个年榜时间重叠
  253 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
  254 + }
  255 +
  256 + // 开始时间不能小于上一个活动结束时间
  257 + if startTime.Before(listIntervals[currentListIntervalIndex + 1].IntervalEndTime.Local()) || startTime.Equal(listIntervals[currentListIntervalIndex + 1].IntervalEndTime.Local()) { // 判断和下一个年榜时间是否重叠
  258 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "年榜时间不能重叠")
235 } 259 }
236 } 260 }
  261 +
237 if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil { 262 if err := listIntervalFound.Update(tool_funs.SimpleStructToMap(updateListIntervalCommand)); err != nil {
238 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error()) 263 return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
239 } 264 }
@@ -966,18 +966,27 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -966,18 +966,27 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
966 // 更新兑换活动命令已兑换素币 966 // 更新兑换活动命令已兑换素币
967 updateExchangeCashActivityCommand.ExchangedSuMoney = activityFound.ExchangedSuMoney 967 updateExchangeCashActivityCommand.ExchangedSuMoney = activityFound.ExchangedSuMoney
968 968
  969 + var currentExchangeCashActivityIndex int
  970 +
969 // 获取该公司所有兑换现金活动 971 // 获取该公司所有兑换现金活动
970 if _, activities, err := exchangeCashActivityRepository.FindAll(map[string]interface{}{ 972 if _, activities, err := exchangeCashActivityRepository.FindAll(map[string]interface{}{
971 "companyId": activityFound.CompanyId, 973 "companyId": activityFound.CompanyId,
972 }); err != nil { 974 }); err != nil {
973 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 975 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
974 } else { 976 } else {
975 - for _, activity := range activities { 977 + for i, activity := range activities {
  978 + if activityFound.Deadline.Local().Format("2006-01-02") == activity.Deadline.Local().Format("2006-01-02") {
  979 + currentExchangeCashActivityIndex = i
  980 + }
  981 + }
  982 + for i, activity := range activities {
  983 + if i != currentExchangeCashActivityIndex {
976 if updateExchangeCashActivityCommand.Deadline.Local().Format("2006-01-02") == activity.Deadline.Local().Format("2006-01-02") { 984 if updateExchangeCashActivityCommand.Deadline.Local().Format("2006-01-02") == activity.Deadline.Local().Format("2006-01-02") {
977 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "兑换活动截止时间不能重合") 985 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "兑换活动截止时间不能重合")
978 } 986 }
979 } 987 }
980 } 988 }
  989 + }
981 990
982 // 更新兑换活动 991 // 更新兑换活动
983 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil { 992 if err := activityFound.Update(tool_funs.SimpleStructToMap(updateExchangeCashActivityCommand)); err != nil {