Skip to content

Commit

Permalink
remove funcs to storage
Browse files Browse the repository at this point in the history
  • Loading branch information
hasa1K committed Apr 26, 2024
1 parent 4a7b6a0 commit 9a7a69c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 18 deletions.
4 changes: 2 additions & 2 deletions sqle/api/controller/v2/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,13 +1022,13 @@ func UpdateWorkflowScheduleV2(c echo.Context) error {
}

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

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

This file was deleted.

69 changes: 69 additions & 0 deletions sqle/model/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,3 +438,72 @@ func (s *Storage) GetFeishuRecordsByTaskIds(taskIds []uint) ([]*FeishuScheduledR
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 9a7a69c

Please sign in to comment.