]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
feat(ERP-292): модель Products1cAutomarkPrediction и DTO ParseResult
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 17 Apr 2026 13:31:16 +0000 (16:31 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Fri, 17 Apr 2026 13:31:16 +0000 (16:31 +0300)
erp24/records/Products1cAutomarkPrediction.php [new file with mode: 0644]
erp24/services/automark/ParseResult.php [new file with mode: 0644]
erp24/tests/unit/records/Products1cAutomarkPredictionTest.php [new file with mode: 0644]

diff --git a/erp24/records/Products1cAutomarkPrediction.php b/erp24/records/Products1cAutomarkPrediction.php
new file mode 100644 (file)
index 0000000..201c3ac
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+
+declare(strict_types=1);
+
+namespace yii_app\records;
+
+use yii\db\ActiveQuery;
+
+/**
+ * Предсказание авторазметки товара из 1С.
+ *
+ * @property int         $id
+ * @property string      $product_id
+ * @property string|null $category
+ * @property string|null $subcategory
+ * @property string|null $species
+ * @property string|null $sort
+ * @property string|null $type
+ * @property int|null    $size
+ * @property string|null $color
+ * @property float       $confidence
+ * @property string      $method
+ * @property int         $status
+ * @property int|null    $approved_by
+ * @property string      $created_at
+ * @property string|null $updated_at
+ */
+class Products1cAutomarkPrediction extends \yii\db\ActiveRecord
+{
+    public const STATUS_PENDING  = 0;
+    public const STATUS_APPROVED = 1;
+    public const STATUS_REJECTED = 2;
+
+    public const METHOD_RULE       = 'rule';
+    public const METHOD_SIMILARITY = 'similarity';
+
+    public static function tableName(): string
+    {
+        return 'products_1c_automark_predictions';
+    }
+
+    public function rules(): array
+    {
+        return [
+            [['product_id', 'confidence', 'method', 'status'], 'required'],
+            [['product_id', 'category', 'subcategory', 'species', 'sort', 'type', 'color', 'method'], 'string', 'max' => 255],
+            [['size', 'status', 'approved_by'], 'integer'],
+            [['confidence'], 'number', 'min' => 0, 'max' => 1],
+            [['method'], 'in', 'range' => [self::METHOD_RULE, self::METHOD_SIMILARITY]],
+            [['status'], 'in', 'range' => [self::STATUS_PENDING, self::STATUS_APPROVED, self::STATUS_REJECTED]],
+            [['created_at', 'updated_at'], 'safe'],
+            [['category', 'subcategory', 'species', 'sort', 'type', 'color', 'approved_by', 'updated_at', 'size'], 'default', 'value' => null],
+        ];
+    }
+
+    public function isPending(): bool
+    {
+        return $this->status === self::STATUS_PENDING;
+    }
+
+    public function isApproved(): bool
+    {
+        return $this->status === self::STATUS_APPROVED;
+    }
+
+    public function getProduct(): ActiveQuery
+    {
+        return $this->hasOne(Products1c::class, ['id' => 'product_id']);
+    }
+}
diff --git a/erp24/services/automark/ParseResult.php b/erp24/services/automark/ParseResult.php
new file mode 100644 (file)
index 0000000..a7ea9c9
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+declare(strict_types=1);
+
+namespace yii_app\services\automark;
+
+final class ParseResult
+{
+    public function __construct(
+        public readonly ?string $category,
+        public readonly ?string $subcategory,
+        public readonly ?string $species,
+        public readonly ?string $sort,
+        public readonly ?string $type,
+        public readonly ?int    $size,
+        public readonly ?string $color,
+        public readonly float   $confidence,
+        public readonly string  $method,
+    ) {}
+
+    public function isConfident(float $threshold = 0.7): bool
+    {
+        return $this->confidence >= $threshold;
+    }
+
+    public function toArray(): array
+    {
+        return [
+            'category'    => $this->category,
+            'subcategory' => $this->subcategory,
+            'species'     => $this->species,
+            'sort'        => $this->sort,
+            'type'        => $this->type,
+            'size'        => $this->size,
+            'color'       => $this->color,
+            'confidence'  => $this->confidence,
+            'method'      => $this->method,
+        ];
+    }
+}
diff --git a/erp24/tests/unit/records/Products1cAutomarkPredictionTest.php b/erp24/tests/unit/records/Products1cAutomarkPredictionTest.php
new file mode 100644 (file)
index 0000000..ef6e43a
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+declare(strict_types=1);
+
+namespace tests\unit\records;
+
+use Codeception\Test\Unit;
+use yii_app\records\Products1cAutomarkPrediction;
+
+/**
+ * @covers \yii_app\records\Products1cAutomarkPrediction
+ */
+class Products1cAutomarkPredictionTest extends Unit
+{
+    public function testTableName(): void
+    {
+        $this->assertSame('products_1c_automark_predictions', Products1cAutomarkPrediction::tableName());
+    }
+
+    public function testStatusConstants(): void
+    {
+        $this->assertSame(0, Products1cAutomarkPrediction::STATUS_PENDING);
+        $this->assertSame(1, Products1cAutomarkPrediction::STATUS_APPROVED);
+        $this->assertSame(2, Products1cAutomarkPrediction::STATUS_REJECTED);
+    }
+
+    public function testMethodConstants(): void
+    {
+        $this->assertSame('rule', Products1cAutomarkPrediction::METHOD_RULE);
+        $this->assertSame('similarity', Products1cAutomarkPrediction::METHOD_SIMILARITY);
+    }
+
+    public function testIsPendingMethod(): void
+    {
+        $model = new Products1cAutomarkPrediction();
+        $model->status = Products1cAutomarkPrediction::STATUS_PENDING;
+        $this->assertTrue($model->isPending());
+    }
+
+    public function testIsApprovedMethod(): void
+    {
+        $model = new Products1cAutomarkPrediction();
+        $model->status = Products1cAutomarkPrediction::STATUS_APPROVED;
+        $this->assertTrue($model->isApproved());
+    }
+}