Compare commits
No commits in common. "dev" and "main" have entirely different histories.
|
|
@ -0,0 +1,7 @@
|
||||||
|
DB_CONN=postgres://btr_db_user:StrongPassword123@localhost:5432/btr_db
|
||||||
|
OBS_API_URL=https://script.google.com/macros/s/AKfycbwilIPLrUQR0hSFseTRQPyVQon4rO-TmXJ0bceovj9xwhC5GM3CelOtVnFAdlxFOqaQvQ/exec
|
||||||
|
DEPS_API_URL=https://script.google.com/macros/s/AKfycbyiRLAPyszxpYGCrwDreAJt3jxO4eXsNw31dylyMR_OBRr27FFhhYXl_1Uz_NanRUE6/exec
|
||||||
|
BITRIX_TASK_API_URL=https://thebest.bitrix24.ru/rest/334/748roorgdjcdji3f/
|
||||||
|
LOAD_BALANCER_API_URL=https://45.10.40.213.nip.io/balancer/api/balancer/send
|
||||||
|
LOAD_BALANCER_PRIVATE_KEY=89bab1c15544e7bb667b773df786e65f9aed0bf173a84e66e2a88aec3f0014d89a289807c34f71c876b79f67997c9ac281ffd19d00fe8582ebcda97660bddaa3
|
||||||
|
LOAD_BALANCER_PUBLIC_KEY=68929830b9a07e7c6fa1d4bdfbcafe798a50de4da2969e743fee690dfaec3fb4
|
||||||
|
|
@ -260,15 +260,63 @@ 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
|
||||||
|
|
||||||
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
linked := getRespLinked.Task
|
||||||
|
if linked.TaskControl == "" {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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{}{
|
||||||
|
"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 {
|
||||||
|
|
@ -431,7 +479,6 @@ 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"`
|
||||||
|
|
@ -498,7 +545,6 @@ func (s *Service) GetTaskDetails(ctx context.Context, taskID int) (*TaskDetails,
|
||||||
"ALLOW_CHANGE_DEADLINE",
|
"ALLOW_CHANGE_DEADLINE",
|
||||||
"GROUP_ID",
|
"GROUP_ID",
|
||||||
"TAGS",
|
"TAGS",
|
||||||
"PARENT_ID",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -718,55 +764,3 @@ 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
|
|
||||||
}
|
|
||||||
|
|
|
||||||
15
main.go
15
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, currentAuditorIDs, err := bitrixService.GetTaskUsers(ctx, event.GetTaskId())
|
changedByID, auditorIDS, 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(currentAuditorIDs, obsIDs)
|
auditorIDs, updateNeeded := ensureAllObsInAuditors(auditorIDS, obsIDs)
|
||||||
|
|
||||||
err = bitrixService.SyncTaskCompletion(ctx, event.GetTaskId())
|
err = bitrixService.SyncTaskCompletion(ctx, event.GetTaskId())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -108,10 +108,6 @@ 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)
|
||||||
|
|
@ -123,13 +119,12 @@ func processNewTaskEvent(ctx context.Context, event *BitrixEvent, mandatoryAudit
|
||||||
}
|
}
|
||||||
|
|
||||||
func isTaskControlNeeded(taskName string) bool {
|
func isTaskControlNeeded(taskName string) bool {
|
||||||
codeSubstrEnd := strings.IndexAny(taskName, "#*")
|
codeSubstrEnd := strings.Index(taskName, "#")
|
||||||
isCopy := strings.Index(taskName, "Копия ") == 0
|
return codeSubstrEnd != -1
|
||||||
return codeSubstrEnd != -1 && !isCopy
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func isTaskControl(taskName string) bool {
|
func isTaskControl(taskName string) bool {
|
||||||
codeSubstrEnd := strings.IndexAny(taskName, "#*")
|
codeSubstrEnd := strings.Index(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