作者 tangxvhui

增加 app 消息通知 的定时任务

@@ -19,6 +19,7 @@ func main() { @@ -19,6 +19,7 @@ func main() {
19 startSummaryEvaluation() 19 startSummaryEvaluation()
20 startConfirmEvaluationScore() 20 startConfirmEvaluationScore()
21 go notify.RunTaskSmsNotify() 21 go notify.RunTaskSmsNotify()
  22 + go notify.AppMessageRun()
22 go consumer.Run() 23 go consumer.Run()
23 web.Run() 24 web.Run()
24 } 25 }
1 package notify 1 package notify
2 2
3 -// 手机端 ,消息通知  
4 -// 定时任务检查业务,确定是否发送短信消息 3 +import (
  4 + "encoding/json"
  5 + "fmt"
  6 + "strconv"
  7 + "time"
5 8
6 -// 关于反馈异常的消息通知;早上9点 开始检查,并确认发送的消息  
7 -func taskRecordAnomaly() (map[string]string, error) { 9 + "github.com/linmadan/egglib-go/core/application"
  10 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
  11 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
  12 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
  13 + "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
  14 +)
  15 +
  16 +func messageTaskStageAnomaly(companyId int) ([]*domain.MessagePersonal, error) {
  17 + transactionContext, err := factory.CreateTransactionContext(nil)
  18 + if err != nil {
  19 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  20 + }
  21 + if err := transactionContext.StartTransaction(); err != nil {
  22 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  23 + }
  24 + defer func() {
  25 + _ = transactionContext.RollbackTransaction()
  26 + }()
  27 + taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
  28 + userDao := dao.NewUserDao(map[string]interface{}{"transactionContext": transactionContext})
  29 + taskData, err := taskDao.TaskStageAnomalyAll(companyId)
  30 + if err != nil {
  31 + return nil, fmt.Errorf("获取任务信息%s", err)
  32 + }
  33 + if len(taskData) == 0 {
8 return nil, nil 34 return nil, nil
  35 + }
  36 + var allMessage []*domain.MessagePersonal
  37 + for _, val := range taskData {
  38 + //获取我全上级
  39 + userList, err := userDao.AllParentUser(val.LeaderId)
  40 + if err != nil {
  41 + return nil, fmt.Errorf("获取上级人员信息%s", err)
  42 + }
  43 + if len(userList) == 0 {
  44 + continue
  45 + }
  46 +
  47 + for _, val2 := range userList {
  48 + content := ""
  49 + if val2.Level == 1 {
  50 + content = fmt.Sprintf("【您下级%s关注的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.TaskName)
  51 + } else if val2.Level == 2 {
  52 + content = fmt.Sprintf("【您下级%s负责的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.TaskName)
  53 + } else if val2.Level == 3 {
  54 + content = fmt.Sprintf("【您下级%s关注的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.TaskName)
  55 + }
  56 + if content == "" {
  57 + continue
  58 + }
  59 + payload := map[string]string{
  60 + "task_id": strconv.Itoa(val.TaskId),
  61 + "task_alias": val.TaskAlias,
  62 + "task_name": val.TaskName,
  63 + }
  64 + payloadStr, _ := json.Marshal(payload)
  65 + newMessage := domain.MessagePersonal{
  66 + Id: 0,
  67 + Types: domain.MessageTypesTaskStageApp,
  68 + TargetUserId: val2.Id,
  69 + ReadFlag: domain.MessageIsRead,
  70 + Title: content,
  71 + Content: content,
  72 + CreatedAt: time.Time{},
  73 + UpdatedAt: time.Time{},
  74 + Payload: string(payloadStr),
  75 + }
  76 + allMessage = append(allMessage, &newMessage)
  77 + }
  78 + }
  79 + if err := transactionContext.CommitTransaction(); err != nil {
  80 + return nil, err
  81 + }
  82 + return allMessage, nil
9 } 83 }
10 84
11 -// 关于里程碑异常的消息通知;早上9点 开始检查,并确认发送的消息  
12 -func taskStageAnomaly() (map[string]string, error) { 85 +func saveAllMessagePersonal(msgList []*domain.MessagePersonal) error {
  86 + transactionContext, err := factory.CreateTransactionContext(nil)
  87 + if err != nil {
  88 + return err
  89 + }
  90 + if err := transactionContext.StartTransaction(); err != nil {
  91 + return err
  92 + }
  93 + defer func() {
  94 + _ = transactionContext.RollbackTransaction()
  95 + }()
  96 + messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
  97 + "transactionContext": transactionContext,
  98 + })
  99 + for _, val := range msgList {
  100 + err = messageRepo.Save(val)
  101 + if err != nil {
  102 + return fmt.Errorf("保存MessagePersonal%s", err)
  103 + }
  104 + }
  105 + if err := transactionContext.CommitTransaction(); err != nil {
  106 + return err
  107 + }
  108 + return nil
  109 +}
13 110
14 - return nil, nil 111 +func appMessageSend() error {
  112 + transactionContext, err := factory.CreateTransactionContext(nil)
  113 + if err != nil {
  114 + return err
  115 + }
  116 + if err := transactionContext.StartTransaction(); err != nil {
  117 + return err
  118 + }
  119 + defer func() {
  120 + _ = transactionContext.RollbackTransaction()
  121 + }()
  122 +
  123 + taskDao := dao.NewTaskDao(map[string]interface{}{"transactionContext": transactionContext})
  124 + //获取公司id
  125 + companyIds, err := taskDao.TaskStageAnomalyForCompany()
  126 + if err != nil {
  127 + return fmt.Errorf("获取公司id%s", err)
  128 + }
  129 + if err := transactionContext.CommitTransaction(); err != nil {
  130 + return err
  131 + }
  132 + var appMessage []*domain.MessagePersonal
  133 + for _, val := range companyIds {
  134 + messageList, err := messageTaskStageAnomaly(val)
  135 + if err != nil {
  136 + return fmt.Errorf("生成里程碑异常的消息通知失败%s", err)
  137 + }
  138 + appMessage = append(appMessage, messageList...)
  139 + }
  140 + err = saveAllMessagePersonal(appMessage)
  141 + if err != nil {
  142 + return fmt.Errorf("保存里程碑异常的消息通知失败%s", err)
  143 + }
  144 + return nil
  145 +}
  146 +
  147 +// 关于里程碑异常的消息通知;早上9点 开始检查,并确认发送的消息
  148 +func AppMessageRun() {
  149 + nowTime := time.Now()
  150 + y, m, d := nowTime.Date()
  151 + t1 := time.Date(y, m, d, 9, 0, 0, 0, time.Local) //今天的9点
  152 + interval := t1.Sub(nowTime)
  153 + if interval < 0 {
  154 + interval = (24 * time.Hour) + interval
  155 + }
  156 + timer := time.NewTimer(interval)
  157 + for {
  158 + <-timer.C
  159 + err := appMessageSend()
  160 + if err != nil {
  161 + log.Logger.Error("发送关于里程碑异常的消息通知:" + err.Error())
  162 + }
  163 + timer.Reset(24 * time.Hour)
  164 + }
15 } 165 }
@@ -162,9 +162,9 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G @@ -162,9 +162,9 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G
162 } 162 }
163 } 163 }
164 // 作为上级,我的下级员工的异常里程碑 164 // 作为上级,我的下级员工的异常里程碑
165 - var taskStageList2 []dao.TaskStageData 165 + var taskList2 []dao.TaskData3
166 if len(childUserId) == 0 { 166 if len(childUserId) == 0 {
167 - taskStageList2, err = taskDao.TaskStageAnomalyByLeader(childUserId) 167 + taskList2, err = taskDao.TaskStageAnomalyByLeader(childUserId)
168 if err != nil { 168 if err != nil {
169 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error()) 169 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
170 } 170 }
@@ -176,9 +176,9 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G @@ -176,9 +176,9 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G
176 } 176 }
177 } 177 }
178 // 作为上级, 我的下下级员工的异常里程碑 178 // 作为上级, 我的下下级员工的异常里程碑
179 - var taskStageList3 []dao.TaskStageData 179 + var taskList3 []dao.TaskData3
180 if len(childUserId) == 0 { 180 if len(childUserId) == 0 {
181 - taskStageList3, err = taskDao.TaskStageAnomalyByLeader(childUserId2) 181 + taskList3, err = taskDao.TaskStageAnomalyByLeader(childUserId2)
182 if err != nil { 182 if err != nil {
183 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error()) 183 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查任务里程碑异常的消息"+err.Error())
184 } 184 }
@@ -186,13 +186,14 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G @@ -186,13 +186,14 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G
186 186
187 msgList := []adapter.MessageListAdapter{} 187 msgList := []adapter.MessageListAdapter{}
188 for _, val := range taskStageList { 188 for _, val := range taskStageList {
189 - s := fmt.Sprintf("【您负责的项目【%s】里程碑未按时完成,请重点关注,积极寻找上级辅导。】", val.Name) 189 + s := fmt.Sprintf("【您负责的项目【%s】里程碑未按时完成,请重点关注,积极寻找上级辅导。】", val.TaskAlias)
190 msgList = append(msgList, adapter.MessageListAdapter{ 190 msgList = append(msgList, adapter.MessageListAdapter{
191 Content: s, 191 Content: s,
192 }) 192 })
193 payload := map[string]string{ 193 payload := map[string]string{
194 - "id": strconv.Itoa(val.Id),  
195 - "taskName": val.Name, 194 + "task_id": strconv.Itoa(val.TaskId),
  195 + "task_alias": val.TaskAlias,
  196 + "task_name": val.TaskName,
196 } 197 }
197 payloadStr, _ := json.Marshal(payload) 198 payloadStr, _ := json.Marshal(payload)
198 newMessage := domain.MessagePersonal{ 199 newMessage := domain.MessagePersonal{
@@ -211,14 +212,15 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G @@ -211,14 +212,15 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G
211 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 212 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
212 } 213 }
213 } 214 }
214 - for _, val := range taskStageList2 {  
215 - s := fmt.Sprintf("【您下级%s负责的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.Name) 215 + for _, val := range taskList2 {
  216 + s := fmt.Sprintf("【您下级%s负责的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.TaskAlias)
216 msgList = append(msgList, adapter.MessageListAdapter{ 217 msgList = append(msgList, adapter.MessageListAdapter{
217 Content: s, 218 Content: s,
218 }) 219 })
219 payload := map[string]string{ 220 payload := map[string]string{
220 - "id": strconv.Itoa(val.Id),  
221 - "taskName": val.Name, 221 + "task_id": strconv.Itoa(val.TaskId),
  222 + "task_alias": val.TaskAlias,
  223 + "task_name": val.TaskName,
222 } 224 }
223 payloadStr, _ := json.Marshal(payload) 225 payloadStr, _ := json.Marshal(payload)
224 newMessage := domain.MessagePersonal{ 226 newMessage := domain.MessagePersonal{
@@ -237,14 +239,15 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G @@ -237,14 +239,15 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G
237 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 239 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
238 } 240 }
239 } 241 }
240 - for _, val := range taskStageList3 {  
241 - s := fmt.Sprintf("【您下级%s关注的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.Name) 242 + for _, val := range taskList3 {
  243 + s := fmt.Sprintf("【您下级%s关注的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.TaskAlias)
242 msgList = append(msgList, adapter.MessageListAdapter{ 244 msgList = append(msgList, adapter.MessageListAdapter{
243 Content: s, 245 Content: s,
244 }) 246 })
245 payload := map[string]string{ 247 payload := map[string]string{
246 - "id": strconv.Itoa(val.Id),  
247 - "taskName": val.Name, 248 + "task_id": strconv.Itoa(val.TaskId),
  249 + "task_alias": val.TaskAlias,
  250 + "task_name": val.TaskName,
248 } 251 }
249 payloadStr, _ := json.Marshal(payload) 252 payloadStr, _ := json.Marshal(payload)
250 newMessage := domain.MessagePersonal{ 253 newMessage := domain.MessagePersonal{
@@ -265,13 +268,14 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G @@ -265,13 +268,14 @@ func (srv *MessagePersonalService) TodayMessageTaskStageAnomaly(param *command.G
265 } 268 }
266 //我作为任务相关人 269 //我作为任务相关人
267 for _, val := range taskStageList0 { 270 for _, val := range taskStageList0 {
268 - s := fmt.Sprintf("【您下级%s关注的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.Name) 271 + s := fmt.Sprintf("【您下级%s关注的项目【%s】里程碑未按时完成,请前往辅导。】", val.LeaderName, val.TaskName)
269 msgList = append(msgList, adapter.MessageListAdapter{ 272 msgList = append(msgList, adapter.MessageListAdapter{
270 Content: s, 273 Content: s,
271 }) 274 })
272 payload := map[string]string{ 275 payload := map[string]string{
273 - "id": strconv.Itoa(val.Id),  
274 - "taskName": val.Name, 276 + "task_id": strconv.Itoa(val.TaskId),
  277 + "task_alias": val.TaskAlias,
  278 + "task_name": val.TaskName,
275 } 279 }
276 payloadStr, _ := json.Marshal(payload) 280 payloadStr, _ := json.Marshal(payload)
277 newMessage := domain.MessagePersonal{ 281 newMessage := domain.MessagePersonal{
@@ -25,6 +25,9 @@ var PLATFORM_ADMIN_ID = 28 @@ -25,6 +25,9 @@ var PLATFORM_ADMIN_ID = 28
25 // 员工绩效平台ID 25 // 员工绩效平台ID
26 var PLATFORM_FONT_ID = 29 26 var PLATFORM_FONT_ID = 29
27 27
  28 +// app 应用消息通知
  29 +var APP_MESSAGE_KEY = "mmm.ability.performance"
  30 +
28 func init() { 31 func init() {
29 if os.Getenv("LOG_LEVEL") != "" { 32 if os.Getenv("LOG_LEVEL") != "" {
30 LOG_LEVEL = os.Getenv("LOG_LEVEL") 33 LOG_LEVEL = os.Getenv("LOG_LEVEL")
@@ -23,6 +23,7 @@ const ( @@ -23,6 +23,7 @@ const (
23 MessageTypesTaskStage MessageTypes = "task_stage" //任务里程碑未按时完成 23 MessageTypesTaskStage MessageTypes = "task_stage" //任务里程碑未按时完成
24 MessageTypesTaskRecord MessageTypes = "task_record" //任务每日反馈异常 24 MessageTypesTaskRecord MessageTypes = "task_record" //任务每日反馈异常
25 MessageTypesTaskModify MessageTypes = "task_modify" //修改任务 25 MessageTypesTaskModify MessageTypes = "task_modify" //修改任务
  26 + MessageTypesTaskStageApp MessageTypes = "task_stage-app" //任务里程碑未按时完成
26 ) 27 )
27 28
28 type MessageReadFlag string 29 type MessageReadFlag string
@@ -385,65 +385,58 @@ func (d *TaskDao) IncreaseAnomaly(id []int, incr int) error { @@ -385,65 +385,58 @@ func (d *TaskDao) IncreaseAnomaly(id []int, incr int) error {
385 } 385 }
386 386
387 // TaskStageData 387 // TaskStageData
388 -type TaskStageData struct {  
389 - Id int `pg:"id"`  
390 - Name string `pg:"name"` 388 +// type TaskStageData struct {
  389 +// TaskStageId int `pg:"task_stage_id"`
  390 +// TaskStageName string `pg:"task_stage_name"`
  391 +// LeaderName string `pg:"leader_name"`
  392 +// TaskAlias string `pg:"task_alias"`
  393 +// }
  394 +
  395 +type TaskData3 struct {
  396 + TaskId int `pg:"task_id"`
  397 + TaskName string `pg:"task_name"`
  398 + TaskAlias string `pg:"task_alias"`
391 LeaderName string `pg:"leader_name"` 399 LeaderName string `pg:"leader_name"`
392 } 400 }
393 401
394 // 根据负责人获取超期未完成的异常的里程碑任务 402 // 根据负责人获取超期未完成的异常的里程碑任务
395 -func (d *TaskDao) TaskStageAnomalyByLeader(leaderId []string) ([]TaskStageData, error) {  
396 - sqlStr := `select  
397 - task_stage.id,  
398 - task_stage."name" ,  
399 - task.leader ->>'name' as leader_name  
400 - from task_stage  
401 - join task on task.id=task_stage.task_id 403 +func (d *TaskDao) TaskStageAnomalyByLeader(leaderId []string) ([]TaskData3, error) {
  404 + sqlStr := `select distinct
  405 + task.id as task_id,
  406 + task.leader ->>'name' as leader_name,
  407 + task.alias as task_alias,
  408 + task.name as task_name
  409 + from task
  410 + join task_stage on task.id=task_stage.task_id
402 where 1=1 411 where 1=1
403 and task_stage.real_completed_at=0 and task_stage.plan_completed_at<extract(epoch from now()) 412 and task_stage.real_completed_at=0 and task_stage.plan_completed_at<extract(epoch from now())
404 and task.leader ->>'id' in(?) ` 413 and task.leader ->>'id' in(?) `
405 - result := []TaskStageData{} 414 + result := []TaskData3{}
406 tx := d.transactionContext.PgTx 415 tx := d.transactionContext.PgTx
407 _, err := tx.Query(&result, sqlStr, pg.In(leaderId)) 416 _, err := tx.Query(&result, sqlStr, pg.In(leaderId))
408 return result, err 417 return result, err
409 } 418 }
410 419
411 // 根据任务相关人获取超期未完成的异常的里程碑任务 420 // 根据任务相关人获取超期未完成的异常的里程碑任务
412 -func (d *TaskDao) TaskStageAnomalyByRelatedUser(relatedUserId int) ([]TaskStageData, error) {  
413 - sqlStr := `select  
414 - task_stage.id,  
415 - task_stage."name" ,  
416 - task.leader ->>'name' as leader_name  
417 - from task_stage  
418 - join task on task.id=task_stage.task_id 421 +func (d *TaskDao) TaskStageAnomalyByRelatedUser(relatedUserId int) ([]TaskData3, error) {
  422 + sqlStr := `select distinct
  423 + task.id as task_id,
  424 + task.leader ->>'name' as leader_name,
  425 + task.alias as task_alias,
  426 + task.name as task_name
  427 + from task
  428 + join task_stage on task.id=task_stage.task_id
419 where 1=1 429 where 1=1
420 and task_stage.real_completed_at=0 and task_stage.plan_completed_at<extract(epoch from now()) 430 and task_stage.real_completed_at=0 and task_stage.plan_completed_at<extract(epoch from now())
421 and task.related_user @>? ` 431 and task.related_user @>? `
422 432
423 relatedUser := fmt.Sprintf("[%d]", relatedUserId) 433 relatedUser := fmt.Sprintf("[%d]", relatedUserId)
424 - result := []TaskStageData{} 434 + result := []TaskData3{}
425 tx := d.transactionContext.PgTx 435 tx := d.transactionContext.PgTx
426 _, err := tx.Query(&result, sqlStr, relatedUser) 436 _, err := tx.Query(&result, sqlStr, relatedUser)
427 return result, err 437 return result, err
428 } 438 }
429 439
430 -// TaskStageAnomalyAll 获取所有异常的里程碑任务  
431 -func (d TaskDao) TaskStageAnomalyAll() ([]TaskStageData, error) {  
432 - sqlStr := `select  
433 - task_stage.id,  
434 - task_stage."name" ,  
435 - task.leader ->>'name' as leader_name  
436 - from task_stage  
437 - join task 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 -  
441 - result := []TaskStageData{}  
442 - tx := d.transactionContext.PgTx  
443 - _, err := tx.Query(&result, sqlStr)  
444 - return result, err  
445 -}  
446 -  
447 type TaskData2 struct { 440 type TaskData2 struct {
448 Id int `pg:"id"` 441 Id int `pg:"id"`
449 Name string `pg:"name"` 442 Name string `pg:"name"`
@@ -562,3 +555,54 @@ func (d *TaskDao) ListTask2ForHrbp(userId int, companyId int) ([]TaskData1, erro @@ -562,3 +555,54 @@ func (d *TaskDao) ListTask2ForHrbp(userId int, companyId int) ([]TaskData1, erro
562 return result, err 555 return result, err
563 556
564 } 557 }
  558 +
  559 +// 获取异常任务对应的公司
  560 +func (d *TaskDao) TaskStageAnomalyForCompany() ([]int, error) {
  561 + var companyIds []struct {
  562 + CompanyId int `pg:"company_id"`
  563 + }
  564 + sqlStr := `select distinct company_id
  565 + from task
  566 + where 1=1
  567 + and (task.warn_flag >0)`
  568 + result := []TaskData1{}
  569 + tx := d.transactionContext.PgTx
  570 + _, err := tx.Query(&result, sqlStr)
  571 + if err != nil {
  572 + return nil, err
  573 + }
  574 + var ids []int
  575 + for _, v := range companyIds {
  576 + ids = append(ids, v.CompanyId)
  577 + }
  578 + return ids, nil
  579 +}
  580 +
  581 +type TaskData4 struct {
  582 + TaskId int `pg:"task_id"`
  583 + TaskName string `pg:"task_name"`
  584 + TaskAlias string `pg:"task_alias"`
  585 + LeaderName string `pg:"leader_name"`
  586 + LeaderId int `pg:"leader_id"`
  587 +}
  588 +
  589 +// TaskStageAnomalyAll 获取所有异常的里程碑任务
  590 +func (d TaskDao) TaskStageAnomalyAll(companyId int) ([]TaskData4, error) {
  591 + sqlStr := `select distinct
  592 + task.id as task_id,
  593 + task."name" as task_name ,
  594 + task.alias as task_alias,
  595 + task.leader ->>'id' as leader_id,
  596 + task.leader ->>'name' as leader_name
  597 + from task
  598 + join task_stage on task.id=task_stage.task_id
  599 + where 1=1
  600 + and task_stage.real_completed_at=0
  601 + and task_stage.plan_completed_at<extract(epoch from now())
  602 + and task.company_id =?
  603 + `
  604 + result := []TaskData4{}
  605 + tx := d.transactionContext.PgTx
  606 + _, err := tx.Query(&result, sqlStr, companyId)
  607 + return result, err
  608 +}
@@ -31,7 +31,7 @@ func (d *UserDao) AllChildUser(userId int) ([]UserData1, error) { @@ -31,7 +31,7 @@ func (d *UserDao) AllChildUser(userId int) ([]UserData1, error) {
31 ( 31 (
32 select "user".id,"user".parent_id ,"user".account,"user".name, 1 as "level" 32 select "user".id,"user".parent_id ,"user".account,"user".name, 1 as "level"
33 from "user" 33 from "user"
34 - where "user".id=? 34 + where "user".id=? and "user".deleted_at isnull
35 ) 35 )
36 union 36 union
37 ( 37 (
@@ -39,6 +39,7 @@ func (d *UserDao) AllChildUser(userId int) ([]UserData1, error) { @@ -39,6 +39,7 @@ func (d *UserDao) AllChildUser(userId int) ([]UserData1, error) {
39 "parent_user"."level"+1 as "level" 39 "parent_user"."level"+1 as "level"
40 from "user" as "child_user" 40 from "user" as "child_user"
41 join t_user as "parent_user" on "parent_user".id="child_user".parent_id 41 join t_user as "parent_user" on "parent_user".id="child_user".parent_id
  42 + where "child_user".deleted_at isnull
42 ) 43 )
43 )select * from t_user ` 44 )select * from t_user `
44 result := []UserData1{} 45 result := []UserData1{}
@@ -47,10 +48,35 @@ func (d *UserDao) AllChildUser(userId int) ([]UserData1, error) { @@ -47,10 +48,35 @@ func (d *UserDao) AllChildUser(userId int) ([]UserData1, error) {
47 return result, err 48 return result, err
48 } 49 }
49 50
50 -func (d *UserDao) ChildUser(userId int) ([]UserData1, error) {  
51 - sqlStr := `select "user".id,"user".parent_id ,"user".account,"user".name 51 +// func (d *UserDao) ChildUser(userId int) ([]UserData1, error) {
  52 +// sqlStr := `select "user".id,"user".parent_id ,"user".account,"user".name
  53 +// from "user"
  54 +// where "user".parent_id=?`
  55 +// result := []UserData1{}
  56 +// tx := d.transactionContext.PgTx
  57 +// _, err := tx.Query(&result, sqlStr, userId)
  58 +// return result, err
  59 +// }
  60 +
  61 +// AllParentUser 获取我的全上级
  62 +func (d *UserDao) AllParentUser(userId int) ([]UserData1, error) {
  63 + sqlStr := `with
  64 +-- 人员自身以及全下级
  65 +recursive t_user as (
  66 + (
  67 + select "user".id,"user".parent_id ,"user".account,"user".name,1 as "level"
52 from "user" 68 from "user"
53 - where "user".parent_id=?` 69 + where "user".id=? and "user".deleted_at isnull
  70 + )
  71 + union
  72 + (
  73 + select "child_user".id,"child_user".parent_id,"child_user".account,"child_user".name,
  74 + "child_user"."level" + 1 as "level"
  75 + from "user" as "parent_user"
  76 + join t_user as "child_user" on "parent_user".id="child_user".parent_id
  77 + where "parent_user".id <>0 and "parent_user".deleted_at isnull
  78 + )
  79 +)select * from t_user `
54 result := []UserData1{} 80 result := []UserData1{}
55 tx := d.transactionContext.PgTx 81 tx := d.transactionContext.PgTx
56 _, err := tx.Query(&result, sqlStr, userId) 82 _, err := tx.Query(&result, sqlStr, userId)
@@ -18,6 +18,15 @@ type MessageOptions struct { @@ -18,6 +18,15 @@ type MessageOptions struct {
18 Receivers []int64 `json:"receivers"` // 消息接收者uid 18 Receivers []int64 `json:"receivers"` // 消息接收者uid
19 Title string `json:"title"` // 个推标题 19 Title string `json:"title"` // 个推标题
20 Content string `json:"content"` // 个推内容 20 Content string `json:"content"` // 个推内容
  21 + Ext MessageExt `json:"ext"` // 为保证请求正常,保留字段. 暂时用不到的字段。
  22 +}
  23 +
  24 +type MessageExt struct {
  25 + TransData struct {
  26 + MmmType string `json:"mmmType"`
  27 + MmmTitle string `json:"mmmTitle"`
  28 + MmmContent string `json:"mmmContent"`
  29 + } `json:"transData"`
21 } 30 }
22 31
23 // PushInfo 个推 32 // PushInfo 个推