作者 tangxvhui

优化

@@ -86,6 +86,79 @@ func messageTaskStageAnomaly() ([]*domain.MessagePersonal, error) { @@ -86,6 +86,79 @@ func messageTaskStageAnomaly() ([]*domain.MessagePersonal, error) {
86 return allMessage, nil 86 return allMessage, nil
87 } 87 }
88 88
  89 +// messageTaskRecordAnomaly 反馈异常
  90 +func messageTaskRecordAnomaly() ([]*domain.MessagePersonal, error) {
  91 + // transactionContext, err := factory.CreateTransactionContext(nil)
  92 + // if err != nil {
  93 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  94 + // }
  95 + // if err := transactionContext.StartTransaction(); err != nil {
  96 + // return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  97 + // }
  98 + // defer func() {
  99 + // _ = transactionContext.RollbackTransaction()
  100 + // }()
  101 + // taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
  102 + // userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
  103 + // taskData, err := taskDao.TaskRecordAnomalyAll()
  104 + // if err != nil {
  105 + // return nil, fmt.Errorf("获取任务信息%s", err)
  106 + // }
  107 + // if len(taskData) == 0 {
  108 + // return nil, nil
  109 + // }
  110 + // var allMessage []*domain.MessagePersonal
  111 + // for _, val := range taskData {
  112 + // //获取我全上级
  113 + // userList, err := userDao.AllParentUser(val.LeaderId)
  114 + // if err != nil {
  115 + // return nil, fmt.Errorf("获取上级人员信息%s", err)
  116 + // }
  117 + // if len(userList) == 0 {
  118 + // continue
  119 + // }
  120 + // //通知相关人员
  121 +
  122 + // //通知负责人
  123 + // for _, val2 := range userList {
  124 + // content := ""
  125 + // if val2.Level == 1 {
  126 + // content = fmt.Sprintf("【您负责的项目【%s】已超过%s日未反馈进度,请前往该战略任务进行反馈。】", val.TaskName)
  127 + // } else if val2.Level == 2 {
  128 + // content = fmt.Sprintf("【您下级%s负责的项目【%s】已超过%s日未反馈进度,请前往辅导。】", val.LeaderName, val.TaskName)
  129 + // } else if val2.Level == 3 {
  130 + // content = fmt.Sprintf("【您下级%s关注的项目【%s】已超过%s日未反馈进度,请前往辅导。】", val.LeaderName, val.TaskName)
  131 + // }
  132 + // if content == "" {
  133 + // continue
  134 + // }
  135 + // payload := map[string]string{
  136 + // "task_id": strconv.Itoa(val.TaskId),
  137 + // "task_alias": val.TaskAlias,
  138 + // "task_name": val.TaskName,
  139 + // }
  140 + // payloadStr, _ := json.Marshal(payload)
  141 + // newMessage := domain.MessagePersonal{
  142 + // Id: 0,
  143 + // Types: domain.MessageTypesTaskStageApp,
  144 + // TargetUserId: val2.Id,
  145 + // ReadFlag: domain.MessageIsRead,
  146 + // Title: content,
  147 + // Content: content,
  148 + // CreatedAt: time.Time{},
  149 + // UpdatedAt: time.Time{},
  150 + // Payload: string(payloadStr),
  151 + // }
  152 + // allMessage = append(allMessage, &newMessage)
  153 + // }
  154 + // }
  155 + // if err := transactionContext.CommitTransaction(); err != nil {
  156 + // return nil, err
  157 + // }
  158 + // return allMessage, nil
  159 + return nil, nil
  160 +}
  161 +
89 func saveAllMessagePersonal(msgList []*domain.MessagePersonal) error { 162 func saveAllMessagePersonal(msgList []*domain.MessagePersonal) error {
90 transactionContext, err := factory.CreateTransactionContext(nil) 163 transactionContext, err := factory.CreateTransactionContext(nil)
91 if err != nil { 164 if err != nil {
@@ -602,20 +602,8 @@ type TaskData4 struct { @@ -602,20 +602,8 @@ type TaskData4 struct {
602 LeaderId int `pg:"leader_id"` 602 LeaderId int `pg:"leader_id"`
603 } 603 }
604 604
605 -// TaskStageAnomalyAll 获取所有异常的里程碑任务, 605 +// TaskStageAnomalyAll 获取所有里程碑异常的任务,
606 func (d TaskDao) TaskStageAnomalyAll() ([]TaskData4, error) { 606 func (d TaskDao) TaskStageAnomalyAll() ([]TaskData4, error) {
607 - // sqlStr := `select distinct  
608 - // task.id as task_id,  
609 - // task."name" as task_name ,  
610 - // task.alias as task_alias,  
611 - // task.leader ->>'id' as leader_id,  
612 - // task.leader ->>'name' as leader_name  
613 - // from task  
614 - // join task_stage on task.id=task_stage.task_id  
615 - // where 1=1  
616 - // and task_stage.real_completed_at=0  
617 - // and task_stage.plan_completed_at<extract(epoch from now())  
618 - // `  
619 sqlStr := `select 607 sqlStr := `select
620 task.id as task_id, 608 task.id as task_id,
621 task."name" as task_name , 609 task."name" as task_name ,
@@ -635,6 +623,33 @@ and ( @@ -635,6 +623,33 @@ and (
635 return result, err 623 return result, err
636 } 624 }
637 625
  626 +type TaskData5 struct {
  627 + TaskId int `pg:"task_id"`
  628 + TaskName string `pg:"task_name"`
  629 + TaskAlias string `pg:"task_alias"`
  630 + LeaderName string `pg:"leader_name"`
  631 + LeaderId int `pg:"leader_id"`
  632 + Anomaly int `pg:"anomaly"`
  633 +}
  634 +
  635 +// TaskRecordAnomalyAll 获取所有反馈异常的任务,
  636 +func (d TaskDao) TaskRecordAnomalyAll() ([]TaskData5, error) {
  637 + sqlStr := `select
  638 + task.id as task_id,
  639 + task."name" as task_name ,
  640 + task.alias as task_alias,
  641 + task.anomaly,
  642 + task.leader ->>'id' as leader_id,
  643 + task.leader ->>'name' as leader_name
  644 +from task where 1=1
  645 +and task.deleted_at isnull
  646 +and task.anomaly>0 `
  647 + result := []TaskData5{}
  648 + tx := d.transactionContext.PgTx
  649 + _, err := tx.Query(&result, sqlStr)
  650 + return result, err
  651 +}
  652 +
638 type ListTask struct { 653 type ListTask struct {
639 SortBy1 int `pg:"sort_by_1"` 654 SortBy1 int `pg:"sort_by_1"`
640 CPlanCompletedAt int `pg:"c_plan_completed_at"` 655 CPlanCompletedAt int `pg:"c_plan_completed_at"`