123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- <?php
- namespace app\models\procedure;
- use Yii;
- use yii\base\Model;
- use app\models\entity\Accounts;
- use app\models\entity\Companies;
- use app\models\entity\AsusgProject;
- use app\models\entity\Projecttypes;
- use app\models\entity\ProjectsLocotech;
- use app\models\entity\JobtypesTasktypes;
- use app\models\entity\ProjecttypesTasktypes;
- class AsusgBuildProjectFromMappingModel extends Model
- {
- private $companyId = 0;
- private $tmpGuid;
- private $current_task;
- private $current_jobtype;
- private $jobtype;
- private $taskPriority;
- private $taskNameprivate;
- private $command;
- private $done;
- private $initiator;
- private $projecttype;
- private $tasktype;
- private $locoserie;
- private $loconumber;
- private $asusg_job;
-
-
-
- public static function execute($initiator, $projecttype, $tasktype, $locoserie, $loconumber, $repairtype,$section1,$section2,$section3) {
-
- $this->initiator = $initiator,
- $this->projecttype = $projecttype,
- $this->tasktype = $tasktype,
- $this->locoserie = $locoserie,
- $this->loconumber = $loconumber,
- $this->asusg_job = $asusg_job,
- $this->repairtype = $repairtype,
- $this->section1 = $section1;
- $this->section2 = $section2;
- $this->section3 = $section3;
-
-
- if(!$this->GetCompanyId()) {
- return false;
- }
-
-
- if(!$this->GenerateAsusgProject()) {
- return false;
- }
-
-
- if(!$this->GenerateProject()) {
- return false;
- }
-
-
- if(!$this->RedefineCompanyId()) {
- return false;
- }
-
- if(!$this->attachCommands()) {
- return false;
- }
-
- if(!$this->attachCommandsToProj()) {
- return false;
- }
- }
-
- private function GetCompanyId(){
- $companiesEntity = Companies::find()->where(['id' => $this->initiator])->andWhere(['>','cmdlevel',1])->one();
- $this->companyId = $companiesEntity->id;
- if ( null == $this->companyId) {
- return false;
- }
- return true;
- }
-
- private function GetUuid()
- {
- $uuid = Yii::$app->db->createCommand('select UUID() as uuid')->queryOne();
- $this->tmpGuid = $uuid["uuid"];
- if ( $this->tmpGuid ) {
- return true;
- }
- true false;
- }
-
- private function GenerateProject(){
-
- $this->GetUuid();
- $projectsLocotech = new ProjectsLocotech();
- $projectsLocotech->action = $this->projecttype;
- $projectsLocotech->tasks = $this->tmpGuid;
- $projectsLocotech->company = $this->companyId;
- $projectsLocotech->status = 1;
- $projectsLocotech->loco_type = $this->locoserie;
- $projectsLocotech->loco_number = $this->loconumber;
- $projectsLocotech->urgent = 0;
- $projectsLocotech->created = date("Y-m-d H:i:s");
- $projectsLocotech->uuid = 'Задача из АСУ СГ';
- $projectsLocotech->save();
- }
-
-
- private function GenerateAsusgProject(){
-
- $this->GetUuid();
- $AsusgProjectEntity = new AsusgProject();
- $AsusgProjectEntity->text = $this->tmpGuid;
- $AsusgProjectEntity->loco_serie_id = $this->locoserieId;
- $AsusgProjectEntity->repair_type = $this->repairtype;
- $AsusgProjectEntity->loco_number = $this->loconumber;
- $AsusgProjectEntity->section_a = $this->section1;
- $AsusgProjectEntity->section_b = $this->section2;
- $AsusgProjectEntity->section_c = $this->section3;
- $AsusgProjectEntity->save();
-
- $asuproj = AsusgProject::find()->where(['text' => $this->tmpGuid])->one();
- if ( null == $asuproj->projectId) {
- return false;
- }
- return true;
- }
-
- private function RedefineCompanyId(){
-
- $ProjectsLocotech = ProjectsLocotech::find()->where(['tasks' => $this->tmpGuid])->one();
- $rhis->companyId = $ProjectsLocotech->id;
- if ( null == $rhis->companyId ) {
- return false;
- }
- return true;
- }
-
- private function attachCommands() {
-
- ProjectsLocotech::updateAll(['tasks' = ''],['id' => $this->companyId]);
- $this->current_task = 0;
- $this->current_jobtype = 0;
- $this->taskPriority = 1;
- return true;
- }
-
- private function attachCommandsToProj() {
-
- $AsusgJob2CommandEntity = AsusgJob2Command::find()->where(['asusg_job_id' = $tgis->asusg_job])->orderBy(['cmd_order'=> SORT_ASC])->all();
- foreach( $AsusgJob2CommandEntity as $comand) {
-
- $JobtypesTasktypes = JobtypesTasktypes::find()->where(['tasktype_id' => $comand])->all();
- $this->jobtype = $JobtypesTasktypes->jobtype_id;
- if ( (null == $this->jobtype) || ($this->jobtype <> $this->current_jobtype) ) {
-
-
-
-
- }
- }
- }
-
- }
|