Skip to content

Commit 17a8d99

Browse files
authored
Merge pull request #2391 from actiontech/fix-issue1500
Fix issue1500
2 parents a70917b + 9a7a69c commit 17a8d99

File tree

3 files changed

+85
-13
lines changed

3 files changed

+85
-13
lines changed

sqle/api/controller/v2/workflow.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,14 @@ func UpdateWorkflowScheduleV2(c echo.Context) error {
10211021
return controller.JSONBaseErrorReq(c, err)
10221022
}
10231023

1024-
if req.IsNotify != nil && *req.IsNotify && req.NotifyType != nil {
1025-
if err := createNotifyRecord(*req.NotifyType, curTaskRecord); err != nil {
1024+
if req.IsNotify != nil && *req.IsNotify && req.NotifyType != nil && req.ScheduleTime != nil {
1025+
if err := s.CreateNotifyRecord(*req.NotifyType, curTaskRecord); err != nil {
1026+
return controller.JSONBaseErrorReq(c, err)
1027+
}
1028+
}
1029+
1030+
if req.ScheduleTime == nil {
1031+
if err := s.CancelNotify(uint(taskIdUint)); err != nil {
10261032
return controller.JSONBaseErrorReq(c, err)
10271033
}
10281034
}

sqle/api/controller/v2/workflow_ce.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

sqle/model/configuration.go

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ func (s *Storage) UpdateWechatRecordByTaskId(taskId uint, m map[string]interface
362362
return nil
363363
}
364364

365+
func (s *Storage) DeleteWechatRecordByTaskId(taskId uint) error {
366+
return s.db.Where("task_id = ?", taskId).Delete(&WechatRecord{}).Error
367+
}
368+
365369
type FeishuScheduledRecord struct {
366370
Model
367371
TaskId uint `json:"task_id" gorm:"column:task_id"`
@@ -430,3 +434,76 @@ func (s *Storage) GetFeishuRecordsByTaskIds(taskIds []uint) ([]*FeishuScheduledR
430434
}
431435
return fsRecords, nil
432436
}
437+
438+
func (s *Storage) DeleteFeishuRecordByTaskId(taskId uint) error {
439+
return s.db.Where("task_id = ?", taskId).Delete(&FeishuScheduledRecord{}).Error
440+
}
441+
442+
const (
443+
NotifyTypeWechat = "wechat"
444+
NotifyTypeFeishu = "feishu"
445+
)
446+
447+
func (s *Storage) CreateNotifyRecord(notifyType string, curTaskRecord *WorkflowInstanceRecord) error {
448+
switch notifyType {
449+
case NotifyTypeWechat:
450+
record := WechatRecord{
451+
TaskId: curTaskRecord.TaskId,
452+
}
453+
if err := s.Save(&record); err != nil {
454+
return nil
455+
}
456+
case NotifyTypeFeishu:
457+
record := FeishuScheduledRecord{
458+
TaskId: curTaskRecord.TaskId,
459+
}
460+
if err := s.Save(&record); err != nil {
461+
return nil
462+
}
463+
default:
464+
return nil
465+
}
466+
err := s.UpdateWorkflowInstanceRecordById(curTaskRecord.ID, map[string]interface{}{"need_scheduled_task_notify": true})
467+
if err != nil {
468+
return err
469+
}
470+
return nil
471+
}
472+
473+
func (s *Storage) CancelNotify(taskId uint) error {
474+
ir, err := s.GetWorkInstanceRecordByTaskId(fmt.Sprint(taskId))
475+
if err != nil {
476+
return err
477+
}
478+
// 定时上线原本不需要发送通知,就不需要再删除record记录
479+
if !ir.NeedScheduledTaskNotify {
480+
return nil
481+
}
482+
483+
ir.NeedScheduledTaskNotify = false
484+
if err := s.Save(ir); err != nil {
485+
return err
486+
}
487+
488+
// wechat
489+
{
490+
records, err := s.GetWechatRecordsByTaskIds([]uint{taskId})
491+
if err != nil {
492+
return err
493+
}
494+
if len(records) > 0 {
495+
return s.DeleteWechatRecordByTaskId(taskId)
496+
}
497+
}
498+
// feishu
499+
{
500+
records, err := s.GetFeishuRecordsByTaskIds([]uint{taskId})
501+
if err != nil {
502+
return err
503+
}
504+
if len(records) > 0 {
505+
return s.DeleteFeishuRecordByTaskId(taskId)
506+
}
507+
}
508+
return nil
509+
}

0 commit comments

Comments
 (0)