Commit 3a2da2a11c07e69b2ce2363668031be55220665e
1 parent
2bb35b07f0
Экспорт данных в документ с фильтрами
Showing 10 changed files with 206 additions and 32 deletions Side-by-side Diff
- app/Enums/DbExportColumns.php
- app/Http/Controllers/Admin/UsersController.php
- app/Http/Controllers/MainController.php
- app/Http/Controllers/WorkerController.php
- app/Models/Job_title.php
- app/Models/Worker.php
- app/Models/worker_jobs.php
- database/migrations/2024_11_01_124040_create_worker_jobs_table.php
- resources/views/admin/job_titles/form.blade.php
- resources/views/employers/bd.blade.php
app/Enums/DbExportColumns.php
... | ... | @@ -8,10 +8,13 @@ enum DbExportColumns: string |
8 | 8 | { |
9 | 9 | use EnumToArray; |
10 | 10 | |
11 | - case job_titles__name = 'Должность'; | |
12 | - case users__surname = 'Фамилия'; | |
11 | + //case job_titles__code = 'Коды должностей'; | |
12 | + case users__id = 'Код пользователя'; | |
13 | 13 | case users__name_man = 'Имя'; |
14 | - case users__surname2 = 'Отчетство'; | |
15 | - case users__email = 'Почта'; | |
14 | + case users__surname = 'Фамилия'; | |
15 | + case users__surname2 = 'Отчество'; | |
16 | + case users__jobs = 'Должности'; | |
17 | + case users__email = 'Email'; | |
16 | 18 | case users__telephone = 'Телефон'; |
19 | + | |
17 | 20 | } |
app/Http/Controllers/Admin/UsersController.php
... | ... | @@ -8,6 +8,8 @@ use App\Models\ContentRoles; |
8 | 8 | use App\Models\Job_title; |
9 | 9 | use App\Models\User; |
10 | 10 | use App\Models\Worker; |
11 | +use App\Models\worker_jobs; | |
12 | +use Illuminate\Database\Eloquent\Model; | |
11 | 13 | use Illuminate\Http\Request; |
12 | 14 | use Illuminate\Support\Facades\Auth; |
13 | 15 | use Illuminate\Support\Facades\Storage; |
... | ... | @@ -75,13 +77,14 @@ class UsersController extends Controller |
75 | 77 | } |
76 | 78 | |
77 | 79 | public function add_bd() { |
78 | - $list_job_titles = Job_title::query()->active()->where('is_bd', '=' , '2')->orderBy('name', 'asc')->get(); | |
80 | + $list_job_titles = Job_title::query()->active()->where('is_bd', '=' , '2')-> | |
81 | + orderBy('name', 'asc')->get(); | |
79 | 82 | return view('admin.users.add', compact('list_job_titles')); |
80 | 83 | } |
81 | 84 | |
82 | 85 | public function add_store_bd(BaseUserRequest $request) { |
83 | 86 | $params = $request->all(); |
84 | - | |
87 | + //dd($params); | |
85 | 88 | if ($request->has('file')) { |
86 | 89 | $params['file'] = $request->file('file')->store('basedata', 'public'); |
87 | 90 | } |
... | ... | @@ -90,12 +93,25 @@ class UsersController extends Controller |
90 | 93 | $params['name'] = $request->surname." ".$request->name_man." ".$request->surname2; |
91 | 94 | } |
92 | 95 | |
93 | - $user = User::create($params); | |
94 | - $worker = new Worker(); | |
95 | - $worker->positions_work = isset($params['positions_work']) ? json_encode($params['positions_work']) : []; | |
96 | - $worker->user_id = $user->id; | |
97 | - $worker->comment = isset($params['comment']) ? $params['comment'] : null; | |
98 | - $worker->save(); | |
96 | + try { | |
97 | + $user = User::create($params); | |
98 | + } finally { | |
99 | + $worker = new Worker(); | |
100 | + $worker->positions_work = isset($params['positions_work']) ? json_encode($params['positions_work']) : []; | |
101 | + $worker->user_id = $user->id; | |
102 | + $worker->comment = isset($params['comment']) ? $params['comment'] : null; | |
103 | + $worker->save(); | |
104 | + | |
105 | + /* Отказ от рефакторинга из-за сжатых сроков! Ларионов | |
106 | + * if (is_array($params['positions_work'])) | |
107 | + foreach ($params['positions_work'] as $it) { | |
108 | + $worker_job = new worker_jobs(); | |
109 | + $worker_job->user_id = $user->id; | |
110 | + $worker_job->job_id = $it; | |
111 | + $worker_job->save(); | |
112 | + } | |
113 | + */ | |
114 | + } | |
99 | 115 | |
100 | 116 | return redirect()->route('admin.basedata'); |
101 | 117 | } |
... | ... | @@ -125,18 +141,32 @@ class UsersController extends Controller |
125 | 141 | $params['name'] = $request->surname." ".$request->name_man." ".$request->surname2; |
126 | 142 | } |
127 | 143 | |
128 | - $user->update($params); | |
129 | - if (isset($user->workers[0]->id)) { | |
130 | - $worker = Worker::find($user->workers[0]->id); | |
131 | - $worker->positions_work = $positions_work; | |
132 | - $worker->comment = isset($params['comment']) ? $params['comment'] : null; | |
133 | - $worker->save(); | |
134 | - } else { | |
135 | - $worker = new Worker(); | |
136 | - $worker->user_id = $user->id; | |
137 | - $worker->positions_work = $positions_work; | |
138 | - $worker->comment = isset($params['comment']) ? $params['comment'] : null; | |
139 | - $worker->save(); | |
144 | + try { | |
145 | + $user->update($params); | |
146 | + | |
147 | + } finally { | |
148 | + if (isset($user->workers[0]->id)) { | |
149 | + $worker = Worker::find($user->workers[0]->id); | |
150 | + $worker->positions_work = $positions_work; | |
151 | + $worker->comment = isset($params['comment']) ? $params['comment'] : null; | |
152 | + $worker->save(); | |
153 | + } else { | |
154 | + $worker = new Worker(); | |
155 | + $worker->user_id = $user->id; | |
156 | + $worker->positions_work = $positions_work; | |
157 | + $worker->comment = isset($params['comment']) ? $params['comment'] : null; | |
158 | + $worker->save(); | |
159 | + } | |
160 | + /* | |
161 | + * Отказ от рефакторинга структуры БД из-за сжатых сроков сдачи. Ларионов. | |
162 | + if (is_array($params['positions_work'])) | |
163 | + foreach ($params['positions_work'] as $it) { | |
164 | + worker_jobs::updateOrCreate( | |
165 | + ['user_id' => $user->id], | |
166 | + ['job_id' => $it] | |
167 | + ); | |
168 | + } | |
169 | + */ | |
140 | 170 | } |
141 | 171 | |
142 | 172 | return redirect()->route('admin.basedata'); |
app/Http/Controllers/MainController.php
... | ... | @@ -67,7 +67,7 @@ class MainController extends Controller |
67 | 67 | orderBy('sort')->get(); |
68 | 68 | $vacancy = Ad_jobs::query()->with('job_title')->orderBy('position_ship')->get(); |
69 | 69 | |
70 | - $block_names = MainPageCounters::values();; | |
70 | + $block_names = MainPageCounters::values(); | |
71 | 71 | $blocks_counters = PageContent::select('name', 'title', 'description', 'extra') |
72 | 72 | ->whereIn('name', $block_names) |
73 | 73 | ->orderBy('name', 'asc') |
app/Http/Controllers/WorkerController.php
... | ... | @@ -288,6 +288,7 @@ class WorkerController extends Controller |
288 | 288 | |
289 | 289 | $jobIds = $request->input('job_title_list', []); |
290 | 290 | |
291 | + | |
291 | 292 | /* //query for mysql ver 8.0 or higher |
292 | 293 | $users = DB::select( |
293 | 294 | "select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone` |
... | ... | @@ -304,17 +305,56 @@ class WorkerController extends Controller |
304 | 305 | )". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '') |
305 | 306 | );*/ |
306 | 307 | |
307 | - $users = DB::select( | |
308 | + /*$users = DB::select( | |
308 | 309 | "select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone` |
309 | 310 | from users |
310 | 311 | join workers on `users`.`id` = `workers`.`user_id` |
311 | 312 | join `job_titles` |
312 | - where `users`.`is_bd` = 1 | |
313 | + where `users`.`is_bd` = 2 | |
313 | 314 | and (`workers`.`position_work` = `job_titles`.`id` |
314 | 315 | or `workers`.`positions_work` |
315 | 316 | )". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '') |
316 | - ); | |
317 | + );*/ | |
318 | + | |
319 | + /*$users = DB::select("select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, | |
320 | + `users`.`surname2`, `users`.`email`, `users`.`telephone`, `users`.`id`, `job_titles`.`id` | |
321 | + FROM `users` | |
322 | + JOIN `job_titles` | |
323 | + JOIN workers ON `users`.id = `workers`.user_id | |
324 | + JOIN worker_jobs ON `users`.`id` = `worker_jobs`.user_id AND | |
325 | + `job_titles`.`id` = `worker_jobs`.job_id"); | |
326 | + */ | |
327 | + $first_part = "SELECT | |
328 | + w.user_id, u.`name`, u.`surname`, u.`surname2`, | |
329 | + GROUP_CONCAT(j.`name` SEPARATOR ', ') AS job_titles_names, | |
330 | + u.`email`, u.`telephone`, w.`positions_work` | |
331 | + FROM | |
332 | + users u | |
333 | + INNER JOIN | |
334 | + Workers w ON u.id = w.user_id | |
335 | + INNER JOIN | |
336 | + JSON_TABLE(w.positions_work, '$[*]' COLUMNS (pos INT PATH '$')) AS extracted_positions | |
337 | + INNER JOIN | |
338 | + job_titles j ON j.id = extracted_positions.pos"; | |
339 | + | |
340 | + $second_part = " "; | |
341 | + if (!is_null($jobIds)) | |
342 | + if (is_array($jobIds)) | |
343 | + if (count($jobIds) > 0) | |
344 | + { | |
345 | + $second_part = " WHERE "; | |
346 | + foreach ($jobIds as $key => $it) { | |
347 | + if ($key == 0) | |
348 | + $second_part .= "(j.id = ".$it.") "; | |
349 | + elseif ($key > 0) | |
350 | + $second_part .= "OR (j.id = ".$it.") "; | |
351 | + } | |
352 | + } | |
353 | + | |
354 | + $three_part = "GROUP BY w.user_id, w.positions_work, u.`name` | |
355 | + HAVING COUNT(DISTINCT j.id) = JSON_LENGTH(w.positions_work)"; | |
317 | 356 | |
357 | + $users = DB::select($first_part.$second_part.$three_part); | |
318 | 358 | $users = collect($users); |
319 | 359 | |
320 | 360 | if ($users->count()) { |
app/Models/Job_title.php
... | ... | @@ -32,6 +32,14 @@ class Job_title extends Model |
32 | 32 | return $this->belongsTo(Job_title::class, 'parent_id'); |
33 | 33 | } |
34 | 34 | |
35 | + /* | |
36 | + * Связь модели Вакансии (Job_title) с моделью Вакансии работника (worker_jobs) | |
37 | + один-ко-многим | |
38 | + */ | |
39 | + public function worker_job() { | |
40 | + return $this->hasMany(worker_jobs::class); | |
41 | + } | |
42 | + | |
35 | 43 | public function scopeActive($query) { |
36 | 44 | return $query->where('is_remove', '=', '0'); |
37 | 45 | } |
app/Models/Worker.php
... | ... | @@ -122,6 +122,14 @@ class Worker extends Model |
122 | 122 | )->withPivot('status'); |
123 | 123 | } |
124 | 124 | |
125 | + /* | |
126 | + * Связь модели Работники (Workers) с моделью Вакансии работника (worker_jobs) | |
127 | + один-ко-многим | |
128 | + */ | |
129 | + public function worker_job() { | |
130 | + return $this->hasMany(worker_jobs::class); | |
131 | + } | |
132 | + | |
125 | 133 | //Связи Работника с дополнительными |
126 | 134 | public function dop_info() { |
127 | 135 | return $this->hasMany(Dop_info::class, 'worker_id'); |
app/Models/worker_jobs.php
... | ... | @@ -0,0 +1,34 @@ |
1 | +<?php | |
2 | + | |
3 | +namespace App\Models; | |
4 | + | |
5 | +use Illuminate\Database\Eloquent\Factories\HasFactory; | |
6 | +use Illuminate\Database\Eloquent\Model; | |
7 | + | |
8 | +class worker_jobs extends Model | |
9 | +{ | |
10 | + use HasFactory; | |
11 | + | |
12 | + protected $fillable = [ | |
13 | + 'id', | |
14 | + 'user_id', | |
15 | + 'job_id' | |
16 | + ]; | |
17 | + | |
18 | + /* | |
19 | + * Связь таблицы users с таблицей worker_jobs | |
20 | + многие-к-одному | |
21 | + */ | |
22 | + public function users() { | |
23 | + return $this->belongsTo(User::class, 'user_id'); | |
24 | + } | |
25 | + | |
26 | + /* | |
27 | + * Связь таблицы Job_titles с таблицей worker_jobs | |
28 | + многие-к-одному | |
29 | + */ | |
30 | + public function job_titles() { | |
31 | + return $this->belongsTo(Job_title::class, 'job_id'); | |
32 | + } | |
33 | + | |
34 | +} |
database/migrations/2024_11_01_124040_create_worker_jobs_table.php
... | ... | @@ -0,0 +1,36 @@ |
1 | +<?php | |
2 | + | |
3 | +use Illuminate\Database\Migrations\Migration; | |
4 | +use Illuminate\Database\Schema\Blueprint; | |
5 | +use Illuminate\Support\Facades\Schema; | |
6 | + | |
7 | +return new class extends Migration | |
8 | +{ | |
9 | + /** | |
10 | + * Run the migrations. | |
11 | + * | |
12 | + * @return void | |
13 | + */ | |
14 | + public function up() | |
15 | + { | |
16 | + | |
17 | + /* Отказ от рефакторинга и нормализации табличных структур БД из-за сжатых сроков. Ларионов | |
18 | + Schema::create('worker_jobs', function (Blueprint $table) { | |
19 | + $table->id(); | |
20 | + $table->bigInteger('user_id')->nullable(false); | |
21 | + $table->bigInteger('job_id')->nullable(false); | |
22 | + $table->timestamps(); | |
23 | + }); | |
24 | + */ | |
25 | + } | |
26 | + | |
27 | + /** | |
28 | + * Reverse the migrations. | |
29 | + * | |
30 | + * @return void | |
31 | + */ | |
32 | + public function down() | |
33 | + { | |
34 | + //Schema::dropIfExists('worker_jobs'); | |
35 | + } | |
36 | +}; |
resources/views/admin/job_titles/form.blade.php
... | ... | @@ -25,6 +25,17 @@ |
25 | 25 | </select> |
26 | 26 | </label><br> |
27 | 27 | |
28 | + <? /*?> | |
29 | + <label class="block text-sm"> | |
30 | + <span class="text-gray-700 dark:text-gray-400">Активность записи</span> | |
31 | + <select name="is_remove" class="block w-full mt-1 text-sm dark:text-gray-300 dark:border-gray-600 dark:bg-gray-700 form-select focus:border-purple-400 focus:outline-none focus:shadow-outline-purple dark:focus:shadow-outline-gray" | |
32 | + title="Активность"> | |
33 | + <option value="0" @isset ($job_title) @if ($job_title->is_remove==0) selected @endif @endisset>Запись видимая</option> | |
34 | + <option value="1" @isset ($job_title) @if ($job_title->is_remove==1) selected @endif @endisset>Запись отключена</option> | |
35 | + </select> | |
36 | + </label><br> | |
37 | + <? */ ?> | |
38 | + | |
28 | 39 | <label class="block text-sm"> |
29 | 40 | <span class="text-gray-700 dark:text-gray-400">Категория должности</span> |
30 | 41 |
resources/views/employers/bd.blade.php
... | ... | @@ -161,14 +161,18 @@ |
161 | 161 | @if ($users->count()) |
162 | 162 | @foreach ($users as $key => $it) |
163 | 163 | <tr> |
164 | - <td style="max-width: 40px; min-width: 30px; font-size: 1.5rem">{{ $it->workers[0]->comment }}</td> | |
164 | + <td style="max-width: 40px; min-width: 30px; font-size: 1.5rem">@isset($it->workers[0]->comment){{ $it->workers[0]->comment }}@else @endisset</td> | |
165 | 165 | |
166 | 166 | <td>{{ $it->surname." ".$it->name_man }}<br>{{ $it->surname2 }}</td> |
167 | 167 | |
168 | 168 | <td> |
169 | - @if($it->workers[0]->positions_work) | |
170 | - {{ $it->workers[0]->jobs->first()->name }} | |
171 | - @endif | |
169 | + @isset ($it->workers[0]->positions_work) | |
170 | + @if($it->workers[0]->positions_work) | |
171 | + {{ $it->workers[0]->jobs->first()->name }} | |
172 | + @endif | |
173 | + @else | |
174 | + | |
175 | + @endisset | |
172 | 176 | </td> |
173 | 177 | |
174 | 178 | <td> |