Przeglądaj źródła

新增 department table

maa3606 2 lat temu
rodzic
commit
00c6c08efc

+ 86 - 0
app/Http/Controllers/DepartmentController.php

@@ -0,0 +1,86 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Models\Department;
+use App\Http\Requests\StoreDepartmentRequest;
+use App\Http\Requests\UpdateDepartmentRequest;
+
+class DepartmentController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \App\Http\Requests\StoreDepartmentRequest  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(StoreDepartmentRequest $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Http\Response
+     */
+    public function show(Department $department)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(Department $department)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \App\Http\Requests\UpdateDepartmentRequest  $request
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Http\Response
+     */
+    public function update(UpdateDepartmentRequest $request, Department $department)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(Department $department)
+    {
+        //
+    }
+}

+ 30 - 0
app/Http/Requests/StoreDepartmentRequest.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Requests;
+
+use Illuminate\Foundation\Http\FormRequest;
+
+class StoreDepartmentRequest extends FormRequest
+{
+    /**
+     * Determine if the user is authorized to make this request.
+     *
+     * @return bool
+     */
+    public function authorize()
+    {
+        return false;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array<string, mixed>
+     */
+    public function rules()
+    {
+        return [
+            //
+        ];
+    }
+}

+ 30 - 0
app/Http/Requests/UpdateDepartmentRequest.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Requests;
+
+use Illuminate\Foundation\Http\FormRequest;
+
+class UpdateDepartmentRequest extends FormRequest
+{
+    /**
+     * Determine if the user is authorized to make this request.
+     *
+     * @return bool
+     */
+    public function authorize()
+    {
+        return false;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array<string, mixed>
+     */
+    public function rules()
+    {
+        return [
+            //
+        ];
+    }
+}

+ 17 - 0
app/Models/Department.php

@@ -0,0 +1,17 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class Department extends Model
+{
+    use HasFactory;
+
+    protected $fillable = [
+        'DepartmentID',
+        'DepartmentName',
+        'Manager',
+    ];
+}

+ 94 - 0
app/Policies/DepartmentPolicy.php

@@ -0,0 +1,94 @@
+<?php
+
+namespace App\Policies;
+
+use App\Models\Department;
+use App\Models\User;
+use Illuminate\Auth\Access\HandlesAuthorization;
+
+class DepartmentPolicy
+{
+    use HandlesAuthorization;
+
+    /**
+     * Determine whether the user can view any models.
+     *
+     * @param  \App\Models\User  $user
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function viewAny(User $user)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can view the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function view(User $user, Department $department)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can create models.
+     *
+     * @param  \App\Models\User  $user
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function create(User $user)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can update the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function update(User $user, Department $department)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can delete the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function delete(User $user, Department $department)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can restore the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function restore(User $user, Department $department)
+    {
+        //
+    }
+
+    /**
+     * Determine whether the user can permanently delete the model.
+     *
+     * @param  \App\Models\User  $user
+     * @param  \App\Models\Department  $department
+     * @return \Illuminate\Auth\Access\Response|bool
+     */
+    public function forceDelete(User $user, Department $department)
+    {
+        //
+    }
+}

+ 182 - 0
database/MAA_department.json

@@ -0,0 +1,182 @@
+[
+  {
+    "DepartmentID": "a00",
+    "DepartmentName": "行政管理部",
+    "Manager": "a00"
+  },
+  {
+    "DepartmentID": "a21",
+    "DepartmentName": "行政管理部庶務科",
+    "Manager": "a21"
+  },
+  {
+    "DepartmentID": "a22",
+    "DepartmentName": "人力資源科",
+    "Manager": "a22"
+  },
+  {
+    "DepartmentID": "a24",
+    "DepartmentName": "行政管理部文書科",
+    "Manager": "a24"
+  },
+  {
+    "DepartmentID": "b00",
+    "DepartmentName": "南區辦事處",
+    "Manager": "b00"
+  },
+  {
+    "DepartmentID": "b10",
+    "DepartmentName": "中區辦事處",
+    "Manager": "b10"
+  },
+  {
+    "DepartmentID": "c00",
+    "DepartmentName": "工程管理一部",
+    "Manager": "c00"
+  },
+  {
+    "DepartmentID": "c10",
+    "DepartmentName": "工程管理二部",
+    "Manager": "c10"
+  },
+  {
+    "DepartmentID": "d00",
+    "DepartmentName": "發展與企畫部",
+    "Manager": "d00"
+  },
+  {
+    "DepartmentID": "e10",
+    "DepartmentName": "工程製圖科",
+    "Manager": "e10"
+  },
+  {
+    "DepartmentID": "f10",
+    "DepartmentName": "工務部",
+    "Manager": "f10"
+  },
+  {
+    "DepartmentID": "g00",
+    "DepartmentName": "大地工程部",
+    "Manager": "g00"
+  },
+  {
+    "DepartmentID": "i00",
+    "DepartmentName": "財務部",
+    "Manager": "i00"
+  },
+  {
+    "DepartmentID": "j00",
+    "DepartmentName": "運輸及土木工程部",
+    "Manager": "j00"
+  },
+  {
+    "DepartmentID": "j10",
+    "DepartmentName": "城鄉發展部",
+    "Manager": "j10"
+  },
+  {
+    "DepartmentID": "j20",
+    "DepartmentName": "軌道工程部",
+    "Manager": "j20"
+  },
+  {
+    "DepartmentID": "l00",
+    "DepartmentName": "董事長室",
+    "Manager": "l00"
+  },
+  {
+    "DepartmentID": "l10",
+    "DepartmentName": "總經理室",
+    "Manager": "l10"
+  },
+  {
+    "DepartmentID": "l40",
+    "DepartmentName": "企業發展中心",
+    "Manager": "l40"
+  },
+  {
+    "DepartmentID": "l60",
+    "DepartmentName": "成本中心",
+    "Manager": "l60"
+  },
+  {
+    "DepartmentID": "m00",
+    "DepartmentName": "資訊中心",
+    "Manager": "m00"
+  },
+  {
+    "DepartmentID": "p00",
+    "DepartmentName": "環境及水資源工程部",
+    "Manager": "p00"
+  },
+  {
+    "DepartmentID": "p10",
+    "DepartmentName": "環境水務部",
+    "Manager": "p10"
+  },
+  {
+    "DepartmentID": "p20",
+    "DepartmentName": "環境永續部",
+    "Manager": "p20"
+  },
+  {
+    "DepartmentID": "r00",
+    "DepartmentName": "機電系統工程部",
+    "Manager": "r00"
+  },
+  {
+    "DepartmentID": "s00",
+    "DepartmentName": "結構工程部",
+    "Manager": "s00"
+  },
+  {
+    "DepartmentID": "u20",
+    "DepartmentName": "工程設計群",
+    "Manager": "u20"
+  },
+  {
+    "DepartmentID": "u30",
+    "DepartmentName": "工程監理群",
+    "Manager": "u30"
+  },
+  {
+    "DepartmentID": "u40",
+    "DepartmentName": "總管理處",
+    "Manager": "u40"
+  },
+  {
+    "DepartmentID": "u50",
+    "DepartmentName": "建築及設施群",
+    "Manager": "u50"
+  },
+  {
+    "DepartmentID": "x05",
+    "DepartmentName": "數位工程發展部",
+    "Manager": "x05"
+  },
+  {
+    "DepartmentID": "x06",
+    "DepartmentName": "淡海輕軌計畫監造專案",
+    "Manager": "x06"
+  },
+  {
+    "DepartmentID": "x08",
+    "DepartmentName": "安坑輕軌計畫監造專案",
+    "Manager": "x08"
+  },
+  {
+    "DepartmentID": "x09",
+    "DepartmentName": "先進技術中心",
+    "Manager": "x09"
+  },
+  {
+    "DepartmentID": "x10",
+    "DepartmentName": "塭仔圳市地重劃公共工程專案管理與監造專案",
+    "Manager": "x10"
+  },
+  {
+    "DepartmentID": "x12",
+    "DepartmentName": "萬大果菜市場專案",
+    "Manager": "x12"
+  }
+]

+ 23 - 0
database/factories/DepartmentFactory.php

@@ -0,0 +1,23 @@
+<?php
+
+namespace Database\Factories;
+
+use Illuminate\Database\Eloquent\Factories\Factory;
+
+/**
+ * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Department>
+ */
+class DepartmentFactory extends Factory
+{
+    /**
+     * Define the model's default state.
+     *
+     * @return array<string, mixed>
+     */
+    public function definition()
+    {
+        return [
+            //
+        ];
+    }
+}

+ 33 - 0
database/migrations/2023_02_09_055743_create_departments_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('departments', function (Blueprint $table) {
+            $table->id();
+            $table->string('DepartmentID');
+            $table->string('DepartmentName');
+            $table->string('Manager');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('departments');
+    }
+};

+ 2 - 1
database/seeders/DatabaseSeeder.php

@@ -49,7 +49,8 @@ class DatabaseSeeder extends Seeder
             ActivitySeeder::class,
             CheckInSeeder::class,
             PrizeSeeder::class,
-            RecipientsSeeder::class,
+            // RecipientsSeeder::class,
+            DepartmentSeeder::class,
         ]);
     }
 }

+ 31 - 0
database/seeders/DepartmentSeeder.php

@@ -0,0 +1,31 @@
+<?php
+
+namespace Database\Seeders;
+
+use Illuminate\Database\Console\Seeds\WithoutModelEvents;
+use Illuminate\Database\Seeder;
+use \App\Models\Department;
+use Illuminate\Support\Facades\File;
+
+class DepartmentSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        Department::truncate();
+        $json = File::get("database/MAA_department.json");
+        $countries = json_decode($json);
+
+        foreach ($countries as $key => $value) {
+            Department::insert([
+                'DepartmentID' => $value->DepartmentID,
+                'DepartmentName' => $value->DepartmentName,
+                'Manager' => $value->Manager,
+            ]);
+        }
+    }
+}

+ 99 - 99
database/seeders/PrizeSeeder.php

@@ -15,104 +15,104 @@ class PrizeSeeder extends Seeder
      */
     public function run()
     {
-        // Prize::truncate();
-        // Prize::insert([
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '普獎現金 1,200 元',
-        //         'provider' => '亞新',
-        //         'count' => 0,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '現金 16,800 元',
-        //         'provider' => '亞新',
-        //         'count' => 2,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '現金 12,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 1,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '現金 10,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 1,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '大潤發禮券 10,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 4,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '現金 8,800 元',
-        //         'provider' => '亞新',
-        //         'count' => 5,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '大潤發禮券 8,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 6,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '現金 6,600 元',
-        //         'provider' => '亞新',
-        //         'count' => 13,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '大潤發禮券 6,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 10,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '大潤發禮券 3,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 80,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '大潤發禮券 2,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 50,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        //     [
-        //         'activity_id' => '0',
-        //         'name' => '福利即享券 2,000 元',
-        //         'provider' => '亞新',
-        //         'count' => 50,
-        //         'created_at' => now(),
-        //         'updated_at' => now(),
-        //     ],
-        // ]);
+        Prize::truncate();
+        Prize::insert([
+            [
+                'activity_id' => '1',
+                'name' => '普獎現金 1,200 元',
+                'provider' => '亞新',
+                'count' => 0,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '現金 16,800 元',
+                'provider' => '亞新',
+                'count' => 2,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '現金 12,000 元',
+                'provider' => '亞新',
+                'count' => 1,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '現金 10,000 元',
+                'provider' => '亞新',
+                'count' => 1,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '大潤發禮券 10,000 元',
+                'provider' => '亞新',
+                'count' => 4,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '現金 8,800 元',
+                'provider' => '亞新',
+                'count' => 5,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '大潤發禮券 8,000 元',
+                'provider' => '亞新',
+                'count' => 6,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '現金 6,600 元',
+                'provider' => '亞新',
+                'count' => 13,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '大潤發禮券 6,000 元',
+                'provider' => '亞新',
+                'count' => 10,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '大潤發禮券 3,000 元',
+                'provider' => '亞新',
+                'count' => 80,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '大潤發禮券 2,000 元',
+                'provider' => '亞新',
+                'count' => 50,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+            [
+                'activity_id' => '1',
+                'name' => '福利即享券 2,000 元',
+                'provider' => '亞新',
+                'count' => 50,
+                'created_at' => now(),
+                'updated_at' => now(),
+            ],
+        ]);
     }
 }