123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- namespace app\models;
- use Yii;
- use app\models\entity\Tasks;
- use app\models\entity\AsusgJob2Launch;
- class MappingworksModel extends MainModel
- {
- private static $_instance;
- public $returnArrayWorks = ['result' => false, 'int'=> 0, 'error'=> ''];
- private $url = '/Thingworx/Things/2050UserLibraryExp/Services/';
- private $execMethod = 'work_to_execute';
- private $doneMethod = 'work_done';
-
- public static function workToExecute($tid,$test = 0)
- {
- $result = false;
-
- self::$_instance = new self();
-
- $GWparams = [
- 'url' => 'http://' . Yii::$app->params['api']['domain'] . self::$_instance->url,
- 'param' => [],
- 'login' => 'ПройдаковИА',
- 'pass' => 'Ip15351112'
- ];
-
- $tasksEntity = Tasks::findOne($tid);
-
- if ( null == $tasksEntity->asusg_job_mapped_id ) {
- Logs::addlog(2,'работы не нашел => '.$tid.' ->' . $tasksEntity->asusg_job_mapped_id);
-
- return $result;
- }
- Logs::addlog(2,'принял работу => '.$tid.', завершение команды => ' . $tasksEntity->accounts->uuid);
- Logs::addlog(2,'принял работу => '.$tid.', завершение команды => ' . $tasksEntity->asusgjob2launch->asusg_job_uuid);
- if( null == $tasksEntity->accounts->uuid || null == $tasksEntity->asusgjob2launch->asusg_job_uuid ) {
- Logs::addlog(2,'не нашел uuid-ы. id = ' . $tid);
- return $result;
- }
-
- $status = self::$_instance->worksStatusHandler( $tasksEntity->accounts->uuid, $tasksEntity->asusgjob2launch->asusg_job_uuid );
- $GWparams['param'] = ['id_work' => $tasksEntity->asusgjob2launch->asusg_job_uuid, 'user_id' => $tasksEntity->accounts->uuid];
-
- if ( $status ) {
- $GWparams['url'] .= self::$_instance->doneMethod;
- //Logs::addlog(4,json_encode($GWparams),true);
- ElasticLog::eipp($GWparams, $tasksEntity->asusgjob2launch->asusg_job_uuid, $tasksEntity->accounts->uuid);
- $execResult = self::$_instance->curlRequestUni($GWparams,'post');
- ElasticLog::eipp($execResult, $tasksEntity->asusgjob2launch->asusg_job_uuid, $tasksEntity->accounts->uuid, false);
- //Logs::addlog(4,$execResult);
- LogEippResponse::addLog($time . "done1" . $tasksEntity->asusgjob2launch->asusg_job_uuid, json_encode($GWparams) ,'Попытка закрыть, параметры');
- LogEippResponse::addLog($time . "done2" . $tasksEntity->asusgjob2launch->asusg_job_uuid, $execResult ,'Попытка закрыть, ответ от ЕИПП');
- Logs::addlog(4,'ФИО : '. $tasksEntity->accounts->name. ', Заказ наряд: '. $tasksEntity->asusgjob2launch->outfit . ', Секция: ' . $tasksEntity->project->sections->section_number.$tasksEntity->project->sections->letter);
- $result = self::$_instance->checkResponse($execResult);
- //$result = 'true';
- Logs::addlog(4,$result);
- LogEippResponse::addLog($time . "done4" . $tasksEntity->asusgjob2launch->asusg_job_uuid, $result ,'Работа должна закрыться');
- return $result;
- }
-
- Logs::addlog(2,'execMethod');
-
-
- $GWparams['url'] .= self::$_instance->execMethod;
- ElasticLog::eipp($GWparams, $tasksEntity->asusgjob2launch->asusg_job_uuid, $tasksEntity->accounts->uuid);
- $execResult = self::$_instance->curlRequestUni($GWparams,'post');
- ElasticLog::eipp($execResult, $tasksEntity->asusgjob2launch->asusg_job_uuid, $tasksEntity->accounts->uuid, false);
- LogEippResponse::addLog($time . "done" . $tasksEntity->asusgjob2launch->asusg_job_uuid, $execResult ,'Работа не должна закрыться');
- //var_dump($execResult);
- //$result = self::$_instance->checkResponse($execResult);
- // ЗАГЛУШКА
-
- $result = true;
-
- //var_dump($result);
-
- return $result;
- }
-
-
- public static function workToExecuteBegin($tid,$test = 0)
- {
- $result = false;
-
- self::$_instance = new self();
-
- $GWparams = [
- 'url' => 'http://' . Yii::$app->params['api']['domain'] . self::$_instance->url,
- 'param' => [],
- 'login' => 'ПройдаковИА',
- 'pass' => 'Ip15351112'
- ];
-
- $tasksEntity = Tasks::findOne($tid);
-
- if ( null == $tasksEntity->asusg_job_mapped_id ) {
- Logs::addlog(2,'работы не нашел => '.$tid.' ->' . $tasksEntity->asusg_job_mapped_id);
-
- return $result;
- }
- Logs::addlog(2,'принял работу => '.$tid.', завершение команды => ' . $tasksEntity->accounts->uuid);
- Logs::addlog(2,'принял работу => '.$tid.', завершение команды => ' . $tasksEntity->asusgjob2launch->asusg_job_uuid);
- if( null == $tasksEntity->accounts->uuid || null == $tasksEntity->asusgjob2launch->asusg_job_uuid ) {
- Logs::addlog(2,'не нашел uuid-ы. id = ' . $tid);
- return $result;
- }
-
- //$status = self::$_instance->worksStatusHandler( $tasksEntity->accounts->uuid, $tasksEntity->asusgjob2launch->asusg_job_uuid );
- $GWparams['param'] = ['id_work' => $tasksEntity->asusgjob2launch->asusg_job_uuid, 'user_id' => $tasksEntity->accounts->uuid];
-
-
-
- Logs::addlog(2,'execMethod');
-
-
- $GWparams['url'] .= self::$_instance->execMethod;
- ElasticLog::eipp($GWparams, $tasksEntity->asusgjob2launch->asusg_job_uuid, $tasksEntity->accounts->uuid);
- $execResult = self::$_instance->curlRequestUni($GWparams,'post');
- ElasticLog::eipp($execResult, $tasksEntity->asusgjob2launch->asusg_job_uuid, $tasksEntity->accounts->uuid, false);
- LogEippResponse::addLog($time . "done" . $tasksEntity->asusgjob2launch->asusg_job_uuid, $execResult ,'Работа не должна закрыться');
- //var_dump($execResult);
- //$result = self::$_instance->checkResponse($execResult);
- // ЗАГЛУШКА
-
- $result = true;
-
- //var_dump($result);
-
- return $result;
- }
-
- public static function checkResponse($execResult)
- {
- $conf = ['true' => true, 'false' => false];
- $execResult = json_decode($execResult,true);
- if ( is_array($execResult)) {
- foreach( $execResult['rows'] as $row) {
- $rowArray = json_decode($row["result"],true);
- foreach($rowArray as $key => $r) {
- if ( $key == 'result' and null != $r) {
- return $rowArray["result"];
- }
- }
-
- }
- }
- return false;
- }
-
-
- 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 ) {
-
- self::$_instance->returnArrayWorks['error'] = 'Не найден сотрудник';
- return false;//self::$_instance->returnArrayWorks;
- }
- */
-
- $asusgJob2LaunchEntity = AsusgJob2Launch::find()->where(['asusg_job_uuid' => $job_uuid])->one();
- //if ( 0 == count($asusgJob2LaunchEntity) ) {
- if ( null == $asusgJob2LaunchEntity ) {
- self::$_instance->returnArrayWorks['error'] = 'Не найдена работа';
- return false;//self::$_instance->returnArrayWorks;
- }
-
- //var_dump($asusgJob2LaunchEntity->tasks->id); exit;
- $qu = 1;
- $parLog = 'jl.asusg_job_uuid' . $job_uuid;
- $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) ) {
- $qu = 2;
- $parLog = 't.parent_id = '.$asusgJob2LaunchEntity->tasks->id;
- $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) ) {
- self::$_instance->returnArrayWorks['error'] = 'Работа не запланирована';
- return false;//self::$_instance->returnArrayWorks;
- }
- $countWorks = count($row_last);
- $countWorksDone = 1;
- foreach($row_last as $work){
- //Logs::addlog(2,'status =>' . $work['status']);
- if( 5 == $work['status'] ){
- $countWorksDone++;
- }
- }
- Logs::addlog(2,'Кол-во команд =>'.count($row_last). ', Сработал запрос №=' . $qu . ', переменная для проверки ' . $parLog);
- $doneWorks = (int)round((100/$countWorks)* $countWorksDone);
-
- Logs::addlog(2,'worksStatusHandler2 =>'.$doneWorks . ': (100/'.$countWorks.')* '.$countWorksDone);
-
- if ( 100 != $doneWorks ) {
- return false;
- }
- /*
- if ( 0 <= $doneWorks ) {//var_dump('asda');
- self::$_instance->returnArrayWorks['result'] = true;
- self::$_instance->returnArrayWorks['int'] = $doneWorks;
- return self::$_instance->returnArrayWorks;
- }
- */
- return true;//self::$_instance->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();
- }
-
- }
|