Skip to content

Commit

Permalink
Merge pull request #2391 from actiontech/fix-issue1500
Browse files Browse the repository at this point in the history
Fix issue1500
  • Loading branch information
ColdWaterLW authored Apr 26, 2024
2 parents a70917b + 9a7a69c commit 17a8d99
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 13 deletions.
10 changes: 8 additions & 2 deletions sqle/api/controller/v2/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,14 @@ func UpdateWorkflowScheduleV2(c echo.Context) error {
return controller.JSONBaseErrorReq(c, err)
}

if req.IsNotify != nil && *req.IsNotify && req.NotifyType != nil {
if err := createNotifyRecord(*req.NotifyType, curTaskRecord); err != nil {
if req.IsNotify != nil && *req.IsNotify && req.NotifyType != nil && req.ScheduleTime != nil {
if err := s.CreateNotifyRecord(*req.NotifyType, curTaskRecord); err != nil {
return controller.JSONBaseErrorReq(c, err)
}
}

if req.ScheduleTime == nil {
if err := s.CancelNotify(uint(taskIdUint)); err != nil {
return controller.JSONBaseErrorReq(c, err)
}
}
Expand Down
11 changes: 0 additions & 11 deletions sqle/api/controller/v2/workflow_ce.go

This file was deleted.

77 changes: 77 additions & 0 deletions sqle/model/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ func (s *Storage) UpdateWechatRecordByTaskId(taskId uint, m map[string]interface
return nil
}

func (s *Storage) DeleteWechatRecordByTaskId(taskId uint) error {
return s.db.Where("task_id = ?", taskId).Delete(&WechatRecord{}).Error
}

type FeishuScheduledRecord struct {
Model
TaskId uint `json:"task_id" gorm:"column:task_id"`
Expand Down Expand Up @@ -430,3 +434,76 @@ func (s *Storage) GetFeishuRecordsByTaskIds(taskIds []uint) ([]*FeishuScheduledR
}
return fsRecords, nil
}

func (s *Storage) DeleteFeishuRecordByTaskId(taskId uint) error {
return s.db.Where("task_id = ?", taskId).Delete(&FeishuScheduledRecord{}).Error
}

const (
NotifyTypeWechat = "wechat"
NotifyTypeFeishu = "feishu"
)

func (s *Storage) CreateNotifyRecord(notifyType string, curTaskRecord *WorkflowInstanceRecord) error {
switch notifyType {
case NotifyTypeWechat:
record := WechatRecord{
TaskId: curTaskRecord.TaskId,
}
if err := s.Save(&record); err != nil {
return nil
}
case NotifyTypeFeishu:
record := FeishuScheduledRecord{
TaskId: curTaskRecord.TaskId,
}
if err := s.Save(&record); err != nil {
return nil
}
default:
return nil
}
err := s.UpdateWorkflowInstanceRecordById(curTaskRecord.ID, map[string]interface{}{"need_scheduled_task_notify": true})
if err != nil {
return err
}
return nil
}

func (s *Storage) CancelNotify(taskId uint) error {
ir, err := s.GetWorkInstanceRecordByTaskId(fmt.Sprint(taskId))
if err != nil {
return err
}
// 定时上线原本不需要发送通知,就不需要再删除record记录
if !ir.NeedScheduledTaskNotify {
return nil
}

ir.NeedScheduledTaskNotify = false
if err := s.Save(ir); err != nil {
return err
}

// wechat
{
records, err := s.GetWechatRecordsByTaskIds([]uint{taskId})
if err != nil {
return err
}
if len(records) > 0 {
return s.DeleteWechatRecordByTaskId(taskId)
}
}
// feishu
{
records, err := s.GetFeishuRecordsByTaskIds([]uint{taskId})
if err != nil {
return err
}
if len(records) > 0 {
return s.DeleteFeishuRecordByTaskId(taskId)
}
}
return nil
}

0 comments on commit 17a8d99

Please sign in to comment.