From 3a2da2a11c07e69b2ce2363668031be55220665e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=20=D0=9B=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Sat, 2 Nov 2024 15:38:03 +0700 Subject: [PATCH] =?UTF-8?q?=D0=AD=D0=BA=D1=81=D0=BF=D0=BE=D1=80=D1=82=20=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B2=20=D0=B4=D0=BE=D0=BA=D1=83?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=20=D1=81=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Enums/DbExportColumns.php | 11 +-- app/Http/Controllers/Admin/UsersController.php | 70 ++++++++++++++------ app/Http/Controllers/MainController.php | 2 +- app/Http/Controllers/WorkerController.php | 46 ++++++++++++- app/Models/Job_title.php | 8 +++ app/Models/Worker.php | 8 +++ app/Models/worker_jobs.php | 34 ++++++++++ .../2024_11_01_124040_create_worker_jobs_table.php | 36 ++++++++++ resources/views/admin/job_titles/form.blade.php | 11 +++ resources/views/employers/bd.blade.php | 12 ++-- 10 files changed, 206 insertions(+), 32 deletions(-) create mode 100644 app/Models/worker_jobs.php create mode 100644 database/migrations/2024_11_01_124040_create_worker_jobs_table.php diff --git a/app/Enums/DbExportColumns.php b/app/Enums/DbExportColumns.php index 53476a8..f67f2d0 100644 --- a/app/Enums/DbExportColumns.php +++ b/app/Enums/DbExportColumns.php @@ -8,10 +8,13 @@ enum DbExportColumns: string { use EnumToArray; - case job_titles__name = 'Должность'; - case users__surname = 'Фамилия'; + //case job_titles__code = 'Коды должностей'; + case users__id = 'Код пользователя'; case users__name_man = 'Имя'; - case users__surname2 = 'Отчетство'; - case users__email = 'Почта'; + case users__surname = 'Фамилия'; + case users__surname2 = 'Отчество'; + case users__jobs = 'Должности'; + case users__email = 'Email'; case users__telephone = 'Телефон'; + } diff --git a/app/Http/Controllers/Admin/UsersController.php b/app/Http/Controllers/Admin/UsersController.php index 88442cc..a4c996c 100644 --- a/app/Http/Controllers/Admin/UsersController.php +++ b/app/Http/Controllers/Admin/UsersController.php @@ -8,6 +8,8 @@ use App\Models\ContentRoles; use App\Models\Job_title; use App\Models\User; use App\Models\Worker; +use App\Models\worker_jobs; +use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; @@ -75,13 +77,14 @@ class UsersController extends Controller } public function add_bd() { - $list_job_titles = Job_title::query()->active()->where('is_bd', '=' , '2')->orderBy('name', 'asc')->get(); + $list_job_titles = Job_title::query()->active()->where('is_bd', '=' , '2')-> + orderBy('name', 'asc')->get(); return view('admin.users.add', compact('list_job_titles')); } public function add_store_bd(BaseUserRequest $request) { $params = $request->all(); - + //dd($params); if ($request->has('file')) { $params['file'] = $request->file('file')->store('basedata', 'public'); } @@ -90,12 +93,25 @@ class UsersController extends Controller $params['name'] = $request->surname." ".$request->name_man." ".$request->surname2; } - $user = User::create($params); - $worker = new Worker(); - $worker->positions_work = isset($params['positions_work']) ? json_encode($params['positions_work']) : []; - $worker->user_id = $user->id; - $worker->comment = isset($params['comment']) ? $params['comment'] : null; - $worker->save(); + try { + $user = User::create($params); + } finally { + $worker = new Worker(); + $worker->positions_work = isset($params['positions_work']) ? json_encode($params['positions_work']) : []; + $worker->user_id = $user->id; + $worker->comment = isset($params['comment']) ? $params['comment'] : null; + $worker->save(); + + /* Отказ от рефакторинга из-за сжатых сроков! Ларионов + * if (is_array($params['positions_work'])) + foreach ($params['positions_work'] as $it) { + $worker_job = new worker_jobs(); + $worker_job->user_id = $user->id; + $worker_job->job_id = $it; + $worker_job->save(); + } + */ + } return redirect()->route('admin.basedata'); } @@ -125,18 +141,32 @@ class UsersController extends Controller $params['name'] = $request->surname." ".$request->name_man." ".$request->surname2; } - $user->update($params); - if (isset($user->workers[0]->id)) { - $worker = Worker::find($user->workers[0]->id); - $worker->positions_work = $positions_work; - $worker->comment = isset($params['comment']) ? $params['comment'] : null; - $worker->save(); - } else { - $worker = new Worker(); - $worker->user_id = $user->id; - $worker->positions_work = $positions_work; - $worker->comment = isset($params['comment']) ? $params['comment'] : null; - $worker->save(); + try { + $user->update($params); + + } finally { + if (isset($user->workers[0]->id)) { + $worker = Worker::find($user->workers[0]->id); + $worker->positions_work = $positions_work; + $worker->comment = isset($params['comment']) ? $params['comment'] : null; + $worker->save(); + } else { + $worker = new Worker(); + $worker->user_id = $user->id; + $worker->positions_work = $positions_work; + $worker->comment = isset($params['comment']) ? $params['comment'] : null; + $worker->save(); + } + /* + * Отказ от рефакторинга структуры БД из-за сжатых сроков сдачи. Ларионов. + if (is_array($params['positions_work'])) + foreach ($params['positions_work'] as $it) { + worker_jobs::updateOrCreate( + ['user_id' => $user->id], + ['job_id' => $it] + ); + } + */ } return redirect()->route('admin.basedata'); diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php index 9fed572..69d811d 100644 --- a/app/Http/Controllers/MainController.php +++ b/app/Http/Controllers/MainController.php @@ -67,7 +67,7 @@ class MainController extends Controller orderBy('sort')->get(); $vacancy = Ad_jobs::query()->with('job_title')->orderBy('position_ship')->get(); - $block_names = MainPageCounters::values();; + $block_names = MainPageCounters::values(); $blocks_counters = PageContent::select('name', 'title', 'description', 'extra') ->whereIn('name', $block_names) ->orderBy('name', 'asc') diff --git a/app/Http/Controllers/WorkerController.php b/app/Http/Controllers/WorkerController.php index 4c000f4..6521e9a 100644 --- a/app/Http/Controllers/WorkerController.php +++ b/app/Http/Controllers/WorkerController.php @@ -288,6 +288,7 @@ class WorkerController extends Controller $jobIds = $request->input('job_title_list', []); + /* //query for mysql ver 8.0 or higher $users = DB::select( "select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone` @@ -304,17 +305,56 @@ class WorkerController extends Controller )". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '') );*/ - $users = DB::select( + /*$users = DB::select( "select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone` from users join workers on `users`.`id` = `workers`.`user_id` join `job_titles` - where `users`.`is_bd` = 1 + where `users`.`is_bd` = 2 and (`workers`.`position_work` = `job_titles`.`id` or `workers`.`positions_work` )". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '') - ); + );*/ + + /*$users = DB::select("select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, + `users`.`surname2`, `users`.`email`, `users`.`telephone`, `users`.`id`, `job_titles`.`id` + FROM `users` + JOIN `job_titles` + JOIN workers ON `users`.id = `workers`.user_id + JOIN worker_jobs ON `users`.`id` = `worker_jobs`.user_id AND + `job_titles`.`id` = `worker_jobs`.job_id"); + */ + $first_part = "SELECT + w.user_id, u.`name`, u.`surname`, u.`surname2`, + GROUP_CONCAT(j.`name` SEPARATOR ', ') AS job_titles_names, + u.`email`, u.`telephone`, w.`positions_work` + FROM + users u + INNER JOIN + Workers w ON u.id = w.user_id + INNER JOIN + JSON_TABLE(w.positions_work, '$[*]' COLUMNS (pos INT PATH '$')) AS extracted_positions + INNER JOIN + job_titles j ON j.id = extracted_positions.pos"; + + $second_part = " "; + if (!is_null($jobIds)) + if (is_array($jobIds)) + if (count($jobIds) > 0) + { + $second_part = " WHERE "; + foreach ($jobIds as $key => $it) { + if ($key == 0) + $second_part .= "(j.id = ".$it.") "; + elseif ($key > 0) + $second_part .= "OR (j.id = ".$it.") "; + } + } + + $three_part = "GROUP BY w.user_id, w.positions_work, u.`name` + HAVING COUNT(DISTINCT j.id) = JSON_LENGTH(w.positions_work)"; + $users = DB::select($first_part.$second_part.$three_part); $users = collect($users); if ($users->count()) { diff --git a/app/Models/Job_title.php b/app/Models/Job_title.php index 4a9cef1..e482e5b 100644 --- a/app/Models/Job_title.php +++ b/app/Models/Job_title.php @@ -32,6 +32,14 @@ class Job_title extends Model return $this->belongsTo(Job_title::class, 'parent_id'); } + /* + * Связь модели Вакансии (Job_title) с моделью Вакансии работника (worker_jobs) + один-ко-многим + */ + public function worker_job() { + return $this->hasMany(worker_jobs::class); + } + public function scopeActive($query) { return $query->where('is_remove', '=', '0'); } diff --git a/app/Models/Worker.php b/app/Models/Worker.php index 8d693df..13ec598 100644 --- a/app/Models/Worker.php +++ b/app/Models/Worker.php @@ -122,6 +122,14 @@ class Worker extends Model )->withPivot('status'); } + /* + * Связь модели Работники (Workers) с моделью Вакансии работника (worker_jobs) + один-ко-многим + */ + public function worker_job() { + return $this->hasMany(worker_jobs::class); + } + //Связи Работника с дополнительными public function dop_info() { return $this->hasMany(Dop_info::class, 'worker_id'); diff --git a/app/Models/worker_jobs.php b/app/Models/worker_jobs.php new file mode 100644 index 0000000..254a091 --- /dev/null +++ b/app/Models/worker_jobs.php @@ -0,0 +1,34 @@ +belongsTo(User::class, 'user_id'); + } + + /* + * Связь таблицы Job_titles с таблицей worker_jobs + многие-к-одному + */ + public function job_titles() { + return $this->belongsTo(Job_title::class, 'job_id'); + } + +} diff --git a/database/migrations/2024_11_01_124040_create_worker_jobs_table.php b/database/migrations/2024_11_01_124040_create_worker_jobs_table.php new file mode 100644 index 0000000..c90370d --- /dev/null +++ b/database/migrations/2024_11_01_124040_create_worker_jobs_table.php @@ -0,0 +1,36 @@ +id(); + $table->bigInteger('user_id')->nullable(false); + $table->bigInteger('job_id')->nullable(false); + $table->timestamps(); + }); + */ + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + //Schema::dropIfExists('worker_jobs'); + } +}; diff --git a/resources/views/admin/job_titles/form.blade.php b/resources/views/admin/job_titles/form.blade.php index d15c952..853fe6f 100644 --- a/resources/views/admin/job_titles/form.blade.php +++ b/resources/views/admin/job_titles/form.blade.php @@ -25,6 +25,17 @@
+ +
+ +