FB_new_features_and_changes_task_control_system #2
|
|
@ -260,63 +260,15 @@ func (s *Service) SyncTaskCompletion(ctx context.Context, taskID int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
current := getResp.Task
|
current := getResp.Task
|
||||||
|
if current.Status == 5 {
|
||||||
|
err := s.CompleteSubtasks(ctx, taskID)
|
||||||
|
|
||||||
// --- Определяем связанную задачу ---
|
if err != nil {
|
||||||
var linkedTaskID int
|
return err
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
payload := map[string]interface{}{
|
return nil
|
||||||
"taskId": linkedTaskID,
|
|
||||||
"fields": map[string]interface{}{
|
|
||||||
"STATUS": newStatus,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp struct {
|
|
||||||
Result interface{} `json:"result"`
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.call(ctx, "tasks.task.update", payload, &resp)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) SetTaskControl(ctx context.Context, taskID int, control bool) error {
|
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 {
|
type TaskDetails struct {
|
||||||
ID int `json:"id,string"`
|
ID int `json:"id,string"`
|
||||||
|
ParentID int `json:"parentId,string"`
|
||||||
IsCopy *string `json:"ufAuto682289870673"`
|
IsCopy *string `json:"ufAuto682289870673"`
|
||||||
CopyID *string `json:"ufAuto889836441236"`
|
CopyID *string `json:"ufAuto889836441236"`
|
||||||
ResponsibleID int `json:"responsibleId,string"`
|
ResponsibleID int `json:"responsibleId,string"`
|
||||||
|
|
@ -545,6 +498,7 @@ func (s *Service) GetTaskDetails(ctx context.Context, taskID int) (*TaskDetails,
|
||||||
"ALLOW_CHANGE_DEADLINE",
|
"ALLOW_CHANGE_DEADLINE",
|
||||||
"GROUP_ID",
|
"GROUP_ID",
|
||||||
"TAGS",
|
"TAGS",
|
||||||
|
"PARENT_ID",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -764,3 +718,55 @@ func (s *Service) GetCRMElementTitles(
|
||||||
|
|
||||||
return titles, nil
|
return titles, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type taskListResponse struct {
|
||||||
|
Tasks []struct {
|
||||||
|
ID int `json:"id,string"`
|
||||||
|
Status int `json:"status,string"`
|
||||||
|
} `json:"tasks"`
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
TaskStatusSupposedly = 4 // ждет контроля
|
||||||
|
TaskStatusCompleted = 5 // завершена
|
||||||
|
)
|
||||||
|
|
||||||
|
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", "STATUS"},
|
||||||
|
},
|
||||||
|
&resp,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("get subtasks: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Завершаем каждую подзадачу
|
||||||
|
for _, task := range resp.Tasks {
|
||||||
|
if task.Status == TaskStatusCompleted || task.Status == TaskStatusSupposedly {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
12
main.go
12
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 {
|
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)
|
fmt.Println(changedByID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
obsIDs := *mandatoryAuditors
|
obsIDs := *mandatoryAuditors
|
||||||
auditorIDs, updateNeeded := ensureAllObsInAuditors(auditorIDS, obsIDs)
|
auditorIDs, updateNeeded := ensureAllObsInAuditors(currentAuditorIDs, obsIDs)
|
||||||
|
|
||||||
err = bitrixService.SyncTaskCompletion(ctx, event.GetTaskId())
|
err = bitrixService.SyncTaskCompletion(ctx, event.GetTaskId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -108,6 +108,10 @@ func processNewTaskEvent(ctx context.Context, event *BitrixEvent, mandatoryAudit
|
||||||
|
|
||||||
bitrixService.SetTaskAuditors(ctx, event.GetTaskId(), auditorIDS)
|
bitrixService.SetTaskAuditors(ctx, event.GetTaskId(), auditorIDS)
|
||||||
|
|
||||||
|
if taskInfo.CreatorID == taskInfo.ResponsibleID && taskInfo.ParentID != 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
CRMElementNames, err := bitrixService.GetCRMElementTitles(ctx, taskInfo.CRMElements)
|
CRMElementNames, err := bitrixService.GetCRMElementTitles(ctx, taskInfo.CRMElements)
|
||||||
|
|
||||||
err = bitrixService.CreateTaskCopyAtomic(ctx, *taskInfo, auditorIDS, CRMElementNames)
|
err = bitrixService.CreateTaskCopyAtomic(ctx, *taskInfo, auditorIDS, CRMElementNames)
|
||||||
|
|
@ -119,13 +123,13 @@ func processNewTaskEvent(ctx context.Context, event *BitrixEvent, mandatoryAudit
|
||||||
}
|
}
|
||||||
|
|
||||||
func isTaskControlNeeded(taskName string) bool {
|
func isTaskControlNeeded(taskName string) bool {
|
||||||
codeSubstrEnd := strings.Index(taskName, "#")
|
codeSubstrEnd := strings.IndexAny(taskName, "#*")
|
||||||
isCopy := strings.Index(taskName, "Копия ") == 0
|
isCopy := strings.Index(taskName, "Копия ") == 0
|
||||||
return codeSubstrEnd != -1 && !isCopy
|
return codeSubstrEnd != -1 && !isCopy
|
||||||
}
|
}
|
||||||
|
|
||||||
func isTaskControl(taskName string) bool {
|
func isTaskControl(taskName string) bool {
|
||||||
codeSubstrEnd := strings.Index(taskName, "#")
|
codeSubstrEnd := strings.IndexAny(taskName, "#*")
|
||||||
codeSubstr := taskName[0:codeSubstrEnd]
|
codeSubstr := taskName[0:codeSubstrEnd]
|
||||||
return strings.Contains(codeSubstr, "В") || strings.Contains(codeSubstr, "П")
|
return strings.Contains(codeSubstr, "В") || strings.Contains(codeSubstr, "П")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue