作者 陈志颖

test:兑换活动截止时间

@@ -478,3 +478,73 @@ @@ -478,3 +478,73 @@
478 } 478 }
479 2020/11/22 21:46:19.214 [D] [server.go:2843] <====Send RequestId:POST./cash-pool/activity.1606052779207498000 BodyData:{"code":0,"data":{"activityId":94,"exchangeActivityName":"这是公司311的兑换活动7","companyId":311,"exchangedCash":0,"exchangedSuMoney":0,"deadline":"2028-01-06T23:59:59+08:00","countDown":2602,"rate":5,"createTime":"2020-11-22T21:46:19.209323+08:00"},"msg":"ok"} 479 2020/11/22 21:46:19.214 [D] [server.go:2843] <====Send RequestId:POST./cash-pool/activity.1606052779207498000 BodyData:{"code":0,"data":{"activityId":94,"exchangeActivityName":"这是公司311的兑换活动7","companyId":311,"exchangedCash":0,"exchangedSuMoney":0,"deadline":"2028-01-06T23:59:59+08:00","countDown":2602,"rate":5,"createTime":"2020-11-22T21:46:19.209323+08:00"},"msg":"ok"}
480 2020/11/22 21:46:19.214 [D] [server.go:1925] | 127.0.0.1| 200 | 7.123034ms| match| POST  /cash-pool/activity r:/cash-pool/activity 480 2020/11/22 21:46:19.214 [D] [server.go:1925] | 127.0.0.1| 200 | 7.123034ms| match| POST  /cash-pool/activity r:/cash-pool/activity
  481 +2020/11/22 22:01:13.392 [I] [???:0] http server Running on http://:8082
  482 +2020/11/22 22:01:24.461 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/cash-pool?companyId=311.1606053684461108000
  483 + Auth=
  484 + BodyData:{}
  485 +2020/11/22 22:01:24.667 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/cash-pool?companyId=311.1606053684461108000 BodyData:{"code":0,"data":{"cashPoolId":14,"cash":2000,"companyId":311,"exchangedCash":1007,"unExchangeCash":993,"exchangedSuMoney":196,"unExchangeSuMoney":1079,"rate":5.14,"lastRate":5,"createTime":"2020-11-18T01:46:49.196257+08:00"},"msg":"ok"}
  486 +2020/11/22 22:01:24.667 [D] [server.go:1925] | 127.0.0.1| 200 | 206.362552ms| match| GET  /cash-pool/cash-pool r:/cash-pool/cash-pool
  487 +2020/11/22 22:01:26.749 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/cash-pool?companyId=311.1606053686749200000
  488 + Auth=
  489 + BodyData:{}
  490 +2020/11/22 22:01:26.776 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/cash-pool?companyId=311.1606053686749200000 BodyData:{"code":0,"data":{"cashPoolId":14,"cash":2000,"companyId":311,"exchangedCash":1007,"unExchangeCash":993,"exchangedSuMoney":196,"unExchangeSuMoney":1079,"rate":5.14,"lastRate":5,"createTime":"2020-11-18T01:46:49.196257+08:00"},"msg":"ok"}
  491 +2020/11/22 22:01:26.776 [D] [server.go:1925] | 127.0.0.1| 200 | 27.660727ms| match| GET  /cash-pool/cash-pool r:/cash-pool/cash-pool
  492 +2020/11/22 22:01:33.761 [D] [server.go:2843] ====>Recv User:<nil> RequestId:GET./cash-pool/activity/?companyId=311&offset=0&limit=20&isEnd=true.1606053693761505000
  493 + Auth=
  494 + BodyData:{}
  495 +2020/11/22 22:01:33.791 [D] [server.go:2843] <====Send RequestId:GET./cash-pool/activity/?companyId=311&offset=0&limit=20&isEnd=true.1606053693761505000 BodyData:{"code":0,"data":{"activities":[{"activityId":79,"companyId":311,"countDown":1,"createTime":"2020-11-21T01:17:38.434336+08:00","deadline":1606060800000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":0,"exchangedSuMoney":0,"rate":5},{"activityId":77,"companyId":311,"countDown":1,"createTime":"2020-11-21T01:10:52.822645+08:00","deadline":1606060800000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":0,"exchangedSuMoney":0,"rate":5},{"activityId":78,"companyId":311,"countDown":1,"createTime":"2020-11-21T01:17:36.794075+08:00","deadline":1606060800000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":0,"exchangedSuMoney":0,"rate":5},{"activityId":81,"companyId":311,"countDown":2,"createTime":"2020-11-21T02:28:44.157965+08:00","deadline":1606147200000,"exchangeActivityName":"这是公司311的兑换活动7","exchangedCash":65,"exchangedSuMoney":13,"rate":5},{"activityId":83,"companyId":311,"countDown":6,"createTime":"2
  496 +2020/11/22 22:01:33.791 [D] [server.go:1925] | 127.0.0.1| 200 | 29.957451ms| match| GET  /cash-pool/activity/ r:/cash-pool/activity/
  497 +2020/11/22 22:02:18.823 [D] [server.go:2843] ====>Recv User:<nil> RequestId:PUT./cash-pool/activity/93.1606053738823832000
  498 + Auth=
  499 + BodyData:{
  500 + "exchangeActivityName": "这是更新后的公司10019的兑换活动,哈哈哈",
  501 + "deadline": "2020-12-08T16:00:00.000Z",
  502 + "exchangeRate": 10
  503 +}
  504 +2020/11/22 22:02:18.879 [D] [server.go:2843] <====Send RequestId:PUT./cash-pool/activity/93.1606053738823832000 BodyData:{"code":501,"msg":"内部服务出错:兑换活动截止时间不能重合"}
  505 +2020/11/22 22:02:18.879 [D] [server.go:1925] | 127.0.0.1| 200 | 55.769551ms| match| PUT  /cash-pool/activity/93 r:/cash-pool/activity/:activityId
  506 +2020/11/22 22:02:59.210 [D] [server.go:2843] ====>Recv User:<nil> RequestId:PUT./cash-pool/activity/93.1606053779210695000
  507 + Auth=
  508 + BodyData:{
  509 + "exchangeActivityName": "这是更新后的公司10019的兑换活动,哈哈哈",
  510 + "deadline": "2020-11-22T21:44:27.822562+08:00",
  511 + "exchangeRate": 10
  512 +}
  513 +2020/11/22 22:02:59.232 [D] [server.go:2843] <====Send RequestId:PUT./cash-pool/activity/93.1606053779210695000 BodyData:{"code":501,"msg":"内部服务出错:兑换活动截止时间不能重合"}
  514 +2020/11/22 22:02:59.232 [D] [server.go:1925] | 127.0.0.1| 200 | 21.503813ms| match| PUT  /cash-pool/activity/93 r:/cash-pool/activity/:activityId
  515 +2020/11/22 22:03:05.041 [D] [server.go:2843] ====>Recv User:<nil> RequestId:PUT./cash-pool/activity/93.1606053785041403000
  516 + Auth=
  517 + BodyData:{
  518 + "exchangeActivityName": "这是更新后的公司10019的兑换活动,哈哈哈",
  519 + "deadline": "2020-11-23T21:44:27.822562+08:00",
  520 + "exchangeRate": 10
  521 +}
  522 +2020/11/22 22:03:05.059 [D] [server.go:2843] <====Send RequestId:PUT./cash-pool/activity/93.1606053785041403000 BodyData:{"code":501,"msg":"内部服务出错:兑换活动截止时间不能重合"}
  523 +2020/11/22 22:03:05.059 [D] [server.go:1925] | 127.0.0.1| 200 | 17.980245ms| match| PUT  /cash-pool/activity/93 r:/cash-pool/activity/:activityId
  524 +2020/11/22 22:03:12.780 [D] [server.go:2843] ====>Recv User:<nil> RequestId:PUT./cash-pool/activity/93.1606053792780230000
  525 + Auth=
  526 + BodyData:{
  527 + "exchangeActivityName": "这是更新后的公司10019的兑换活动,哈哈哈",
  528 + "deadline": "2020-11-26T21:44:27.822562+08:00",
  529 + "exchangeRate": 10
  530 +}
  531 +2020/11/22 22:03:12.791 [D] [server.go:2843] <====Send RequestId:PUT./cash-pool/activity/93.1606053792780230000 BodyData:{"code":501,"msg":"内部服务出错:兑换活动截止时间不能重合"}
  532 +2020/11/22 22:03:12.796 [D] [server.go:1925] | 127.0.0.1| 200 | 16.047125ms| match| PUT  /cash-pool/activity/93 r:/cash-pool/activity/:activityId
  533 +2020/11/22 22:03:24.273 [D] [server.go:2843] ====>Recv User:<nil> RequestId:PUT./cash-pool/activity/93.1606053804273394000
  534 + Auth=
  535 + BodyData:{
  536 + "exchangeActivityName": "这是更新后的公司10019的兑换活动,哈哈哈",
  537 + "deadline": "2020-12-26T21:44:27.822562+08:00",
  538 + "exchangeRate": 10
  539 +}
  540 +2020/11/22 22:03:24.283 [D] [server.go:2843] <====Send RequestId:PUT./cash-pool/activity/93.1606053804273394000 BodyData:{"code":501,"msg":"内部服务出错:兑换活动截止时间不能重合"}
  541 +2020/11/22 22:03:24.283 [D] [server.go:1925] | 127.0.0.1| 200 | 9.873065ms| match| PUT  /cash-pool/activity/93 r:/cash-pool/activity/:activityId
  542 +2020/11/22 22:03:35.155 [D] [server.go:2843] ====>Recv User:<nil> RequestId:PUT./cash-pool/activity/93.1606053815155869000
  543 + Auth=
  544 + BodyData:{
  545 + "exchangeActivityName": "这是更新后的公司10019的兑换活动,哈哈哈",
  546 + "deadline": "2021-12-26T21:44:27.822562+08:00",
  547 + "exchangeRate": 10
  548 +}
  549 +2020/11/22 22:03:35.205 [D] [server.go:2843] <====Send RequestId:PUT./cash-pool/activity/93.1606053815155869000 BodyData:{"code":501,"msg":"内部服务出错:兑换活动截止时间不能重合"}
  550 +2020/11/22 22:03:35.205 [D] [server.go:1925] | 127.0.0.1| 200 | 49.68737ms| match| PUT  /cash-pool/activity/93 r:/cash-pool/activity/:activityId
@@ -68,6 +68,16 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -68,6 +68,16 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
68 cashPoolRepository = value 68 cashPoolRepository = value
69 } 69 }
70 70
  71 + // 兑换现金活动仓储初始化
  72 + var exchangeActivityRepository domain.ExchangeActivityRepository
  73 + if value, err := factory.CreateExchangeCashActivityRepository(map[string]interface{}{
  74 + "transactionContext": transactionContext,
  75 + }); err != nil {
  76 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  77 + } else {
  78 + exchangeActivityRepository = value
  79 + }
  80 +
71 //公司id判断 81 //公司id判断
72 count, _, err := employeeRepository.Find(map[string]interface{}{ 82 count, _, err := employeeRepository.Find(map[string]interface{}{
73 "companyId": createCashPoolCommand.CompanyId, 83 "companyId": createCashPoolCommand.CompanyId,
@@ -126,6 +136,21 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -126,6 +136,21 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
126 // 重新计算平均兑换汇率 136 // 重新计算平均兑换汇率
127 newRate := cashPools[0].ExchangedCash / systemExchangedSuMoney 137 newRate := cashPools[0].ExchangedCash / systemExchangedSuMoney
128 138
  139 + // 获取上次兑换活动兑换汇率查询
  140 + var lastActivityRate float64
  141 + listExchangeCashActivityQuery := map[string]interface{}{
  142 + "companyId": createCashPoolCommand.CompanyId,
  143 + }
  144 + if count, activities, err := exchangeActivityRepository.Find(listExchangeCashActivityQuery); err != nil {
  145 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  146 + } else {
  147 + if count > 1 {
  148 + lastActivityRate = activities[1].Rate
  149 + } else { // 未查询到相关兑换活动
  150 + lastActivityRate = 0
  151 + }
  152 + }
  153 +
129 // 更新现金池 154 // 更新现金池
130 newCashPool := &domain.CashPool{ 155 newCashPool := &domain.CashPool{
131 CashPoolId: cashPools[0].CashPoolId, 156 CashPoolId: cashPools[0].CashPoolId,
@@ -136,7 +161,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co @@ -136,7 +161,7 @@ func (cashPoolService *CashPoolService) CreateCashPool(createCashPoolCommand *co
136 ExchangedSuMoney: systemExchangedSuMoney, 161 ExchangedSuMoney: systemExchangedSuMoney,
137 UnExchangeSuMoney: systemUnExchangeSuMoney, 162 UnExchangeSuMoney: systemUnExchangeSuMoney,
138 Rate: newRate, 163 Rate: newRate,
139 - LastRate: cashPools[0].LastRate, 164 + LastRate: lastActivityRate,
140 CreateTime: time.Now().Local(), 165 CreateTime: time.Now().Local(),
141 } 166 }
142 // 保存现金池更新 167 // 保存现金池更新
@@ -337,7 +362,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang @@ -337,7 +362,7 @@ func (cashPoolService *CashPoolService) CreateExchangeCashActivity(createExchang
337 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 362 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
338 } else { 363 } else {
339 for _, activity := range activities { 364 for _, activity := range activities {
340 - if t2.Format("2006-01-02") <= activity.Deadline.Local().Format("2006-01-02") { 365 + if t2.Format("2006-01-02") == activity.Deadline.Local().Format("2006-01-02") {
341 //if t2.Before(activity.Deadline.Local()) || t2.Equal(activity.Deadline.Local()) { 366 //if t2.Before(activity.Deadline.Local()) || t2.Equal(activity.Deadline.Local()) {
342 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "兑换活动截止时间不能重合") 367 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "兑换活动截止时间不能重合")
343 } 368 }
@@ -936,7 +961,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang @@ -936,7 +961,7 @@ func (cashPoolService *CashPoolService) UpdateExchangeCashActivity(updateExchang
936 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 961 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
937 } else { 962 } else {
938 for _, activity := range activities { 963 for _, activity := range activities {
939 - if updateExchangeCashActivityCommand.Deadline.Local().Format("2006-01-02") < activity.Deadline.Local().Format("2006-01-02") { 964 + if updateExchangeCashActivityCommand.Deadline.Local().Format("2006-01-02") == activity.Deadline.Local().Format("2006-01-02") {
940 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "兑换活动截止时间不能重合") 965 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "兑换活动截止时间不能重合")
941 } 966 }
942 } 967 }
@@ -342,6 +342,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -342,6 +342,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
342 if err := searchTaskCommand.ValidateCommand(); err != nil { // 校验搜索命令 342 if err := searchTaskCommand.ValidateCommand(); err != nil { // 校验搜索命令
343 return nil, application.ThrowError(application.ARG_ERROR, err.Error()) 343 return nil, application.ThrowError(application.ARG_ERROR, err.Error())
344 } 344 }
  345 +
345 transactionContext, err := factory.CreateTransactionContext(nil) // 工厂类创建事务上下文 346 transactionContext, err := factory.CreateTransactionContext(nil) // 工厂类创建事务上下文
346 if err != nil { 347 if err != nil {
347 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 348 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -352,6 +353,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -352,6 +353,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
352 defer func() { 353 defer func() {
353 transactionContext.RollbackTransaction() 354 transactionContext.RollbackTransaction()
354 }() 355 }()
  356 +
355 var taskRepository domain.TaskRepository 357 var taskRepository domain.TaskRepository
356 if value, err := factory.CreateTaskRepository(map[string]interface{}{ 358 if value, err := factory.CreateTaskRepository(map[string]interface{}{
357 "transactionContext": transactionContext, 359 "transactionContext": transactionContext,
@@ -360,6 +362,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -360,6 +362,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
360 } else { 362 } else {
361 taskRepository = value 363 taskRepository = value
362 } 364 }
  365 +
363 var projectBelongRepository domain.ProjectBelongRepository 366 var projectBelongRepository domain.ProjectBelongRepository
364 if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{ 367 if value, err := factory.CreateProjectBelongRepository(map[string]interface{}{
365 "transactionContext": transactionContext, 368 "transactionContext": transactionContext,
@@ -368,6 +371,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -368,6 +371,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
368 } else { 371 } else {
369 projectBelongRepository = value 372 projectBelongRepository = value
370 } 373 }
  374 +
371 projectBelongMap := make(map[int]*domain.ProjectBelong) 375 projectBelongMap := make(map[int]*domain.ProjectBelong)
372 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{ 376 if _, projectBelongs, err := projectBelongRepository.Find(map[string]interface{}{
373 "companyId": searchTaskCommand.CompanyId, 377 "companyId": searchTaskCommand.CompanyId,
@@ -378,6 +382,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -378,6 +382,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
378 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong 382 projectBelongMap[projectBelong.ProjectBelongId] = projectBelong
379 } 383 }
380 } 384 }
  385 +
381 var customerValueRepository domain.CustomerValueRepository 386 var customerValueRepository domain.CustomerValueRepository
382 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{ 387 if value, err := factory.CreateCustomerValueRepository(map[string]interface{}{
383 "transactionContext": transactionContext, 388 "transactionContext": transactionContext,
@@ -386,6 +391,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -386,6 +391,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
386 } else { 391 } else {
387 customerValueRepository = value 392 customerValueRepository = value
388 } 393 }
  394 +
389 customerValueMap := make(map[int]*domain.CustomerValue) 395 customerValueMap := make(map[int]*domain.CustomerValue)
390 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{ 396 if _, customerValues, err := customerValueRepository.Find(map[string]interface{}{
391 "companyId": searchTaskCommand.CompanyId, 397 "companyId": searchTaskCommand.CompanyId,
@@ -396,6 +402,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -396,6 +402,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
396 customerValueMap[customerValue.CustomerValueId] = customerValue 402 customerValueMap[customerValue.CustomerValueId] = customerValue
397 } 403 }
398 } 404 }
  405 +
399 var taskNatureRepository domain.TaskNatureRepository 406 var taskNatureRepository domain.TaskNatureRepository
400 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{ 407 if value, err := factory.CreateTaskNatureRepository(map[string]interface{}{
401 "transactionContext": transactionContext, 408 "transactionContext": transactionContext,
@@ -404,6 +411,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -404,6 +411,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
404 } else { 411 } else {
405 taskNatureRepository = value 412 taskNatureRepository = value
406 } 413 }
  414 +
407 taskNatureMap := make(map[int]*domain.TaskNature) 415 taskNatureMap := make(map[int]*domain.TaskNature)
408 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{ 416 if _, taskNatures, err := taskNatureRepository.Find(map[string]interface{}{
409 "companyId": searchTaskCommand.CompanyId, 417 "companyId": searchTaskCommand.CompanyId,
@@ -414,6 +422,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask @@ -414,6 +422,7 @@ func (taskService *TaskService) SearchTask(searchTaskCommand *command.SearchTask
414 taskNatureMap[taskNature.TaskNatureId] = taskNature 422 taskNatureMap[taskNature.TaskNatureId] = taskNature
415 } 423 }
416 } 424 }
  425 +
417 if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(searchTaskCommand)); err != nil { 426 if count, tasks, err := taskRepository.Find(tool_funs.SimpleStructToMap(searchTaskCommand)); err != nil {
418 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 427 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
419 } else { 428 } else {