123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- <?php
- namespace app\controllers;
- use Yii;
- use app\models\entity\Accounts;
- use yii\web\Request;
- use yii\rest\Controller;
- use app\models\UserModel;
- use app\models\TasksModel;
- use app\models\AccountModel;
- use app\models\LocomotiveModel;
- use app\models\EmployeesModel;
- use app\models\ProjectsModel;
- use app\models\ServiceModel;
- use app\models\entity\Sections;
- use app\models\entity\AsusgJob2Launch;
- use app\models\entity\Jobtypes;
- class ServiceController extends MainController
- {
- const PROJECT_TYPE_TO_START = 129;
- const PROJECT_TYPE_RFID_TO_START = 132;
-
- public $returnArrayWorks = ['result' => false, 'int'=> 0, 'error'=> ''];
- public function beforeAction($action)
- {
- parent::beforeAction($action);
- //$date = strtotime('-3 weeks');
- //$this->threeWeeksAgo = date('Y-m-d', $date);
- $key = Yii::$app->request->headers->get('uuid-key');
- $this->checkAuth($key);
- $headerContent = Yii::$app->request->headers->get('content-type');
- //\Yii::$app->response->format = \yii\web\Response::FORMAT_XML;
- //if ( 'application/json' == $headerContent ) {
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- //}
- return true;
- }
-
- /** Принять Запрос (SMoPP от ЕИПП) на проверку RFID метки секции Проверить RFIDМетку */
- public function actionCheckrfid()
- {
- $this->LogRequest();
- $params = ['action' => self::PROJECT_TYPE_RFID_TO_START, 'company' => 3, 'kind'=> 'ТР-3','loco_number' => '','depo' => '', 'depo_service'=> 'Братское'];
- $locomotiveModel = new LocomotiveModel();
- $projectsModel = new ProjectsModel();
- $serviceModel = new ServiceModel();
- $taskModel = new TasksModel();
- $userModel = new UserModel();
- $this->status(self::PROJECT_TYPE_RFID_TO_START);
- $arrayParams['series'] = Yii::$app->request->post('series');
- $arrayParams['number'] = Yii::$app->request->post('number');
- $arrayParams['subnumber'] = Yii::$app->request->post('subnumber');
- $arrayParams['dateTime'] = Yii::$app->request->post('dateTime');
- $arrayParams['rfid'] = Yii::$app->request->post('rfid');
- $arrayParams['sectionId'] = Yii::$app->request->post('sectionId');
- $params['diagnosticCard'] = Yii::$app->request->post('diagnosticCard');
- $params['dateTime'] = Yii::$app->request->post('dateTime');
- $params['loco_type'] = Yii::$app->request->post('series');
- $res = $serviceModel->addSections($arrayParams); // +
- $activeid = $projectsModel->addProject($params,$res->id); // Добавление новой записи в ProjectLocotech +
- $locomotiveModel->project_id = $activeid;
- $res = $locomotiveModel->getSectionRemarks($arrayParams, true); // +
- if ($activeid > 0) {
- $res = $projectsModel->StartProjectRequest($params['action'],$activeid);
- require_once ("../../functions.php");
- require_once ("doctrine/bootstrap.php");
- $proj = \Project::Find($activeid, $entityManager);
- $workers = $proj->GetWorkers();
- }
- $resultArray = [
- "workers" => $workers,
- "inspectionId" => $activeid,
- "inspectionIdCheck" => true,
- "error_code" => 200,
- "error_message" => "Success"
- ];
- return $resultArray;
- }
- /** Принять Запрос (SMoPP от ЕИПП) на проведение осмотра на дату и время */
- public function actionAddwork()
- {
- $this->LogRequest();
- $params = ['action' => self::PROJECT_TYPE_TO_START, 'company' => 3, 'depo_service'=> 'Братское'];
- $locomotiveModel = new LocomotiveModel();
- $projectsModel = new ProjectsModel();
- $serviceModel = new ServiceModel();
- $taskModel = new TasksModel();
- $userModel = new UserModel();
- $post = Yii::$app->request->post();
- if (!$serviceModel->checkPost($post)) {
- $resultArray = [
- 'error_code' => 200,
- 'error_message' => $serviceModel->errors['checkPost']
- ];
- return $resultArray;
- }
- $this->status(self::PROJECT_TYPE_TO_START);
- $arrayParams['series'] = Yii::$app->request->post('series');
- $arrayParams['number'] = Yii::$app->request->post('number');
- $arrayParams['subnumber'] = Yii::$app->request->post('subnumber');
- $arrayParams['dateTime'] = Yii::$app->request->post('dateTime');
- $arrayParams['sectionId'] = Yii::$app->request->post('sectionId');
- $params['series'] = Yii::$app->request->post('series');
- $params['number'] = Yii::$app->request->post('number');
- $params['subnumber'] = Yii::$app->request->post('subnumber');
- $params['dateTime'] = Yii::$app->request->post('dateTime');
- $params['diagnosticCard'] = Yii::$app->request->post('diagnosticCard');
- $params['loco_number'] = (int)Yii::$app->request->post('number');
- $params['kind'] = Yii::$app->request->post('kind');
- $res = $serviceModel->addSections($arrayParams);
- $activeid = $projectsModel->addProject($params, $res->id); // Добавление новой записи в ProjectLocotech +
- $locomotiveModel->project_id = $activeid;
- $res = $locomotiveModel->getSectionRemarks($arrayParams, true); // +
- if ($activeid > 0) {
- require_once ("../../functions.php");
- require_once ("doctrine/bootstrap.php");
- $proj = \Project::Find($activeid, $entityManager);
- $workers = $proj->GetWorkers();
- }
- $resultArray = [
- 'Employee' => $workers,
- 'ID' => $activeid,
- 'Date' => '2019-06-13 12:34:16',
- 'error_code' => 200,
- 'error_message' => 'Success',
- 'executeData' => $projectsModel->message,
- ];
- return $resultArray;
- }
-
-
- /** Принять Запрос (SMoPP от ЕИПП) на проведение осмотра на дату и время */
-
- public function actionGetworkstatus($user_id, $work_id)
- {
-
-
-
- $params = ['url' => 'http://devplatform.digitaldepot.ru:8085/Thingworx/Things/SMoPPIntegrationLibrary/Services/getUserWorks',
- 'param' => '0f9ed850-e473-11e2-aaad-ac162db0b20c',
- 'login' => 'ПройдаковИА',
- 'pass' => 'Ip15351112'
- ];
- $listWorks = json_decode($this->curlRequest2($params));
-
- //$arr = $this->worksStatusHandler($listWorks->data);
- //var_dump($listWorks->data);
- //$this->worksStatusHandler($user_uuid, $job_uuid);
-
- //->where(['jl.asusg_job_uuid' => '445943a8-36b8-11ea-aec2-2e728ce88125'])
- //->andWhere(['ai.uuid' => 'f37deefa-3849-11ea-a137-2e728ce88125'])
- //$this->worksStatusHandler($user_uuid, $job_uuid);
-
- return $this->worksStatusHandler($user_id, $work_id);//$this->curlRequest2($params);
- }
-
-
- public function status($active)
- {
- $date = (new \DateTime())->getTimestamp();
- $accounts = [
- [
- 'worker' => '7b8ebba7-c9a4-11e7-80cd-0050560110fa', 'date' => $date
- ], [
- 'worker' => 'f4a9cbc2-e472-11e2-aaad-ac162db0b20c', 'date' => $date
- ]
- ];
- $response = [];
- foreach ($accounts as $params) {
- $employeesModel = new EmployeesModel();
- $resp = $employeesModel->getEmployeeStatus($params);
- $resp = json_decode($resp);
- $response[$params['worker']] = ($resp->Status == "Уход") ? false : true;
- }
- foreach ($response as $key => $person) {
- if (strlen($key) > 5) {
- $accountEntity = \app\models\entity\Accounts::findOne(['uuid' => $key]);
- $accountEntity->employee_status = $person;
- $accountEntity->update();
- }
- }
- }
- public function actionAddworke()
- {
- $this->LogRequest();
- require_once ("../../functions.php");
- require_once ("doctrine/bootstrap.php");
- $res = \ProjectType::Find(self::PROJECT_TYPE_TO_START);
- $r = $res->GetAccounts();
- foreach ($r as $acc) {
- echo "$acc->id<br>";
- }
- die();
- }
- /* Запись запроса в таблицу логов api_log */
- public function Log($date, $post, $userIP, $userHost, $userAgent, $query, $method)
- {
- $serverIP = $_SERVER['SERVER_ADDR'];
- $sql_query = "INSERT INTO api_log SET"
- . " timestamp='$date',"
- . " post='$post',"
- . " user_ip='$userIP',"
- . " user_host='$userHost',"
- . " user_agent='$userAgent',"
- . " query='$query',"
- . " method='$method',"
- . " server_ip = '$serverIP'";
- $result = Yii::$app->db->createCommand($sql_query)->execute();
- return $result;
- }
- public function LogRequest()
- {
- return $this->Log(
- date('Y-m-d H:i:s'),
- Yii::$app->request->rawBody,
- Yii::$app->request->userIP,
- Yii::$app->request->userHost,
- Yii::$app->request->userAgent,
- Yii::$app->request->url,
- Yii::$app->request->method
- );
- }
-
-
- public function curlRequest2($params){
-
- $urlWithParam = $params['url'].'?user_id='. $params['param'] ;
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $urlWithParam);
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($curl, CURLOPT_USERPWD, $params['login'] . ":" . $params['pass']);
- curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json"));
- curl_setopt($curl, CURLOPT_TIMEOUT, 20);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- $result = curl_exec($curl);
- return $result;
- }
-
-
-
- public function worksStatusHandler($user_uuid, $job_uuid){
- //public function worksStatusHandler(){
-
-
- $accountsEntity = Accounts::find()->where(['uuid' => $user_uuid])->one();
- //var_dump($accountsEntity); exit;
- //if ( 0 == count($accountsEntity) ) {
- if ( null == $accountsEntity ) {
-
- $this->returnArrayWorks['error'] = 'Не найден сотрудник';
- return $this->returnArrayWorks;
- }
-
- $asusgJob2LaunchEntity = AsusgJob2Launch::find()->where(['asusg_job_uuid' => $job_uuid])->one();
- //if ( 0 == count($asusgJob2LaunchEntity) ) {
- if ( null == $asusgJob2LaunchEntity ) {
- $this->returnArrayWorks['error'] = 'Не найдена работа';
- return $this->returnArrayWorks;
- }
-
-
- //var_dump($asusgJob2LaunchEntity->tasks->id); exit;
- $row_last = (new \yii\db\Query())
- ->select(['t.assignees_arr','ai.id','t.status','t.id'])
- //->select(['t.assignees_arr'])
- ->from('`asusg_job2launch` as `jl`')
- ->leftJoin('`tasks` as `t`', 'jl.id = t.asusg_job_mapped_id')
- ->rightJoin('`accounts_internal` as `ai`', 't.assignees_arr = cast(ai.id as char)')
- ->where(['jl.asusg_job_uuid' => $job_uuid])
- ->andWhere(['ai.uuid' => $user_uuid])
- ->andWhere(['<>','t.parent_id', 0])
- ->all();
- if ( 0 == count($row_last) ) {
-
- $row_last = (new \yii\db\Query())
- ->select(['t.assignees_arr','t.status','t.id'])
- //->select(['t.assignees_arr'])
- //->from('`asusg_job2launch` as `jl`')
- ->from('`tasks` as `t`', 'jl.id = t.asusg_job_mapped_id')
- //->rightJoin('`accounts_internal` as `ai`', 't.assignees_arr = cast(ai.id as char)')
- //->where(['jl.asusg_job_uuid' => $job_uuid])
- //->andWhere(['ai.uuid' => $user_uuid])
- ->andWhere(['t.parent_id' => $asusgJob2LaunchEntity->tasks->id])
- ->all();
- }
- //var_dump($row_last) ;
- //exit;
- if ( 0 == count($row_last) ) {
- $this->returnArrayWorks['error'] = 'Работа не запланирована';
- return $this->returnArrayWorks;
- }
- $countWorks = count($row_last);
- $countWorksDone = 0;
- foreach($row_last as $work){
- if( 5 == $work['status'] ){
- $countWorksDone++;
- }
- }
- $doneWorks = (int)round((100/$countWorks)* $countWorksDone);
- if ( 0 <= $doneWorks ) {//var_dump('asda');
- $this->returnArrayWorks['result'] = true;
- $this->returnArrayWorks['int'] = $doneWorks;
- return $this->returnArrayWorks;
- }
- return $this->returnArrayWorks;
- //$sqlText = $row_last->createCommand()->getRawSql();
- //var_dump($sqlText);
- //var_dump($doneWorks);
- //exit;
-
- //$workParams = [];
- //foreach( $listWorks as $work){
- // $workParams[] = $work->id_work;
- // }
- // return AsusgJob2Launch::find()->where(['in','asusg_job_uuid',$workParams])->all();
- }
- }
|