Exemplo n.º 1
0
 static function index_action()
 {
     $model_task = new Model_Task();
     $tasks = $model_task->get_all(['status' => 2], 10);
     if ($tasks['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(Lib_Helper::format_err_struct($tasks));
         $tasks = [];
     }
     $tasks = $tasks['data'];
     $ap_ids = [];
     $src_ids = [];
     foreach ($tasks as $_k => $_t) {
         $ap_ids[$_k] = isset($_t['ap_id']) ? $_t['ap_id'] : '';
         $src_ids[$_k] = isset($_t['src_id']) ? $_t['src_id'] : '';
     }
     $ap_model = new Model_AccessPoint();
     $aps = $ap_model->get_ap_by_ids($ap_ids);
     if ($aps['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(Lib_Helper::format_err_struct($aps));
         $aps = [];
     }
     $aps = $aps['data'];
     $source_model = new Model_Source();
     $sources = $source_model->get_sources_by_ids($src_ids);
     if ($sources['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(Lib_Helper::format_err_struct($sources));
         $sources = [];
     }
     $sources = $sources['data'];
     $gt_time = strtotime('-1 month');
     $source_model->set_table_name('t_src_statistics');
     $cond = ['update_time' => ['$gte' => $gt_time]];
     $source_statistics = $source_model->get_table()->get_all($cond, [], 0, 0, null, true);
     if ($source_statistics['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(Lib_Helper::format_err_struct($source_statistics));
         $source_statistics = [];
     }
     $source_statistics = $source_statistics['data'];
     $statistics = [];
     foreach ($source_statistics as $v) {
         $day = date('m-d', $v['update_time']);
         $statistics[$day] = isset($statistics[$day]) ? $statistics[$day] : [];
         $statistics[$day]['total'] = isset($statistics[$day]['total']) ? $statistics[$day]['total'] : 0;
         $statistics[$day]['status_1'] = isset($statistics[$day]['status_1']) ? $statistics[$day]['status_1'] : 0;
         $statistics[$day]['status_other'] = isset($statistics[$day]['status_other']) ? $statistics[$day]['status_other'] : 0;
         $statistics[$day]['total'] += intval($v['total']);
         $statistics[$day]['status_1'] += intval($v['status_1']);
         $statistics[$day]['status_other'] = $statistics[$day]['total'] - $statistics[$day]['status_1'];
     }
     foreach ($statistics as $day => $v) {
         $source_statistics_min = isset($source_statistics_min) && $source_statistics_min < $v['status_1'] ? $source_statistics_min : $v['status_1'];
     }
     $_access = Module_Statistics_Action::get_index_month_charts();
     $access_date = $_access['access_date'];
     $receive_data = $_access['receive_data'];
     $send_data = $_access['send_data'];
     self::render('common/index', ['tasks' => $tasks, 'aps' => $aps, 'sources' => $sources, 'source_statistics' => $statistics, 'source_statistics_min' => $source_statistics_min, 'access_date' => $access_date, 'send_data' => $send_data, 'receive_data' => $receive_data]);
 }
Exemplo n.º 2
0
 public function action_send()
 {
     //Inserir tarefas no TimeSheet com data do horário comercial vigente (hoje se 5h-23h, ontem se 0h-5h)?
     $this->session = Session::instance();
     $task = new Model_Task();
     $task->batch_all($this->session->get('tsuser'));
     $this->request->headers['Content-Type'] = 'application/json';
     $this->request->response = my_json_encode(array('success' => 1, 'msg' => 'TimeSheet salvo com sucesso!'));
 }
Exemplo n.º 3
0
 /**
  * @param array $options
  * @return array
  */
 private static function _add_task_record_hook($options)
 {
     $current_task = self::current_task();
     // record
     $model_task = new Model_Task();
     $task_options = $options;
     $task_options['task_pid'] = posix_getpid();
     $task_options['create_time'] = $current_task->create_time;
     $before_record = function ($data) use($current_task, $task_options, $model_task) {
         $create = $model_task->create($current_task->id, $task_options, self::TASK_STATUS_RUNNING);
         return $create;
     };
     $after_record = function ($result) use($current_task, $model_task) {
         $status = self::TASK_STATUS_FINISH;
         if (!isset($result['errno'])) {
             $status = self::TASK_STATUS_FAILED;
         } elseif ($result['errno'] !== Const_Err_Base::ERR_OK) {
             if (isset($result[Const_DataAccess::MREK_STATUS]) && isset(self::$_module_task_stat_map[$result[Const_DataAccess::MREK_STATUS]])) {
                 $status = self::$_module_task_stat_map[$result[Const_DataAccess::MREK_STATUS]];
             } else {
                 $status = self::TASK_STATUS_FAILED;
             }
         }
         $upinfo = ['result' => $result, 'status' => $status, 'end_time' => time()];
         $all_counts = Module_ControlCentre_Counter::get_all_counts();
         if ($all_counts[Const_DataAccess::MREK_ERRNO] == Const_Err_Base::ERR_OK) {
             $counts = $all_counts[Const_DataAccess::MREK_DATA];
             foreach ($counts as $_k => $_c) {
                 if ($_c == 0) {
                     unset($counts[$_k]);
                 }
             }
             $upinfo['counts'] = $counts;
         }
         $upinfo['server'] = Module_ScheduledTask_Main::current_server_name();
         return $model_task->update($current_task->id, $upinfo);
     };
     $current_task->register_before_run_hook('record_create_task', $before_record);
     $current_task->register_after_run_hook('record_finish_task', $after_record);
 }
Exemplo n.º 4
0
 /**
  * @param int $task_id
  * @return array
  */
 private static function _get_task_status($task_id)
 {
     $rtn = [];
     if ($task_id > 0) {
         $model_task = new Model_Task();
         $tasks = $model_task->get_one_by_id($task_id);
         if ($tasks['errno'] !== Const_Err_Base::ERR_OK) {
             $rtn['msg'] = '任务信息获取失败!';
         } else {
             if (isset($tasks['data']['status'])) {
                 $rtn['status'] = $tasks['data']['status'];
             } else {
                 $rtn['msg'] = '未获取到任务状态!';
             }
         }
     } else {
         $rtn['msg'] = '任务ID错误!';
     }
     return $rtn;
 }
Exemplo n.º 5
0
 public function get_tasks_completed($user_id = 0, $date = '')
 {
     $tasks = new Model_Task();
     return $tasks->where('deleted', '=', FALSE)->where('complete', '=', TRUE)->where('list_id', '=', $this->id)->where('user_id', '=', (int) $user_id)->order_by('sequence', 'ASC')->where_date($date)->find_all();
 }
Exemplo n.º 6
0
 public function action_edit_task()
 {
     if (Input::is_ajax()) {
         $task = Model_Task::find(intval(Input::post('task_id')));
         $task->name = trim(Security::clean(Input::post('task_content')));
         $task->save();
     }
     return false;
     // we return no content at all
 }
Exemplo n.º 7
0
 /**
  * @param int $id
  * @return mixed
  */
 static function task($id)
 {
     $task_model = new Model_Task();
     return $task_model->get_one_by_id($id);
 }