new copy logic
This commit is contained in:
parent
b22284cf83
commit
b616de42ee
|
|
@ -260,63 +260,15 @@ func (s *Service) SyncTaskCompletion(ctx context.Context, taskID int) error {
|
|||
}
|
||||
|
||||
current := getResp.Task
|
||||
if current.Status == 5 {
|
||||
err := s.CompleteSubtasks(ctx, taskID)
|
||||
|
||||
// --- Определяем связанную задачу ---
|
||||
var linkedTaskID int
|
||||
|
||||
if current.IsCopyString == "1" {
|
||||
// если это копия — связанная это главная
|
||||
linkedTaskID = current.ParentID
|
||||
} else {
|
||||
// если это главная — связанная это копия
|
||||
linkedTaskID = current.CopyID
|
||||
}
|
||||
|
||||
if linkedTaskID == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
getPayload["taskId"] = linkedTaskID
|
||||
var getRespLinked struct {
|
||||
Task taskInfo `json:"task"`
|
||||
}
|
||||
if err := s.call(ctx, "tasks.task.get", getPayload, &getRespLinked); err != nil {
|
||||
if strings.Contains(err.Error(), "0: ") {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
linked := getRespLinked.Task
|
||||
if linked.TaskControl == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
var newStatus int
|
||||
if linked.Status != current.Status {
|
||||
if current.Status == 5 || current.Status == 4 {
|
||||
if linked.TaskControl == "" || linked.TaskControl != "Y" {
|
||||
newStatus = 5
|
||||
} else {
|
||||
newStatus = 4
|
||||
}
|
||||
}
|
||||
if current.Status == 2 {
|
||||
newStatus = 2
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
payload := map[string]interface{}{
|
||||
"taskId": linkedTaskID,
|
||||
"fields": map[string]interface{}{
|
||||
"STATUS": newStatus,
|
||||
},
|
||||
}
|
||||
|
||||
var resp struct {
|
||||
Result interface{} `json:"result"`
|
||||
}
|
||||
|
||||
return s.call(ctx, "tasks.task.update", payload, &resp)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Service) SetTaskControl(ctx context.Context, taskID int, control bool) error {
|
||||
|
|
@ -479,6 +431,7 @@ func (c *CRMTags) UnmarshalJSON(data []byte) error {
|
|||
|
||||
type TaskDetails struct {
|
||||
ID int `json:"id,string"`
|
||||
ParentID int `json:"parentId,string"`
|
||||
IsCopy *string `json:"ufAuto682289870673"`
|
||||
CopyID *string `json:"ufAuto889836441236"`
|
||||
ResponsibleID int `json:"responsibleId,string"`
|
||||
|
|
@ -545,6 +498,7 @@ func (s *Service) GetTaskDetails(ctx context.Context, taskID int) (*TaskDetails,
|
|||
"ALLOW_CHANGE_DEADLINE",
|
||||
"GROUP_ID",
|
||||
"TAGS",
|
||||
"PARENT_ID",
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -764,3 +718,45 @@ func (s *Service) GetCRMElementTitles(
|
|||
|
||||
return titles, nil
|
||||
}
|
||||
|
||||
type taskListResponse struct {
|
||||
Tasks []struct {
|
||||
ID int `json:"id,string"`
|
||||
} `json:"tasks"`
|
||||
}
|
||||
|
||||
func (s *Service) CompleteSubtasks(ctx context.Context, taskID int) error {
|
||||
// Получаем список подзадач
|
||||
var resp taskListResponse
|
||||
|
||||
err := s.call(
|
||||
ctx,
|
||||
"tasks.task.list",
|
||||
map[string]interface{}{
|
||||
"filter": map[string]interface{}{
|
||||
"PARENT_ID": taskID,
|
||||
},
|
||||
"select": []string{"ID"},
|
||||
},
|
||||
&resp,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get subtasks: %w", err)
|
||||
}
|
||||
|
||||
// Завершаем каждую подзадачу
|
||||
for _, task := range resp.Tasks {
|
||||
if err := s.call(
|
||||
ctx,
|
||||
"tasks.task.complete",
|
||||
map[string]interface{}{
|
||||
"taskId": task.ID,
|
||||
},
|
||||
nil,
|
||||
); err != nil {
|
||||
return fmt.Errorf("complete subtask %d: %w", task.ID, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
8
main.go
8
main.go
|
|
@ -58,14 +58,14 @@ func ensureAllObsInAuditors(auditorIDs, obsIDs []int) ([]int, bool) {
|
|||
}
|
||||
|
||||
func processTaskChangeEvent(ctx context.Context, event *BitrixEvent, mandatoryAuditors *[]int, bitrixService *bitrix.Service) error {
|
||||
changedByID, auditorIDS, err := bitrixService.GetTaskUsers(ctx, event.GetTaskId())
|
||||
changedByID, currentAuditorIDs, err := bitrixService.GetTaskUsers(ctx, event.GetTaskId())
|
||||
fmt.Println(changedByID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
obsIDs := *mandatoryAuditors
|
||||
auditorIDs, updateNeeded := ensureAllObsInAuditors(auditorIDS, obsIDs)
|
||||
auditorIDs, updateNeeded := ensureAllObsInAuditors(currentAuditorIDs, obsIDs)
|
||||
|
||||
err = bitrixService.SyncTaskCompletion(ctx, event.GetTaskId())
|
||||
if err != nil {
|
||||
|
|
@ -108,6 +108,10 @@ func processNewTaskEvent(ctx context.Context, event *BitrixEvent, mandatoryAudit
|
|||
|
||||
bitrixService.SetTaskAuditors(ctx, event.GetTaskId(), auditorIDS)
|
||||
|
||||
if taskInfo.CreatorID == taskInfo.ResponsibleID && taskInfo.ParentID == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
CRMElementNames, err := bitrixService.GetCRMElementTitles(ctx, taskInfo.CRMElements)
|
||||
|
||||
err = bitrixService.CreateTaskCopyAtomic(ctx, *taskInfo, auditorIDS, CRMElementNames)
|
||||
|
|
|
|||
Loading…
Reference in New Issue