コード例 #1
0
ファイル: AllocationController.php プロジェクト: hunglmtb/eb
 public function editJob(Request $request)
 {
     $data = $request->all();
     $job_id = $data['id'];
     $job_name = $data['name'];
     $value_type = $data['value_type'];
     $gas = $data['alloc_gas'];
     $oil = $data['alloc_oil'];
     $water = $data['alloc_water'];
     $comp = $data['alloc_comp'];
     $gaslift = $data['alloc_gaslift'];
     $condensate = $data['alloc_condensate'];
     $daybyday = $data['alloc_daybyday'];
     if ($gas == 0) {
         $comp = 0;
     }
     if ($data['clone'] == 1) {
         $r = AllocJob::where(['ID' => $job_id])->select('NETWORK_ID')->first();
         $network_id = $r->NETWORK_ID;
         $condition = array('ID' => -1);
         $allocjob = ['NAME' => $job_name, 'NETWORK_ID' => $network_id, 'VALUE_TYPE' => $value_type, 'ALLOC_GAS' => $gas, 'ALLOC_OIL' => $oil, 'ALLOC_WATER' => $water, 'ALLOC_COMP' => $comp, 'ALLOC_GASLIFT' => $gaslift, 'ALLOC_CONDENSATE' => $condensate, 'DAY_BY_DAY' => $daybyday];
         $tmp = AllocJob::updateOrCreate($condition, $allocjob);
         $new_job_id = $tmp->ID;
         $result = AllocRunner::where(['JOB_ID' => $job_id])->select('*')->get();
         foreach ($result as $row) {
             $old_runner_id = $row->ID;
             $allocRunner = AllocRunner::where(['ID' => $old_runner_id])->get(['JOB_ID', 'ORDER', 'ALLOC_TYPE', 'THEOR_PHASE']);
             $allocRunner->JOB_ID = $new_job_id;
             $allocRunner = json_decode(json_encode($allocRunner), true);
             $condition = array('ID' => -1);
             $tmp = AllocRunner::updateOrCreate($condition, $allocRunner);
             $new_runner_id = $tmp->ID;
             $alloc_runner_objects = AllocRunnerObjects::where(['RUNNER_ID' => $old_runner_id])->select(DB::raw($new_runner_id . ' AS RUNNER_ID'), 'OBJECT_TYPE', 'OBJECT_ID', 'DIRECTION', 'FIXED', 'MINUS')->get();
             $condition = array('ID' => -1);
             $tmp = AllocRunner::updateOrCreate($condition, $alloc_runner_objects);
         }
     } else {
         $param = ['NAME' => $job_name, 'VALUE_TYPE' => $value_type, 'ALLOC_GAS' => $gas, 'ALLOC_OIL' => $oil, 'ALLOC_WATER' => $water, 'ALLOC_COMP' => $comp, 'ALLOC_GASLIFT' => $gaslift, 'ALLOC_CONDENSATE' => $condensate, 'DAY_BY_DAY' => $daybyday];
         AllocJob::where(['ID' => $job_id])->update($param);
     }
     return response()->json('ok');
 }
コード例 #2
0
ファイル: DVController.php プロジェクト: hunglmtb/eb
 public function loadFormSetting(Request $request)
 {
     $data = $request->all();
     $result = array();
     $value = $data['value'];
     $task_id = isset($data['task_id']) ? $data['task_id'] : 0;
     switch ($value) {
         case 'ALLOC_CHECK':
         case 'ALLOC_RUN':
             $network = Network::getTableName();
             $allocJob = AllocJob::getTableName();
             $tm = [];
             $tm = DB::table($network . ' AS a')->join($allocJob . ' AS b', 'a.ID', '=', 'b.NETWORK_ID')->distinct()->get(['a.ID', 'a.NAME']);
             $alloc_job = AllocJob::where(['NETWORK_ID' => $tm[0]->ID])->get(['ID', 'NAME']);
             $result['network'] = $tm;
             $result['allocJob'] = $alloc_job;
             break;
         case 'VIS_REPORT':
             $result = Facility::all(['ID', 'NAME']);
             break;
         case 'FDC_EU':
             $models = ['Facility', 'EnergyUnitGroup', 'CodeReadingFrequency', 'CodeFlowPhase', 'CodeEventType', 'CodeAllocType', 'CodePlanType', 'CodeForecastType'];
             foreach ($models as $m) {
                 $tm = [];
                 $model = 'App\\Models\\' . $m;
                 $tm = $model::all(['ID', 'NAME']);
                 $result[$m] = $tm;
             }
             break;
         case 'FDC_FLOW':
             $models = ['Facility', 'CodeReadingFrequency', 'CodeFlowPhase'];
             foreach ($models as $m) {
                 $tm = [];
                 $model = 'App\\Models\\' . $m;
                 $tm = $model::all(['ID', 'NAME']);
                 $result[$m] = $tm;
             }
             break;
         case 'INT_IMPORT_DATA':
             $tm = [];
             $tm = IntConnection::all(['ID', 'NAME']);
             $intTagSet = IntTagSet::where(['CONNECTION_ID' => $tm[0]->ID])->get(['ID', 'NAME']);
             $result['IntConnection'] = $tm;
             $result['IntTagSet'] = $intTagSet;
             break;
         default:
             $result = [];
     }
     $task = TmWorkflowTask::where(['ID' => $task_id])->get();
     $result['task'] = $task;
     $result['value'] = $value;
     return response()->json(array('result' => $result));
 }
コード例 #3
0
ファイル: run.php プロジェクト: hunglmtb/eb
 private function exec_job($job_id, $from_date, $to_date)
 {
     $tmp = AllocJob::where(['ID' => $job_id])->select('NAME')->first();
     $job_name = $tmp['NAME'];
     $this->_log("Begin job {$job_name} (id:{$job_id}) from date: {$from_date}, to date: {$to_date} at " . date("Y-m-d H:i:s"), 2);
     //\DB::enableQueryLog ();
     $tmps = DB::table('alloc_runner AS a')->join('alloc_job AS b', 'a.job_id', '=', 'b.ID')->join('code_alloc_value_type AS c', 'c.id', '=', 'b.value_type')->where(['b.id' => $job_id])->orderBy('a.ORDER')->get(['a.ID AS RUNNER_ID', 'a.THEOR_VALUE_TYPE', 'a.ALLOC_TYPE', 'a.THEOR_PHASE', 'c.CODE AS ALLOC_ATTR_CODE', 'b.*']);
     //\Log::info ( \DB::getQueryLog () );
     $count = 0;
     foreach ($tmps as $row) {
         $alloc_attr = $row->ALLOC_ATTR_CODE;
         $alloc_type = $row->ALLOC_TYPE;
         $theor_attr = $row->THEOR_VALUE_TYPE;
         $theor_phase = $row->THEOR_PHASE;
         $alloc_oil = $row->ALLOC_OIL == 1;
         $alloc_gas = $row->ALLOC_GAS == 1;
         $alloc_water = $row->ALLOC_WATER == 1;
         $alloc_gaslift = $row->ALLOC_GASLIFT == 1;
         $alloc_condensate = $row->ALLOC_CONDENSATE == 1;
         $alloc_comp = $row->ALLOC_COMP == 1;
         $runner_id = $row->RUNNER_ID;
         if ($alloc_oil) {
             $this->run_runner($runner_id, $from_date, $to_date, $alloc_attr, 1, $theor_phase, $alloc_comp, $alloc_type, $theor_attr);
         }
         if ($alloc_gas) {
             $this->run_runner($runner_id, $from_date, $to_date, $alloc_attr, 2, $theor_phase, $alloc_comp, $alloc_type, $theor_attr);
         }
         if ($alloc_water) {
             $this->run_runner($runner_id, $from_date, $to_date, $alloc_attr, 3, $theor_phase, $alloc_comp, $alloc_type, $theor_attr);
         }
         if ($alloc_gaslift) {
             $this->run_runner($runner_id, $from_date, $to_date, $alloc_attr, 21, $theor_phase, $alloc_comp, $alloc_type, $theor_attr);
         }
         if ($alloc_condensate) {
             $this->run_runner($runner_id, $from_date, $to_date, $alloc_attr, 5, $theor_phase, $alloc_comp, $alloc_type, $theor_attr);
         }
         $count++;
     }
     if ($count == 0) {
         $this->_log("No runner to run", 2);
         $this->_log("End job ID: {$job_id} =====================================================================", 2);
     }
 }