Show/Hide Toolbars

Руководство администратора

Подсчет трудозатрат + отправка комментария

Ссылки Назад Вверх Вперед

--[[ GENERAL ]]

 

COMMENT_TASK = 416665;--365522;

COMMENT_USER = 3;

 

local function isempty(s)

 return s == nil or s == ''

end

 

--[[ GET STORY INFO ]]

 

function get_story_info()

   local res = SQL:query(

       [[

           SELECT TOP 1

               td.ExtParam12133Value AS type,

               td2.TaskID AS storyId,

               td2.TaskText AS storyDescr,

               team.UserID AS teamLeadUserId

           FROM TasksInSubcat5641Denormalized td

               JOIN TasksInSubcat5574Denormalized td2 ON td.ExtParam11980NativeValue = td2.TaskID

               OUTER APPLY (

                   SELECT TOP 1 UserId

                   FROM ExtParamSelectUsersValues euv

                   WHERE euv.TaskID =  td2.ExtParam10435NativeValue AND euv.ExtParamID = 10433

               ) team

           WHERE td.TaskId = @TaskId

       ]],

       { TaskId = CONTEXT['Id'] }

   );

 

   local task = res[0];

   local short_task = string.sub(task.storyDescr, 0, utf8.offset(task.storyDescr, 60));

   task.storyShortText ='#' .. tostring(task.storyId) .. ' (' .. short_task  .. ')';

 

   return task;

end;

 

info = get_story_info();

 

--[[ GET PLAN / FACT ]]

 

function get_plan_fact()

   return SQL:query(

       "EXEC sp_cm_ustoryGetPlanFact NULL, @TaskId",

       { TaskId = CONTEXT['Id'] }

   );

end;

 

--[[ SEND COMMENT FUNC ]]

 

function send_comment(comment)

   local recipients;

   local recipients_in_copy;

 

   if not isempty(EVENTPARAMS.PerformerUserId) then

       recipients = EVENTPARAMS.PerformerUserId.Id;

       --table.insert(recipients, EVENTPARAMS.PerformerUserId.Id)

   end;

 

   if not isempty(info.teamLeadUserId) then

       recipients_in_copy = info.teamLeadUserId;

   end;

 

   SMART:execute_action('PostComment', null, 'task', {

       CommentAuthor = COMMENT_USER,

       CommentText = comment,

       Recipients = recipients,

       RecipCopies = recipients_in_copy,

       CommentType = 3,

       Task = COMMENT_TASK,

       ForcedEmail = false,

       CommentSMS = false,

       TextAsHTML = false,

       NoSubscription = false,

       MarkAsQuestion = true,

       CommentVisibleOnlyToRealRecipients = true

   });

end

 

--[[ MAIN ]]

 

function main()

   local plan_fact = get_plan_fact();

   local plan_amount = plan_fact[0]['planAmount'];

   local fact_amount = plan_fact[0]['factAmount'];

 

   -- если плана нет

   if plan_amount == 0 then

       if fact_amount > 1 then

           send_comment('Внесены трудозатраты по сценарию без плана ' .. info.storyShortText);

       end;

       return;

   end;

 

   local plan_fact_overage = (fact_amount * 100 / plan_amount) — 100;

   local plan_fact_overage_limit = 20;

 

  -- если план превышен

   if plan_fact_overage > plan_fact_overage_limit then

       return send_comment(

           'Превышение плана по сценарию ' .. info.storyShortText

           .. ' на ' .. string.format('%.f', plan_fact_overage) .. '% '

           .. '(факт: ' .. string.format('%.f', fact_amount) .. 'ч)'

       );

   end;

 

   print('everything is ok!');

end;

 

--[[ INIT ]]

 

if (info['type'] == 'Разработка') then

 main();

end;