Browse Source

task requirement container 支持审批、我的审批

moell 8 months ago
parent
commit
3651d633aa

+ 19 - 2
app/Http/Controllers/API/ApprovalController.php

@@ -27,9 +27,25 @@ class ApprovalController extends Controller
     /**
      * Display a listing of the resource.
      */
-    public function index()
+    public function index(Request $request)
     {
-        //
+        $approvals = Approval::query()->filter($request->all())->orderByDesc("created_at")->paginate();
+
+        $items = [];
+        foreach ($approvals as $approval) {
+            $items[] = [
+                'id' => $approval->id,
+                'status' => $approval->status,
+                'object_type' => $approval->object_type,
+                'object_id' => $approval->object_id,
+                'node_level' => $approval->node_level,
+                'created_by' => new UserProfileResource($approval->createdBy),
+            ];
+        }
+
+        return $this->success([
+            'data' => $items
+        ]);
     }
 
     /**
@@ -73,6 +89,7 @@ class ApprovalController extends Controller
                     'id' => $object->id,
                     'name' => $object[$approvalObjectType->nameField()],
                 ],
+                'remark' => $approval->remark,
                 'node_level' => $approval->node_level,
                 'created_by' => new UserProfileResource($approval->createdBy),
                 'approval_flow' => new ApprovalFlowDetailResource($approval->approvalFlow),

+ 1 - 0
app/Http/Resources/API/ContainerResource.php

@@ -25,6 +25,7 @@ class ContainerResource extends JsonResource
             "doc_stage"  => $this->doc_stage,
             "doc_type"  => $this->doc_type,
             "version" => $this->version,
+            'approval_status' => $this->approval_status,
             "created_at"  => (string)$this->created_at,
             "created_by" => new UserProfileResource($this->createdBy),
         ];

+ 1 - 0
app/Http/Resources/API/RequirementResource.php

@@ -23,6 +23,7 @@ class RequirementResource extends JsonResource
             'requirement_group' => new RequirementGroupResource($this->group),
             'asset' => new SimpleAssetResource($this->asset),
             'reviewed_by' => $this->reviewed_by,
+            'approval_status' => $this->approval_status,
             'priority' => $this->priority,
             'note' => $this->note,
             'description' => $this->description?(new \App\Services\File\ImageUrlService)->getImageUrl($this->description):null,

+ 2 - 1
app/Http/Resources/API/TaskDetailResource.php

@@ -30,8 +30,9 @@ class TaskDetailResource extends JsonResource
             "doc_stage" => $this->doc_stage,
             "doc_type" => $this->doc_type,
             "status" => $this->status,
+            'approval_status' => $this->approval_status,
             "assign" => $this->assign,
-            'description' => $this->description?(new \App\Services\File\ImageUrlService)->getImageUrl($this->description):null,
+            'description' => $this->description ? (new \App\Services\File\ImageUrlService)->getImageUrl($this->description) : null,
             "begin" => $this->begin,
             "end" => $this->end,
             "mailto"  => $this->mailto,

+ 1 - 0
app/Http/Resources/API/TaskResource.php

@@ -21,6 +21,7 @@ class TaskResource extends JsonResource
             "begin" => $this->begin,
             "end" => $this->end,
             "status" => $this->status,
+            'approval_status' => $this->approval_status,
             "assign_to" => new UserProfileResource($this->assignTo),
             "created_by" => new UserProfileResource($this->createdBy),
             //"children" => TaskResource::collection($this->children),

+ 33 - 0
app/ModelFilters/ApprovalFilter.php

@@ -0,0 +1,33 @@
+<?php
+
+namespace App\ModelFilters;
+
+use App\Models\Enums\ObjectApprovalStatus;
+use Carbon\Carbon;
+use EloquentFilter\ModelFilter;
+use Illuminate\Support\Facades\Auth;
+
+class ApprovalFilter extends ModelFilter
+{
+    /**
+    * Related Models that have ModelFilters as well as the method on the ModelFilter
+    * As [relationMethod => [input_key1, input_key2]].
+    *
+    * @var array
+    */
+    public $relations = [];
+
+    public function setup()
+    {
+        $tab = $this->query['tab'] ?? null;
+
+        $this->where(function ($query) use ($tab) {
+            return match ($tab) {
+                'wait_for_me' => $query->where("users", 'like', '%,'.Auth::id().',%')->where("status", ObjectApprovalStatus::DOING),
+                'approved' => $query,
+                'pr' => $query->where("created_at", Auth::id()),
+                default => $query->where("created_at", Auth::id())->orWhere("users", 'like', '%,'.Auth::id().',%'),
+            };
+        });
+    }
+}

+ 2 - 1
app/Models/Approval.php

@@ -2,13 +2,14 @@
 
 namespace App\Models;
 
+use EloquentFilter\Filterable;
 use Illuminate\Database\Eloquent\Factories\HasFactory;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\SoftDeletes;
 
 class Approval extends Model
 {
-    use HasFactory, SoftDeletes;
+    use HasFactory, SoftDeletes, Filterable;
 
     protected $fillable = [
         'approval_flow_id',

+ 28 - 0
database/migrations/2024_06_26_161803_add_approval_status_to_requirements_table.php

@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('requirements', function (Blueprint $table) {
+            $table->string("approval_status", 30)->nullable()->default(\App\Models\Enums\ObjectApprovalStatus::WAIT->value);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('requirements', function (Blueprint $table) {
+            $table->dropColumn(['approval_status']);
+        });
+    }
+};

+ 28 - 0
database/migrations/2024_06_26_161851_add_approval_status_to_tasks_table.php

@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('tasks', function (Blueprint $table) {
+            $table->string("approval_status", 30)->nullable()->default(\App\Models\Enums\ObjectApprovalStatus::WAIT->value);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('tasks', function (Blueprint $table) {
+            $table->dropColumn(['approval_status']);
+        });
+    }
+};

+ 28 - 0
database/migrations/2024_06_26_161906_add_approval_status_to_containers_table.php

@@ -0,0 +1,28 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('containers', function (Blueprint $table) {
+            $table->string("approval_status", 30)->nullable()->default(\App\Models\Enums\ObjectApprovalStatus::WAIT->value);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('containers', function (Blueprint $table) {
+            $table->dropColumn(['approval_status']);
+        });
+    }
+};