作者 tangxvhui

调整每日弹窗的查询

@@ -122,9 +122,11 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G @@ -122,9 +122,11 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G
122 messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{ 122 messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
123 "transactionContext": transactionContext, 123 "transactionContext": transactionContext,
124 }) 124 })
  125 + nowDay := time.Now().Format("2006-01-02")
125 cnt, _, err := messageRepo.Find(map[string]interface{}{ 126 cnt, _, err := messageRepo.Find(map[string]interface{}{
126 "types": domain.MessageTypesTaskStage, 127 "types": domain.MessageTypesTaskStage,
127 "targetUserId": param.UserId, 128 "targetUserId": param.UserId,
  129 + "createdAtDay": nowDay,
128 "limit": 1, 130 "limit": 1,
129 }) 131 })
130 if err != nil { 132 if err != nil {
@@ -331,9 +333,11 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command. @@ -331,9 +333,11 @@ func (srv *MessagePersonalService) TodayMessageTaskRecordAnomaly(param *command.
331 messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{ 333 messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
332 "transactionContext": transactionContext, 334 "transactionContext": transactionContext,
333 }) 335 })
  336 + nowDay := time.Now().Format("2006-01-02")
334 cnt, _, err := messageRepo.Find(map[string]interface{}{ 337 cnt, _, err := messageRepo.Find(map[string]interface{}{
335 "types": domain.MessageTypesTaskRecord, 338 "types": domain.MessageTypesTaskRecord,
336 "targetUserId": param.UserId, 339 "targetUserId": param.UserId,
  340 + "createdAtDay": nowDay,
337 "limit": 1, 341 "limit": 1,
338 }) 342 })
339 if err != nil { 343 if err != nil {
@@ -408,17 +408,21 @@ type TaskData3 struct { @@ -408,17 +408,21 @@ type TaskData3 struct {
408 408
409 // 根据负责人获取超期未完成的异常的里程碑任务 409 // 根据负责人获取超期未完成的异常的里程碑任务
410 func (d *TaskDao) TaskStageAnomalyByLeader(leaderId []string) ([]TaskData3, error) { 410 func (d *TaskDao) TaskStageAnomalyByLeader(leaderId []string) ([]TaskData3, error) {
411 - sqlStr := `select distinct 411 + sqlStr := `select
412 task.id as task_id, 412 task.id as task_id,
413 - task.leader ->>'name' as leader_name,  
414 - task.leader ->>'id' as leader_id, 413 + task."name" as task_name ,
415 task.alias as task_alias, 414 task.alias as task_alias,
416 - task.name as task_name  
417 - from task  
418 - join task_stage on task.id=task_stage.task_id  
419 - where 1=1  
420 - and task_stage.real_completed_at=0 and task_stage.plan_completed_at<extract(epoch from now())  
421 - and task.leader ->>'id' in(?) ` 415 + task.leader ->>'id' as leader_id,
  416 + task.leader ->>'name' as leader_name
  417 +from task where 1=1
  418 +and task.deleted_at isnull
  419 +and (
  420 + task.last_stage ->>'planCompletedAt'< task.last_stage ->>'realCompletedAt'
  421 + or
  422 + cast(COALESCE(task.current_stage ->>'plan_completed_at','0') as int) between 1 and floor(extract(epoch from now()))
  423 +)
  424 +and task.leader ->>'id' in(?) `
  425 +
422 result := []TaskData3{} 426 result := []TaskData3{}
423 tx := d.transactionContext.PgTx 427 tx := d.transactionContext.PgTx
424 _, err := tx.Query(&result, sqlStr, pg.In(leaderId)) 428 _, err := tx.Query(&result, sqlStr, pg.In(leaderId))
@@ -427,17 +431,20 @@ func (d *TaskDao) TaskStageAnomalyByLeader(leaderId []string) ([]TaskData3, erro @@ -427,17 +431,20 @@ func (d *TaskDao) TaskStageAnomalyByLeader(leaderId []string) ([]TaskData3, erro
427 431
428 // 根据任务相关人获取超期未完成的异常的里程碑任务 432 // 根据任务相关人获取超期未完成的异常的里程碑任务
429 func (d *TaskDao) TaskStageAnomalyByRelatedUser(relatedUserId int) ([]TaskData3, error) { 433 func (d *TaskDao) TaskStageAnomalyByRelatedUser(relatedUserId int) ([]TaskData3, error) {
430 - sqlStr := `select distinct 434 + sqlStr := `select
431 task.id as task_id, 435 task.id as task_id,
432 - task.leader ->>'name' as leader_name,  
433 - task.leader ->>'id' as leader_id, 436 + task."name" as task_name ,
434 task.alias as task_alias, 437 task.alias as task_alias,
435 - task.name as task_name  
436 - from task  
437 - join task_stage on task.id=task_stage.task_id  
438 - where 1=1  
439 - and task_stage.real_completed_at=0 and task_stage.plan_completed_at<extract(epoch from now())  
440 - and task.related_user @>? ` 438 + task.leader ->>'id' as leader_id,
  439 + task.leader ->>'name' as leader_name
  440 +from task where 1=1
  441 +and task.deleted_at isnull
  442 +and (
  443 + task.last_stage ->>'planCompletedAt'< task.last_stage ->>'realCompletedAt'
  444 + or
  445 + cast(COALESCE(task.current_stage ->>'plan_completed_at','0') as int) between 1 and floor(extract(epoch from now()))
  446 +)
  447 +and task.related_user @>? `
441 448
442 relatedUser := fmt.Sprintf("[%d]", relatedUserId) 449 relatedUser := fmt.Sprintf("[%d]", relatedUserId)
443 result := []TaskData3{} 450 result := []TaskData3{}
@@ -73,6 +73,9 @@ func (repo *MessagePersonalRepository) Find(param map[string]interface{}) (int, @@ -73,6 +73,9 @@ func (repo *MessagePersonalRepository) Find(param map[string]interface{}) (int,
73 if v, ok := param["payload"]; ok { 73 if v, ok := param["payload"]; ok {
74 query.Where("payload @>?", v) 74 query.Where("payload @>?", v)
75 } 75 }
  76 + if v, ok := param["createdAtDay"]; ok {
  77 + query.Where("to_char(created_at at time zone 'PRC' ,'YYYY-MM-DD')=?", v)
  78 + }
76 query.Order("id desc") 79 query.Order("id desc")
77 count, err := query.SelectAndCount() 80 count, err := query.SelectAndCount()
78 if err != nil { 81 if err != nil {