Skip to content

Commit

Permalink
Merge pull request #2368 from actiontech/fix-issue1473
Browse files Browse the repository at this point in the history
Fix issue1473
  • Loading branch information
ColdWaterLW authored Apr 19, 2024
2 parents f77fc8a + 65c4534 commit e3b5138
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 82 deletions.
2 changes: 1 addition & 1 deletion sqle/api/controller/v2/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ func UpdateWorkflowV2(c echo.Context) error {
type UpdateWorkflowScheduleReqV2 struct {
ScheduleTime *time.Time `json:"schedule_time"`
IsNotify *bool `json:"is_notify"`
NotifyType *string `json:"notify_type" enums:"Wechat"`
NotifyType *string `json:"notify_type" enums:"Wechat,feishu"`
}

// UpdateWorkflowScheduleV2
Expand Down
3 changes: 2 additions & 1 deletion sqle/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13810,7 +13810,8 @@ var doc = `{
"notify_type": {
"type": "string",
"enum": [
"Wechat"
"Wechat",
"feishu"
]
},
"schedule_time": {
Expand Down
3 changes: 2 additions & 1 deletion sqle/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -13794,7 +13794,8 @@
"notify_type": {
"type": "string",
"enum": [
"Wechat"
"Wechat",
"feishu"
]
},
"schedule_time": {
Expand Down
1 change: 1 addition & 0 deletions sqle/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3964,6 +3964,7 @@ definitions:
notify_type:
enum:
- Wechat
- feishu
type: string
schedule_time:
type: string
Expand Down
71 changes: 70 additions & 1 deletion sqle/model/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ type WechatRecord struct {

func (s *Storage) GetWechatRecordByStatus(status string) ([]WechatRecord, error) {
var wcRecords []WechatRecord
err := s.db.Where("oa_result = ?", status).Find(&wcRecords).Error
err := s.db.Where("oa_result = ?", status).Preload("Task").Find(&wcRecords).Error
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -362,3 +362,72 @@ func (s *Storage) UpdateWechatRecordByTaskId(taskId uint, m map[string]interface
}
return nil
}

type FeishuScheduledRecord struct {
Model
TaskId uint `json:"task_id" gorm:"column:task_id"`
OaResult string `json:"oa_result" gorm:"column:oa_result;default:\"INITIALIZED\""`
ApproveInstanceCode string `json:"approve_instance_code" gorm:"column:approve_instance_code"`

Task *Task `gorm:"foreignkey:TaskId"`
}

func (s *Storage) UpdateFeishuScheduledByTaskId(taskId uint, m map[string]interface{}) error {
err := s.db.Model(&FeishuScheduledRecord{}).Where("task_id = ?", taskId).Updates(m).Error
if err != nil {
return errors.New(errors.ConnectStorageError, err)
}
return nil
}

func (s *Storage) GetFeishuScheduledByStatus(status string) ([]FeishuScheduledRecord, error) {
var fsRecords []FeishuScheduledRecord
err := s.db.Where("oa_result = ?", status).Preload("Task").Find(&fsRecords).Error
if err != nil {
return nil, err
}
return fsRecords, nil
}

func (s *Storage) FeishuCancelScheduledTask(f FeishuScheduledRecord) error {
err := s.db.Transaction(func(tx *gorm.DB) error {
err := s.RejectScheduledInstanceRecord(f.TaskId)
if err != nil {
return err
}

f.OaResult = FeishuAuditStatusRejected
err = s.Save(&f)
if err != nil {
return err
}
return nil
})
return err
}

func (s *Storage) FeishuAgreeScheduledTask(f FeishuScheduledRecord) error {
err := s.db.Transaction(func(tx *gorm.DB) error {
err := s.AgreeScheduledInstanceRecord(f.TaskId)
if err != nil {
return err
}

f.OaResult = FeishuAuditStatusApprove
err = s.Save(&f)
if err != nil {
return err
}
return nil
})
return err
}

func (s *Storage) GetFeishuRecordsByTaskIds(taskIds []uint) ([]*FeishuScheduledRecord, error) {
var fsRecords []*FeishuScheduledRecord
err := s.db.Where("task_id in (?)", taskIds).Find(&fsRecords).Error
if err != nil {
return nil, err
}
return fsRecords, nil
}
1 change: 1 addition & 0 deletions sqle/model/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ var autoMigrateList = []interface{}{
&SqlManageEndpoint{},
&SQLDevRecord{},
&WechatRecord{},
&FeishuScheduledRecord{},
}

func (s *Storage) AutoMigrate() error {
Expand Down
32 changes: 10 additions & 22 deletions sqle/model/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ func (s *Storage) UpdateWorkflowInstanceRecordById(id uint, m map[string]interfa
return nil
}

func (s *Storage) UpdateWorkflowInstanceRecordByTaskId(taskId uint, m map[string]interface{}) error {
err := s.db.Model(&WorkflowInstanceRecord{}).Where("task_id = ?", taskId).Updates(m).Error
if err != nil {
return errors.New(errors.ConnectStorageError, err)
}
return nil
}

func (s *Storage) GetWorkInstanceRecordByTaskId(id string) (instanceRecord WorkflowInstanceRecord, err error) {
return instanceRecord, s.db.Where("task_id = ?", id).First(&instanceRecord).Error
}
Expand All @@ -276,32 +284,12 @@ func (s *Storage) GetWorkInstanceRecordByTaskIds(taskIds []uint) ([]*WorkflowIns
}

func (s *Storage) AgreeScheduledInstanceRecord(taskId uint) error {
insRecord := WorkflowInstanceRecord{}
err := s.db.Where("task_id = ?", taskId).Find(&insRecord).Error
if err != nil {
return err
}
insRecord.IsCanExec = true
err = s.Save(&insRecord)
if err != nil {
return err
}
return nil
return s.UpdateWorkflowInstanceRecordByTaskId(taskId, map[string]interface{}{"is_can_exec": true})
}

func (s *Storage) RejectScheduledInstanceRecord(taskId uint) error {
// 取消该task对应的定时上线任务,将WorkflowInstanceRecord表中的ScheduledAt字段设置为null
insRecord := WorkflowInstanceRecord{}
err := s.db.Where("task_id = ?", taskId).Find(&insRecord).Error
if err != nil {
return err
}
insRecord.ScheduledAt = nil
err = s.Save(&insRecord)
if err != nil {
return err
}
return nil
return s.UpdateWorkflowInstanceRecordByTaskId(taskId, map[string]interface{}{"scheduled_at": nil})
}

const (
Expand Down
52 changes: 0 additions & 52 deletions sqle/pkg/im/im.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,55 +187,3 @@ func BatchCancelApprove(workflowIds []string, user *model.User) {
}
}
}

func CreateScheduledApprove(taskId uint, projectId, workflowId string) {
newLog := log.NewEntry()
s := model.GetStorage()

workflow, err := dms.GetWorkflowDetailByWorkflowId(projectId, workflowId, s.GetWorkflowDetailWithoutInstancesByWorkflowID)
if err != nil {
newLog.Errorf("get workflow error: %v", err)
}
assignUserIds := workflow.CurrentAssigneeUser()

assignUsers, err := dms.GetUsers(context.TODO(), assignUserIds, controller.GetDMSServerAddress())
if err != nil {
newLog.Errorf("get user error: %v", err)
return
}

ims, err := s.GetAllIMConfig()
if err != nil {
newLog.Errorf("get im config error: %v", err)
return
}

for _, im := range ims {
if !im.IsEnable {
continue
}

systemVariables, err := s.GetAllSystemVariables()
if err != nil {
newLog.Errorf("get sqle url system variables error: %v", err)
continue
}

sqleUrl := systemVariables[model.SystemVariableSqleUrl].Value
workflowUrl := fmt.Sprintf("%v/project/%s/order/%s", sqleUrl, workflow.ProjectId, workflow.WorkflowId)
if sqleUrl == "" {
newLog.Errorf("sqle url is empty")
workflowUrl = ""
}

switch im.Type {
case model.ImTypeWechatAudit:
if err := CreateWechatAuditRecord(context.TODO(), im, workflow, assignUsers, workflowUrl, taskId); err != nil {
newLog.Errorf("create wechat audit error: %v", err)
continue
}
default:
newLog.Errorf("im type %s not found", im.Type)
}
}
}
4 changes: 0 additions & 4 deletions sqle/pkg/im/im_ce.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,3 @@ func CancelDingdingAuditInst(ctx context.Context, im model.IM, workflowIDs []str
func CreateWechatAuditTemplate(ctx context.Context, im model.IM) error {
return ErrCommunityEditionNotSupportWechatAudit
}

func CreateWechatAuditRecord(ctx context.Context, im model.IM, workflow *model.Workflow, assignUsers []*model.User, url string, taskId uint) error {
return ErrCommunityEditionNotSupportWechatAudit
}

0 comments on commit e3b5138

Please sign in to comment.