作者 tangxvhui

优化

@@ -15,7 +15,7 @@ import ( @@ -15,7 +15,7 @@ import (
15 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log" 15 "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
16 ) 16 )
17 17
18 -func messageTaskStageAnomaly(companyId int) ([]*domain.MessagePersonal, error) { 18 +func messageTaskStageAnomaly() ([]*domain.MessagePersonal, error) {
19 transactionContext, err := factory.CreateTransactionContext(nil) 19 transactionContext, err := factory.CreateTransactionContext(nil)
20 if err != nil { 20 if err != nil {
21 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 21 return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
@@ -28,7 +28,7 @@ func messageTaskStageAnomaly(companyId int) ([]*domain.MessagePersonal, error) { @@ -28,7 +28,7 @@ func messageTaskStageAnomaly(companyId int) ([]*domain.MessagePersonal, error) {
28 }() 28 }()
29 taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext}) 29 taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
30 userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext}) 30 userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
31 - taskData, err := taskDao.TaskStageAnomalyAll(companyId) 31 + taskData, err := taskDao.TaskStageAnomalyAll()
32 if err != nil { 32 if err != nil {
33 return nil, fmt.Errorf("获取任务信息%s", err) 33 return nil, fmt.Errorf("获取任务信息%s", err)
34 } 34 }
@@ -112,36 +112,14 @@ func saveAllMessagePersonal(msgList []*domain.MessagePersonal) error { @@ -112,36 +112,14 @@ func saveAllMessagePersonal(msgList []*domain.MessagePersonal) error {
112 return nil 112 return nil
113 } 113 }
114 114
  115 +// 发送手机端通知
115 func appMessageSend() error { 116 func appMessageSend() error {
116 - transactionContext, err := factory.CreateTransactionContext(nil)  
117 - if err != nil {  
118 - return err  
119 - }  
120 - if err := transactionContext.StartTransaction(); err != nil {  
121 - return err  
122 - }  
123 - defer func() {  
124 - _ = transactionContext.RollbackTransaction()  
125 - }()  
126 -  
127 - taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})  
128 - //获取公司id  
129 - companyIds, err := taskDao.TaskStageAnomalyForCompany()  
130 - if err != nil {  
131 - return fmt.Errorf("获取公司id%s", err)  
132 - }  
133 - if err := transactionContext.CommitTransaction(); err != nil {  
134 - return err  
135 - }  
136 var appMessage []*domain.MessagePersonal 117 var appMessage []*domain.MessagePersonal
137 - for _, val := range companyIds {  
138 - messageList, err := messageTaskStageAnomaly(val) 118 + messageList, err := messageTaskStageAnomaly()
139 if err != nil { 119 if err != nil {
140 return fmt.Errorf("生成里程碑异常的消息通知失败%s", err) 120 return fmt.Errorf("生成里程碑异常的消息通知失败%s", err)
141 } 121 }
142 appMessage = append(appMessage, messageList...) 122 appMessage = append(appMessage, messageList...)
143 - }  
144 -  
145 openApi := serviceGateway.NewHttplibMmmOpenApiServiceGateway() 123 openApi := serviceGateway.NewHttplibMmmOpenApiServiceGateway()
146 for _, val := range appMessage { 124 for _, val := range appMessage {
147 _, err := openApi.PushInfo(1, constant.APP_MESSAGE_KEY, []int64{int64(val.TargetUserId)}, val.Title, val.Content) 125 _, err := openApi.PushInfo(1, constant.APP_MESSAGE_KEY, []int64{int64(val.TargetUserId)}, val.Title, val.Content)
@@ -149,7 +127,6 @@ func appMessageSend() error { @@ -149,7 +127,6 @@ func appMessageSend() error {
149 log.Logger.Error("发送远端openApi关于里程碑异常的消息通知:" + err.Error()) 127 log.Logger.Error("发送远端openApi关于里程碑异常的消息通知:" + err.Error())
150 } 128 }
151 } 129 }
152 -  
153 err = saveAllMessagePersonal(appMessage) 130 err = saveAllMessagePersonal(appMessage)
154 if err != nil { 131 if err != nil {
155 return fmt.Errorf("保存里程碑异常的消息通知失败%s", err) 132 return fmt.Errorf("保存里程碑异常的消息通知失败%s", err)
@@ -596,7 +596,7 @@ type TaskData4 struct { @@ -596,7 +596,7 @@ type TaskData4 struct {
596 } 596 }
597 597
598 // TaskStageAnomalyAll 获取所有异常的里程碑任务, 598 // TaskStageAnomalyAll 获取所有异常的里程碑任务,
599 -func (d TaskDao) TaskStageAnomalyAll(companyId int) ([]TaskData4, error) { 599 +func (d TaskDao) TaskStageAnomalyAll() ([]TaskData4, error) {
600 sqlStr := `select distinct 600 sqlStr := `select distinct
601 task.id as task_id, 601 task.id as task_id,
602 task."name" as task_name , 602 task."name" as task_name ,
@@ -608,11 +608,10 @@ func (d TaskDao) TaskStageAnomalyAll(companyId int) ([]TaskData4, error) { @@ -608,11 +608,10 @@ func (d TaskDao) TaskStageAnomalyAll(companyId int) ([]TaskData4, error) {
608 where 1=1 608 where 1=1
609 and task_stage.real_completed_at=0 609 and task_stage.real_completed_at=0
610 and task_stage.plan_completed_at<extract(epoch from now()) 610 and task_stage.plan_completed_at<extract(epoch from now())
611 - and task.company_id =?  
612 ` 611 `
613 result := []TaskData4{} 612 result := []TaskData4{}
614 tx := d.transactionContext.PgTx 613 tx := d.transactionContext.PgTx
615 - _, err := tx.Query(&result, sqlStr, companyId) 614 + _, err := tx.Query(&result, sqlStr)
616 return result, err 615 return result, err
617 } 616 }
618 617