Преглед изворни кода

Merge branch 'refs/heads/dev' into f-saas

peterguo пре 2 месеци
родитељ
комит
241daaa21a

+ 1 - 1
app/Http/Controllers/API/ActionController.php

@@ -23,7 +23,7 @@ class ActionController extends Controller
     {
         $actionObjectType = ActionObjectType::from($objectType);
 
-        $model = $actionObjectType->modelBuilder()->where("company_id", Auth::user()->company_id)->findOrFail($objectId);
+        $model = $actionObjectType->modelBuilder()->findOrFail($objectId);
 
         $objectIds = [$objectId];
         if (ActionObjectType::CONTAINER_FILE->value == $objectType) {

+ 38 - 1
app/Http/Controllers/API/ApprovalController.php

@@ -25,12 +25,15 @@ use App\Models\Enums\ObjectAction;
 use App\Models\Enums\ObjectApprovalStatus;
 use App\Models\File;
 use App\Models\Folder;
+use App\Models\Scopes\CompanyScope;
 use App\Repositories\ActionRepository;
+use App\Repositories\ApprovalRepository;
 use App\Services\Approval\ActionService;
 use App\Services\Approval\StoreService;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Auth;
+use function Symfony\Component\Translation\t;
 
 class ApprovalController extends Controller
 {
@@ -84,7 +87,7 @@ class ApprovalController extends Controller
         $approvalObjectType = ApprovalObjectType::from($approval->object_type);
         $object = $approvalObjectType
             ->modelBuilder()
-            ->find($approval->object_id);
+            ->findOrFail($approval->object_id);
 
         $actions = Action::with(['createdBy', 'file'])->where([
             'object_type' => $approvalObjectType->actionObjectType(),
@@ -138,6 +141,40 @@ class ApprovalController extends Controller
         return $this->noContent();
     }
 
+    public function detail(Request $request)
+    {
+        //判断是否已经有审批
+        $approvalList = Approval::query()
+            ->withoutGlobalScope(CompanyScope::class)
+            ->where('object_type', $request->get('object_type'))
+            ->where('object_id', $request->get('object_id'))
+            ->get();
+        $approval = '';
+        foreach ($approvalList as $item) {
+            if (in_array($request->get('file_id'),$item->sub_object_ids)){
+                $approval = $item;
+            }
+        }
+        //Get total approvalFlow
+        if ($approval) {
+            $approvalFlow = ApprovalFlow::query()->withoutGlobalScope(CompanyScope::class)->find($approval->approval_flow_id);
+        }else{
+            return $this->success([
+                'data' => [],
+            ]);
+        }
+
+        //获取审批时间
+        $action = Action::with(['createdBy', 'file'])->where([
+            'object_type' => $request->get('object_type'),
+            'object_id' => $request->get('object_id'),
+            'additional_id' => $approval->id,
+        ])->orderBy("created_at")->get();
+
+        return $this->success([
+            'data' => ApprovalRepository::approvalDetail($approvalFlow,ActionByApprovalLogResource::collection($action)),
+        ]);
+    }
     /**
      * Update the specified resource in storage.
      */

+ 9 - 3
app/Http/Controllers/API/ContainerController.php

@@ -220,9 +220,15 @@ class ContainerController extends Controller
 
     public function linkage(string $libraryId)
     {
-        $items = Container::select(['id', 'name'])->withCount(['folder' => function ($query) {
-            $query->where('parent_id', 0);
-        }])->allowed()->where("library_id", $libraryId)->get()->each(function ($items) {
+        $items = Container::select(['id', 'name'])
+            ->withCount(['folder' => function ($query) {
+                $query->where('parent_id', 0);
+            }])
+            ->withCount(['file' => function ($query) {
+                $query->where('folder_id', 0);
+            }])
+            ->allowed()->where("library_id", $libraryId)->get()->each(function ($items) {
+
             // 设置固定的type值
             $items->type = 'container';
             $items->uniId=$items->type.'_'.$items->id;

+ 32 - 1
app/Http/Controllers/API/DocumentController.php

@@ -3,7 +3,9 @@
 namespace App\Http\Controllers\API;
 
 use App\Http\Controllers\Controller;
+use App\Models\Asset;
 use App\Models\Enums\ActionObjectType;
+use App\Models\Project;
 use App\Services\Folder\FoldersService;
 use Illuminate\Http\JsonResponse;
 
@@ -14,20 +16,29 @@ class DocumentController extends Controller
         $data = [
             'type' => null,
             'asset_id' => null,
+            'asset_name' => null,
             'project_id' => null,
+            'project_name' => null,
             'library_id' => null,
+            'library_name' => null,
             'container_id' => null,
+            'container_name' => null,
             'folder' => null,
             'object_id' => intval($objectId),
             'object_type' => $objectType,
+            'object_name' => '',
         ];
-        $model = ActionObjectType::from($objectType)->modelBuilder()->findOrFail($objectId);
+        $modelEnum = ActionObjectType::from($objectType);
+        $model = $modelEnum->modelBuilder()->findOrFail($objectId);
+        $data['object_name'] = $model->{$modelEnum->nameField()};
 
         switch ($objectType) {
             case ActionObjectType::CONTAINER_FILE->value:
                 $data['folder'] = (new FoldersService())->getAllParentTree($model->folder_id);
                 $data['container_id'] = $model->container?->id;
+                $data['container_name'] = $model->container?->name;
                 $data['library_id'] = $model->library?->id;
+                $data['library_name'] = $model->library?->name;
                 $data['asset_id'] = $model->library?->asset_id;
                 $data['project_id'] = $model->library?->project_id;
                 $data['type'] = $model->library?->type;
@@ -35,26 +46,46 @@ class DocumentController extends Controller
             case ActionObjectType::FOLDER->value:
                 $data['folder'] = (new FoldersService())->getAllParentTree($model->id);
                 $data['container_id'] = $model->container?->id;
+                $data['container_name'] = $model->container?->name;
                 $data['library_id'] = $model->library?->id;
+                $data['library_name'] = $model->library?->name;
                 $data['asset_id'] = $model->library?->asset_id;
                 $data['project_id'] = $model->library?->project_id;
                 $data['type'] = $model->library?->type;
                 break;
             case ActionObjectType::CONTAINER->value:
                 $data['container_id'] = $model->id;
+                $data['container_name'] = $model->name;
                 $data['library_id'] = $model->library?->id;
+                $data['library_name'] = $model->library?->name;
                 $data['asset_id'] = $model->library?->asset_id;
                 $data['project_id'] = $model->library?->project_id;
                 $data['type'] = $model->library?->type;
                 break;
             case ActionObjectType::LIBRARY->value:
                 $data['library_id'] = $model->id;
+                $data['library_name'] = $model->name;
                 $data['asset_id'] = $model->asset_id;
                 $data['project_id'] = $model->project_id;
                 $data['type'] = $model->type;
+                break;
+            case ActionObjectType::PROJECT->value:
+                $data['project_id'] = $model->id;
+                $data['project_name'] = $model->name;
+                break;
+            case ActionObjectType::ASSET->value:
+                $data['asset_id'] = $model->id;
+                $data['asset_name'] = $model->name;
+                break;
             default:
                 break;
         }
+        if ($data['asset_id'] && ! $data['asset_name']) {
+            $data['asset_name'] = Asset::query()->findOrFail($data['asset_id'])->name;
+        }
+        if ($data['project_id'] && ! $data['project_name']) {
+            $data['project_name'] = Project::query()->findOrFail($data['project_id'])->name;
+        }
         return $this->success(['data' => $data]);
     }
 }

+ 2 - 1
app/Http/Controllers/API/FileController.php

@@ -362,7 +362,8 @@ class FileController extends Controller
             ->where('object_type', $file->object_type)
             ->where('object_id', $file->object_id)
             ->where('folder_id', $file->folder_id)
-            ->where('title', $file->title)
+            ->where('source_file_id', $file->source_file_id)
+            ->orWhere('id', $file->source_file_id)
             ->latest('version')
             ->paginate($pageSize);
 

+ 1 - 1
app/Http/Controllers/API/FolderController.php

@@ -32,7 +32,7 @@ class FolderController extends Controller
 
         $object=$folderObjectType->modelBuilderAllowed()->with(['library'])->findOrFail($objectId);
 
-        $folders = Folder::select(['id', 'name', 'parent_id'])->withCount('children')
+        $folders = Folder::select(['id', 'name', 'parent_id'])->withCount('children')->withCount('files')
             ->where([
                 'object_type' => $objectType,
                 'object_id' => $objectId,

+ 5 - 0
app/Models/Container.php

@@ -68,4 +68,9 @@ class Container extends Model
     {
         return $this->hasMany(Folder::class, "object_id")->where("object_type", ActionObjectType::CONTAINER->value);
     }
+
+    public function file()
+    {
+        return $this->hasMany(File::class, "object_id")->where("object_type", ActionObjectType::CONTAINER->value);
+    }
 }

+ 5 - 0
app/Models/File.php

@@ -66,6 +66,11 @@ class File extends Model
         return $this->belongsTo(Container::class, 'object_id');
     }
 
+    public function containerLibrary(): HasOneThrough
+    {
+        return $this->hasOneThrough(Library::class, Container::class, 'id', 'id', 'object_id', 'library_id');
+    }
+
     public function library(): HasOneThrough
     {
         return $this->hasOneThrough(Library::class, Container::class, 'id', 'id', 'object_id', 'library_id');

+ 28 - 0
app/Repositories/ApprovalRepository.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace App\Repositories;
+
+
+use App\Http\Resources\API\UserProfileResource;
+use App\Models\ApprovalFlow;
+use App\Models\User;
+
+class ApprovalRepository
+{
+    public static function approvalDetail(ApprovalFlow $approvalFlow, $action): array
+    {
+        //获取整个流程
+        $nodes = isset($approvalFlow->nodes) ? $approvalFlow->nodes : [];
+
+        foreach ($nodes as $k=> &$value) {
+            $approvalUsers=User::query()->whereIn('id', $value['approval_users'])->get();
+            $value['approval_log']   = isset($action[$k]) ? $action[$k] : [];
+            $value['approval_users']   = UserProfileResource::collection($approvalUsers);
+        }
+
+        return $nodes;
+    }
+
+
+
+}

+ 6 - 3
app/Services/Folder/FoldersService.php

@@ -14,6 +14,9 @@ class FoldersService
     {
         $folder = Folder::query()->findOrFail($id);
         $namingRule = NamingRule::query()->findOrFail($namingRuleId);
+        if ($folder->naming_rule_id == $namingRule->id) {
+            return;
+        }
         // 子孙均需更新
         DB::transaction(function () use ($folder, $namingRule) {
             Folder::query()
@@ -23,17 +26,17 @@ class FoldersService
             File::query()
                 ->join('folders', 'files.folder_id', '=', 'folders.id')
                 ->where('folders.path', 'like', $folder->path . '%')
-                ->update(['files.naming_rule_id' => $namingRule->id]);
+                ->update(['files.naming_rule_id' => $namingRule->id, 'naming_rules' => null]);
         });
     }
 
     public function getAllParentTree($folderId): Collection|array
     {
-        $folder = Folder::query() ->select('id', 'parent_id', 'path')->findOrFail($folderId);
+        $folder = Folder::query() ->select('id', 'name', 'parent_id', 'path')->findOrFail($folderId);
         $folderIds = explode(',', $folder->path);
 
         $allChildren = Folder::query()
-            ->select('id', 'parent_id')
+            ->select('id', 'name', 'parent_id')
             ->whereIn('id', $folderIds ?? [])
             ->get();
 

+ 1 - 0
routes/api.php

@@ -165,6 +165,7 @@ Route::middleware((function() {
             Route::post("approval/{approval}/copy-container-file", [API\ApprovalController::class, "copyContainerFile"])
                 ->name("approval.copy-container-file");
 
+        Route::post("approval-detail", [API\ApprovalController::class, "detail"])->name("approval.detail");
 
             Route::get("asset/{asset}/dynamic", [API\AssetController::class, "dynamic"])->name("asset.dynamic");