Ver código fonte

创建容器支持版本和文件

moell 11 meses atrás
pai
commit
e9825d2a04

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

@@ -6,9 +6,11 @@ use App\Http\Controllers\Controller;
 use App\Http\Requests\API\Container\CreateOrUpdateRequest;
 use App\Http\Resources\API\ContainerDetailResource;
 use App\Models\Container;
+use App\Models\ContainerContent;
 use App\Models\Enums\ActionObjectType;
 use App\Models\Enums\FileObjectType;
 use App\Models\Enums\ObjectAction;
+use App\Models\File;
 use App\Repositories\ActionRepository;
 use App\Repositories\CustomFieldRepository;
 use App\Services\File\FileAssociationService;
@@ -42,7 +44,6 @@ class ContainerController extends Controller
             'company_id' => Auth::user()->company_id,
             'created_by' => Auth::id(),
             'whitelist' => $request->whitelist ? sprintf(",%s,", implode(',', $request->whitelist)) : null,
-            'description' => $imageUrlService->interceptImageUrl($request->description) ,
         ];
 
         if ($request->has("naming_rule_id") && $request->get("naming_rule_id") > 0) {
@@ -55,8 +56,6 @@ class ContainerController extends Controller
         $container->fill($formData);
         $container->save();
 
-        $container = Container::query()->create($formData);
-
         ActionRepository::createByContainer($container, ObjectAction::CREATED);
 
         $service->association(
@@ -65,6 +64,21 @@ class ContainerController extends Controller
             FileObjectType::CONTAINER
         );
 
+        $files = File::query()->where('object_id', $container->id)
+            ->where('object_type', ActionObjectType::CONTAINER)
+            ->where('source', 1)
+            ->pluck("id");
+
+        $contentFormData = [
+            'description' => $imageUrlService->interceptImageUrl($request->description),
+            'container_id' => $container->id,
+            'created_by' => Auth::id(),
+            'name' => $request->name,
+            'files' => $files->implode(",") ?: null
+        ];
+
+        ContainerContent::query()->create($contentFormData);
+
         return $this->created();
     }
 

+ 1 - 1
app/Models/Container.php

@@ -13,7 +13,7 @@ class Container extends Model
 
     protected $fillable = [
         'name', 'library_id', 'naming_rule_id', 'naming_rules', 'mailto', 'email_subject', 'acl', 'whitelist',
-        'description', 'doc_stage', 'doc_type'
+        'doc_stage', 'doc_type'
     ];
 
     protected $casts = [

+ 15 - 0
app/Models/ContainerContent.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Database\Eloquent\Model;
+
+class ContainerContent extends Model
+{
+    use HasFactory;
+
+    protected $fillable = [
+        'container_id', 'description', 'files', 'version', 'name', 'created_by',
+    ];
+}

+ 1 - 1
database/migrations/2024_04_14_105925_create_containers_table.php

@@ -24,8 +24,8 @@ return new class extends Migration
             $table->string('email_subject')->nullable();
             $table->string('acl')->default('private')->comment('private,custom');
             $table->string("whitelist")->nullable();
-            $table->text("description")->nullable();
             $table->integer("created_by")->nullable();
+            $table->integer("version")->default(1);
             $table->softDeletes();
             $table->timestamps();
         });

+ 5 - 7
database/migrations/2024_04_14_124847_create_documents_table.php → database/migrations/2024_04_17_211914_create_container_contents_table.php

@@ -11,16 +11,14 @@ return new class extends Migration
      */
     public function up(): void
     {
-        Schema::create('documents', function (Blueprint $table) {
+        Schema::create('container_contents', function (Blueprint $table) {
             $table->id();
             $table->string("name", 150);
             $table->integer("container_id");
-            $table->integer("folder_id");
-            $table->text("content")->nullable();
-            $table->tinyInteger("source")->default(1)->comment("1-系统文档;2-外部上传");
-            $table->integer("file_id")->nullable()->comment("上传文档文件ID");
+            $table->string("files")->nullable();
+            $table->text("description")->nullable();
             $table->integer("created_by")->nullable();
-            $table->softDeletes();
+            $table->integer("version")->default(1);
             $table->timestamps();
         });
     }
@@ -30,6 +28,6 @@ return new class extends Migration
      */
     public function down(): void
     {
-        Schema::dropIfExists('documents');
+        Schema::dropIfExists('container_contents');
     }
 };